| 1 | use crate::simd::{Simd, SimdElement}; |
| 2 | use core::ops::{Neg, Not}; // unary ops |
| 3 | |
| 4 | macro_rules! neg { |
| 5 | ($(impl<const N: usize> Neg for Simd<$scalar:ty, N>)*) => { |
| 6 | $(impl<const N: usize> Neg for Simd<$scalar, N> |
| 7 | where |
| 8 | $scalar: SimdElement, |
| 9 | { |
| 10 | type Output = Self; |
| 11 | |
| 12 | #[inline] |
| 13 | fn neg(self) -> Self::Output { |
| 14 | // Safety: `self` is a signed vector |
| 15 | unsafe { core::intrinsics::simd::simd_neg(self) } |
| 16 | } |
| 17 | })* |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | neg! { |
| 22 | impl<const N: usize> Neg for Simd<f32, N> |
| 23 | |
| 24 | impl<const N: usize> Neg for Simd<f64, N> |
| 25 | |
| 26 | impl<const N: usize> Neg for Simd<i8, N> |
| 27 | |
| 28 | impl<const N: usize> Neg for Simd<i16, N> |
| 29 | |
| 30 | impl<const N: usize> Neg for Simd<i32, N> |
| 31 | |
| 32 | impl<const N: usize> Neg for Simd<i64, N> |
| 33 | |
| 34 | impl<const N: usize> Neg for Simd<isize, N> |
| 35 | } |
| 36 | |
| 37 | macro_rules! not { |
| 38 | ($(impl<const N: usize> Not for Simd<$scalar:ty, N>)*) => { |
| 39 | $(impl<const N: usize> Not for Simd<$scalar, N> |
| 40 | where |
| 41 | $scalar: SimdElement, |
| 42 | { |
| 43 | type Output = Self; |
| 44 | |
| 45 | #[inline] |
| 46 | fn not(self) -> Self::Output { |
| 47 | self ^ (Simd::splat(!(0 as $scalar))) |
| 48 | } |
| 49 | })* |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | not! { |
| 54 | impl<const N: usize> Not for Simd<i8, N> |
| 55 | |
| 56 | impl<const N: usize> Not for Simd<i16, N> |
| 57 | |
| 58 | impl<const N: usize> Not for Simd<i32, N> |
| 59 | |
| 60 | impl<const N: usize> Not for Simd<i64, N> |
| 61 | |
| 62 | impl<const N: usize> Not for Simd<isize, N> |
| 63 | |
| 64 | impl<const N: usize> Not for Simd<u8, N> |
| 65 | |
| 66 | impl<const N: usize> Not for Simd<u16, N> |
| 67 | |
| 68 | impl<const N: usize> Not for Simd<u32, N> |
| 69 | |
| 70 | impl<const N: usize> Not for Simd<u64, N> |
| 71 | |
| 72 | impl<const N: usize> Not for Simd<usize, N> |
| 73 | } |
| 74 | |