extlwi

Extract and Left Justify Immediate

extlwi ra,rs,n,b (n > 0)

Extracts a specified number of bits from the source register, left-justifies them, and places them in the target register.

Encoding

Binary Layout
18
0:5
LI
6:29
AA
30
LK
31
 
Format XO-form
Opcode 0x54000000
Extension Base

Operands

  • ra
    Target General Purpose Register
  • rs
    Source General Purpose Register
  • n
    Number of bits to extract (must be greater than 0)
  • b
    Starting bit position for extraction

Example

extlwi ra, rs, n, b (n > 0)

Related

More in Base

Reference

Description

Extracts n bits starting at bit position b from GPR rs, left-justifies them in the target GPR ra, and zeros the remaining bits. This is a pseudo-instruction (alias) for rlwimi with specific parameters and operates in 32-bit mode. The instruction updates CR0 if the record bit (Rc) is set.

Operation

mask ← MASK(0, n-1)
ra ← (rs >> b) & mask
ra ← ra << (32 - n)
if Rc then CR0 ← record_cr(ra) endif

Extended Mnemonics

Extended Mnemonic Equivalent Instruction

Programming Note

The extlwi instruction is useful for extracting a specific bit field from a source register and left-justifying it in the target register. Ensure that the bit positions 'b' and 'n' are correctly specified to avoid data corruption. The operation preserves or rotates the high-order bits of the target register, so be aware of this behavior if you need to maintain specific register contents.