Skip to content

ps2xRuntime: reduce VU1 interpreter overhead - #278

Closed
anxiousintrovert wants to merge 1 commit into
ran-j:mainfrom
anxiousintrovert:pr/vu1-interpreter-performance
Closed

anxiousintrovert wants to merge 1 commit into
ran-j:mainfrom
anxiousintrovert:pr/vu1-interpreter-performance

Conversation

@anxiousintrovert

Copy link
Copy Markdown

Summary

Reduce CPU overhead in the VU1 interpreter. In Holyland's first 3D-area measurements, VU1 dominates the EE thread and is the main remaining frame-rate limit. This change improves the interpreter itself; it does not claim to solve the complete game frame-rate issue.

Related context: Holyland performance issue #1.

Changes

  • Precompute VF/VI/ACC read and write hazard slots in decoded instruction pairs instead of reconstructing dependencies on each issue.
  • Write interlocked VF/VI/ACC results immediately and track their ready cycles, avoiding delayed writeback copies while preserving instruction stalls and program-end cycle timing.
  • Track occupied pipeline slots with bitmasks and the earliest pending commit cycle, so idle cycles skip unnecessary scans while commits retain slot order.
  • Reduce exact FMAC flag work when the rounded result proves the classification; retain exact double handling and a long-double fallback for the boundary case.
  • Normalize vector operands with SSE4.1 where available and reuse cached decoded pairs by reference.
  • Copy XGKICK data a qword at a time.

The measured VU1 interpreter speedup for this change was about 2.3x. This is interpreter speed, not a 2.3x whole-game frame-rate claim.

Verification

  • Compared against the frozen original interpreter for 720,000 VU1 microprogram runs into gameplay: zero mismatches in registers, flags, cycle counts, VU1 memory, or XGKICK output.
  • Built the ps2_runtime target from current upstream main on Windows with MSVC (RelWithDebInfo).
  • git diff --check passes.

No ROM, generated game code, captures, or other game data is included. The current-upstream validation here is a runtime-library build; a complete game run requires the maintainer's local generated game files.

The VU1 interpreter was ~90% of the frame in KFIV's 3D areas. Same
cycle and flag model, cheaper bookkeeping:

- Hazards: each decoded pair carries the ready-time slots it reads and
  writes (VF lanes, VI, ACC in one array), instead of re-deriving them
  from the usages with nested loops on every issue.
- VF/VI/ACC results are written back at issue. These registers are
  interlocked: every reader already stalls until the write's latency has
  elapsed, so the delayed write-back pipelines (and their copy-out /
  restore per instruction) could never be observed. A program still ends
  only once its last write would have landed (write-back horizon), so
  cycle counts are unchanged. Flags, Q, P and stores keep their pipelines.
- Pipelines track occupied slots in bitmasks and the earliest pending
  commit, so cycles with nothing due skip the commit scan, idle cycles are
  skipped, and commits still run in slot order.
- FMAC flags: a single-rounding (toward zero) result that is normal and
  below FLT_MAX can only report its sign, so the exact recomputation is
  skipped; ADD/SUB results that round to zero are exactly zero. Otherwise
  the exact result is computed in double, which classifies like the long
  double (a float product is exact in double); a sum that lands exactly on
  FLT_MAX still takes the long double. Operands are decoded once per
  instruction and normalized with SSE4.1 where available.
- XGKICK copies a qword at a time; decoded pairs are used by reference.

Verified by running the original interpreter in lockstep on every
microprogram of a KFIV session (720k runs into gameplay): registers,
flags, cycle counts, VU1 memory and XGKICK output identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants