Skip to content

Commit cbca211

Browse files
Merge pull request rust-lang#67 from rust-lang/limit-lanes
Limit all types to 64 lanes
2 parents 8aa7ba7 + faae170 commit cbca211

23 files changed

+519
-151
lines changed

crates/core_simd/src/fmt.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ macro_rules! impl_fmt_trait {
3333
{ $($type:ident => $(($trait:ident, $format:ident)),*;)* } => {
3434
$( // repeat type
3535
$( // repeat trait
36-
impl<const LANES: usize> core::fmt::$trait for crate::$type<LANES> {
36+
impl<const LANES: usize> core::fmt::$trait for crate::$type<LANES>
37+
where
38+
Self: crate::LanesAtMost64,
39+
{
3740
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
3841
$format(self.as_ref(), f)
3942
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// Implemented for bitmask sizes that are supported by the implementation.
2+
pub trait LanesAtMost64 {}
3+
4+
macro_rules! impl_for {
5+
{ $name:ident } => {
6+
impl LanesAtMost64 for $name<1> {}
7+
impl LanesAtMost64 for $name<2> {}
8+
impl LanesAtMost64 for $name<4> {}
9+
impl LanesAtMost64 for $name<8> {}
10+
impl LanesAtMost64 for $name<16> {}
11+
impl LanesAtMost64 for $name<32> {}
12+
impl LanesAtMost64 for $name<64> {}
13+
}
14+
}
15+
16+
use crate::*;
17+
18+
impl_for! { SimdU8 }
19+
impl_for! { SimdU16 }
20+
impl_for! { SimdU32 }
21+
impl_for! { SimdU64 }
22+
impl_for! { SimdU128 }
23+
impl_for! { SimdUsize }
24+
25+
impl_for! { SimdI8 }
26+
impl_for! { SimdI16 }
27+
impl_for! { SimdI32 }
28+
impl_for! { SimdI64 }
29+
impl_for! { SimdI128 }
30+
impl_for! { SimdIsize }
31+
32+
impl_for! { SimdF32 }
33+
impl_for! { SimdF64 }
34+
35+
impl_for! { BitMask }

crates/core_simd/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ mod intrinsics;
1414
mod ops;
1515
mod round;
1616

17+
mod lanes_at_most_64;
18+
pub use lanes_at_most_64::LanesAtMost64;
19+
1720
mod masks;
1821
pub use masks::*;
1922

crates/core_simd/src/macros.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro_rules! from_transmute_x86 {
2929
/// Implements common traits on the specified vector `$name`, holding multiple `$lanes` of `$type`.
3030
macro_rules! impl_vector {
3131
{ $name:ident, $type:ty } => {
32-
impl<const LANES: usize> $name<LANES> {
32+
impl<const LANES: usize> $name<LANES> where Self: crate::LanesAtMost64 {
3333
/// Construct a SIMD vector by setting all lanes to the given value.
3434
pub const fn splat(value: $type) -> Self {
3535
Self([value; LANES])
@@ -72,31 +72,31 @@ macro_rules! impl_vector {
7272
}
7373
}
7474

75-
impl<const LANES: usize> Copy for $name<LANES> {}
75+
impl<const LANES: usize> Copy for $name<LANES> where Self: crate::LanesAtMost64 {}
7676

77-
impl<const LANES: usize> Clone for $name<LANES> {
77+
impl<const LANES: usize> Clone for $name<LANES> where Self: crate::LanesAtMost64 {
7878
#[inline]
7979
fn clone(&self) -> Self {
8080
*self
8181
}
8282
}
8383

84-
impl<const LANES: usize> Default for $name<LANES> {
84+
impl<const LANES: usize> Default for $name<LANES> where Self: crate::LanesAtMost64 {
8585
#[inline]
8686
fn default() -> Self {
8787
Self::splat(<$type>::default())
8888
}
8989
}
9090

91-
impl<const LANES: usize> PartialEq for $name<LANES> {
91+
impl<const LANES: usize> PartialEq for $name<LANES> where Self: crate::LanesAtMost64 {
9292
#[inline]
9393
fn eq(&self, other: &Self) -> bool {
9494
// TODO use SIMD equality
9595
self.to_array() == other.to_array()
9696
}
9797
}
9898

99-
impl<const LANES: usize> PartialOrd for $name<LANES> {
99+
impl<const LANES: usize> PartialOrd for $name<LANES> where Self: crate::LanesAtMost64 {
100100
#[inline]
101101
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
102102
// TODO use SIMD equalitya
@@ -105,44 +105,44 @@ macro_rules! impl_vector {
105105
}
106106

107107
// array references
108-
impl<const LANES: usize> AsRef<[$type; LANES]> for $name<LANES> {
108+
impl<const LANES: usize> AsRef<[$type; LANES]> for $name<LANES> where Self: crate::LanesAtMost64 {
109109
#[inline]
110110
fn as_ref(&self) -> &[$type; LANES] {
111111
&self.0
112112
}
113113
}
114114

115-
impl<const LANES: usize> AsMut<[$type; LANES]> for $name<LANES> {
115+
impl<const LANES: usize> AsMut<[$type; LANES]> for $name<LANES> where Self: crate::LanesAtMost64 {
116116
#[inline]
117117
fn as_mut(&mut self) -> &mut [$type; LANES] {
118118
&mut self.0
119119
}
120120
}
121121

122122
// slice references
123-
impl<const LANES: usize> AsRef<[$type]> for $name<LANES> {
123+
impl<const LANES: usize> AsRef<[$type]> for $name<LANES> where Self: crate::LanesAtMost64 {
124124
#[inline]
125125
fn as_ref(&self) -> &[$type] {
126126
&self.0
127127
}
128128
}
129129

130-
impl<const LANES: usize> AsMut<[$type]> for $name<LANES> {
130+
impl<const LANES: usize> AsMut<[$type]> for $name<LANES> where Self: crate::LanesAtMost64 {
131131
#[inline]
132132
fn as_mut(&mut self) -> &mut [$type] {
133133
&mut self.0
134134
}
135135
}
136136

137137
// vector/array conversion
138-
impl<const LANES: usize> From<[$type; LANES]> for $name<LANES> {
138+
impl<const LANES: usize> From<[$type; LANES]> for $name<LANES> where Self: crate::LanesAtMost64 {
139139
fn from(array: [$type; LANES]) -> Self {
140140
Self(array)
141141
}
142142
}
143143

144144
// splat
145-
impl<const LANES: usize> From<$type> for $name<LANES> {
145+
impl<const LANES: usize> From<$type> for $name<LANES> where Self: crate::LanesAtMost64 {
146146
#[inline]
147147
fn from(value: $type) -> Self {
148148
Self::splat(value)
@@ -158,17 +158,17 @@ macro_rules! impl_integer_vector {
158158
{ $name:ident, $type:ty } => {
159159
impl_vector! { $name, $type }
160160

161-
impl<const LANES: usize> Eq for $name<LANES> {}
161+
impl<const LANES: usize> Eq for $name<LANES> where Self: crate::LanesAtMost64 {}
162162

163-
impl<const LANES: usize> Ord for $name<LANES> {
163+
impl<const LANES: usize> Ord for $name<LANES> where Self: crate::LanesAtMost64 {
164164
#[inline]
165165
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
166166
// TODO use SIMD cmp
167167
self.to_array().cmp(other.as_ref())
168168
}
169169
}
170170

171-
impl<const LANES: usize> core::hash::Hash for $name<LANES> {
171+
impl<const LANES: usize> core::hash::Hash for $name<LANES> where Self: crate::LanesAtMost64 {
172172
#[inline]
173173
fn hash<H>(&self, state: &mut H)
174174
where
@@ -187,7 +187,11 @@ macro_rules! impl_float_vector {
187187
{ $name:ident, $type:ty, $bits_ty:ident } => {
188188
impl_vector! { $name, $type }
189189

190-
impl<const LANES: usize> $name<LANES> {
190+
impl<const LANES: usize> $name<LANES>
191+
where
192+
Self: crate::LanesAtMost64,
193+
crate::$bits_ty<LANES>: crate::LanesAtMost64,
194+
{
191195
/// Raw transmutation to an unsigned integer vector type with the
192196
/// same size and number of lanes.
193197
#[inline]

crates/core_simd/src/masks/bitmask.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
/// Implemented for bitmask sizes that are supported by the implementation.
2-
pub trait LanesAtMost64 {}
3-
impl LanesAtMost64 for BitMask<1> {}
4-
impl LanesAtMost64 for BitMask<2> {}
5-
impl LanesAtMost64 for BitMask<4> {}
6-
impl LanesAtMost64 for BitMask<8> {}
7-
impl LanesAtMost64 for BitMask<16> {}
8-
impl LanesAtMost64 for BitMask<32> {}
9-
impl LanesAtMost64 for BitMask<64> {}
1+
use crate::LanesAtMost64;
102

113
/// A mask where each lane is represented by a single bit.
124
#[derive(Copy, Clone, Debug)]

0 commit comments

Comments
 (0)