Skip to content

Commit 7c80b69

Browse files
Merge pull request #311 from rust-lang/alias
Specify aliases in one place, and make it more uniform which are defined
2 parents aad8f0a + 402b50a commit 7c80b69

File tree

7 files changed

+229
-284
lines changed

7 files changed

+229
-284
lines changed

crates/core_simd/src/alias.rs

+227
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
macro_rules! number {
2+
{ 1 } => { "one" };
3+
{ 2 } => { "two" };
4+
{ 4 } => { "four" };
5+
{ 8 } => { "eight" };
6+
{ $x:literal } => { stringify!($x) };
7+
}
8+
9+
macro_rules! plural {
10+
{ 1 } => { "" };
11+
{ $x:literal } => { "s" };
12+
}
13+
14+
macro_rules! alias {
15+
{
16+
$(
17+
$element_ty:ty = {
18+
$($alias:ident $num_elements:tt)*
19+
}
20+
)*
21+
} => {
22+
$(
23+
$(
24+
#[doc = concat!("A SIMD vector with ", number!($num_elements), " element", plural!($num_elements), " of type [`", stringify!($element_ty), "`].")]
25+
#[allow(non_camel_case_types)]
26+
pub type $alias = $crate::simd::Simd<$element_ty, $num_elements>;
27+
)*
28+
)*
29+
}
30+
}
31+
32+
macro_rules! mask_alias {
33+
{
34+
$(
35+
$element_ty:ty : $size:literal = {
36+
$($alias:ident $num_elements:tt)*
37+
}
38+
)*
39+
} => {
40+
$(
41+
$(
42+
#[doc = concat!("A SIMD mask with ", number!($num_elements), " element", plural!($num_elements), " for vectors with ", $size, " element types.")]
43+
///
44+
#[doc = concat!(
45+
"The layout of this type is unspecified, and may change between platforms and/or Rust versions, and code should not assume that it is equivalent to `[",
46+
stringify!($element_ty), "; ", $num_elements, "]`."
47+
)]
48+
#[allow(non_camel_case_types)]
49+
pub type $alias = $crate::simd::Mask<$element_ty, $num_elements>;
50+
)*
51+
)*
52+
}
53+
}
54+
55+
alias! {
56+
i8 = {
57+
i8x1 1
58+
i8x2 2
59+
i8x4 4
60+
i8x8 8
61+
i8x16 16
62+
i8x32 32
63+
i8x64 64
64+
}
65+
66+
i16 = {
67+
i16x1 1
68+
i16x2 2
69+
i16x4 4
70+
i16x8 8
71+
i16x16 16
72+
i16x32 32
73+
i16x64 64
74+
}
75+
76+
i32 = {
77+
i32x1 1
78+
i32x2 2
79+
i32x4 4
80+
i32x8 8
81+
i32x16 16
82+
i32x32 32
83+
i32x64 64
84+
}
85+
86+
i64 = {
87+
i64x1 1
88+
i64x2 2
89+
i64x4 4
90+
i64x8 8
91+
i64x16 16
92+
i64x32 32
93+
i64x64 64
94+
}
95+
96+
isize = {
97+
isizex1 1
98+
isizex2 2
99+
isizex4 4
100+
isizex8 8
101+
isizex16 16
102+
isizex32 32
103+
isizex64 64
104+
}
105+
106+
u8 = {
107+
u8x1 1
108+
u8x2 2
109+
u8x4 4
110+
u8x8 8
111+
u8x16 16
112+
u8x32 32
113+
u8x64 64
114+
}
115+
116+
u16 = {
117+
u16x1 1
118+
u16x2 2
119+
u16x4 4
120+
u16x8 8
121+
u16x16 16
122+
u16x32 32
123+
u16x64 64
124+
}
125+
126+
u32 = {
127+
u32x1 1
128+
u32x2 2
129+
u32x4 4
130+
u32x8 8
131+
u32x16 16
132+
u32x32 32
133+
u32x64 64
134+
}
135+
136+
u64 = {
137+
u64x1 1
138+
u64x2 2
139+
u64x4 4
140+
u64x8 8
141+
u64x16 16
142+
u64x32 32
143+
u64x64 64
144+
}
145+
146+
usize = {
147+
usizex1 1
148+
usizex2 2
149+
usizex4 4
150+
usizex8 8
151+
usizex16 16
152+
usizex32 32
153+
usizex64 64
154+
}
155+
156+
f32 = {
157+
f32x1 1
158+
f32x2 2
159+
f32x4 4
160+
f32x8 8
161+
f32x16 16
162+
f32x32 32
163+
f32x64 64
164+
}
165+
166+
f64 = {
167+
f64x1 1
168+
f64x2 2
169+
f64x4 4
170+
f64x8 8
171+
f64x16 16
172+
f64x32 32
173+
f64x64 64
174+
}
175+
}
176+
177+
mask_alias! {
178+
i8 : "8-bit" = {
179+
mask8x1 1
180+
mask8x2 2
181+
mask8x4 4
182+
mask8x8 8
183+
mask8x16 16
184+
mask8x32 32
185+
mask8x64 64
186+
}
187+
188+
i16 : "16-bit" = {
189+
mask16x1 1
190+
mask16x2 2
191+
mask16x4 4
192+
mask16x8 8
193+
mask16x16 16
194+
mask16x32 32
195+
mask16x64 64
196+
}
197+
198+
i32 : "32-bit" = {
199+
mask32x1 1
200+
mask32x2 2
201+
mask32x4 4
202+
mask32x8 8
203+
mask32x16 16
204+
mask32x32 32
205+
mask32x64 64
206+
}
207+
208+
i64 : "64-bit" = {
209+
mask64x1 1
210+
mask64x2 2
211+
mask64x4 4
212+
mask64x8 8
213+
mask64x16 16
214+
mask64x32 32
215+
mask64x64 64
216+
}
217+
218+
isize : "pointer-sized" = {
219+
masksizex1 1
220+
masksizex2 2
221+
masksizex4 4
222+
masksizex8 8
223+
masksizex16 16
224+
masksizex32 32
225+
masksizex64 64
226+
}
227+
}

crates/core_simd/src/masks.rs

-126
Original file line numberDiff line numberDiff line change
@@ -530,132 +530,6 @@ where
530530
}
531531
}
532532

533-
/// A mask for SIMD vectors with eight elements of 8 bits.
534-
///
535-
/// The layout of this type is unspecified, and may change between platforms
536-
/// and/or Rust versions, and code should not assume that it is equivalent to
537-
/// `[i8; 8]`.
538-
pub type mask8x8 = Mask<i8, 8>;
539-
540-
/// A mask for SIMD vectors with 16 elements of 8 bits.
541-
///
542-
/// The layout of this type is unspecified, and may change between platforms
543-
/// and/or Rust versions, and code should not assume that it is equivalent to
544-
/// `[i8; 16]`.
545-
pub type mask8x16 = Mask<i8, 16>;
546-
547-
/// A mask for SIMD vectors with 32 elements of 8 bits.
548-
///
549-
/// The layout of this type is unspecified, and may change between platforms
550-
/// and/or Rust versions, and code should not assume that it is equivalent to
551-
/// `[i8; 32]`.
552-
pub type mask8x32 = Mask<i8, 32>;
553-
554-
/// A mask for SIMD vectors with 64 elements of 8 bits.
555-
///
556-
/// The layout of this type is unspecified, and may change between platforms
557-
/// and/or Rust versions, and code should not assume that it is equivalent to
558-
/// `[i8; 64]`.
559-
pub type mask8x64 = Mask<i8, 64>;
560-
561-
/// A mask for SIMD vectors with four elements of 16 bits.
562-
///
563-
/// The layout of this type is unspecified, and may change between platforms
564-
/// and/or Rust versions, and code should not assume that it is equivalent to
565-
/// `[i16; 4]`.
566-
pub type mask16x4 = Mask<i16, 4>;
567-
568-
/// A mask for SIMD vectors with eight elements of 16 bits.
569-
///
570-
/// The layout of this type is unspecified, and may change between platforms
571-
/// and/or Rust versions, and code should not assume that it is equivalent to
572-
/// `[i16; 8]`.
573-
pub type mask16x8 = Mask<i16, 8>;
574-
575-
/// A mask for SIMD vectors with 16 elements of 16 bits.
576-
///
577-
/// The layout of this type is unspecified, and may change between platforms
578-
/// and/or Rust versions, and code should not assume that it is equivalent to
579-
/// `[i16; 16]`.
580-
pub type mask16x16 = Mask<i16, 16>;
581-
582-
/// A mask for SIMD vectors with 32 elements of 16 bits.
583-
///
584-
/// The layout of this type is unspecified, and may change between platforms
585-
/// and/or Rust versions, and code should not assume that it is equivalent to
586-
/// `[i16; 32]`.
587-
pub type mask16x32 = Mask<i16, 32>;
588-
589-
/// A mask for SIMD vectors with two elements of 32 bits.
590-
///
591-
/// The layout of this type is unspecified, and may change between platforms
592-
/// and/or Rust versions, and code should not assume that it is equivalent to
593-
/// `[i32; 2]`.
594-
pub type mask32x2 = Mask<i32, 2>;
595-
596-
/// A mask for SIMD vectors with four elements of 32 bits.
597-
///
598-
/// The layout of this type is unspecified, and may change between platforms
599-
/// and/or Rust versions, and code should not assume that it is equivalent to
600-
/// `[i32; 4]`.
601-
pub type mask32x4 = Mask<i32, 4>;
602-
603-
/// A mask for SIMD vectors with eight elements of 32 bits.
604-
///
605-
/// The layout of this type is unspecified, and may change between platforms
606-
/// and/or Rust versions, and code should not assume that it is equivalent to
607-
/// `[i32; 8]`.
608-
pub type mask32x8 = Mask<i32, 8>;
609-
610-
/// A mask for SIMD vectors with 16 elements of 32 bits.
611-
///
612-
/// The layout of this type is unspecified, and may change between platforms
613-
/// and/or Rust versions, and code should not assume that it is equivalent to
614-
/// `[i32; 16]`.
615-
pub type mask32x16 = Mask<i32, 16>;
616-
617-
/// A mask for SIMD vectors with two elements of 64 bits.
618-
///
619-
/// The layout of this type is unspecified, and may change between platforms
620-
/// and/or Rust versions, and code should not assume that it is equivalent to
621-
/// `[i64; 2]`.
622-
pub type mask64x2 = Mask<i64, 2>;
623-
624-
/// A mask for SIMD vectors with four elements of 64 bits.
625-
///
626-
/// The layout of this type is unspecified, and may change between platforms
627-
/// and/or Rust versions, and code should not assume that it is equivalent to
628-
/// `[i64; 4]`.
629-
pub type mask64x4 = Mask<i64, 4>;
630-
631-
/// A mask for SIMD vectors with eight elements of 64 bits.
632-
///
633-
/// The layout of this type is unspecified, and may change between platforms
634-
/// and/or Rust versions, and code should not assume that it is equivalent to
635-
/// `[i64; 8]`.
636-
pub type mask64x8 = Mask<i64, 8>;
637-
638-
/// A mask for SIMD vectors with two elements of pointer width.
639-
///
640-
/// The layout of this type is unspecified, and may change between platforms
641-
/// and/or Rust versions, and code should not assume that it is equivalent to
642-
/// `[isize; 2]`.
643-
pub type masksizex2 = Mask<isize, 2>;
644-
645-
/// A mask for SIMD vectors with four elements of pointer width.
646-
///
647-
/// The layout of this type is unspecified, and may change between platforms
648-
/// and/or Rust versions, and code should not assume that it is equivalent to
649-
/// `[isize; 4]`.
650-
pub type masksizex4 = Mask<isize, 4>;
651-
652-
/// A mask for SIMD vectors with eight elements of pointer width.
653-
///
654-
/// The layout of this type is unspecified, and may change between platforms
655-
/// and/or Rust versions, and code should not assume that it is equivalent to
656-
/// `[isize; 8]`.
657-
pub type masksizex8 = Mask<isize, 8>;
658-
659533
macro_rules! impl_from {
660534
{ $from:ty => $($to:ty),* } => {
661535
$(

crates/core_simd/src/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod intrinsics;
66
#[cfg(feature = "generic_const_exprs")]
77
mod to_bytes;
88

9+
mod alias;
910
mod elements;
1011
mod eq;
1112
mod fmt;
@@ -22,6 +23,7 @@ mod vendor;
2223
pub mod simd {
2324
pub(crate) use crate::core_simd::intrinsics;
2425

26+
pub use crate::core_simd::alias::*;
2527
pub use crate::core_simd::elements::*;
2628
pub use crate::core_simd::eq::*;
2729
pub use crate::core_simd::lane_count::{LaneCount, SupportedLaneCount};

crates/core_simd/src/vector.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
mod float;
2-
mod int;
3-
mod uint;
4-
5-
pub use float::*;
6-
pub use int::*;
7-
pub use uint::*;
8-
91
// Vectors of pointers are not for public use at the current time.
102
pub(crate) mod ptr;
113

0 commit comments

Comments
 (0)