fix stuint truncate on 32bit platform

This commit is contained in:
jangko 2023-06-19 18:27:49 +07:00
parent 140afc31ab
commit 4a3f300bd6
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 6 additions and 12 deletions

View File

@ -152,9 +152,6 @@ jobs:
# https://github.com/status-im/nimbus-eth2/issues/3121 # https://github.com/status-im/nimbus-eth2/issues/3121
export NIMFLAGS="-d:nimRawSetjmp" export NIMFLAGS="-d:nimRawSetjmp"
fi fi
if [[ "${{ matrix.branch }}" == "devel" ]]; then
export NIMFLAGS="${NIMFLAGS} -d:nimDevelFixVarParam"
fi
nim --version nim --version
nimble --version nimble --version
nimble install -y --depsOnly nimble install -y --depsOnly

View File

@ -64,7 +64,7 @@ func truncate*(num: StUint, T: typedesc[SomeInteger]): T {.inline.}=
## Note that int and uint are 32-bit on 32-bit platform. ## Note that int and uint are 32-bit on 32-bit platform.
## For unsigned result type, result is modulo 2^(sizeof T in bit) ## For unsigned result type, result is modulo 2^(sizeof T in bit)
## For signed result type, result is undefined if input does not fit in the target type. ## For signed result type, result is undefined if input does not fit in the target type.
when T is SomeSignedInt: when T is SomeSignedInt and sizeof(T) <= sizeof(Word):
result = T(num.leastSignificantWord() and Word(T.high)) result = T(num.leastSignificantWord() and Word(T.high))
else: else:
result = T(num.leastSignificantWord()) result = T(num.leastSignificantWord())

View File

@ -16,11 +16,8 @@ import ../datatypes
# ############################################################ # ############################################################
const const
# at the time of writing June 14th 2023 newerNim = (NimMajor, NimMinor) > (1, 6)
# only devel branch codegen can generate noExplicitPtrDeref = defined(cpp) or newerNim
# ptr deref when using var param
# while version-1-6 and version-2-0 branch cannot
noExplicitPtrDeref = defined(cpp) or defined(nimDevelFixVarParam)
static: static:
doAssert GCC_Compatible doAssert GCC_Compatible

View File

@ -724,14 +724,14 @@ template testIO(chk, tst, handleErr: untyped) =
chkDumpHexStint(chk, "abcdef0012345678abcdef1122334455", "5544332211efcdab7856341200efcdab", 128) chkDumpHexStint(chk, "abcdef0012345678abcdef1122334455", "5544332211efcdab7856341200efcdab", 128)
#static: static:
#testIO(ctCheck, ctTest, ctExpect) testIO(ctCheck, ctTest, ctExpect)
proc main() = proc main() =
# Nim GC protests we are using too much global variables # Nim GC protests we are using too much global variables
# so put it in a proc # so put it in a proc
suite "Testing input and output procedures": suite "Testing input and output procedures":
#testIO(check, test, expect) testIO(check, test, expect)
test "toByteArrayBE CT vs RT": test "toByteArrayBE CT vs RT":
chkCTvsRT(check, 0xab'u64, 64) chkCTvsRT(check, 0xab'u64, 64)