]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/ops/unary.rs
Rollup merge of #107108 - sulami:issue-83968-doc-alias-typo-suggestions, r=compiler...
[rust.git] / library / portable-simd / crates / core_simd / src / ops / unary.rs
1 use crate::simd::intrinsics;
2 use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
3 use core::ops::{Neg, Not}; // unary ops
4
5 macro_rules! neg {
6     ($(impl<const LANES: usize> Neg for Simd<$scalar:ty, LANES>)*) => {
7         $(impl<const LANES: usize> Neg for Simd<$scalar, LANES>
8         where
9             $scalar: SimdElement,
10             LaneCount<LANES>: 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
24 neg! {
25     impl<const LANES: usize> Neg for Simd<f32, LANES>
26
27     impl<const LANES: usize> Neg for Simd<f64, LANES>
28
29     impl<const LANES: usize> Neg for Simd<i8, LANES>
30
31     impl<const LANES: usize> Neg for Simd<i16, LANES>
32
33     impl<const LANES: usize> Neg for Simd<i32, LANES>
34
35     impl<const LANES: usize> Neg for Simd<i64, LANES>
36
37     impl<const LANES: usize> Neg for Simd<isize, LANES>
38 }
39
40 macro_rules! not {
41     ($(impl<const LANES: usize> Not for Simd<$scalar:ty, LANES>)*) => {
42         $(impl<const LANES: usize> Not for Simd<$scalar, LANES>
43         where
44             $scalar: SimdElement,
45             LaneCount<LANES>: 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
58 not! {
59     impl<const LANES: usize> Not for Simd<i8, LANES>
60
61     impl<const LANES: usize> Not for Simd<i16, LANES>
62
63     impl<const LANES: usize> Not for Simd<i32, LANES>
64
65     impl<const LANES: usize> Not for Simd<i64, LANES>
66
67     impl<const LANES: usize> Not for Simd<isize, LANES>
68
69     impl<const LANES: usize> Not for Simd<u8, LANES>
70
71     impl<const LANES: usize> Not for Simd<u16, LANES>
72
73     impl<const LANES: usize> Not for Simd<u32, LANES>
74
75     impl<const LANES: usize> Not for Simd<u64, LANES>
76
77     impl<const LANES: usize> Not for Simd<usize, LANES>
78 }