Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ARM GCC have a builtin function for the assembly 'REV' instruction?

Tags:

gcc

arm

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?

like image 799
joeforker Avatar asked Oct 25 '25 06:10

joeforker


1 Answers

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.

like image 67
artless noise Avatar answered Oct 27 '25 01:10

artless noise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!