Remove the fooPragma placeholder (for noinit)
This commit is contained in:
parent
0dae6897b1
commit
1ff544eabf
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./private/datatypes, macros
|
import ./private/datatypes, macros
|
||||||
export StInt, IntImpl, intImpl # TODO remove the need to export intImpl and this macro
|
export StInt, IntImpl, intImpl # TODO remove the need to export intImpl and this macro
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ type
|
||||||
Int256* = Stint[256]
|
Int256* = Stint[256]
|
||||||
|
|
||||||
template make_conv(conv_name: untyped, size: int): untyped =
|
template make_conv(conv_name: untyped, size: int): untyped =
|
||||||
func `convname`*(n: SomeInteger): Stint[size] {.inline, fooPragma.}=
|
func `convname`*(n: SomeInteger): Stint[size] {.inline.}=
|
||||||
n.stint(size)
|
n.stint(size)
|
||||||
|
|
||||||
make_conv(i128, 128)
|
make_conv(i128, 128)
|
||||||
make_conv(i256, 256)
|
make_conv(i256, 256)
|
||||||
|
|
||||||
template make_unary(op, ResultTy): untyped =
|
template make_unary(op, ResultTy): untyped =
|
||||||
func `op`*(x: Stint): ResultTy {.fooPragma, inline.} =
|
func `op`*(x: Stint): ResultTy {.inline.} =
|
||||||
when ResultTy is Stint:
|
when ResultTy is Stint:
|
||||||
result.data = op(x.data)
|
result.data = op(x.data)
|
||||||
else:
|
else:
|
||||||
|
@ -30,7 +30,7 @@ template make_unary(op, ResultTy): untyped =
|
||||||
export op
|
export op
|
||||||
|
|
||||||
template make_binary(op, ResultTy): untyped =
|
template make_binary(op, ResultTy): untyped =
|
||||||
func `op`*(x, y: Stint): ResultTy {.fooPragma, inline.} =
|
func `op`*(x, y: Stint): ResultTy {.inline.} =
|
||||||
when ResultTy is Stint:
|
when ResultTy is Stint:
|
||||||
result.data = op(x.data, y.data)
|
result.data = op(x.data, y.data)
|
||||||
else:
|
else:
|
||||||
|
@ -60,7 +60,7 @@ import ./private/int_div
|
||||||
|
|
||||||
make_binary(`div`, Stint)
|
make_binary(`div`, Stint)
|
||||||
make_binary(`mod`, Stint)
|
make_binary(`mod`, Stint)
|
||||||
func divmod*(x, y: Stint): tuple[quot, rem: Stint] {.fooPragma, inline.} =
|
func divmod*(x, y: Stint): tuple[quot, rem: Stint] {.inline.} =
|
||||||
(result.quot.data, result.rem.data) = divmod(x.data, y.data)
|
(result.quot.data, result.rem.data) = divmod(x.data, y.data)
|
||||||
|
|
||||||
import ./private/int_comparison
|
import ./private/int_comparison
|
||||||
|
@ -77,9 +77,9 @@ make_unary(`not`, Stint)
|
||||||
make_binary(`or`, Stint)
|
make_binary(`or`, Stint)
|
||||||
make_binary(`and`, Stint)
|
make_binary(`and`, Stint)
|
||||||
make_binary(`xor`, Stint)
|
make_binary(`xor`, Stint)
|
||||||
# proc `shr`*(x: Stint, y: SomeInteger): Stint {.fooPragma, inline, noSideEffect.} =
|
# proc `shr`*(x: Stint, y: SomeInteger): Stint {.inline, noSideEffect.} =
|
||||||
# result.data = x.data shr y
|
# result.data = x.data shr y
|
||||||
# proc `shl`*(x: Stint, y: SomeInteger): Stint {.fooPragma, inline, noSideEffect.} =
|
# proc `shl`*(x: Stint, y: SomeInteger): Stint {.inline, noSideEffect.} =
|
||||||
# result.data = x.data shl y
|
# result.data = x.data shl y
|
||||||
|
|
||||||
import ./private/int_highlow
|
import ./private/int_highlow
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import
|
import
|
||||||
./private/datatypes,
|
./private/datatypes,
|
||||||
./private/int_negabs,
|
./private/int_negabs,
|
||||||
|
@ -176,7 +176,7 @@ func parse*[bits: static[int]](T: typedesc[Stint[bits]], input: string, base: st
|
||||||
else:
|
else:
|
||||||
result = cast[Stint[bits]](no_overflow)
|
result = cast[Stint[bits]](no_overflow)
|
||||||
|
|
||||||
func parse*[bits: static[int]](T: typedesc[Stint[bits]|Stuint[bits]], input: string): T {.inline, fooPragma.}=
|
func parse*[bits: static[int]](T: typedesc[Stint[bits]|Stuint[bits]], input: string): T {.inline.}=
|
||||||
## Parse a string and store the result in a Stint[bits] or Stuint[bits].
|
## Parse a string and store the result in a Stint[bits] or Stuint[bits].
|
||||||
## Input is considered a decimal string.
|
## Input is considered a decimal string.
|
||||||
# TODO: Have a default static argument in the previous proc. Currently we get
|
# TODO: Have a default static argument in the previous proc. Currently we get
|
||||||
|
@ -237,7 +237,7 @@ func toString*[bits: static[int]](num: Stint[bits], base: static[int]): string =
|
||||||
|
|
||||||
reverse(result)
|
reverse(result)
|
||||||
|
|
||||||
func toString*[bits: static[int]](num: Stint[bits] or StUint[bits]): string {.inline, fooPragma.}=
|
func toString*[bits: static[int]](num: Stint[bits] or StUint[bits]): string {.inline.}=
|
||||||
## Convert to a string.
|
## Convert to a string.
|
||||||
## Output is considered a decimal string.
|
## Output is considered a decimal string.
|
||||||
#
|
#
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./conversion, ./as_signed_words
|
import ./datatypes, ./conversion, ./as_signed_words
|
||||||
|
|
||||||
func `+`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}=
|
func `+`*(x, y: IntImpl): IntImpl {.inline.}=
|
||||||
# Addition for multi-precision signed int.
|
# Addition for multi-precision signed int.
|
||||||
type SubTy = type x.lo
|
type SubTy = type x.lo
|
||||||
result.lo = x.lo + y.lo
|
result.lo = x.lo + y.lo
|
||||||
|
@ -27,7 +27,7 @@ func `+=`*(x: var IntImpl, y: IntImpl) {.inline.}=
|
||||||
## In-place addition for multi-precision signed int.
|
## In-place addition for multi-precision signed int.
|
||||||
x = x + y
|
x = x + y
|
||||||
|
|
||||||
func `-`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}=
|
func `-`*(x, y: IntImpl): IntImpl {.inline.}=
|
||||||
# Substraction for multi-precision signed int.
|
# Substraction for multi-precision signed int.
|
||||||
|
|
||||||
type SubTy = type x.lo
|
type SubTy = type x.lo
|
||||||
|
|
|
@ -6,26 +6,25 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./as_words
|
import ./datatypes, ./as_words
|
||||||
|
|
||||||
|
func `not`*(x: IntImpl): IntImpl {.inline.}=
|
||||||
func `not`*(x: IntImpl): IntImpl {.fooPragma, inline.}=
|
|
||||||
## Bitwise complement of unsigned integer x
|
## Bitwise complement of unsigned integer x
|
||||||
m_asWordsZip(result, x, ignoreEndianness = true):
|
m_asWordsZip(result, x, ignoreEndianness = true):
|
||||||
result = not x
|
result = not x
|
||||||
|
|
||||||
func `or`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}=
|
func `or`*(x, y: IntImpl): IntImpl {.inline.}=
|
||||||
## `Bitwise or` of numbers x and y
|
## `Bitwise or` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x or y
|
result = x or y
|
||||||
|
|
||||||
func `and`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}=
|
func `and`*(x, y: IntImpl): IntImpl {.inline.}=
|
||||||
## `Bitwise and` of numbers x and y
|
## `Bitwise and` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x and y
|
result = x and y
|
||||||
|
|
||||||
func `xor`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}=
|
func `xor`*(x, y: IntImpl): IntImpl {.inline.}=
|
||||||
## `Bitwise xor` of numbers x and y
|
## `Bitwise xor` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x xor y
|
result = x xor y
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison
|
import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison
|
||||||
|
|
||||||
# Here are the expected signs for division/modulo by opposite signs and both negative numbers
|
# Here are the expected signs for division/modulo by opposite signs and both negative numbers
|
||||||
|
@ -32,11 +32,11 @@ import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison
|
||||||
# echo "-10 mod -3: " & $(-10 mod -3) # -1
|
# echo "-10 mod -3: " & $(-10 mod -3) # -1
|
||||||
# echo '\n'
|
# echo '\n'
|
||||||
|
|
||||||
func divmod*(x, y: SomeSignedInt): tuple[quot, rem: SomeSignedInt] {.fooPragma, inline.}=
|
func divmod*(x, y: SomeSignedInt): tuple[quot, rem: SomeSignedInt] {.inline.}=
|
||||||
# hopefully the compiler fuse that in a single op
|
# hopefully the compiler fuse that in a single op
|
||||||
(x div y, x mod y)
|
(x div y, x mod y)
|
||||||
|
|
||||||
proc divmod*[T](x, y: IntImpl[T]): tuple[quot, rem: IntImpl[T]] {.fooPragma.}=
|
proc divmod*[T](x, y: IntImpl[T]): tuple[quot, rem: IntImpl[T]] =
|
||||||
## Divmod operation for multi-precision signed integer
|
## Divmod operation for multi-precision signed integer
|
||||||
|
|
||||||
result = cast[type result](divmod(
|
result = cast[type result](divmod(
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./uint_bitwise_ops, ./int_bitwise_ops, ./initialization
|
import ./datatypes, ./uint_bitwise_ops, ./int_bitwise_ops, ./initialization
|
||||||
|
|
||||||
func high*[T](_: typedesc[IntImpl[T]]): IntImpl[T] {.inline, fooPragma.}=
|
func high*[T](_: typedesc[IntImpl[T]]): IntImpl[T] {.inline.}=
|
||||||
|
|
||||||
# The lowest signed int has representation
|
# The lowest signed int has representation
|
||||||
# 0b0111_1111_1111_1111 ....
|
# 0b0111_1111_1111_1111 ....
|
||||||
|
@ -17,7 +17,7 @@ func high*[T](_: typedesc[IntImpl[T]]): IntImpl[T] {.inline, fooPragma.}=
|
||||||
let only_msb_set = UintImpl[T].zero.not shr 1
|
let only_msb_set = UintImpl[T].zero.not shr 1
|
||||||
result = cast[IntImpl[T]](only_msb_set)
|
result = cast[IntImpl[T]](only_msb_set)
|
||||||
|
|
||||||
func low*[T](_: typedesc[IntImpl[T]]): IntImpl[T] {.inline, fooPragma.}=
|
func low*[T](_: typedesc[IntImpl[T]]): IntImpl[T] {.inline.}=
|
||||||
|
|
||||||
# The lowest signed int has representation
|
# The lowest signed int has representation
|
||||||
# 0b1000_0000_0000_0000 ....
|
# 0b1000_0000_0000_0000 ....
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./uint_mul
|
import ./datatypes, ./uint_mul
|
||||||
|
|
||||||
func `*`*[T](x, y: IntImpl[T]): IntImpl[T] {.inline, fooPragma.}=
|
func `*`*[T](x, y: IntImpl[T]): IntImpl[T] {.inline.}=
|
||||||
## Multiplication for multi-precision signed integers
|
## Multiplication for multi-precision signed integers
|
||||||
# For 2-complement representation this is the exact same
|
# For 2-complement representation this is the exact same
|
||||||
# as unsigned multiplication. We don't need to deal with the sign
|
# as unsigned multiplication. We don't need to deal with the sign
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import
|
import
|
||||||
./datatypes,
|
./datatypes,
|
||||||
./initialization, ./int_highlow,
|
./initialization, ./int_highlow,
|
||||||
./int_addsub, ./int_comparison
|
./int_addsub, ./int_comparison
|
||||||
|
|
||||||
func `-`*[T: IntImpl](x: T): T {.fooPragma, inline.}=
|
func `-`*[T: IntImpl](x: T): T {.inline.}=
|
||||||
# Negate a multi-precision signed int.
|
# Negate a multi-precision signed int.
|
||||||
|
|
||||||
when compileOption("boundChecks"):
|
when compileOption("boundChecks"):
|
||||||
|
@ -22,7 +22,7 @@ func `-`*[T: IntImpl](x: T): T {.fooPragma, inline.}=
|
||||||
result = not x
|
result = not x
|
||||||
result += one(T)
|
result += one(T)
|
||||||
|
|
||||||
func abs*[T: IntImpl](x: T): T {.fooPragma, inline.}=
|
func abs*[T: IntImpl](x: T): T {.inline.}=
|
||||||
## Returns the absolute value of a signed int.
|
## Returns the absolute value of a signed int.
|
||||||
|
|
||||||
result = if x.isNegative: -x
|
result = if x.isNegative: -x
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./bithacks, ./conversion, ./initialization,
|
import ./bithacks, ./conversion, ./initialization,
|
||||||
./datatypes,
|
./datatypes,
|
||||||
./uint_comparison,
|
./uint_comparison,
|
||||||
|
@ -21,12 +21,12 @@ proc `+=`*(x: var UintImpl, y: UintImpl) {.noSideEffect, inline.}=
|
||||||
x.lo += y.lo
|
x.lo += y.lo
|
||||||
x.hi += (x.lo < y.lo).toSubtype(SubTy) + y.hi
|
x.hi += (x.lo < y.lo).toSubtype(SubTy) + y.hi
|
||||||
|
|
||||||
proc `+`*(x, y: UintImpl): UintImpl {.noSideEffect, fooPragma, inline.}=
|
proc `+`*(x, y: UintImpl): UintImpl {.noSideEffect, inline.}=
|
||||||
# Addition for multi-precision unsigned int
|
# Addition for multi-precision unsigned int
|
||||||
result = x
|
result = x
|
||||||
result += y
|
result += y
|
||||||
|
|
||||||
proc `-`*(x, y: UintImpl): UintImpl {.noSideEffect, fooPragma, inline.}=
|
proc `-`*(x, y: UintImpl): UintImpl {.noSideEffect, inline.}=
|
||||||
# Substraction for multi-precision unsigned int
|
# Substraction for multi-precision unsigned int
|
||||||
|
|
||||||
type SubTy = type x.lo
|
type SubTy = type x.lo
|
||||||
|
|
|
@ -6,26 +6,26 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./datatypes, ./as_words
|
import ./datatypes, ./as_words
|
||||||
|
|
||||||
|
|
||||||
func `not`*(x: UintImpl): UintImpl {.fooPragma, inline.}=
|
func `not`*(x: UintImpl): UintImpl {.inline.}=
|
||||||
## Bitwise complement of unsigned integer x
|
## Bitwise complement of unsigned integer x
|
||||||
m_asWordsZip(result, x, ignoreEndianness = true):
|
m_asWordsZip(result, x, ignoreEndianness = true):
|
||||||
result = not x
|
result = not x
|
||||||
|
|
||||||
func `or`*(x, y: UintImpl): UintImpl {.fooPragma, inline.}=
|
func `or`*(x, y: UintImpl): UintImpl {.inline.}=
|
||||||
## `Bitwise or` of numbers x and y
|
## `Bitwise or` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x or y
|
result = x or y
|
||||||
|
|
||||||
func `and`*(x, y: UintImpl): UintImpl {.fooPragma, inline.}=
|
func `and`*(x, y: UintImpl): UintImpl {.inline.}=
|
||||||
## `Bitwise and` of numbers x and y
|
## `Bitwise and` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x and y
|
result = x and y
|
||||||
|
|
||||||
func `xor`*(x, y: UintImpl): UintImpl {.fooPragma, inline.}=
|
func `xor`*(x, y: UintImpl): UintImpl {.inline.}=
|
||||||
## `Bitwise xor` of numbers x and y
|
## `Bitwise xor` of numbers x and y
|
||||||
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
m_asWordsZip(result, x, y, ignoreEndianness = true):
|
||||||
result = x xor y
|
result = x xor y
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import ./bithacks, ./conversion, ./initialization,
|
import ./bithacks, ./conversion, ./initialization,
|
||||||
./datatypes,
|
./datatypes,
|
||||||
./uint_comparison,
|
./uint_comparison,
|
||||||
|
@ -48,7 +48,7 @@ func div2n1n[T: SomeunsignedInt](q, r: var T, n_hi, n_lo, d: T)
|
||||||
func div2n1n(q, r: var UintImpl, ah, al, b: UintImpl)
|
func div2n1n(q, r: var UintImpl, ah, al, b: UintImpl)
|
||||||
# Forward declaration
|
# Forward declaration
|
||||||
|
|
||||||
func divmod*(x, y: SomeUnsignedInt): tuple[quot, rem: SomeUnsignedInt] {.fooPragma, inline.}=
|
func divmod*(x, y: SomeUnsignedInt): tuple[quot, rem: SomeUnsignedInt] {.inline.}=
|
||||||
# hopefully the compiler fuse that in a single op
|
# hopefully the compiler fuse that in a single op
|
||||||
(x div y, x mod y)
|
(x div y, x mod y)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
import ./datatypes, ./initialization
|
import ./datatypes, ./initialization
|
||||||
|
|
||||||
func low*(T: typedesc[UintImpl]): T {.inline, fooPragma.}=
|
func low*(T: typedesc[UintImpl]): T {.inline.}=
|
||||||
zero(T)
|
zero(T)
|
||||||
|
|
||||||
func high*(T: typedesc[UintImpl]): T {.inline, fooPragma.}=
|
func high*(T: typedesc[UintImpl]): T {.inline.}=
|
||||||
not zero(T)
|
not zero(T)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
{.pragma: fooPragma.}
|
|
||||||
import macros,
|
import macros,
|
||||||
./conversion,
|
./conversion,
|
||||||
./initialization,
|
./initialization,
|
||||||
|
@ -142,7 +142,7 @@ func extPrecMul*[T](result: var UintImpl[UintImpl[T]], u, v: UintImpl[T]) =
|
||||||
## Extended precision multiplication
|
## Extended precision multiplication
|
||||||
extPrecMulImpl(result, `=`, u, v)
|
extPrecMulImpl(result, `=`, u, v)
|
||||||
|
|
||||||
func `*`*[T](x, y: UintImpl[T]): UintImpl[T] {.inline, fooPragma.}=
|
func `*`*[T](x, y: UintImpl[T]): UintImpl[T] {.inline.}=
|
||||||
## Multiplication for multi-precision unsigned uint
|
## Multiplication for multi-precision unsigned uint
|
||||||
#
|
#
|
||||||
# For our representation, it is similar to school grade multiplication
|
# For our representation, it is similar to school grade multiplication
|
||||||
|
|
|
@ -9,20 +9,20 @@
|
||||||
|
|
||||||
import ./private/datatypes, macros
|
import ./private/datatypes, macros
|
||||||
export StUint, UintImpl, uintImpl # TODO remove the need to export UintImpl and this macro
|
export StUint, UintImpl, uintImpl # TODO remove the need to export UintImpl and this macro
|
||||||
{.pragma: fooPragma.}
|
|
||||||
type
|
type
|
||||||
UInt128* = StUint[128]
|
UInt128* = StUint[128]
|
||||||
UInt256* = StUint[256]
|
UInt256* = StUint[256]
|
||||||
|
|
||||||
template make_conv(conv_name: untyped, size: int): untyped =
|
template make_conv(conv_name: untyped, size: int): untyped =
|
||||||
func `convname`*(n: SomeInteger): StUint[size] {.inline, fooPragma.}=
|
func `convname`*(n: SomeInteger): StUint[size] {.inline.}=
|
||||||
n.stuint(size)
|
n.stuint(size)
|
||||||
|
|
||||||
make_conv(u128, 128)
|
make_conv(u128, 128)
|
||||||
make_conv(u256, 256)
|
make_conv(u256, 256)
|
||||||
|
|
||||||
template make_unary(op, ResultTy): untyped =
|
template make_unary(op, ResultTy): untyped =
|
||||||
func `op`*(x: StUint): ResultTy {.fooPragma, inline.} =
|
func `op`*(x: StUint): ResultTy {.inline.} =
|
||||||
when ResultTy is StUint:
|
when ResultTy is StUint:
|
||||||
result.data = op(x.data)
|
result.data = op(x.data)
|
||||||
else:
|
else:
|
||||||
|
@ -30,7 +30,7 @@ template make_unary(op, ResultTy): untyped =
|
||||||
export op
|
export op
|
||||||
|
|
||||||
template make_binary(op, ResultTy): untyped =
|
template make_binary(op, ResultTy): untyped =
|
||||||
func `op`*(x, y: StUint): ResultTy {.fooPragma, inline.} =
|
func `op`*(x, y: StUint): ResultTy {.inline.} =
|
||||||
when ResultTy is StUint:
|
when ResultTy is StUint:
|
||||||
result.data = op(x.data, y.data)
|
result.data = op(x.data, y.data)
|
||||||
else:
|
else:
|
||||||
|
@ -56,7 +56,7 @@ import ./private/uint_div
|
||||||
|
|
||||||
make_binary(`div`, StUint)
|
make_binary(`div`, StUint)
|
||||||
make_binary(`mod`, StUint)
|
make_binary(`mod`, StUint)
|
||||||
func divmod*(x, y: StUint): tuple[quot, rem: StUint] {.fooPragma, inline.} =
|
func divmod*(x, y: StUint): tuple[quot, rem: StUint] {.inline.} =
|
||||||
(result.quot.data, result.rem.data) = divmod(x.data, y.data)
|
(result.quot.data, result.rem.data) = divmod(x.data, y.data)
|
||||||
|
|
||||||
import ./private/uint_comparison
|
import ./private/uint_comparison
|
||||||
|
@ -72,9 +72,9 @@ make_unary(`not`, StUint)
|
||||||
make_binary(`or`, StUint)
|
make_binary(`or`, StUint)
|
||||||
make_binary(`and`, StUint)
|
make_binary(`and`, StUint)
|
||||||
make_binary(`xor`, StUint)
|
make_binary(`xor`, StUint)
|
||||||
proc `shr`*(x: StUint, y: SomeInteger): StUint {.fooPragma, inline, noSideEffect.} =
|
proc `shr`*(x: StUint, y: SomeInteger): StUint {.inline, noSideEffect.} =
|
||||||
result.data = x.data shr y
|
result.data = x.data shr y
|
||||||
proc `shl`*(x: StUint, y: SomeInteger): StUint {.fooPragma, inline, noSideEffect.} =
|
proc `shl`*(x: StUint, y: SomeInteger): StUint {.inline, noSideEffect.} =
|
||||||
result.data = x.data shl y
|
result.data = x.data shl y
|
||||||
|
|
||||||
import ./private/uint_highlow
|
import ./private/uint_highlow
|
||||||
|
|
Loading…
Reference in New Issue