cpu: lift scalar SSE/SSE2 leaf functions #265
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/269"
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 Vonsek on 2026-11-21T19:51:33Z.
Change
The instruction-form map showed no covered x64 SSE or SSE2 form. This adds
tools/cpu_sse_aot.py, a translator for Windows x64 leaf functions that keepfloatanddoublevalues in XMM registers, with a source fixture and a CTest test.Supported forms:
MOVSS,MOVSDbetween registers and memory; registerMOVAPS/MOVAPD/MOVUPS/MOVUPDcopies;ADDSS,SUBSS,MULSS,DIVSSand theSDforms, with register or memory sources;CVTSI2SS,CVTSI2SDfrom 32- and 64-bit registers or memory;CVTTSS2SI,CVTTSD2SIto 32- and 64-bit registers;CVTSS2SD,CVTSD2SS;UCOMISS,COMISS,UCOMISD,COMISDfeedingJE,JNE,JB,JAE,JBE,JA,JP,JNP;MOVDbetween XMM and a 32-bit register or memory,MOVQbetween XMM registers and memory;XORPS,XORPD,PXORof a register with itself.Design:
name=<result>:<slots>withf,dorqper slot (for exampleblend_ss=f:ffqf). Slot N is XMM0-XMM3 when floating point and RCX/RDX/R8/R9 otherwise, and the generated function has the matching C++ signature. A PE does not record this, so it cannot be inferred.floatargument defines the low dword only, a register copy carries undefined parts, and reading an undefined part is rejected.a + b, which changes the payload when both operands are NaN.0x80000000,0x8000000000000000); the plain C++ cast is undefined there.JPthenJNE). Integer flags keep the existing rule.The translator is a separate module that imports
Function,Lifterand the prelude fromcpu_switch_aot.pyand does not edit that file, so it does not conflict with #173, #242 or #246. It overridesFunction.constants()to return nothing, so every jump table is rejected in this profile. Itslift()repeats the label and must-defined loops ofcpu_switch_aot.lift(); these can be shared once the open changes to that function have landed.Other files:
tests/cpu/scalar_float.asm/.def(six exports:blend_ss,blend_sd,convert,from_int,classify_ss,classify_sd;SWAP_OPERANDSbuilds the control);tests/cpu/scalar_float_check.py(CTestcpu_aot_scalar_float);tools/form_coverage.py(scalar_floatmaps tocpu_aot_scalar_float) andcheck_scalar_floatintests/form_coverage_check.py;docs/experiments.md(new section);README.md(CPU translation row). With the new test passing, the fixture adds 11 SSE and 11 SSE2 forms (plusmovd,movq,pxor, filed under MMX, andmovsd,jp,jnp, filed under Integer).Verification
ctest --preset dev --no-tests=error -R '^cpu_aot_scalar_float$' -Vat399617c(rebased on maind311159, with the round_trip conversion fix; the runs at 8c8fa8f and 5d0c75c gave the same output for the existing exports) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207, ML64 14.44.35230), Windows SDK 10.0.26100, Python 3.12: passed in Debug (thedevpreset) and in a Release build (cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release), with identical output:23 fixed results and {'blend_ss': 2916, 'blend_sd': 3481, 'convert': 432, 'from_int': 61, 'classify_ss': 2916, 'classify_sd': 3481} calls match on the result and the guarded buffer for the original and the swapped-operand build; swapped operands changed {'blend_ss': 42, 'blend_sd': 1503, 'convert': 273, 'from_int': 53, 'classify_ss': 2160, 'classify_sd': 2650}and13 patched-instruction rejections and 8 signature rejections passed. The original DLLs are called through ctypes, and the signalling-NaN cases still match, so that path does not quiet them. The fullctest --preset dev --no-tests=errorpassed 137/137, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.tests/cpu/scalar_float.asmunchanged, with and without/DSWAP_OPERANDS.llvm-ml18 (--m64) also accepts the file unchanged.llvm-ml+lld-linkbuild both DLLs. The original code is called in-process through a Windows-ABI trampoline; the lifted C++ is built with clang 18 at-O0,-O2and-O3(-Wall -Wextra -Werror).check()andcheck_rejections()run unchanged:blend_ss, where onlya + bbecomesb + a, the 42 differences are exactly inputs with two NaN operands;x86_64-pc-windows-msvcunder-Wall -Wextra -Werrorand with clang-cl/W4 /WX.JBEcondition, dropping the sign extension inCVTSI2SS, or making a single-precision result or a registerMOVSSoverwrite bits 32-63 each failscheck().tests/form_coverage_check.pypasses; with theCPU_FIXTURESentry removed it fails incheck_scalar_float.Evidence and follow-up
fp_contractoff).SQRTSS,MINSS/MAXSS,CVTSS2SI/CVTSD2SI,MOVQwith an integer register,SETcc/CMOVccafter a compare (depends on #173), stack frames, calls, and saving XMM6-XMM15.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T20:01:01Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
8c8fa8fbe2ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T20:38:20Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:59:19Z.
At
8c8fa8f, onlyCMakeLists.txtandtools/form_coverage.pyconflict. Please keep the recently merged shift/address fixture registrations alongsidecpu_aot_scalar_float, then rerun the scalar-float and form-coverage checks.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:53:40Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
8c8fa8fℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T20:35:31Z.
Rebased on main
496fc28(5d0c75c). OnlyCMakeLists.txtandtools/form_coverage.pyconflicted: thecpu_aot_switch_addr32fixture registration and itsCPU_FIXTURESentry from main are kept besidecpu_aot_scalar_float. On Windows 11 26200.9974 (MSVC 14.44.35207, ML64 14.44.35230):cpu_aot_scalar_floatandcpu_aot_switch_addr32pass,tests/form_coverage_check.pypasses, and the full suite passed 127/127.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:57:45Z.
At
1b186f29, Git reports conflicts inCMakeLists.txtandREADME.md. Please retain the newly merged CPU fixture registrations and the SSE/SSE2 capability and reproduction entries when rebasing.Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T21:03:32Z.
Heads up on coverage split: I am taking the AVX2 group in a separate tool (), scoped to register-domain forms (broadcast/permute i128, vpbroadcast, vperm{,2}, variable shifts, vpblendd) with gathers and vpmaskmov explicitly rejected pending a memory model. It shares only the registration points (CMakeLists, README, experiments, form_coverage) with your scalar SSE work, so the two can land in either order. The memory-domain AVX2 forms and the FP AVX/FMA groups stay open for whoever wants them.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:27:55Z.
At
399617c, the merge conflicts are inCMakeLists.txt. The conversion review is resolved. Please retain bothcpu_aot_scalar_floatand #285's narrow-return target and test registration.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:35:26Z.
A coverage note from reading the diff at
399617c, without building it.The self-zeroing forms
xorps xmm0,xmm0,pxor xmm1,xmm1andxorpd xmm2,xmm2appear only infrom_int, and nothing there can observe them:from_intisd:qq, so its XMM locals are declared= 0;cvtsi2sskeeps bits 32–63 ofxmm0andxmm1, butmovssstores only the low dword;cvtsi2sdthen replaces the whole modelled quadword ofxmm2andxmm0before they are stored or returned.Lowering the three forms to no assignment at all would still pass. A
d:dleaf such asxorps xmm0,xmm0; ret, called with 1.0 and expected to return +0.0, would pin it, and the same applies topxor/xorpd. Becausecheck()requires every export to differ in theSWAP_OPERANDSbuild, such a leaf also needs a control variant.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T20:01:01Z.
Code review location:
tools/cpu_sse_aot.py; line 197For a supported
f:fleaf containingcvtss2sd xmm0,xmm0; cvtsd2ss xmm0,xmm0; ret, these plain C++ casts allow the host compiler to eliminate both conversions. Using the emitted statements and prelude, Clang 17 and GCC 13 on Linux reduce the function toretat-O2: input0x7f800001returns unchanged instead of the native instructions' quieted0x7fc00001. With DAZ enabled, denormal inputs also incorrectly survive instead of becoming zero. Disabling FP contraction does not prevent this optimization. Preserve instruction-level conversion semantics, for example through strict-FP controls, and add a chained-conversion regression case; Clang's strict-FP mode restores the native results in this reproducer.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T20:38:20Z.
Code review location:
tools/cpu_sse_aot.py; line 197Fixed in 1b186f2.
CVTSS2SDandCVTSD2SSnow go through aresize()helper that reads its input from avolatile, so each conversion is performed and a pair cannot be folded to an identity: a signalling NaN is quieted at each step and, with DAZ set, a denormal input is flushed as on hardware.The fixture gains
round_trip=f:f(cvtss2sd xmm0, xmm0; cvtsd2ss xmm0, xmm0; ret), with fixed results0x7f800001 -> 0x7fc00001and0xffa00000 -> 0xffe00000(quieted), a quiet NaN and -2.75 unchanged, and the full single-precision input set in the differential run. ItsSWAP_OPERANDSbuild replaces the pair withMOVSSand must differ from the original only for signalling NaNs (3 inputs). On Windows 11 26200 the test passes in Debug and Release; MSVC (default/fp:precise) kept both conversions even before the change, so the reported Clang/GCC-O2folding is not reproducible with MSVC, but the generated source no longer depends on it.