diff options
| author | Senne Cools <113857183+sennecools@users.noreply.github.com> | 2026-11-23 23:07:51 +0100 |
|---|---|---|
| committer | Senne Cools <113857183+sennecools@users.noreply.github.com> | 2026-11-23 23:07:51 +0100 |
| commit | ad6e5d6bbee5bd8c3c8a7e95216f12038fe3db22 (patch) | |
| tree | 4f0020d3c5053cf5ce189b7a26c5150c4861b5af /runtime/src/host_cpu.h | |
| parent | 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff) | |
gta6rt: --init/--run stop with a clear message on a host without AVX
The game runs AVX code from its TLS callbacks on, so a CPU or OS without
AVX (a QEMU qemu64 guest) died with a bare 0xC000001D. Check CPUID.1
AVX/OSXSAVE and XCR0 YMM state first, print one line and exit 4 (3 is
LEONIDA_UNIMPLEMENTED=stop). --dry-run is unchanged and
LEONIDA_SKIP_CPU_CHECK=1 skips the check.
AI-assisted.
Diffstat (limited to 'runtime/src/host_cpu.h')
| -rw-r--r-- | runtime/src/host_cpu.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/runtime/src/host_cpu.h b/runtime/src/host_cpu.h new file mode 100644 index 000000000..b9dd143db --- /dev/null +++ b/runtime/src/host_cpu.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Host CPU preflight for --init and --run: the game executes AVX instructions from its TLS callbacks on, so a host | ||
| 2 | // whose CPU or OS lacks AVX (a QEMU qemu64 guest, for one) dies there with a bare EXCEPTION_ILLEGAL_INSTRUCTION | ||
| 3 | // (0xC000001D) that reads like a loader bug. This checks AVX only, which is what was measured; it claims nothing | ||
| 4 | // about AVX2, FMA or BMI2. No emulation here: that is RT-500's scope. Rosetta on macOS runs AVX code but leaves | ||
| 5 | // AVX out of CPUID unless ROSETTA_ADVERTISE_AVX=1 is set, so the check fails there until that variable is set. | ||
| 6 | #pragma once | ||
| 7 | |||
| 8 | #include <cstdint> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace rt::host_cpu { | ||
| 13 | |||
| 14 | constexpr uint32_t kCpuid1EcxOsxsave = 1u << 27; // CPUID.1:ECX.OSXSAVE: the OS enabled XSAVE, XGETBV is usable | ||
| 15 | constexpr uint32_t kCpuid1EcxAvx = 1u << 28; // CPUID.1:ECX.AVX | ||
| 16 | constexpr uint64_t kXcr0SseYmm = 0x6; // XCR0 bits 1 (SSE state) and 2 (AVX/YMM state) | ||
| 17 | |||
| 18 | // gta6rt's exit code when the check fails (2 is a usage error, 3 is LEONIDA_UNIMPLEMENTED=stop). | ||
| 19 | constexpr int kExitCode = 4; | ||
| 20 | |||
| 21 | constexpr const char* kMissingAvx = "AVX"; | ||
| 22 | constexpr const char* kMissingOsxsave = "OSXSAVE"; | ||
| 23 | constexpr const char* kMissingYmmState = "OS support for YMM state (XCR0 bits 1-2)"; | ||
| 24 | |||
| 25 | // The features missing for the game's AVX code, from CPUID.1:ECX. read_xcr0 is called only when OSXSAVE is set, | ||
| 26 | // because XGETBV faults without it. An empty list means the host can run AVX code. | ||
| 27 | std::vector<const char*> missing_host_features(uint32_t cpuid1_ecx, uint64_t (*read_xcr0)()); | ||
| 28 | |||
| 29 | // The same for the running host: CPUID leaf 1 and XGETBV(0). Empty on a host that is not x86-64. | ||
| 30 | std::vector<const char*> missing_host_features(); | ||
| 31 | |||
| 32 | // The one stderr line gta6rt prints when the list is not empty. | ||
| 33 | std::string message(const std::vector<const char*>& missing); | ||
| 34 | |||
| 35 | // LEONIDA_SKIP_CPU_CHECK=1 skips the check (for the #UD emulation work). | ||
| 36 | bool check_skipped(); | ||
| 37 | |||
| 38 | } // namespace rt::host_cpu | ||