1
2
3
4
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! v0.8.0 Block C — SIMD intrinsics scoped module (ADR-0019).
//!
//! `#![allow(unsafe_code)]` at MODULE scope — the crate root has
//! `#![deny(unsafe_code)]` (`lib.rs` line 69). `forbid` cannot be
//! relaxed by inner `#[allow]` per Rust lint hierarchy, so v0.8.0
//! Block C downgraded the crate-level lint to `deny`. The unsafe
//! blast radius remains bounded to `src/simd/{x86_64,aarch64}.rs`
//! by lint enforcement (no `#[allow(unsafe_code)]` outside this
//! module — verified by CI grep). The only `unsafe` in
//! this module sits inside `x86_64.rs` and `aarch64.rs` (intrinsic shims).
//!
//! Cross-ref: ADR-0019, contracts/semiflow-core.tensor.yaml `simd` block.
// ---------------------------------------------------------------------------
// Arch-specific implementations (only one compiles per target).
// ---------------------------------------------------------------------------
// Scalar is always compiled. On x86_64+avx2, F32x4Scalar is still needed
// (no native SSE f32x4 type in our trait; only F32x8 uses AVX2 on x86_64).
// On aarch64+neon, F64x4Scalar and F32x8Scalar are still needed fallbacks.
// Dead-code gates: #[allow(dead_code)] on the items that are unused per arch.
// ---------------------------------------------------------------------------
// Type alias: F64x4 resolves to the fastest impl for the target arch.
// ---------------------------------------------------------------------------
pub use F64x4Neon as F64x4;
pub use F64x4Scalar as F64x4;
pub use F64x4Avx2 as F64x4;
// ---------------------------------------------------------------------------
// Type alias: F32x8 (AVX2: 8 lanes) / F32x4 (NEON: 4 lanes).
// ---------------------------------------------------------------------------
/// 8-lane f32 alias — AVX2 impl on x86_64+avx2, scalar fallback elsewhere.
pub use F32x8Avx2 as F32x8;
pub use F32x8Scalar as F32x8;
/// 4-lane f32 alias — NEON impl on aarch64+neon, scalar fallback elsewhere.
pub use F32x4Neon as F32x4;
pub use F32x4Scalar as F32x4;
// ---------------------------------------------------------------------------
// Wave B3: G⁴ stencil SIMD kernels re-exported for truncated_exp4_cached.
// ---------------------------------------------------------------------------
pub use apply_g4_stencil_neon_4nodes;
pub use apply_g4_stencil_avx2_4nodes;
// ---------------------------------------------------------------------------
// Test-hook: thread-local flag to force scalar path even on x86_64/aarch64.
// ---------------------------------------------------------------------------
thread_local!
/// Run `closure` with the SIMD force-scalar flag active; resets afterwards.
///
/// Integration-test hook. Not part of the stable API.
// ---------------------------------------------------------------------------
// Trait — crate-private, 4-lane f64 SIMD.
// ---------------------------------------------------------------------------
/// 4-lane f64 SIMD trait, crate-private.
///
/// Determinism contract (ADR-0019 §`determinism_contract`):
/// every method is bit-equal to the corresponding scalar f64 op.
/// FMA is FORBIDDEN — `mul` and `add` are SEPARATE rounding steps.
// full trait surface mandated by contract; not all methods used in v0.8.0
pub
// ---------------------------------------------------------------------------
// Trait — crate-private, 8-lane f32 SIMD (ADR-0175, Phase 5b).
// ---------------------------------------------------------------------------
/// 8-lane f32 SIMD trait, crate-private (AVX2 path; scalar fallback for other arches).
///
/// Determinism contract (extends ADR-0019 to f32, ADR-0175):
/// every method is bit-equal to the corresponding scalar f32 op.
/// FMA is FORBIDDEN — `mul` and `add` are SEPARATE rounding steps.
/// `horizontal_sum` uses a hard-fixed addition tree matching the scalar reference.
// full trait surface mandated by contract
pub
// ---------------------------------------------------------------------------
// Trait — crate-private, 4-lane f32 SIMD (ADR-0175, Phase 5b, NEON path).
// ---------------------------------------------------------------------------
/// 4-lane f32 SIMD trait, crate-private (NEON path; scalar fallback for other arches).
///
/// Determinism contract: same as `SimdF32x8`. FMA FORBIDDEN.
// full trait surface mandated by contract
pub