cpu: add dedicated cpu_avx_round_aot lifter for VROUNDPS, VROUNDPD, VROUNDSS, and VROUNDSD #2382
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2390"
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 R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T14:57:32Z.
Change
Add a dedicated standalone AOT lifter (
tools/cpu_avx_round_aot.py), source-built MASM fixture (tests/cpu/avx_round.asm,tests/cpu/avx_round.def), and differential/mutant/rejection check suite (tests/cpu/avx_round_check.py) for VEX AVX floating-point rounding instructionsVROUNDPS,VROUNDPD,VROUNDSS, andVROUNDSD(docs/coverage/x64_zen2.tsvgroupAVX).Why a separate lifter alongside
cpu_aot_avx_shuffle_blend/cpu_aot_avx_scalar_fp(tools/ffx_version_query.py): those shared lowerings rejectimm8[2]=1(MXCSR rounding mode); this dedicated leaf lifter implements full live MXCSR rounding (std::fegetround()),imm8[3]=1FE_INEXACTsuppression, host DAZ (_mm_getcsr() & 0x0040u) subnormal flushing before rounding, andsNaNFE_INVALID+ payload-preserving quieting with portable IEEE-754 integer arithmetic andALTER_ROUND//O2controls.VROUNDPS/VROUNDPDand scalarVROUNDSS/VROUNDSD(register and flat[rcx|rdx|r8]memory sources) in pure portable IEEE-754 integer bit arithmetic with no<immintrin.h>rounding intrinsics.0), floor (1), ceil (2), and trunc (3), livestd::fegetround()dispatch whenimm8[2]=1,FE_INEXACTraising/suppression (imm8[3]=1), DAZ subnormal flushing (host_daz_enabled()via_mm_getcsr() & 0x0040u),FE_INVALID+ payload-preserving quieting onsNaN, signed-zero preservation,YMM[255:128]zeroing on all VEX.128 writes, and scalar high-lane preservation.docs/experiments.md.Verification
Commit:
7e907313(merged withupstream/main7e5c378d) across bothdev(Debug) andrelease(/O2) presets on Windows x64:cmake --build --preset dev --target cpu_sse_fp_harness cpu_avx_round_original cpu_avx_round_original_lifted cpu_avx_round_altered cpu_avx_round_altered_lifted-> exit 0.ctest --preset dev -R "^cpu_aot_avx_round$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skips):rejections passed: 6 alt + 36 IR + 4 raw + 9 PE-patched + CLIavx_round passed: 2580 native + 2580 lifted + 2494 /O2 cases across 43 exports; 4896 native + 4896 lifted + 4896 /O2 MXCSR runs; ALTER_ROUND diverged on 37 exports + 29 mutants caughtcmake --build --preset release --target cpu_sse_fp_harness cpu_avx_round_original cpu_avx_round_original_lifted cpu_avx_round_altered cpu_avx_round_altered_lifted-> exit 0.ctest --preset release -R "^cpu_aot_avx_round$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skips).out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py,tests/docs_links_check.py(154 md / 677 links),tests/bidi_controls_check.py(2542 files) -> all exit 0.Evidence and follow-up
tests/cpu/avx_round.{asm,def,_check.py}is a clean-room, source-built MASM fixture (MIT, repo-authored; no game files, dumps, or binaries).fractions.Fractionreference model; runs lift, rejection, portable lifted, MXCSR (DAZ off/on + subnormals under RD/RU),FE_INEXACT,FE_INVALID(sNaNvsqNaN), mutant, and/O2checks before anyhost_has_avx()exit-77 capability skip (0 skips on this AVX-capable host).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T15:04:36Z.
Review: CHANGES_REQUESTED
The current Release test passes, but an extra native/lifted run at
4a38e19bfound a result mismatch. Using the existing MXCSR driver andop_vroundps_xmm_ruwith input lane bits00000001, both implementations return3f800000at MXCSR0x1f80. At0x1fc0(DAZ), native returns00000000and lifted still returns3f800000. Please handle DAZ at the rounding input or constrain and enforce the entry profile so the unsupported mode cannot silently produce a different result. Cover positive and negative subnormals with directed rounding for f32 and f64. Also clarify whether MXCSR invalid sticky status on signaling NaNs is in the proposed contract, since the current evidence covers the output payload and precision status.Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T15:20:31Z.
Addressed in
00548e41:tools/cpu_avx_round_aot.pynow reads live MXCSR DAZ (_mm_getcsr() & 0x0040u) inhost_daz_enabled()and flushes subnormal inputs to signed zero (+/-0.0) before rounding inround_f32_bitsandround_f64_bits(matching native hardware at0x1fc0for0x00000001->0x00000000, without raisingFE_INEXACT).tests/cpu/avx_round_check.pynow testsMXCSR_EXPORTSacross all 4 rounding modes x DAZ0/1, plus all 18 explicit directed-rounding_rd/_ru/_rzexports (f32 and f64, XMM/YMM/SS/SD) under0x1f80and0x1fc0, explicit+/-minand+/-maxsubnormal assertions, and 8ignore_dazmutant controls.FE_INVALIDcontract:round_f32_bitsandround_f64_bitsnow raiseFE_INVALIDon sNaN inputs (unaffected byimm8[3]inexact suppress) and quiet them preserving sign/payload; verified on both native AVX and lifted code (with negative checks on qNaN).Verified on
00548e41on both--preset devand--preset release(ctest -R "^cpu_aot_avx_round$"): 2580 native + 2580 lifted + 2494/O2cases across 43 exports, 4896 native + 4896 lifted + 4896/O2MXCSR runs, 37ALTER_ROUND+ 29 mutants + 2 spot-mutations (DAZ,FE_INVALID) caught, plusform_coverage_check.py,docs_links_check.py, andbidi_controls_check.py(all exit 0).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:02:37Z.
APPROVED: AVX rounding AOT lifter by Ammmae0x. Author self-addressed DAZ handling per R0Y00's feedback.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:18:40Z.
Review: APPROVED
I reviewed
00548e41merged over currentmaine582a9a4. The merge is clean andgit diff --cached --checkis clean. The merged diff is the five files of the PR.R0Y00's findings on
4a38e19bare addressed.round_f32_bitsandround_f64_bitsnow read MXCSR bit 6 throughhost_daz_enabled(). With DAZ set, a subnormal input becomes signed zero before the mode is applied, soop_vroundps_xmm_ruon00000001at0x1fc0now returns00000000, as native does.avx_round_check.pyruns the MXCSR exports in all four modes with DAZ off and on. It runs the 18 explicit_rd/_ru/_rzexports at0x1f80and0x1fc0, comparing native, lifted and/O2against the reference. The inputs include positive and negative minimum and maximum subnormals in f32 and f64, and the check asserts that RD and RU separate DAZ=0 from DAZ=1.FE_INVALIDand is quieted with its sign and payload kept, while a qNaN raises nothing. Native and lifted are both checked for this.What I ran. I built
cpu_sse_fp_harness,cpu_avx_round_original,cpu_avx_round_alteredand both_liftedtargets indevandrelease, then ranThe test passes in both presets with no skip. The output reads:
2580 native + 2580 lifted + 2494 /O2 cases across 43 exports; 4896 native + 4896 lifted + 4896 /O2 MXCSR runs; ALTER_ROUND diverged on 37 exports + 29 mutants caught, andrejections passed: 6 alt + 36 IR + 4 raw + 9 PE-patched + CLI.Mutants in
tools/cpu_avx_round_aot.py. For each, I rebuilt the lifted targets indevand rerancpu_aot_avx_round:host_daz_enabledreads FTZ (bit 15) instead of DAZ (bit 6)+0instead of the signed zeroFE_INVALIDsNaN f32 unexpected flags)FE_INVALIDsNaN f64 unexpected flags)Restored and rebuilt afterwards;
git diff --quietis clean.Non-blocking. The PR description still reads "Verified on commit
4a38e19b", and its Change list doesn't mention DAZ orFE_INVALID. The00548e41comment has the current receipt, so moving that into the description would keep the two in step.Verdict: approve on
00548e41. R0Y00's changes request on4a38e19bstill stands, so the merge waits for R0Y00 to re-check it.Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; AVX-capable host. No GPU is involved in this test.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass on00548e41.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T08:12:32Z.
Review of head
00548e41: I'd merge this with the notes below. This is a comment, not an approval.reviewDecisionis stillCHANGES_REQUESTED, so it needs R0Y00's re-review before it can land.The three requested changes are all on the head. DAZ:
abs_bits < 0x00800000u && host_daz_enabled()returns the signed zero, f64 does the same, and the bit comes from_mm_getcsr() & 0x0040u. ± subnormals under RD/RU:0x80000001, # -min subnormalandfor rc in (1, 2):are inavx_round_check.py. sNaN:std::feraiseexcept(FE_INVALID)on both widths, checked bysNaN f32 unexpected flags. pigalot's review table on this head shows 8/8 mutants killed.Rounding core. I ported
round_f32_bits/round_f64_bitsto Python and compared it with an exactfractions.Fractionreference. The cases covered every exponent, ties and near-ties, both signs and all 4 modes, and compared the result plus the inexact flag:0 of 689256mismatches. Two controls both go red: ties-away gives104mismatches and rounding 0.5 up for|x|<1gives8.Merge.
git merge-tree --write-tree origin/main pr2390(main1f07b2c1) has rc=0. On the merged tree,tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pyall exit 0. Scope: static review plus Python on Linux. I didn't do a Windows or Wine build.Should fix
git diff --name-only→ 0.mdfiles), but the checklist ticks "I updated README/docs". Sibling lifters each have a paragraph with their ctest line. A note withctest --preset dev --no-tests=error -R '^cpu_aot_avx_round$' -Vand the DAZ/FE_INVALID contract would match them.ctest --preset pr(100% tests passed out of 33), andgrep -c cpu_aot_avx_roundon that log gives0. The only runs are the author's and pigalot's. A run on the current merge would be worth having before landing.Nits
3. The body still says "Verified on commit
4a38e19b" with1392MXCSR runs, and it doesn't mention DAZ or FE_INVALID. The current receipt is in the00548e41comment.4.
cpu_aot_avx_shuffle_blendandcpu_aot_avx_scalar_fpalready liftvroundps/pd/ss/sdand reject the MXCSR mode. A line explaining why this is a separate lifter would help. That's a maintainer call, not a defect.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-28T11:17:08Z.
Addressed the remaining documentation and receipt items from pigalot and JohnConnorNPC in
7e907313(merged withupstream/main7e5c378d):cpu_aot_avx_roundtodocs/experiments.mddocumenting the DAZ (_mm_getcsr() & 0x0040u),FE_INVALID(sNaNvsqNaN),FE_INEXACTsuppression, and livestd::fegetround()contract alongside thectest --preset dev --no-tests=error -R '^cpu_aot_avx_round$' -Vreproduction command and measured counts.FE_INVALIDreceipt (4896MXCSR runs,29mutants caught), explain whycpu_avx_round_aotis a separate dedicated leaf lifter alongsidecpu_aot_avx_shuffle_blend/cpu_aot_avx_scalar_fp, and record the current Windowsdev+release(/O2) verification output (100% tests passed, 0 tests failed out of 1in both presets;form_coverage_check.py,docs_links_check.py, andbidi_controls_check.pyexit 0).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T11:29:48Z.
Review: APPROVED
Retested
7e907313integrated overmain24fcd0b5(tree0ec9b3e4). This follows my approval on00548e41.What changed since
00548e41. Two commits, both by the author:8aeab5demergesmain.git show --remerge-diff 8aeab5deis empty, so it resolved without hand edits. The lifter, fixture,.defand check script are byte-identical to00548e41, and the PR'sCMakeLists.txthunk is unchanged.7e907313adds one paragraph forcpu_aot_avx_roundtodocs/experiments.md. I checked it against the code and the test output: the DAZ bit (_mm_getcsr() & 0x0040u),FE_INVALIDon sNaN with the payload kept,FE_INEXACTsuppression onimm8[3], livestd::fegetround()onimm8[2], and the counts all match what the test prints.The trial merge over current
mainis clean,git diff --cached --checkis clean, and the merged diff is the six files of the PR.Earlier findings. My review on
00548e41had no blocking finding. Its one non-blocking note (the description still cited4a38e19band didn't mention DAZ orFE_INVALID) is addressed: the description now gives the7e907313receipt. JohnConnorNPC's notes 1, 3 and 4 (docs entry, stale receipt, why a separate lifter) are addressed in the docs paragraph and the description. Note 2 still holds: theprpreset in CI doesn't runcpu_aot_avx_round, so the runs below are local.What I ran. Built
cpu_sse_fp_harness,cpu_avx_round_original,cpu_avx_round_alteredand both_liftedtargets indevandrelease, then1 passed in Debug and in Release
/O2, no skip. Both print2580 native + 2580 lifted + 2494 /O2 cases across 43 exports; 4896 native + 4896 lifted + 4896 /O2 MXCSR runs; ALTER_ROUND diverged on 37 exports + 29 mutants caughtandrejections passed: 6 alt + 36 IR + 4 raw + 9 PE-patched + CLI. On the merged tree,tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pyexit 0.Mutants in
tools/cpu_avx_round_aot.py, mostly different from the eight in my last review. For each I rebuilt both lifted targets indevand reran the test.Killed (12):
FE_INVALIDsNaN f64 unexpected flagsFE_DOWNWARDmapped to ceilFE_TOWARDZEROmapped to nearestgot ... != exp ...got ... != exp ...got ... != exp ...got ... != exp ...vroundssdrops source-1 bits 63:32got ... != exp ...vroundsdzeroes the high qword instead of taking source 1got ... != exp ...vroundpd xmmkeepsYMM[255:128]got ... != exp ...got ... != exp ...Surviving: none. Equivalent: none.
The file was restored from its raw bytes, the targets rebuilt and the test passes again;
git diff --quietis clean.Non-blocking.
AGENTS.mdnow says new notes go indocs/experiments/<topic>.mdand new test families intests/cmake/<family>.cmake. This PR adds its paragraph todocs/experiments.mdand its 34 lines to the rootCMakeLists.txt, next to the sibling AVX lifters. I'm not asking for a move; it's the maintainer's call whether the older placement is fine here.Verdict: approve on
7e907313. R0Y00's changes request on4a38e19bstill stands on the PR, so I'm not merging it; its three points (DAZ, subnormal directed-rounding coverage, sNaN invalid status) were addressed in00548e41and are unchanged at this head.Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; AVX-capable host. No GPU is involved in this test.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass on7e907313.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T13:24:32Z.
Re-review of head
7e907313, trial-merged ontomainc04e0dd6(git merge-tree --write-treeexits 0,git diff --checkclean). Static review plus Python on Linux. I did no Windows or Wine build.Since my comment on
00548e41:8aeab5deis a clean merge ofmain(git show --remerge-diff 8aeab5deprints nothing).tools/cpu_avx_round_aot.py,avx_round.asm,avx_round.defandavx_round_check.pyhave the same blob ids as at00548e41.round_f32_bits/round_f64_bitsagainst an exactfractions.Fractionreference, covering every exponent, ties and near-ties, both signs and all four modes:port!=Fraction ref: 0 of 689256. It is still a faithful port, because the lifter is byte-identical.ROUNDPS/PD/SS/SDrules. DAZ is applied only to the element being rounded, andop_vroundsscopiessrc1[63:32]andsrc1.q[1]bit for bit. An sNaN raisesFE_INVALIDand comes back quiet with its payload kept, while a qNaN passes through. A DAZ-flushed input returns the signed zero withoutFE_INEXACT. Nothing raises a denormal flag, and the SDM lists no denormal exception for these instructions.docs/experiments.mdparagraph matches the code.host_daz_enabledreads_mm_getcsr() & 0x0040u. Its claim that the portable checks run before the AVX skip is right:avx_round_check.py'smain()runsverify_against_ref(lifted),verify_mxcsr_modes,check_altered_and_mutantsandcompile_o2_and_verifybeforeif not host_has_avx(...): sys.exit(77). The.defhas 43 exports, as the paragraph says.form_coverage_check,docs_links_check(Checked 171 Markdown files and 711 links.) andbidi_controls_checkexit 0.MUST: none.
SHOULD: none from me. The CI coverage and the file-placement notes are already in the latest approval, so I won't repeat them.
NIT: the paragraph calls the code "pure portable IEEE-754 integer bit arithmetic", but DAZ is read with the x86
_mm_getcsr()intrinsic. "Integer bit arithmetic, with DAZ read from MXCSR" would be exact.From my side this is ready to merge. It is still blocked by the changes request on
4a38e19b. All three of its points (DAZ at the rounding input, ± subnormals under directed rounding, sNaNFE_INVALID) are on this head, so it needs a re-review or a dismissal by the reviewer who opened it.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-12-01T03:22:00Z.
@R0Y00 Friendly re-review ping: your
CHANGES_REQUESTEDreview on4a38e19bis currently the only merge block on this PR.Head
7e907313addresses live MXCSR DAZ subnormal flushing (_mm_getcsr() & 0x0040u),FE_INVALIDon sNaN inputs, directed-rounding subnormal coverage, anddocs/experiments.md. All 5 CI checks pass,git merge-tree --write-treeontoupstream/main(1c634037) exits0, and@pigalothas reviewed and approved7e907313(confirming the findings on4a38e19bare addressed).Could you re-review when you have a moment so this can land? Thank you!
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:18:44Z.
Review: APPROVED
The original DAZ mismatch is covered by the signed-subnormal f32/f64 controls, and the sNaN invalid-status contract is specified and tested. Pigalot independently checked native/lifted results in Debug and Release and confirmed the reviewed implementation is byte-identical on
7e907313. The current trial merge and required Windows job are green.