Skip to content

SSE4a on Intel CPUs: MOVNTSS and MOVNTSD emulated - #234

Open
philip-sudowicki wants to merge 1 commit into
ivall:mainfrom
philip-sudowicki:sse4a-movnts
Open

philip-sudowicki wants to merge 1 commit into
ivall:mainfrom
philip-sudowicki:sse4a-movnts

Conversation

@philip-sudowicki

Copy link
Copy Markdown

SSE4a's scalar streaming stores, movntss m32, xmm (F3 0F 2B /r) and movntsd m64, xmm (F2 0F 2B /r), are emulated like EXTRQ / INSERTQ (#216, 0cd0a53 / af20b4b): on an Intel CPU they raise STATUS_ILLEGAL_INSTRUCTION too, and they were the part of SSE4a still missing. One commit on main 60565c4. No retail title is known to use them yet; this closes the set so a title that streams scalars (_mm_stream_ss / _mm_stream_sd) does not stop on Intel.

What is in it

  • crates/xcl/src/insn.rs: ConsoleOnly::Movnts { bytes, src, mem } and a memory-operand decoder (Mem, mem_operand, address): ModRM / SIB, disp8 / disp32, rip-relative, REX.R / X / B, 0x67 (32-bit address). The last of F2 / F3 decides, as for EXTRQ / INSERTQ; 0F 2B without them (movntps) or with 66 alone (movntpd) is not decoded, nor a register operand, nor a store through fs / gs (its segment base is not in the context).
  • crates/xcl/src/eh.rs: the store of the XMM register's low dword / quadword at the computed address; memory that is not readable is left to fault, as the real store would. End-to-end test sse4a_streaming_stores_run_in_a_title_image: real movntsd / movntss / rip-relative movntsd in a registered title page, through the vectored handler (on an AMD CPU they run natively, same results).
  • HANDOFF.md: the SSE4a sentence in "Console CPU instructions the PC lacks".

Tested

  • CPU: Intel Xeon @ 2.10 GHz, no SSE4a (the trap path runs: the log shows Movnts { .. } in …+0x5 – a console CPU instruction this CPU lacks: emulated)
  • Linux, cross-compiled x86_64-pc-windows-gnu (mingw-w64 13.2), Rust 1.97.0, debug; run under Wine 9.0
  • xcl-*.exe insn:: eh:: on top of 60565c4: 8 passed, 0 failed (the new decodes_the_sse4a_streaming_stores, memory_operand_addresses, sse4a_streaming_stores_run_in_a_title_image, and the existing insn / eh tests, clzero_with_an_address_size_prefix_zeroes_at_eax included)
  • cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: no warnings

Not tested

  • Windows itself, the MSVC toolchain, scripts/test.ps1 / the full suite (the D3D12 and audio tests cannot run under Wine on this machine)
  • an AMD CPU (the native path) and the F2 / F3 order on hardware for 0F 2B (it follows the rule measured for EXTRQ / INSERTQ in af20b4b)
  • any retail title

The rest of SSE4a after EXTRQ / INSERTQ (ivall#216): the scalar streaming stores
movntss m32, xmm (F3 0F 2B /r) and movntsd m64, xmm (F2 0F 2B /r) raise
STATUS_ILLEGAL_INSTRUCTION on an Intel CPU as well. They are decoded with
their memory operand (ModRM, SIB, disp8 / disp32, rip-relative, REX.R / X / B,
a 0x67 32-bit address; the last of F2 / F3 decides, as for EXTRQ / INSERTQ)
and done as a plain store of the XMM register's low dword / quadword. A store
through fs / gs is not decoded (its segment base is not in the context), and
one to memory that is not readable is left to fault, as the real store would.

Not seen in a retail title yet: this closes the SSE4a set, so a title that
streams scalars (_mm_stream_ss / _mm_stream_sd) does not stop on Intel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jb9jP9N4iPe9ifX4YaaTrF
@AlpPesen

Copy link
Copy Markdown
Contributor

Tested commit 099f1abe0fc8430f94fe8c1543a3e43bd5f19c17 natively on Windows 11 (MSVC) + Intel Core i9-9900K (Coffee Lake, no SSE4a) + AMD Radeon RX 6800 (driver 32.0.21045.29003, DXC 1.9.2602.17, rustc 1.100.0, debug).

Tested

  • XCL_REQUIRE_GPU=wave64,mesh + .\scripts\test.ps1: 654 passed, 0 failed, 40 ignored, 0 GPU skipped (xcl lib: 614 passed / 20 ignored; integration/e2e: 40 passed / 20 ignored; XCL_SAMPLE_* unset).
  • Confirmed on i9-9900K that eh::tests::sse4a_streaming_stores_run_in_a_title_image triggers the real #UD VEH trap (Movnts ... emulated (logged once)) and passes, alongside insn::tests::decodes_the_sse4a_streaming_stores and insn::tests::memory_operand_addresses.

Not tested

  • AMD CPU native execution path (no AMD host CPU here).
  • Retail title run (scripts/smoke.ps1).

Review notes

  1. crates/xcl/src/eh.rs (ConsoleOnly::Movnts): the write guard currently calls crate::gpu::shader::readable(at, bytes as usize) instead of is_writable(at, bytes as usize) (already used right above for Clzero/ClzeroLoop). For a PAGE_READONLY / PAGE_EXECUTE_READ target, readable() returns true and write_unaligned will fault inside the VEH instead of cleanly returning 0.
  2. HANDOFF.md: now that CONTRIBUTING.md is merged, feature PRs should leave HANDOFF.md untouched for the maintainer.
  3. Needs a rebase onto current main (especially around 0x67 handling in insn.rs after Console CPU instructions: CLZERO with an address-size prefix zeroes the line at EAX #227).

Tested and reviewed with Antigravity (Gemini 4 Neon); each point checked by the author before posting.

@ersinhf

ersinhf commented Nov 23, 2026

Copy link
Copy Markdown

Tested 099f1abe0fc8430f94fe8c1543a3e43bd5f19c17 on an AMD CPU with SSE4a (the native path this PR lists under Not tested), clean tree.

Tested

  • AMD Ryzen 5 7500F (Zen 4; CPUID 8000_0001 ECX bit 6 = SSE4a), 32 GB; NVIDIA GeForce RTX 4070, driver 621.14 (32.0.16.2114); Windows 11 build 26200; rustc 1.100.0 stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (SDK 10.0.26100.0); no XCL_SAMPLE_* set
  • .\scripts\test.ps1: 654 passed, 0 failed, 40 ignored; SKIPPED 2 (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • eh::tests::sse4a_streaming_stores_run_in_a_title_image, insn::tests::decodes_the_sse4a_streaming_stores and insn::tests::sse4a_bit_fields pass. On this CPU the first one runs the stores natively, so the expected memory contents it asserts are what the hardware writes.

The F2 / F3 order of 0F 2B on hardware

A standalone probe (not part of XCL) ran movq xmm0, rdx; <prefixes> 0F 2B 01; ret natively on the 7500F into a 0xAA-filled buffer and counted the bytes written:

prefixes bytes stored
F3 0F 2B 4 (movntss)
F2 0F 2B 8 (movntsd)
F2 F3 0F 2B 4
F3 F2 0F 2B 8
66 F2 0F 2B / F2 66 0F 2B 8 / 8
66 F3 0F 2B / F3 66 0F 2B 4 / 4

So on Zen 4 the last of F2 / F3 decides and a 66 next to them does not matter, the same rule as for EXTRQ / INSERTQ. That is what decode does and what decodes_the_sse4a_streaming_stores asserts (F2 F3 → 4 bytes, 66 F2 → 8 bytes).

Not tested

  • Zen 2 itself (the console's CPU) and Intel (covered by the report above)
  • the fs / gs-relative and 0x67 forms on hardware (the probe used [rcx] only)
  • a retail title / scripts/smoke.ps1

AI use

  • Claude Code with Claude Opus 5.5 ran the build, the suite and the probe on this machine and wrote this comment; the person posting it checked each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants