[PR #7381] [MERGED] Windows: start on CPUs without POPCNT again (Core 2), and check builds for it #7566

Closed
opened 2026-11-03 07:19:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7381
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/old-cpu-mimalloc-popcnt


📝 Commits (3)

  • e478b7e third_party: libmimalloc-sys 0.1.49 as published, mimalloc v3 sources only
  • 3380705 Game: start on CPUs without POPCNT again (Core 2), and check every build for it
  • 0ca03e3 Merge remote-tracking branch 'origin/main' into fix/old-cpu-mimalloc-popcnt

📊 Changes

56 files changed (+25680 additions, -3 deletions)

View changed files

📝 .github/workflows/game-build.yml (+9 -0)
📝 Cargo.lock (+0 -2)
📝 Cargo.toml (+5 -1)
📝 THIRD_PARTY_NOTICES.md (+9 -0)
➕ tests/test_check_cpu_baseline.py (+33 -0)
➕ third_party/libmimalloc-sys/Cargo.toml (+79 -0)
➕ third_party/libmimalloc-sys/LICENSE.txt (+25 -0)
➕ third_party/libmimalloc-sys/build.rs (+138 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/LICENSE (+21 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-new-delete.h (+66 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-override.h (+68 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-stats.h (+168 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc.h (+706 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/atomic.h (+562 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/bits.h (+345 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/internal.h (+1282 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/prim.h (+542 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/track.h (+150 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/types.h (+732 -0)
➕ third_party/libmimalloc-sys/c_src/mimalloc/v3/src/alloc-aligned.c (+441 -0)

...and 36 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #7264: since the 10-29 nightlies the Windows game exits with 0xc000001d (illegal instruction) at once, with no log, on CPUs without POPCNT (Core 2 Penryn/Merom, AMD K8).

Cause

  • #4160 (10-29) made mimalloc v3 the game's allocator (libmimalloc-sys 0.1.49). On MSVC, its mi_popcount (include/mimalloc/bits.h) is __popcnt64. cl.exe always emits that as the POPCNT instruction, whatever /arch says, and mimalloc runs before main. This is upstream microsoft/mimalloc#1291, fixed upstream in July, but no libmimalloc-sys release has it yet.
  • Measured on the released binaries, disassembled with llvm-objdump: horizon-client.exe of v0.2.97 has 0 popcnt; nightly-2026-10-31 (d91cab6) and nightly-2026-11-01 (4aa6854) have 9, all in one cluster. No lzcnt anywhere. AVX, BMI2 and SSE4.x counts are the same in v0.2.97, which ran on the reporter's PC. In the Linux build, which has symbols, they all sit in runtime-dispatched code (ring, memchr, half's F16C, compiler_builtins' FMA).
  • Linux was never affected: GCC's __builtin_popcountll without -mpopcnt calls libgcc (0 popcnt in the Linux client).

Change

  • third_party/libmimalloc-sys: the published crate, copied verbatim in the first commit (only the v3 sources, which are all the build reads; v2 now panics with a clear message). The second commit holds the one-line fix: on MSVC x86/x64, mi_popcount takes mimalloc's own portable _mi_popcount_generic, as the GCC builds already do. The root Cargo.toml has a [patch.crates-io] entry, and THIRD_PARTY_NOTICES.md credits both projects (MIT).
  • Why not upstream's per-call CPUID check: it leaves guarded POPCNTs in the exe, so the build guard below couldn't be strict. Bit counts only run in mimalloc's arena bitmaps (page and slice operations, beside atomic RMWs), never on malloc's fast path, so the portable count costs nothing measurable. Windows now does what Linux already does.
  • tools/check_cpu_baseline.py + a "Baseline x86-64 CPUs only" step in game-build.yml (Linux and Windows): the step disassembles the 4 programs and fails on any popcnt/lzcnt. The script's docstring says why only those two (dispatched AVX/BMI2/SSE4 code exists, and the Windows exe has no symbols). It takes 15-30 s per client. Run on the downloaded builds, it fails on 11-01's horizon-client.exe (9 hits) and passes v0.2.97's and the Linux 11-01 client. Parser unit test: tests/test_check_cpu_baseline.py.

Verification

  • MSVC code shape, checked with clang in MSVC mode (--target x86_64-pc-windows-msvc -mpopcnt to imitate cl.exe, with __has_builtin undefined so it takes the MSVC branch): the original mi_popcount is a bare popcntq; the patched one has no POPCNT and tail-calls _mi_popcount_generic.
  • cargo test -p horizon-threads on macOS passes, building libmimalloc-sys from third_party/.
  • Not verified here: a real cl.exe build. PR CI has no Windows game build. game-build.yml always runs from main's copy, so the first nightly after the merge runs the new guard on the real Windows exe. After it passes, the reporter can retry.

pr_ready

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at fdd290b99, 44 min 46 s)

Check Result
Scope ⚠️ 56 files, +25680 −3; 25615 lines of code: over 500, split it if it can ship in parts; mixes CI, game
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ✅ 613 passed (1 min 3 s)
rustfmt ✅ (14 s)
clippy ✅ (5 min 12 s)
tests: workspace ❌ 5188 passed, 1 failed (11 min 54 s)
doc tests ✅ 0 passed (6 min 2 s)
content root tests ✅ 24 passed (4 min 10 s)
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (3 s)
launcher clippy ✅ (5 min 23 s)
launcher tests ✅ 445 passed (10 min 44 s)
Parity ➖ 382 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 370 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The one failing test (xtask mod_api::tests::new_hook_placeholder_is_reported_then_filled) is the stale base: main fixed it in #7337. After merging main (head 0ca03e3887), cargo test -p xtask --bin xtask passes 19/19 on playhorizon. Scope: 25.5k of the lines are the verbatim vendored crate (first commit); the hand-written change is the second commit, about 150 lines.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7381 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/old-cpu-mimalloc-popcnt` --- ### 📝 Commits (3) - [`e478b7e`](https://github.com/horizon-rust/horizon/commit/e478b7e2105352e0f2af5b6a908609f89fdd051f) third_party: libmimalloc-sys 0.1.49 as published, mimalloc v3 sources only - [`3380705`](https://github.com/horizon-rust/horizon/commit/3380705af9485d12776305e094ef43a56c8fee76) Game: start on CPUs without POPCNT again (Core 2), and check every build for it - [`0ca03e3`](https://github.com/horizon-rust/horizon/commit/0ca03e388799915c638852b965dca8f7d6a0b164) Merge remote-tracking branch 'origin/main' into fix/old-cpu-mimalloc-popcnt ### 📊 Changes **56 files changed** (+25680 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/game-build.yml` (+9 -0) 📝 `Cargo.lock` (+0 -2) 📝 `Cargo.toml` (+5 -1) 📝 `THIRD_PARTY_NOTICES.md` (+9 -0) ➕ `tests/test_check_cpu_baseline.py` (+33 -0) ➕ `third_party/libmimalloc-sys/Cargo.toml` (+79 -0) ➕ `third_party/libmimalloc-sys/LICENSE.txt` (+25 -0) ➕ `third_party/libmimalloc-sys/build.rs` (+138 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/LICENSE` (+21 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-new-delete.h` (+66 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-override.h` (+68 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc-stats.h` (+168 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc.h` (+706 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/atomic.h` (+562 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/bits.h` (+345 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/internal.h` (+1282 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/prim.h` (+542 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/track.h` (+150 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/include/mimalloc/types.h` (+732 -0) ➕ `third_party/libmimalloc-sys/c_src/mimalloc/v3/src/alloc-aligned.c` (+441 -0) _...and 36 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #7264: since the 10-29 nightlies the Windows game exits with 0xc000001d (illegal instruction) at once, with no log, on CPUs without POPCNT (Core 2 Penryn/Merom, AMD K8). ## Cause - #4160 (10-29) made mimalloc v3 the game's allocator (libmimalloc-sys 0.1.49). On MSVC, its `mi_popcount` (`include/mimalloc/bits.h`) is `__popcnt64`. cl.exe always emits that as the POPCNT instruction, whatever `/arch` says, and mimalloc runs before `main`. This is upstream microsoft/mimalloc#1291, fixed upstream in July, but no libmimalloc-sys release has it yet. - Measured on the released binaries, disassembled with llvm-objdump: `horizon-client.exe` of v0.2.97 has **0** `popcnt`; nightly-2026-10-31 (d91cab6) and nightly-2026-11-01 (4aa6854) have **9**, all in one cluster. No `lzcnt` anywhere. AVX, BMI2 and SSE4.x counts are the same in v0.2.97, which ran on the reporter's PC. In the Linux build, which has symbols, they all sit in runtime-dispatched code (ring, memchr, half's F16C, compiler_builtins' FMA). - Linux was never affected: GCC's `__builtin_popcountll` without `-mpopcnt` calls libgcc (0 `popcnt` in the Linux client). ## Change - `third_party/libmimalloc-sys`: the published crate, copied verbatim in the first commit (only the v3 sources, which are all the build reads; `v2` now panics with a clear message). The second commit holds the one-line fix: on MSVC x86/x64, `mi_popcount` takes mimalloc's own portable `_mi_popcount_generic`, as the GCC builds already do. The root `Cargo.toml` has a `[patch.crates-io]` entry, and `THIRD_PARTY_NOTICES.md` credits both projects (MIT). - Why not upstream's per-call CPUID check: it leaves guarded POPCNTs in the exe, so the build guard below couldn't be strict. Bit counts only run in mimalloc's arena bitmaps (page and slice operations, beside atomic RMWs), never on malloc's fast path, so the portable count costs nothing measurable. Windows now does what Linux already does. - `tools/check_cpu_baseline.py` + a "Baseline x86-64 CPUs only" step in `game-build.yml` (Linux and Windows): the step disassembles the 4 programs and fails on any `popcnt`/`lzcnt`. The script's docstring says why only those two (dispatched AVX/BMI2/SSE4 code exists, and the Windows exe has no symbols). It takes 15-30 s per client. Run on the downloaded builds, it **fails on 11-01's `horizon-client.exe` (9 hits) and passes v0.2.97's and the Linux 11-01 client**. Parser unit test: `tests/test_check_cpu_baseline.py`. ## Verification - MSVC code shape, checked with clang in MSVC mode (`--target x86_64-pc-windows-msvc -mpopcnt` to imitate cl.exe, with `__has_builtin` undefined so it takes the MSVC branch): the original `mi_popcount` is a bare `popcntq`; the patched one has no POPCNT and tail-calls `_mi_popcount_generic`. - `cargo test -p horizon-threads` on macOS passes, building libmimalloc-sys from `third_party/`. - Not verified here: a real cl.exe build. PR CI has no Windows game build. `game-build.yml` always runs from main's copy, so the first nightly after the merge runs the new guard on the real Windows exe. After it passes, the reporter can retry. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at fdd290b99, 44 min 46 s) | Check | Result | | --- | --- | | Scope | ⚠️ 56 files, +25680 −3; 25615 lines of code: over 500, split it if it can ship in parts; mixes CI, game | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 613 passed (1 min 3 s) | | rustfmt | ✅ (14 s) | | clippy | ✅ (5 min 12 s) | | tests: workspace | ❌ 5188 passed, 1 failed (11 min 54 s) | | doc tests | ✅ 0 passed (6 min 2 s) | | content root tests | ✅ 24 passed (4 min 10 s) | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (3 s) | | launcher clippy | ✅ (5 min 23 s) | | launcher tests | ✅ 445 passed (10 min 44 s) | | Parity | ➖ 382 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 370 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The one failing test (`xtask mod_api::tests::new_hook_placeholder_is_reported_then_filled`) is the stale base: main fixed it in #7337. After merging main (head 0ca03e3887), `cargo test -p xtask --bin xtask` passes 19/19 on playhorizon. Scope: 25.5k of the lines are the verbatim vendored crate (first commit); the hand-written change is the second commit, about 150 lines. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:19:55 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7566
No description provided.