Skip to content

Commit 5ed57b4

Browse files
committed
Remove most usage of type aliases
1 parent e11286a commit 5ed57b4

File tree

12 files changed

+145
-152
lines changed

12 files changed

+145
-152
lines changed

crates/core_simd/src/iter.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
1-
use crate::{LaneCount, SupportedLaneCount};
1+
use crate::{LaneCount, Simd, SupportedLaneCount};
2+
use core::{
3+
iter::{Product, Sum},
4+
ops::{Add, Mul},
5+
};
26

37
macro_rules! impl_traits {
4-
{ $type:ident } => {
5-
impl<const LANES: usize> core::iter::Sum<Self> for crate::$type<LANES>
8+
{ $type:ty } => {
9+
impl<const LANES: usize> Sum<Self> for Simd<$type, LANES>
610
where
711
LaneCount<LANES>: SupportedLaneCount,
812
{
9-
fn sum<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
10-
iter.fold(Default::default(), core::ops::Add::add)
13+
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
14+
iter.fold(Simd::splat(0 as $type), Add::add)
1115
}
1216
}
1317

14-
impl<const LANES: usize> core::iter::Product<Self> for crate::$type<LANES>
18+
impl<const LANES: usize> core::iter::Product<Self> for Simd<$type, LANES>
1519
where
1620
LaneCount<LANES>: SupportedLaneCount,
1721
{
18-
fn product<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
19-
iter.fold(Default::default(), core::ops::Mul::mul)
22+
fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
23+
iter.fold(Simd::splat(1 as $type), Mul::mul)
2024
}
2125
}
2226

23-
impl<'a, const LANES: usize> core::iter::Sum<&'a Self> for crate::$type<LANES>
27+
impl<'a, const LANES: usize> Sum<&'a Self> for Simd<$type, LANES>
2428
where
2529
LaneCount<LANES>: SupportedLaneCount,
2630
{
27-
fn sum<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
28-
iter.fold(Default::default(), core::ops::Add::add)
31+
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
32+
iter.fold(Simd::splat(0 as $type), Add::add)
2933
}
3034
}
3135

32-
impl<'a, const LANES: usize> core::iter::Product<&'a Self> for crate::$type<LANES>
36+
impl<'a, const LANES: usize> Product<&'a Self> for Simd<$type, LANES>
3337
where
3438
LaneCount<LANES>: SupportedLaneCount,
3539
{
36-
fn product<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
37-
iter.fold(Default::default(), core::ops::Mul::mul)
40+
fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
41+
iter.fold(Simd::splat(1 as $type), Mul::mul)
3842
}
3943
}
4044
}
4145
}
4246

43-
impl_traits! { SimdF32 }
44-
impl_traits! { SimdF64 }
45-
impl_traits! { SimdU8 }
46-
impl_traits! { SimdU16 }
47-
impl_traits! { SimdU32 }
48-
impl_traits! { SimdU64 }
49-
impl_traits! { SimdUsize }
50-
impl_traits! { SimdI8 }
51-
impl_traits! { SimdI16 }
52-
impl_traits! { SimdI32 }
53-
impl_traits! { SimdI64 }
54-
impl_traits! { SimdIsize }
47+
impl_traits! { f32 }
48+
impl_traits! { f64 }
49+
impl_traits! { u8 }
50+
impl_traits! { u16 }
51+
impl_traits! { u32 }
52+
impl_traits! { u64 }
53+
impl_traits! { usize }
54+
impl_traits! { i8 }
55+
impl_traits! { i16 }
56+
impl_traits! { i32 }
57+
impl_traits! { i64 }
58+
impl_traits! { isize }

crates/core_simd/src/masks.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,21 @@ pub type masksizex4 = MaskSize<4>;
522522
pub type masksizex8 = MaskSize<8>;
523523

524524
macro_rules! impl_from {
525-
{ $from:ident ($from_inner:ident) => $($to:ident ($to_inner:ident)),* } => {
525+
{ $from:ty => $($to:ty),* } => {
526526
$(
527-
impl<const LANES: usize> From<$from<LANES>> for $to<LANES>
527+
impl<const LANES: usize> From<Mask<$from, LANES>> for Mask<$to, LANES>
528528
where
529-
crate::LaneCount<LANES>: crate::SupportedLaneCount,
529+
LaneCount<LANES>: SupportedLaneCount,
530530
{
531-
fn from(value: $from<LANES>) -> Self {
531+
fn from(value: Mask<$from, LANES>) -> Self {
532532
Self(value.0.convert())
533533
}
534534
}
535535
)*
536536
}
537537
}
538-
impl_from! { Mask8 (SimdI8) => Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize) }
539-
impl_from! { Mask16 (SimdI16) => Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8) }
540-
impl_from! { Mask32 (SimdI32) => Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16) }
541-
impl_from! { Mask64 (SimdI64) => MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32) }
542-
impl_from! { MaskSize (SimdIsize) => Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64) }
538+
impl_from! { i8 => i16, i32, i64, isize }
539+
impl_from! { i16 => i32, i64, isize, i8 }
540+
impl_from! { i32 => i64, isize, i8, i16 }
541+
impl_from! { i64 => isize, i8, i16, i32 }
542+
impl_from! { isize => i8, i16, i32, i64 }

crates/core_simd/src/masks/full_masks.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ where
158158
))
159159
}
160160
}
161+
162+
#[inline]
163+
pub fn any(self) -> bool {
164+
unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
165+
}
166+
167+
#[inline]
168+
pub fn all(self) -> bool {
169+
unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
170+
}
161171
}
162172

163173
impl<Element, const LANES: usize> core::convert::From<Mask<Element, LANES>> for Simd<Element, LANES>
@@ -217,5 +227,3 @@ where
217227
Self::splat(true) ^ self
218228
}
219229
}
220-
221-
impl_full_mask_reductions! {}

crates/core_simd/src/math.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
use crate::{LaneCount, Simd, SupportedLaneCount};
2+
13
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 {
46

57
/// Lanewise saturating add.
68
///
79
/// # Examples
810
/// ```
911
/// # #![feature(portable_simd)]
1012
/// # 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);
1416
/// let unsat = x + max;
1517
/// let sat = x.saturating_add(max);
1618
/// assert_eq!(x - 1, unsat);
@@ -27,13 +29,13 @@ macro_rules! impl_uint_arith {
2729
/// ```
2830
/// # #![feature(portable_simd)]
2931
/// # 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);
3335
/// let unsat = x - max;
3436
/// let sat = x.saturating_sub(max);
3537
/// assert_eq!(unsat, x + 1);
36-
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::splat(0));")]
38+
/// assert_eq!(sat, Simd::splat(0));
3739
#[inline]
3840
pub fn saturating_sub(self, second: Self) -> Self {
3941
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
@@ -43,22 +45,22 @@ macro_rules! impl_uint_arith {
4345
}
4446

4547
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 {
4850

4951
/// Lanewise saturating add.
5052
///
5153
/// # Examples
5254
/// ```
5355
/// # #![feature(portable_simd)]
5456
/// # 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);
5860
/// let unsat = x + max;
5961
/// 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]));
6264
/// ```
6365
#[inline]
6466
pub fn saturating_add(self, second: Self) -> Self {
@@ -71,13 +73,13 @@ macro_rules! impl_int_arith {
7173
/// ```
7274
/// # #![feature(portable_simd)]
7375
/// # 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);
7779
/// let unsat = x - max;
7880
/// 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]));
8183
#[inline]
8284
pub fn saturating_sub(self, second: Self) -> Self {
8385
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
@@ -90,13 +92,13 @@ macro_rules! impl_int_arith {
9092
/// ```
9193
/// # #![feature(portable_simd)]
9294
/// # 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]));
9698
/// ```
9799
#[inline]
98100
pub fn abs(self) -> Self {
99-
const SHR: $n = <$n>::BITS as $n - 1;
101+
const SHR: $ty = <$ty>::BITS as $ty - 1;
100102
let m = self >> SHR;
101103
(self^m) - m
102104
}
@@ -108,17 +110,17 @@ macro_rules! impl_int_arith {
108110
/// ```
109111
/// # #![feature(portable_simd)]
110112
/// # 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]);
113115
/// let unsat = xs.abs();
114116
/// 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]));
117119
/// ```
118120
#[inline]
119121
pub fn saturating_abs(self) -> Self {
120122
// 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;
122124
let m = self >> SHR;
123125
(self^m).saturating_sub(m)
124126
}
@@ -130,12 +132,12 @@ macro_rules! impl_int_arith {
130132
/// ```
131133
/// # #![feature(portable_simd)]
132134
/// # 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]);
135137
/// let unsat = -x;
136138
/// 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]));
139141
/// ```
140142
#[inline]
141143
pub fn saturating_neg(self) -> Self {
@@ -145,7 +147,5 @@ macro_rules! impl_int_arith {
145147
}
146148
}
147149

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 }

crates/core_simd/src/reduction.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use crate::{LaneCount, Simd, SupportedLaneCount};
2+
13
macro_rules! impl_integer_reductions {
2-
{ $name:ident, $scalar:ty } => {
3-
impl<const LANES: usize> crate::$name<LANES>
4+
{ $scalar:ty } => {
5+
impl<const LANES: usize> Simd<$scalar, LANES>
46
where
5-
crate::LaneCount<LANES>: crate::SupportedLaneCount,
7+
LaneCount<LANES>: SupportedLaneCount,
68
{
79
/// Horizontal wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
810
#[inline]
@@ -52,11 +54,22 @@ macro_rules! impl_integer_reductions {
5254
}
5355
}
5456

57+
impl_integer_reductions! { i8 }
58+
impl_integer_reductions! { i16 }
59+
impl_integer_reductions! { i32 }
60+
impl_integer_reductions! { i64 }
61+
impl_integer_reductions! { isize }
62+
impl_integer_reductions! { u8 }
63+
impl_integer_reductions! { u16 }
64+
impl_integer_reductions! { u32 }
65+
impl_integer_reductions! { u64 }
66+
impl_integer_reductions! { usize }
67+
5568
macro_rules! impl_float_reductions {
56-
{ $name:ident, $scalar:ty } => {
57-
impl<const LANES: usize> crate::$name<LANES>
69+
{ $scalar:ty } => {
70+
impl<const LANES: usize> Simd<$scalar, LANES>
5871
where
59-
crate::LaneCount<LANES>: crate::SupportedLaneCount,
72+
LaneCount<LANES>: SupportedLaneCount,
6073
{
6174

6275
/// Horizontal add. Returns the sum of the lanes of the vector.
@@ -102,22 +115,5 @@ macro_rules! impl_float_reductions {
102115
}
103116
}
104117

105-
macro_rules! impl_full_mask_reductions {
106-
{} => {
107-
impl<Element, const LANES: usize> Mask<Element, LANES>
108-
where
109-
Element: MaskElement,
110-
LaneCount<LANES>: SupportedLaneCount,
111-
{
112-
#[inline]
113-
pub fn any(self) -> bool {
114-
unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
115-
}
116-
117-
#[inline]
118-
pub fn all(self) -> bool {
119-
unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
120-
}
121-
}
122-
}
123-
}
118+
impl_float_reductions! { f32 }
119+
impl_float_reductions! { f64 }

0 commit comments

Comments
 (0)