Your C compiler almost certainly recognizes this idiom and compiles it to a single processor instruction.
unsigned int x, y;
y = (x << shift) | (x >> (sizeof(x)*8 - shift));
What instruction is that ?
C doesn`t have instruction to binary rotate variable, only to binary shift. But we can use this idiom to make binary rotate.
ReplyDeleteIn assembler code on Intel arch it is rol instruction, rotate dest register to the left