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>
6.7 KiB
6.7 KiB
mtfsfx — Move to FPSCR Fields
Category: Control / CR / SPR · Form: XFL · Opcode:
0xfc00058e
Assembler Mnemonics
| Mnemonic | XML entry | Flags | Description |
|---|---|---|---|
mtfsf |
mtfsfx |
— | Move to FPSCR Fields |
mtfsf. |
mtfsfx |
Rc=1 | Move to FPSCR Fields |
Syntax
mtfsf[Rc] [FM], [FB]
Encoding
mtfsfx — form XFL
- Opcode word:
0xfc00058e - Primary opcode (bits 0–5):
63 - Extended opcode:
711 - Synchronising: no
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode (63) |
| 6 | L |
field-select behaviour |
| 7–14 | FM |
FPSCR field mask |
| 15 | W |
immediate-value flag |
| 16–20 | FRB |
source FPR |
| 21–30 | XO |
extended opcode |
| 31 | Rc |
record-form flag (updates CR1) |
Operands
| Field | Role | Description |
|---|---|---|
FM |
mtfsfx: read | 8-bit FPSCR field-mask used by mtfsf. |
FB |
mtfsfx: read | Source B floating-point register. |
FPSCR |
mtfsfx: write | Floating-Point Status and Control Register. |
CR |
mtfsfx: write (conditional) | Condition-register update. When Rc=1, CR field 0 (or CR6 for vector compares, CR1 for FPU) is updated from the result. |
Register Effects
mtfsfx
- Reads (always):
FM,FB - Reads (conditional): none
- Writes (always):
FPSCR - Writes (conditional):
CR
Status-Register Effects
mtfsfx: CR1 ← FPSCR[FX, FEX, VX, OX] whenRc=1.; FPSCR updated per IEEE-754 flags (FX, FEX, FPRF, FR, FI, exceptions).
Operation (pseudocode)
; No hand-written pseudocode for this instruction yet.
; The authoritative semantics are the Canary emitter snapshot under
; Implementation References; about half of Canary's emitters open
; with the PPC-style definition as a comment (`RD <- (RA) + (RB)`).
; Every side effect is also enumerated in the Register Effects and
; Status-Register Effects tables above.
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
mtfsfx
- Canary XML:
tools/ppc-instructions.xml— search formnem="mtfsfx" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_fpu.cc:416 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:182 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:1026
Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_mtfsfx(PPCHIRBuilder& f, const InstrData& i) {
if (i.XFL.L) {
// Move/shift.
f.StoreFPSCR(
f.Truncate(f.Cast(f.LoadFPR(i.XFL.RB), INT64_TYPE), INT32_TYPE));
return 1;
} else {
assert_zero(i.XFL.W);
// Store under control of mask.
// Expand the mask from 8 bits -> 32 bits.
uint32_t mask = 0;
for (int j = 0; j < 8; j++) {
if (i.XFL.FM & (1 << (j ^ 7))) {
mask |= 0xF << (4 * j);
}
}
Value* v = f.Truncate(f.Cast(f.LoadFPR(i.XFL.RB), INT64_TYPE), INT32_TYPE);
if (mask != 0xFFFFFFFF) {
Value* fpscr = f.LoadFPSCR();
v = f.And(v, f.LoadConstantInt32(mask));
v = f.Or(v, f.And(fpscr, f.LoadConstantInt32(~mask)));
}
f.StoreFPSCR(v);
// Update the system rounding mode.
if (mask & 0x7) {
f.SetRoundingMode(f.And(v, f.LoadConstantInt32(7)));
}
}
if (i.XFL.Rc) {
f.CopyFPSCRToCR1();
}
return 0;
}
Special Cases & Edge Conditions
FMis an 8-bit field-mask. Each of the eight bits selects one 4-bit FPSCR field (0..7).FM[0](0x80) selects FPSCR field 0 (bits 0..3 = FX, FEX, VX, OX), …,FM[7](0x01) selects FPSCR field 7 (rounding-mode bits RN). Set bits cause that field ofFRB's low 32 bits to overwrite the corresponding FPSCR field; clear bits leave the field unchanged.- Source is the LOW 32 bits of
FRB. The high 32 bits are ignored. Software that wants to write a 32-bit pattern typically constructs it in a GPR, stores to memory, and reloads as a double vialfd. - Most common use: setting rounding mode. Compilers wrap calls to
<fenv.h>-style functions withmtfsf 1, fXto update only the rounding-mode field (RN, FPSCR field 7). Rc=1updates CR1.mtfsf.copies FPSCR's top 4 bits (FX, FEX, VX, OX) into CR1 after the write.L/Wbits. PowerISA v2.05+ addsL=1to mean "write all FPSCR bits regardless of FM" andW=1to select the upper or lower 32 bits. Canary handlesL=0; itsL=1path writes FPSCR but still reports the instruction as unimplemented, andWis only asserted to be zero.- Canary behaviour. Canary applies the field mask correctly and, when the mask covers
RN, reloads the host rounding mode, so conversions and arithmetic that round follow the new mode. The exception bits are another matter: Canary'sUpdateFPSCRis a stub, so they are never set by FP arithmetic. - Not synchronising. Reorderable; PowerISA recommends an
isyncafter FPSCR changes that affect subsequent FP behaviour.
Related Instructions
mtfsfix— write a 4-bit immediate into one FPSCR field (no FPR source needed).mtfsb0x,mtfsb1x— single-bit FPSCR write.mffsx— read FPSCR into an FPR.mcrfs— copy FPSCR field → CR field.
mtfsf is the simplified form (Rc=0); mtfsf. is the recording variant.
IBM Reference
- AIX 7.3 —
mtfsf(Move to FPSCR Fields) - PowerISA v2.07B, Book I §4.6.6 —
mtfsfdefinition andL/Wextensions.