1
+ use crate :: { LaneCount , Simd , SupportedLaneCount } ;
2
+
1
3
macro_rules! impl_uint_arith {
2
- ( $( ( $name : ident , $n : ident ) ) ,+) => {
3
- $( impl <const LANES : usize > $name< LANES > where crate :: LaneCount <LANES >: crate :: SupportedLaneCount {
4
+ ( $( $ty : ty ) ,+) => {
5
+ $( impl <const LANES : usize > Simd <$ty , LANES > where LaneCount <LANES >: SupportedLaneCount {
4
6
5
7
/// Lanewise saturating add.
6
8
///
7
9
/// # Examples
8
10
/// ```
9
11
/// # #![feature(portable_simd)]
10
12
/// # use core_simd::*;
11
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::MAX;" ) ]
12
- # [ doc = concat! ( " let x = " , stringify! ( $name ) , " ::from_array([2, 1, 0, MAX]);" ) ]
13
- # [ doc = concat! ( " let max = " , stringify! ( $name ) , " ::splat(MAX);" ) ]
13
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::MAX;" ) ]
14
+ /// let x = Simd ::from_array([2, 1, 0, MAX]);
15
+ /// let max = Simd ::splat(MAX);
14
16
/// let unsat = x + max;
15
17
/// let sat = x.saturating_add(max);
16
18
/// assert_eq!(x - 1, unsat);
@@ -27,13 +29,13 @@ macro_rules! impl_uint_arith {
27
29
/// ```
28
30
/// # #![feature(portable_simd)]
29
31
/// # use core_simd::*;
30
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::MAX;" ) ]
31
- # [ doc = concat! ( " let x = " , stringify! ( $name ) , " ::from_array([2, 1, 0, MAX]);" ) ]
32
- # [ doc = concat! ( " let max = " , stringify! ( $name ) , " ::splat(MAX);" ) ]
32
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::MAX;" ) ]
33
+ /// let x = Simd ::from_array([2, 1, 0, MAX]);
34
+ /// let max = Simd ::splat(MAX);
33
35
/// let unsat = x - max;
34
36
/// let sat = x.saturating_sub(max);
35
37
/// assert_eq!(unsat, x + 1);
36
- # [ doc = concat! ( " assert_eq!(sat, " , stringify! ( $name ) , " ::splat(0));" ) ]
38
+ /// assert_eq!(sat, Simd ::splat(0));
37
39
#[ inline]
38
40
pub fn saturating_sub( self , second: Self ) -> Self {
39
41
unsafe { crate :: intrinsics:: simd_saturating_sub( self , second) }
@@ -43,22 +45,22 @@ macro_rules! impl_uint_arith {
43
45
}
44
46
45
47
macro_rules! impl_int_arith {
46
- ( $( ( $name : ident , $n : ident ) ) ,+) => {
47
- $( impl <const LANES : usize > $name< LANES > where crate :: LaneCount <LANES >: crate :: SupportedLaneCount {
48
+ ( $( $ty : ty ) ,+) => {
49
+ $( impl <const LANES : usize > Simd <$ty , LANES > where LaneCount <LANES >: SupportedLaneCount {
48
50
49
51
/// Lanewise saturating add.
50
52
///
51
53
/// # Examples
52
54
/// ```
53
55
/// # #![feature(portable_simd)]
54
56
/// # use core_simd::*;
55
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::{MIN, MAX};" ) ]
56
- # [ doc = concat! ( " let x = " , stringify! ( $name ) , " ::from_array([MIN, 0, 1, MAX]);" ) ]
57
- # [ doc = concat! ( " let max = " , stringify! ( $name ) , " ::splat(MAX);" ) ]
57
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::{MIN, MAX};" ) ]
58
+ /// let x = Simd ::from_array([MIN, 0, 1, MAX]);
59
+ /// let max = Simd ::splat(MAX);
58
60
/// let unsat = x + max;
59
61
/// let sat = x.saturating_add(max);
60
- # [ doc = concat! ( " assert_eq!(unsat, " , stringify! ( $name ) , " ::from_array([-1, MAX, MIN, -2]));" ) ]
61
- # [ doc = concat! ( " assert_eq!(sat, " , stringify! ( $name ) , " ::from_array([-1, MAX, MAX, MAX]));" ) ]
62
+ /// assert_eq!(unsat, Simd ::from_array([-1, MAX, MIN, -2]));
63
+ /// assert_eq!(sat, Simd ::from_array([-1, MAX, MAX, MAX]));
62
64
/// ```
63
65
#[ inline]
64
66
pub fn saturating_add( self , second: Self ) -> Self {
@@ -71,13 +73,13 @@ macro_rules! impl_int_arith {
71
73
/// ```
72
74
/// # #![feature(portable_simd)]
73
75
/// # use core_simd::*;
74
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::{MIN, MAX};" ) ]
75
- # [ doc = concat! ( " let x = " , stringify! ( $name ) , " ::from_array([MIN, -2, -1, MAX]);" ) ]
76
- # [ doc = concat! ( " let max = " , stringify! ( $name ) , " ::splat(MAX);" ) ]
76
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::{MIN, MAX};" ) ]
77
+ /// let x = Simd ::from_array([MIN, -2, -1, MAX]);
78
+ /// let max = Simd ::splat(MAX);
77
79
/// let unsat = x - max;
78
80
/// let sat = x.saturating_sub(max);
79
- # [ doc = concat! ( " assert_eq!(unsat, " , stringify! ( $name ) , " ::from_array([1, MAX, MIN, 0]));" ) ]
80
- # [ doc = concat! ( " assert_eq!(sat, " , stringify! ( $name ) , " ::from_array([MIN, MIN, MIN, 0]));" ) ]
81
+ /// assert_eq!(unsat, Simd ::from_array([1, MAX, MIN, 0]));
82
+ /// assert_eq!(sat, Simd ::from_array([MIN, MIN, MIN, 0]));
81
83
#[ inline]
82
84
pub fn saturating_sub( self , second: Self ) -> Self {
83
85
unsafe { crate :: intrinsics:: simd_saturating_sub( self , second) }
@@ -90,13 +92,13 @@ macro_rules! impl_int_arith {
90
92
/// ```
91
93
/// # #![feature(portable_simd)]
92
94
/// # use core_simd::*;
93
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::{MIN, MAX};" ) ]
94
- # [ doc = concat! ( " let xs = " , stringify! ( $name ) , " ::from_array([MIN, MIN +1, -5, 0]);" ) ]
95
- # [ doc = concat! ( " assert_eq!(xs.abs(), " , stringify! ( $name ) , " ::from_array([MIN, MAX, 5, 0]));" ) ]
95
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::{MIN, MAX};" ) ]
96
+ /// let xs = Simd ::from_array([MIN, MIN +1, -5, 0]);
97
+ /// assert_eq!(xs.abs(), Simd ::from_array([MIN, MAX, 5, 0]));
96
98
/// ```
97
99
#[ inline]
98
100
pub fn abs( self ) -> Self {
99
- const SHR : $n = <$n >:: BITS as $n - 1 ;
101
+ const SHR : $ty = <$ty >:: BITS as $ty - 1 ;
100
102
let m = self >> SHR ;
101
103
( self ^m) - m
102
104
}
@@ -108,17 +110,17 @@ macro_rules! impl_int_arith {
108
110
/// ```
109
111
/// # #![feature(portable_simd)]
110
112
/// # use core_simd::*;
111
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::{MIN, MAX};" ) ]
112
- # [ doc = concat! ( " let xs = " , stringify! ( $name ) , " ::from_array([MIN, -2, 0, 3]);" ) ]
113
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::{MIN, MAX};" ) ]
114
+ /// let xs = Simd ::from_array([MIN, -2, 0, 3]);
113
115
/// let unsat = xs.abs();
114
116
/// let sat = xs.saturating_abs();
115
- # [ doc = concat! ( " assert_eq!(unsat, " , stringify! ( $name ) , " ::from_array([MIN, 2, 0, 3]));" ) ]
116
- # [ doc = concat! ( " assert_eq!(sat, " , stringify! ( $name ) , " ::from_array([MAX, 2, 0, 3]));" ) ]
117
+ /// assert_eq!(unsat, Simd ::from_array([MIN, 2, 0, 3]));
118
+ /// assert_eq!(sat, Simd ::from_array([MAX, 2, 0, 3]));
117
119
/// ```
118
120
#[ inline]
119
121
pub fn saturating_abs( self ) -> Self {
120
122
// arith shift for -1 or 0 mask based on sign bit, giving 2s complement
121
- const SHR : $n = <$n >:: BITS as $n - 1 ;
123
+ const SHR : $ty = <$ty >:: BITS as $ty - 1 ;
122
124
let m = self >> SHR ;
123
125
( self ^m) . saturating_sub( m)
124
126
}
@@ -130,12 +132,12 @@ macro_rules! impl_int_arith {
130
132
/// ```
131
133
/// # #![feature(portable_simd)]
132
134
/// # use core_simd::*;
133
- #[ doc = concat!( "# use core::" , stringify!( $n ) , "::{MIN, MAX};" ) ]
134
- # [ doc = concat! ( " let x = " , stringify! ( $name ) , " ::from_array([MIN, -2, 3, MAX]);" ) ]
135
+ #[ doc = concat!( "# use core::" , stringify!( $ty ) , "::{MIN, MAX};" ) ]
136
+ /// let x = Simd ::from_array([MIN, -2, 3, MAX]);
135
137
/// let unsat = -x;
136
138
/// let sat = x.saturating_neg();
137
- # [ doc = concat! ( " assert_eq!(unsat, " , stringify! ( $name ) , " ::from_array([MIN, 2, -3, MIN + 1]));" ) ]
138
- # [ doc = concat! ( " assert_eq!(sat, " , stringify! ( $name ) , " ::from_array([MAX, 2, -3, MIN + 1]));" ) ]
139
+ /// assert_eq!(unsat, Simd ::from_array([MIN, 2, -3, MIN + 1]));
140
+ /// assert_eq!(sat, Simd ::from_array([MAX, 2, -3, MIN + 1]));
139
141
/// ```
140
142
#[ inline]
141
143
pub fn saturating_neg( self ) -> Self {
@@ -145,7 +147,5 @@ macro_rules! impl_int_arith {
145
147
}
146
148
}
147
149
148
- use crate :: vector:: * ;
149
-
150
- impl_uint_arith ! { ( SimdU8 , u8 ) , ( SimdU16 , u16 ) , ( SimdU32 , u32 ) , ( SimdU64 , u64 ) , ( SimdUsize , usize ) }
151
- impl_int_arith ! { ( SimdI8 , i8 ) , ( SimdI16 , i16 ) , ( SimdI32 , i32 ) , ( SimdI64 , i64 ) , ( SimdIsize , isize ) }
150
+ impl_uint_arith ! { u8 , u16 , u32 , u64 , usize }
151
+ impl_int_arith ! { i8 , i16 , i32 , i64 , isize }
0 commit comments