diff options
author | deansher <deansherthompson@gmail.com> | 2019-01-28 08:12:24 -0500 |
---|---|---|
committer | deansher <deansherthompson@gmail.com> | 2019-01-28 08:12:24 -0500 |
commit | d60f8ab99181ea18cc534728ba4d0470c0ca1bce (patch) | |
tree | 64cef5bc336a6d0038dcb47a4e3b1cd30ed434d7 /lib/system/arithm.nim | |
parent | a6de0274ee768d135bab280d2b2700a0bb475300 (diff) | |
parent | 9402c82e803d133e0b845a7c5c79c261781e7d8d (diff) | |
download | Nim-d60f8ab99181ea18cc534728ba4d0470c0ca1bce.tar.gz |
Merge remote-tracking branch 'upstream/devel' into devel
Diffstat (limited to 'lib/system/arithm.nim')
-rw-r--r-- | lib/system/arithm.nim | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/lib/system/arithm.nim b/lib/system/arithm.nim index 69c558799..a875e95a7 100644 --- a/lib/system/arithm.nim +++ b/lib/system/arithm.nim @@ -197,26 +197,40 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): proc divInt(a, b: int): int {.compilerProc, asmNoStackFrame.} = asm """ - mov eax, ecx - mov ecx, edx - xor edx, edx - idiv ecx - jno theEnd - call `raiseOverflow` - theEnd: + 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 ecx, edx + cdq + idiv ecx ret """ proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} = asm """ - mov eax, ecx - mov ecx, edx - xor edx, edx - idiv ecx - jno theEnd - call `raiseOverflow` - theEnd: - mov eax, edx + 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 ecx, edx + cdq + idiv ecx + mov eax, edx ret """ |