remove pre-Nim 1.2 support (#127)
This commit is contained in:
parent
94fc521ee0
commit
86621eced1
|
@ -7,7 +7,7 @@ skipDirs = @["tests", "benchmarks"]
|
|||
### Dependencies
|
||||
|
||||
# TODO test only requirements don't work: https://github.com/nim-lang/nimble/issues/482
|
||||
requires "nim >= 0.19",
|
||||
requires "nim >= 1.2.0",
|
||||
"stew"
|
||||
#, "https://github.com/alehander42/nim-quicktest >= 0.18.0", "https://github.com/status-im/nim-ttmath"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Stint
|
||||
# Copyright 2018 Status Research & Development GmbH
|
||||
# Copyright 2018-2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
#
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -127,15 +127,7 @@ func `xor`*(x, y: SomeBigInteger): SomeBigInteger {.inline.}=
|
|||
result.data = x.data xor y.data
|
||||
|
||||
func `shr`*(x: SomeBigInteger, y: SomeInteger): SomeBigInteger {.inline.} =
|
||||
when x.data is SomeSignedInt:
|
||||
when (NimMajor, NimMinor, NimPatch) >= (0, 20, 0):
|
||||
result.data = x.data shr y
|
||||
elif (NimMajor, NimMinor, NimPatch) < (0, 20, 0) and defined(nimAshr):
|
||||
result.data = ashr(x.data, y)
|
||||
else:
|
||||
{.error: "arithmetic right shift is not defined for this Nim version".}
|
||||
else:
|
||||
result.data = x.data shr y
|
||||
result.data = x.data shr y
|
||||
|
||||
func `shl`*(x: SomeBigInteger, y: SomeInteger): SomeBigInteger {.inline.} =
|
||||
result.data = x.data shl y
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Stint
|
||||
# Copyright 2018 Status Research & Development GmbH
|
||||
# Copyright 2018-2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
#
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -66,15 +66,7 @@ template createShr(name, operator: untyped) =
|
|||
result.lo = convert[LoType](name(x.hi, (y - halfSize)))
|
||||
result.hi = name(x.hi, halfSize-1)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (0, 20, 0):
|
||||
createShr(shrOfShr, `shr`)
|
||||
elif (NimMajor, NimMinor, NimPatch) < (0, 20, 0) and defined(nimAshr):
|
||||
createShr(shrOfAshr, ashr)
|
||||
else:
|
||||
{.error: "arithmetic right shift is not defined for this Nim version".}
|
||||
createShr(shrOfShr, `shr`)
|
||||
|
||||
template `shr`*(a, b: typed): untyped =
|
||||
when (NimMajor, NimMinor, NimPatch) >= (0, 20, 0):
|
||||
shrOfShr(a, b)
|
||||
elif (NimMajor, NimMinor, NimPatch) < (0, 20, 0) and defined(nimAshr):
|
||||
shrOfAShr(a, b)
|
||||
shrOfShr(a, b)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Stint
|
||||
# Copyright 2018 Status Research & Development GmbH
|
||||
# Copyright 2018-2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
#
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -170,15 +170,13 @@ template testIO(chk, tst: untyped) =
|
|||
nativeStuint(chk, low(uint32), 64)
|
||||
nativeStuint(chk, high(int32), 64)
|
||||
nativeStuint(chk, 0'u64, 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint64), 64)
|
||||
nativeStuint(chk, low(uint64), 64)
|
||||
nativeStuint(chk, high(uint64), 64)
|
||||
nativeStuint(chk, low(uint64), 64)
|
||||
nativeStuint(chk, high(int64), 64)
|
||||
|
||||
when sizeof(uint) == 4:
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint), 32)
|
||||
nativeStuint(chk, low(uint), 32)
|
||||
nativeStuint(chk, high(uint), 32)
|
||||
nativeStuint(chk, low(uint), 32)
|
||||
nativeStuint(chk, high(int), 32)
|
||||
else:
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
|
@ -200,9 +198,8 @@ template testIO(chk, tst: untyped) =
|
|||
nativeStuint(chk, low(uint32), 128)
|
||||
nativeStuint(chk, high(int32), 128)
|
||||
nativeStuint(chk, 0'u64, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint64), 128)
|
||||
nativeStuint(chk, low(uint64), 128)
|
||||
nativeStuint(chk, high(uint64), 128)
|
||||
nativeStuint(chk, low(uint64), 128)
|
||||
nativeStuint(chk, high(int64), 128)
|
||||
|
||||
tst "[stint] Creation from native ints":
|
||||
|
@ -252,19 +249,16 @@ template testIO(chk, tst: untyped) =
|
|||
nativeStint(chk, 0'u64, 64)
|
||||
nativeStint(chk, high(int64), 64)
|
||||
nativeStint(chk, low(int64), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint64), 64)
|
||||
nativeStint(chk, low(uint64), 64)
|
||||
|
||||
when sizeof(uint) == 4:
|
||||
nativeStint(chk, high(int), 32)
|
||||
nativeStint(chk, low(int), 32)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint), 32)
|
||||
nativeStint(chk, low(uint), 32)
|
||||
else:
|
||||
nativeStint(chk, high(int), 64)
|
||||
nativeStint(chk, low(int), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint), 64)
|
||||
nativeStint(chk, low(uint), 64)
|
||||
|
||||
nativeStint(chk, 0, 128)
|
||||
nativeStint(chk, 0'u8, 128)
|
||||
|
@ -278,8 +272,7 @@ template testIO(chk, tst: untyped) =
|
|||
nativeStint(chk, low(uint32), 128)
|
||||
nativeStint(chk, 0'u64, 128)
|
||||
nativeStint(chk, high(int64), 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint64), 128)
|
||||
nativeStint(chk, low(uint64), 128)
|
||||
|
||||
# TODO: bug #92
|
||||
#nativeStint(chk, low(int8), 128)
|
||||
|
@ -383,9 +376,8 @@ template testIO(chk, tst: untyped) =
|
|||
chkTruncateStuint(chk, high(int32), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int32), int64, 64)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int64), int64, 64)
|
||||
|
||||
|
@ -434,9 +426,8 @@ template testIO(chk, tst: untyped) =
|
|||
chkTruncateStuint(chk, high(int32), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int32), int64, 128)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int64), int64, 128)
|
||||
|
||||
|
@ -555,8 +546,7 @@ template testIO(chk, tst: untyped) =
|
|||
chkTruncateStint(chk, high(int32), int64, 64)
|
||||
chkTruncateStint(chk, low(int32), uint64, "0xFFFFFFFF80000000", 64)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStint(chk, low(int64), int64, 64)
|
||||
chkTruncateStint(chk, high(int64), uint64, 64)
|
||||
chkTruncateStint(chk, high(int64), int64, 64)
|
||||
|
@ -616,8 +606,7 @@ template testIO(chk, tst: untyped) =
|
|||
chkTruncateStint(chk, high(int32), int64, 128)
|
||||
#chkTruncateStint(chk, low(int32), uint64, "0xFFFFFFFF80000000", 128) # TODO: bug #92
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStint(chk, low(uint64), uint64, 128)
|
||||
chkTruncateStint(chk, low(uint64), uint64, 128)
|
||||
#chkTruncateStint(chk, low(int64), int64, 128) # TODO: bug #92
|
||||
chkTruncateStint(chk, high(int64), uint64, 128)
|
||||
chkTruncateStint(chk, high(int64), int64, 128)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Stint
|
||||
# Copyright 2018 Status Research & Development GmbH
|
||||
# Copyright 2018-2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
#
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -60,9 +60,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkAddition(chk, low(uint16), 17'u16, low(uint16) + 17'u16, 64)
|
||||
chkAddition(chk, high(uint32) - 17'u32, 17'u32, high(uint32), 64)
|
||||
chkAddition(chk, low(uint32), 17'u32, low(uint32) + 17'u32, 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 64)
|
||||
chkAddition(chk, low(uint64), 17'u64, low(uint64) + 17'u64, 64)
|
||||
chkAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 64)
|
||||
chkAddition(chk, low(uint64), 17'u64, low(uint64) + 17'u64, 64)
|
||||
|
||||
chkAddition(chk, 0'u8, 0'u8, 0'u8, 128)
|
||||
chkAddition(chk, high(uint8) - 17'u8, 17'u8, high(uint8), 128)
|
||||
|
@ -71,9 +70,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkAddition(chk, low(uint16), 17'u16, low(uint16) + 17'u16, 128)
|
||||
chkAddition(chk, high(uint32) - 17'u32, 17'u32, high(uint32), 128)
|
||||
chkAddition(chk, low(uint32), 17'u32, low(uint32) + 17'u32, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 128)
|
||||
chkAddition(chk, low(uint64), 17'u64, low(uint64) + 17'u64, 128)
|
||||
chkAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 128)
|
||||
chkAddition(chk, low(uint64), 17'u64, low(uint64) + 17'u64, 128)
|
||||
|
||||
tst "inplace addition":
|
||||
chkInplaceAddition(chk, 0'u8, 0'u8, 0'u8, 8)
|
||||
|
@ -101,9 +99,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkInplaceAddition(chk, low(uint16) + 17'u16, 17'u16, low(uint16) + 34'u16, 64)
|
||||
chkInplaceAddition(chk, high(uint32) - 17'u32, 17'u32, high(uint32), 64)
|
||||
chkInplaceAddition(chk, low(uint32) + 17'u32, 17'u32, low(uint32) + 34'u32, 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkInplaceAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 64)
|
||||
chkInplaceAddition(chk, low(uint64) + 17'u64, 17'u64, low(uint64) + 34'u64, 64)
|
||||
chkInplaceAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 64)
|
||||
chkInplaceAddition(chk, low(uint64) + 17'u64, 17'u64, low(uint64) + 34'u64, 64)
|
||||
|
||||
chkInplaceAddition(chk, 0'u8, 0'u8, 0'u8, 128)
|
||||
chkInplaceAddition(chk, high(uint8) - 17'u8, 17'u8, high(uint8), 128)
|
||||
|
@ -112,9 +109,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkInplaceAddition(chk, low(uint16) + 17'u16, 17'u16, low(uint16) + 34'u16, 128)
|
||||
chkInplaceAddition(chk, high(uint32) - 17'u32, 17'u32, high(uint32), 128)
|
||||
chkInplaceAddition(chk, low(uint32) + 17'u32, 17'u32, low(uint32) + 34'u32, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkInplaceAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 128)
|
||||
chkInplaceAddition(chk, low(uint64) + 17'u64, 17'u64, low(uint64) + 34'u64, 128)
|
||||
chkInplaceAddition(chk, high(uint64) - 17'u64, 17'u64, high(uint64), 128)
|
||||
chkInplaceAddition(chk, low(uint64) + 17'u64, 17'u64, low(uint64) + 34'u64, 128)
|
||||
|
||||
tst "substraction":
|
||||
chkSubstraction(chk, 0'u8, 0'u8, 0'u8, 8)
|
||||
|
@ -142,9 +138,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkSubstraction(chk, low(uint16) + 17'u16, 17'u16, low(uint16), 64)
|
||||
chkSubstraction(chk, high(uint32) - 17'u32, 17'u32, high(uint32) - 34'u32, 64)
|
||||
chkSubstraction(chk, low(uint32) + 17'u32, 17'u32, low(uint32), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 64)
|
||||
chkSubstraction(chk, low(uint64) + 17'u64, 17'u64, low(uint64), 64)
|
||||
chkSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 64)
|
||||
chkSubstraction(chk, low(uint64) + 17'u64, 17'u64, low(uint64), 64)
|
||||
|
||||
chkSubstraction(chk, 0'u8, 0'u8, 0'u8, 128)
|
||||
chkSubstraction(chk, high(uint8) - 17'u8, 17'u8, high(uint8) - 34'u8, 128)
|
||||
|
@ -153,9 +148,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkSubstraction(chk, high(uint16), high(uint16), 0'u16, 128)
|
||||
chkSubstraction(chk, high(uint32) - 17'u32, 17'u32, high(uint32) - 34'u32, 128)
|
||||
chkSubstraction(chk, high(uint32), high(uint32), 0'u32, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 128)
|
||||
chkSubstraction(chk, high(uint64), high(uint64), 0'u64, 128)
|
||||
chkSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 128)
|
||||
chkSubstraction(chk, high(uint64), high(uint64), 0'u64, 128)
|
||||
|
||||
tst "inplace substraction":
|
||||
chkInplaceSubstraction(chk, 0'u8, 0'u8, 0'u8, 8)
|
||||
|
@ -183,9 +177,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkInplaceSubstraction(chk, low(uint16) + 17'u16, 17'u16, low(uint16), 64)
|
||||
chkInplaceSubstraction(chk, high(uint32) - 17'u32, 17'u32, high(uint32) - 34'u32, 64)
|
||||
chkInplaceSubstraction(chk, low(uint32) + 17'u32, 17'u32, low(uint32), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkInplaceSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 64)
|
||||
chkInplaceSubstraction(chk, low(uint64) + 17'u64, 17'u64, low(uint64), 64)
|
||||
chkInplaceSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 64)
|
||||
chkInplaceSubstraction(chk, low(uint64) + 17'u64, 17'u64, low(uint64), 64)
|
||||
|
||||
chkInplaceSubstraction(chk, 0'u8, 0'u8, 0'u8, 128)
|
||||
chkInplaceSubstraction(chk, high(uint8) - 17'u8, 17'u8, high(uint8) - 34'u8, 128)
|
||||
|
@ -194,9 +187,8 @@ template testAddSub(chk, tst: untyped) =
|
|||
chkInplaceSubstraction(chk, high(uint16), high(uint16), 0'u16, 128)
|
||||
chkInplaceSubstraction(chk, high(uint32) - 17'u32, 17'u32, high(uint32) - 34'u32, 128)
|
||||
chkInplaceSubstraction(chk, high(uint32), high(uint32), 0'u32, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkInplaceSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 128)
|
||||
chkInplaceSubstraction(chk, high(uint64), high(uint64), 0'u64, 128)
|
||||
chkInplaceSubstraction(chk, high(uint64) - 17'u64, 17'u64, high(uint64) - 34'u64, 128)
|
||||
chkInplaceSubstraction(chk, high(uint64), high(uint64), 0'u64, 128)
|
||||
|
||||
static:
|
||||
testAddSub(ctCheck, ctTest)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Stint
|
||||
# Copyright 2018 Status Research & Development GmbH
|
||||
# Copyright 2018-2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
#
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -83,8 +83,7 @@ template testBitwise(chk, tst: untyped) =
|
|||
chkNot(chk, high(uint8), not uint64(high(uint8)), 64)
|
||||
chkNot(chk, high(uint16), not uint64(high(uint16)), 64)
|
||||
chkNot(chk, high(uint32), not uint64(high(uint32)), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkNot(chk, high(uint64), not high(uint64), 64)
|
||||
chkNot(chk, high(uint64), not high(uint64), 64)
|
||||
|
||||
chkNot(chk, "0", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 128)
|
||||
chkNot(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "0", 128)
|
||||
|
|
Loading…
Reference in New Issue