CLI: check every extension the title uses unchecked, not only AVX2 (depends on #238) #558

Closed
mercuryVM wants to merge 3 commits from upstream-pr/558 into main
mercuryVM commented 2026-11-24 04:53:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T04:53:39Z.


Depends on #238 (this branch is #238's commit plus one on top; once #238 lands, only the second commit remains).

#238 stops victory run --execute on a CPU without AVX2. The title needs more than that, and it does not ask first, so a CPU missing any of the rest still dies on STATUS_ILLEGAL_INSTRUCTION (#102, #103, #106, #108, #210 are crashes of this kind).

What the title uses (Grand Theft Auto VI 1.0.2.1, measured)

dumpbin /disasm over the executable's code: 26.7 M instructions, cpuid from 9 places only. Counts only, nothing of the title quoted:

Extension Uses Checked here
FMA3 204,279 yes
AVX/AVX2 (ymm) 259,868 yes (avx2)
BMI1 (bextr, andn, tzcnt, blsr, ...) 60,850 yes
BMI2 (shlx, mulx, shrx, rorx, bzhi, pext, ...) 14,959 yes
F16C 3,303 yes
AES-NI / VAES 3,107 yes (aes)
PCLMULQDQ 1,128 yes
POPCNT 458 yes
MOVBE 422 yes
LZCNT 321 yes
ADX 2,678 no: all in one 0.26 MB block right after the title's AES code, so it may be picked by cpuid; requiring it would turn away Haswell CPUs that may run fine
SSE4a insertq 19, clzero 10, clwb 8, monitorx/mwaitx 2+2 no: victory_loader::crash emulates them on main
SHA, AVX-512, XOP, FMA4, RDPRU 0 —

Change

  • REQUIRED_FEATURES lists the ten; missing_cpu_features() detects each with is_x86_feature_detected!; the error names every missing one (not just the first), and VICTORY_SKIP_CPU_CHECK=1 still bypasses it.
  • README's requirement line names the extensions.
  • Tests: the pure check_cpu_features_with cases (nothing missing, AVX2 missing, several missing named, skip), the host check, and that the list has no duplicates.

Tested

c27c9df on Windows 11, Rust 1.98.1, AMD Ryzen + RTX 5070: cargo test --workspace 271 passed, 0 failed; rustfmt --check on the changed file; cargo xtask policy ok. Not run against the title (no package on this machine), and I have no CPU without these extensions to see the message on real hardware.

Note: cargo fmt --all -- --check fails on main itself (31 files); this PR does not touch them.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574900771 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/558). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T04:53:39Z. --- Depends on #238 (this branch is #238's commit plus one on top; once #238 lands, only the second commit remains). #238 stops `victory run --execute` on a CPU without AVX2. The title needs more than that, and it does not ask first, so a CPU missing any of the rest still dies on `STATUS_ILLEGAL_INSTRUCTION` (#102, #103, #106, #108, #210 are crashes of this kind). ## What the title uses (Grand Theft Auto VI 1.0.2.1, measured) `dumpbin /disasm` over the executable's code: 26.7 M instructions, `cpuid` from 9 places only. Counts only, nothing of the title quoted: | Extension | Uses | Checked here | |---|---:|---| | FMA3 | 204,279 | yes | | AVX/AVX2 (ymm) | 259,868 | yes (`avx2`) | | BMI1 (`bextr`, `andn`, `tzcnt`, `blsr`, ...) | 60,850 | yes | | BMI2 (`shlx`, `mulx`, `shrx`, `rorx`, `bzhi`, `pext`, ...) | 14,959 | yes | | F16C | 3,303 | yes | | AES-NI / VAES | 3,107 | yes (`aes`) | | PCLMULQDQ | 1,128 | yes | | POPCNT | 458 | yes | | MOVBE | 422 | yes | | LZCNT | 321 | yes | | ADX | 2,678 | **no**: all in one 0.26 MB block right after the title's AES code, so it may be picked by `cpuid`; requiring it would turn away Haswell CPUs that may run fine | | SSE4a `insertq` 19, `clzero` 10, `clwb` 8, `monitorx`/`mwaitx` 2+2 | | no: `victory_loader::crash` emulates them on main | | SHA, AVX-512, XOP, FMA4, RDPRU | 0 | — | ## Change - `REQUIRED_FEATURES` lists the ten; `missing_cpu_features()` detects each with `is_x86_feature_detected!`; the error names every missing one (not just the first), and `VICTORY_SKIP_CPU_CHECK=1` still bypasses it. - README's requirement line names the extensions. - Tests: the pure `check_cpu_features_with` cases (nothing missing, AVX2 missing, several missing named, skip), the host check, and that the list has no duplicates. ## Tested `c27c9df` on Windows 11, Rust 1.98.1, AMD Ryzen + RTX 5070: `cargo test --workspace` 271 passed, 0 failed; `rustfmt --check` on the changed file; `cargo xtask policy` ok. Not run against the title (no package on this machine), and I have no CPU without these extensions to see the message on real hardware. Note: `cargo fmt --all -- --check` fails on main itself (31 files); this PR does not touch them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 13:01:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:48:56Z.

Review: COMMENTED


Static review (app crate doesn't build on macOS; nothing compiled or run here). The design is sound:

  • check_cpu_features runs only if execute — prepare/map operations don't need Zen 2 extensions, correct scoping.
  • missing_cpu_features is #[cfg(windows)] + x86_64-only with a Vec::new() fallback elsewhere; the pure decision logic (check_cpu_features_with) is #[cfg(any(windows, test))] so it could be unit-tested off Windows — but the app crate itself doesn't build on macOS, so even those tests are Windows-only in practice today.
  • Feature list matches the comment's claim (FMA3/BMI1/2/F16C/MOVBE/LZCNT/POPCNT/AES/PCLMULQDQ, ADX deliberately excluded with a reason, SSE4a/monitorx handled by the loader per the comment).
  • VICTORY_SKIP_CPU_CHECK=1 exact-match semantics are documented in the error message itself.

The two test modules are well-designed (host-consistency test, every-missing-feature-named test, skip-env test). Would approve on Windows CI evidence; the README update matches the new behavior.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039466452 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/558#pullrequestreview-6039466452). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:48:56Z. **Review:** COMMENTED --- Static review (app crate doesn't build on macOS; nothing compiled or run here). The design is sound: - `check_cpu_features` runs only `if execute` — prepare/map operations don't need Zen 2 extensions, correct scoping. - `missing_cpu_features` is `#[cfg(windows)]` + x86_64-only with a `Vec::new()` fallback elsewhere; the pure decision logic (`check_cpu_features_with`) is `#[cfg(any(windows, test))]` so it *could* be unit-tested off Windows — but the app crate itself doesn't build on macOS, so even those tests are Windows-only in practice today. - Feature list matches the comment's claim (FMA3/BMI1/2/F16C/MOVBE/LZCNT/POPCNT/AES/PCLMULQDQ, ADX deliberately excluded with a reason, SSE4a/monitorx handled by the loader per the comment). - `VICTORY_SKIP_CPU_CHECK=1` exact-match semantics are documented in the error message itself. The two test modules are well-designed (host-consistency test, every-missing-feature-named test, skip-env test). Would approve on Windows CI evidence; the README update matches the new behavior.
mercuryVM commented 2026-11-24 13:02:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:54:51Z.


@catminou4 thanks for the review. CI hasn't run on this PR yet; I think fork PRs wait for a maintainer to approve workflow runs. Here is the same check locally on Windows 11 x64 (AMD CPU, RTX 5070, rustc 1.98.1 MSVC), head fa83a31 (main 8e79c80 merged in), with the CI's own commands: cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant are clean, and cargo test -p victory --locked has 8 passed, the CPU-check tests among them.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132089840 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/558#issuecomment-7132089840). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:54:51Z. --- @catminou4 thanks for the review. CI hasn't run on this PR yet; I think fork PRs wait for a maintainer to approve workflow runs. Here is the same check locally on Windows 11 x64 (AMD CPU, RTX 5070, rustc 1.98.1 MSVC), head `fa83a31` (`main` `8e79c80` merged in), with the CI's own commands: `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant are clean, and `cargo test -p victory --locked` has 8 passed, the CPU-check tests among them. AI-assisted (Claude Code).
hadrianhola commented 2026-11-24 21:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by hadrianhola on 2026-11-24T20:30:44Z.


On the open question in the table ("may be picked by cpuid"): it is. Static analysis of game_scarlett_master.exe 1.0.2.1 (dumpbin /disasm, the same 26.7 M instructions and the same counts as above), counts only:

  • Of the 9 cpuid sites, 3 are the MSVC CRT's __isa_available setup. 4 belong to a feature-detection routine of the library that holds the ADX code: it tests leaf/register/bit one at a time and records AVX, AVX2, RDRAND, RDSEED, BMI1, BMI2, AES, ADX (leaf 7 EBX bit 19), MOVBE and SHA as bits of one flags word. The other 2 read leaf 7 subleaves 0/1 for AVX2, BMI2, AVX-512 and VNNI, and record nothing for ADX.
  • All 2,678 adcx/adox sit in one 0.26 MB block. Building the control flow of that block gives the addresses from which an ADX instruction can be reached. All 289 direct code references from outside the block into those addresses go through a function that reads the flags word and tests a mask that includes ADX, within at most 8 call levels. ADX is always tested together with BMI2 (0x50), or with AVX2 and BMI2 (0x52), and the other branch takes a generic path. I checked one dispatcher by hand: not flags; test flags, 0x52; jnz generic.
  • No 64-bit pointer in .rdata/.data points into ADX-reachable code. Three 32-bit values do, but they land in the middle of unrolled mulx/adcx runs with no indirect jump around them, so they look coincidental.
  • Not covered: indirect calls through pointers built at run time.

So a CPU without ADX (Haswell, as in #68) should take the generic path. Leaving ADX out of REQUIRED_FEATURES looks right. The CPU here is a Haswell-E i7-5820K (no ADX, CPUID-checked); the title has not been run on it yet.

AI-assisted (Claude Code); analysis on my machine, nothing of the title quoted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143658540 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/558#issuecomment-7143658540). Originally posted by [hadrianhola](https://github.com/hadrianhola) on 2026-11-24T20:30:44Z. --- On the open question in the table ("may be picked by `cpuid`"): it is. Static analysis of `game_scarlett_master.exe` 1.0.2.1 (`dumpbin /disasm`, the same 26.7 M instructions and the same counts as above), counts only: - Of the 9 `cpuid` sites, 3 are the MSVC CRT's `__isa_available` setup. 4 belong to a feature-detection routine of the library that holds the ADX code: it tests leaf/register/bit one at a time and records AVX, AVX2, RDRAND, RDSEED, BMI1, BMI2, AES, **ADX (leaf 7 EBX bit 19)**, MOVBE and SHA as bits of one flags word. The other 2 read leaf 7 subleaves 0/1 for AVX2, BMI2, AVX-512 and VNNI, and record nothing for ADX. - All 2,678 `adcx`/`adox` sit in one 0.26 MB block. Building the control flow of that block gives the addresses from which an ADX instruction can be reached. All **289** direct code references from outside the block into those addresses go through a function that reads the flags word and tests a mask that includes ADX, within at most 8 call levels. ADX is always tested together with BMI2 (`0x50`), or with AVX2 and BMI2 (`0x52`), and the other branch takes a generic path. I checked one dispatcher by hand: `not flags; test flags, 0x52; jnz generic`. - No 64-bit pointer in `.rdata`/`.data` points into ADX-reachable code. Three 32-bit values do, but they land in the middle of unrolled `mulx`/`adcx` runs with no indirect jump around them, so they look coincidental. - Not covered: indirect calls through pointers built at run time. So a CPU without ADX (Haswell, as in #68) should take the generic path. Leaving ADX out of `REQUIRED_FEATURES` looks right. The CPU here is a Haswell-E i7-5820K (no ADX, CPUID-checked); the title has not been run on it yet. AI-assisted (Claude Code); analysis on my machine, nothing of the title quoted.
upstream-sync closed this pull request 2026-11-25 01:04:13 +00:00
Marvisak commented 2026-11-25 01:07:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:24:55Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #238. #238's commit plus checks for FMA, BMI1/2, F16C, LZCNT, POPCNT, MOVBE, AES and PCLMULQDQ, which by its own comment every AVX2 CPU has, so the added checks cannot fire where #238's does not; also edits the README to say victory run checks them. Take #238.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148485087 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/558#issuecomment-7148485087). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:24:55Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #238. #238's commit plus checks for FMA, BMI1/2, F16C, LZCNT, POPCNT, MOVBE, AES and PCLMULQDQ, which by its own comment every AVX2 CPU has, so the added checks cannot fire where #238's does not; also edits the README to say `victory run` checks them. Take #238. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!558
No description provided.