|
2022-09-22
| ||
| 15:50 | • Closed ticket [931802a0f5]: Require Tcl_WideInt/Tcl_WideUInt to be exactly 64 bi... artifact: bbac1f16f3 user: jan.nijtmans | |
|
2022-09-17
| ||
| 21:51 | • Ticket [931802a0f5]: 3 changes artifact: 1b69c18c4e user: chrstphrchvz | |
|
2022-09-06
| ||
| 15:57 | • Ticket [931802a0f5]: 3 changes artifact: 1d151b3ba4 user: jan.nijtmans | |
| 10:30 | • Ticket [931802a0f5]: 4 changes artifact: 06d0e04968 user: jan.nijtmans | |
| 09:35 | • Ticket [931802a0f5]: 3 changes artifact: bb8ccef738 user: chrstphrchvz | |
| 09:11 | • New ticket [931802a0f5]. artifact: 6312c6358a user: chrstphrchvz | |
Require Tcl_WideInt/Tcl_WideUInt to be exactly 64 bits
Some compilers on some platforms, such as GCC and Clang on 64-bit (but not 32-bit), already offer an __int128 type. 128-bit arithmetic is accomplished using several 64-bit operations, since it is not natively supported by hardware (general purpose register file/ALU), similar to how 64-bit operations are accomplished on 32-bit platforms. But even without native 128-bit arithmetic, __int128 could still be far faster than bignum for any Tcl applications doing up to 128-bit computing.
However, I would think far more software, including core Tcl, would be broken by defining Tcl_WideInt as wider than 64-bit. And following TIP 484, there is presumably little interest in Tcl once again having two "native" integer types (wide and double-wide).
So maybe defining Tcl_WideInt as anything other than 64 bit, e.g.__int128, should be forbidden. Alternatively, if Tcl_WideInt is to ever be redefined as (preferably exactly) 128-bit, it should be done by some future Tcl version when the ABI is allowed to change.
Alternatively, amend any “at least 64-bit” verbiage to say something like “smallest type covering 64-bit range”. That way, the 64-bit type is always used on platforms with one, and any debates are avoided regarding what to do for an unusual platform only having type(s) larger than but not exactly 64 bits.
See TIP #476:
Whenever possible, typedef `Tcl_WideInt` to be equal to `long long`, even on platforms where long has the same size as `long long`.
I don't think there's any platform (still supported by Tcl 8.7) which doesn't have "long long". Does that answer your concern?
Indeed, changing Tcl_WideInt is a binary incompatible thing to do. I just consider it the same as "long long".
The biggest problem using __int128 would be that there is no matching printf modifier. Does 'inttypes.h' have a definition for 'PRId128'??? I never say that anywhere. Tcl has 'TCL_LL_MODIFIER'(see the same TIP), that wouldn't work any more
Dup of [45ddcfc3b1]
I ask mainly in case it would be nice to know that Tcl_WideInt is exactly 64-bit when writing library/extension code (a possibly more strict guarantee than it being long long), but even without this guarantee, any concerns seem remote enough for the time being.
I now notice the IntObj documentation has already taken TIP 476 into account, so I am probably just behind (Tcl 8.6 not requiring C99 probably a reason for it to avoid mentioning long long). The ABI stability requirement should already be obvious to me, though maybe that is not what I should have asked about, and instead I should have asked about __int128 merely as a configuration option for those not concerned about ABI compatibility with anything built with Tcl defaults. But as long as compilers have yet to provide format specifiers for __int128 then I agree there isn’t much for early adopters to try; they are probably better off adding a new Tcl value type for __int128 than redefining Tcl_WideInt.
I had searched this site for __int128 but was not lead to the existing ticket. I am fine with this ticket being closed as e.g. duplicate or out of date.