Fix corner case of checked div/mod on x86 (#10406)

Fixes #10377
This commit is contained in:
LemonBoy 2019-01-22 07:33:27 +01:00 • committed by Andreas Rumpf
commit 7a3f382517

View file

@ -197,26 +197,40 @@ 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 """
mov eax, ecx test edx, edx
mov ecx, edx jne L_NOT_ZERO
xor edx, edx call `raiseDivByZero`
idiv ecx L_NOT_ZERO:
jno theEnd cmp ecx, 0x80000000
call `raiseOverflow` jne L_DO_DIV
theEnd: cmp edx, -1
jne L_DO_DIV
call `raiseOverflow`
L_DO_DIV:
mov eax, ecx
mov ecx, edx
cdq
idiv ecx
ret ret
""" """
proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} = proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
asm """ asm """
mov eax, ecx test edx, edx
mov ecx, edx jne L_NOT_ZERO
xor edx, edx call `raiseDivByZero`
idiv ecx L_NOT_ZERO:
jno theEnd cmp ecx, 0x80000000
call `raiseOverflow` jne L_DO_DIV
theEnd: cmp edx, -1
mov eax, edx jne L_DO_DIV
call `raiseOverflow`
L_DO_DIV:
mov eax, ecx
mov ecx, edx
cdq
idiv ecx
mov eax, edx
ret ret
""" """