diff --git a/stint/private/uint_shift.nim b/stint/private/uint_shift.nim index 12eb944..3bff3d6 100644 --- a/stint/private/uint_shift.nim +++ b/stint/private/uint_shift.nim @@ -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)) diff --git a/stint/uintops.nim b/stint/uintops.nim index a227613..9c7efc5 100644 --- a/stint/uintops.nim +++ b/stint/uintops.nim @@ -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) diff --git a/tests/test_uint_bitwise.nim b/tests/test_uint_bitwise.nim index 0f9d2af..369c807 100644 --- a/tests/test_uint_bitwise.nim +++ b/tests/test_uint_bitwise.nim @@ -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