Support 1.0+ int128 (can't use magic for bitnot)
This commit is contained in:
parent
8229bf384b
commit
f18a958d5e
|
@ -68,7 +68,11 @@ func high*(T: typedesc[Ct]): T {.inline.}=
|
||||||
func `and`*[T: Ct](x, y: T): T {.magic: "BitandI".}
|
func `and`*[T: Ct](x, y: T): T {.magic: "BitandI".}
|
||||||
func `or`*[T: Ct](x, y: T): T {.magic: "BitorI".}
|
func `or`*[T: Ct](x, y: T): T {.magic: "BitorI".}
|
||||||
func `xor`*[T: Ct](x, y: T): T {.magic: "BitxorI".}
|
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, y: T): T {.magic: "AddU".}
|
||||||
func `+=`*[T: Ct](x: var T, y: T): T {.magic: "Inc".}
|
func `+=`*[T: Ct](x: var T, y: T): T {.magic: "Inc".}
|
||||||
func `-`*[T: Ct](x, y: T): T {.magic: "SubU".}
|
func `-`*[T: Ct](x, y: T): T {.magic: "SubU".}
|
||||||
|
|
|
@ -19,11 +19,11 @@ suite "Constant-time unsigned integers":
|
||||||
test "High - getting the biggest representable number":
|
test "High - getting the biggest representable number":
|
||||||
check:
|
check:
|
||||||
high(Ct[byte]).undistinct == 0xFF.byte
|
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[uint16]).undistinct == 0xFFFF'u16
|
||||||
high(Ct[uint32]).undistinct == 0xFFFFFFFF.uint32
|
high(Ct[uint32]).undistinct == 0xFFFFFFFF'u32
|
||||||
high(Ct[uint64]).undistinct == 0xFFFFFFFF_FFFFFFFF.uint64
|
high(Ct[uint64]).undistinct == 0xFFFFFFFF_FFFFFFFF'u64
|
||||||
|
|
||||||
test "bitwise `and`, `or`, `xor`, `not`":
|
test "bitwise `and`, `or`, `xor`, `not`":
|
||||||
let x1 = rand(high(int)).uint64
|
let x1 = rand(high(int)).uint64
|
||||||
|
|
Loading…
Reference in New Issue