nisse@lysator.liu.se (Niels Möller) writes:
I think current gcc may recognize (x << n) | (x >> (wordsize - n)) and generate a rotate instruction (but I haven't tested).
Now I have tested. gcc 4.4.5 seems to recognize it, even without optimization.
Test program:
#include <stdint.h>
uint32_t rot32(uint32_t x, int k) { return (x << k) | (x >> (32-k)); }
uint32_t rot64(uint64_t x, int k) { return (x << k) | (x >> (64-k)); }
Compile with gcc -S -O0, and examine the generated assembler.
Regards, /Niels