Skip to content

Commit 2a3885d

Browse files
authored
Merge pull request #146 from AdaWorldAPI/claude/portable-simd-nightly
feat(simd_nightly): 30-type portable-simd backend (draft, nightly-simd feature)
2 parents 74b1858 + 752cb33 commit 2a3885d

18 files changed

Lines changed: 6512 additions & 0 deletions

.claude/board/AGENT_LOG.md

Lines changed: 346 additions & 0 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ serde = ["dep:serde"]
147147
std = ["num-traits/std", "matrixmultiply/std"]
148148
rayon = ["dep:rayon", "std"]
149149

150+
# Portable-SIMD backend (NIGHTLY ONLY). Routes `crate::simd::*` types
151+
# through `core::simd::*` instead of the architecture-specific intrinsics
152+
# in `simd_avx512.rs` / `simd_avx2.rs` / `simd_neon.rs`. The point is
153+
# miri compatibility: miri can execute `core::simd` semantics but treats
154+
# `_mm*_*` intrinsics as opaque. With this feature on, miri-run tests
155+
# exercise the actual SIMD code paths in consumer code (`hpc/byte_scan`,
156+
# `hpc/framebuffer`, etc.) and catch UB that the intrinsics backend hides.
157+
#
158+
# Requires `cargo +nightly` because `src/simd_nightly.rs` is gated on
159+
# `#![feature(portable_simd)]` (Rust unstable issue #86656). The default
160+
# build (stable 1.95) does NOT touch this; the existing intrinsics
161+
# cfg-dispatch in `simd.rs` remains the production path.
162+
nightly-simd = ["std"]
163+
150164
# HPC extras: blake3 hashing, p64 palette/NARS bridge, fractal manifold.
151165
# These pull in a non-trivial dependency tree; downstream crates such as
152166
# burn-ndarray that only need the core array layer can disable this with

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88
#![crate_name = "ndarray"]
9+
// Crate-level nightly feature gate for the optional `nightly-simd` backend
10+
// (`src/simd_nightly/`). When the `nightly-simd` cargo feature is OFF
11+
// (default), this attribute is absent and stable rustc compiles the crate
12+
// normally. When ON, the crate requires nightly rustc to access
13+
// `core::simd::*` types.
14+
#![cfg_attr(feature = "nightly-simd", feature(portable_simd))]
915
#![doc(html_root_url = "https://docs.rs/ndarray/0.15/")]
1016
#![doc(html_logo_url = "https://rust-ndarray.github.io/images/rust-ndarray_logo.svg")]
1117
#![allow(
@@ -240,6 +246,14 @@ pub(crate) mod simd_avx512;
240246
#[allow(clippy::all, missing_docs, dead_code, unused_variables, unused_imports)]
241247
pub mod simd_avx2;
242248

249+
// Portable-SIMD backend — nightly-only. Wraps `core::simd::*` so miri can
250+
// execute the polyfill paths (intrinsic-based backends are opaque to
251+
// miri). Gated behind `nightly-simd` feature; the file itself requires
252+
// `#![feature(portable_simd)]` so it only compiles on nightly rustc.
253+
#[cfg(feature = "nightly-simd")]
254+
#[allow(clippy::all, missing_docs)]
255+
pub mod simd_nightly;
256+
243257
#[cfg(feature = "std")]
244258
#[allow(clippy::all, missing_docs, dead_code, unused_variables, unused_imports)]
245259
// AMX is an x86_64-only ISA (Intel Sapphire Rapids+); the module uses

src/simd.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ pub const PREFERRED_I16_LANES: usize = 16;
203203
// at compile time → all types use native __m512/__m512d/__m512i.
204204
// The 256-bit types (F32x8, F64x4) also live in simd_avx512 (__m256).
205205

206+
// Note on the `nightly-simd` feature: it adds the `crate::simd_nightly`
207+
// module (a portable-simd backend wrapping `core::simd`) but does NOT
208+
// replace the intrinsics dispatch below. Full type-parity coverage
209+
// would require the nightly module to define ~30 types; the current
210+
// draft covers 5 (F32x16, F64x8, U8x64, U32x16, F32Mask16). Consumers
211+
// who want miri-runnable SIMD code import from `simd_nightly`
212+
// explicitly (e.g. `use ndarray::simd_nightly::F32x16`). The main
213+
// polyfill via `crate::simd::F32x16` continues to use intrinsics.
214+
206215
#[cfg(all(target_arch = "x86_64", target_feature = "avx512f"))]
207216
pub use crate::simd_avx512::{
208217
f32x16,

0 commit comments

Comments
 (0)