simba/simd/
simd_signed.rs

1use crate::simd::SimdValue;
2use num::Signed;
3
4/// A lane-wise generalization of [`num::Signed`](https://rust-num.github.io/num/num/trait.Signed.html) for SIMD values.
5pub trait SimdSigned: SimdValue {
6    /// The absolute value of each lane of `self`.
7    fn simd_abs(&self) -> Self;
8    /// The absolute difference of each lane of `self`.
9    ///
10    /// For each lane, this zero if the lane of self is less than or equal to the corresponding lane of other
11    /// otherwise the difference between the lane of self and the lane of other is returned.
12    fn simd_abs_sub(&self, other: &Self) -> Self;
13    /// The signum of each lane of `Self`.
14    fn simd_signum(&self) -> Self;
15    /// Tests which lane is positive.
16    fn is_simd_positive(&self) -> Self::SimdBool;
17    /// Tests which lane is negative.
18    fn is_simd_negative(&self) -> Self::SimdBool;
19}
20
21impl<T: Signed + SimdValue<SimdBool = bool>> SimdSigned for T {
22    #[inline(always)]
23    fn simd_abs(&self) -> Self {
24        self.abs()
25    }
26
27    #[inline(always)]
28    fn simd_abs_sub(&self, other: &Self) -> Self {
29        self.abs_sub(other)
30    }
31
32    #[inline(always)]
33    fn simd_signum(&self) -> Self {
34        self.signum()
35    }
36
37    #[inline(always)]
38    fn is_simd_positive(&self) -> Self::SimdBool {
39        self.is_positive()
40    }
41
42    #[inline(always)]
43    fn is_simd_negative(&self) -> Self::SimdBool {
44        self.is_negative()
45    }
46}