Skip to content

shader, docs: keep GFX10.1 legacy MAD/MAC names - #71

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:shader/legacy-mad-mac
Nov 25, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:shader/legacy-mad-mac

Conversation

@PrivacyOnion

Copy link
Copy Markdown
Contributor

What and why

Resolves the legacy MAD/MAC question of #64 (the decoder gaps were filled by #68). XTP keeps v_mad_legacy_f32 at VOP3 0x140 and v_mac_legacy_f32 at VOP2 0x006 (and its e64 form): unfused, with the legacy rule 0 × x = +0.

Evidence:

  • In LLVM 19.1.7, V_MAD_LEGACY_F32 (0x140) and V_MAD_F32 (0x141) sit under the same predicate, HasMadMacF32Insts, and V_MAC_F32 is gated on it too. V_FMA_LEGACY_F32 and V_FMAC_LEGACY_F32 need HasFmaLegacy32 (GFX10.3 instructions) and are decoded only in the GFX10_B namespace (VOP3Instructions.td, VOP2Instructions.td).
  • In AMDGPU.td, the GFX10.1 targets have FeatureMadMacF32Insts and gfx1030 does not. gfx1013 is GFX10.1 plus FeatureGFX10_AEncoding ("Has BVH ray tracing instructions"), and it is the only target with both.
  • The title's programs, counted with XTP's own decoder, use both feature sets. A GFX10.3 decoder would have no v_mad_f32 or v_mac_f32 at all.
Instruction Uses
v_mad_f32 (VOP3 0x141) 139,287
v_mac_f32 250,033
v_madak_f32 8,444
image_bvh_intersect_ray 638
image_bvh64_intersect_ray 78
VOP3 0x140 24,765
VOP2 0x006 0
any v_dot* 0

This matches the GFX10.1 + BVH profile that LLVM calls gfx1013, which decodes 0x140 and 0x006 with the legacy MAD/MAC names. The conformance test now documents the two names as intended differences from the GFX10.3 corpus, and it still flags them if they go stale. The existing lowering was already unfused and already applied the zero rule. The new tests pin that behaviour.

Fixes: #64
Depends on: none

Area

Shader decoder conformance and VALU tests, plus shader analysis documentation.

Tests

  • cargo xtask pr-check passes on my machine with --skip test

  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

  • Ran on a title: no

  • cargo test -p xtp-shader --lib reported 492 passed, 0 failed, and 41 ignored.

  • legacy_mad_mac_round_product_and_preserve_zero_rule runs v_mad_legacy_f32 and both v_mac_legacy_f32 forms through run_cases, so it fails rather than skips without a device. With a = b = 1 + 2⁻¹² and c = -(1 + 2⁻¹¹), the unfused result is +0, while a fused one would be 2⁻²⁴. It also checks 0 × ∞ + 1 = 1, NaN × 0 + 1 = 1 and 0 × -5 + (-0) = +0. It passed on an NVIDIA RTX 5070 and on WARP.

  • cargo test -p xtp-shader --test gfx10_conformance passed both tests. The new test checks MAD and both MAC forms.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

The opcode and target-feature facts come from LLVM Project llvmorg-19.1.7 (Apache-2.0 WITH LLVM-exception). No LLVM implementation code was copied.
The decoder test reuses three encodings from the checked-in LLVM MC corpus, which includes LICENSE-LLVM.txt. LLVM Project llvmorg-19.1.7

AI assistance: AI coding tools wrote this change and its tests, mainly OpenAI Codex.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added the overlap another open PR changes the same files label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#65 crates/xtp-shader/src/emit/valu_tests.rs

This comment is kept up to date automatically and removed when the overlap ends.

@github-actions github-actions Bot added area/shader touches crates/xtp-shader area/docs docs/, Markdown size/S 10 to 99 changed lines labels Nov 25, 2026
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

About the overlap with #65: this PR only adds one test at the end of valu_tests.rs and calls run_cases unchanged. After 753d6a7, it no longer touches the lines #65 changes, so either PR can land first without a rebase. Once #65 lands, the new test picks up its Host::test_hosts() skip handling.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against LLVM 19.1.7: MAD/MAC need HasMadMacF32Insts and legacy FMA/FMAC need HasFmaLegacy32, so keeping both name sets fits this console's mix. Decoding and lowering are unchanged, and the new VALU cases tell fused results from unfused ones and IEEE zeros from legacy ones; I checked the maths. Nit for later: the decode test repeats corpus entries 2097, 2099 and 2105. CI is green, so I'm merging.

@simnJS
simnJS merged commit e721432 into MiamiGame:main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs docs/, Markdown area/shader touches crates/xtp-shader overlap another open PR changes the same files size/S 10 to 99 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover the GFX10 decoder gaps and resolve legacy MAD/MAC semantics

2 participants