relinker, libkernel: let --to-avx output run on Linux and Windows by recording the CPU features it still needs #22530

Open
opened 2026-11-17 19:10:33 +00:00 by SchmashinPrunes · 0 comments
SchmashinPrunes commented 2026-11-17 19:10:33 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by SchmashinPrunes on 2026-11-17T19:10:33Z.


--to-avx lowers instructions that hosts with AVX but without AVX2 lack, such as Sandy and Ivy Bridge, but it is limited to --macos (CliArgs.cpp: "--to-avx requires --macos"; Conversion.cpp checks the same). On Linux and Windows, CheckHostCpu in libkernel/System/src/HostCpu.cpp stops at start-up when the host lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA or F16C. It does not know which of them the conversion lowered, so --to-avx output could not start there even if the CLI allowed it.

The host side is not in the way. The project builds without -march or ISA flags, and the host code that uses AVX2 or FMA checks first with __builtin_cpu_supports (Bessel.cpp, GuestArena.cpp). The start-up check is what blocks these hosts.

Proposal

  1. Relinker: record what the output still needs. A classifier in codegen maps a decoded instruction to the checked extensions it requires: LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA, F16C. After conversion, the relinker takes the union over the instructions that were not lowered in the executable and in the bundled modules it converts in the same run, and writes it into the main executable:

    • Linux: a PT_NOTE in a loaded segment
    • Windows: a section next to .procpar

    The runtime already reads the main image this way for process parameters (ApplicationProcessParameters.cpp).

  2. libkernel: check only what is recorded. When the record is present, CheckHostCpu requires the baseline (SSE through SSE4.2, POPCNT, CMPXCHG16B, LAHF/SAHF, AVX) plus the recorded extensions. Without a record it behaves as it does now, so existing conversions are unchanged. The error names the missing features and, when --to-avx would remove them, says so.

  3. CLI: drop the --macos requirement of --to-avx once both parts are in.

A title whose code contains only instructions that --to-avx lowers then starts on a Sandy or Ivy Bridge host. A title that still uses, for example, PDEP or a gather is still refused at start-up with a clear message, rather than raising an illegal instruction later.

Questions

  1. Is a PT_NOTE (owner AnyPS5) and a new 8-byte-named PE section the right place, or is another existing channel preferred?
  2. Should the executable carry the union for its bundled modules, as above, or should each module carry its own record and be checked when DynamicLoader loads it?
  3. Should the record be written for every conversion, or only for --to-avx? Writing it for every conversion makes the start-up check exact for all output, but a linear scan can decode data in a code segment as an instruction, so the record can only err toward requiring more.
  4. One pull request, or two: the relinker record first, which the runtime ignores until it reads it, then the runtime check together with the CLI change?

I'd like to implement this and wanted agreement on the design first. Related lowerings that make --to-avx cover more titles, F16C and single-precision FMA, are prepared and will follow as separate pull requests.

This issue was written and posted by Claude Code, an AI assistant, at my request.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6452109882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/22530). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-17T19:10:33Z. --- `--to-avx` lowers instructions that hosts with AVX but without AVX2 lack, such as Sandy and Ivy Bridge, but it is limited to `--macos` (`CliArgs.cpp`: "--to-avx requires --macos"; `Conversion.cpp` checks the same). On Linux and Windows, `CheckHostCpu` in `libkernel/System/src/HostCpu.cpp` stops at start-up when the host lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA or F16C. It does not know which of them the conversion lowered, so `--to-avx` output could not start there even if the CLI allowed it. The host side is not in the way. The project builds without `-march` or ISA flags, and the host code that uses AVX2 or FMA checks first with `__builtin_cpu_supports` (`Bessel.cpp`, `GuestArena.cpp`). The start-up check is what blocks these hosts. ### Proposal 1. **Relinker: record what the output still needs.** A classifier in codegen maps a decoded instruction to the checked extensions it requires: LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA, F16C. After conversion, the relinker takes the union over the instructions that were not lowered in the executable and in the bundled modules it converts in the same run, and writes it into the main executable: - Linux: a `PT_NOTE` in a loaded segment - Windows: a section next to `.procpar` The runtime already reads the main image this way for process parameters (`ApplicationProcessParameters.cpp`). 2. **libkernel: check only what is recorded.** When the record is present, `CheckHostCpu` requires the baseline (SSE through SSE4.2, POPCNT, CMPXCHG16B, LAHF/SAHF, AVX) plus the recorded extensions. Without a record it behaves as it does now, so existing conversions are unchanged. The error names the missing features and, when `--to-avx` would remove them, says so. 3. **CLI:** drop the `--macos` requirement of `--to-avx` once both parts are in. A title whose code contains only instructions that `--to-avx` lowers then starts on a Sandy or Ivy Bridge host. A title that still uses, for example, PDEP or a gather is still refused at start-up with a clear message, rather than raising an illegal instruction later. ### Questions 1. Is a `PT_NOTE` (owner `AnyPS5`) and a new 8-byte-named PE section the right place, or is another existing channel preferred? 2. Should the executable carry the union for its bundled modules, as above, or should each module carry its own record and be checked when `DynamicLoader` loads it? 3. Should the record be written for every conversion, or only for `--to-avx`? Writing it for every conversion makes the start-up check exact for all output, but a linear scan can decode data in a code segment as an instruction, so the record can only err toward requiring more. 4. One pull request, or two: the relinker record first, which the runtime ignores until it reads it, then the runtime check together with the CLI change? I'd like to implement this and wanted agreement on the design first. Related lowerings that make `--to-avx` cover more titles, F16C and single-precision FMA, are prepared and will follow as separate pull requests. This issue was written and posted by Claude Code, an AI assistant, at my request. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
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
boykopovar/AnyPS5#22530
No description provided.