Files
Sylpheed/tools/ppc-manual/memory/lwa.md
sim f3c512f2ab docs(ppc-manual): check every xenia-rs claim against Canary's source
The hand-written parts of the manual still described how the retired
xenia-rs interpreter behaved: its snapshots, Rust casts and helpers. Each of
those 490 statements is now either restated as what Canary's emitters and
x64 backend actually do (at the pinned canary_experimental commit), or
dropped where it only made sense for xenia-rs.

Checking them turned up claims that were wrong, not just outdated:

- VSCR[SAT] is never modelled in Canary (DID_SATURATE is a stub and mfvscr
  cannot see it); the pages said saturating ops set it stickily.
- Canary does not implement lswi/lswx/stswi/stswx, dcbi, mtfsb0/mtfsb1,
  vmsum*, vmhaddshs, vupkhpx/vupklpx, and most SPRs; pages described them
  as working.
- Traps evaluate TO in Canary; stvebx/stvehx/stvewx store one element, not
  16 bytes; mtmsrd writes only EE; fres/frsqrte/vrsqrtefp precision claims
  and the stfs "rounds under RN / sets FPSCR" claim contradicted the spec.
- Reservations are a 64 KiB block bitmap plus a value compare, not
  per-address tracking.

Claims that neither Canary's source nor a public spec settles are marked
unverified (NI at boot, vmaddcfp128 operand order, estimate bit-exactness).

Generated regions are untouched; re-running the generator changes nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 21:52:38 +02:00

9.1 KiB
Raw Permalink Blame History

lwa — Load Word Algebraic

Category: Memory · Form: DS · Opcode: 0xe8000002

Assembler Mnemonics

Mnemonic XML entry Flags Description
lwa lwa Load Word Algebraic
lwaux lwaux Load Word Algebraic with Update Indexed
lwax lwax Load Word Algebraic Indexed

Syntax

lwa [RD], [ds]([RA0])
lwaux [RD], [RA], [RB]
lwax [RD], [RA0], [RB]

Encoding

lwa — form DS

  • Opcode word: 0xe8000002
  • Primary opcode (bits 05): 58
  • Extended opcode:
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode
610 RT destination GPR (or RS)
1115 RA source GPR (0 ⇒ literal 0)
1629 DS 14-bit signed word-scaled displacement
3031 XO extended opcode

lwaux — form X

  • Opcode word: 0x7c0002ea
  • Primary opcode (bits 05): 31
  • Extended opcode: 373
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode
610 RT/FRT/VRT destination
1115 RA/FRA/VRA source A
1620 RB/FRB/VRB source B
2130 XO extended opcode (10 bits)
31 Rc record-form flag

lwax — form X

  • Opcode word: 0x7c0002aa
  • Primary opcode (bits 05): 31
  • Extended opcode: 341
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode
610 RT/FRT/VRT destination
1115 RA/FRA/VRA source A
1620 RB/FRB/VRB source B
2130 XO extended opcode (10 bits)
31 Rc record-form flag

Operands

Field Role Description
RA0 lwa: read; lwax: read Source GPR; when the encoded register number is 0 the operand is the literal 64-bit zero, not r0.
ds lwa: read 14-bit signed word-aligned displacement (DS << 2).
RD lwa: write; lwaux: write; lwax: write Destination GPR.
RA lwaux: read; lwaux: write Source GPR (r0r31).
RB lwaux: read; lwax: read Source GPR.

Register Effects

lwa

  • Reads (always): RA0, ds
  • Reads (conditional): none
  • Writes (always): RD
  • Writes (conditional): none

lwaux

  • Reads (always): RA, RB
  • Reads (conditional): none
  • Writes (always): RD, RA
  • Writes (conditional): none

lwax

  • Reads (always): RA0, RB
  • Reads (conditional): none
  • Writes (always): RD
  • Writes (conditional): none

Status-Register Effects

No condition-register or status-register effects.

Operation (pseudocode)

EA <- (RA|0) + EXTS(ds || 0b00)
RT <- SEXT32_to_64(MEM(EA, 4))

C Translation Example

/* No hand-written C yet. Translate the Canary emitter snapshot   */
/* under Implementation References; its HIR maps directly:        */
/*   f.LoadGPR(n) / f.StoreGPR(n, v)  -> r[n] / r[n] = v          */
/*   f.LoadFPR / StoreFPR, f.LoadVR / StoreVR -> f[n], v[n]        */
/*   f.Load(ea, T), f.Store(ea, v) -> raw read / write; emitters   */
/*     wrap them in f.ByteSwap for the big-endian guest value      */
/*   f.UpdateCR(n, v)  -> CR field n from v's LOW 32 BITS vs 0     */
/*   f.LoadCA / f.StoreCA -> xer.CA;  f.StoreSAT -> vscr.SAT       */
/*   i.XO.RA, i.D.DS, ... -> the bit-fields listed under Operands  */
/* The Register Effects and Status-Register Effects tables above  */
/* enumerate every side effect a faithful translation must emit.  */

Implementation References

lwa

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_lwa(PPCHIRBuilder& f, const InstrData& i) {
  // if RA = 0 then
  //   b <- 0
  // else
  //   b <- (RA)
  // EA <- b + EXTS(D || 00)
  // RT <- EXTS(MEM(EA, 4))
  Value* b;
  if (i.DS.RA == 0) {
    b = f.LoadZeroInt64();
  } else {
    b = f.LoadGPR(i.DS.RA);
  }

  Value* offset = f.LoadConstantInt64(XEEXTS16(i.DS.DS << 2));
  Value* rt =
      f.SignExtend(f.ByteSwap(f.LoadOffset(b, offset, INT32_TYPE)), INT64_TYPE);
  f.StoreGPR(i.DS.RT, rt);
  return 0;
}

lwaux

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_lwaux(PPCHIRBuilder& f, const InstrData& i) {
  // EA <- (RA) + (RB)
  // RT <- EXTS(MEM(EA, 4))
  // RA <- EA
  Value* ea = CalculateEA(f, i.X.RA, i.X.RB);
  Value* rt = f.SignExtend(f.ByteSwap(f.Load(ea, INT32_TYPE)), INT64_TYPE);
  f.StoreGPR(i.X.RT, rt);
  StoreEA(f, i.X.RA, ea);
  return 0;
}

lwax

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_lwax(PPCHIRBuilder& f, const InstrData& i) {
  // if RA = 0 then
  //   b <- 0
  // else
  //   b <- (RA)
  // EA <- b + (RB)
  // RT <- EXTS(MEM(EA, 4))
  Value* ea = CalculateEA_0(f, i.X.RA, i.X.RB);
  Value* rt = f.SignExtend(f.ByteSwap(f.Load(ea, INT32_TYPE)), INT64_TYPE);
  f.StoreGPR(i.X.RT, rt);
  return 0;
}

Special Cases & Edge Conditions

  • Sign-extending word load (32→64). Reads 4 bytes big-endian, treats them as a signed int32, sign-extends to 64 bits. Canary emits SignExtend(ByteSwap(LoadOffset(…, INT32)), INT64).
  • No lwau (D-form-update) in PowerISA. Only lwa (DS-form), lwax (X-form), and lwaux (X-form-update) exist. The D-form-update slot is occupied by something else in the encoding space — to update with a 16-bit immediate you must use a separate addi plus lwa.
  • DS-form displacement. Like ld, lwa uses a 14-bit signed displacement scaled by 4 (EXTS(ds || 0b00)). The two encoding bits 3031 distinguish lwa (XO=10) from ld (XO=00) and ldu (XO=01).
  • RA0 semantics. RA = 0 in lwa and lwax selects literal zero. lwaux invokes RA = 0 and RA = RT as invalid forms; Canary performs the load before writing back RA, so an RA = RT collision destroys the loaded value.
  • Alignment. Xenon tolerates unaligned 4-byte loads. PowerISA permits but does not require an alignment exception; some implementations may raise one for cache-inhibited storage.
  • Use lwa rather than lwz + extsw. When the source type is int32_t, lwa is one fused instruction.
  • Common in 64-bit code. Sign-extending 32-bit fields out of structures (e.g. signed file offsets) into 64-bit GPRs uses this family.
  • lwz, lwzu, lwzx, lwzux — zero-extending counterparts.
  • ld, ldu, ldx, ldux — 64-bit doubleword loads.
  • lha, lhax — 16-bit sign-extending loads.
  • lwbrx — byte-reversed word load (zero-extending only).
  • stw — corresponding store (no separate "store sign-extended" — narrow stores discard the high bits).

IBM Reference