Repository navigation
cpu: lower AVX broadcast, permute, shuffle, blend, dot, round, and vzeroall instructions - #390
evilclanker9000 wants to merge 2 commits into
Conversation
…eroall instructions
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: a0881a1512
ℹ️ 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"{{ auto lhs = {src1}; {s2_init} for (size_t l=0; l<{nbytes}; l+=16) {{ " | ||
| f"{ftype} a[{lanes}], b[{lanes}], s = {ftype}(0); " | ||
| f"memcpy(a, lhs.data()+l, 16); memcpy(b, rhs.data()+l, 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 pairwise reduction order of VDPPS
For cancellation-sensitive inputs, this sequential accumulation produces different results from the instruction. With the fixture's existing 0xd5 immediate, source lanes [1e20f, 0, -1e20f, 3] dotted with [1, 1, 1, 1] produce 0 natively but 3 in the emitted code, reproduced with a source-built AVX probe under default MXCSR. VDPPS reduces the masked products as (p0 + p1) + (p2 + p3), with intermediate rounding, rather than accumulating left to right. Emit that reduction tree and add a cancellation-sensitive differential case.
Useful? React with 👍 / 👎.
| nbytes = 32 if i.op0_register in wide else 16 | ||
| zero_hi = f" memset({dst}.data()+16, 0, 16);" if nbytes == 16 else "" | ||
| s_init = (f"std::array<uint8_t,32> rhs = {wide_any[i.op1_register]};" if i.op1_kind == K.REGISTER | ||
| else f"std::array<uint8_t,32> rhs{{}}; memcpy(rhs.data(), reinterpret_cast<const void*>({address()}), {nbytes});") |
There was a problem hiding this comment.
Limit XMM VMOVDDUP memory loads to eight bytes
For vmovddup xmm0, qword ptr [rcx], the architectural memory operand is only eight bytes, but nbytes is 16 because it describes the destination width. This initializer consequently reads eight bytes beyond the operand. When the source occupies the last eight readable bytes before a protected page, the native instruction succeeds while the emitted code faults in an unoptimized build; this was reproduced with a guarded-page probe. Derive the read size from the memory operand or special-case the 128-bit VMOVDDUP form instead of using the output width.
Useful? React with 👍 / 👎.
| vzeroall_op PROC FRAME | ||
| .endprolog | ||
| vmovups ymm0, ymmword ptr [rcx] | ||
| vzeroall |
There was a problem hiding this comment.
Preserve Win64 nonvolatile XMM registers around VZEROALL
On the x64 Windows target, vzeroall clears the low 128 bits of XMM6–XMM15, which are callee-saved, but this export returns without restoring them. The native fixture is called directly through ctypes in check(), so any live caller state in those registers is lost even when the output comparison passes. A source-built register probe confirms that an XMM6 sentinel returns as zero. Save and restore the nonvolatile XMM halves, or invoke this fixture through an ABI-preserving native wrapper.
AGENTS.md reference: AGENTS.md:L37-L38
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 in the packed-rounding helper
When a source lane contains a signaling NaN and invalid exceptions are masked, VROUNDPS/VROUNDPD return a quiet NaN rather than preserving the signaling representation. This early return leaves the input bits unchanged: with the fixture's vroundps immediate 8, a source-built probe produced native bits 0x7fc00001 versus lowered bits 0x7f800001 for input 0x7f800001. Handle signaling NaNs explicitly so the helper quiets them while preserving the appropriate payload.
Useful? React with 👍 / 👎.
|
Verified Two notes:
AI-assisted (Claude Code). |
Change
vzeroallinstructions intools/ffx_version_query.py:vbroadcastss,vbroadcastsd,vbroadcastf128,vextractf128,vinsertf128,vperm2f128vpermilps,vpermilpd,vshufps,vshufpd,vunpcklps,vunpckhps,vunpcklpd,vunpckhpd,vmovddup,vmovsldup,vmovshdupvblendps,vblendpd,vblendvps,vblendvpd,vdpps,vdppd,vroundps,vroundpd,vzeroallEncodingKind.VEX(rejecting EVEX and MXCSR rounding mode imm8 & 4 != 0) and zero upper YMM bytes for 128-bit XMM destinations.OSXSAVE) and 28 (AVX) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 withSKIP_RETURN_CODE 77on hosts without AVX).tests/cpu/avx_shuffle_blend.{asm,def,py}, CMake targetcpu_avx_shuffle_blend_lifted, CTestcpu_aot_avx_shuffle_blend, coverage mapping intools/form_coverage.py, and documentation indocs/experiments.md.Verification
cmake --build --preset dev --target cpu_avx_shuffle_blend_lifted:ValueError: unsupported query operation at 0x1000: vbroadcastss ymm0,dword ptr [rcx]cmake --build --preset dev --target cpu_avx_shuffle_blend_liftedsucceeded with 0 warningsctest --preset dev --no-tests=error -R "^(cpu_aot_avx_shuffle_blend|cpu_aot_bmi1)$" -V: 2/2 passed (26 AVX broadcast/permute/shuffle/blend/dot/round/zeroall cases matched native and translated DLLs+ MXCSR-modevroundpsrejection control).\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py:form coverage checks passedEvidence and follow-up
AVX-grouped mnemonics indocs/coverage/x64_zen2.tsvusing source-built fixtures, gated by a runtime CPUID/XCR0 check.