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

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

 



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.



[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