jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules
204 stars 37 forks source link

Missing `__u/int128` support #288

Closed kassane closed 7 months ago

kassane commented 8 months ago

Source to translate: https://github.com/tigerbeetle/tigerbeetle/blob/main/src/clients/c/tb_client.h

typedef __uint128_t tb_uint128_t; -> alias tb_uint128_t = <unimplemented>;

The translation gave an undefined type.

https://github.com/jacob-carlborg/dstep/blob/2cb53c131c18d1d94d7f4fc2896305dd4154763a/dstep/translator/Type.d#L188-L196

jacob-carlborg commented 8 months ago

D doesn't support 128bit integers. What do you suggest the result would be?

kassane commented 8 months ago

D doesn't support 128bit integers

https://dlang.org/phobos/core_int128.html ?


Edit:

Not yet how supported it is by other D compilers... At first it would be enough to just translate to 64bit integers. (Like Pascal)

kassane commented 8 months ago

In my test core.int128 not working in DMD2: https://d.godbolt.org/z/n3bG75d3K

LDC and GDC works!

<source>(9): Error: module `int128` is in file 'core/int128.d' which cannot be read
import path[0] = /opt/compiler-explorer/dmd2-nightly/dmd2/linux/bin64/../../src/phobos
import path[1] = /opt/compiler-explorer/dmd2-nightly/dmd2/linux/bin64/../../src/druntime/import
Compiler returned: 1
jacob-carlborg commented 8 months ago

Strange, it's available in the repository. BTW, have you checked if it's ABI compatible with __uint128_t?

kassane commented 8 months ago

Strange, it's available in the repository. BTW, have you checked if it's ABI compatible with __uint128_t?

More recent information is below:

cc: @ibuclaw

jacob-carlborg commented 8 months ago

BTW, should it be core.int128 or std.int128?

kassane commented 8 months ago

BTW, should it be core.int128 or std.int128?

Please, use core.int128! Added the Cent to my wrapper and it's fine during the test.

jacob-carlborg commented 8 months ago

I'm not that familiar with 128 bit integers, but it seems there's no unsigned version in core.int128?

kassane commented 8 months ago

I'm not that familiar with 128 bit integers, but it seems there's no unsigned version in core.int128?

I know. Not ideal, but for some simulated operations so far haven't had any problems.

I tried using uint64 with high values ​​during concurrent transactions and in some cases I applied the use of integer casts.

Then I will publish the D client to compare with the C Client as a reference. I need to better integrate Zig's event-loop (libtbClient) with D concurrency (appClient).

References

Why not 64-bit?

A: https://tigerbeetle.com/blog/2023-09-19-64-bit-bank-balances-ought-to-be-enough-for-anybody/

Clients FFI https://tigerbeetle.com/blog/2023-02-21-writing-high-performance-clients-for-tigerbeetle/

jacob-carlborg commented 8 months ago

Do you suggest using the signed Cent for both signed and unsigned?

kassane commented 8 months ago

Do you suggest using the signed Cent for both signed and unsigned?

It's not ideal, but yeah. Using Cent in signed and unsigned.

jacob-carlborg commented 7 months ago

@kassane is this what you had in mind: https://github.com/jacob-carlborg/dstep/commit/ac4b87638d5bb83624105fa7e9c04f10b8657d73#diff-9347ce4d022101ff02a5f37861df6934dc17bd9a72590f391f603a555f6e10b8?

kassane commented 7 months ago

Exactly.