rlwimi
Rotate Left Word Immediate Then Mask Insert
Rotates a word left, then inserts bits into the target under a mask. Used for inserting bitfields.
Details
The rlwimi instruction rotates the contents of the low-order 32 bits of register RS left by SH bits. It then generates a mask with 1-bits from bit MB+32 through bit ME+32 and ANDs the rotated data with this mask. The result is inserted into the low-order 32 bits of register RA, preserving the high-order 32 bits of RA.
Pseudocode Operation
Programming Note
The rlwimi instruction is commonly used for bit manipulation tasks such as rotating bits and selectively inserting them into a register. Be cautious with the shift amount (SH), mask bits (MB and ME), and ensure they are within valid ranges to avoid unexpected results. This instruction operates at user privilege level and does not generate exceptions under normal conditions, but improper use can lead to data corruption.
Example
Encoding
Operands
-
RA
Target/Dest -
RS
Source -
SH
Shift -
MB
Mask Begin -
ME
Mask End