Re: Detect whether we have a native 64-bit type?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 25 Apr 2016, Jonathan Lennox wrote:
> Is there any portable way in GCC to detect whether the architecture we’re
> targeting has a fast native 64-bit type?
> 
> The motivation is that there are operations that it’s faster to do as a
> single 64-bit multiplication if the architecture really supports native
> 64-bit operations, but if instead 64-bit is emulated, it’s faster to write
> multiple 32-bit multiplications.
> [snip]
> I know there are any number of 64-bit platforms that have x32-style ABIs.
> Rather than enumerate them all, is there some way I can get this information
> from GCC directly?  (Extra points if it works on Clang as well.)

As an approximation, you can use availability of non-standard integer type
__int128 to infer whether 64-bit operations are native or not.  Of course it
doesn't guarantee that 64-bit paths would be faster than 32-bit paths, but
chaining on exceptions to that should be easier.  So something like:

#ifdef __SIZEOF_INT128__
/* use 64-bit arith */
#else
/* 32-bit */
#endif

(__int128 is a GNU extension also supported by Clang)

HTH.
Alexander

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux