← Back to Pull requests

[rocjitsu] Ignore VOP3P prefix neg/neg_hi bits on cdna4 V_MFMA_SCALE_F32_*_F8F6F4 #17158

Closed
unknown closed this pull request without merging on Dec 03, 2026 02:33 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 03:23 UTC
Author

Motivation

ENC_VOP3PX2 in the CDNA4 ISA XML inherits the generic VOP3P NEG (w1[31:29]) and NEG_HI (w0[10:8]) bitfields on the first 64-bit word (v_mfma_ld_scale_b32). Based on that XML definition, cdna4's generated v_mfma_scale_f32_{16x16x128,32x32x64}_f8f6f4 decoder previously rejected encodings with non-zero neg[1:0] / neg_hi[1:0], and execute_impl decoded wmma_c_modifier((raw_words_[1] >> 29) & 7u, (raw_words_[0] >> 8) & 7u) to negate or take the absolute value of accumulator C (which also caused strict BitExactEmpirical* execution to reject non-zero w0[10] / w1[31]).

Sweeping 16 sampled (neg, neg_hi) pairs out of the 8 × 8 (64) prefix modifier space — (0,0), (4,0), (0,4), (4,4), (1,0), (0,1), (1,1), (2,0), (0,2), (2,2), (3,0), (7,0), (0,7), (7,7), (5,2), and (6,5) — across 10 16x16x128 and 32x32x64 format, scale-byte, and MODE.FP16_OVFL configurations (32 waves = 2,048 lanes each) on physical MI350X (AMD Instinct MI350X OAM, gfx950, ROCm 7.2.4 / HIP 7.2.53211) establishes that v_mfma_ld_scale_b32 ignores VOP3P neg[2:0] and neg_hi[2:0]:

  • Every sampled (neg, neg_hi) pair executes without ILLEGAL_INST or TRAPSTS flags (0x00) and produces 100% bit-identical output to (0, 0) (0 word differences across A, B, C, scale_a, and scale_b). In particular, the two cases that independently set the former C modifiers on 16x16x128 (va=v[0:7], vb=v[8:15], vd=src2=v[16:19], vsa=v32, vsb=v33) match base (0, 0) (.long 0xD3AC0000, 0x00024320, 0xD3AD0810, 0x04421100):

  • - (4, 0) (w1[31] = 1, former c_neg): .long 0xD3AC0000, 0x80024320, 0xD3AD0810, 0x04421100
    - (0, 4) (w0[10] = 1, former c_abs): .long 0xD3AC0400, 0x00024320, 0xD3AD0810, 0x04421100
  • LLVM's gfx950 MC layer (llvm-mc --triple=amdgcn -mcpu=gfx950) likewise rejects -src2 / |src2| / neg_lo / neg_hi operands in assembly and ignores w0[10:8] and w1[31:29] when disassembling ENC_VOP3PX2.
  • Technical Details

  • Decoder & execute codegen (lib/python/amdisa/codegen/_generator.py, regenerated cdna4/decoder.cpp and cdna4/vop3p_exec.cpp):

  • - Remove the (neg & 0x3u) == 0 && (neg_hi & 0x3u) == 0 rejection from isValidMfmaScaleF8f6f4 while retaining scale-selector and cbsz/blgp <= 4 validation.
    - Stop decoding wmma_c_modifier from raw_words_[0:1] in VMfmaScaleF32{16x16x128,32x32x64}F8f6f4Vop3px2::execute_impl, passing controls = inst_.cbsz | (uint64_t(inst_.blgp) << 3) across all semantics.
    - Keep rj-arith's synthetic RJ_ARITH_MFMA_SCALE_NEG_C / RJ_ARITH_MFMA_SCALE_ABS_C C-API flags unchanged for library callers.

    Issue Tracking

    Follow-up to #16887 and #13670 (rj-arith).

    Test Plan

  • amdisa generator tests (test_generator_profile_gates.py):

  • - Verify cdna4 decoder.cpp no longer gates ENC_VOP3PX2 on neg/neg_hi and cdna4 vop3p_exec.cpp no longer emits wmma_c_modifier.
  • Decode & execution harness tests (tests/instruction_execution_harness_test.cpp):

  • - Cdna4BlockScaleMfmaDecodeTest.RejectsReservedFormatsAndAcceptsPrefixModifierBits: verifies reserved formats 5..7 still fail decode while all 8 × 8 (neg, neg_hi) prefix bit combinations decode as 16-byte v_mfma_scale_f32_{16x16x128,32x32x64}_f8f6f4 instructions.
    - Cdna4BlockScaleMfmaExecutionTest.PrefixModifierBitsAreIgnoredAcrossAllSemantics: verifies across Compatibility, Loose, BitExactEmpiricalNoFpStatus, and BitExactEmpirical, both 16x16x128 and 32x32x64 shapes, signed non-equal A/B (-1.0 × +1.0), negative VGPR accumulator (-3.0f), and negative inline constant accumulator (-1.0f tested separately under (4, 0), (0, 4), and (4, 4)) that prefix neg and neg_hi bits leave inputs and accumulators unmodified.

    Test Result

    Verified on Linux x86-64 Zen 4 (-fno-exceptions, -DRJ_ENABLE_EXPENSIVE_CHECKS=ON):

  • Debug rj_arith baseline_linkage: 2 / 2 passed

  • Release lib/arith ctest: 3,639 / 3,639 passed

  • Release rocjitsu ctest: 19,432 / 19,432 passed (including Cdna4BlockScaleMfmaDecodeTest.RejectsReservedFormatsAndAcceptsPrefixModifierBits and Cdna4BlockScaleMfmaExecutionTest.PrefixModifierBitsAreIgnoredAcrossAllSemantics)

  • amdisa pytest: 6,265 passed, 41 skipped
  • Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/rocm-systems/blob/develop/CONTRIBUTING.md.
  • Diff: 562 lines (+421 / -141) across 7 files Reviewer: kuhar Review duration: 2830m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.55) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 562 lines diff across 7 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.379
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #17158"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 54.7% (MEDIUM) · Higher = larger blast radius
    54.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.6% · Safe to merge
    23.6%