Change the test flag from mpint_test to stint_test

This commit is contained in:
mratsim 2018-10-06 12:18:03 +02:00 committed by tersec
parent 7591373f15
commit 7fa6329d4c
4 changed files with 7 additions and 14 deletions

View File

@ -17,14 +17,14 @@ proc test(name: string, lang: string = "c") =
setCommand lang, "tests/" & name & ".nim"
task test_internal_debug, "Run tests for internal procs - test implementation (StUint[64] = 2x uint32":
switch("define", "mpint_test")
switch("define", "stint_test")
test "internal"
task test_internal_release, "Run tests for internal procs - prod implementation (StUint[64] = uint64":
test "internal"
task test_debug, "Run all tests - test implementation (StUint[64] = 2x uint32":
switch("define", "mpint_test")
switch("define", "stint_test")
test "all_tests"
task test_release, "Run all tests - prod implementation (StUint[64] = uint64":
@ -32,12 +32,12 @@ task test_release, "Run all tests - prod implementation (StUint[64] = uint64":
task test_property_debug, "Run random tests (debug mode) - test implementation (StUint[64] = 2x uint32)":
requires "https://github.com/alehander42/nim-quicktest >= 0.18.0"
switch("define", "mpint_test")
switch("define", "stint_test")
test "property_based"
task test_property_release, "Run random tests (release mode) - test implementation (StUint[64] = 2x uint32)":
requires "https://github.com/alehander42/nim-quicktest >= 0.18.0"
switch("define", "mpint_test")
switch("define", "stint_test")
switch("define", "release")
test "property_based"

View File

@ -36,7 +36,6 @@ func toUint*(n: SomeUnsignedInt): SomeUnsignedInt {.inline.}=
func asDoubleUint*(n: BaseUint): auto {.inline.} =
## Convert an integer or StUint to an uint with double the size
type Double = (
when n.sizeof == 4: uint64
elif n.sizeof == 2: uint32

View File

@ -10,10 +10,9 @@
# TODO: test if GCC/Clang support uint128 natively
import macros
# The macro uintImpl must be exported
when defined(mpint_test):
when defined(stint_test):
macro uintImpl*(bits: static[int]): untyped =
# Test version, StUint[64] = 2 uint32. Test the logic of the library
assert (bits and (bits-1)) == 0, $bits & " is not a power of 2"
@ -34,7 +33,7 @@ when defined(mpint_test):
macro intImpl*(bits: static[int]): untyped =
# Test version, StInt[64] = 2 uint32. Test the logic of the library
# Note that ints are implemented in terms of unsigned ints
# Signed operatiosn will be built on top of that.
# Signed operations will be built on top of that.
assert (bits and (bits-1)) == 0, $bits & " is not a power of 2"
assert bits >= 16, "The number of bits in a should be greater or equal to 16"
@ -90,9 +89,7 @@ else:
error "Fatal: unreachable"
proc getSize*(x: NimNode): static[int] =
# Size of doesn't always work at compile-time, pending PR https://github.com/nim-lang/Nim/pull/5664
# Default Nim's `sizeof` doesn't always work at compile-time, pending PR https://github.com/nim-lang/Nim/pull/5664
var multiplier = 1
var node = x.getTypeInst
@ -137,7 +134,6 @@ type
lo*, hi*: BaseUint
else:
hi*, lo*: BaseUint
# ### Private ### #
StUint*[bits: static[int]] = object

View File

@ -19,7 +19,6 @@ func `+`*(x, y: UintImpl): UintImpl {.inline.}
func `+=`*(x: var UintImpl, y: UintImpl) {.inline.}=
## In-place addition for multi-precision unsigned int
type SubTy = type x.lo
x.lo += y.lo
x.hi += (x.lo < y.lo).toSubtype(SubTy) + y.hi # This helps the compiler produce ADC (add with carry)
@ -31,7 +30,6 @@ func `+`*(x, y: UintImpl): UintImpl {.inline.}=
func `-`*(x, y: UintImpl): UintImpl {.inline.}=
# Substraction for multi-precision unsigned int
type SubTy = type x.lo
result.lo = x.lo - y.lo
result.hi = x.hi - y.hi - (x.lo < y.lo).toSubtype(SubTy) # This might (?) help the compiler produce SBB (sub with borrow)