Skip to main content

iris/simd/
mod.rs

1/// Stubs and helpers for low-level CPU vector instructions (AVX2, Neon) for custom manual loops.
2pub struct SimdHelper;
3
4impl SimdHelper {
5    /// Vectorized sum of two floating point slices.
6    pub fn vector_add(a: &[f32], b: &[f32], out: &mut [f32]) {
7        assert_eq!(a.len(), b.len());
8        assert_eq!(a.len(), out.len());
9
10        // Simple autovectorizable compiler optimization loop
11        for i in 0..a.len() {
12            out[i] = a[i] + b[i];
13        }
14    }
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn test_simd_helper() {
23        let a = vec![1.0f32, 2.0, 3.0];
24        let b = vec![4.0f32, 5.0, 6.0];
25        let mut out = vec![0.0f32; 3];
26        SimdHelper::vector_add(&a, &b, &mut out);
27        assert_eq!(out, vec![5.0f32, 7.0, 9.0]);
28    }
29}