cpu: lower ENDBR64 and ENDBR32 as no-ops in the shared lowering #2848

Merged
R0D4X merged 1 commit from upstream-pr/2856 into main 2026-11-26 14:47:17 +00:00
R0D4X commented 2026-11-26 14:30:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-26T14:30:27Z.


Fixes #1476

Root Cause / Motivation

The first slice of #1476 (a1455727, a72a0929, 7368c1b6) lowered the documented RESERVEDNOP encodings (0F 19, 0F 1D, 0F 1E, 0F 1F) and deliberately left ENDBR64 (F3 0F 1E FA) and ENDBR32 (F3 0F 1E FB) refused for a separate follow-up. CET-instrumented functions (-fcf-protection) begin with endbr64, so they were still rejected by tools/ffx_version_query.py.

Summary

  • Shared lowering (tools/ffx_version_query.py): Add _ENDBR_CODES = frozenset((C.ENDBR64, C.ENDBR32)) and lower both exact iced_x86.Code values to ;. Per Intel SDM Vol. 2A, ENDBR64 and ENDBR32 affect no registers, flags, or memory, and on x64_zen2 (no CET-IBT) they execute as architectural NOPs. Neighbouring encodings (RDSSPD/RDSSPQ F3 0F 1E /1, CLDEMOTE, 0F 0D, 0F 18, 0F 1A-0F 1C, MPX) remain refused.
  • Unit & Refusal Controls (tests/cpu/hint_nop_check.py): Move f30f1efa (endbr64) and f30f1efb (endbr32) to ACCEPTED (verifying lifted-body equality with 0f1f00 NOP) and add f3480f1ec8 (rdsspq rax) to REFUSED (13 accepted, 9 refused).
  • Native vs. Lifted Fixture (tests/cpu/hint_nop_fixture.py): Add hn_endbr64 and hn_endbr32 comparing native execution against the lifted C++ body (preserving RAX and LAHF arithmetic flags) in both dev and release (/O2) builds alongside the existing PAGE_NOACCESS and register-clobber controls.

Before / After

  • Before: F3 0F 1E FA (endbr64) and F3 0F 1E FB (endbr32) raised unsupported query operation.
  • After: Both lower to ; with identical lifted bodies to 0f1f00 and match native register/flag execution in Debug and Release (/O2), while all 9 neighbouring encodings stay refused.

Verification

  • Commit under test: 22d567e8 (based on 4992a46e)
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0

Commands and measured results (0 failures, 0 skips):

  • out\pe-env\Scripts\python.exe -B tests/cpu/hint_nop_check.py: PASS (13 accepted forms lowered to a no-op, 9 neighbours still refused)
  • git diff --check, docs_links_check.py, bidi_controls_check.py: PASS
  • ctest --preset dev --no-tests=error -j 1 -R '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' -V: 3/3 passed (hn_endbr64 and hn_endbr32: native=0x123456789ab1600 lifted=0x123456789ab1600 faulted=0 lifted_faulted=0 ok)
  • ctest --preset release --no-tests=error -j 1 -R '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' -V: 3/3 passed (0.55 sec)
  • Live self-mutations (drop_endbr64, drop_endbr32): 2/2 caught (rc=1) and reverted cleanly.

Evidence Scope

  • Verified locally: pure-Python lifted-body equality and refusal controls, native vs. lifted register/flag execution in dev and release (/O2), and neighbour regression cpu_aot_integer_flags.
  • Not covered: CET/IBT indirect-branch enforcement semantics (not present on x64_zen2; ENDBR64/ENDBR32 are modelled strictly as architectural no-ops).

AI-assisted; source-built fixtures only.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6628823414 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2856). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-26T14:30:27Z. --- Fixes #1476 ## Root Cause / Motivation The first slice of #1476 (`a1455727`, `a72a0929`, `7368c1b6`) lowered the documented `RESERVEDNOP` encodings (`0F 19`, `0F 1D`, `0F 1E`, `0F 1F`) and deliberately left `ENDBR64` (`F3 0F 1E FA`) and `ENDBR32` (`F3 0F 1E FB`) refused for a separate follow-up. CET-instrumented functions (`-fcf-protection`) begin with `endbr64`, so they were still rejected by `tools/ffx_version_query.py`. ## Summary - **Shared lowering (`tools/ffx_version_query.py`):** Add `_ENDBR_CODES = frozenset((C.ENDBR64, C.ENDBR32))` and lower both exact `iced_x86.Code` values to `;`. Per Intel SDM Vol. 2A, `ENDBR64` and `ENDBR32` affect no registers, flags, or memory, and on `x64_zen2` (no CET-IBT) they execute as architectural NOPs. Neighbouring encodings (`RDSSPD`/`RDSSPQ` `F3 0F 1E /1`, `CLDEMOTE`, `0F 0D`, `0F 18`, `0F 1A`-`0F 1C`, MPX) remain refused. - **Unit & Refusal Controls (`tests/cpu/hint_nop_check.py`):** Move `f30f1efa` (`endbr64`) and `f30f1efb` (`endbr32`) to `ACCEPTED` (verifying lifted-body equality with `0f1f00` NOP) and add `f3480f1ec8` (`rdsspq rax`) to `REFUSED` (13 accepted, 9 refused). - **Native vs. Lifted Fixture (`tests/cpu/hint_nop_fixture.py`):** Add `hn_endbr64` and `hn_endbr32` comparing native execution against the lifted C++ body (preserving RAX and `LAHF` arithmetic flags) in both `dev` and `release` (`/O2`) builds alongside the existing `PAGE_NOACCESS` and register-clobber controls. ## Before / After - **Before:** `F3 0F 1E FA` (`endbr64`) and `F3 0F 1E FB` (`endbr32`) raised `unsupported query operation`. - **After:** Both lower to `;` with identical lifted bodies to `0f1f00` and match native register/flag execution in Debug and Release (`/O2`), while all 9 neighbouring encodings stay refused. ## Verification - Commit under test: `22d567e8` (based on `4992a46e`) - Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0` Commands and measured results (0 failures, 0 skips): - `out\pe-env\Scripts\python.exe -B tests/cpu/hint_nop_check.py`: **PASS** (13 accepted forms lowered to a no-op, 9 neighbours still refused) - `git diff --check`, `docs_links_check.py`, `bidi_controls_check.py`: **PASS** - `ctest --preset dev --no-tests=error -j 1 -R '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' -V`: **3/3 passed** (`hn_endbr64` and `hn_endbr32`: `native=0x123456789ab1600 lifted=0x123456789ab1600 faulted=0 lifted_faulted=0 ok`) - `ctest --preset release --no-tests=error -j 1 -R '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' -V`: **3/3 passed** (`0.55 sec`) - Live self-mutations (`drop_endbr64`, `drop_endbr32`): **2/2 caught (`rc=1`)** and reverted cleanly. ## Evidence Scope - Verified locally: pure-Python lifted-body equality and refusal controls, native vs. lifted register/flag execution in `dev` and `release` (`/O2`), and neighbour regression `cpu_aot_integer_flags`. - Not covered: CET/IBT indirect-branch enforcement semantics (not present on `x64_zen2`; `ENDBR64`/`ENDBR32` are modelled strictly as architectural no-ops). AI-assisted; source-built fixtures only.
upstream-sync closed this pull request 2026-11-26 15:00:53 +00:00
tedin7 commented 2026-11-26 15:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:46:58Z.

Review: COMMENTED


Review and Win2025 WARP receipt for head 22d567e8 (10 commits behind main, no conflicts).

Review (code + fixture tests only):

  • tools/ffx_version_query.py: _ENDBR_CODES selects the exact iced codes ENDBR64/ENDBR32, so RDSSPD/RDSSPQ (F3 0F 1E /1), CLDEMOTE, 0F 0D/18/1A-1C and MPX stay refused. Lowering to ; matches the SDM (no register, flag or memory effect).
  • Tests: hint_nop_check.py moves both encodings to ACCEPTED (body equal to 0f1f00) and adds rdsspq rax to REFUSED; hint_nop_fixture.py adds hn_endbr64 / hn_endbr32 (native vs lifted).
  • Siblings: no other open or merged PR covers ENDBR/CET hint NOPs (only merged #1547, the first slice this extends).
  • Mutations (Linux, local): dropping i.code in _ENDBR_CODES from the lowering -> hint_nop_check.py rc=1; shrinking _ENDBR_CODES to ENDBR64 only -> rc=1. Both reverted.
  • Linux: hint_nop_check.py PASS (13 accepted, 9 refused), docs_links_check.py ok, bidi_controls_check.py ok, git diff --check origin/main...HEAD clean.

Win2025 (Build 26100, MSVC 14.44 + D3D12 WARP), command: x2w_pipe.py win2025 2856 --wait 7200 --keep-release --regex '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' --py-checks tests/cpu/hint_nop_check.py

  • Debug (dev): 100% tests passed out of 3 (cpu_hint_nop, cpu_hint_nop_fixture, cpu_aot_integer_flags).
  • Release: 100% tests passed out of 3 (same tests).
  • PYCHECK name=tests/cpu/hint_nop_check.py rc=0.
  • Real-GPU run not available (RunPod stopped); this change is CPU lowering only.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6076119839 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2856#pullrequestreview-6076119839). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:46:58Z. **Review:** COMMENTED --- Review and Win2025 WARP receipt for head 22d567e8 (10 commits behind main, no conflicts). Review (code + fixture tests only): - `tools/ffx_version_query.py`: `_ENDBR_CODES` selects the exact iced codes ENDBR64/ENDBR32, so RDSSPD/RDSSPQ (`F3 0F 1E /1`), CLDEMOTE, `0F 0D/18/1A-1C` and MPX stay refused. Lowering to `;` matches the SDM (no register, flag or memory effect). - Tests: `hint_nop_check.py` moves both encodings to ACCEPTED (body equal to `0f1f00`) and adds `rdsspq rax` to REFUSED; `hint_nop_fixture.py` adds `hn_endbr64` / `hn_endbr32` (native vs lifted). - Siblings: no other open or merged PR covers ENDBR/CET hint NOPs (only merged #1547, the first slice this extends). - Mutations (Linux, local): dropping `i.code in _ENDBR_CODES` from the lowering -> `hint_nop_check.py` rc=1; shrinking `_ENDBR_CODES` to ENDBR64 only -> rc=1. Both reverted. - Linux: `hint_nop_check.py` PASS (13 accepted, 9 refused), `docs_links_check.py` ok, `bidi_controls_check.py` ok, `git diff --check origin/main...HEAD` clean. Win2025 (Build 26100, MSVC 14.44 + D3D12 WARP), command: `x2w_pipe.py win2025 2856 --wait 7200 --keep-release --regex '^(cpu_hint_nop|cpu_hint_nop_fixture|cpu_aot_integer_flags)$' --py-checks tests/cpu/hint_nop_check.py` - Debug (`dev`): 100% tests passed out of 3 (`cpu_hint_nop`, `cpu_hint_nop_fixture`, `cpu_aot_integer_flags`). - Release: 100% tests passed out of 3 (same tests). - `PYCHECK name=tests/cpu/hint_nop_check.py rc=0`. - Real-GPU run not available (RunPod stopped); this change is CPU lowering only. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2848
No description provided.