blob: e87ba45546b811a1da21fbeb3276e97a9c01e365 [file] [log] [blame]
Bill Buzbee7c58bd42016-01-20 20:46:01 +00001%default {"result":"","special":"","rem":""}
2/*
3 * 32-bit binary div/rem operation. Handles special case of op0=minint and
4 * op1=-1.
5 */
6 /* div/rem vAA, vBB, vCC */
7 movzbl 2(rPC), %eax # eax <- BB
8 movzbl 3(rPC), %ecx # ecx <- CC
Serguei Katkov05dfaaa2016-01-28 08:21:26 +06009 GET_VREG %eax, %eax # eax <- vBB
10 GET_VREG %ecx, %ecx # ecx <- vCC
Bill Buzbee7c58bd42016-01-20 20:46:01 +000011 mov rIBASE, LOCAL0(%esp)
12 testl %ecx, %ecx
13 je common_errDivideByZero
14 movl %eax, %edx
15 orl %ecx, %edx
Serguei Katkovff8579e2016-02-17 11:30:23 +060016 testl $$0xFFFFFF00, %edx # If both arguments are less
Bill Buzbee7c58bd42016-01-20 20:46:01 +000017 # than 8-bit and +ve
18 jz .L${opcode}_8 # Do 8-bit divide
Serguei Katkovff8579e2016-02-17 11:30:23 +060019 testl $$0xFFFF0000, %edx # If both arguments are less
Bill Buzbee7c58bd42016-01-20 20:46:01 +000020 # than 16-bit and +ve
21 jz .L${opcode}_16 # Do 16-bit divide
22 cmpl $$-1, %ecx
23 jne .L${opcode}_32
24 cmpl $$0x80000000, %eax
25 jne .L${opcode}_32
26 movl $special, $result
27 jmp .L${opcode}_finish
28.L${opcode}_32:
29 cltd
30 idivl %ecx
31 jmp .L${opcode}_finish
32.L${opcode}_8:
33 div %cl # 8-bit divide otherwise.
34 # Remainder in %ah, quotient in %al
35 .if $rem
36 movl %eax, %edx
37 shr $$8, %edx
38 .else
39 andl $$0x000000FF, %eax
40 .endif
41 jmp .L${opcode}_finish
42.L${opcode}_16:
43 xorl %edx, %edx # Clear %edx before divide
44 div %cx
45.L${opcode}_finish:
Serguei Katkov05dfaaa2016-01-28 08:21:26 +060046 SET_VREG $result, rINST
Bill Buzbee7c58bd42016-01-20 20:46:01 +000047 mov LOCAL0(%esp), rIBASE
48 ADVANCE_PC_FETCH_AND_GOTO_NEXT 2