From f18a958d5e9462da6658db2ef4a3e89321333cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Sat, 8 Feb 2020 13:28:43 +0100 Subject: [PATCH] Support 1.0+ int128 (can't use magic for bitnot) --- constantine/word_types.nim | 6 +++++- tests/test_word_types.nim | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/constantine/word_types.nim b/constantine/word_types.nim index f05cab4..e889a45 100644 --- a/constantine/word_types.nim +++ b/constantine/word_types.nim @@ -68,7 +68,11 @@ func high*(T: typedesc[Ct]): T {.inline.}= func `and`*[T: Ct](x, y: T): T {.magic: "BitandI".} func `or`*[T: Ct](x, y: T): T {.magic: "BitorI".} func `xor`*[T: Ct](x, y: T): T {.magic: "BitxorI".} -func `not`*[T: Ct](x: T): T {.magic: "BitnotI".} +# func `not`*[T: Ct](x: T): T {.magic: "BitnotI".} # int128 changes broke the magic +template `not`*[T: Ct](x: T): T = + # Note: T.T is Ct.T is the conversion to the base type + T(not T.T(x)) + func `+`*[T: Ct](x, y: T): T {.magic: "AddU".} func `+=`*[T: Ct](x: var T, y: T): T {.magic: "Inc".} func `-`*[T: Ct](x, y: T): T {.magic: "SubU".} diff --git a/tests/test_word_types.nim b/tests/test_word_types.nim index d59ee60..65af987 100644 --- a/tests/test_word_types.nim +++ b/tests/test_word_types.nim @@ -19,11 +19,11 @@ suite "Constant-time unsigned integers": test "High - getting the biggest representable number": check: high(Ct[byte]).undistinct == 0xFF.byte - high(Ct[uint8]).undistinct == 0xFF.uint8 + high(Ct[uint8]).undistinct == 0xFF'u8 - high(Ct[uint16]).undistinct == 0xFFFF.uint16 - high(Ct[uint32]).undistinct == 0xFFFFFFFF.uint32 - high(Ct[uint64]).undistinct == 0xFFFFFFFF_FFFFFFFF.uint64 + high(Ct[uint16]).undistinct == 0xFFFF'u16 + high(Ct[uint32]).undistinct == 0xFFFFFFFF'u32 + high(Ct[uint64]).undistinct == 0xFFFFFFFF_FFFFFFFF'u64 test "bitwise `and`, `or`, `xor`, `not`": let x1 = rand(high(int)).uint64