-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Labels
Description
The current code add/sub/mul can be tuned to help GCC/Clang significantly improve the assembly generated.
Next commit will bring the ADD code from this:
to this
This is unrolled, add is just add + adc now instead of leaq, addq, cmpq, adcq
Notice how the leaq (corresponding to the "tmp" and the cmpq were removed.
Multiplications deserve the same.
Test case:
import ../src/mpint, times
let a = 42.initMpUint(128)
let b = 1000.initMpUint(128)
var c = 0.initMpUint(128)
proc carry(foo: var MpUint[128], a: MpUint[128]) =
for _ in 0 ..< 1_000_000_000:
foo += a
proc borrow(foo: var MpUint[128], b: MpUint[128]) =
for _ in 0 ..< 1_000_000_000:
foo -= a
var start = cpuTime()
carry(c, a)
var stop = cpuTime()
echo "Carry: " & $(stop - start) & "s"
start = cpuTime()
borrow(c, b)
stop = cpuTime()
echo "Borrow: " & $(stop - start) & "s"
echo c
echo (c - 1.initMpUint(128))
