diff --git a/stint/int_public.nim b/stint/int_public.nim index f058e45..684ef77 100644 --- a/stint/int_public.nim +++ b/stint/int_public.nim @@ -8,7 +8,8 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import ./private/datatypes, macros -export StInt, IntImpl, intImpl # TODO remove the need to export intImpl and this macro +export StInt +export IntImpl, intImpl # TODO remove the need to export these template make_unary(op, ResultTy): untyped = func `op`*(x: Stint): ResultTy {.inline.} = diff --git a/stint/private/datatypes.nim b/stint/private/datatypes.nim index f6c29e4..f46fa8b 100644 --- a/stint/private/datatypes.nim +++ b/stint/private/datatypes.nim @@ -92,12 +92,15 @@ # to explore creating an object pool to reuse the memory buffers. template checkDiv2(bits: static[int]): untyped = + # TODO: There is no need to check if power of 2 at each uintImpl instantiation, it slows compilation. + # However we easily get into nested templates instantiation if we use another + # template that first checks power-of-two and then calls the recursive uintImpl static: doAssert (bits and (bits-1)) == 0, $bits & " is not a power of 2" doAssert bits >= 8, "The number of bits in a should be greater or equal to 8" bits div 2 -when defined(mpint_test): +when defined(mpint_test): # TODO stint_test template uintImpl*(bits: static[int]): untyped = # Test version, StUint[64] = 2 uint32. Test the logic of the library @@ -183,6 +186,12 @@ template bitsof*(x: UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[SomeIn template bitsof*(x: UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[SomeInteger]]]]]]]): untyped = # Uint4096 - modExp in Nimbus 2 * bitsof(x.lo) +template bitsof*(x: UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[SomeInteger]]]]]]]]): untyped = + # Uint8192 - modExp in Nimbus + 2 * bitsof(x.lo) + +template bitsof*(x: IntImpl): untyped = + 2 * bitsof(x.lo) template applyHiLo*(a: UintImpl | IntImpl, c: untyped): untyped = ## Apply `c` to each of `hi` and `lo`