lwarx

Load Word and Reserve Indexed

lwarx RT,RA,D
lwarx EH=0 RT,RA,D
lwarx EH=1 RT,RA,D

Loads a word and creates a reservation for use with 'stwcx.'. Critical for implementing atomic primitives (mutexes).

Details

Loads a 32-bit word from memory at address (RA + RB) and places it into RT, and creates a reservation on that cache line for atomic updates with stwcx. The optional EH field (bit 31) provides a hint about the expected success of a subsequent conditional store. This instruction is critical for implementing atomic operations and locks. No condition or status registers are modified by this instruction itself.

Pseudocode Operation

EA ← (RA) + (RB)
RT ← sign_extend([EA+3:EA])
RESERVATION_VALID ← 1
RESERVATION_ADDR ← page_address(EA)
// EH field (bit 31) is a hint for subsequent stwcx.

Programming Note

EH = 0 should be used when all accesses to a mutex variable are performed using an instruction sequence with Load And Reserve followed by Store Conditional. EH = 1 should be used when the program is obtaining a lock variable which it will subsequently release before another program attempts to perform a store to it.

Extended Mnemonics

Extended Mnemonic Equivalent Instruction
lwarx

Example

lwarx r3, 0, r4

// Start atomic read-modify-write.

Encoding

Binary Layout
31
0
RT
6
RA
11
RB
16
20
21
EH
31
 
Format X-form
Opcode 0x7C000028
Extension Base
Registers Altered XER, LR

Operands

  • RT
    Target Register
  • RA
    Base Register
  • RB
    Index Register
  • D
    Immediate Displacement
  • EH
    Hint for subsequent store operation