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