Files
Sylpheed/tools/ppc-manual/fpu/fctidzx.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

6.4 KiB
Raw Permalink Blame History

fctidzx — Floating Convert to Integer Doubleword with Round Toward Zero

Category: Floating-Point · Form: X · Opcode: 0xfc00065e

Assembler Mnemonics

Mnemonic XML entry Flags Description
fctidz fctidzx Floating Convert to Integer Doubleword with Round Toward Zero
fctidz. fctidzx Rc=1 Floating Convert to Integer Doubleword with Round Toward Zero

Syntax

fctidz[Rc] [FD], [FB]

Encoding

fctidzx — form X

  • Opcode word: 0xfc00065e
  • Primary opcode (bits 05): 63
  • Extended opcode: 815
  • 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
FB fctidzx: read Source B floating-point register.
FD fctidzx: write Destination floating-point register.
CR fctidzx: write (conditional) Condition-register update. When Rc=1, CR field 0 (or CR6 for vector compares, CR1 for FPU) is updated from the result.
FPSCR fctidzx: write Floating-Point Status and Control Register.

Register Effects

fctidzx

  • Reads (always): FB
  • Reads (conditional): none
  • Writes (always): FD, FPSCR
  • Writes (conditional): CR

Status-Register Effects

  • fctidzx: CR0 ← signed-compare(result, 0) with SO ← XER[SO], when Rc=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

fctidzx

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_fctidzx(PPCHIRBuilder& f, const InstrData& i) {
  return InstrEmit_fctidxx_(f, i, ROUND_TO_ZERO);
}

// ── delegates to (src/xenia/cpu/ppc/ppc_emit_fpu.cc:261) ──
int InstrEmit_fctidxx_(PPCHIRBuilder& f, const InstrData& i,
                       RoundMode round_mode) {
  auto end = f.NewLabel();
  auto isnan = f.NewLabel();
  Value* v;
  f.BranchTrue(f.IsNan(f.LoadFPR(i.X.RB)), isnan);
  v = f.Convert(f.LoadFPR(i.X.RB), INT64_TYPE, round_mode);
  v = f.Cast(v, FLOAT64_TYPE);
  f.StoreFPR(i.X.RT, v);
  f.UpdateFPSCR(v, i.X.Rc);
  f.Branch(end);
  f.MarkLabel(isnan);
  v = f.Cast(f.LoadConstantUint64(0x8000000000000000u), FLOAT64_TYPE);
  f.StoreFPR(i.X.RT, v);
  f.UpdateFPSCR(v, i.X.Rc);
  f.MarkLabel(end);
  return 0;
}

Special Cases & Edge Conditions

  • binary64 → 64-bit signed integer, round toward zero. The "z" suffix forces truncation regardless of FPSCR[RN]. Canary passes ROUND_TO_ZERO, which its x64 backend emits as cvttsd2si — matching PPC fctidz semantics.
  • Saturation on out-of-range. PowerPC saturates: +∞ or a large positive → 0x7FFF_FFFF_FFFF_FFFF, −∞ or a large negative → 0x8000_0000_0000_0000, both setting FPSCR[VXCVI, VX, FX]. Canary's x64 backend reproduces both values — cvttsd2si yields 0x8000… on any overflow and a fix-up turns it into 0x7FFF… when the input was non-negative — but raises no FPSCR bits (UpdateFPSCR is a stub).
  • NaN. Returns sentinel 0x8000_0000_0000_0000 (matches PPC).
  • Inexact. Sets FPSCR[XX, FX] on any non-integer input on hardware; Canary raises no FPSCR bits (UpdateFPSCR is a stub).
  • No FPSCR[RN] dependence. fctidz always truncates; this is the right choice for C/C++ (int64_t) casts.
  • Rc=1 (fctidz.) copies FPSCR[FX, FEX, VX, OX] into CR1.
  • Encoding. X-form, primary 63, XO 815. Reads FRB only.
  • Common pairing. Translation of C (int64_t)d casts; combined with stfd to move the value to integer memory.
  • fctidx — same conversion but uses FPSCR[RN] (default nearest-even), which Canary honours through the rounding mode mtfsf/mtfsfi set.
  • fctiwzx — 32-bit truncating variant.
  • fctiwx — 32-bit FPSCR[RN]-rounded variant.
  • fcfidx — inverse direction.
  • stfd — store the integer-bits FPR to memory.

IBM Reference