less branching for shift ops
This commit is contained in:
parent
35e80263a3
commit
6e27069298
|
@ -40,14 +40,11 @@ proc `shl`*[T: MpUint](x: T, y: SomeInteger): T {.noInit, noSideEffect.}=
|
||||||
|
|
||||||
type Sub = getSubType T
|
type Sub = getSubType T
|
||||||
|
|
||||||
if y > halfSize:
|
if y < halfSize:
|
||||||
result.hi = x.lo shl (y - halfSize)
|
|
||||||
result.lo = 0.Sub
|
|
||||||
elif y < halfSize:
|
|
||||||
result.hi = (x.hi shl y) or (x.lo shr (halfSize - y))
|
result.hi = (x.hi shl y) or (x.lo shr (halfSize - y))
|
||||||
result.lo = x.lo shl y
|
result.lo = x.lo shl y
|
||||||
else:
|
else:
|
||||||
result.hi = x.lo
|
result.hi = x.lo shl (y - halfSize)
|
||||||
result.lo = 0.Sub
|
result.lo = 0.Sub
|
||||||
|
|
||||||
proc `shr`*[T: MpUint](x: T, y: SomeInteger): T {.noInit, noSideEffect.}=
|
proc `shr`*[T: MpUint](x: T, y: SomeInteger): T {.noInit, noSideEffect.}=
|
||||||
|
@ -62,12 +59,9 @@ proc `shr`*[T: MpUint](x: T, y: SomeInteger): T {.noInit, noSideEffect.}=
|
||||||
|
|
||||||
type Sub = getSubType T
|
type Sub = getSubType T
|
||||||
|
|
||||||
if y > halfSize:
|
if y < halfSize:
|
||||||
result.hi = x.hi shr (y - halfSize)
|
|
||||||
result.lo = 0.Sub
|
|
||||||
elif y < halfSize:
|
|
||||||
result.lo = (x.lo shr y) or (x.hi shl (halfSize - y))
|
result.lo = (x.lo shr y) or (x.hi shl (halfSize - y))
|
||||||
result.hi = x.hi shr y
|
result.hi = x.hi shr y
|
||||||
else:
|
else:
|
||||||
result.lo = x.hi
|
result.hi = x.hi shr (y - halfSize)
|
||||||
result.hi = 0.Sub
|
result.lo = 0.Sub
|
Loading…
Reference in New Issue