Select the Windows game library automatically for v2 and v3 CPUs #11

Open
MilqueAndToast wants to merge 5 commits from MilqueAndToast/fe3h-recomp:codex/windows-without-avx2 into fe3h
Contributor

Codex here. Refs #2.

What this changes and why

The standard Windows ZIP now works with both CPU targets. The launcher selects v3 on supported CPUs and x86-64-v2 on older CPUs that meet the v2 requirements. Existing v3 installations keep their game DLL and cache ID. The v2 library has its own filename and cache ID. Set LARECOMP_FORCE_X86_64_V2=1 to exercise that path on a modern CPU.

The v2 build uses software fused multiply-add from musl, including its FreeBSD-derived single-precision routine, to preserve the game’s rounding behavior. The package includes the notices.

Tested on

  • Windows, RTX 3070, Prologue at 1280×720. The v2 build matched the reference on all 72,000 instruction cases. Across three paired Prologue runs on a modern CPU, v2 used 6.4–7.6% more process CPU time per frame. Both builds averaged 59.8 FPS at the 60 FPS cap.
  • Upgraded a stock 0.2.7 install, forced v2 once, then switched back to v3. Both v3 launches reused the original DLL with its hash and timestamp intact.
  • Intel SDE’s Sandy Bridge profile reached the title and Prologue after a build from an empty cache. In a separate Windows 10 Nehalem VM with AVX unavailable, the packaged generator processed a complete module and all 248 output files matched the native run byte for byte. In the same no-AVX Windows VM, the 0.2.7-based package automatically selected v2, built the complete game DLL from an empty cache, and loaded it. A fresh launch reused the DLL without rebuilding. The rebased 0.2.8 package at 5653d8b also loaded that same DLL unchanged. We verified startup through the game DLL load. Title-screen rendering in the VM and gameplay on a physical i5-2400 remain unverified.
  • The Windows release build, make test-mods, and make dist passed.

To reproduce the 72,000-case v3 check from the repository root with Clang on PATH and the project’s Python dependencies installed:

python tools/test_simd.py --encodings 6000 --cases 12 --seed 2049 --no-validity --jobs 6

All 72,000 cases matched Unicorn. Commit 05b6e67 updates the test harness’s fnprof_hit stub to match runtime/cpu.h, so the command works from a clean checkout. We kept that fix in its own commit and are happy to split it out if you prefer.

  • No game code, generated code (generated/), extracted files, assets or logs containing game code are included.
Codex here. Refs #2. **What this changes and why** The standard Windows ZIP now works with both CPU targets. The launcher selects v3 on supported CPUs and x86-64-v2 on older CPUs that meet the v2 requirements. Existing v3 installations keep their game DLL and cache ID. The v2 library has its own filename and cache ID. Set `LARECOMP_FORCE_X86_64_V2=1` to exercise that path on a modern CPU. The v2 build uses software fused multiply-add from musl, including its FreeBSD-derived single-precision routine, to preserve the game’s rounding behavior. The package includes the notices. **Tested on** - Windows, RTX 3070, Prologue at 1280×720. The v2 build matched the reference on all 72,000 instruction cases. Across three paired Prologue runs on a modern CPU, v2 used 6.4–7.6% more process CPU time per frame. Both builds averaged 59.8 FPS at the 60 FPS cap. - Upgraded a stock 0.2.7 install, forced v2 once, then switched back to v3. Both v3 launches reused the original DLL with its hash and timestamp intact. - Intel SDE’s Sandy Bridge profile reached the title and Prologue after a build from an empty cache. In a separate Windows 10 Nehalem VM with AVX unavailable, the packaged generator processed a complete module and all 248 output files matched the native run byte for byte. In the same no-AVX Windows VM, the 0.2.7-based package automatically selected v2, built the complete game DLL from an empty cache, and loaded it. A fresh launch reused the DLL without rebuilding. The rebased 0.2.8 package at `5653d8b` also loaded that same DLL unchanged. We verified startup through the game DLL load. Title-screen rendering in the VM and gameplay on a physical i5-2400 remain unverified. - The Windows release build, `make test-mods`, and `make dist` passed. To reproduce the 72,000-case v3 check from the repository root with Clang on `PATH` and the project’s Python dependencies installed: ```sh python tools/test_simd.py --encodings 6000 --cases 12 --seed 2049 --no-validity --jobs 6 ``` All 72,000 cases matched Unicorn. Commit `05b6e67` updates the test harness’s `fnprof_hit` stub to match `runtime/cpu.h`, so the command works from a clean checkout. We kept that fix in its own commit and are happy to split it out if you prefer. - [x] No game code, generated code (`generated/`), extracted files, assets or logs containing game code are included.
Build the Windows game library with a correctly rounded software FMA when targeting x86-64-v2. Carry the helper through first-launch compilation and preserve its source for rebuilds. Check the configured CPU target at startup and keep cached library identities distinct.
Owner

@MilqueAndToast Thanks, this is great work. The software FMA matching all 72,000 cases is exactly the hard part, and the licence notice is handled right.

On your question: I'd rather not ship a separate download. The updater always fetches the standard zip, so anyone on a v2 package would be "updated" onto the AVX2 build and it would stop starting. Players could also pick the wrong zip.

Since the game code is built on the player's PC anyway, could the target be chosen there instead?

  • At game-code build time, check the CPU: AVX2 → today's v3 build, unchanged (same GAMELIB_ID as now, so nobody rebuilds); no AVX2 → x86-64-v2 + gamelib_fma.c, with its own id.
  • Ship both zig runtimes (e.g. zig/rt and zig/rt-v2), each built by zig_slim.sh for its own CPU.
  • The exe and its DLLs need to run on a v2 CPU then; please check nothing in the runtime itself needs AVX2.
  • An env var to force the v2 target on a modern CPU (logged like our other switches), so we can test it without an old PC.
  • Small one: the runtime objects depending on .gamelib-id means every generator edit rebuilds the whole runtime; only the target should trigger that.

Once that works under SDE, we'd put out a pre-release for Barthomero (#2) to try on his i5-2400. No promises on performance there, but at least it would start.

@MilqueAndToast Thanks, this is great work. The software FMA matching all 72,000 cases is exactly the hard part, and the licence notice is handled right. On your question: I'd rather not ship a separate download. The updater always fetches the standard zip, so anyone on a v2 package would be "updated" onto the AVX2 build and it would stop starting. Players could also pick the wrong zip. Since the game code is built on the player's PC anyway, could the target be chosen there instead? - At game-code build time, check the CPU: AVX2 → today's v3 build, unchanged (same GAMELIB_ID as now, so nobody rebuilds); no AVX2 → x86-64-v2 + gamelib_fma.c, with its own id. - Ship both zig runtimes (e.g. `zig/rt` and `zig/rt-v2`), each built by zig_slim.sh for its own CPU. - The exe and its DLLs need to run on a v2 CPU then; please check nothing in the runtime itself needs AVX2. - An env var to force the v2 target on a modern CPU (logged like our other switches), so we can test it without an old PC. - Small one: the runtime objects depending on `.gamelib-id` means every generator edit rebuilds the whole runtime; only the target should trigger that. Once that works under SDE, we'd put out a pre-release for Barthomero (#2) to try on his i5-2400. No promises on performance there, but at least it would start.
Author
Contributor

Codex here. Thanks for explaining the updater behavior. We’re working on a single Windows package that selects the CPU target automatically. We traced the v3 cache ID difference to two trailing spaces in the 0.2.7 Makefile. Setting the same v3 target explicitly dropped those spaces from the hash input. Our local build now produces the same v3 cache ID as the released version. We’re checking that upgrading a stock 0.2.7 install reuses its existing game DLL without recompiling.

Codex here. Thanks for explaining the updater behavior. We’re working on a single Windows package that selects the CPU target automatically. We traced the v3 cache ID difference to two trailing spaces in the 0.2.7 Makefile. Setting the same v3 target explicitly dropped those spaces from the hash input. Our local build now produces the same v3 cache ID as the released version. We’re checking that upgrading a stock 0.2.7 install reuses its existing game DLL without recompiling.
Author
Contributor

Codex here. The single Windows package is ready for review at 874a66a. Under Intel SDE’s Sandy Bridge profile, the launcher automatically selected v2 from an empty cache, built the game DLL, and reached the title screen and Prologue. SDE reported no unsupported instructions during setup or either launch.

We also upgraded a stock 0.2.7 v3 install, forced v2 once, then switched back to v3 in the same folder. Both v3 launches reused the original DLL. Its hash and timestamp stayed the same, and neither launch started the generator or compiler. Gameplay and performance on a physical i5-2400 are still unverified.

Codex here. The single Windows package is ready for review at `874a66a`. Under Intel SDE’s Sandy Bridge profile, the launcher automatically selected v2 from an empty cache, built the game DLL, and reached the title screen and Prologue. SDE reported no unsupported instructions during setup or either launch. We also upgraded a stock 0.2.7 v3 install, forced v2 once, then switched back to v3 in the same folder. Both v3 launches reused the original DLL. Its hash and timestamp stayed the same, and neither launch started the generator or compiler. Gameplay and performance on a physical i5-2400 are still unverified.
Owner

@MilqueAndToast Thanks, this is exactly the shape I hoped for, and the v3 id check is a great catch. We reviewed the whole diff (plus an independent review); nothing wrong on the normal path. A few things before we test it here:

  1. The CPU check runs after code that's now built for v2: reserve_guest_space (constructor 101, main.c) and the C++ static initializers (ImGui / UI, built with -march=x86-64-v2). On a pre-v2 CPU that could crash before the message. Could the check move into a constructor(100) in windows.c?
  2. The "needs an x86-64-v2 CPU" box only shows when the log goes to fe3hrecomp.log; with a console or pipe on stderr, or if the log couldn't be opened, the player gets a silent exit. Please show it always, as before.
  3. Could the commit message say why the custom FMA is needed rather than the fma in zig's compiler_rt? (We guess MinGW's non-correctly-rounded fma wins the link, but it'd be good to have it written down.)
  4. One more SDE run with a CPU without AVX (-nhm or -wsm), since Sandy Bridge has AVX and the README now promises any v2 CPU.
  5. Nit: runtime/gamebuild.h line 3 still only mentions fe3hgame.*.

Once those are in, we'll test it on our AMD and NVIDIA PCs and put out a pre-release for users.

@MilqueAndToast Thanks, this is exactly the shape I hoped for, and the v3 id check is a great catch. We reviewed the whole diff (plus an independent review); nothing wrong on the normal path. A few things before we test it here: 1. The CPU check runs after code that's now built for v2: `reserve_guest_space` (constructor 101, main.c) and the C++ static initializers (ImGui / UI, built with -march=x86-64-v2). On a pre-v2 CPU that could crash before the message. Could the check move into a `constructor(100)` in windows.c? 2. The "needs an x86-64-v2 CPU" box only shows when the log goes to fe3hrecomp.log; with a console or pipe on stderr, or if the log couldn't be opened, the player gets a silent exit. Please show it always, as before. 3. Could the commit message say why the custom FMA is needed rather than the fma in zig's compiler_rt? (We guess MinGW's non-correctly-rounded fma wins the link, but it'd be good to have it written down.) 4. One more SDE run with a CPU without AVX (`-nhm` or `-wsm`), since Sandy Bridge has AVX and the README now promises any v2 CPU. 5. Nit: runtime/gamebuild.h line 3 still only mentions fe3hgame.*. Once those are in, we'll test it on our AMD and NVIDIA PCs and put out a pre-release for users.
Check the host CPU floor before reserving guest space or running the
application's C++ initializers. Present the error independently of
normal logging and document the v2 and v3 game-library names.

The v2 game library keeps its strong software fma and fmaf definitions
because Zig 0.17.0 compiler_rt supplies both symbols ahead of the UCRT
math imports in the packaged rt-v2 link order. The MinGW archive defines
fmal and supplies neither of the resolved definitions.

With the local helpers omitted, the same packaged link returns
fff8000000000001 for finite f64 operands 1cb6956cffa1689b and
8a4134fc6db4f664 with finite nonzero addend 7bbcb35d00322ef4. The
correct round-to-nearest result is 7bbcb35d00322ef4. The packaged
compiler_rt fmaf also misrounds midpoint cases. The existing v2-only
definitions give correctly rounded results in all four rounding modes.
MilqueAndToast changed title from WIP: Add an optional Windows build target for CPUs without AVX2 to WIP: Select the Windows game library automatically for v2 and v3 CPUs 2026-11-22 22:45:10 +00:00
Author
Contributor

Codex here. Thanks for the review and for offering to test on AMD and NVIDIA. 333d7ad is ready for that testing.

  1. CPU check order. Moved the check into constructor(100) in windows.c, which is compiled for baseline x86-64. We checked the linked Windows executable and confirmed the guard runs before reserve_guest_space and all six C++ UI initializers.
  2. Unsupported-CPU message. The dialog now opens before log setup. Under SDE’s Penryn profile we saw it with a console, with stderr piped, and with the log locked and no usable stderr. Each run exited with status 1 after the dialog closed.
  3. Why we keep the software FMA. The commit message records which implementation wins the packaged link. Zig’s compiler_rt supplies fma and fmaf; MinGW supplies fmal. Without the v2 helpers we reproduced a NaN for finite double inputs and incorrect rounding for single-precision midpoint cases. The helpers matched the reference in all four rounding modes.
  4. CPU without AVX. We ran SDE with -nhm. The launcher selected v2, but Windows still advertised host AVX to the generator’s C runtime, and lasgen --help trapped in its AVX memcpy. The launcher also stopped under SDE with an OSXSAVE error. We then booted Windows 10 in a Nehalem VM where both CPUID and Windows reported AVX unavailable. The same generator selected its non-AVX memcpy, passed --help, and processed the complete subsdk0 module. All 248 outputs matched the native run byte for byte. A full first-launch build and gameplay on a no-AVX CPU remain unverified.
  5. Library names in runtime/gamebuild.h. The header now names both Windows outputs: fe3hgame-v2.dll for v2 and fe3hgame.dll for v3.
Codex here. Thanks for the review and for offering to test on AMD and NVIDIA. `333d7ad` is ready for that testing. 1. **CPU check order.** Moved the check into `constructor(100)` in `windows.c`, which is compiled for baseline x86-64. We checked the linked Windows executable and confirmed the guard runs before `reserve_guest_space` and all six C++ UI initializers. 2. **Unsupported-CPU message.** The dialog now opens before log setup. Under SDE’s Penryn profile we saw it with a console, with stderr piped, and with the log locked and no usable stderr. Each run exited with status 1 after the dialog closed. 3. **Why we keep the software FMA.** The commit message records which implementation wins the packaged link. Zig’s `compiler_rt` supplies `fma` and `fmaf`; MinGW supplies `fmal`. Without the v2 helpers we reproduced a NaN for finite double inputs and incorrect rounding for single-precision midpoint cases. The helpers matched the reference in all four rounding modes. 4. **CPU without AVX.** We ran SDE with `-nhm`. The launcher selected v2, but Windows still advertised host AVX to the generator’s C runtime, and `lasgen --help` trapped in its AVX `memcpy`. The launcher also stopped under SDE with an OSXSAVE error. We then booted Windows 10 in a Nehalem VM where both CPUID and Windows reported AVX unavailable. The same generator selected its non-AVX `memcpy`, passed `--help`, and processed the complete `subsdk0` module. All 248 outputs matched the native run byte for byte. A full first-launch build and gameplay on a no-AVX CPU remain unverified. 5. **Library names in `runtime/gamebuild.h`.** The header now names both Windows outputs: `fe3hgame-v2.dll` for v2 and `fe3hgame.dll` for v3.
Match the fnprof_hit declaration in cpu.h so the stock differential test compiles with profiling disabled.
Owner

@MilqueAndToast Thanks, that covers everything, and the Nehalem VM run is a better test than SDE could give. #19 is merged now, so #11 conflicts in tools/zig_slim.sh: could you rebase onto the current fe3h branch and drop the duplicate part?

@MilqueAndToast Thanks, that covers everything, and the Nehalem VM run is a better test than SDE could give. #19 is merged now, so #11 conflicts in `tools/zig_slim.sh`: could you rebase onto the current `fe3h` branch and drop the duplicate part?
MilqueAndToast force-pushed codex/windows-without-avx2 from 05b6e676d4 to 5653d8bd81 2026-11-23 07:51:44 +00:00 Compare
Author
Contributor

Codex here. Rebased #11 onto 8e78dbd (0.2.8) and dropped our duplicate Zig packaging commit. The script now uses the path fix merged in #19 for both CPU targets. At 5653d8b, the Windows ZIP built successfully, the mod tests passed, and both the v2 and v3 slim compilers linked a DLL from an empty cache after relocation.

Codex here. Rebased #11 onto `8e78dbd` (0.2.8) and dropped our duplicate Zig packaging commit. The script now uses the path fix merged in #19 for both CPU targets. At `5653d8b`, the Windows ZIP built successfully, the mod tests passed, and both the v2 and v3 slim compilers linked a DLL from an empty cache after relocation.
MilqueAndToast changed title from WIP: Select the Windows game library automatically for v2 and v3 CPUs to Select the Windows game library automatically for v2 and v3 CPUs 2026-11-23 07:52:49 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u codex/windows-without-avx2:MilqueAndToast-codex/windows-without-avx2
git switch MilqueAndToast-codex/windows-without-avx2

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch fe3h
git merge --no-ff MilqueAndToast-codex/windows-without-avx2
git switch MilqueAndToast-codex/windows-without-avx2
git rebase fe3h
git switch fe3h
git merge --ff-only MilqueAndToast-codex/windows-without-avx2
git switch MilqueAndToast-codex/windows-without-avx2
git rebase fe3h
git switch fe3h
git merge --no-ff MilqueAndToast-codex/windows-without-avx2
git switch fe3h
git merge --squash MilqueAndToast-codex/windows-without-avx2
git switch fe3h
git merge --ff-only MilqueAndToast-codex/windows-without-avx2
git switch fe3h
git merge MilqueAndToast-codex/windows-without-avx2
git push origin fe3h
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
recomps/fe3h-recomp!11
No description provided.