fix(shader): round v_div_fmas_f64 in the directed FLOAT_MODE rounding modes #26101
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26101"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DannyOppenheimer on 2026-11-23T08:37:22Z.
What
v_div_fmas_f64computessrc0 * src1 + src2, scaled by 2^128 or 2^-128 when VCC is set, and rounds it once in theFLOAT_MODEf16/f64 round mode. The translation (FPFmaScale64) always rounded to nearest even, so the directed modes differed from the hardware on 1228 to 1448 of 2628 rows per mode in the differential sweep.IntegerFloat64::Fma,FPFmaRound64). With the f64 result flush on, it rounds to 53 bits with an unbounded exponent and flushes when that is below the smallest normal, so the flush is decided before the result is rounded onto the denormal grid. This PR givesFmaan optional scale, added to the unbounded result exponent before rounding, and a newFPFmaScaleRound64operation (onef64_fma_scale_round_<mode>[_flush]function per mode). When a finite factor is zero and the addend is a finite nonzero value, the scaled form computesaddend * 1 + 0so that the addend is still scaled and rounded.vDivFmasF64emitsFPFmaScaleRound64when the round field is directed; round to nearest keepsFPFmaScale64and its existing flush.RoundingMode.cppclassifiesVDivFmasF64asDirected16.Found by a differential sweep of VOP1/VOP2/VOP3 opcodes through
tools/hw-oracleon an RX 5700 XT (gfx1010, RDNA1, the PS5's gfx10.1 generation) against the same bodies throughagc_oracle_runner, in the directedFLOAT_MODEround modes. This branch contains #22446's headb027630e15(which contains #22034) merged withmainc64b9d323fand thenmaina2d8d409db(a4cbdb998f); this change is the commitsc6d5466ba7(the fix),5ec3a0ac83(the boundary rows added in review) and7be00388a0(the debt fragment's wording) and3dec488975. That last commit limits the fragment's negative-zero rule to exact cancellation, and drops the sentence in #22446'sfix-f64-fma-directed-rounding.mdsayingv_div_fmas_f64still rounds to nearest in the directed modes, since this change makes it stale.Tested
Windows 11, Radeon RX 5700 XT (gfx1010), AMD driver 32.0.21045.5002. The f64 operands do not fit the oracle's four input words, so
cand the VCC flag were passed in the oracle's extra input block and loaded by the body.s_round_mode, the hardware matches "keep the inputs; round(src0 * src1 + src2) * 2^(VCC ? ±128 : 0)once in the mode; when bit 1 of the f16/f64 denormal field is clear, flush the result to a zero of its sign if, rounded to 53 bits with an unbounded exponent, it is below the smallest normal" with 0 mismatches.agc_oracle_runnerresults equal the hardware's on all of those 28672 rows, NaN and infinity rows included.agc_oracle_runner. The rows:minNormal * nextDown(1) + ±0and its negative, which give a signed zero in the directed mode toward them with the flush on and±minNormalwith it off;0x000fffffffffffff * nextUp(1) + 0and its negative, which round up to±minNormalin 53 bits and so are kept with the flush on; the same four with VCC set andsrc0×2^128; an exact denormal product;2^-1074 * 2^-1074of both signs; a denormalsrc0;1 ± 2^-1074; and1 * 1 + 0with VCC. gfx1010 agrees with Helldiverr's gfx1201 rows, and Helldiverr's rerun of all 48 rows on gfx1201 (RDNA4) also gives 0 differences, from the hardware and fromagc_oracle_runner.agc_driver_div_fmas_f64_directed_rounding: 48 rows (overflow and ordinary results of both signs, VCC clear and set, signed zero sums, and the 16 boundary rows above) with the hardware's results for round modes 1 to 3 with the f64 flush on and off, run with FLOAT_MODE 0xc0 and 0x00 at IEEE 0 and 1, declared and set bys_round_mode(24 of 24 runs pass). #22446'sagc_driver_f64_fma_directed_roundingand the existingdiv_fmas/division tests still pass.ctest --test-dir build -R "agc_driver_.*(directed_rounding|legacy|div_fmas|division|f64_fma|f64_ldexp|ldexp_f32|vop3_cube|nan_quieting|f64_arithmetic|f32_output_modifier|cubema|f32_denormal_flush|fract|f16_denormal_flush|f64_rounding|dx10_clamp|f32_result_clamp|unused_nan|dpp_no_form|vcvt_pk_u8)|vector_constant_factor_tininess|agc_shader_mode_register" -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, Khronos validation layer 1.4.369,mainata2d8d409dband this branch ata4cbdb998f(maina2d8d409dbmerged), each from its own build directory with all execution tests enabled and its test targets relinked from that commit:main39 of 39 passed, this branch 42 of 42 passed (with the newagc_driver_div_fmas_f64_directed_roundingand #22446's two directed rounding tests). On both,agc_driver_float16_unused_nan_payloadsreports itself skipped (the RX 5700 XT has no native f16 conversions with RTE rounding and kept f16 denormals).Insert instance layer "VK_LAYER_KHRONOS_validation"appears 37 and 40 times, once per GPU test (agc_shader_mode_registerandvector_constant_factor_tininesscreate no Vulkan instance);was not found but was requestedappears 0 and 0 times, andVUID-0 and 0 times.tools/check_conventions.pyona4cbdb998freports 0 errors and twodebt-lengthwarnings, both in #22446's fragments (fix-f64-add-mul-directed-rounding.md,fix-f64-fma-directed-rounding.md); this change's own fragment is under the limit.maina2d8d409db(a4cbdb998f): #26096 had movedVLdexpF64toDirected16, so theUnmodelledlist conflict resolves to neither side. Two silent conflicts needed fixing:main's #21508 declares an f32roundinginfloat64Operationnext to #22034's f64rounding, somain's is renamedroundingF32; andShaderModeRegisters.cpp's check list is sized 24. #22034 and #22446 will meet the sameroundingclash when they mergemain.tools/pr_overlap.py --branchreports the conflicts #22446 itself has (#19505 and #19710 inShaderModeRegisters.cpp, #22688 infloat64Operation, #26047 inRoundingUseOf) and the old PRs that share the backend files; this change itself addsFPFmaScaleRound64next to #22446'sFPFmaRound64, a scale toIntegerFloat64::Fma, the directed path ofvDivFmasF64and oneRoundingUseOfline.The earlier
debt_foldclash between #22446's fragments andf64-fma-denormals-gfx1031.md/shader-f64-add-mul-denorm-gfx1036.mdis gone since #22446's8546a86ca7folded them, andconventionsno longer fails on this branch.tools/debt_fold.py --checkstill reportsfix-shader-cube-face-converted-store.mdandfix-cube-face-gathers.mdtargeting the same entry; both are onmainand untouched here.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:19:12Z.
Review: COMMENTED
No blocker found, but one denormal/normal midpoint should be pinned directly on gfx1010 because the current 32-row fixture accepts both possible FTZ interpretations.
With VCC clear, please capture
(minNormal, nextDown(1), +0)in round-up and the sign-symmetric case in round-down, with output flushing both on and off. With VCC set andc=0, multiply the first operand by2^128so the instruction's2^-128scale lands on the same boundary. The shared helper returns signed zero with FTZ and signedminNormalwithout FTZ. #22446 has hardware-captured rows for this exact distinction inv_fma_f64, but not yet for scaledv_div_fmas_f64.If gfx1010 agrees, please add those raw rows and phrase the model precisely as rounding to 53 bits with an unbounded exponent before the FTZ decision. That avoids describing it as an ordinary post-round IEEE flush, which predicts
minNormalfor the halfway directed cases.Independent CPU review evaluated the exact integer-f64 helper through a typed SPIR-V integer-op interpreter. After matching #22446's measured pre-FTZ model, exact head passed 12,696/12,696 finite cases plus 7,980/7,980 NaN/infinity wrapper cases. The current DIV_FMAS tables do not exercise this distinction. I did not run a GPU test, so this is a request for targeted hardware evidence rather than a correctness finding.
Reference rows in the dependency:
github.com/boykopovar/AnyPS5@a5ba7af79b/core/libs/prx/libSceAgcDriver/tests/execution/F64FmaDirectedRounding.cpp (L78-L79)AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T09:43:06Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: verify that the new rounding paths preserve f64 flush-to-zero behavior for underflowing directed results.
What I ran
Reviewed head
c6d5466ba799afbc327c4be301a8b071ac50150busing the prepared diff and pinned readerrepo_read.py. No repository commands or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
FPFmaScaleRound64's rounding helper sets itsflushResultflag for the mode, but the new path'sFmalogic computes flushing based onunboundedandwideatcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:760-764. The directed rounding underflow cases deserve explicit confirmation against the stated output-flush rule, especially when a tiny result rounds up to the minimum normal value.Not verified
To get this to a good state
Nothing is required. The optional point is to confirm the directed underflow flush behavior with targeted cases and report the results.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T13:23:58Z.
Review: COMMENTED
Rechecked current head
7be00388a02d0c6f83c66f402d7b133d0f534ba1. The boundary point from my earlier comment is resolved: the added 16 rows and revised text distinguish the relevant models, and contributor measurements on gfx1010 and gfx1201 agree. An independent exact-rational reference reproduced all 288 directed results; the competing models diverge on the new cases.I am not approving the combined head while its conventions check is red. The reported failures are two non-foldable debt fragments inherited from the still-open #22446 dependency; this PR's own debt entry is within the limit on the current head. No additional change is requested in this PR's own commits. Please update the dependency after #22446 is corrected and re-request review.
No GPU test was run on my machine. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T23:05:55Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review evidence supports merging, and the listed hardware and test runs are author-reported.
What I ran
Reviewed head
7be00388a02d0c6f83c66f402d7b133d0f534ba1using the preparedreview/diff.patchand the pinned repository reader. No commands or tests were run by me; the PR description reports hardware oracle and Vulkan test runs.Read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch; all 19 changed files listed in the manifest were included, but I read targeted ranges rather than every changed file in full.review/files.jsonwas not available through the reader. No changed files were excluded according to the directory listing.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The execution test fixtures
F64AddMulDirectedRounding.cppandF64FmaDirectedRounding.cppwere not read in full. No tests were run in this review, and physical console behavior on PS5 gfx1013 was not verified. The reported RX 5700 XT and RX 1200-series results and CI/test output are author-supplied, not independently confirmed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T04:35:47Z.
Review: COMMENTED
Actionable comments posted: 6
f3395dde-1983-44ac-bd6c-37f2351690a9Reviewing files that changed from the base of the PR and between
c64b9d323fande4552e9852.core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cppcore/libs/prx/libSceAgcDriver/tests/execution/DivFmasF64DirectedRounding.cppcore/libs/prx/libSceAgcDriver/tests/execution/F64AddMulDirectedRounding.cppcore/libs/prx/libSceAgcDriver/tests/execution/F64FmaDirectedRounding.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/MaskedSelectEliminator.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvAnalysis.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterInstructions.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cppcore/shader/recompiler/SpirvBackend/src/SpirvAnalysis.cppcore/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/Float64Instructions.cppcore/shader/recompiler/Translation/src/RoundingMode.cppdocs/dev/debt/changes/div-fmas-f64-directed-rounding.mddocs/dev/debt/changes/f64-fma-denormals-gfx1031.mddocs/dev/debt/changes/fix-f64-add-mul-directed-rounding.mddocs/dev/debt/changes/fix-f64-fma-directed-rounding.mddocs/dev/debt/changes/shader-f64-add-mul-denorm-gfx1036.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T04:36:08Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the reviewed implementation blocks merging; the review is limited because two inherited debt files were excluded and no checks were run here.
What I ran
Inspected the prepared diff for head
e4552e98525c108477b989db5cb567d8146094eand usedrepo_read.pyto read the relevant backend and translation code. No test or build commands were run. The test results below are reported in the PR description, not run by me.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The two excluded files were
docs/dev/debt/changes/f64-fma-denormals-gfx1031.mdanddocs/dev/debt/changes/shader-f64-add-mul-denorm-gfx1036.md; their deletion hunks were visible in the prepared diff, but their full contents were not read. The PR-reported hardware sweeps, Vulkan test runs, and conventions checks were not independently run. No merged-preview check or negative control was run.Files read at the pinned head:
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp,core/shader/recompiler/Translation/src/Float64Instructions.cpp,core/shader/recompiler/Translation/src/RoundingMode.cpp, andcore/libs/prx/libSceAgcDriver/tests/execution/DivFmasF64DirectedRounding.cpp. Other changed-file full texts were not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T06:07:27Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
3dec4889751db5f2f15dc790310345f5e7827694against the prepared diff and targeted repository files throughrepo_read.py. No commands or tests were run by me.Results
Findings
Blocking
None.
Non-blocking
Not verified
I did not run builds, tests, the hardware differential sweep, or the convention and overlap checks; reported results in the PR description remain author-reported. The deleted
docs/dev/debt/changes/shader-f64-add-mul-denorm-gfx1036.mdwas excluded by the prepared bundle and was not read. I read the description, commits, manifest, diff, and all included changed files’ added lines; targeted context included the translation, rounding classification, IR metadata, optimizer, and SPIR-V backend. The full text of the large fixture files was not read beyond the targeted portions described above.To get this to a good state
Nothing is required. Optional: preserve a reproducible method for checking the generated expected-value fixtures.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:34:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review found no verified defects in the inspected implementation.
What I ran
Reviewed head
a4cbdb998fa08040a2c7676fa84bb5c184fbfed0. No commands or tests were run in this review; test results below are author-reported in the PR description.Read
description.md,commits.md,manifest.json,diff.patch, and the included changed filesShaderModeRegisters.cpp,DivFmasF64DirectedRounding.cpp,F64AddMulDirectedRounding.cpp,F64FmaDirectedRounding.cpp,IrOpcode.hpp,IrOpcode.cpp,MaskedSelectEliminator.cpp,SpirvAnalysis.hpp,SpirvEmitterInstructions.hpp,SpirvEmitterState.hpp,SpirvAluEmitterFloat64.cpp,SpirvAnalysis.cpp,SpirvFlowEmitter.cpp,SpirvModuleSetup.cpp,TranslationContext.hpp,Float64Instructions.cpp,RoundingMode.cpp, and the three included debt fragments. The deletionshader-f64-add-mul-denorm-gfx1036.mdhas no head text to read.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests and convention checks were not independently run. Physical hardware behavior and the author-reported oracle measurements were not independently confirmed. The deleted debt fragment has no head text; all other changed files listed above were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:30:16Z.
Review: COMMENTED
Please keep #22446 (and its #22034 dependency) as the comparison base for the instruction-specific coverage. This head's diff against
mainincludes the general f64 add, multiply and FMA implementation. The divide-specific path must apply the VCC scale before rounding and flushing, including when a zero factor leaves only a nonzero addend. Please retain explicit bit-pattern coverage of that branch with VCC set in both scale directions when rebasing the stack. The paired lavapipe comparison and the new divide fixture are queued. Native evidence in the description is on gfx1010.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.