Does ARM GCC have a builtin function for the assem

2019-08-10 02:25发布

问题:

It's pretty common for compilers to have builtin intrinsic functions for processor features, but I'm having trouble finding them. Is there one to get at the 'REV' (reverse byte order of a word) instruction in ARM?

Where can I find the list of builtin functions?

回答1:

Is there one to get at the 'REV' (reverse byte order of a word) instruction in ARM?

There is a more 'portable' form that is available on all architectures. It is __builtin_bswap32. For example the compiler explorer has,

unsigned int foo(unsigned int a)
{
  return __builtin_bswap32(a);
}

Giving,

foo(unsigned int):
        rev     r0, r0
        bx      lr

This is better than __builtin_rev would be as it will only be available on certain ARM targets (and certainly only ARM CPUs). You can use __builtin_bswap32 even on PowerPC, x86, etc.



标签: gcc arm