Add 8192-bit overloads
This commit is contained in:
parent
023007b2ef
commit
308ed51d59
|
@ -8,7 +8,8 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import ./private/datatypes, macros
|
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 =
|
template make_unary(op, ResultTy): untyped =
|
||||||
func `op`*(x: Stint): ResultTy {.inline.} =
|
func `op`*(x: Stint): ResultTy {.inline.} =
|
||||||
|
|
|
@ -92,12 +92,15 @@
|
||||||
# to explore creating an object pool to reuse the memory buffers.
|
# to explore creating an object pool to reuse the memory buffers.
|
||||||
|
|
||||||
template checkDiv2(bits: static[int]): untyped =
|
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:
|
static:
|
||||||
doAssert (bits and (bits-1)) == 0, $bits & " is not a power of 2"
|
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"
|
doAssert bits >= 8, "The number of bits in a should be greater or equal to 8"
|
||||||
bits div 2
|
bits div 2
|
||||||
|
|
||||||
when defined(mpint_test):
|
when defined(mpint_test): # TODO stint_test
|
||||||
template uintImpl*(bits: static[int]): untyped =
|
template uintImpl*(bits: static[int]): untyped =
|
||||||
# Test version, StUint[64] = 2 uint32. Test the logic of the library
|
# 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 =
|
template bitsof*(x: UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[UintImpl[SomeInteger]]]]]]]): untyped =
|
||||||
# Uint4096 - modExp in Nimbus
|
# Uint4096 - modExp in Nimbus
|
||||||
2 * bitsof(x.lo)
|
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 =
|
template applyHiLo*(a: UintImpl | IntImpl, c: untyped): untyped =
|
||||||
## Apply `c` to each of `hi` and `lo`
|
## Apply `c` to each of `hi` and `lo`
|
||||||
|
|
Loading…
Reference in New Issue