Skip to content

Commit a7279e0

Browse files
committed
fix(simd_profile): target_arch guards on cpu-* features + std-gate example
Two independent bug fixes for codex P2 on de52a44 and the no-default-features CI failure: 1) codex P2 — Reject ARM cpu-* on x86 builds (and vice versa). Without target_arch guards, `--features cpu-a76` on an x86_64 build silently routes simd_profile() to A76DotProd, breaking the is_x86()/is_aarch64() partitioning and routing callers into the wrong dispatch family. Add compile_error! checks that fail fast for the current target_arch — same fail-fast pattern as the existing _PIN_COUNT mutual-exclusion assert. 2) CI fix — examples/simd_profile_probe.rs uses ndarray::hpc::* and ndarray::simd_amx::* which are gated behind the "std" feature. On `cargo test --no-default-features` the example target still tries to compile, producing E0433 "cannot find hpc in ndarray". Add `required-features = ["std"]` to the example's Cargo.toml entry so it is skipped when std is disabled, matching the existing pattern for ocr_benchmark. No behavioral change on default builds. Both fixes are independent of the architectural question about whether cpu-* features should exist at all (which is for the originating session to revisit if they want to unify with cpu_ops_for_cpu); this just makes the existing features less of a footgun.
1 parent de52a44 commit a7279e0

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ required-features = ["std"]
4242
name = "splat3d_flex"
4343
required-features = ["splat3d"]
4444

45+
[[example]]
46+
name = "simd_profile_probe"
47+
required-features = ["std"]
48+
4549
[dependencies]
4650
num-integer = { workspace = true }
4751
num-traits = { workspace = true }

src/hpc/simd_profile.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,44 @@ const _: () = assert!(
271271
"cpu-* cargo features are mutually exclusive: enable at most one (cpu-gnr, cpu-spr, cpu-zen4, cpu-cpl, cpu-tigerlake, cpu-icx, cpu-clx, cpu-skx, cpu-arrowlake, cpu-haswell, cpu-a76, cpu-a72, cpu-a53)"
272272
);
273273

274+
// ────────────────────────────────────────────────────────────────────
275+
// target_arch guards (codex P2 closure).
276+
//
277+
// Each `cpu-<codename>` pin is only valid on its native silicon
278+
// family. Without these guards `--features cpu-a76` on an x86_64
279+
// build would silently route `simd_profile()` to `A76DotProd`,
280+
// breaking the `is_x86()` / `is_aarch64()` partitioning and routing
281+
// callers into the wrong dispatch family. Fail fast at compile time
282+
// instead.
283+
// ────────────────────────────────────────────────────────────────────
284+
285+
#[cfg(all(
286+
not(target_arch = "x86_64"),
287+
any(
288+
feature = "cpu-gnr",
289+
feature = "cpu-spr",
290+
feature = "cpu-zen4",
291+
feature = "cpu-cpl",
292+
feature = "cpu-tigerlake",
293+
feature = "cpu-icx",
294+
feature = "cpu-clx",
295+
feature = "cpu-skx",
296+
feature = "cpu-arrowlake",
297+
feature = "cpu-haswell",
298+
)
299+
))]
300+
compile_error!(
301+
"x86 cpu-* pinning features (cpu-gnr, cpu-spr, cpu-zen4, cpu-cpl, cpu-tigerlake, cpu-icx, cpu-clx, cpu-skx, cpu-arrowlake, cpu-haswell) require target_arch = \"x86_64\""
302+
);
303+
304+
#[cfg(all(
305+
not(target_arch = "aarch64"),
306+
any(feature = "cpu-a76", feature = "cpu-a72", feature = "cpu-a53",)
307+
))]
308+
compile_error!(
309+
"ARM cpu-* pinning features (cpu-a76, cpu-a72, cpu-a53) require target_arch = \"aarch64\""
310+
);
311+
274312
/// The compile-time pinned profile, or `None` when runtime detection is in
275313
/// effect. `Some(_)` exactly when one of the `cpu-*` cargo features is
276314
/// enabled; mutually exclusive features are enforced by the `_PIN_COUNT`

0 commit comments

Comments
 (0)