rlwimi
Rotate Left Word Immediate Then Mask Insert
rlwimi RA, RS, SH, MB, ME
Rotates a word left, then inserts bits into the target under a mask. Used for inserting bitfields.
Encoding
Binary Layout
20
0:5
RS
6:10
RA
11:15
SH
16:20
MB
21:25
ME
26:31
Operands
-
RA
Target/Dest -
RS
Source -
SH
Shift -
MB
Mask Begin -
ME
Mask End
Example
rlwimi r4, r3, 3, 0, 31
Related
More in Base
Reference
View in PowerISA v3.1C Specification ↗
OPF Power ISA v3.1C
Description
Rotates the contents of RS left by SH bit positions, creates a mask from bits MB through ME, and inserts the rotated value into RA under that mask, leaving other bits in RA unchanged. The condition register CR0 is updated if Rc=1.
Operation
n ← SH
mask ← MASK(MB, ME)
rotated ← ROTL32(RS, n)
RA ← (RA & ¬mask) | (rotated & mask)
if Rc = 1 then CR0 ← (RA < 0, RA > 0, RA = 0, SO)
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.