Merge branch 'master' into ct-fixes
This commit is contained in:
commit
a8418ac2e9
|
@ -26,10 +26,10 @@ jobs:
|
||||||
include:
|
include:
|
||||||
- target:
|
- target:
|
||||||
os: linux
|
os: linux
|
||||||
builder: ubuntu-20.04
|
builder: ubuntu-latest
|
||||||
- target:
|
- target:
|
||||||
os: macos
|
os: macos
|
||||||
builder: macos-12
|
builder: macos-latest
|
||||||
- target:
|
- target:
|
||||||
os: windows
|
os: windows
|
||||||
builder: windows-latest
|
builder: windows-latest
|
||||||
|
@ -42,7 +42,7 @@ jobs:
|
||||||
runs-on: ${{ matrix.builder }}
|
runs-on: ${{ matrix.builder }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set GCC 10 as default compiler (Linux)
|
- name: Set GCC 10 as default compiler (Linux)
|
||||||
if: runner.os == 'Linux' && matrix.target.cpu != 'i386'
|
if: runner.os == 'Linux' && matrix.target.cpu != 'i386'
|
||||||
|
@ -74,7 +74,7 @@ jobs:
|
||||||
- name: Restore llvm-mingw (Windows) from cache
|
- name: Restore llvm-mingw (Windows) from cache
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
id: windows-mingw-cache
|
id: windows-mingw-cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: external/mingw-${{ matrix.target.cpu }}
|
path: external/mingw-${{ matrix.target.cpu }}
|
||||||
key: 'mingw-llvm-17-${{ matrix.target.cpu }}'
|
key: 'mingw-llvm-17-${{ matrix.target.cpu }}'
|
||||||
|
@ -100,7 +100,7 @@ jobs:
|
||||||
- name: Restore Nim DLLs dependencies (Windows) from cache
|
- name: Restore Nim DLLs dependencies (Windows) from cache
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
id: windows-dlls-cache
|
id: windows-dlls-cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: external/dlls
|
path: external/dlls
|
||||||
key: 'dlls'
|
key: 'dlls'
|
||||||
|
@ -168,6 +168,6 @@ jobs:
|
||||||
env TEST_LANG="c" nimble test
|
env TEST_LANG="c" nimble test
|
||||||
# run test against intx
|
# run test against intx
|
||||||
env TEST_LANG="cpp" nimble test
|
env TEST_LANG="cpp" nimble test
|
||||||
# test conditional compilation for arm654 arch
|
# test conditional compilation for arm64 arch
|
||||||
# without running the binary
|
# without running the binary
|
||||||
nim c -c --cpu:arm64 --os:linux tests/all_tests
|
nim c -c --cpu:arm64 --os:linux tests/all_tests
|
||||||
|
|
|
@ -6,3 +6,4 @@
|
||||||
|
|
||||||
nimcache/
|
nimcache/
|
||||||
build/
|
build/
|
||||||
|
nimble.paths
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# begin Nimble config (version 1)
|
||||||
|
when fileExists("nimble.paths"):
|
||||||
|
include "nimble.paths"
|
||||||
|
# end Nimble config
|
|
@ -168,7 +168,7 @@ func `xor`*(a, b: StInt): StInt =
|
||||||
## `Bitwise xor` of numbers x and y
|
## `Bitwise xor` of numbers x and y
|
||||||
result.impl.bitxor(a.impl, b.impl)
|
result.impl.bitxor(a.impl, b.impl)
|
||||||
|
|
||||||
{.pop.} # End noInit
|
{.pop.} # End noinit
|
||||||
|
|
||||||
{.push raises: [], inline, gcsafe.}
|
{.push raises: [], inline, gcsafe.}
|
||||||
|
|
||||||
|
|
11
stint/io.nim
11
stint/io.nim
|
@ -194,7 +194,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
|
||||||
of 'A'..'F': result = int8 ord(c) - ord('A') + 10
|
of 'A'..'F': result = int8 ord(c) - ord('A') + 10
|
||||||
else:
|
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.} =
|
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
|
## Returns the index of the first meaningful char in `hexStr` by skipping
|
||||||
|
@ -229,10 +230,14 @@ func nextNonBlank(current_idx: var int, s: string) {.inline.} =
|
||||||
while current_idx < s.len and s[current_idx] in blanks:
|
while current_idx < s.len and s[current_idx] in blanks:
|
||||||
inc current_idx
|
inc current_idx
|
||||||
|
|
||||||
func readDecChar(c: range['0'..'9']): int {.inline.}=
|
func readDecChar(c: char): int8 {.inline.}=
|
||||||
## Converts a decimal char to an int
|
## Converts a decimal char to an int
|
||||||
# specialization without branching for base <= 10.
|
# 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,
|
func parse*[bits: static[int]](input: string,
|
||||||
T: typedesc[StUint[bits]],
|
T: typedesc[StUint[bits]],
|
||||||
|
|
|
@ -88,6 +88,10 @@ const
|
||||||
useIntrinsics = X86 and not stintNoIntrinsics
|
useIntrinsics = X86 and not stintNoIntrinsics
|
||||||
useInt128 = GCC_Compatible and sizeof(int) == 8 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 useIntrinsics:
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
{.pragma: intrinsics, header:"<intrin.h>", nodecl.}
|
{.pragma: intrinsics, header:"<intrin.h>", nodecl.}
|
||||||
|
@ -97,8 +101,8 @@ when useIntrinsics:
|
||||||
func addcarry_u32(carryIn: Carry, a, b: uint32, sum: var uint32): Carry {.importc: "_addcarry_u32", intrinsics.}
|
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 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 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 uint64): Borrow {.importc: "_subborrow_u64", intrinsics.}
|
func subborrow_u64(borrowIn: Borrow, a, b:uint64, diff: var culonglong): Borrow {.importc: "_subborrow_u64", intrinsics.}
|
||||||
|
|
||||||
# ############################################################
|
# ############################################################
|
||||||
#
|
#
|
||||||
|
@ -146,13 +150,13 @@ func addC*(cOut: var Carry, sum: var uint64, a, b: uint64, cIn: Carry) {.inline.
|
||||||
addC_nim(cOut, sum, a, b, cIn)
|
addC_nim(cOut, sum, a, b, cIn)
|
||||||
else:
|
else:
|
||||||
when useIntrinsics:
|
when useIntrinsics:
|
||||||
cOut = addcarry_u64(cIn, a, b, sum)
|
cOut = addcarry_u64(cIn, a, b, culonglong(sum))
|
||||||
elif useInt128:
|
elif useInt128:
|
||||||
var dblPrec {.noInit.}: uint128
|
var dblPrec {.noinit.}: uint128
|
||||||
{.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].}
|
{.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].}
|
||||||
|
|
||||||
# Don't forget to dereference the var param in C mode
|
# Don't forget to dereference the var param in C mode
|
||||||
when defined(cpp):
|
when noExplicitPtrDeref:
|
||||||
{.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
|
{.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
|
||||||
{.emit:[sum, " = (NU64)", dblPrec,";"].}
|
{.emit:[sum, " = (NU64)", dblPrec,";"].}
|
||||||
else:
|
else:
|
||||||
|
@ -168,14 +172,14 @@ func subB*(bOut: var Borrow, diff: var uint64, a, b: uint64, bIn: Borrow) {.inli
|
||||||
subB_nim(bOut, diff, a, b, bIn)
|
subB_nim(bOut, diff, a, b, bIn)
|
||||||
else:
|
else:
|
||||||
when useIntrinsics:
|
when useIntrinsics:
|
||||||
bOut = subborrow_u64(bIn, a, b, diff)
|
bOut = subborrow_u64(bIn, a, b, culonglong(diff))
|
||||||
elif useInt128:
|
elif useInt128:
|
||||||
var dblPrec {.noInit.}: uint128
|
var dblPrec {.noinit.}: uint128
|
||||||
{.emit:[dblPrec, " = (unsigned __int128)", a," - (unsigned __int128)", b, " - (unsigned __int128)",bIn,";"].}
|
{.emit:[dblPrec, " = (unsigned __int128)", a," - (unsigned __int128)", b, " - (unsigned __int128)",bIn,";"].}
|
||||||
|
|
||||||
# Don't forget to dereference the var param in C mode
|
# 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
|
# 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:[bOut, " = (NU64)(", dblPrec," >> ", 64'u64, ") & 1;"].}
|
||||||
{.emit:[diff, " = (NU64)", dblPrec,";"].}
|
{.emit:[diff, " = (NU64)", dblPrec,";"].}
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -123,7 +123,7 @@ func `xor`*(a, b: StUint): StUint =
|
||||||
## `Bitwise xor` of numbers x and y
|
## `Bitwise xor` of numbers x and y
|
||||||
result.bitxor(a, b)
|
result.bitxor(a, b)
|
||||||
|
|
||||||
{.pop.} # End noInit
|
{.pop.} # End noinit
|
||||||
|
|
||||||
export
|
export
|
||||||
countOnes,
|
countOnes,
|
||||||
|
|
Loading…
Reference in New Issue