Support for int128 and uint128 #1410
Replies: 4 comments 7 replies
-
Both those types look like they're trying to do the same thing, sorta. Could you elaborate on the example with some comments? Thanks. |
Beta Was this translation helpful? Give feedback.
-
I'd further like to comment that double word atomic ops are essential for producing the most modern lock free data structures; there's no way to take advantage of this natively in nimskull at the moment that doesn't look like the example AFAIK Obviously I'd be stupendously surprised and delighted if someone can point me in the direction of a better path to take. |
Beta Was this translation helpful? Give feedback.
-
One option might be to, allow/improve the following:
Then the type could be defined in either |
Beta Was this translation helpful? Give feedback.
-
Here's my attempt: type
int128* = object
hi*{.align:16.}, lo*: uint64
cint128 {.importc: "__int128",nodecl.} = object
proc atomicAddFetch(p: ptr cint128, v: cint128, mo = ATOMIC_SEQ_CST): cint128 {.importc:"__atomic_add_fetch",nodecl,discardable.}
proc `+`*(a,b: int128): int128 {.inline.} =
result = a
discard atomicAddFetch(cast[ptr cint128](result.addr), cast[ptr cint128](b.addr)[])
proc `+=`*(a: var int128, b: int128) {.inline.} =
atomicAddFetch(cast[ptr cint128](a.addr), cast[ptr cint128](b.addr)[])
var start = int128(hi: 0'u64, lo: 1'u64)
let adder = int128(hi: 1'u64, lo: 0'u64)
echo start + adder
echo start
start += adder
echo start Here the builtin Hopefully the double casts of |
Beta Was this translation helpful? Give feedback.
-
The topic of supporting big ints like int128 and uint128 come up frequently.
I'd like to know what the thoughts are with supporting these internally, or at least providing better support for using them on supported archs.
This is how it currently has to be used afaik if I want to take advantage of builtin operations like double word atomic ops on viable architectures:
In the case of using double word atomics:
This feels very obstructive and reduces clarity of the codebase.
Beta Was this translation helpful? Give feedback.
All reactions