From e639ba700cb83a6b22e5b5a1053bea2820c8b4f6 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Tue, 27 Feb 2024 02:36:02 +0200 Subject: [PATCH 1/5] Make decimal string parser raise ValueError instead of RangeDefect. (#148) * Fix decimal parser helper to raise ValueError instead of RangeDefect. * Get some fixes in place. --- stint/io.nim | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stint/io.nim b/stint/io.nim index 884865b..992da71 100644 --- a/stint/io.nim +++ b/stint/io.nim @@ -196,7 +196,8 @@ func readHexChar(c: char): int8 {.inline.}= of 'a'..'f': result = int8 ord(c) - ord('a') + 10 of 'A'..'F': result = int8 ord(c) - ord('A') + 10 else: - raise newException(ValueError, $c & "is not a hexadecimal character") + raise newException(ValueError, + "[" & $c & "] is not a hexadecimal character") func skipPrefixes(current_idx: var int, str: string, radix: range[2..16]) {.inline.} = ## Returns the index of the first meaningful char in `hexStr` by skipping @@ -231,10 +232,14 @@ func nextNonBlank(current_idx: var int, s: string) {.inline.} = while current_idx < s.len and s[current_idx] in blanks: inc current_idx -func readDecChar(c: range['0'..'9']): int {.inline.}= +func readDecChar(c: char): int8 {.inline.}= ## Converts a decimal char to an int # specialization without branching for base <= 10. - ord(c) - ord('0') + case c + of '0'..'9': + int8(ord(c) - ord('0')) + else: + raise newException(ValueError, "[" & $c & "] is not a decimal character") func parse*[bits: static[int]](input: string, T: typedesc[StUint[bits]], From 7bb0ccc7842577243edc3b8d61f75bf498551a7a Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 27 Feb 2024 19:55:11 +0700 Subject: [PATCH 2/5] Upgrade github actions to v4 (#149) --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f1e034..18fa79e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: runs-on: ${{ matrix.builder }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set GCC 10 as default compiler (Linux) if: runner.os == 'Linux' && matrix.target.cpu != 'i386' @@ -74,7 +74,7 @@ jobs: - name: Restore llvm-mingw (Windows) from cache if: runner.os == 'Windows' id: windows-mingw-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: external/mingw-${{ matrix.target.cpu }} key: 'mingw-llvm-17-${{ matrix.target.cpu }}' @@ -100,7 +100,7 @@ jobs: - name: Restore Nim DLLs dependencies (Windows) from cache if: runner.os == 'Windows' id: windows-dlls-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: external/dlls key: 'dlls' From 3c238df6cd4b9c1f37a9f103383e7d2bbd420c13 Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 13 Mar 2024 04:45:06 +0000 Subject: [PATCH 3/5] fix noInit to noinit; use evergreen GitHub Actions image versions (#151) --- .github/workflows/ci.yml | 4 ++-- stint/intops.nim | 2 +- stint/private/primitives/addcarry_subborrow.nim | 4 ++-- stint/uintops.nim | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18fa79e..6ee1567 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,10 +26,10 @@ jobs: include: - target: os: linux - builder: ubuntu-20.04 + builder: ubuntu-latest - target: os: macos - builder: macos-12 + builder: macos-latest - target: os: windows builder: windows-latest diff --git a/stint/intops.nim b/stint/intops.nim index 7949ffc..245d1f7 100644 --- a/stint/intops.nim +++ b/stint/intops.nim @@ -168,7 +168,7 @@ func `xor`*(a, b: StInt): StInt = ## `Bitwise xor` of numbers x and y result.impl.bitxor(a.impl, b.impl) -{.pop.} # End noInit +{.pop.} # End noinit {.push raises: [], inline, gcsafe.} diff --git a/stint/private/primitives/addcarry_subborrow.nim b/stint/private/primitives/addcarry_subborrow.nim index 0f9c807..b5e264c 100644 --- a/stint/private/primitives/addcarry_subborrow.nim +++ b/stint/private/primitives/addcarry_subborrow.nim @@ -148,7 +148,7 @@ func addC*(cOut: var Carry, sum: var uint64, a, b: uint64, cIn: Carry) {.inline. when useIntrinsics: cOut = addcarry_u64(cIn, a, b, sum) elif useInt128: - var dblPrec {.noInit.}: uint128 + var dblPrec {.noinit.}: uint128 {.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].} # Don't forget to dereference the var param in C mode @@ -170,7 +170,7 @@ func subB*(bOut: var Borrow, diff: var uint64, a, b: uint64, bIn: Borrow) {.inli when useIntrinsics: bOut = subborrow_u64(bIn, a, b, diff) elif useInt128: - var dblPrec {.noInit.}: uint128 + var dblPrec {.noinit.}: uint128 {.emit:[dblPrec, " = (unsigned __int128)", a," - (unsigned __int128)", b, " - (unsigned __int128)",bIn,";"].} # Don't forget to dereference the var param in C mode diff --git a/stint/uintops.nim b/stint/uintops.nim index 0c4daf0..b1bc580 100644 --- a/stint/uintops.nim +++ b/stint/uintops.nim @@ -123,7 +123,7 @@ func `xor`*(a, b: StUint): StUint = ## `Bitwise xor` of numbers x and y result.bitxor(a, b) -{.pop.} # End noInit +{.pop.} # End noinit export countOnes, @@ -270,4 +270,4 @@ func divmod*(x, y: StUint): tuple[quot, rem: StUint] = ## Division and remainder operations for multi-precision unsigned uint divRem(result.quot.limbs, result.rem.limbs, x.limbs, y.limbs) -{.pop.} \ No newline at end of file +{.pop.} From 379901ad36b1febf06106c18b22b31a1d5dfdf67 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 20 May 2024 23:39:33 +0700 Subject: [PATCH 4/5] Fix pointer deref issue on Macos and Nim >= 2.0 (#152) --- .github/workflows/ci.yml | 2 +- .gitignore | 1 + config.nims | 4 ++++ stint/private/primitives/addcarry_subborrow.nim | 8 ++++++-- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 config.nims diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee1567..53629ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,6 +168,6 @@ jobs: env TEST_LANG="c" nimble test # run test against intx env TEST_LANG="cpp" nimble test - # test conditional compilation for arm654 arch + # test conditional compilation for arm64 arch # without running the binary nim c -c --cpu:arm64 --os:linux tests/all_tests diff --git a/.gitignore b/.gitignore index a68fbaa..eee2a2b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ nimcache/ build/ +nimble.paths diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..7c9db32 --- /dev/null +++ b/config.nims @@ -0,0 +1,4 @@ +# begin Nimble config (version 1) +when fileExists("nimble.paths"): + include "nimble.paths" +# end Nimble config diff --git a/stint/private/primitives/addcarry_subborrow.nim b/stint/private/primitives/addcarry_subborrow.nim index b5e264c..7ed2680 100644 --- a/stint/private/primitives/addcarry_subborrow.nim +++ b/stint/private/primitives/addcarry_subborrow.nim @@ -88,6 +88,10 @@ const useIntrinsics = X86 and not stintNoIntrinsics useInt128 = GCC_Compatible and sizeof(int) == 8 and not stintNoIntrinsics +const + newerNim = (NimMajor, NimMinor) > (1, 6) + noExplicitPtrDeref = defined(cpp) or newerNim + when useIntrinsics: when defined(windows): {.pragma: intrinsics, header:"", nodecl.} @@ -152,7 +156,7 @@ func addC*(cOut: var Carry, sum: var uint64, a, b: uint64, cIn: Carry) {.inline. {.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].} # Don't forget to dereference the var param in C mode - when defined(cpp): + when noExplicitPtrDeref: {.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].} {.emit:[sum, " = (NU64)", dblPrec,";"].} else: @@ -175,7 +179,7 @@ func subB*(bOut: var Borrow, diff: var uint64, a, b: uint64, bIn: Borrow) {.inli # Don't forget to dereference the var param in C mode # On borrow the high word will be 0b1111...1111 and needs to be masked - when defined(cpp): + when noExplicitPtrDeref: {.emit:[bOut, " = (NU64)(", dblPrec," >> ", 64'u64, ") & 1;"].} {.emit:[diff, " = (NU64)", dblPrec,";"].} else: From 9d2b382c5dc34f0d6bbd93b2a5d65dde85067e0f Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Thu, 23 May 2024 07:31:45 +0300 Subject: [PATCH 5/5] Fix GCC-14 [-Wincompatible-pointer-types] issue. (#153) --- stint/private/primitives/addcarry_subborrow.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stint/private/primitives/addcarry_subborrow.nim b/stint/private/primitives/addcarry_subborrow.nim index 7ed2680..b63fd9e 100644 --- a/stint/private/primitives/addcarry_subborrow.nim +++ b/stint/private/primitives/addcarry_subborrow.nim @@ -101,8 +101,8 @@ when useIntrinsics: func addcarry_u32(carryIn: Carry, a, b: uint32, sum: var uint32): Carry {.importc: "_addcarry_u32", intrinsics.} func subborrow_u32(borrowIn: Borrow, a, b: uint32, diff: var uint32): Borrow {.importc: "_subborrow_u32", intrinsics.} - func addcarry_u64(carryIn: Carry, a, b: uint64, sum: var uint64): Carry {.importc: "_addcarry_u64", intrinsics.} - func subborrow_u64(borrowIn: Borrow, a, b:uint64, diff: var uint64): Borrow {.importc: "_subborrow_u64", intrinsics.} + func addcarry_u64(carryIn: Carry, a, b: uint64, sum: var culonglong): Carry {.importc: "_addcarry_u64", intrinsics.} + func subborrow_u64(borrowIn: Borrow, a, b:uint64, diff: var culonglong): Borrow {.importc: "_subborrow_u64", intrinsics.} # ############################################################ # @@ -150,7 +150,7 @@ func addC*(cOut: var Carry, sum: var uint64, a, b: uint64, cIn: Carry) {.inline. addC_nim(cOut, sum, a, b, cIn) else: when useIntrinsics: - cOut = addcarry_u64(cIn, a, b, sum) + cOut = addcarry_u64(cIn, a, b, culonglong(sum)) elif useInt128: var dblPrec {.noinit.}: uint128 {.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].} @@ -172,7 +172,7 @@ func subB*(bOut: var Borrow, diff: var uint64, a, b: uint64, bIn: Borrow) {.inli subB_nim(bOut, diff, a, b, bIn) else: when useIntrinsics: - bOut = subborrow_u64(bIn, a, b, diff) + bOut = subborrow_u64(bIn, a, b, culonglong(diff)) elif useInt128: var dblPrec {.noinit.}: uint128 {.emit:[dblPrec, " = (unsigned __int128)", a," - (unsigned __int128)", b, " - (unsigned __int128)",bIn,";"].}