Missing overflow carry in multiplication (todo need test)

This commit is contained in:
mratsim 2018-02-27 13:40:18 +01:00
parent 8865ab874f
commit f53f7bd33a
1 changed files with 4 additions and 2 deletions

View File

@ -87,8 +87,10 @@ template naiveMulImpl[T: MpUint](x, y: T): MpUint[T] =
z1 += naiveMul(x.hi, y.lo) z1 += naiveMul(x.hi, y.lo)
let z2 = (z1 < tmp).T + naiveMul(x.hi, y.hi) let z2 = (z1 < tmp).T + naiveMul(x.hi, y.hi)
result.lo = z1.lo shl halfSize + z0 let tmp2 = z1.lo shl halfSize
result.hi = z2 + z1.hi result.lo = tmp2
result.lo += z0
result.hi = (result.lo < tmp2).T + z2 + z1.hi
proc naiveMul[T: BaseUint](x, y: T): MpUint[T] {.noSideEffect, noInit, inline.}= proc naiveMul[T: BaseUint](x, y: T): MpUint[T] {.noSideEffect, noInit, inline.}=
## Naive multiplication algorithm with extended precision ## Naive multiplication algorithm with extended precision