summary refs log tree commit diff stats
path: root/compiler/int128.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/int128.nim')
-rw-r--r--compiler/int128.nim363
1 files changed, 87 insertions, 276 deletions
diff --git a/compiler/int128.nim b/compiler/int128.nim
index 067edeeed..74e581cd5 100644
--- a/compiler/int128.nim
+++ b/compiler/int128.nim
@@ -1,13 +1,16 @@
 ## This module is for compiler internal use only. For reliable error
 ## messages and range checks, the compiler needs a data type that can
-## hold all from ``low(BiggestInt)`` to ``high(BiggestUInt)``, This
+## hold all from `low(BiggestInt)` to `high(BiggestUInt)`, This
 ## type is for that purpose.
 
-from math import trunc
+from std/math import trunc
+
+when defined(nimPreviewSlimSystem):
+  import std/assertions
 
 type
   Int128* = object
-    udata: array[4,uint32]
+    udata: array[4, uint32]
 
 template sdata(arg: Int128, idx: int): int32 =
   # udata and sdata was supposed to be in a union, but unions are
@@ -17,12 +20,12 @@ template sdata(arg: Int128, idx: int): int32 =
 # encoding least significant int first (like LittleEndian)
 
 const
-  Zero* = Int128(udata: [0'u32,0,0,0])
-  One* = Int128(udata: [1'u32,0,0,0])
-  Ten* = Int128(udata: [10'u32,0,0,0])
-  Min = Int128(udata: [0'u32,0,0,0x80000000'u32])
-  Max = Int128(udata: [high(uint32),high(uint32),high(uint32),uint32(high(int32))])
-  NegOne* = Int128(udata: [0xffffffff'u32,0xffffffff'u32,0xffffffff'u32,0xffffffff'u32])
+  Zero* = Int128(udata: [0'u32, 0, 0, 0])
+  One* = Int128(udata: [1'u32, 0, 0, 0])
+  Ten* = Int128(udata: [10'u32, 0, 0, 0])
+  Min = Int128(udata: [0'u32, 0, 0, 0x80000000'u32])
+  Max = Int128(udata: [high(uint32), high(uint32), high(uint32), uint32(high(int32))])
+  NegOne* = Int128(udata: [0xffffffff'u32, 0xffffffff'u32, 0xffffffff'u32, 0xffffffff'u32])
 
 template low*(t: typedesc[Int128]): Int128 = Min
 template high*(t: typedesc[Int128]): Int128 = Max
@@ -30,39 +33,35 @@ template high*(t: typedesc[Int128]): Int128 = Max
 proc `$`*(a: Int128): string
 
 proc toInt128*[T: SomeInteger | bool](arg: T): Int128 =
-  when T is bool: result.sdata(0) = int32(arg)
-  elif T is SomeUnsignedInt:
-    when sizeof(arg) <= 4:
-      result.udata[0] = uint32(arg)
+  {.noSideEffect.}:
+    result = Zero
+    when T is bool: result.sdata(0) = int32(arg)
+    elif T is SomeUnsignedInt:
+      when sizeof(arg) <= 4:
+        result.udata[0] = uint32(arg)
+      else:
+        result.udata[0] = uint32(arg and T(0xffffffff))
+        result.udata[1] = uint32(arg shr 32)
+    elif sizeof(arg) <= 4:
+      result.sdata(0) = int32(arg)
+      if arg < 0: # sign extend
+        result.sdata(1) = -1
+        result.sdata(2) = -1
+        result.sdata(3) = -1
     else:
-      result.udata[0] = uint32(arg and T(0xffffffff))
-      result.udata[1] = uint32(arg shr 32)
-  elif sizeof(arg) <= 4:
-    result.sdata(0) = int32(arg)
-    if arg < 0: # sign extend
-      result.sdata(1) = -1
-      result.sdata(2) = -1
-      result.sdata(3) = -1
-  else:
-    let tmp = int64(arg)
-    result.udata[0] = uint32(tmp and 0xffffffff)
-    result.sdata(1) = int32(tmp shr 32)
-    if arg < 0: # sign extend
-      result.sdata(2) = -1
-      result.sdata(3) = -1
+      let tmp = int64(arg)
+      result.udata[0] = uint32(tmp and 0xffffffff)
+      result.sdata(1) = int32(tmp shr 32)
+      if arg < 0: # sign extend
+        result.sdata(2) = -1
+        result.sdata(3) = -1
 
 template isNegative(arg: Int128): bool =
   arg.sdata(3) < 0
 
-template isNegative(arg: int32): bool =
-  arg < 0
-
-proc bitconcat(a,b: uint32): uint64 =
+proc bitconcat(a, b: uint32): uint64 =
   (uint64(a) shl 32) or uint64(b)
 
-proc bitsplit(a: uint64): (uint32,uint32) =
-  (cast[uint32](a shr 32), cast[uint32](a))
-
 proc toInt64*(arg: Int128): int64 =
   if isNegative(arg):
     assert(arg.sdata(3) == -1, "out of range")
@@ -173,10 +172,10 @@ proc addToHex*(result: var string; arg: Int128) =
     i -= 1
 
 proc toHex*(arg: Int128): string =
+  result = ""
   result.addToHex(arg)
 
 proc inc*(a: var Int128, y: uint32 = 1) =
-  let input = a
   a.udata[0] += y
   if unlikely(a.udata[0] < y):
     a.udata[1].inc
@@ -186,7 +185,7 @@ proc inc*(a: var Int128, y: uint32 = 1) =
         a.udata[3].inc
         doAssert(a.sdata(3) != low(int32), "overflow")
 
-proc cmp*(a,b: Int128): int =
+proc cmp*(a, b: Int128): int =
   let tmp1 = cmp(a.sdata(3), b.sdata(3))
   if tmp1 != 0: return tmp1
   let tmp2 = cmp(a.udata[2], b.udata[2])
@@ -196,50 +195,49 @@ proc cmp*(a,b: Int128): int =
   let tmp4 = cmp(a.udata[0], b.udata[0])
   return tmp4
 
-proc `<`*(a,b: Int128): bool =
-  cmp(a,b) < 0
+proc `<`*(a, b: Int128): bool =
+  cmp(a, b) < 0
 
-proc `<=`*(a,b: Int128): bool =
-  cmp(a,b) <= 0
+proc `<=`*(a, b: Int128): bool =
+  cmp(a, b) <= 0
 
-proc `==`*(a,b: Int128): bool =
+proc `==`*(a, b: Int128): bool =
   if a.udata[0] != b.udata[0]: return false
   if a.udata[1] != b.udata[1]: return false
   if a.udata[2] != b.udata[2]: return false
   if a.udata[3] != b.udata[3]: return false
   return true
 
-proc inplaceBitnot(a: var Int128) =
-  a.udata[0] = not a.udata[0]
-  a.udata[1] = not a.udata[1]
-  a.udata[2] = not a.udata[2]
-  a.udata[3] = not a.udata[3]
-
 proc bitnot*(a: Int128): Int128 =
+  result = Zero
   result.udata[0] = not a.udata[0]
   result.udata[1] = not a.udata[1]
   result.udata[2] = not a.udata[2]
   result.udata[3] = not a.udata[3]
 
-proc bitand*(a,b: Int128): Int128 =
+proc bitand*(a, b: Int128): Int128 =
+  result = Zero
   result.udata[0] = a.udata[0] and b.udata[0]
   result.udata[1] = a.udata[1] and b.udata[1]
   result.udata[2] = a.udata[2] and b.udata[2]
   result.udata[3] = a.udata[3] and b.udata[3]
 
-proc bitor*(a,b: Int128): Int128 =
+proc bitor*(a, b: Int128): Int128 =
+  result = Zero
   result.udata[0] = a.udata[0] or b.udata[0]
   result.udata[1] = a.udata[1] or b.udata[1]
   result.udata[2] = a.udata[2] or b.udata[2]
   result.udata[3] = a.udata[3] or b.udata[3]
 
-proc bitxor*(a,b: Int128): Int128 =
+proc bitxor*(a, b: Int128): Int128 =
+  result = Zero
   result.udata[0] = a.udata[0] xor b.udata[0]
   result.udata[1] = a.udata[1] xor b.udata[1]
   result.udata[2] = a.udata[2] xor b.udata[2]
   result.udata[3] = a.udata[3] xor b.udata[3]
 
 proc `shr`*(a: Int128, b: int): Int128 =
+  result = Zero
   let b = b and 127
   if b < 32:
     result.sdata(3) = a.sdata(3) shr b
@@ -266,6 +264,7 @@ proc `shr`*(a: Int128, b: int): Int128 =
     result.sdata(0) = a.sdata(3) shr (b and 31)
 
 proc `shl`*(a: Int128, b: int): Int128 =
+  result = Zero
   let b = b and 127
   if b < 32:
     result.udata[0] = a.udata[0] shl b
@@ -288,7 +287,8 @@ proc `shl`*(a: Int128, b: int): Int128 =
     result.udata[2] = 0
     result.udata[3] = a.udata[0] shl (b and 31)
 
-proc `+`*(a,b: Int128): Int128 =
+proc `+`*(a, b: Int128): Int128 =
+  result = Zero
   let tmp0 = uint64(a.udata[0]) + uint64(b.udata[0])
   result.udata[0] = cast[uint32](tmp0)
   let tmp1 = uint64(a.udata[1]) + uint64(b.udata[1]) + (tmp0 shr 32)
@@ -305,7 +305,7 @@ proc `-`*(a: Int128): Int128 =
   result = bitnot(a)
   result.inc
 
-proc `-`*(a,b: Int128): Int128 =
+proc `-`*(a, b: Int128): Int128 =
   a + (-b)
 
 proc `-=`*(a: var Int128, b: Int128) =
@@ -321,6 +321,7 @@ proc abs(a: int32): int =
   if a < 0: -a else: a
 
 proc `*`(a: Int128, b: uint32): Int128 =
+  result = Zero
   let tmp0 = uint64(a.udata[0]) * uint64(b)
   let tmp1 = uint64(a.udata[1]) * uint64(b)
   let tmp2 = uint64(a.udata[2]) * uint64(b)
@@ -339,10 +340,11 @@ proc `*`*(a: Int128, b: int32): Int128 =
   if b < 0:
     result = -result
 
-proc `*=`*(a: var Int128, b: int32): Int128 =
-  result = result * b
+proc `*=`(a: var Int128, b: int32) =
+  a = a * b
 
-proc makeInt128(high,low: uint64): Int128 =
+proc makeInt128(high, low: uint64): Int128 =
+  result = Zero
   result.udata[0] = cast[uint32](low)
   result.udata[1] = cast[uint32](low shr 32)
   result.udata[2] = cast[uint32](high)
@@ -354,34 +356,22 @@ proc high64(a: Int128): uint64 =
 proc low64(a: Int128): uint64 =
   bitconcat(a.udata[1], a.udata[0])
 
-proc `*`*(lhs,rhs: Int128): Int128 =
-  let
-    a = cast[uint64](lhs.udata[0])
-    b = cast[uint64](lhs.udata[1])
-    c = cast[uint64](lhs.udata[2])
-    d = cast[uint64](lhs.udata[3])
-
-    e = cast[uint64](rhs.udata[0])
-    f = cast[uint64](rhs.udata[1])
-    g = cast[uint64](rhs.udata[2])
-    h = cast[uint64](rhs.udata[3])
-
-
-  let a32 = cast[uint64](lhs.udata[1])
-  let a00 = cast[uint64](lhs.udata[0])
-  let b32 = cast[uint64](rhs.udata[1])
-  let b00 = cast[uint64](rhs.udata[0])
-
+proc `*`*(lhs, rhs: Int128): Int128 =
+  let a32 = uint64(lhs.udata[1])
+  let a00 = uint64(lhs.udata[0])
+  let b32 = uint64(rhs.udata[1])
+  let b00 = uint64(rhs.udata[0])
   result = makeInt128(high64(lhs) * low64(rhs) + low64(lhs) * high64(rhs) + a32 * b32, a00 * b00)
-  result = result + toInt128(a32 * b00) shl 32
-  result = result + toInt128(a00 * b32) shl 32
+  result += toInt128(a32 * b00) shl 32
+  result += toInt128(a00 * b32) shl 32
 
 proc `*=`*(a: var Int128, b: Int128) =
   a = a * b
 
-import bitops
+import std/bitops
 
 proc fastLog2*(a: Int128): int =
+  result = 0
   if a.udata[3] != 0:
     return 96 + fastLog2(a.udata[3])
   if a.udata[2] != 0:
@@ -389,10 +379,12 @@ proc fastLog2*(a: Int128): int =
   if a.udata[1] != 0:
     return 32 + fastLog2(a.udata[1])
   if a.udata[0] != 0:
-    return      fastLog2(a.udata[0])
+    return fastLog2(a.udata[0])
 
 proc divMod*(dividend, divisor: Int128): tuple[quotient, remainder: Int128] =
   assert(divisor != Zero)
+  result = (Zero, Zero)
+
   let isNegativeA = isNegative(dividend)
   let isNegativeB = isNegative(divisor)
 
@@ -427,7 +419,7 @@ proc divMod*(dividend, divisor: Int128): tuple[quotient, remainder: Int128] =
   for i in 0..shift:
     quotient = quotient shl 1
     if dividend >= denominator:
-      dividend = dividend - denominator
+      dividend -= denominator
       quotient = bitor(quotient, One)
 
     denominator = denominator shr 1
@@ -441,18 +433,18 @@ proc divMod*(dividend, divisor: Int128): tuple[quotient, remainder: Int128] =
   else:
     result.remainder = dividend
 
-proc `div`*(a,b: Int128): Int128 =
-  let (a,b) = divMod(a,b)
+proc `div`*(a, b: Int128): Int128 =
+  let (a, _) = divMod(a, b)
   return a
 
-proc `mod`*(a,b: Int128): Int128 =
-  let (a,b) = divMod(a,b)
+proc `mod`*(a, b: Int128): Int128 =
+  let (_, b) = divMod(a, b)
   return b
 
 proc addInt128*(result: var string; value: Int128) =
   let initialSize = result.len
   if value == Zero:
-    result.add "0"
+    result.add '0'
   elif value == low(Int128):
     result.add "-170141183460469231731687303715884105728"
   else:
@@ -473,11 +465,13 @@ proc addInt128*(result: var string; value: Int128) =
       j -= 1
 
 proc `$`*(a: Int128): string =
+  # "-170141183460469231731687303715884105728".len == 41
+  result = newStringOfCap(41)
   result.addInt128(a)
 
 proc parseDecimalInt128*(arg: string, pos: int = 0): Int128 =
   assert(pos < arg.len)
-  assert(arg[pos] in {'-','0'..'9'})
+  assert(arg[pos] in {'-', '0'..'9'})
 
   var isNegative = false
   var pos = pos
@@ -497,13 +491,13 @@ proc parseDecimalInt128*(arg: string, pos: int = 0): Int128 =
 # fluff
 
 proc `<`*(a: Int128, b: BiggestInt): bool =
-  cmp(a,toInt128(b)) < 0
+  cmp(a, toInt128(b)) < 0
 
 proc `<`*(a: BiggestInt, b: Int128): bool =
   cmp(toInt128(a), b) < 0
 
 proc `<=`*(a: Int128, b: BiggestInt): bool =
-  cmp(a,toInt128(b)) <= 0
+  cmp(a, toInt128(b)) <= 0
 
 proc `<=`*(a: BiggestInt, b: Int128): bool =
   cmp(toInt128(a), b) <= 0
@@ -539,7 +533,7 @@ proc toFloat64*(arg: Int128): float64 =
 
 proc ldexp(x: float64, exp: cint): float64 {.importc: "ldexp", header: "<math.h>".}
 
-template bitor(a,b,c: Int128): Int128 = bitor(bitor(a,b), c)
+template bitor(a, b, c: Int128): Int128 = bitor(bitor(a, b), c)
 
 proc toInt128*(arg: float64): Int128 =
   let isNegative = arg < 0
@@ -557,24 +551,28 @@ proc toInt128*(arg: float64): Int128 =
     return res
 
 proc maskUInt64*(arg: Int128): Int128 {.noinit, inline.} =
+  result = Zero
   result.udata[0] = arg.udata[0]
   result.udata[1] = arg.udata[1]
   result.udata[2] = 0
   result.udata[3] = 0
 
 proc maskUInt32*(arg: Int128): Int128 {.noinit, inline.} =
+  result = Zero
   result.udata[0] = arg.udata[0]
   result.udata[1] = 0
   result.udata[2] = 0
   result.udata[3] = 0
 
 proc maskUInt16*(arg: Int128): Int128 {.noinit, inline.} =
+  result = Zero
   result.udata[0] = arg.udata[0] and 0xffff
   result.udata[1] = 0
   result.udata[2] = 0
   result.udata[3] = 0
 
 proc maskUInt8*(arg: Int128): Int128 {.noinit, inline.} =
+  result = Zero
   result.udata[0] = arg.udata[0] and 0xff
   result.udata[1] = 0
   result.udata[2] = 0
@@ -591,191 +589,4 @@ proc maskBytes*(arg: Int128, numbytes: int): Int128 {.noinit.} =
   of 8:
     return maskUInt64(arg)
   else:
-    assert(false, "masking only implemented for 1, 2, 4 and 8 bytes")
-
-
-
-
-when isMainModule:
-  let (a,b) = divMod(Ten,Ten)
-
-  doAssert $One == "1"
-  doAssert $Ten == "10"
-  doAssert $Zero == "0"
-  let c = parseDecimalInt128("12345678989876543210123456789")
-  doAssert $c == "12345678989876543210123456789"
-
-  var d : array[39, Int128]
-  d[0] =  parseDecimalInt128("1")
-  d[1] =  parseDecimalInt128("10")
-  d[2] =  parseDecimalInt128("100")
-  d[3] =  parseDecimalInt128("1000")
-  d[4] =  parseDecimalInt128("10000")
-  d[5] =  parseDecimalInt128("100000")
-  d[6] =  parseDecimalInt128("1000000")
-  d[7] =  parseDecimalInt128("10000000")
-  d[8] =  parseDecimalInt128("100000000")
-  d[9] =  parseDecimalInt128("1000000000")
-  d[10] = parseDecimalInt128("10000000000")
-  d[11] = parseDecimalInt128("100000000000")
-  d[12] = parseDecimalInt128("1000000000000")
-  d[13] = parseDecimalInt128("10000000000000")
-  d[14] = parseDecimalInt128("100000000000000")
-  d[15] = parseDecimalInt128("1000000000000000")
-  d[16] = parseDecimalInt128("10000000000000000")
-  d[17] = parseDecimalInt128("100000000000000000")
-  d[18] = parseDecimalInt128("1000000000000000000")
-  d[19] = parseDecimalInt128("10000000000000000000")
-  d[20] = parseDecimalInt128("100000000000000000000")
-  d[21] = parseDecimalInt128("1000000000000000000000")
-  d[22] = parseDecimalInt128("10000000000000000000000")
-  d[23] = parseDecimalInt128("100000000000000000000000")
-  d[24] = parseDecimalInt128("1000000000000000000000000")
-  d[25] = parseDecimalInt128("10000000000000000000000000")
-  d[26] = parseDecimalInt128("100000000000000000000000000")
-  d[27] = parseDecimalInt128("1000000000000000000000000000")
-  d[28] = parseDecimalInt128("10000000000000000000000000000")
-  d[29] = parseDecimalInt128("100000000000000000000000000000")
-  d[30] = parseDecimalInt128("1000000000000000000000000000000")
-  d[31] = parseDecimalInt128("10000000000000000000000000000000")
-  d[32] = parseDecimalInt128("100000000000000000000000000000000")
-  d[33] = parseDecimalInt128("1000000000000000000000000000000000")
-  d[34] = parseDecimalInt128("10000000000000000000000000000000000")
-  d[35] = parseDecimalInt128("100000000000000000000000000000000000")
-  d[36] = parseDecimalInt128("1000000000000000000000000000000000000")
-  d[37] = parseDecimalInt128("10000000000000000000000000000000000000")
-  d[38] = parseDecimalInt128("100000000000000000000000000000000000000")
-
-  for i in 0..<d.len:
-    for j in 0..<d.len:
-      doAssert(cmp(d[i], d[j]) == cmp(i,j))
-      if i + j < d.len:
-        doAssert d[i] * d[j] == d[i+j]
-      if i - j >= 0:
-        doAssert d[i] div d[j] == d[i-j]
-
-  var sum: Int128
-
-  for it in d:
-    sum += it
-
-  doAssert $sum == "111111111111111111111111111111111111111"
-
-  for it in d.mitems:
-    it = -it
-
-  for i in 0..<d.len:
-    for j in 0..<d.len:
-      doAssert(cmp(d[i], d[j]) == -cmp(i,j))
-      if i + j < d.len:
-        doAssert d[i] * d[j] == -d[i+j]
-      if i - j >= 0:
-        doAssert d[i] div d[j] == -d[i-j]
-
-  doAssert $high(Int128) == "170141183460469231731687303715884105727"
-  doAssert $low(Int128) == "-170141183460469231731687303715884105728"
-
-  var ma = 100'i64
-  var mb = 13
-
-  doAssert toInt128(ma) * toInt128(0) == toInt128(0)
-  doAssert toInt128(-ma) * toInt128(0) == toInt128(0)
-
-  # sign correctness
-  doAssert divMod(toInt128( ma),toInt128( mb)) == (toInt128( ma div  mb), toInt128( ma mod  mb))
-  doAssert divMod(toInt128(-ma),toInt128( mb)) == (toInt128(-ma div  mb), toInt128(-ma mod  mb))
-  doAssert divMod(toInt128( ma),toInt128(-mb)) == (toInt128( ma div -mb), toInt128( ma mod -mb))
-  doAssert divMod(toInt128(-ma),toInt128(-mb)) == (toInt128(-ma div -mb), toInt128(-ma mod -mb))
-
-  doAssert divMod(toInt128( mb),toInt128( mb)) == (toInt128( mb div  mb), toInt128( mb mod  mb))
-  doAssert divMod(toInt128(-mb),toInt128( mb)) == (toInt128(-mb div  mb), toInt128(-mb mod  mb))
-  doAssert divMod(toInt128( mb),toInt128(-mb)) == (toInt128( mb div -mb), toInt128( mb mod -mb))
-  doAssert divMod(toInt128(-mb),toInt128(-mb)) == (toInt128(-mb div -mb), toInt128(-mb mod -mb))
-
-  doAssert divMod(toInt128( mb),toInt128( ma)) == (toInt128( mb div  ma), toInt128( mb mod  ma))
-  doAssert divMod(toInt128(-mb),toInt128( ma)) == (toInt128(-mb div  ma), toInt128(-mb mod  ma))
-  doAssert divMod(toInt128( mb),toInt128(-ma)) == (toInt128( mb div -ma), toInt128( mb mod -ma))
-  doAssert divMod(toInt128(-mb),toInt128(-ma)) == (toInt128(-mb div -ma), toInt128(-mb mod -ma))
-
-  let e = parseDecimalInt128("70997106675279150998592376708984375")
-
-  let strArray = [
-    # toHex(e shr 0), toHex(e shr 1), toHex(e shr 2), toHex(e shr 3)
-    "000dac6d782d266a37300c32591eee37", "0006d636bc1693351b9806192c8f771b", "00036b1b5e0b499a8dcc030c9647bb8d", "0001b58daf05a4cd46e601864b23ddc6",
-    "0000dac6d782d266a37300c32591eee3", "00006d636bc1693351b9806192c8f771", "000036b1b5e0b499a8dcc030c9647bb8", "00001b58daf05a4cd46e601864b23ddc",
-    "00000dac6d782d266a37300c32591eee", "000006d636bc1693351b9806192c8f77", "0000036b1b5e0b499a8dcc030c9647bb", "000001b58daf05a4cd46e601864b23dd",
-    "000000dac6d782d266a37300c32591ee", "0000006d636bc1693351b9806192c8f7", "00000036b1b5e0b499a8dcc030c9647b", "0000001b58daf05a4cd46e601864b23d",
-    "0000000dac6d782d266a37300c32591e", "00000006d636bc1693351b9806192c8f", "000000036b1b5e0b499a8dcc030c9647", "00000001b58daf05a4cd46e601864b23",
-    "00000000dac6d782d266a37300c32591", "000000006d636bc1693351b9806192c8", "0000000036b1b5e0b499a8dcc030c964", "000000001b58daf05a4cd46e601864b2",
-    "000000000dac6d782d266a37300c3259", "0000000006d636bc1693351b9806192c", "00000000036b1b5e0b499a8dcc030c96", "0000000001b58daf05a4cd46e601864b",
-    "0000000000dac6d782d266a37300c325", "00000000006d636bc1693351b9806192", "000000000036b1b5e0b499a8dcc030c9", "00000000001b58daf05a4cd46e601864",
-    "00000000000dac6d782d266a37300c32", "000000000006d636bc1693351b980619", "0000000000036b1b5e0b499a8dcc030c", "000000000001b58daf05a4cd46e60186",
-    "000000000000dac6d782d266a37300c3", "0000000000006d636bc1693351b98061", "00000000000036b1b5e0b499a8dcc030", "0000000000001b58daf05a4cd46e6018",
-    "0000000000000dac6d782d266a37300c", "00000000000006d636bc1693351b9806", "000000000000036b1b5e0b499a8dcc03", "00000000000001b58daf05a4cd46e601",
-    "00000000000000dac6d782d266a37300", "000000000000006d636bc1693351b980", "0000000000000036b1b5e0b499a8dcc0", "000000000000001b58daf05a4cd46e60",
-    "000000000000000dac6d782d266a3730", "0000000000000006d636bc1693351b98", "00000000000000036b1b5e0b499a8dcc", "0000000000000001b58daf05a4cd46e6",
-    "0000000000000000dac6d782d266a373", "00000000000000006d636bc1693351b9", "000000000000000036b1b5e0b499a8dc", "00000000000000001b58daf05a4cd46e",
-    "00000000000000000dac6d782d266a37", "000000000000000006d636bc1693351b", "0000000000000000036b1b5e0b499a8d", "000000000000000001b58daf05a4cd46",
-    "000000000000000000dac6d782d266a3", "0000000000000000006d636bc1693351", "00000000000000000036b1b5e0b499a8", "0000000000000000001b58daf05a4cd4",
-    "0000000000000000000dac6d782d266a", "00000000000000000006d636bc169335", "000000000000000000036b1b5e0b499a", "00000000000000000001b58daf05a4cd",
-    "00000000000000000000dac6d782d266", "000000000000000000006d636bc16933", "0000000000000000000036b1b5e0b499", "000000000000000000001b58daf05a4c",
-    "000000000000000000000dac6d782d26", "0000000000000000000006d636bc1693", "00000000000000000000036b1b5e0b49", "0000000000000000000001b58daf05a4",
-    "0000000000000000000000dac6d782d2", "00000000000000000000006d636bc169", "000000000000000000000036b1b5e0b4", "00000000000000000000001b58daf05a",
-    "00000000000000000000000dac6d782d", "000000000000000000000006d636bc16", "0000000000000000000000036b1b5e0b", "000000000000000000000001b58daf05",
-    "000000000000000000000000dac6d782", "0000000000000000000000006d636bc1", "00000000000000000000000036b1b5e0", "0000000000000000000000001b58daf0",
-    "0000000000000000000000000dac6d78", "00000000000000000000000006d636bc", "000000000000000000000000036b1b5e", "00000000000000000000000001b58daf",
-    "00000000000000000000000000dac6d7", "000000000000000000000000006d636b", "0000000000000000000000000036b1b5", "000000000000000000000000001b58da",
-    "000000000000000000000000000dac6d", "0000000000000000000000000006d636", "00000000000000000000000000036b1b", "0000000000000000000000000001b58d",
-    "0000000000000000000000000000dac6", "00000000000000000000000000006d63", "000000000000000000000000000036b1", "00000000000000000000000000001b58",
-    "00000000000000000000000000000dac", "000000000000000000000000000006d6", "0000000000000000000000000000036b", "000000000000000000000000000001b5",
-    "000000000000000000000000000000da", "0000000000000000000000000000006d", "00000000000000000000000000000036", "0000000000000000000000000000001b",
-    "0000000000000000000000000000000d", "00000000000000000000000000000006", "00000000000000000000000000000003", "00000000000000000000000000000001",
-    "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000",
-    "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000",
-    "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000",
-  ]
-
-  for i in 0 ..< 128:
-    let str1 = toHex(e shr i)
-    let str2 = strArray[i]
-    doAssert str1 == str2
-
-  let strArray2 = [
-    "000dac6d782d266a37300c32591eee37", "001b58daf05a4cd46e601864b23ddc6e", "0036b1b5e0b499a8dcc030c9647bb8dc", "006d636bc1693351b9806192c8f771b8",
-    "00dac6d782d266a37300c32591eee370", "01b58daf05a4cd46e601864b23ddc6e0", "036b1b5e0b499a8dcc030c9647bb8dc0", "06d636bc1693351b9806192c8f771b80",
-    "0dac6d782d266a37300c32591eee3700", "1b58daf05a4cd46e601864b23ddc6e00", "36b1b5e0b499a8dcc030c9647bb8dc00", "6d636bc1693351b9806192c8f771b800",
-    "dac6d782d266a37300c32591eee37000", "b58daf05a4cd46e601864b23ddc6e000", "6b1b5e0b499a8dcc030c9647bb8dc000", "d636bc1693351b9806192c8f771b8000",
-    "ac6d782d266a37300c32591eee370000", "58daf05a4cd46e601864b23ddc6e0000", "b1b5e0b499a8dcc030c9647bb8dc0000", "636bc1693351b9806192c8f771b80000",
-    "c6d782d266a37300c32591eee3700000", "8daf05a4cd46e601864b23ddc6e00000", "1b5e0b499a8dcc030c9647bb8dc00000", "36bc1693351b9806192c8f771b800000",
-    "6d782d266a37300c32591eee37000000", "daf05a4cd46e601864b23ddc6e000000", "b5e0b499a8dcc030c9647bb8dc000000", "6bc1693351b9806192c8f771b8000000",
-    "d782d266a37300c32591eee370000000", "af05a4cd46e601864b23ddc6e0000000", "5e0b499a8dcc030c9647bb8dc0000000", "bc1693351b9806192c8f771b80000000",
-    "782d266a37300c32591eee3700000000", "f05a4cd46e601864b23ddc6e00000000", "e0b499a8dcc030c9647bb8dc00000000", "c1693351b9806192c8f771b800000000",
-    "82d266a37300c32591eee37000000000", "05a4cd46e601864b23ddc6e000000000", "0b499a8dcc030c9647bb8dc000000000", "1693351b9806192c8f771b8000000000",
-    "2d266a37300c32591eee370000000000", "5a4cd46e601864b23ddc6e0000000000", "b499a8dcc030c9647bb8dc0000000000", "693351b9806192c8f771b80000000000",
-    "d266a37300c32591eee3700000000000", "a4cd46e601864b23ddc6e00000000000", "499a8dcc030c9647bb8dc00000000000", "93351b9806192c8f771b800000000000",
-    "266a37300c32591eee37000000000000", "4cd46e601864b23ddc6e000000000000", "99a8dcc030c9647bb8dc000000000000", "3351b9806192c8f771b8000000000000",
-    "66a37300c32591eee370000000000000", "cd46e601864b23ddc6e0000000000000", "9a8dcc030c9647bb8dc0000000000000", "351b9806192c8f771b80000000000000",
-    "6a37300c32591eee3700000000000000", "d46e601864b23ddc6e00000000000000", "a8dcc030c9647bb8dc00000000000000", "51b9806192c8f771b800000000000000",
-    "a37300c32591eee37000000000000000", "46e601864b23ddc6e000000000000000", "8dcc030c9647bb8dc000000000000000", "1b9806192c8f771b8000000000000000",
-    "37300c32591eee370000000000000000", "6e601864b23ddc6e0000000000000000", "dcc030c9647bb8dc0000000000000000", "b9806192c8f771b80000000000000000",
-    "7300c32591eee3700000000000000000", "e601864b23ddc6e00000000000000000", "cc030c9647bb8dc00000000000000000", "9806192c8f771b800000000000000000",
-    "300c32591eee37000000000000000000", "601864b23ddc6e000000000000000000", "c030c9647bb8dc000000000000000000", "806192c8f771b8000000000000000000",
-    "00c32591eee370000000000000000000", "01864b23ddc6e0000000000000000000", "030c9647bb8dc0000000000000000000", "06192c8f771b80000000000000000000",
-    "0c32591eee3700000000000000000000", "1864b23ddc6e00000000000000000000", "30c9647bb8dc00000000000000000000", "6192c8f771b800000000000000000000",
-    "c32591eee37000000000000000000000", "864b23ddc6e000000000000000000000", "0c9647bb8dc000000000000000000000", "192c8f771b8000000000000000000000",
-    "32591eee370000000000000000000000", "64b23ddc6e0000000000000000000000", "c9647bb8dc0000000000000000000000", "92c8f771b80000000000000000000000",
-    "2591eee3700000000000000000000000", "4b23ddc6e00000000000000000000000", "9647bb8dc00000000000000000000000", "2c8f771b800000000000000000000000",
-    "591eee37000000000000000000000000", "b23ddc6e000000000000000000000000", "647bb8dc000000000000000000000000", "c8f771b8000000000000000000000000",
-    "91eee370000000000000000000000000", "23ddc6e0000000000000000000000000", "47bb8dc0000000000000000000000000", "8f771b80000000000000000000000000",
-    "1eee3700000000000000000000000000", "3ddc6e00000000000000000000000000", "7bb8dc00000000000000000000000000", "f771b800000000000000000000000000",
-    "eee37000000000000000000000000000", "ddc6e000000000000000000000000000", "bb8dc000000000000000000000000000", "771b8000000000000000000000000000",
-    "ee370000000000000000000000000000", "dc6e0000000000000000000000000000", "b8dc0000000000000000000000000000", "71b80000000000000000000000000000",
-    "e3700000000000000000000000000000", "c6e00000000000000000000000000000", "8dc00000000000000000000000000000", "1b800000000000000000000000000000",
-    "37000000000000000000000000000000", "6e000000000000000000000000000000", "dc000000000000000000000000000000", "b8000000000000000000000000000000",
-    "70000000000000000000000000000000", "e0000000000000000000000000000000", "c0000000000000000000000000000000", "80000000000000000000000000000000",
-  ]
-
-  for i in 0 ..< 128:
-    let str1 = toHex(e shl i)
-    let str2 = strArray2[i]
-    doAssert str1 == str2
+    raiseAssert "masking only implemented for 1, 2, 4 and 8 bytes"