Detect whether we have a native 64-bit type?

Alexander Monakov amonakov@ispras.ru
Wed Apr 27 14:44:00 GMT 2016


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


More information about the Gcc-help mailing list