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
use std::ops::Add;

use super::Sum;
use crate::types::simd::{i128x8, NativeSimd};

macro_rules! simd_add {
    ($simd:tt, $type:ty, $lanes:expr, $add:tt) => {
        impl std::ops::AddAssign for $simd {
            #[inline]
            fn add_assign(&mut self, rhs: Self) {
                for i in 0..$lanes {
                    self[i] = <$type>::$add(self[i], rhs[i]);
                }
            }
        }

        impl std::ops::Add for $simd {
            type Output = Self;

            #[inline]
            fn add(self, rhs: Self) -> Self::Output {
                let mut result = Self::default();
                for i in 0..$lanes {
                    result[i] = <$type>::$add(self[i], rhs[i]);
                }
                result
            }
        }

        impl Sum<$type> for $simd {
            #[inline]
            fn simd_sum(self) -> $type {
                let mut reduced = <$type>::default();
                (0..<$simd>::LANES).for_each(|i| {
                    reduced += self[i];
                });
                reduced
            }
        }
    };
}

// #[cfg(not(feature = "simd"))]
// pub(super) use simd_add;

simd_add!(i128x8, i128, 8, add);

#[cfg(not(feature = "simd"))]
mod native;

#[cfg(feature = "simd")]
mod packed;