docs(cpu_features): record baseline instruction counts and AVX1/SSE4.2 host delta #2188

Merged
leonida/mandy
robot00f merged 1 commit from docs/cpu-avx1-baseline-counts into main 2026-12-01 11:02:10 +00:00

Pull request successfully merged and closed

robot00f commented 2026-11-26 03:41:32 +00:00

Summary

Record the baseline instruction counts measured by tools/cpu_feature_scan.py (at 0b11d86b) on the 1.0.2.1 executable in docs/cpu_features.md and document the AVX1 + SSE4.2 host delta (Intel Sandy Bridge and Ivy Bridge).

  • Fill in the previously unrecorded baseline feature counts in the Instruction sets used table (AVX, FMA, AVX2, BMI1, BMI2, AES, F16C, ADX, PCLMULQDQ, POPCNT, MOVBE, LZCNT, CX16, PREFETCHW, and 0 for RDRAND, RDSEED, FSGSBASE, CLFLUSHOPT).
  • Note two scan-bucket details relevant to pre-Haswell hosts:
    • AVX (2,871,070 in .pdata) includes 32,101 register-source vbroadcastss (31,970) and vbroadcastsd (131) sites (ModRM.mod == 3), which require AVX2 (#UD on AVX1) unlike the memory-source forms.
    • AVX2 (81,500 in .pdata) contains 0 vgather* or vpgather* sites anywhere in .text.
  • Add an AVX1 + SSE4.2 hosts (pre-Haswell) subsection distinguishing:
    1. Instructions that raise #UD (STATUS_ILLEGAL_INSTRUCTION) cleanly on an AVX1 + SSE4.2 host (AVX2, FMA3, F16C, VEX-encoded BMI1/BMI2, MOVBE).
    2. Legacy LZCNT (F3 0F BD) and TZCNT (F3 0F BC), which execute without faulting as BSR and BSF when CPUID.80000001H:ECX.LZCNT[bit 5] == 0 / CPUID.07H:EBX.BMI1[bit 3] == 0 (988 of 11,827 .pdata tzcnt sites immediately feed a CF-reading conditional move or branch, and 149 of 294 .pdata lzcnt sites use 4-byte non-REX encodings).

Validation

  • python -I -m unittest tests/test_docs_links.py tests/test_docs_table_rows.py tests/test_docs_table_ids.py tests/test_docs_repo_paths.py tests/test_docs_list_items.py tests/test_docs_repeated_lines.py tests/test_text_write_line_endings.py (all 7 suites OK)
  • python -I scripts/check_no_game_data.py docs/cpu_features.md (clean)

Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7181466437
AI-assisted: yes (Antigravity, Gemini 4 Carbon)

## Summary Record the baseline instruction counts measured by `tools/cpu_feature_scan.py` (at `0b11d86b`) on the `1.0.2.1` executable in `docs/cpu_features.md` and document the `AVX1 + SSE4.2` host delta (Intel Sandy Bridge and Ivy Bridge). - Fill in the previously unrecorded `baseline` feature counts in the `Instruction sets used` table (`AVX`, `FMA`, `AVX2`, `BMI1`, `BMI2`, `AES`, `F16C`, `ADX`, `PCLMULQDQ`, `POPCNT`, `MOVBE`, `LZCNT`, `CX16`, `PREFETCHW`, and `0` for `RDRAND`, `RDSEED`, `FSGSBASE`, `CLFLUSHOPT`). - Note two scan-bucket details relevant to pre-Haswell hosts: - `AVX` (`2,871,070` in `.pdata`) includes `32,101` register-source `vbroadcastss` (`31,970`) and `vbroadcastsd` (`131`) sites (`ModRM.mod == 3`), which require `AVX2` (`#UD` on `AVX1`) unlike the memory-source forms. - `AVX2` (`81,500` in `.pdata`) contains **`0`** `vgather*` or `vpgather*` sites anywhere in `.text`. - Add an `AVX1 + SSE4.2 hosts (pre-Haswell)` subsection distinguishing: 1. Instructions that raise `#UD` (`STATUS_ILLEGAL_INSTRUCTION`) cleanly on an `AVX1 + SSE4.2` host (`AVX2`, `FMA3`, `F16C`, VEX-encoded `BMI1`/`BMI2`, `MOVBE`). 2. Legacy `LZCNT` (`F3 0F BD`) and `TZCNT` (`F3 0F BC`), which execute **without faulting** as `BSR` and `BSF` when `CPUID.80000001H:ECX.LZCNT[bit 5] == 0` / `CPUID.07H:EBX.BMI1[bit 3] == 0` (`988` of `11,827` `.pdata` `tzcnt` sites immediately feed a `CF`-reading conditional move or branch, and `149` of `294` `.pdata` `lzcnt` sites use 4-byte non-REX encodings). ## Validation - `python -I -m unittest tests/test_docs_links.py tests/test_docs_table_rows.py tests/test_docs_table_ids.py tests/test_docs_repo_paths.py tests/test_docs_list_items.py tests/test_docs_repeated_lines.py tests/test_text_write_line_endings.py` (all 7 suites OK) - `python -I scripts/check_no_game_data.py docs/cpu_features.md` (clean) Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7181466437 AI-assisted: yes (Antigravity, Gemini 4 Carbon)
zmasi commented 2026-11-28 23:33:02 +00:00

Native Windows 11 Verification (c59ae5ed63) — PASS

Diff-audited docs/cpu_features.md (+46/-4) and verified merged onto origin/main (ba8b77b390) on Windows 11 (10.0.26200, Python 3.12.10 with -I).

Results

  • Arithmetic & Scanner Cross-Check:
    • Programmatically verified all 14 rows of the baseline feature table (Sites == Inside .pdata + Outside .pdata across every row, 0 mismatches) as well as all inline subtotals (BMI1: 21,546 + 17,585 + 11,827 + 7,301 + 139 = 58,398; BMI2: 7,581 + 1,612 + 1,309 + 1,064 + 808 + 29 = 12,403; F16C: 1,526 + 1,440 = 2,966; LZCNT: 149 + 145 = 294; genuine AVX1 .pdata sites 2,871,070 - 32,101 + 284 = 2,839,253; tzcnt CF-consumer sites 793 + 174 + 20 + 1 = 988).
    • python -I tests/test_cpu_feature_scan.py: Ran 26 tests in 0.046s — OK
    • python -I tests/test_cpu_ref.py: Ran 39 tests in 2.396s — OK
  • Documentation & Policy Suites (PR #2188 merged onto origin/main):
    • tests/test_docs_links.py (17/17), tests/test_docs_repo_paths.py (5/5), tests/test_docs_table_rows.py (2/2), tests/test_docs_list_items.py (3/3), tests/test_docs_encoding.py (1/1), tests/test_docs_cli_flags.py (4/4), tests/test_text_write_line_endings.py (3/3), and scripts/check_no_game_data.py: OK.

AI-assisted.

### Native Windows 11 Verification (`c59ae5ed63`) — PASS Diff-audited `docs/cpu_features.md` (`+46/-4`) and verified merged onto `origin/main` (`ba8b77b390`) on Windows 11 (`10.0.26200`, Python `3.12.10` with `-I`). #### Results - **Arithmetic & Scanner Cross-Check**: - Programmatically verified all 14 rows of the `baseline` feature table (`Sites == Inside .pdata + Outside .pdata` across every row, `0` mismatches) as well as all inline subtotals (`BMI1`: `21,546 + 17,585 + 11,827 + 7,301 + 139 = 58,398`; `BMI2`: `7,581 + 1,612 + 1,309 + 1,064 + 808 + 29 = 12,403`; `F16C`: `1,526 + 1,440 = 2,966`; `LZCNT`: `149 + 145 = 294`; genuine AVX1 `.pdata` sites `2,871,070 - 32,101 + 284 = 2,839,253`; `tzcnt` `CF`-consumer sites `793 + 174 + 20 + 1 = 988`). - `python -I tests/test_cpu_feature_scan.py`: **`Ran 26 tests in 0.046s — OK`** - `python -I tests/test_cpu_ref.py`: **`Ran 39 tests in 2.396s — OK`** - **Documentation & Policy Suites (`PR #2188` merged onto `origin/main`)**: - `tests/test_docs_links.py` (`17/17`), `tests/test_docs_repo_paths.py` (`5/5`), `tests/test_docs_table_rows.py` (`2/2`), `tests/test_docs_list_items.py` (`3/3`), `tests/test_docs_encoding.py` (`1/1`), `tests/test_docs_cli_flags.py` (`4/4`), `tests/test_text_write_line_endings.py` (`3/3`), and `scripts/check_no_game_data.py`: **`OK`**. AI-assisted.
timbot103 reviewed 2026-11-29 04:28:48 +00:00
timbot103 left a comment
No description provided.
Static review of `c59ae5ed6` against `b6bf3aa0b`. No tests, builds, or GPU runs were performed. All 14 baseline rows reconcile with their inside and outside `.pdata` counts, and the AVX bucket corrections and instruction subtotals add up. The scanner revision resolves, the change introduces no PR references, and the table structure, tracked paths, encoding, and file contents match the repository’s documentation and file checks. The underlying instruction census was outside the scope of this static review. - `docs/cpu_features.md:102` — Please label the fault list as the behavior of unpatched instructions and make F16C conditional on its CPUID bit. `runtime/src/pe_loader.cpp` already rewrites eligible sites, and `runtime/src/bmi_emulation.h` routes discovered short `TZCNT` and `LZCNT` sites through `UD2`. A short description of those paths and the exception fallback would bring the runtime section in line with main. - `docs/cpu_features.md:48` — Please add the method used for the register-source, encoding-length, and carry-consumer counts. `tools/cpu_feature_scan.py` reports baseline totals, and `tools/inline_scan.py` requests disassembly without instruction bytes. The listed commands cannot reproduce those site-level details on their own. AI-assisted.
TheGeogeo commented 2026-11-29 17:12:49 +00:00

Tested c59ae5ed6 merged (no commit) with main 0bc6e21a1: Python 3.12.4, Windows 11 10.0.26300, CPU only.

  • The change is docs only (docs/cpu_features.md), so no test can show a red.
  • No regression: the 13 tests/test_docs_*.py files (links, CLI flags, env vars, repo paths, tables, encoding and the rest) all pass on main and on the merge.
  • No game data check passes.

AI-assisted (Claude Code).

Tested c59ae5ed6 merged (no commit) with main 0bc6e21a1: Python 3.12.4, Windows 11 10.0.26300, CPU only. - The change is docs only (`docs/cpu_features.md`), so no test can show a red. - No regression: the 13 `tests/test_docs_*.py` files (links, CLI flags, env vars, repo paths, tables, encoding and the rest) all pass on main and on the merge. - No game data check passes. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 19:52:57 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, Python 3.12.16, main 0e8737f2a (merges cleanly; does not force a rebase of #2566 at cfd12b24f), PR head c59ae5ed6 : docs only, doc tests green

  • Doc tests on main and on the merge: the 13 tests/test_docs_*.py + test_design_contract_rows, test_progress_dashboard, test_make_game_preflight (16 files): all OK on main, identical on the merge. Docs-only change, so no red is possible.
  • Diff: docs/cpu_features.md adds a table of baseline CPU-feature instruction counts (AVX, FMA3, …, inside/outside .pdata) and the absent features list, from tools/cpu_feature_scan.py.
  • For a maintainer: these counts are measured on the retail executable. They are aggregate statistics (no addresses, names or bytes), but please confirm they are acceptable under the "no game data" rule.

Verdict: READY on tests (docs only); maintainer check on the game-derived counts.

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, Python 3.12.16, main 0e8737f2a (merges cleanly; does not force a rebase of #2566 at cfd12b24f), PR head c59ae5ed6 : docs only, doc tests green - Doc tests on main and on the merge: the 13 `tests/test_docs_*.py` + `test_design_contract_rows`, `test_progress_dashboard`, `test_make_game_preflight` (16 files): all OK on main, identical on the merge. Docs-only change, so no red is possible. - Diff: `docs/cpu_features.md` adds a table of baseline CPU-feature instruction counts (AVX, FMA3, …, inside/outside `.pdata`) and the absent features list, from `tools/cpu_feature_scan.py`. - For a maintainer: these counts are measured on the retail executable. They are aggregate statistics (no addresses, names or bytes), but please confirm they are acceptable under the "no game data" rule. **Verdict: READY on tests** (docs only); maintainer check on the game-derived counts. AI-assisted: Claude Code
OreoFR commented 2026-11-29 20:06:44 +00:00

"No game data" review by OreoFR (requested for maintainers), PR head c59ae5ed6, merged locally on main 720bd3b4e:

  • scripts/check_no_game_data.py on the merge: rc 0; the no-game-data.yml extension filter: 0 files.
  • The diff only touches docs/cpu_features.md: aggregate counts per CPU feature and mnemonic, split inside/outside .pdata. No address, bytes, hash or function name. The CPUID / XCR0 values quoted belong to an example host CPU, not to the game.

Review: OK from a no-game-data point of view.

AI-assisted: Claude Code

"No game data" review by OreoFR (requested for maintainers), PR head c59ae5ed6, merged locally on main 720bd3b4e: - `scripts/check_no_game_data.py` on the merge: rc 0; the `no-game-data.yml` extension filter: 0 files. - The diff only touches `docs/cpu_features.md`: aggregate counts per CPU feature and mnemonic, split inside/outside `.pdata`. No address, bytes, hash or function name. The CPUID / XCR0 values quoted belong to an example host CPU, not to the game. **Review: OK** from a no-game-data point of view. AI-assisted: Claude Code
aslan2142 approved these changes 2026-12-01 11:01:22 +00:00
aslan2142 left a comment

Reviewed docs/cpu_features.md line-by-line: all 14 baseline feature rows and inline subtotals reconcile cleanly (independently verified by @zmasi and @timbot103), aggregate counts only with zero game data (independently audited by @OreoFR and no-game-data: SUCCESS), merges cleanly, and docs CI is green. Merging.

(AI-assisted review.)

Reviewed `docs/cpu_features.md` line-by-line: all 14 baseline feature rows and inline subtotals reconcile cleanly (independently verified by @zmasi and @timbot103), aggregate counts only with zero game data (independently audited by @OreoFR and `no-game-data: SUCCESS`), merges cleanly, and docs CI is green. Merging. *(AI-assisted review.)*
Sign in to join this conversation.
No description provided.