gcc has a __builtin_bswap16, __builtin_bswap32, and __builtin_bswap64 which will presumably take advantage of these built-in instructions on x86 and any other gcc-supported architectures where similar instructions exist (and fall back to a reasonably fast and well-tested multi-instruction implementation where they don't).
You should really RTFM every couple years, just to know what your processor [1] and compiler [2] can do.
Comments
x86 has had the BSWAP instruction since the 486.
gcc has a __builtin_bswap16, __builtin_bswap32, and __builtin_bswap64 which will presumably take advantage of these built-in instructions on x86 and any other gcc-supported architectures where similar instructions exist (and fall back to a reasonably fast and well-tested multi-instruction implementation where they don't).
You should really RTFM every couple years, just to know what your processor [1] and compiler [2] can do.
[1] http://www.intel.com/content/www/us/en/processors/architectu...
[2] http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Oh, I RTFM. Not always working on Intel platforms though. And still:
http://hardwarebug.org/2010/01/14/beware-the-builtins/