remove unused files
This commit is contained in:
parent
c6422a9439
commit
6a79fcb25b
|
@ -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)
|
|
|
@ -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
|
|
|
@ -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))
|
|
Loading…
Reference in New Issue