cpu: lower scalar CVTSS2SI and CVTSD2SI by the MXCSR rounding control #1378
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1385"
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-24T10:09:08Z.
Change
tools/cpu_sse_aot.pynow lowers the rounding scalar float-to-integer conversionsCVTSS2SIandCVTSD2SIin bounded leaf functions: 32-bit (upper half zeroed) and 64-bit (REX.W) general-register destination, XMM orm32/m64source. Before this change the translator refused them withunsupported instruction; the truncatingCVTTSS2SI/CVTTSD2SIwere already lifted and are untouched.0x80000000,0x8000000000000000). DAZ reads a denormal source as zero. FTZ plays no part in a conversion to an integer. Note a value that rounds up to 2^31 is out of range for a 32-bit destination where it truncates in range (for example 2147483647.5 gives0x7ffffffftoward zero and the indefinite to nearest).std::lrint/std::llrintwith a guard for the indefinite: the Windows C runtime (UCRT/MSVC) does not follow the instruction for NaN, out-of-range values, DAZ or a non-default rounding control (the same family of defect as theSQRTSSwith DAZ case in #1168), and a guard would only restore the indefinite while the rounding still came from the library. The generated code calls_mm_cvtss_si32,_mm_cvtss_si64,_mm_cvtsd_si32and_mm_cvtsd_si64(<xmmintrin.h>/<emmintrin.h>, available with MSVC x64, clang and gcc) on an operand read through a volatile, so the compiler cannot fold a constant with the default environment and the hardware decides every case.docs/experiments.md.Advances the scalar SSE translator coverage in
docs/experiments.md. No overlapping open PR touchestools/cpu_sse_aot.pyortests/cpu/scalar_float_check.py(the one shared file istests/form_coverage_check.py, two lines).Verification
Linux, assembled with
llvm-ml-19, linked withlld-link-19, original machine code run natively through a Windows-ABI trampoline, 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> <mxcsr harness>: 84 fixed results and 1,890 newround_cvtcalls (and the 24 other exports) match on result and guarded buffer for the original and the control build;round_cvtmatches the processor and an independent reference under all 16 MXCSR words (4 rounding controls x DAZ x FTZ) with 32 further fixed answers; 33 patched-instruction rejections and 14 signature rejections pass. Same output at -O0, -O2 and -O3.python3 -B tests/form_coverage_check.py,python3 -B tests/docs_links_check.py,python3 -B tests/bidi_controls_check.py,python3 -m py_compile: pass.x86_64-w64-mingw32-g++, -O0/-O2/-O3) build of the translation under Wine against the fixture DLL: 8,400 calls over the 16 MXCSR words, 0 mismatches.tools/cpu_sse_aot.pyfromorigin/mainthe new fixture fails at translation (unsupported instruction at RVA 0x1370: cvtss2si eax,xmm0). With the conversion lowered as a truncation, or with a 32-bit destination that keeps the upper half, the check fails atround_cvt(0, 0x3ff0000000000000)andround_cvt(0, 0)respectively.ctest. PR outside--preset pr:ctest --preset dev -R '^cpu_aot_scalar_float$'(and--preset release). The scalar-fp fuzz area does not generate these instructions and is unchanged.Evidence and follow-up
tests/cpu/scalar_float.asm, one new exportround_cvt(float, double, uint8_t*): 32- and 64-bit destinations from a register and from memory, each 32-bit destination starting from all ones. All stores are inside an 80-byte window of the guarded buffer, and the check compares the whole buffer with 8 guard bytes either side, so nothing outside the eight result words, the float and the double may change.vcvtss2si),CVTPS2PI/CVTPD2PI(MMX destination), an unwritten source register, a nonvolatile destination, a RIP-relative source. The old rejection control that usedCVTSS2SIas the unsupported example now usesCVTPS2PI.CVTPS2PI/CVTPD2PI, EVEX forms.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:12:23Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit
166a6a9a62987acc1004d5e4ee76558dc2dfa68f:tests/form_coverage_check.pyok (39.8s)--preset dev):cpu_float_*,cpu_mxcsr_harness,cpu_fuzz_scalar_fp*):3.76s(configure1.65s)ctest --preset dev -R '^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_fuzz_scalar_fp1.19s,cpu_aot_scalar_float3.79s)/O2(--preset release):cpu_float_*,cpu_mxcsr_harness,cpu_fuzz_scalar_fp*):1.92s(configure1.59s)ctest --preset release -R '^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_fuzz_scalar_fp1.38s,cpu_aot_scalar_float3.70s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:12:32Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
166a6a9ℹ️ 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.