runtime(cpu): add ahead-of-time AVX1/SSE4.2 stub compiler for pre-Haswell hosts #2414

Merged
leonida/mandy
robot00f merged 5 commits from feat/rt-cpu-avx1-aot-patch into main 2026-11-29 01:02:51 +00:00

Pull request successfully merged and closed

robot00f commented 2026-11-26 23:57:18 +00:00

Claimed in the coordination issue as: RT-CPU-AVX1-AOT-PATCH (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7205557017)

Depends on: #2190, #2191

What and why

While #2190 and #2191 enable pre-Haswell AVX1 + SSE4.2 hosts (Intel Sandy Bridge and Ivy Bridge) to execute BMI1, BMI2, MOVBE, F16C, FMA3 and AVX2 instructions via #UD (STATUS_ILLEGAL_INSTRUCTION), each #UD round-trip through KiUserExceptionDispatcher costs ~4,000–6,000 cycles, stalling hot decompression and SIMD loops.

Add runtime/src/isa_jit_patch.h and wire it into Loader::protect_sections (runtime/src/pe_loader.cpp) before executable sections are write-protected (LEONIDA_ISA_PATCH=0 disables it):

  • Same-length in-place AVX1 VEX rewrites (zero stub overhead): rewrites bit-identical 256-bit vpand/vpandn/vpor/vpxor (-> vandps/vandnps/vorps/vxorps), vextracti128/vinserti128/vperm2i128 (-> *f128), vbroadcasti128 m128 (-> vbroadcastf128), vpblendd (-> vblendps), vpbroadcastd m32 (-> vbroadcastss), and vpbroadcastq ymm, m64 (-> vbroadcastsd).
  • Out-of-line native x86-64 + AVX1 stubs (jmp rel32 within ±2 GiB):
    • >=5-byte BMI1, BMI2, and MOVBE sites compile to native GPR sequences preserving or computing exact architectural RFLAGS (including [rsp + disp] stack adjustments, [rip + disp32] relocation, rcx/rax/rdx register-aliasing handling, and 16-bit movbe).
    • >=5-byte AVX2 and FMA3 sites compile to native AVX1 (YMM + 2x128-bit XMM via vextractf128/vinsertf128, flag-preserving lea rsp, [rsp ± N] scratch spills, and upper-128 zeroing on scalar FMA3).
    • 4-byte 0xC5 AVX2 sites fuse forward with the immediately following instruction when a whole-module target scan (exports, relocations, .pdata unwind scopes, data/gap RVA tables, and direct branches) confirms the interior boundary is never targeted.
  • Any unpatched site (F16C, vpmaskmov*, pdep/pext, unfusable 4-byte sites) stays intact and falls back cleanly to #UD emulation (#2190, #2191). Zero changes to cpu_emulation.h.

Tested

  • Built and ran ctest -R "^(isa_jit_patch|bmi_emulation|avx2_emulation|pe_loader)$" live on an Intel Core i7-2600 (Sandy Bridge, AVX1 + SSE4.2, bmi1=0 bmi2=0 movbe=0 avx2=0 fma=0 f16c=0, Windows 10 19045):
    • isa_jit_patch_test: 45 instruction families × 8 randomized GPR/YMM/RFLAGS trials + 2 fused 4B+6B / 4B+8B RIP-relative pairs + synthetic PE32+ image test (in-place rewrites, BMI/AVX2/FMA3 stubs, unmarked 4B fusion, RVA-table fusion refusal, and LEONIDA_ISA_PATCH=0), all executing with 0 #UD traps and exact state parity.
  • python -I tests/test_ctest_registration.py, python -I tests/test_docs_env_vars.py, test_docs_links.py, test_docs_repo_paths.py, test_text_write_line_endings.py, and python -I scripts/check_no_game_data.py: all clean.

GPUs tested: n/a (CPU runtime; tested on Intel Core i7-2600, Sandy Bridge, AVX1 + SSE4.2, Windows 10 19045)

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. (n/a — x86-64 CPU runtime only)
Claimed in the coordination issue as: RT-CPU-AVX1-AOT-PATCH (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7205557017) Depends on: #2190, #2191 ### What and why While #2190 and #2191 enable pre-Haswell `AVX1 + SSE4.2` hosts (Intel Sandy Bridge and Ivy Bridge) to execute `BMI1`, `BMI2`, `MOVBE`, `F16C`, `FMA3` and `AVX2` instructions via `#UD` (`STATUS_ILLEGAL_INSTRUCTION`), each `#UD` round-trip through `KiUserExceptionDispatcher` costs ~4,000–6,000 cycles, stalling hot decompression and SIMD loops. Add `runtime/src/isa_jit_patch.h` and wire it into `Loader::protect_sections` (`runtime/src/pe_loader.cpp`) before executable sections are write-protected (`LEONIDA_ISA_PATCH=0` disables it): - **Same-length in-place `AVX1` VEX rewrites (zero stub overhead):** rewrites bit-identical 256-bit `vpand`/`vpandn`/`vpor`/`vpxor` (`-> vandps`/`vandnps`/`vorps`/`vxorps`), `vextracti128`/`vinserti128`/`vperm2i128` (`-> *f128`), `vbroadcasti128 m128` (`-> vbroadcastf128`), `vpblendd` (`-> vblendps`), `vpbroadcastd m32` (`-> vbroadcastss`), and `vpbroadcastq ymm, m64` (`-> vbroadcastsd`). - **Out-of-line native `x86-64` + `AVX1` stubs (`jmp rel32` within `±2 GiB`):** - `>=5`-byte `BMI1`, `BMI2`, and `MOVBE` sites compile to native GPR sequences preserving or computing exact architectural `RFLAGS` (including `[rsp + disp]` stack adjustments, `[rip + disp32]` relocation, `rcx`/`rax`/`rdx` register-aliasing handling, and 16-bit `movbe`). - `>=5`-byte `AVX2` and `FMA3` sites compile to native `AVX1` (`YMM` + `2x128`-bit `XMM` via `vextractf128`/`vinsertf128`, flag-preserving `lea rsp, [rsp ± N]` scratch spills, and upper-128 zeroing on scalar `FMA3`). - `4`-byte `0xC5` `AVX2` sites fuse forward with the immediately following instruction when a whole-module target scan (exports, relocations, `.pdata` unwind scopes, data/gap RVA tables, and direct branches) confirms the interior boundary is never targeted. - Any unpatched site (`F16C`, `vpmaskmov*`, `pdep`/`pext`, unfusable 4-byte sites) stays intact and falls back cleanly to `#UD` emulation (#2190, #2191). Zero changes to `cpu_emulation.h`. ### Tested - Built and ran `ctest -R "^(isa_jit_patch|bmi_emulation|avx2_emulation|pe_loader)$"` live on an **Intel Core i7-2600** (Sandy Bridge, `AVX1 + SSE4.2`, `bmi1=0 bmi2=0 movbe=0 avx2=0 fma=0 f16c=0`, Windows 10 `19045`): - `isa_jit_patch_test`: 45 instruction families × 8 randomized GPR/YMM/`RFLAGS` trials + 2 fused `4B+6B` / `4B+8B` RIP-relative pairs + synthetic `PE32+` image test (in-place rewrites, BMI/AVX2/FMA3 stubs, unmarked 4B fusion, RVA-table fusion refusal, and `LEONIDA_ISA_PATCH=0`), all executing with `0` `#UD` traps and exact state parity. - `python -I tests/test_ctest_registration.py`, `python -I tests/test_docs_env_vars.py`, `test_docs_links.py`, `test_docs_repo_paths.py`, `test_text_write_line_endings.py`, and `python -I scripts/check_no_game_data.py`: all clean. GPUs tested: n/a (CPU runtime; tested on Intel Core i7-2600, Sandy Bridge, AVX1 + SSE4.2, Windows 10 19045) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — x86-64 CPU runtime only)
akimfomin commented 2026-11-27 00:16:50 +00:00

On native Windows / i5-13600KF I built and ran your exact synthetic test at 8cde0bef: 51 instruction families, two fused pairs and one synthetic PE image passed. LLVM-MinGW required -fms-extensions for SEH and emitted a missing explicit __cpuidex declaration warning. The host has AVX2/FMA/BMI; native pre-Haswell coverage remains open.

The useful next report is this same synthetic program on an AVX1-only host, with its printed capability line and exit code. If you have a volunteer or a receiving backport, PortBridge Test Lab can carry this one narrow task and return the credited result here. AI-assisted native test.

On native Windows / i5-13600KF I built and ran your [exact synthetic test at 8cde0bef](https://github.com/ubiquitarianism/leonida/blob/8cde0bef3922116bef153f2ab65ee6e8a8d01245/runtime/test/isa_jit_patch_test.cpp): 51 instruction families, two fused pairs and one synthetic PE image passed. LLVM-MinGW required -fms-extensions for SEH and emitted a missing explicit __cpuidex declaration warning. The host has AVX2/FMA/BMI; native pre-Haswell coverage remains open. The useful next report is this same synthetic program on an AVX1-only host, with its printed capability line and exit code. If you have a volunteer or a receiving backport, [PortBridge Test Lab](https://akimfomin.github.io/PortBridge/#/lab) can carry this one narrow task and return the credited result here. AI-assisted native test.
timbot103 reviewed 2026-11-28 03:21:02 +00:00
timbot103 left a comment
No description provided.
Built and tested head `402035db4` on native Windows 11 x64 (Ryzen 9 9950X3D, MSVC `19.44.35230.0`, Ninja RelWithDebInfo). Existing CTest targets (`pe_loader`, `cpu_emulation`, `bmi_emulation`, `avx2_emulation`, `isa_jit_patch`) pass 5/5 (`isa_jit_patch_test`: 51 single-insn families + 2 fused pairs + synthetic PE32+), along with `tests/test_ctest_registration.py` (6/6) and `tests/test_docs_env_vars.py` (5/5). However, static inspection and live execution against `runtime/src/isa_jit_patch.h` reproduce **three blocking correctness/stability bugs** in the AOT stub compiler: 1. **FMA stubs lose fused rounding and suffer intermediate overflow (`runtime/src/isa_jit_patch.h:695-736, 1352-1363`):** `emit_avx2_fma_body` lowers FMA3 to separate `VMUL` + `VADD`/`VSUB` (double rounding), diverging from both native FMA hardware and the existing `std::fmaf`/`std::fma` VEH fallback (`runtime/src/avx2_emulation.h:845-865`). The existing test (`runtime/test/isa_jit_patch_test.cpp:339-340, 444`) masks this by generating `0.125f` steps and allowing `1e-3f` absolute error. Live repro on `vfmadd213ss xmm0, xmm1, xmm2`: - Cancellation (`a=0x3F800001, b=0x3F7FFFFE, c=0xBF800000`): `std::fmaf` = native = `0xA8800000`, AOT stub = `0x00000000`. - Intermediate overflow (`a=0x7F000000, b=0x40000000, c=0xFF000000`): `std::fmaf` = native = `0x7F000000`, AOT stub = `0x7F800000` (`+inf`). Keep FMA on the existing exact fallback until the emitted code implements fused rounding, and compare FMA test outputs bit-for-bit. 2. **`movbe [mem], rsp` stores `bswap64(original_rsp - 8)` (`runtime/src/isa_jit_patch.h:246-271`):** `bmi_emulation::decode` accepts `movbe qword ptr [r8], rsp` (`49 0F 38 F1 20`), and the VEH fallback reads original `RSP`. In `emit_bmi_body`, pushing a scratch GPR decrements `RSP` before copying `d.src1`, and the RSP displacement adjustment only covers the memory operand — not a register source of `rsp`. Live repro on `movbe qword ptr [r8], rsp` (reading the stored 8 bytes byte-swapped back): - Native: `rsp = 0x000000EA121AF9D8`, stored value byte-swapped back = `0x000000EA121AF9D8` (`diff = 0`). - AOT stub: `rsp = 0x000000EA121AF9D8`, stored value byte-swapped back = `0x000000EA121AF9D0` (`diff = -8`). Preserve the pre-push RSP value when `d.src1 == 4` or decline to AOT-patch `movbe [mem], rsp`. 3. **Stack-adjusting out-of-line stubs break Windows x64 SEH unwinding (`runtime/src/isa_jit_patch.h:829-836, 1496-1516`, `runtime/src/pe_loader.cpp:1617-1642, 2219-2227`):** Relocated AVX2 memory-operand stubs adjust the stack (`lea rsp, [rsp-64]`, spilling YMMs onto the stack) and then perform the original memory access at an out-of-image stub address with no Windows `.pdata`/runtime unwind table entry. If that memory access faults, Windows unwinds the stub PC as a leaf function, reads spilled scratch data from `[rsp]` as the return address, and cannot unwind to the protected caller/guest SEH handler. Live subprocess repro calling a leaf function executing `vpaddd ymm0, ymm1, ymmword ptr [rcx]` (`C4 E1 75 FE 01`) with `rcx = nullptr` from a host `__try / __except` frame: - Unpatched: `__except` catches `0xC0000005` cleanly (`exit 0`). - Patched via `emit_avx2_fma_body`: unwind fails and the process terminates unhandled with `0xC0000005`. Either register proper unwind/exception handling mapping stub faults back to the original site or keep stack-adjusting memory-accessing sites on the fallback until unwind coverage is in place. No game data used. AI-assisted review (Codex static audit + Gemini live MSVC verification).
zmasi commented 2026-11-28 23:58:06 +00:00

Windows 11 Native Verification Report (402035db49 merged onto origin/main a9e247cd69)

  • Merge Status: Clean merge onto origin/main (a9e247cd69) and clean in a 5-PR runtime/ batch merge.
  • Environment: Windows 11 (10.0.26200, x64), MSVC 19.44.35228, Python 3.12.10 (synthetic machine-code pages and PE32+ fixtures only; zero game binaries).

Diff Audit (10 files, +4,987/-0)

  • runtime/src/avx2_emulation.h: VEX decoder and vectored #UD (STATUS_ILLEGAL_INSTRUCTION) handler for F16C, FMA3, and AVX2, reading/writing 256-bit YMM0..YMM15 through CONTEXT::FltSave.XmmRegisters and LocateXStateFeature(XSTATE_AVX) (zeroing YMM[dst][255:128] on 128-bit VEX writes, zero-initializing untouched upper lanes when XSTATE_MASK_AVX transitions from clean to active, and suppressing faults on disabled VPMASKMOV* lanes).
  • runtime/src/bmi_emulation.h: #UD decoder/handler for BMI1, BMI2, MOVBE, and TZCNT/LZCNT plus .pdata/leaf TZCNT/LZCNT rewriting (>= 5-byte 32/64-bit register sites to branchless BSF/BSR + CMOV + BT stubs; 4-byte/16-bit/memory/RSP sites to UD2 + side-table).
  • runtime/src/isa_jit_patch.h: Ahead-of-time AVX1 + SSE4.2 + x86-64 rewriter and trampoline compiler invoked in Loader::protect_sections (same-length AVX1 VEX rewrites, >= 5-byte BMI1/BMI2/MOVBE/AVX2/FMA3 out-of-line stubs within +-2 GiB registered in Loader::ranges_, LEONIDA_ISA_PATCH=0 kill-switch, and opt-in LEONIDA_ISA_FUSE_4B=1 4-byte 0xC5 fusion guarded against exports, relocations, .pdata unwind scopes, data/gap RVA tables, direct branches, and Clang table-relative .rdata switch tables).

Red -> Green Verification

  1. Red (origin/main a9e247cd69):
    • runtime/src/avx2_emulation.h, runtime/src/bmi_emulation.h, and runtime/src/isa_jit_patch.h are absent on origin/main.
  2. Green (#2414 + origin/main):
    • bmi_emulation_test.exe (/O2 /MD /EHsc /W4 /permissive- /utf-8, 0 warnings): bmi_emulation_test: OK (65 checks) (0.06 s, rc=0).
    • avx2_emulation_test.exe (/O2 /MD /EHsc /W4 /permissive- /utf-8, 0 warnings): avx2_emulation_test: OK (38 checks) (0.07 s, rc=0), verifying F16C RN/RD/RU/RZ rounding + subnormals/NaN, VEX negative rejections, XSTATE_AVX 256-bit state & VPMASKMOVD PAGE_NOACCESS boundary handling, and live 256-bit FMA3/F16C/AVX2 execution.
    • isa_jit_patch_test.exe (/O2 /MD /EHsc /W4 /permissive- /utf-8): isa_jit_patch_test: OK (51 single-insn families + 2 fused pairs + synthetic PE32+ image) (0.07 s, rc=0), verifying 0 #UD traps and exact GPR/YMM/RFLAGS parity across 8 randomized trials per family plus LEONIDA_ISA_PATCH=0 and LEONIDA_ISA_FUSE_4B=1 RVA & Clang relative switch-table refusal.
    • loader_test.exe (/O2 /MD /EHsc /W4 /permissive- /utf-8, 0 warnings): 115 checks, 0 failed (20.11 s, rc=0).
    • runtime/src/main.cpp (/c /O2 /MD /EHsc /W4 /permissive- /utf-8 /DLEONIDA_VULKAN_DEVICE): compiled cleanly (rc=0).
    • Repo & CI gates: test_docs_env_vars.py, test_docs_repo_paths.py, test_docs_table_rows.py, test_docs_encoding.py, test_ctest_registration.py, and test_ci_registration.py all passed (OK, rc=0).

Non-Blocking Audit Notes

  1. VirtualSize == 0 executable sections in pe_loader.cpp:2261: isa_jit_patch::patch_image (isa_jit_patch.h:1150) uses sec->Misc.VirtualSize ? sec->Misc.VirtualSize : sec->SizeOfRawData, whereas the TZCNT/LZCNT loop in pe_loader.cpp:2261 uses std::min(cs->Misc.VirtualSize, cs->SizeOfRawData) (yielding 0 if an executable section has Misc.VirtualSize == 0 and SizeOfRawData > 0).
  2. 0x64 (FS:) prefix in bmi_emulation::decode / avx2_emulation::decode: both decoders accept 0x64 (FS) into d.seg while effective_addr() only adds NtCurrentTeb() for 0x65 (GS) and treats 0x64 as flat 0 (isa_jit_patch already rejects d.seg != 0).
  3. Out-of-line stub SEH unwind note: isa.stubs adjusts RSP (push / lea rsp, [rsp - 64]) without RtlAddFunctionTable unwind metadata; first-touch xmem and title_page_watch VEH handlers (EXCEPTION_CONTINUE_EXECUTION) work transparently, though guest __try/__except frame unwinding across an unhandled memory fault inside an out-of-line stub would treat the stub as a leaf function.

Verdict: PASS (with minor non-blocking notes above).

AI-assisted.

### Windows 11 Native Verification Report (`402035db49` merged onto `origin/main` `a9e247cd69`) - **Merge Status**: Clean merge onto `origin/main` (`a9e247cd69`) and clean in a 5-PR `runtime/` batch merge. - **Environment**: Windows 11 (`10.0.26200`, x64), MSVC `19.44.35228`, Python `3.12.10` (synthetic machine-code pages and PE32+ fixtures only; zero game binaries). #### Diff Audit (`10` files, `+4,987/-0`) - `runtime/src/avx2_emulation.h`: VEX decoder and vectored `#UD` (`STATUS_ILLEGAL_INSTRUCTION`) handler for `F16C`, `FMA3`, and `AVX2`, reading/writing 256-bit `YMM0..YMM15` through `CONTEXT::FltSave.XmmRegisters` and `LocateXStateFeature(XSTATE_AVX)` (zeroing `YMM[dst][255:128]` on 128-bit VEX writes, zero-initializing untouched upper lanes when `XSTATE_MASK_AVX` transitions from clean to active, and suppressing faults on disabled `VPMASKMOV*` lanes). - `runtime/src/bmi_emulation.h`: `#UD` decoder/handler for `BMI1`, `BMI2`, `MOVBE`, and `TZCNT`/`LZCNT` plus `.pdata`/leaf `TZCNT`/`LZCNT` rewriting (`>= 5`-byte 32/64-bit register sites to branchless `BSF`/`BSR + CMOV + BT` stubs; 4-byte/16-bit/memory/`RSP` sites to `UD2` + side-table). - `runtime/src/isa_jit_patch.h`: Ahead-of-time `AVX1 + SSE4.2 + x86-64` rewriter and trampoline compiler invoked in `Loader::protect_sections` (same-length `AVX1` VEX rewrites, `>= 5`-byte `BMI1`/`BMI2`/`MOVBE`/`AVX2`/`FMA3` out-of-line stubs within `+-2 GiB` registered in `Loader::ranges_`, `LEONIDA_ISA_PATCH=0` kill-switch, and opt-in `LEONIDA_ISA_FUSE_4B=1` 4-byte `0xC5` fusion guarded against exports, relocations, `.pdata` unwind scopes, data/gap RVA tables, direct branches, and Clang table-relative `.rdata` switch tables). #### Red -> Green Verification 1. **Red (`origin/main` `a9e247cd69`)**: - `runtime/src/avx2_emulation.h`, `runtime/src/bmi_emulation.h`, and `runtime/src/isa_jit_patch.h` are absent on `origin/main`. 2. **Green (`#2414` + `origin/main`)**: - `bmi_emulation_test.exe` (`/O2 /MD /EHsc /W4 /permissive- /utf-8`, **`0` warnings**): **`bmi_emulation_test: OK (65 checks)`** (`0.06 s`, `rc=0`). - `avx2_emulation_test.exe` (`/O2 /MD /EHsc /W4 /permissive- /utf-8`, **`0` warnings**): **`avx2_emulation_test: OK (38 checks)`** (`0.07 s`, `rc=0`), verifying `F16C` RN/RD/RU/RZ rounding + subnormals/NaN, VEX negative rejections, `XSTATE_AVX` 256-bit state & `VPMASKMOVD` `PAGE_NOACCESS` boundary handling, and live 256-bit `FMA3`/`F16C`/`AVX2` execution. - `isa_jit_patch_test.exe` (`/O2 /MD /EHsc /W4 /permissive- /utf-8`): **`isa_jit_patch_test: OK (51 single-insn families + 2 fused pairs + synthetic PE32+ image)`** (`0.07 s`, `rc=0`), verifying `0` `#UD` traps and exact GPR/YMM/RFLAGS parity across 8 randomized trials per family plus `LEONIDA_ISA_PATCH=0` and `LEONIDA_ISA_FUSE_4B=1` RVA & Clang relative switch-table refusal. - `loader_test.exe` (`/O2 /MD /EHsc /W4 /permissive- /utf-8`, **`0` warnings**): **`115 checks, 0 failed`** (`20.11 s`, `rc=0`). - `runtime/src/main.cpp` (`/c /O2 /MD /EHsc /W4 /permissive- /utf-8 /DLEONIDA_VULKAN_DEVICE`): compiled cleanly (`rc=0`). - Repo & CI gates: `test_docs_env_vars.py`, `test_docs_repo_paths.py`, `test_docs_table_rows.py`, `test_docs_encoding.py`, `test_ctest_registration.py`, and `test_ci_registration.py` all passed (`OK`, `rc=0`). #### Non-Blocking Audit Notes 1. **`VirtualSize == 0` executable sections in `pe_loader.cpp:2261`**: `isa_jit_patch::patch_image` (`isa_jit_patch.h:1150`) uses `sec->Misc.VirtualSize ? sec->Misc.VirtualSize : sec->SizeOfRawData`, whereas the `TZCNT`/`LZCNT` loop in `pe_loader.cpp:2261` uses `std::min(cs->Misc.VirtualSize, cs->SizeOfRawData)` (yielding `0` if an executable section has `Misc.VirtualSize == 0` and `SizeOfRawData > 0`). 2. **`0x64` (`FS:`) prefix in `bmi_emulation::decode` / `avx2_emulation::decode`**: both decoders accept `0x64` (`FS`) into `d.seg` while `effective_addr()` only adds `NtCurrentTeb()` for `0x65` (`GS`) and treats `0x64` as flat `0` (`isa_jit_patch` already rejects `d.seg != 0`). 3. **Out-of-line stub SEH unwind note**: `isa.stubs` adjusts `RSP` (`push` / `lea rsp, [rsp - 64]`) without `RtlAddFunctionTable` unwind metadata; first-touch `xmem` and `title_page_watch` VEH handlers (`EXCEPTION_CONTINUE_EXECUTION`) work transparently, though guest `__try/__except` frame unwinding across an unhandled memory fault inside an out-of-line stub would treat the stub as a leaf function. **Verdict**: **PASS** (with minor non-blocking notes above). AI-assisted.
enlight3d commented 2026-11-29 00:45:45 +00:00

Run of #2414 (isa_jit_patch, bmi_emulation, avx2_emulation, plus pe_loader as a regression check), red then green.

  • PR head: 402035db4935d794cfdca1833e7ef73765cc88c4. Current main: 1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3, merge base with the PR: 39f52f39c (the branch is about 2,670 commits behind main). git merge-tree --write-tree main <head> merges cleanly. I tested the PR head as it is, not the merge result.
  • GPU/driver: NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by these CPU-only unit tests). OS: Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake 3.31.6, Ninja 1.12.1, RelWithDebInfo.
  • Host CPU has native BMI/AVX2/FMA (i9-13900K), so these tests compare the patched/emulated sequences with the native instructions on this machine; they do not run on a pre-Haswell host (the PR's own run was on a Sandy Bridge i7-2600).
  • Only the four test targets (and their small dependencies) were built, not the whole runtime.

Commands (in a vcvars64 shell, build folder inside the worktree):

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build --target isa_jit_patch_test bmi_emulation_test avx2_emulation_test pe_loader_test -j 8
ctest -R "^(isa_jit_patch|bmi_emulation|avx2_emulation|pe_loader)$" --output-on-failure

Green (PR head): 4/4 passed (pe_loader 0.12 s, bmi_emulation 0.08 s, avx2_emulation 0.02 s, isa_jit_patch 0.02 s).

Red (non-test changes reverted to the merge base: bmi_emulation.h, avx2_emulation.h, isa_jit_patch.h removed, main.cpp and pe_loader.cpp restored; tests and CMake registration kept): the three new test targets do not build (C1083: cannot open include file for each header) and ctest gives bmi_emulation, avx2_emulation, isa_jit_patch (Not Run), 1 of 4 passed. pe_loader still passes, as expected: the PR does not change pe_loader_test, so it is only a regression check. Red is a build failure because the PR adds new headers. The stale test executables from the green build were deleted before this ctest.

Stack (checked with git merge-base --is-ancestor): #2190 is contained in #2191, which is contained in this PR, so merging #2414 brings both.
Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); new imports vs main: fma and fmaf (C runtime, api-ms-win-crt-math), GetXStateFeaturesMask, LocateXStateFeature and SetXStateFeaturesMask (KERNEL32).

Run of #2414 (`isa_jit_patch`, `bmi_emulation`, `avx2_emulation`, plus `pe_loader` as a regression check), red then green. - PR head: 402035db4935d794cfdca1833e7ef73765cc88c4. Current main: 1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3, merge base with the PR: 39f52f39c (the branch is about 2,670 commits behind main). `git merge-tree --write-tree main <head>` merges cleanly. I tested the PR head as it is, not the merge result. - GPU/driver: NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by these CPU-only unit tests). OS: Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake 3.31.6, Ninja 1.12.1, RelWithDebInfo. - Host CPU has native BMI/AVX2/FMA (i9-13900K), so these tests compare the patched/emulated sequences with the native instructions on this machine; they do not run on a pre-Haswell host (the PR's own run was on a Sandy Bridge i7-2600). - Only the four test targets (and their small dependencies) were built, not the whole runtime. Commands (in a vcvars64 shell, build folder inside the worktree): ``` cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build runtime/build --target isa_jit_patch_test bmi_emulation_test avx2_emulation_test pe_loader_test -j 8 ctest -R "^(isa_jit_patch|bmi_emulation|avx2_emulation|pe_loader)$" --output-on-failure ``` Green (PR head): 4/4 passed (pe_loader 0.12 s, bmi_emulation 0.08 s, avx2_emulation 0.02 s, isa_jit_patch 0.02 s). Red (non-test changes reverted to the merge base: `bmi_emulation.h`, `avx2_emulation.h`, `isa_jit_patch.h` removed, `main.cpp` and `pe_loader.cpp` restored; tests and CMake registration kept): the three new test targets do not build (`C1083: cannot open include file` for each header) and ctest gives `bmi_emulation`, `avx2_emulation`, `isa_jit_patch` (Not Run), 1 of 4 passed. `pe_loader` still passes, as expected: the PR does not change `pe_loader_test`, so it is only a regression check. Red is a build failure because the PR adds new headers. The stale test executables from the green build were deleted before this ctest. Stack (checked with `git merge-base --is-ancestor`): #2190 is contained in #2191, which is contained in this PR, so merging #2414 brings both. Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); new imports vs main: fma and fmaf (C runtime, api-ms-win-crt-math), GetXStateFeaturesMask, LocateXStateFeature and SetXStateFeaturesMask (KERNEL32).
MoonEyes commented 2026-11-29 01:02:54 +00:00

Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and gta6rt.exe still links) and a re-check here: no conflict with main 16f505304, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after **enlight3d** (Thib)'s red/green run ([RUN](https://github.com/ProjectLeonida/mandy/pull/2414#issuecomment-7248333477), RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and `gta6rt.exe` still links) and a re-check here: no conflict with `main` 16f505304, same head as run, `no-game-data` green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.