rlwinm
rotates the value of a register left by the specified number, performs an AND
and stores the result in a register.
Example: rlwinm r3, r4, 5, 0, 31
r4
is the source register which is rotated by 5
and before the rotated result is placed in r3
, it is also AND
ed with a bit mask of only 1s since the interval between 0
and 31
is the entire 32-bit value.
Example taken from here.
For a C
implementation you may want to take a look at how to rotate left and how to AND
which should be trivial to build together now. Something like the following should work:
int rotateLeft(int input, int shift) {
return (input << shift) | ((input >> (32 - shift)) & ~(-1 << shift));
}
int rlwinm(int input, int shift, int mask) {
return rotateLeft(input, shift) & mask;
}