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