nimvm bug workaround
This commit is contained in:
parent
ddcb2111e4
commit
21eeee72df
|
@ -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
|
||||
|
||||
|
|
|
@ -182,13 +182,28 @@ 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
|
||||
for i in countdown(aOffset, 0):
|
||||
q[i] = shlAddMod(
|
||||
r.toOpenArray(0, rLen-1),
|
||||
a[i],
|
||||
b.toOpenArray(0, bLen-1),
|
||||
bBits
|
||||
)
|
||||
|
||||
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),
|
||||
a[i],
|
||||
b.toOpenArray(0, bLen-1),
|
||||
bBits
|
||||
)
|
||||
|
||||
# Clean up extra words
|
||||
for i in aOffset+1 ..< q.len:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue