public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: __builtin_clzll and uintmax_t
@ 2011-03-05 22:05 FX
  2011-03-06  8:57 ` Marc Glisse
  0 siblings, 1 reply; 5+ messages in thread
From: FX @ 2011-03-05 22:05 UTC (permalink / raw)
  To: gcc, marc.glisse

Salut Marc !

> We have a variable of type uintmax_t and want to count the leading zeros. Can we just call __builtin_clzll on it?

Yes.

> In particular, can uintmax_t be larger than unsigned long long in gcc?

uintmax_t is the largest of the standard unsigned C types, so it cannot be larger than unsigned long long. On x86_64, for example:

> #include <stdio.h>
> #include <stdint.h>
> 
> int main (void)
> {
>   printf ("%lu ", sizeof (uintmax_t));
>   printf ("%lu ", sizeof (int));
>   printf ("%lu ", sizeof (long int));
>   printf ("%lu ", sizeof (long long int));
>   printf ("%lu\n", sizeof (__int128));
> }

gives : 8 4 8 8 16


> Is __builtin_clzll available on all platforms?

Yes, we emit calls to this built-in unconditionally in the Fortran front-end, and it has caused no trouble.


FX

^ permalink raw reply	[flat|nested] 5+ messages in thread
* __builtin_clzll and uintmax_t
@ 2011-03-05 21:05 Marc Glisse
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Glisse @ 2011-03-05 21:05 UTC (permalink / raw)
  To: gcc

Hello,

the following question came up for a libstdc++ patch. We have a variable 
of type uintmax_t and want to count the leading zeros. Can we just call 
__builtin_clzll on it?

In particular, can uintmax_t be larger than unsigned long long in gcc? Is 
__builtin_clzll available on all platforms? Is there a good reason to use 
__builtin_clzl instead on platforms where long and long long have the same 
size?

In case it matters, this is strictly for compile-time computations 
(templates, constexpr).

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-08 12:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-05 22:05 __builtin_clzll and uintmax_t FX
2011-03-06  8:57 ` Marc Glisse
2011-03-06 14:52   ` Jakub Jelinek
2011-03-08 12:04     ` Joern Rennecke
  -- strict thread matches above, loose matches on Subject: below --
2011-03-05 21:05 Marc Glisse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).