Detect whether we have a native 64-bit type?
Mason
slash.tmp@free.fr
Wed Apr 27 15:33:00 GMT 2016
On 26/04/2016 00:19, 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.
>
> My specific motivation is the Opus audio codec, which has code like:
>
> /* (a32 * (b32 >> 16)) >> 16 */
> #if OPUS_FAST_INT64
> #define silk_SMULWT(a32, b32) ((opus_int32)(((a32) * (opus_int64)((b32) >> 16)) >> 16))
> #else
> #define silk_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
> #endif
GCC is smart enough that casting an uint32_t to uint64_t will signal
one's intent to use a 32x32->64 widening multiply instruction, when
one is available.
Are you concerned about platforms that don't have such an instruction?
(Which platforms?)
It's not obvious to me what you are saving by, in essence, doing
the compiler's job in the bottom macro?
e.g. on the x86
$ cat mul.c
typedef unsigned int u32;
typedef unsigned long long u64;
u32 silk_SMULWT(u32 a32, u32 b32) {
return ((u64)a32 * (b32 >> 16)) >> 16;
}
$ gcc -m32 -Os -S -fomit-frame-pointer mul.c
silk_SMULWT:
movzwl 10(%esp), %eax
mull 4(%esp)
shrdl $16, %edx, %eax
ret
Regards.
More information about the Gcc-help
mailing list