]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/vector/int.rs
Auto merge of #90821 - scottmcm:new-slice-reverse, r=Mark-Simulacrum
[rust.git] / library / portable-simd / crates / core_simd / src / vector / int.rs
1 #![allow(non_camel_case_types)]
2
3 use crate::simd::{LaneCount, Mask, Simd, SupportedLaneCount};
4
5 /// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
6 macro_rules! impl_integer_vector {
7     { $type:ty } => {
8         impl<const LANES: usize> Simd<$type, LANES>
9         where
10             LaneCount<LANES>: SupportedLaneCount,
11         {
12             /// Returns true for each positive lane and false if it is zero or negative.
13             #[inline]
14             pub fn is_positive(self) -> Mask<$type, LANES> {
15                 self.lanes_gt(Self::splat(0))
16             }
17
18             /// Returns true for each negative lane and false if it is zero or positive.
19             #[inline]
20             pub fn is_negative(self) -> Mask<$type, LANES> {
21                 self.lanes_lt(Self::splat(0))
22             }
23
24             /// Returns numbers representing the sign of each lane.
25             /// * `0` if the number is zero
26             /// * `1` if the number is positive
27             /// * `-1` if the number is negative
28             #[inline]
29             pub fn signum(self) -> Self {
30                 self.is_positive().select(
31                     Self::splat(1),
32                     self.is_negative().select(Self::splat(-1), Self::splat(0))
33                 )
34             }
35         }
36     }
37 }
38
39 impl_integer_vector! { isize }
40 impl_integer_vector! { i16 }
41 impl_integer_vector! { i32 }
42 impl_integer_vector! { i64 }
43 impl_integer_vector! { i8 }
44
45 /// Vector of two `isize` values
46 pub type isizex2 = Simd<isize, 2>;
47
48 /// Vector of four `isize` values
49 pub type isizex4 = Simd<isize, 4>;
50
51 /// Vector of eight `isize` values
52 pub type isizex8 = Simd<isize, 8>;
53
54 /// Vector of two `i16` values
55 pub type i16x2 = Simd<i16, 2>;
56
57 /// Vector of four `i16` values
58 pub type i16x4 = Simd<i16, 4>;
59
60 /// Vector of eight `i16` values
61 pub type i16x8 = Simd<i16, 8>;
62
63 /// Vector of 16 `i16` values
64 pub type i16x16 = Simd<i16, 16>;
65
66 /// Vector of 32 `i16` values
67 pub type i16x32 = Simd<i16, 32>;
68
69 /// Vector of two `i32` values
70 pub type i32x2 = Simd<i32, 2>;
71
72 /// Vector of four `i32` values
73 pub type i32x4 = Simd<i32, 4>;
74
75 /// Vector of eight `i32` values
76 pub type i32x8 = Simd<i32, 8>;
77
78 /// Vector of 16 `i32` values
79 pub type i32x16 = Simd<i32, 16>;
80
81 /// Vector of two `i64` values
82 pub type i64x2 = Simd<i64, 2>;
83
84 /// Vector of four `i64` values
85 pub type i64x4 = Simd<i64, 4>;
86
87 /// Vector of eight `i64` values
88 pub type i64x8 = Simd<i64, 8>;
89
90 /// Vector of four `i8` values
91 pub type i8x4 = Simd<i8, 4>;
92
93 /// Vector of eight `i8` values
94 pub type i8x8 = Simd<i8, 8>;
95
96 /// Vector of 16 `i8` values
97 pub type i8x16 = Simd<i8, 16>;
98
99 /// Vector of 32 `i8` values
100 pub type i8x32 = Simd<i8, 32>;
101
102 /// Vector of 64 `i8` values
103 pub type i8x64 = Simd<i8, 64>;