passing compile-time bitwise tests (but not runtime :?)
This commit is contained in:
parent
777a84e9f5
commit
195480d58a
|
@ -40,7 +40,7 @@ func shrLarge*(r: var Limbs, a: Limbs, w, shift: SomeInteger) =
|
|||
when cpuEndian == littleEndian:
|
||||
for i in w ..< a.len-1:
|
||||
r[i-w] = (a[i] shr shift) or (a[i+1] shl (WordBitWidth - shift))
|
||||
r[^w] = a[^1] shr shift
|
||||
r[^(1+w)] = a[^1] shr shift
|
||||
else:
|
||||
for i in countdown(a.len-1, 1+w):
|
||||
r[i-w] = (a[i] shr shift) or (a[i-1] shl (WordBitWidth - k))
|
||||
|
|
|
@ -166,6 +166,7 @@ func `shr`*(a: Stuint, k: SomeInteger): Stuint {.inline.} =
|
|||
if k < WordBitWidth:
|
||||
result.limbs.shrSmall(a.limbs, k)
|
||||
return
|
||||
|
||||
# w = k div WordBitWidth, shift = k mod WordBitWidth
|
||||
let w = k shr static(log2trunc(uint32(WordBitWidth)))
|
||||
let shift = k and (WordBitWidth - 1)
|
||||
|
@ -181,6 +182,7 @@ func `shl`*(a: Stuint, k: SomeInteger): Stuint {.inline.} =
|
|||
result.limbs.shlSmall(a.limbs, k)
|
||||
result.clearExtraBits()
|
||||
return
|
||||
|
||||
# w = k div WordBitWidth, shift = k mod WordBitWidth
|
||||
let w = k shr static(log2trunc(uint32(WordBitWidth)))
|
||||
let shift = k and (WordBitWidth - 1)
|
||||
|
|
|
@ -337,12 +337,6 @@ suite "Testing unsigned int bitwise operations":
|
|||
check: cast[uint16](b) == z # Sanity check
|
||||
check: cast[uint16](b shl 8) == z shl 8
|
||||
|
||||
block: # Testing shl for nested UintImpl
|
||||
let p2_64 = UintImpl[uint64](hi:1, lo:0)
|
||||
let p = 1.stuint(128) shl 64
|
||||
|
||||
check: p == cast[StUint[128]](p2_64)
|
||||
|
||||
test "Shift right - by less than half the size of the integer":
|
||||
check: cast[uint16](b) == z # Sanity check
|
||||
check: cast[uint16](b shr 2) == z shr 2
|
||||
|
|
Loading…
Reference in New Issue