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

The lwarx instruction loads a word from memory into a target general-purpose register (RT) and reserves the storage location for exclusive access. The effective address is calculated by adding the contents of the base register (RA) to the offset specified in the immediate field (D).

Pseudocode Operation

if RA = 0 then b ←0
else           b ←(RA)
EA ←b +(RB)
RESERVE ←1
RESERVE_LENGTH ←4
RESERVE_ADDR ←real_addr(EA)
RT ←320 || MEM(EA, 4)

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

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