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