cpu: lower AVX quadword move and byte-masked store #1011
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1018"
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 Ammmae0x on 2026-11-23T21:29:09Z.
Change
Add a bounded leaf translator (
tools/cpu_avx_fp_move_aot.py), MASM differential fixture (tests/cpu/avx_fp_move.asm,tests/cpu/avx_fp_move.def), verification suite (tests/cpu/avx_fp_move_check.py), CMake registration (cpu_aot_avx_fp_movewithSKIP_RETURN_CODE 77), and documentation entry (docs/experiments.md) covering four newly covered x64AVXmnemonics fromdocs/coverage/x64_zen2.tsv:vaddsubps(xmmandymm, register and flatm128/m256)vaddsubpd(xmmandymm, register and flatm128/m256)vmovq(all fiveVEX.128operand shapes:xmm, xmm;xmm, m64;m64, xmm;xmm, r64;r64, xmm)vmaskmovdqu(VEX.128conditional byte store to implicit[rdi], requiring nonvolatilerdisave/restore via a volatile scratch GPR aroundmov rdi, r8)The translator models
YMM0..YMM5as portableVec256structs without/arch:AVX, zeroesYMM[255:128]onVEX.128writes andYMM[255:64]onvmovqXMMwrites, preserves x86src1-first NaN precedence/quieting and real-indefinite QNaN semantics, preserves dead-read fault ordering at/O2withstd::atomic_signal_fenceand volatile reads inload64/load128/load256, supportsvmovups/vmovaps/vmovdqu/vmovdqa/vzeroupper/64-bitmov/rettransport glue, and rejects legacy SSE, EVEX, nonvolatile registers, non-r8stores, prefixes, RIP-relative addressing, and trailing bytes afterret.Verification
Verified on commit
b7b6354across bothdev(Debug) andrelease(/O2) presets (0 errors, 0 warnings):cmake --build --preset dev --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted cpu_avx_pcmpstr_original cpu_avx_pcmpstr_original_lifted cpu_avx_pcmpstr_altered cpu_avx_pcmpstr_altered_lifted cpu_sse_fp_original cpu_sse_fp_original_lifted cpu_sse_fp_altered cpu_sse_fp_altered_lifted: 0 errors, 0 warningscmake --build --preset release --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted cpu_avx_pcmpstr_original cpu_avx_pcmpstr_original_lifted cpu_avx_pcmpstr_altered cpu_avx_pcmpstr_altered_lifted cpu_sse_fp_original cpu_sse_fp_original_lifted cpu_sse_fp_altered cpu_sse_fp_altered_lifted: 0 errors, 0 warningsctest --preset dev --no-tests=error -R "^(cpu_aot_avx_fp_move|cpu_aot_avx_pcmpstr|cpu_aot_sse_fp)$" -V: 3/3 Passed (cpu_aot_avx_fp_move: 257 native/lifted/reference cases across 20 exports, 5ALTER_OPdivergence controls,op_discarded_read/op_discarded_read64dead-read fault ordering, 32-byte guard buffers, output mutation control, 7 alternate-encoding lift checks, 37 unit rejection controls, and 8 PE-patched DLL rejection controls;cpu_aot_avx_pcmpstr: 1274 cases / 22 exports;cpu_aot_sse_fp: 720 cases / 34 exports)ctest --preset release --no-tests=error -R "^(cpu_aot_avx_fp_move|cpu_aot_avx_pcmpstr|cpu_aot_sse_fp)$" -V: 3/3 Passed with identical counts.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: passed.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: passed (13 Markdown files, 217 links).\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: passed (847 tracked files)tools/form_coverage.pyoncpu_aot_avx_fp_moveJUnit output:avx_fp_move.asmclassified aspass(x64_zen211/948 covered,AVX9/256)Evidence and follow-up
All fixtures are original source-built MASM and Python tests submitted under the MIT License (
tests/cpu/avx_fp_move.asm,tests/cpu/avx_fp_move.def,tests/cpu/avx_fp_move_check.py) with synthetic IEEE-754 binary32/binary64 edge cases, bit patterns, byte-mask boundary inputs (0x7f/0x80), and negative controls (ALTER_OP, dead-read fault ordering, single-bit output mutation, 37 unit rejections, and 8 PE-patched DLL rejections). Tests skip with return code 77 when the host lacks AVX/OSXSAVE. Non-default MXCSR modes, control flow, and nonvolatile XMM prologues remain out of scope.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:33:29Z.
This overlaps #1015's
vaddsubpsandvaddsubpd, which use the shared lowerer and have an independent Release comparison across seven MXCSR modes. Please split this contribution around the remaining move and store cases. Compare eachvmovqencoding against the existing shared branch first, so we can extend only the missing operand forms rather than add a second FP translator. Keep the useful dead-read and alternate-encoding controls.I reproduced a separate definedness error on
b7b63548withmov rax,rcx; mov rax,rdi; vmovq xmm0,rax; vmovups [r8],xmm0; ret. The generated body stores RCX because the symbolic save of RDI leaves the former RAX value defined. The incoming RDI is outside this ABI. Mark the scratch register unavailable to ordinary consumers after an RDI save, while retaining it for restoration, and add this rejection control. Forvmaskmovdqu, keep the byte masks and compare a synthetic page-edge case natively before promising behavior when part of the vector points outside writable memory.Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T22:00:05Z.
Updated PR #1018 in commit
ff4b71b(mergedupstream/maincleanly and retitled tocpu: lower AVX quadword move and byte-masked store):vaddsubps/vaddsubpd: Removedvaddsubps,vaddsubpd, and all FP arithmetic (fp_arith,ADDSUB_SPECS,_FPFormat, and theop_vaddsub*exports) fromtools/cpu_avx_fp_move_aot.py,tests/cpu/avx_fp_move.*,CMakeLists.txt, anddocs/experiments.md(since #1015 landed inupstream/main). Addedout_of_scope_vaddsubpsto verify it stays rejected here.vmovqencodings against existing translators: Checkedtools/cpu_avx_move_aot.py(which explicitly carves out and rejects allvmovqencodings as verified bytests/cpu/avx_move_regs_check.pyandtests/form_coverage_check.py) andtools/ffx_version_query.py(which only lowersm64load/store forms underhas_widewithoutxmm<-xmm,xmm<-r64,r64<-xmm, orrdisave/restore). Kept all fourVEX.128vmovqCodevariants (VEX_VMOVQ_XMM_XMMM64,VEX_VMOVQ_XMMM64_XMM,VEX_VMOVQ_XMM_RM64,VEX_VMOVQ_RM64_XMM) across all five operand shapes alongsidevmaskmovdqu, theop_discarded_read/op_discarded_read64dead-read controls, and 8 alternate-encoding checks (includingvmovq_6e_m64).RDI-save definedness bug: Onmov <scratch>, rdi,defined_gpr.discard(dst_gpr)now marks the scratch GPR unavailable to ordinary consumers while keeping it incaller_rdi_holdersformov rdi, <scratch>restoration, andread_gprexplicitly rejects reads from a saved-rdiscratch register (GPR <reg> holds saved rdi). Addedrdi_save_clobbers_prior_def(the exactmov rax, rcx; mov rax, rdi; vmovq xmm0, rax; vmovups [r8], xmm0; retsequence),rdi_save_post_restore_still_unavail, andpe_rdi_save_leak.vmaskmovdqupage-edge behavior natively: Testedop_vmaskmovdqunatively withVirtualAlloc+PAGE_NOACCESSandPAGE_READONLYguard pages right after partial vectors (k = 16, 15, 8, 7, 1, 0): native hardware faults whenever any byte of[rdi..rdi+15]is outside writable memory even when all mask MSBs are clear (0x7F), and on unaligned page-crossingk=15writes may commit a writable 8-byte prefix before faulting. Kept byte masks inop_vmaskmovdqu, added pre-writedst[0]/dst[15]endpoint probes so the lifted helper matches the fault boundary while leaving writable prefix bytes unmodified, and added 68 native/lifted page-edge checks.Verification on
ff4b71b:cmake --build --preset dev --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted cpu_avx_move_regs_original cpu_avx_move_regs_original_lifted cpu_avx_move_regs_altered cpu_avx_move_regs_altered_lifted(0 errors, 0 warnings)cmake --build --preset release --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted cpu_avx_move_regs_original cpu_avx_move_regs_original_lifted cpu_avx_move_regs_altered cpu_avx_move_regs_altered_lifted(0 errors, 0 warnings)ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_fp_move|cpu_aot_avx_move_regs)$" -Vandrelease: both passed 2/2 (cpu_aot_avx_fp_move: 134 differential cases across 7 exports, 68 native/lifted page-edge checks, 3ALTER_OPcontrols diverging on 14/12/30 cases, dead-read fault ordering, output-mutation control, 8 alternate-encoding lift checks, 38 unit rejection controls, and 9 PE-patched DLL rejection controls)..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py: all passed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:05:02Z.
The new RDI-save test addresses the stale-value issue and the separated move scope is useful. The masked-store helper still reads and writes both endpoints even for an all-zero mask. Those writes are absent from the guest instruction and can overwrite another observer's update. The test also accepts modified prefix bytes from native execution while requiring an untouched prefix from the lifted version. That is a measured difference in partial-fault behavior. Intel documents all-zero-mask faulting as implementation-dependent.
Please keep the page-edge probe as a native observation. For a portable first slice, require the entire 16-byte destination to be writable ordinary memory and touch only selected bytes. Keep the page-abutting writable case, zero mask, and sparse mask checks. If the profile needs to promise native page-edge faults and partial progress, use a separately verified native-instruction path and compare the fault type, access direction and committed bytes. The VMOVQ forms can also proceed independently. Intel SDM, MASKMOVDQU
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T22:14:55Z.
Updated PR #1018 in commit
5e3ae8f(tools/cpu_avx_fp_move_aot.py,tests/cpu/avx_fp_move_check.py,docs/experiments.md):op_vmaskmovdqusemantics: Removed thedst[0]/dst[15]endpoint read/write probes so the lifted helper touches only bytes selected by(mask[i] & 0x80) != 0and never reads or writes unselected bytes (matching an all-zero mask with zero memory accesses).[rdi..rdi+15]must be writable ordinary memory, while movingk < 16VirtualAlloc+PAGE_NOACCESS/PAGE_READONLYpage-edge probing to a native-only observation (30cases) and keeping both native and lifted differential checks onk = 16page-abutting writable vectors (12cases across full, all-zero, and sparse masks).Verification on
5e3ae8f:cmake --build --preset dev --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted(0 errors, 0 warnings)cmake --build --preset release --clean-first --target cpu_avx_fp_move_original cpu_avx_fp_move_original_lifted cpu_avx_fp_move_altered cpu_avx_fp_move_altered_lifted(0 errors, 0 warnings)ctest --preset dev --no-tests=error -R "^cpu_aot_avx_fp_move$" -Vandrelease: passed 1/1 on both (134differential cases across7exports,12k=16page-abutting checks,30native-onlyk<16page-edge fault observations,3ALTER_OPcontrols diverging on14/12/30cases, dead-read fault ordering, output-mutation control,8alternate-encoding lift checks,38unit rejection controls, and9PE-patched DLL rejection controls)..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py,tests/docs_links_check.py(13 files, 224 links), andtests/bidi_controls_check.py(867 files): all passed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:22:46Z.
The selected-byte helper addresses the endpoint access problem. In
9db7a26I kept the native page-edge cases and made them record the fault status and written prefix. A selected byte in the protected page still requires an access violation, and bytes in the writable prefix must be unchanged or contain their selected value. This also permits hardware-specific success when only writable bytes are selected. Releasecpu_aot_avx_fp_movepassed locally: 134 differential cases, 12 page-abutting native/lifted cases and 30 separate native page-edge observations. The lifted contract remains a fully writable ordinary 16-byte range.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:42:57Z.
The new AVX checks passed in CI. The /O2 job failed because the existing native package-ordinal startup child timed out at 30 seconds, outside this PR's AVX path. I restarted the failed job on the same head,
9db7a26. The PR stays open until both Windows jobs are green.