|
|
|
|
|
by robomartin
4707 days ago
|
|
If you've ever dealt with graphics file manipulation code chances are you've suffered the pain of changing the endian-ness of an image file. I never understood why some of these operations are not implemented as machine instructions that can run in one instruction cycle flat. There's nothing to them, I've done exactly that on FPGA's. Yes, they can be a little resource/routing intensive but not that bad. |
|
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