XPost: comp.arch
On Mon, 04 Aug 2025 12:09:32 GMT
[email protected] (Anton Ertl) wrote:
Michael S <[email protected]> writes:
Actually, in our world the latest C standard (C23) has them, but the >spelling is different: _BitInt(32) and unsigned _BitInt(32).
I'm not sure if any major compiler already has them implemented. Bing >copilot says that clang does, but I don't tend to believe eveything
Bing copilot says.
I asked godbolt, and tried the following program:
It turned out that I didn't need even goldbolt.
I already had sufficiently advanced gcc and clang installed on my new
Windows PC at work. I probably have them installed on very old home PC
as well, but now I am at work. Playing with compilers instead of
working.
typedef ump unsigned _BitInt(65535);
ump sum3(ump a, ump b, ump c)
{
return a+b+c;
}
and for the C setting gcc-15.1 AMD64 produces 129 lines of assembly
language code; for C++ it complains about the syntax. For 65536 bits,
it complains about being beyond the maximum number of 65535 bits.
For the same program with the C setting clang-20.1 produces 29547
lines of assembly language code; that's more than 28 instructions for
every 64-bit word of output, which seems excessive to me, even if you
don't use ADX instructions (which clang apparently does not); I expect
that clang will produce better code at some point in the future.
Compiling this function also takes noticable time, and when I ask for
1000000 bits, clang still does complain about too many bits, but
godbolt's timeout strikes; I finally found out clang's limit: 8388608
bits. On clang-20.1 the C++ setting also accepts this kind of input.
Followups set to comp.arch.
- anton
I didn't pay much attention to code size yet. Had seen two other
worrying things.
1. Both gcc and clang happily* accept _BitInt() syntax even when
-std=c17 or lower. Is not here a potential name clash for existing
sources that use _BitInt() as a name of the function? I should think
more about it.
2. Windows-specific.
gcc and clang appear to have different ABIs for return value of type _BitInt(128).
* - the only sign of less than perfect happiness is a warning produced
with -pedantic flag.
Cross-posted to c.lang.c
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)