nimvm bug workaround

This commit is contained in:
jangko 2023-06-14 17:41:02 +07:00
parent ddcb2111e4
commit 21eeee72df
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 32 additions and 24 deletions

View File

@ -113,13 +113,6 @@ func mulmod*(a, b, m: StUint): StUint =
func powmod*(a, b, m: StUint): StUint =
## Modular exponentiation
when nimvm:
doAssert false, "cannot use powmod at compile-time"
else:
# we need this ugly branch
# because of nim-lang/Nim#12517
discard
let a_m = if a < m: a
else: a mod m

View File

@ -182,6 +182,21 @@ func divRem*(
copyWords(r, 0, a, aOffset+1, bLen-1)
r[rLen-1] = 0
# Now shift-left the copied words while adding the new word mod b
when nimvm:
# workaround nim bug #22095
var rr = @(r.toOpenArray(0, rLen-1))
var bb = @(b.toOpenArray(0, bLen-1))
for i in countdown(aOffset, 0):
q[i] = shlAddMod(
rr,
a[i],
bb,
bBits
)
for i in 0..rLen-1:
r[i] = rr[i]
else:
for i in countdown(aOffset, 0):
q[i] = shlAddMod(
r.toOpenArray(0, rLen-1),

View File

@ -116,8 +116,8 @@ template testMuldiv(chk, tst: untyped) =
chkMod(chk, 2, -5, 2, 64)
chkMod(chk, -2, -5, -2, 64)
#static:
#testMuldiv(ctCheck, ctTest)
static:
testMuldiv(ctCheck, ctTest)
suite "Wider signed int muldiv coverage":
testMuldiv(check, test)

View File

@ -60,8 +60,8 @@ template testdivmod(chk, tst: untyped) =
chkDivMod(chk, "FFFFFFFFFFFFFFFF", "27", "690690690690690", "F", 128)
chkDivMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "27", "6906906906906906906906906906906", "15", 128)
#static:
#testdivmod(ctCheck, ctTest)
static:
testdivmod(ctCheck, ctTest)
suite "Wider unsigned int muldiv coverage":
testdivmod(check, test)

View File

@ -56,8 +56,8 @@ template testModArith(chk, tst: untyped) =
chkPowMod(chk, "FFFFFFFFFFFFFFFF", "3", "C", "3", 128)
chkPowMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "3", "C", "3", 128)
#static:
#testModArith(ctCheck, ctTest)
static:
testModArith(ctCheck, ctTest)
suite "Wider unsigned Modular arithmetic coverage":
testModArith(check, test)