This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Detect whether we have a native 64-bit type?
- From: Mason <slash dot tmp at free dot fr>
- To: Jonathan Lennox <jonathan at vidyo dot com>
- Cc: GCC help <gcc-help at gcc dot gnu dot org>, Sebastian Frias <sf84 at laposte dot net>
- Date: Wed, 27 Apr 2016 17:32:54 +0200
- Subject: Re: Detect whether we have a native 64-bit type?
- Authentication-results: sourceware.org; auth=none
- References: <868BAC2D-4FD6-4656-8719-8D01B332FBD8 at vidyo dot com>
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.