Files
Sylpheed/tools/ppc-manual/vmx/vcmpbfp.md
sim 84856fc081
All checks were successful
CI / Native — linux (pull_request) Successful in 2h1m57s
CI / WASM — Web (pull_request) Successful in 28m8s
CI / Formatting (pull_request) Successful in 1m26s
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

8.8 KiB
Raw Blame History

vcmpbfp — Vector Compare Bounds Floating Point

Category: VMX (Altivec) · Form: VC · Opcode: 0x100003c6

Assembler Mnemonics

Mnemonic XML entry Flags Description
vcmpbfp vcmpbfp Vector Compare Bounds Floating Point
vcmpbfp. vcmpbfp Rc=1 Vector Compare Bounds Floating Point
vcmpbfp128 vcmpbfp128 Vector128 Compare Bounds Floating Point
vcmpbfp128. vcmpbfp128 Rc=1 Vector128 Compare Bounds Floating Point

Syntax

vcmpbfp[Rc] [VD], [VA], [VB]
vcmpbfp128[Rc] [VD], [VA], [VB]

Encoding

vcmpbfp — form VC

  • Opcode word: 0x100003c6
  • Primary opcode (bits 05): 4
  • Extended opcode: 966
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode (4)
610 VRT destination vector register
1115 VRA source A
1620 VRB source B
21 Rc record-form flag (updates CR6)
2231 XO extended opcode (10 bits)

vcmpbfp128 — form VX128_R

  • Opcode word: 0x18000180
  • Primary opcode (bits 05): 6
  • Extended opcode: 384
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode (4)
610 VD128l destination low 5 bits
1115 VA128l source A low 5 bits
1620 VB128l source B low 5 bits
21 VA128H source A high bit
2225 XO extended opcode (compare)
26 VA128h source A middle bit
27 Rc record-form flag (updates CR6)
2829 VD128h destination high 2 bits
3031 VB128h source B high 2 bits

Operands

Field Role Description
VA vcmpbfp: read; vcmpbfp128: read Source A vector register.
VB vcmpbfp: read; vcmpbfp128: read Source B vector register.
VD vcmpbfp: write; vcmpbfp128: write Destination vector register.
CR vcmpbfp: write (conditional); vcmpbfp128: 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

vcmpbfp

  • Reads (always): VA, VB
  • Reads (conditional): none
  • Writes (always): VD
  • Writes (conditional): CR

vcmpbfp128

  • Reads (always): VA, VB
  • Reads (conditional): none
  • Writes (always): VD
  • Writes (conditional): CR

Status-Register Effects

  • vcmpbfp: CR6[all-true, 0, all-false, 0] when Rc=1.
  • vcmpbfp128: CR6[all-true, 0, all-false, 0] when Rc=1.

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

vcmpbfp

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_vcmpbfp(PPCHIRBuilder& f, const InstrData& i) {
  return InstrEmit_vcmpbfp_(f, i, i.VXR.VD, i.VXR.VA, i.VXR.VB, i.VXR.Rc);
}

// ── delegates to (src/xenia/cpu/ppc/ppc_emit_altivec.cc:561) ──
int InstrEmit_vcmpbfp_(PPCHIRBuilder& f, const InstrData& i, uint32_t vd,
                       uint32_t va, uint32_t vb, uint32_t rc) {
  // if vA or vB are NaN, the 2 high-order bits are set (0xC0000000)
  Value* va_value = f.LoadVR(va);
  Value* vb_value = f.LoadVR(vb);
  Value* gt = f.VectorCompareSGT(va_value, vb_value, FLOAT32_TYPE);
  Value* lt =
      f.Not(f.VectorCompareSGE(va_value, f.Neg(vb_value), FLOAT32_TYPE));
  Value* v =
      f.Or(f.And(gt, f.LoadConstantVec128(vec128i(0x80000000, 0x80000000,
                                                  0x80000000, 0x80000000))),
           f.And(lt, f.LoadConstantVec128(vec128i(0x40000000, 0x40000000,
                                                  0x40000000, 0x40000000))));
  f.StoreVR(vd, v);
  if (rc) {
    // CR0:4 = 0; CR0:5 = VT == 0; CR0:6 = CR0:7 = 0;
    // If all of the elements are within bounds, CR6[2] is set
    // FIXME: Does not affect CR6[0], but the following function does.
    f.UpdateCR6(f.Or(gt, lt));
  }
  return 0;
}

vcmpbfp128

Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_vcmpbfp128(PPCHIRBuilder& f, const InstrData& i) {
  return InstrEmit_vcmpbfp_(f, i, VX128_R_VD128, VX128_R_VA128, VX128_R_VB128,
                            i.VX128_R.Rc);
}

Special Cases & Edge Conditions

  • "Bounds" compare, not equality. Per word lane, sets two output bits: bit 0 (mask 0x80000000) if VA[i] > VB[i] (out-of-range high) and bit 1 (mask 0x40000000) if VA[i] < -VB[i] (out-of-range low). Bits 2..31 of each lane are zero.
  • NaN inputs. The IBM manual treats NaN as violating both bounds (0xC0000000), and Canary's comment says the same, but its code sets only 0x40000000: the "greater than" test is vcmpgtps (false for NaN) and only the "not ≥ VB" test comes out true. Canary quirk for NaN inputs.
  • CR6 update when Rc=1. CR6 is set as [lt=0, gt=0, eq=(no-lane-out-of-range), so=0] — i.e. only the eq bit signifies "all four lanes were within ±VB". Useful as bc 12,26 (branch if all in-range) for SIMD clamping loops.
  • No VSCR[SAT], no XER changes, no exceptions.
  • The convention is "is point inside box?" — not a per-lane compare like the other vcmp* ops. Output is a flag-pair, not a boolean mask, so it does not plug directly into vsel. To get a boolean, OR the two bits down with vor and a shift.
  • VMX128 sibling (vcmpbfp128). Identical semantics; the Rc bit lives at bit 27 of the VX128_R encoding.
  • Lane width is fixed at word. Bounds check is single-precision float only; there is no vcmpb* for half / byte / int.
  • vcmpeqfp — element-wise == for floats.
  • vcmpgtfp, vcmpgefp — element-wise > and >= for floats.
  • vsel, vand, vor — combine the two bits per lane into a boolean mask if needed.
  • vmaxfp, vminfp — clamp values to a range without testing.

IBM Reference