cpu: lower legacy SSE packed bitwise FP logic (ANDPS, ANDNPS, ORPS, XORPS) in cpu_sse_fp_aot #2077
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2084"
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-25T00:04:31Z.
Change
Lower legacy SSE packed bitwise FP logic instructions in
tools/cpu_sse_fp_aot.pyand add a source-built MASM fixture (tests/cpu/sse_fp_logic.asm,tests/cpu/sse_fp_logic.def), differential verification suite (tests/cpu/sse_fp_logic_check.py), and CTest registration (cpu_aot_sse_fp_logicinCMakeLists.txt):docs/coverage/x64_zen2.tsvgroupSSE):andps xmm, xmm/m128andnps xmm, xmm/m128(asymmetric(~dst) & src)orps xmm, xmm/m128xorps xmm, xmm/m128(binary XOR and self-zeroingxorps xmmN, xmmN)-0.0,+0.0, denormals, Inf).xorps xmmN, xmmNaccepts an undefined volatilexmmNand lowers viaconst volatile Vec128(op_zero_vec()) so/O2never constant-folds downstream+0.0 + (-0.0)or bypasses MXCSR rules;andps,andnps,orps, and non-selfxorpsrequire a defined destination.m128sources enforce 16-byte alignment (flat_address(alignment=16)) and volatile loads so/O2never eliminates faulting discarded reads.r8stores, undefined reads, and non-leaf branches.Verification
Tested on commit
2253f858(rebased ontoupstream/main6218beb2, Windows x64, MSVC 14.50,devDebug andrelease/O2):cmake --build --preset dev --target cpu_sse_fp_logic_original cpu_sse_fp_logic_original_lifted cpu_sse_fp_logic_altered cpu_sse_fp_logic_altered_lifted cpu_sse_fp_original cpu_sse_fp_original_lifted cpu_sse_fp_altered_lifted cpu_sse_fp_pd_original cpu_sse_fp_pd_original_lifted cpu_sse_fp_pd_altered_lifted cpu_sse_fp_harnesscmake --build --preset release --target ...(same targets)ctest --preset dev -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure -V3/3Passed (cpu_aot_sse_fp,cpu_aot_sse_fp_logic,cpu_aot_sse_fp_pd).cpu_aot_sse_fp_logic:rejections passed: 5 VEX/EVEX + 24 IR + 3 raw + 7 PE-patched + CLI;sse_fp_logic passed: 1060 lifted + 1060 /O2 cases across 20 exports; ALTER_IMM diverged on {'op_andps': 53, 'op_andnps': 53, 'op_andnps_mem': 53, 'op_orps': 53, 'op_xorps': 53, 'op_logic_pipeline': 52}. Capability skips: none.ctest --preset release -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure3/3Passed..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.pySelf-test passed. Checked 18 Markdown files and 393 links.(exit 0)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1416 tracked source, script and build/CI files: no bidirectional controls.(exit 0).Evidence and follow-up
tests/cpu/sse_fp_logic.asm(; coverage: source cpu_aot_sse_fp_logic) andtests/cpu/sse_fp_logic.defare original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used.ALTER_IMMmutant exports (including swappedandnpsoperand order), aNULL-pointer discarded alignedm128read fault check under both Debug and/O2, 5 VEX/EVEX rejections, 24 IR rejections, 3 raw-byte rejections, 7 PE-patched rejections, and CLI non-traceback / zero-leftover-file checks.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:24:43Z.
Review: COMMENTED
Review of head
2253f8587a37f56ecb6d0e92868bc3b3eb855610.Summary: No P1 or P2. Lowering of ANDPS/ANDNPS/ORPS/XORPS is correct and consistent with the existing arithmetic path.
Checked
tools/cpu_sse_fp_aot.py: ANDNPS is(~dst) & src(operand order matches the ISA). Bitwise ops run on the 2x64-bit lanes, so NaN payloads, -0.0 and denormals are preserved. Memory sources usevec_src128(..., alignment=16), like the sibling arithmetic forms.xorps xmmN, xmmNis the only form that accepts an undefined register.andps/orps xmmN, xmmNstill require a defined register. This matches the PR text.op_zero_vec()reads avolatilezero, so/O2cannot fold it. This is the right way to protect the +0.0 + -0.0 case.CMakeLists.txt: export list,ALTER_IMMvariant and test registration follow the neighbouringcpu_sse_fp_pdblock._bit_op) is computed independently of the lifter. It includes asymmetric masks that tell(~d)&sapart fromd&(~s)./O2evidence relies on the author's local run in the PR body.Commands executed locally (Linux)
python3 tests/docs_links_check.py->Self-test passed. Checked 18 Markdown files and 393 links.python3 tests/bidi_controls_check.py->no bidirectional controlsgit diff --check origin/main...HEAD-> exit 0git diff --stat origin/main...HEAD-> 5 files, +807Not run:
cpu_aot_sse_fp_logicand a mutation of the lowering. They need MSVC/MASM andiced_x86(not available on this Linux host). I did not request a Win2025 run because the Windows CI job passed at this SHA. The PR's ownALTER_IMMdivergence counts show the suite kills the swapped-op mutant, but I did not reproduce that here.Nits (non-blocking)
/O2CI job for this suite, or paste the release-preset ctest output. It is the only proof for the volatile self-zero path.andps xmmN, xmmNwith an undefinedxmmNis rejected. That is conservative and fine, but a one-line comment near the self-zero branch would say so.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:16:41Z.
Review: COMMENTED
Review of head
04c6ba382a962a3428c21078483d1f4fca20095c(5 files, +808/-0: CMakeLists.txt, tests/cpu/sse_fp_logic.{asm,def}, tests/cpu/sse_fp_logic_check.py, tools/cpu_sse_fp_aot.py).Verdict: no P1, no P2. Looks correct; the one red check is not caused by this PR.
Commands run locally (worktree at the PR head):
git diff --stat origin/main...HEAD: 5 files, 808 insertions, 0 deletions.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files and 393 links checked.python3 tests/bidi_controls_check.py: 1416 files, no bidirectional controls.git merge-tree --write-tree HEAD origin/main: merges cleanly.python3 tests/startup_run_sh_check.pyon a cleanorigin/main(31f46857): fails withmutant 'watcher without --render' was not detected.CI on this head:
Run platform-independent Python checks on Linux: fail. The only failing script istests/startup_run_sh_check.py. It fails the same way on a cleanorigin/mainand this PR does not touch it. Every other script in that job passed.Build and test on Windows: pass (2m29s).Assemble and translate gfx1013 fixtures: pass.Build and test on Windows at /O2: skipped.Review of the logic:
andpsisd & s,andnpsis(~d) & s,orpsisd | s,xorpsisd ^ s. All are done on both 64-bit halves, so NaN, -0.0 and denormal bits are kept exactly. That matches the ISA (bitwise, no FP exceptions, no MXCSR use).xorps xmmN, xmmNself-zero is special-cased and may read an undefined register. That is the correct dependency-breaking idiom.andps/orps/andnpsself are not special-cased and still need a defined source, which is also correct (andnps x,xgives 0 but is not treated as an idiom, so it stays conservative).op_zero_vec()usesvolatileto stop /O2 constant folding. This is fine. It is a small cost, but it is only used for the self-zero case.vec_src128(..., alignment=16), so unaligned m128 is refused like the sibling arithmetic ops.sse_fp/sse_fp_pdtables: export list in CMake matches the.def, the.asmand the check'sEXPORTStuple (20 names in all three). The altered variant coversandps,andnps(register and memory),orps,xorpsand the pipeline. The check also has anandnpssymmetry mutant and a rejection set.Nits (non-blocking):
xorpsself-zero is only covered by the new fixture. Iftools/cpu_sse_fp_aot.pyor the docs/coverage table lists supported SSE forms elsewhere (e.g.docs/coverage/x64_zen2.tsvrows for these four opcodes), update them in this PR or note that a follow-up does it.volatilezero trick is only checked by the check's owncompile_o2_and_verifystep on Windows.Not done, and why:
sse_fp_logic_check.pyor a real mutation of the new lowering. It needsiced_x86,pefileand MASM-built Windows DLLs, which are not available on this Linux host. The check passed in the Windows CI job, and the Linux-only gates above are clean. No Win2025 run was queued: the change is CPU AOT C++, and the Windows CI job already covers it.AI-assisted; commands listed were executed locally.