Commit 500d57e
committed
feat(simd): real WASM SIMD128 backend (fill simd_wasm.rs scalar scaffolding)
`src/simd_wasm.rs` was commented-out scaffolding; wasm32 fell back to the
pure-scalar SIMD types. Fill it with a native `core::arch::wasm32` v128
backend, mirroring `simd_neon::aarch64_simd`'s proven split (native v128 for
the float/byte hot path, scalar fallback for the long tail).
simd_wasm::wasm32_simd (gated wasm32 + target_feature="simd128"):
- F32x16 / F64x8 as [v128;4] + F32Mask16 / F64Mask8 — full API parity with
the scalar macro (arith/reduce/min-max/clamp/compare-mask/to-from-bits/
cast/round/floor/sqrt/abs/mul_add + operator impls + Mask::select).
- I8x16 (one v128) = union of the scalar + NEON method sets (add/sub/min/max/
cmp_gt + from_i4_packed_u64/lane_i8/saturating_abs).
- v128 hot kernels mirroring the NEON ones: dot_f32x4, popcount_u8x16,
hamming_u8x16, hamming_u8x64 (Fingerprint<256> distance via i8x16_popcnt),
base17_l1 (i16->i32 sign-extend before subtract, no overflow),
codebook_gather_f32x4, bf16_to_f32_batch.
- mul_add: f32x4_relaxed_madd under +relaxed-simd, else mul+add (base
simd128 has no FMA). round = f32x4_nearest (ties-even, =NEON). NaN in
min/max follows IEEE (=NEON). All cross-backend divergences documented.
Dispatch (simd.rs): wasm32+simd128 arm re-exports the 8 native names from
wasm32_simd and the remainder from scalar; the full-scalar fallback arm now
excludes that case. Added wasm32 PREFERRED_*_LANES (128-bit widths) and
.cargo/config-wasm.toml (-Ctarget-feature=+simd128).
Also unblock the wasm build (pre-existing x86-only AMX leaks, not the SIMD
scaffolding): gate the x86-only amx_matmul / simd_amx re-exports in simd.rs
to target_arch="x86_64", and route backend::gemm_bf16 through the portable
hpc::quantized::bf16_gemm_f32 on non-x86 (bit-equivalent to the AMX
dispatcher's own scalar fallback). x86 paths are untouched by construction.
Verified: cargo build -p ndarray --lib for wasm32 (+simd128 native /
scalar / no_std) and x86_64 all green; a faithful standalone copy of
wasm32_simd run under node passes 51 numeric checks (mask bit-patterns,
saturating_abs(i8::MIN)=127, Hamming, Base17 incl. |a-b|=60000 overflow,
bf16 shift); 217 SIMD + 85 backend/bf16 x86 tests pass; clippy -D warnings
and fmt clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NSk1qJ28eh6A2hd4JUWFRr1 parent 72ecee0 commit 500d57e
5 files changed
Lines changed: 1256 additions & 163 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
6 | 85 | | |
7 | 86 | | |
8 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
214 | 219 | | |
215 | 220 | | |
216 | 221 | | |
| |||
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
238 | 259 | | |
239 | 260 | | |
240 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
159 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
| |||
167 | 174 | | |
168 | 175 | | |
169 | 176 | | |
170 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
171 | 180 | | |
172 | 181 | | |
173 | 182 | | |
| |||
178 | 187 | | |
179 | 188 | | |
180 | 189 | | |
181 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
| |||
191 | 202 | | |
192 | 203 | | |
193 | 204 | | |
194 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
195 | 208 | | |
196 | 209 | | |
197 | 210 | | |
| |||
376 | 389 | | |
377 | 390 | | |
378 | 391 | | |
379 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
380 | 410 | | |
381 | 411 | | |
382 | 412 | | |
| 413 | + | |
383 | 414 | | |
384 | 415 | | |
385 | 416 | | |
| |||
577 | 608 | | |
578 | 609 | | |
579 | 610 | | |
580 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
581 | 616 | | |
582 | 617 | | |
583 | 618 | | |
584 | 619 | | |
| 620 | + | |
585 | 621 | | |
586 | 622 | | |
587 | 623 | | |
| |||
0 commit comments