From 6a79fcb25b5fb625ac5e0bcc16651cd4ef3ff158 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 15 Jun 2023 14:07:40 +0700 Subject: [PATCH] remove unused files --- stint/private/compiletime_cast.nim | 23 ----------- stint/private/int_div.nim | 66 ------------------------------ stint/private/int_mul.nim | 17 -------- 3 files changed, 106 deletions(-) delete mode 100644 stint/private/compiletime_cast.nim delete mode 100644 stint/private/int_div.nim delete mode 100644 stint/private/int_mul.nim diff --git a/stint/private/compiletime_cast.nim b/stint/private/compiletime_cast.nim deleted file mode 100644 index d95db90..0000000 --- a/stint/private/compiletime_cast.nim +++ /dev/null @@ -1,23 +0,0 @@ -import ./datatypes - -# this module should be in compiletime_helpers -# but the cyclic dependency of compiletime_helpers -# and int_bitwise_ops make things complicated - -func convertImpl[T: SomeInteger](x: SomeInteger): T {.compileTime.} = - cast[T](x) - -func convertImpl[T: IntImpl|UintImpl](x: IntImpl|UintImpl): T {.compileTime.} = - result.hi = convertImpl[type(result.hi)](x.hi) - result.lo = x.lo - -func convertImpl[T: StUint|StInt](x: StUint|StInt): T {.compileTime.} = - result.data = convertImpl[type(result.data)](x.data) - -template convert*[T](x: StUint|StInt|UintImpl|IntImpl|SomeInteger): T = - when nimvm: - # this is a workaround Nim VM inability to cast - # something non integer - convertImpl[T](x) - else: - cast[T](x) diff --git a/stint/private/int_div.nim b/stint/private/int_div.nim deleted file mode 100644 index 6b462ed..0000000 --- a/stint/private/int_div.nim +++ /dev/null @@ -1,66 +0,0 @@ -# Stint -# Copyright 2018 Status Research & Development GmbH -# Licensed under either of -# -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -# * 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. - -import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison, ./compiletime_helpers - -# Here are the expected signs for division/modulo by opposite signs and both negative numbers -# in EVM -# Parity: https://github.com/paritytech/parity/blob/684322cd6f210684b890055c43d56bb1bc8cae15/ethcore/evm/src/interpreter/mod.rs#L729-L756 -# - SDIV is sign(a) xor sign(b) -# - SMOD is sign(a) -# Go-Ethereum: https://github.com/ethereum/go-ethereum/blob/ba1030b6b84f810c04a82221a1b1c0a3dbf499a8/core/vm/instructions.go#L76-L104 -# - SDIV is "if same sign, div(abs(a), abs(b)), else -div(abs(a), abs(b)) -# - SMOD is "sign(a)" -# -# in Nim -# echo "10 div 3: " & $(10 div 3) # 3 -# echo "10 mod 3: " & $(10 mod 3) # 1 -# echo '\n' -# echo "10 div -3: " & $(10 div -3) # -3 -# echo "10 mod -3: " & $(10 mod -3) # 1 -# echo '\n' -# echo "-10 div 3: " & $(-10 div 3) # -3 -# echo "-10 mod 3: " & $(-10 mod 3) # -1 -# echo '\n' -# echo "-10 div -3: " & $(-10 div -3) # 3 -# echo "-10 mod -3: " & $(-10 mod -3) # -1 -# echo '\n' - -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, T2](x, y: IntImpl[T, T2]): tuple[quot, rem: IntImpl[T, T2]] = - ## Divmod operation for multi-precision signed integer - - when nimvm: - let res = divmod( - convert[UintImpl[T2]](x.abs), - convert[UintImpl[T2]](y.abs)) - result.quot = convert[type result.quot](res.quot) - result.rem = convert[type result.rem](res.rem) - else: - result = cast[type result](divmod( - cast[UintImpl[T2]](x.abs), - cast[UintImpl[T2]](y.abs) - )) - - if (x.isNegative xor y.isNegative): - # If opposite signs - result.quot = -result.quot - if x.isNegative: - result.rem = -result.rem - -func `div`*(x, y: IntImpl): IntImpl {.inline.} = - ## Division operation for multi-precision signed integer - divmod(x,y).quot - -func `mod`*(x, y: IntImpl): IntImpl {.inline.} = - ## Division operation for multi-precision signed integer - divmod(x,y).rem diff --git a/stint/private/int_mul.nim b/stint/private/int_mul.nim deleted file mode 100644 index 5f691c7..0000000 --- a/stint/private/int_mul.nim +++ /dev/null @@ -1,17 +0,0 @@ -# Stint -# Copyright 2018 Status Research & Development GmbH -# Licensed under either of -# -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -# * 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. - -import ./datatypes, ./uint_mul, ./compiletime_helpers - -func `*`*[T, T2](x, y: IntImpl[T, T2]): IntImpl[T, T2] {.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 - # TODO: overflow detection. - convert[type result](convert[UintImpl[T2]](x) * convert[UintImpl[T2]](y))