Repository navigation
cpu: lower SSE3 and SSE4.1 floating-point and data-movement instructions - #375
evilclanker9000 wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9236fdc991
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| stmt = (f"{{ {src_init} {ftype} a[{lanes}], b[{lanes}], s = {ftype}(0); " | ||
| f"memcpy(a, {dst}.data(), 16); memcpy(b, rhs.data(), 16); " | ||
| f"for (size_t k=0; k<{lanes}; ++k) {{ if (({imm}u >> (4u + k)) & 1u) s += a[k] * b[k]; }} " |
There was a problem hiding this comment.
Preserve the architectural dot-product reduction order
For inputs with cancellation, the sequential accumulator does not implement DPPS's pairwise reduction (p0+p1)+(p2+p3). With the fixture's 0xD5 mask, a=(1e20f,0,-1e20f,1) and b=(1,1,1,1), native DPPS returns (0,0,0,0) while the emitted C++ returns (1,0,1,0); this reproduces in both unoptimized and optimized comparisons on Linux x86-64. Initializing the accumulator to positive zero also makes DPPD lose negative zero when both selected products are negative zero. Emit masked products followed by the architectural reduction tree, rather than accumulating from zero, and add cancellation and signed-zero cases.
Useful? React with 👍 / 👎.
| if i.op1_kind == K.REGISTER and i.op1_register in wide_xmm: | ||
| src_init = f"std::array<uint8_t,16> rhs; memcpy(rhs.data(), {wide_xmm[i.op1_register]}.data(), 16);" | ||
| elif i.op1_kind == K.MEMORY: | ||
| src_init = f"std::array<uint8_t,16> rhs; memcpy(rhs.data(), reinterpret_cast<const void*>({address()}), 16);" |
There was a problem hiding this comment.
Limit scalar memory reads to the architectural operand width
When ROUNDSS, ROUNDSD, or MOVDDUP uses a memory source, this emits a 16-byte read even though their memory operands are only 4, 8, and 8 bytes respectively. A scalar occupying the last valid bytes before an inaccessible page therefore succeeds natively but can fault in the unoptimized emitted C++; a Linux x86-64 page-boundary comparison reproduces this for all three instructions. Read only the decoded memory operand's width instead of always copying 16 bytes. The new fixture misses this because it uses register sources for these operations.
Useful? React with 👍 / 👎.
| memcpy(reinterpret_cast<void*>(address), &v, sizeof v); | ||
| } | ||
| template<class T> T round_x86(T x, unsigned mode) { | ||
| if (!std::isfinite(x) || x == T(0)) return x; |
There was a problem hiding this comment.
Quiet signaling NaNs before returning non-finite inputs
For a signaling-NaN source with the normal masked-invalid MXCSR setting, this fast path returns the original signaling bit pattern, whereas SSE4.1 rounding instructions quiet it. For example, native ROUNDPS with immediate 0x08 maps 0x7f800001 to 0x7fc00001, but the emitted helper returns 0x7f800001; this reproduces in both unoptimized and optimized comparisons on Linux x86-64. Consequently, the accepted ROUNDPS/PD/SS/SD forms produce incorrect output bytes for these inputs. Handle signaling NaNs explicitly before returning non-finite values and include exceptional-value comparisons in the fixture.
Useful? React with 👍 / 👎.
|
Verified Two notes:
AI-assisted (Claude Code). |
|
I rebuilt your original 23 exports at 8510482 and translated them with the current #602 candidate (3007320). All 23 positive cases matched the native DLL in an independent MSVC /O2 build, including the legacy MOVUPS/MOVUPD transport and rounding cases. The old MXCSR-selected rejection check was outside that positive comparison because #602 explicitly tests that mode as supported. I am keeping these in the same merge queue. #602 is still open while its Windows check reruns for a separate WARP failure. Your original fixture and the independent Skylake report remain useful cross-checks for the overlapping implementation. |
Change
movups/movupd) intools/ffx_version_query.py:addsubps,addsubpd,haddps,haddpd,hsubps,hsubpd,movddup,movsldup,movshdup,lddqublendps,blendpd,blendvps,blendvpd,dpps,dppd,roundps,roundpd,roundss,roundsd,extractpsEncodingKind.LEGACYXMM forms, implement exact host-independent ties-to-even/floor/ceil/trunc rounding inround_x86, and reject MXCSR rounding mode (imm8 & 4 != 0).SSE3) and 19 (SSE4.1) before invoking the native fixture (exiting 77 withSKIP_RETURN_CODE 77on hosts without SSE3/SSE4.1).tests/cpu/sse3_4_fp.{asm,def,py}, CMake targetcpu_sse3_4_fp_lifted, CTestcpu_aot_sse3_4_fp, coverage mapping intools/form_coverage.py, and documentation indocs/experiments.md.Verification
cmake --build --preset dev --target cpu_sse3_4_fp_lifted:ValueError: unsupported query operation at 0x1000: movups xmm0,[rcx]cmake --build --preset dev --target cpu_sse3_4_fp_liftedsucceeded with 0 warningsctest --preset dev --no-tests=error -R "^(cpu_aot_sse3_4_fp|cpu_aot_bmi1)$" -V: 2/2 passed (23 SSE3/SSE4.1 floating-point and data-movement cases matched native and translated DLLs+ MXCSR-moderoundpsrejection control).\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py:form coverage checks passedEvidence and follow-up
SSE3-4-grouped mnemonics indocs/coverage/x64_zen2.tsvusing source-built fixtures, gated by a runtime CPUID check.