diff options
| author | robot00f <robot00f@users.noreply.github.com> | 2026-11-26 01:08:55 -0300 |
|---|---|---|
| committer | robot00f <robot00f@users.noreply.github.com> | 2026-11-27 18:49:10 -0300 |
| commit | b6e51b737674beebef48d4945a474aa38c862eed (patch) | |
| tree | 5a4e9656d6fb4f17fcc3c79c23ba16267e5ae9bf /runtime/src/main.cpp | |
| parent | 4ba23637e32f320427a4eef540eef14165aba19e (diff) | |
runtime(cpu): emulate F16C, FMA3 and AVX2 via XSTATE_AVX on AVX1 hosts
Add runtime/src/avx2_emulation.h and wire it into gta6rt so pre-Haswell AVX1 +
SSE4.2 CPUs (Intel Sandy Bridge and Ivy Bridge) can execute the game's vector
Haswell instruction delta using the host's native 256-bit YMM0..YMM15 state:
- Read and write 256-bit YMM registers through CONTEXT::FltSave.XmmRegisters
(bits [127:0]) and LocateXStateFeature(XSTATE_AVX) (bits [255:128]), zeroing
YMM[dst][255:128] on every 128-bit VEX register write and zero-initializing
untouched upper lanes when transitioning XSTATE_MASK_AVX from clean (0).
- Emulate F16C (vcvtph2ps, vcvtps2ph with RN/RD/RU/RZ and MXCSR rounding), all
60 FMA3 forms (132/213/231 packed 128/256, scalar ss/sd preserving [127:32] /
[127:64], and alternating fmaddsub/fmsubadd) via single-rounding std::fmaf /
std::fma, and AVX2 (256-bit integer SIMD promotions, register/memory
vbroadcastss/sd/i128 and vpbroadcastb/w/d/q, vinserti128, vextracti128,
vperm2i128, vpermq, vpermpd, vpermd, vpermps, vpblendd/w/vb, vpsllv*/vpsrlv*/
vpsravd, vpmovsx*/vpmovzx*, vpmovmskb, and per-lane fault-accurate
vpmaskmovd/vpmaskmovq).
- Add runtime/test/avx2_emulation_test.cpp covering IEEE-754 F16C conversions,
VEX decoding, XSTATE_AVX + VPMASKMOVD page-boundary semantics, and live
256-bit YMM execution on hardware.
Depends on: #2190
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7181466437
AI-assisted: yes (Antigravity, Gemini 4 Carbon)
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index a797fc19c..37ce6656c 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -176,6 +176,7 @@ void start_title_peek(std::uint8_t* base) { | |||
| 176 | 176 | ||
| 177 | } // namespace | 177 | } // namespace |
| 178 | 178 | ||
| 179 | #include "avx2_emulation.h" | ||
| 179 | #include "base_reservation.h" | 180 | #include "base_reservation.h" |
| 180 | #include "compile_gate_policy.h" | 181 | #include "compile_gate_policy.h" |
| 181 | #include "bmi_emulation.h" | 182 | #include "bmi_emulation.h" |
| @@ -567,6 +568,12 @@ int wmain(int argc, wchar_t** argv) { | |||
| 567 | if (!rt::bmi_emulation::install()) | 568 | if (!rt::bmi_emulation::install()) |
| 568 | std::fprintf(stderr, "[rt] cpu: AddVectoredExceptionHandler (BMI) failed (error %lu); instructions this CPU " | 569 | std::fprintf(stderr, "[rt] cpu: AddVectoredExceptionHandler (BMI) failed (error %lu); instructions this CPU " |
| 569 | "lacks will stop the game\n", GetLastError()); | 570 | "lacks will stop the game\n", GetLastError()); |
| 571 | if (const auto avx2 = rt::avx2_emulation::detect_host(); !avx2.avx2 || !avx2.fma || !avx2.f16c) | ||
| 572 | std::fprintf(stderr, "[rt] cpu: this CPU lacks%s%s%s; the game's uses are emulated (docs/cpu_features.md)\n", | ||
| 573 | avx2.avx2 ? "" : " AVX2", avx2.fma ? "" : " FMA3", avx2.f16c ? "" : " F16C"); | ||
| 574 | if (!rt::avx2_emulation::install()) | ||
| 575 | std::fprintf(stderr, "[rt] cpu: AddVectoredExceptionHandler (AVX2) failed (error %lu); instructions this CPU " | ||
| 576 | "lacks will stop the game\n", GetLastError()); | ||
| 570 | 577 | ||
| 571 | try { | 578 | try { |
| 572 | rt::Loader loader(game_dir); | 579 | rt::Loader loader(game_dir); |