cpu: lower scalar SQRT, MIN and MAX in the scalar SSE translator #1161
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1168"
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 tedin7 on 2026-11-24T02:21:27Z.
Change
tools/cpu_sse_aot.pynow lowers the scalarSQRTSS,SQRTSD,MINSS,MAXSS,MINSDandMAXSDin bounded leaf functions, register and memory source. Before this change the translator refused them withunsupported instruction.Advances the scalar SSE translator coverage in
docs/experiments.md. No overlapping open PR (searched for sqrt, min, max, scalar and SSE).Verification
Assembled with
llvm-ml-19, linked withlld-link-19, original machine code run through a Windows-ABI trampoline on Linux x86-64, translation built with clang++-19 at -O0, -O2 and -O3:python3 -B tests/cpu/scalar_float_check.py <original.dll> <lifted> <swapped.dll> <swapped lifted>: 82 fixed results and 26,597 calls match on result and guarded buffer, for the original and the control build, at every optimization level. 27 patched-instruction rejections and 12 signature rejections pass.python3 -B tests/form_coverage_check.py: passes (SSE and SSE2 fixture forms 11 to 14 each).python3 -B tests/docs_links_check.py: passes.tools/cpu_sse_aot.pyfromorigin/mainthe new fixture fails at translation (unsupported instruction at RVA 0x1230: minss xmm2,xmm1). WithMINSSlowered to>the check fails atmin_ss(2.0, 1.0). With the NaN quieting removed from SQRT it fails atroot_ss(0x7f800001).cpu_aot_scalar_floathas not been run by me. CI runs it.Evidence and follow-up
tests/cpu/scalar_float.asm, six new exports (min_ss, max_ss, min_sd, max_sd, root_ss, root_sd). Each applies its instruction with a register operand and with a memory operand at an odd offset over a seeded buffer.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:10:53Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
b173cede97ℹ️ 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 tedin7 on 2026-11-24T03:23:59Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:24:01Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:30:37Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
2d5e7fa2ebℹ️ 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 tedin7 on 2026-11-24T03:34:54Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:19:16Z.
AI-assisted update for both review findings.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:34:56Z.
AI-assisted follow-up: cpu_float_original_lifted and cpu_float_swapped_lifted now depend on cpu_mxcsr_harness (add_dependencies), so the documented scalar-only build produces the harness DLL the check loads. Verified the dependency form with a minimal CMake project on Linux; the Windows build and the scalar check itself were not run here.
0dc3c4b7.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:06:05Z.
@codex review
AI-assisted: the inline findings are fixed and answered in their threads; please re-read the current head.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:11:32Z.
Codex Review: Didn't find any major issues. You're on a roll.
Reviewed commit:
0dc3c4b7c4ℹ️ 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 tedin7 on 2026-11-24T04:50:16Z.
AI-assisted fix for a failure reported by a Windows Server 2025 node on
0dc3c4b7:cpu_aot_scalar_floatfailed incheck_mxcsrwithroot_ss(0x807fffff)under MXCSR0x1fc0, the translation returning0xffc00000and the processor0x80000000.-0andSQRTSSreturns-0; the Windows C runtime tests the sign of the bits and returns the default NaN.std::sqrton Linux compiles to the instruction, so the Linux run could not show it.52c67518):SQRTSSandSQRTSDnow use_mm_sqrt_ssand_mm_sqrt_sd(<emmintrin.h>), fed from the run-time (volatile) operand as before, so the constant-root rounding fix still holds (root_const_ssunder round-up still gives0x3fb504f4).-0, of a positive one+0, MIN and MAX of denormals flush to a signed zero), and a wrong rule that tests the sign before DAZ. MIN and MAX already used the processor compare and flush the result under DAZ; the new fixed results cover negative denormals for both.sqrt/sqrtfthat tests the sign of the bits fails at -O0 onroot_ss(0x807fffff)with0xffc00000instead of0x80000000; at -O2 and -O3 that stand-in did not reproduce the failure, so the control is shown at -O0 only.@codex review
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:55:11Z.
Codex Review: Didn't find any major issues. 🚀
Reviewed commit:
52c67518edℹ️ 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 chatgpt-codex-connector[bot] on 2026-11-24T03:02:27Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
52c6751ℹ️ 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 tedin7 on 2026-11-24T05:03:12Z.
Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + ML64) at commit
52c67518:--preset dev):cmake --preset dev && cmake --build out/build/dev -j 6 --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harnessctest --test-dir out/build/dev -R "^cpu_aot_scalar_float$" --output-on-failure-> 1/1 passed (2.26s, total2.29s)/O2(--preset release):cmake --preset release && cmake --build out/build/release -j 6 --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harnessctest --test-dir out/build/release -R "^cpu_aot_scalar_float$" --output-on-failure-> 1/1 passed (3.06s, total3.09s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:10:53Z.
Code review location:
tools/cpu_sse_aot.py; line 403When the host thread has MXCSR.DAZ enabled, native scalar MIN/MAX flush a selected denormal operand to signed zero. The floating-point comparison here honors DAZ, but returning the original integer
aorbbypasses that normalization. For example, with MXCSR0x1fc0, nativeMINSS(+0, 0x00000001)returns0x00000000, while this helper returns0x00000001(reproduced with Clang 17 on x86-64 Linux at-O0,-O2, and-O3). This affects all four new MIN/MAX forms without any guest MXCSR write, contrary to the documented host-MXCSR behavior. Normalize the selected operand according to DAZ or use an instruction-level implementation, and cover this in the differential test.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:10:53Z.
Code review location:
tools/cpu_sse_aot.py; line 397When a supported leaf constructs a constant SQRT operand, such as by converting the integer 2 to float, this ordinary
std::sqrtcall can be folded at compile time using default rounding instead of the host MXCSR. With the emitted helper compiled by Clang 17 on x86-64 Linux at-O2or-O3,root<float>(0x40000000u)returns0x3fb504f3even with host MXCSR0x5f80(round toward positive infinity), whereas nativeSQRTSSreturns0x3fb504f4. This requires no guest MXCSR write and violates the documented host-rounding behavior. Prevent constant folding from bypassing runtime rounding, using a suitable barrier or FP-environment-aware compilation, and add a constant-source fixture.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:23:59Z.
Code review location:
tools/cpu_sse_aot.py; line 403Fixed in
2d5e7fa2.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:24:01Z.
Code review location:
tools/cpu_sse_aot.py; line 397Fixed in
2d5e7fa2.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:30:37Z.
Code review location:
CMakeLists.txt; line 1598On a clean Windows build using the scalar experiment’s documented targets (
docs/experiments.md:3408), neithercpu_float_original_liftednorcpu_float_swapped_liftedbuildscpu_mxcsr_harness. CMake’s$<TARGET_FILE:tgt>documentation states that the target “is not added as a dependency” outsideadd_custom_command()/add_custom_target(), so thisadd_test()argument does not supply that dependency.scalar_float_check.pynow unconditionally loads the DLL inmxcsr_access(), so the documented build/test sequence fails with a DLL-load error unless a previous build has already produced it. Add the harness to the documented target list or make it a dependency of the scalar targets.AGENTS.md reference: AGENTS.md:L175-L176
Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:34:54Z.
Code review location:
CMakeLists.txt; line 1598Fixed in
0dc3c4b7.