Skip to content

Commit

Permalink
fix bigint mul non-compilation after #231
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jul 9, 2023
1 parent d69c7bf commit cb038bb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion constantine.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const testDesc: seq[tuple[path: string, useGMP: bool]] = @[
("tests/math_bigints/t_io_bigints.nim", false),
# ("tests/math_bigints/t_bigints.nim", false),
# ("tests/math_bigints/t_bigints_multimod.nim", false),
# ("tests/math_bigints/t_bigints_mul_vs_gmp.nim", true),
("tests/math_bigints/t_bigints_mul_vs_gmp.nim", true),
# ("tests/math_bigints/t_bigints_mul_high_words_vs_gmp.nim", true),

# Big ints - arbitrary precision
Expand Down
2 changes: 1 addition & 1 deletion constantine/math/arithmetic/assembly/limbs_asm_mul_x86.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ macro mul_gen[rLen, aLen, bLen: static int](r_PIR: var Limbs[rLen], a_MEM: Limbs
let
r = asmArray(r_PIR, rLen, PointerInReg, asmInputOutputEarlyClobber, memIndirect = memWrite) # MemOffsettable is the better constraint but compilers say it is impossible. Use early clobber to ensure it is not affected by constant propagation at slight pessimization (reloading it).
a = asmArray(a_MEM, aLen, MemOffsettable, asmInput)
b = asmArray(b_MEM, aLen, MemOffsettable, asmInput)
b = asmArray(b_MEM, bLen, MemOffsettable, asmInput)

tSym = ident"t"
t = asmValue(tSym, Reg, asmOutputEarlyClobber)
Expand Down
4 changes: 4 additions & 0 deletions tests/math_bigints/t_bigints_mul_high_words_vs_gmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ proc main() =
mpz_init(r)
mpz_init(a)
mpz_init(b)
defer:
mpz_clear(b)
mpz_clear(a)
mpz_clear(r)

testRandomModSizes(12, rBits, aBits, bBits, wordsStartIndex):
# echo "--------------------------------------------------------------------------------"
Expand Down
9 changes: 7 additions & 2 deletions tests/math_bigints/t_bigints_mul_vs_gmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import
../../constantine/math/arithmetic,
../../constantine/platforms/abstractions,
# Test utilities
../../constantine/platforms/codecs,
../../helpers/prng_unsafe

echo "\n------------------------------------------------------\n"
Expand Down Expand Up @@ -60,6 +61,10 @@ proc main() =
mpz_init(r)
mpz_init(a)
mpz_init(b)
defer:
mpz_clear(b)
mpz_clear(a)
mpz_clear(r)

testRandomModSizes(12, rBits, aBits, bBits):
# echo "--------------------------------------------------------------------------------"
Expand Down Expand Up @@ -117,8 +122,8 @@ proc main() =
discard mpz_export(aBuf[0].addr, aW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, a)
discard mpz_export(bBuf[0].addr, bW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, b)
"\nMultiplication with operands\n" &
" a (" & align($aBits, 4) & "-bit): " & aBuf.toHex & "\n" &
" b (" & align($bBits, 4) & "-bit): " & bBuf.toHex & "\n" &
" a (" & align($aBits, 4) & "-bit): " & aBuf.toHex() & "\n" &
" b (" & align($bBits, 4) & "-bit): " & bBuf.toHex() & "\n" &
"into r of size " & align($rBits, 4) & "-bit failed:" & "\n" &
" GMP: " & rGMP.toHex() & "\n" &
" Constantine: " & rConstantine.toHex() & "\n" &
Expand Down

0 comments on commit cb038bb

Please sign in to comment.