parent
a0e8d4a93f
commit
7a3f382517
1 changed files with 29 additions and 15 deletions
|
|
@ -197,25 +197,39 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
||||||
|
|
||||||
proc divInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
proc divInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||||
asm """
|
asm """
|
||||||
|
test edx, edx
|
||||||
|
jne L_NOT_ZERO
|
||||||
|
call `raiseDivByZero`
|
||||||
|
L_NOT_ZERO:
|
||||||
|
cmp ecx, 0x80000000
|
||||||
|
jne L_DO_DIV
|
||||||
|
cmp edx, -1
|
||||||
|
jne L_DO_DIV
|
||||||
|
call `raiseOverflow`
|
||||||
|
L_DO_DIV:
|
||||||
mov eax, ecx
|
mov eax, ecx
|
||||||
mov ecx, edx
|
mov ecx, edx
|
||||||
xor edx, edx
|
cdq
|
||||||
idiv ecx
|
idiv ecx
|
||||||
jno theEnd
|
|
||||||
call `raiseOverflow`
|
|
||||||
theEnd:
|
|
||||||
ret
|
ret
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||||
asm """
|
asm """
|
||||||
|
test edx, edx
|
||||||
|
jne L_NOT_ZERO
|
||||||
|
call `raiseDivByZero`
|
||||||
|
L_NOT_ZERO:
|
||||||
|
cmp ecx, 0x80000000
|
||||||
|
jne L_DO_DIV
|
||||||
|
cmp edx, -1
|
||||||
|
jne L_DO_DIV
|
||||||
|
call `raiseOverflow`
|
||||||
|
L_DO_DIV:
|
||||||
mov eax, ecx
|
mov eax, ecx
|
||||||
mov ecx, edx
|
mov ecx, edx
|
||||||
xor edx, edx
|
cdq
|
||||||
idiv ecx
|
idiv ecx
|
||||||
jno theEnd
|
|
||||||
call `raiseOverflow`
|
|
||||||
theEnd:
|
|
||||||
mov eax, edx
|
mov eax, edx
|
||||||
ret
|
ret
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue