The generator had not been able to run correctly since the manual moved into
`tools/ppc-manual/`: it computed the repository root as `HERE.parent.parent`,
which now names `tools/`, so the XML, Canary's emitters and xenia-rs all stopped
resolving — silently, because both scrapers skipped what they could not find.
Every page's references had been pointing at paths that exist nowhere.
What each source contributed, measured on the 350 pages before this change:
Operation (pseudocode) 251 pages: fixed boilerplate "derives from the xenia-rs
interpreter"; 99 carry real hand-written seeds
C translation 337 pages: the same kind of boilerplate
xenia-rs snapshot 336 pages: the interpreter arm, pasted in — the only
per-instruction semantics on unseeded pages
links xenia-rs opcode/decoder/interpreter + Canary emitter
Now:
* semantics come from **Xenia Canary**, the reference emulator, read through
`git show` at a pinned upstream commit (`origin/canary_experimental`,
f21ebd49e9). Not our checkout: it carries instrumentation and lacked
upstream's `mcrf` fix, so it would have published probes and a wrong `mcrf`.
Each page embeds the emitter (`InstrEmit_<mnem>`), and for the 128 pure
one-line delegations also the helper that holds the semantics.
* decode references point at `crates/sylpheed-ppc` — the decoder that
produces `sylpheed.db` — as in-repo relative links.
* the boilerplate now says what is true, and the C translation guide maps
Canary's actual HIR calls, checked against `ppc_hir_builder.h` (including
that `UpdateCR(n, v)` truncates to 32 bits).
* `rust_scraper.py` -> `decoder_scraper.py` (interpreter half dropped);
missing sources are now errors, not empty results.
Verified:
consistency checks 455 XML entries, 350 families, 598 index keys
hand-written tails 386/386 byte-identical after regeneration
xenia-rs in generated 0
pages with a snapshot 349/350 (was 336) — `dcbi` has no Canary emitter at all
in-repo decoder links 910/910 resolve to a line holding the identifier
emitter boundaries brace counter == column-0 `}` rule on 521/521;
preprocessor model unit-tested (#if 0/#else/#elif)
idempotency re-run: 0 pages updated, 0 working-tree changes
Hand-written notes (outside the generated regions) are not rewritten here:
* 110 links into `../../xenia-rs/...` were dead; they now point at the file in
the archived repository (git.mc02.dev/fabi/xenia-rs @ 8401d4d). Line anchors
were dropped because the notes predate that commit — 0 of 441 old line
ranges match it — and a precise-looking wrong anchor is worse than none. The
link text, which carries the author's line numbers, is unchanged.
* 140 prose claims about xenia-rs's behaviour remain. 23 are verified to hold
for Canary too (the 32-bit CR0 truncation, OE left unimplemented); the other
114 need checking one by one, and some invert — e.g. `divdx` notes a correct
64-bit CR0 update in xenia-rs where Canary's `UpdateCR` truncates. Left for
a deliberate pass rather than a blind substitution.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9.1 KiB
9.1 KiB
lwa — Load Word Algebraic
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 0–5):
58 - Extended opcode: —
- Synchronising: no
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode |
| 6–10 | RT |
destination GPR (or RS) |
| 11–15 | RA |
source GPR (0 ⇒ literal 0) |
| 16–29 | DS |
14-bit signed word-scaled displacement |
| 30–31 | XO |
extended opcode |
lwaux — form X
- Opcode word:
0x7c0002ea - Primary opcode (bits 0–5):
31 - Extended opcode:
373 - Synchronising: no
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode |
| 6–10 | RT/FRT/VRT |
destination |
| 11–15 | RA/FRA/VRA |
source A |
| 16–20 | RB/FRB/VRB |
source B |
| 21–30 | XO |
extended opcode (10 bits) |
| 31 | Rc |
record-form flag |
lwax — form X
- Opcode word:
0x7c0002aa - Primary opcode (bits 0–5):
31 - Extended opcode:
341 - Synchronising: no
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode |
| 6–10 | RT/FRT/VRT |
destination |
| 11–15 | RA/FRA/VRA |
source A |
| 16–20 | RB/FRB/VRB |
source B |
| 21–30 | 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 (r0–r31). |
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 XML:
tools/ppc-instructions.xml— search formnem="lwa" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_memory.cc:244 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:157 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:497
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 XML:
tools/ppc-instructions.xml— search formnem="lwaux" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_memory.cc:265 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:159 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:919
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 XML:
tools/ppc-instructions.xml— search formnem="lwax" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_memory.cc:276 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:160 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:915
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. The xenia snapshot does the cast chain
u32 -> i32 -> i64 -> u64to materialise the canonical sign-extended bit pattern. - No
lwau(D-form-update) in PowerISA. Onlylwa(DS-form),lwax(X-form), andlwaux(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 separateaddipluslwa. - DS-form displacement. Like
ld,lwauses a 14-bit signed displacement scaled by 4 (EXTS(ds || 0b00)). The two encoding bits 30–31 distinguishlwa(XO=10) fromld(XO=00) andldu(XO=01). RA0semantics.RA = 0inlwaandlwaxselects literal zero.lwauxinvokesRA = 0andRA = RTas invalid forms; xenia performs the load before writing backRA, so anRA = RTcollision 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
lwarather thanlwz+extsw. When the source type isint32_t,lwais 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.
Related Instructions
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).