diff --git a/src/int_public.nim b/src/int_public.nim index e433887..25c901c 100644 --- a/src/int_public.nim +++ b/src/int_public.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import ./private/datatypes, macros export StInt, IntImpl, intImpl # TODO remove the need to export intImpl and this macro @@ -15,14 +15,14 @@ type Int256* = Stint[256] 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) make_conv(i128, 128) make_conv(i256, 256) template make_unary(op, ResultTy): untyped = - func `op`*(x: Stint): ResultTy {.fooPragma, inline.} = + func `op`*(x: Stint): ResultTy {.inline.} = when ResultTy is Stint: result.data = op(x.data) else: @@ -30,7 +30,7 @@ template make_unary(op, ResultTy): untyped = export op 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: result.data = op(x.data, y.data) else: @@ -60,7 +60,7 @@ import ./private/int_div make_binary(`div`, 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) import ./private/int_comparison @@ -77,9 +77,9 @@ make_unary(`not`, Stint) make_binary(`or`, Stint) make_binary(`and`, 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 -# 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 import ./private/int_highlow diff --git a/src/io.nim b/src/io.nim index bfd9f8c..dbc3cd3 100644 --- a/src/io.nim +++ b/src/io.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import ./private/datatypes, ./private/int_negabs, @@ -176,7 +176,7 @@ func parse*[bits: static[int]](T: typedesc[Stint[bits]], input: string, base: st else: 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]. ## Input is considered a decimal string. # 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) -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. ## Output is considered a decimal string. # diff --git a/src/private/int_addsub.nim b/src/private/int_addsub.nim index 3780cfe..4a0df5b 100644 --- a/src/private/int_addsub.nim +++ b/src/private/int_addsub.nim @@ -6,10 +6,10 @@ # * 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. -{.pragma: fooPragma.} + 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. type SubTy = type x.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. x = x + y -func `-`*(x, y: IntImpl): IntImpl {.fooPragma, inline.}= +func `-`*(x, y: IntImpl): IntImpl {.inline.}= # Substraction for multi-precision signed int. type SubTy = type x.lo diff --git a/src/private/int_bitwise_ops.nim b/src/private/int_bitwise_ops.nim index 127dd74..8fd047e 100644 --- a/src/private/int_bitwise_ops.nim +++ b/src/private/int_bitwise_ops.nim @@ -6,26 +6,25 @@ # * 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. -{.pragma: fooPragma.} + import ./datatypes, ./as_words - -func `not`*(x: IntImpl): IntImpl {.fooPragma, inline.}= +func `not`*(x: IntImpl): IntImpl {.inline.}= ## Bitwise complement of unsigned integer x m_asWordsZip(result, x, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): result = x xor y diff --git a/src/private/int_div.nim b/src/private/int_div.nim index bfc175e..fe0f5d0 100644 --- a/src/private/int_div.nim +++ b/src/private/int_div.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison # 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 '\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 (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 result = cast[type result](divmod( diff --git a/src/private/int_highlow.nim b/src/private/int_highlow.nim index 9d64159..ff32d98 100644 --- a/src/private/int_highlow.nim +++ b/src/private/int_highlow.nim @@ -6,10 +6,10 @@ # * 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. -{.pragma: fooPragma.} + 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 # 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 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 # 0b1000_0000_0000_0000 .... diff --git a/src/private/int_mul.nim b/src/private/int_mul.nim index d15dbe5..4265f7c 100644 --- a/src/private/int_mul.nim +++ b/src/private/int_mul.nim @@ -6,10 +6,10 @@ # * 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. -{.pragma: fooPragma.} + 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 # For 2-complement representation this is the exact same # as unsigned multiplication. We don't need to deal with the sign diff --git a/src/private/int_negabs.nim b/src/private/int_negabs.nim index 1c12480..027a211 100644 --- a/src/private/int_negabs.nim +++ b/src/private/int_negabs.nim @@ -6,13 +6,13 @@ # * 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. -{.pragma: fooPragma.} + import ./datatypes, ./initialization, ./int_highlow, ./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. when compileOption("boundChecks"): @@ -22,7 +22,7 @@ func `-`*[T: IntImpl](x: T): T {.fooPragma, inline.}= result = not x 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. result = if x.isNegative: -x diff --git a/src/private/uint_addsub.nim b/src/private/uint_addsub.nim index d84191f..6e94a5c 100644 --- a/src/private/uint_addsub.nim +++ b/src/private/uint_addsub.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import ./bithacks, ./conversion, ./initialization, ./datatypes, ./uint_comparison, @@ -21,12 +21,12 @@ proc `+=`*(x: var UintImpl, y: UintImpl) {.noSideEffect, inline.}= x.lo += y.lo 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 result = x result += y -proc `-`*(x, y: UintImpl): UintImpl {.noSideEffect, fooPragma, inline.}= +proc `-`*(x, y: UintImpl): UintImpl {.noSideEffect, inline.}= # Substraction for multi-precision unsigned int type SubTy = type x.lo diff --git a/src/private/uint_bitwise_ops.nim b/src/private/uint_bitwise_ops.nim index 0a5ca8e..c1a9070 100644 --- a/src/private/uint_bitwise_ops.nim +++ b/src/private/uint_bitwise_ops.nim @@ -6,26 +6,26 @@ # * 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. -{.pragma: fooPragma.} + import ./datatypes, ./as_words -func `not`*(x: UintImpl): UintImpl {.fooPragma, inline.}= +func `not`*(x: UintImpl): UintImpl {.inline.}= ## Bitwise complement of unsigned integer x m_asWordsZip(result, x, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): 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 m_asWordsZip(result, x, y, ignoreEndianness = true): result = x xor y diff --git a/src/private/uint_div.nim b/src/private/uint_div.nim index 6ca8d85..e66a00b 100644 --- a/src/private/uint_div.nim +++ b/src/private/uint_div.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import ./bithacks, ./conversion, ./initialization, ./datatypes, ./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) # 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 (x div y, x mod y) diff --git a/src/private/uint_highlow.nim b/src/private/uint_highlow.nim index c83524a..f13bf35 100644 --- a/src/private/uint_highlow.nim +++ b/src/private/uint_highlow.nim @@ -9,8 +9,8 @@ import ./datatypes, ./initialization -func low*(T: typedesc[UintImpl]): T {.inline, fooPragma.}= +func low*(T: typedesc[UintImpl]): T {.inline.}= zero(T) -func high*(T: typedesc[UintImpl]): T {.inline, fooPragma.}= +func high*(T: typedesc[UintImpl]): T {.inline.}= not zero(T) diff --git a/src/private/uint_mul.nim b/src/private/uint_mul.nim index e83285d..d1b23c5 100644 --- a/src/private/uint_mul.nim +++ b/src/private/uint_mul.nim @@ -6,7 +6,7 @@ # * 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. -{.pragma: fooPragma.} + import macros, ./conversion, ./initialization, @@ -142,7 +142,7 @@ func extPrecMul*[T](result: var UintImpl[UintImpl[T]], u, v: UintImpl[T]) = ## Extended precision multiplication 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 # # For our representation, it is similar to school grade multiplication diff --git a/src/uint_public.nim b/src/uint_public.nim index 0d8d89d..030a8b9 100644 --- a/src/uint_public.nim +++ b/src/uint_public.nim @@ -9,20 +9,20 @@ import ./private/datatypes, macros export StUint, UintImpl, uintImpl # TODO remove the need to export UintImpl and this macro -{.pragma: fooPragma.} + type UInt128* = StUint[128] UInt256* = StUint[256] 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) make_conv(u128, 128) make_conv(u256, 256) template make_unary(op, ResultTy): untyped = - func `op`*(x: StUint): ResultTy {.fooPragma, inline.} = + func `op`*(x: StUint): ResultTy {.inline.} = when ResultTy is StUint: result.data = op(x.data) else: @@ -30,7 +30,7 @@ template make_unary(op, ResultTy): untyped = export op 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: result.data = op(x.data, y.data) else: @@ -56,7 +56,7 @@ import ./private/uint_div make_binary(`div`, 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) import ./private/uint_comparison @@ -72,9 +72,9 @@ make_unary(`not`, StUint) make_binary(`or`, StUint) make_binary(`and`, 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 -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 import ./private/uint_highlow