Skip to content

x64_recomp: SSE/SSE2 scalar floating-point and XMM move/bitwise emitters (X64-RECOMP-SSE-SCALAR) - #1202

Closed
quietfold wants to merge 1 commit into
ProjectLeonida:mainfrom
quietfold:feat/x64-recomp-sse-scalar
Closed

quietfold wants to merge 1 commit into
ProjectLeonida:mainfrom
quietfold:feat/x64-recomp-sse-scalar

Conversation

@quietfold

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: X64-RECOMP-SSE-SCALAR (#14 (comment))

What and why

Advances Next Step #2 of docs/mobile.md by adding legacy 0F SSE/SSE2 scalar floating-point, conversion, comparison, and 128-bit XMM move/bitwise decoding and arm64 emission to tools/x64_recomp.py (independent of #1174 and conflict-free with all open x64_recomp PRs).

  • Prefix-aware 0F SSE/SSE2 decoder (_OF_SSE): decodes xmm0–xmm15 (("x", reg, size)), width specs x (16B) and y (4/8B via REX.W, ignoring 0x66), mandatory F2/F3 precedence over 66, and keeps unprefixed MMX encodings as unhandled "simd".
  • arm64 FP/SIMD assembler (Asm): adds fldr/fstr (S/D/Q), fadd/fsub/fmul/fdiv/fsqrt, fcmp/fcsel, fmov_r/fmov_to_fp/fmov_to_gpr, fcvt_s2d/fcvt_d2s, scvtf/fcvtzs/fcvtns, vins0, vand16b/vbic16b/vorr16b/veor16b, plus EL1 CPACR_EL1.FPEN enable in build_test_kernel for bare-metal QEMU runs.
  • Translator (XMAP: xmm0–xmm15 -> v0–v15, scratch v28–v30):
    • Scalar add/sub/mul/div/sqrt/min/max (ss/sd), cvt*, and register movss/movsd write lane 0 via ins so upper XMM bits are preserved; memory movss/movsd and movd/movq zero-extend to 128 bits.
    • minss/minsd/maxss/maxsd implement exact x86 NaN and ±0.0 second-operand rules via fcmp + fcsel (mi/gt) while preserving live NZCV.
    • ucomis*/comis* (FCMP_KIND) map all 16 x86 conditions across ordered and unordered (PF/ZF/CF, OF=SF=AF=0) results on both the arm64 NZCV fast path and materialized CTX_EFLAGS (including setcc, cmov, pushf, lahf, adc/sbb/cmc, and intervening inc/dec).
    • Float-to-int conversions (cvttss2si/cvttsd2si/cvtss2si/cvtsd2si, 32/64-bit) return x86 integer indefinite (INT32_MIN/INT64_MIN) for NaN and overflow (including 2147483647.5 for cvtsd2si vs cvttsd2si) while preserving live NZCV.
    • 128-bit moves (movaps/movups/movapd/movupd/movdqa/movdqu) and bitwise ops (xorps/xorpd/pxor, andps/andpd/pand, andnps/andnpd/pandn as (~dst) & src, orps/orpd/por).
  • Two pre-existing flag-path bugs surfaced by hardware execution and fixed:
    • _ctx_jcc_reg emitted tst_i(w, EF_CF | EF_ZF) (0x41 is not a valid arm64 bitmask immediate) on cross-block ja/jbe/seta/setbe; replaced with movz + tst_r.
    • _classify tagged lahf/sahf as kind="conv" instead of "alu", making their _emit_alu handler unreachable.
  • Tests (tests/test_x64_recomp_sse.py): 16 tests covering decoding, LLVM 21–verified arm64 FP/SIMD encodings, translation/liveness, and 8 end-to-end execution tests (SSEExecTests, which run automatically with the Mach-O runner once #1174 lands or under QEMU).

Tested

  • Standalone on main: python3 -I tests/test_x64_recomp_sse.py -v (8 cross-platform passed, 8 exec cleanly skipped without QEMU), tests/test_x64_recomp.py, tests/test_recomp_census.py, tests/test_ci_registration.py, tests/test_text_write_line_endings.py, tests/test_tool_startup.py, all 11 tests/test_docs_*.py, tests/test_i18n_index.py, compileall, make_game.py --help, check_no_game_data.py: all passed.
  • Native arm64 hardware execution on Apple M5 / macOS 27.2.1 (Python 3.14, cleanly merged atop #1174 in a scratch checkout): tests/test_x64_recomp_sse.py 16/16 passed (all 8 SSEExecTests executed natively) and tests/test_x64_recomp.py 46/46 passed.
  • Verified zero conflicts (git apply --check) against open x64_recomp PRs #847, #950, #1120, #1121, and #1174.

GPUs tested: n/a (CPU x86-64 -> arm64 recompiler; tested natively on Apple M5 arm64, macOS 27.2.1)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): tools/x64_recomp.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR cannot merge in its current state:

  • Merge conflict with main in tools/x64_recomp.py.
  • No green CI run on current head e61deb5.

Please rebase onto current main and obtain a green CI run.

(AI-assisted review.)

@quietfold quietfold closed this by deleting the head repository Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants