rlwinm r5, r4, 3, 2, 30
r4 = source register ofc
r4's value is rotated to the left by 3 bits, (rotate each bit counter clockwise by the value of 3).
Bit 0 rotated to the left by value of 3 is now Bit 29
Bit 1 is now Bit 30
Bit 2 is now Bit 31
Bit 3 is now Bit 0
Bit 4 is now Bit 1
Bit 5 is now Bit 2
etc etc
Now you have a temporary rotated value
MB is the start of the ANDing mask, while ME is the end
2 is the start, 30 is the end
in binary that is a mask of 0011 1111 1111 1111 1111 1111 1111 1110
so in hex that's 0x3FFFFFFE
You take the temporary rotated value and AND it with 0x3FFFFFFE
w/e final result that is now goes into r5, and voila that's a rlwinm instruction
---
and as seeky mentioned earlier, the ME value can be lower than MB so the AND mask will 'loop' around clockwise
i.e. rlwinm r0, r31, 7, 29, 3 #This in binary is 1111 0000 0000 0000 0000 0000 0000 0111 (0xF0000007)
---
So the rotation is counter clockwise while the AND mask works in a clockwise fashion
r4 = source register ofc
r4's value is rotated to the left by 3 bits, (rotate each bit counter clockwise by the value of 3).
Bit 0 rotated to the left by value of 3 is now Bit 29
Bit 1 is now Bit 30
Bit 2 is now Bit 31
Bit 3 is now Bit 0
Bit 4 is now Bit 1
Bit 5 is now Bit 2
etc etc
Now you have a temporary rotated value
MB is the start of the ANDing mask, while ME is the end
2 is the start, 30 is the end
in binary that is a mask of 0011 1111 1111 1111 1111 1111 1111 1110
so in hex that's 0x3FFFFFFE
You take the temporary rotated value and AND it with 0x3FFFFFFE
w/e final result that is now goes into r5, and voila that's a rlwinm instruction
---
and as seeky mentioned earlier, the ME value can be lower than MB so the AND mask will 'loop' around clockwise
i.e. rlwinm r0, r31, 7, 29, 3 #This in binary is 1111 0000 0000 0000 0000 0000 0000 0111 (0xF0000007)
---
So the rotation is counter clockwise while the AND mask works in a clockwise fashion