This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: 128-bit integer - nonsensical documentation?
- From: David Brown <david at westcontrol dot com>
- To: Kostas Savvidis <ksavvidis at gmail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 26 Aug 2015 14:13:24 +0200
- Subject: Re: 128-bit integer - nonsensical documentation?
- Authentication-results: sourceware.org; auth=none
- References: <1B1111BE-E274-4C80-8189-22B78D77647A at gmail dot com>
On 26/08/15 13:04, Kostas Savvidis wrote:
> The online documentation contains the attached passage as part of the
> "C-Extensionsâ chapter. There are no actual machines which have an "
> integer mode wide enough to hold 128 bitsâ as the document puts it.
> This would be a harmless confusion if it didnât go on to say ââ long
> long integer less than 128 bits wideâ (???!!!) Whereas in reality
> "long long intâ is 64 bits everywhere i have seen.
>
> KS
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> 6.8 128-bit integers
>
> As an extension the integer scalar type __int128 is supported for
> targets which have an integer mode wide enough to hold 128 bits.
> Simply write __int128 for a signed 128-bit integer, or unsigned
> __int128 for an unsigned 128-bit integer. There is no support in GCC
> for expressing an integer constant of type __int128 for targets with
> long long integer less than 128 bits wide.
>
You can use __int128 integers on any platform that supports them (which
I think is many 64-bit targets), even though "long long int" is
typically 64-bit. The documentation says you can't express an integer
/constant/ of type __int128 without 128-bit long long's. It is perhaps
not very clear, but it makes sense.
Thus you can write (using C++'s new digit separator for clarity):
__int128 a = 0x1111'2222'3333'4444'5555'6666'7777'8888LL;
to initialise a 128-bit integer - but /only/ if "long long" supports
128-bit values. On a platform that has __int128 but 64-bit long long's,
there is no way to write the 128-bit literal. Thus you must use
something like this:
__int128 a = (((__int128) 0x1111'2222'3333'4444LL) << 32)
| 0x5555'6666'7777'8888LL;
This is, I believe, the main reason that __int128 integers are an
"extension", but are not an "extended integer type" - and therefore
there is no int128_t and uint128_t defined in <stdint.h>.
Maybe what we need is a "LLL" suffix for long long long ints :-)