Skip to content

Commit d6f09aa

Browse files
committed
unify shuffle and shuffle_param macros
1 parent 2d0a751 commit d6f09aa

File tree

8 files changed

+91
-115
lines changed

8 files changed

+91
-115
lines changed

crates/core_arch/src/macros.rs

+38-62
Original file line numberDiff line numberDiff line change
@@ -95,120 +95,96 @@ macro_rules! types {
9595

9696
#[allow(unused_macros)]
9797
macro_rules! simd_shuffle2 {
98+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
99+
struct ConstParam<$(const $imm: $ty),+>;
100+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
101+
const IDX: [u32; 2] = $idx;
102+
}
103+
104+
simd_shuffle2($x, $y, ConstParam::<$($imm),+>::IDX)
105+
}};
98106
($x:expr, $y:expr, $idx:expr $(,)?) => {{
99107
const IDX: [u32; 2] = $idx;
100108
simd_shuffle2($x, $y, IDX)
101109
}};
102110
}
103111

104112
#[allow(unused_macros)]
105-
macro_rules! simd_shuffle2_param {
106-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
107-
struct ConstParam<const $imm: $ty>;
108-
impl<const $imm: $ty> ConstParam<$imm> {
109-
const IDX: [u32; 2] = $idx;
113+
macro_rules! simd_shuffle4 {
114+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
115+
struct ConstParam<$(const $imm: $ty),+>;
116+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
117+
const IDX: [u32; 4] = $idx;
110118
}
111119

112-
simd_shuffle2($x, $y, ConstParam::<$imm>::IDX)
120+
simd_shuffle4($x, $y, ConstParam::<$($imm),+>::IDX)
113121
}};
114-
}
115-
116-
#[allow(unused_macros)]
117-
macro_rules! simd_shuffle4 {
118122
($x:expr, $y:expr, $idx:expr $(,)?) => {{
119123
const IDX: [u32; 4] = $idx;
120124
simd_shuffle4($x, $y, IDX)
121125
}};
122126
}
123127

124128
#[allow(unused_macros)]
125-
macro_rules! simd_shuffle4_param {
126-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
127-
struct ConstParam<const $imm: $ty>;
128-
impl<const $imm: $ty> ConstParam<$imm> {
129-
const IDX: [u32; 4] = $idx;
129+
macro_rules! simd_shuffle8 {
130+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
131+
struct ConstParam<$(const $imm: $ty),+>;
132+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
133+
const IDX: [u32; 8] = $idx;
130134
}
131135

132-
simd_shuffle4($x, $y, ConstParam::<$imm>::IDX)
136+
simd_shuffle8($x, $y, ConstParam::<$($imm),+>::IDX)
133137
}};
134-
}
135-
136-
#[allow(unused_macros)]
137-
macro_rules! simd_shuffle8 {
138138
($x:expr, $y:expr, $idx:expr $(,)?) => {{
139139
const IDX: [u32; 8] = $idx;
140140
simd_shuffle8($x, $y, IDX)
141141
}};
142142
}
143143

144144
#[allow(unused_macros)]
145-
macro_rules! simd_shuffle8_param {
146-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
147-
struct ConstParam<const $imm: $ty>;
148-
impl<const $imm: $ty> ConstParam<$imm> {
149-
const IDX: [u32; 8] = $idx;
145+
macro_rules! simd_shuffle16 {
146+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
147+
struct ConstParam<$(const $imm: $ty),+>;
148+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
149+
const IDX: [u32; 16] = $idx;
150150
}
151151

152-
simd_shuffle8($x, $y, ConstParam::<$imm>::IDX)
152+
simd_shuffle16($x, $y, ConstParam::<$($imm),+>::IDX)
153153
}};
154-
}
155-
156-
#[allow(unused_macros)]
157-
macro_rules! simd_shuffle16 {
158154
($x:expr, $y:expr, $idx:expr $(,)?) => {{
159155
const IDX: [u32; 16] = $idx;
160156
simd_shuffle16($x, $y, IDX)
161157
}};
162158
}
163159

164160
#[allow(unused_macros)]
165-
macro_rules! simd_shuffle16_param {
166-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
167-
struct ConstParam<const $imm: $ty>;
168-
impl<const $imm: $ty> ConstParam<$imm> {
169-
const IDX: [u32; 16] = $idx;
161+
macro_rules! simd_shuffle32 {
162+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
163+
struct ConstParam<$(const $imm: $ty),+>;
164+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
165+
const IDX: [u32; 32] = $idx;
170166
}
171167

172-
simd_shuffle16($x, $y, ConstParam::<$imm>::IDX)
168+
simd_shuffle32($x, $y, ConstParam::<$($imm),+>::IDX)
173169
}};
174-
}
175-
176-
#[allow(unused_macros)]
177-
macro_rules! simd_shuffle32 {
178170
($x:expr, $y:expr, $idx:expr $(,)?) => {{
179171
const IDX: [u32; 32] = $idx;
180172
simd_shuffle32($x, $y, IDX)
181173
}};
182174
}
183175

184176
#[allow(unused_macros)]
185-
macro_rules! simd_shuffle32_param {
186-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
187-
struct ConstParam<const $imm: $ty>;
188-
impl<const $imm: $ty> ConstParam<$imm> {
189-
const IDX: [u32; 32] = $idx;
177+
macro_rules! simd_shuffle64 {
178+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
179+
struct ConstParam<$(const $imm: $ty),+>;
180+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
181+
const IDX: [u32; 64] = $idx;
190182
}
191183

192-
simd_shuffle32($x, $y, ConstParam::<$imm>::IDX)
184+
simd_shuffle64($x, $y, ConstParam::<$($imm),+>::IDX)
193185
}};
194-
}
195-
196-
#[allow(unused_macros)]
197-
macro_rules! simd_shuffle64 {
198186
($x:expr, $y:expr, $idx:expr $(,)?) => {{
199187
const IDX: [u32; 64] = $idx;
200188
simd_shuffle64($x, $y, IDX)
201189
}};
202190
}
203-
204-
#[allow(unused_macros)]
205-
macro_rules! simd_shuffle64_param {
206-
($x:expr, $y:expr, <const $imm:ident : $ty:ty> $idx:expr $(,)?) => {{
207-
struct ConstParam<const $imm: $ty>;
208-
impl<const $imm: $ty> ConstParam<$imm> {
209-
const IDX: [u32; 64] = $idx;
210-
}
211-
212-
simd_shuffle64($x, $y, ConstParam::<$imm>::IDX)
213-
}};
214-
}

crates/core_arch/src/x86/avx.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub unsafe fn _mm256_or_ps(a: __m256, b: __m256) -> __m256 {
118118
#[stable(feature = "simd_x86", since = "1.27.0")]
119119
pub unsafe fn _mm256_shuffle_pd<const MASK: i32>(a: __m256d, b: __m256d) -> __m256d {
120120
static_assert_imm8!(MASK);
121-
simd_shuffle4_param!(
121+
simd_shuffle4!(
122122
a,
123123
b,
124124
<const MASK: i32> [
@@ -141,7 +141,7 @@ pub unsafe fn _mm256_shuffle_pd<const MASK: i32>(a: __m256d, b: __m256d) -> __m2
141141
#[stable(feature = "simd_x86", since = "1.27.0")]
142142
pub unsafe fn _mm256_shuffle_ps<const MASK: i32>(a: __m256, b: __m256) -> __m256 {
143143
static_assert_imm8!(MASK);
144-
simd_shuffle8_param!(
144+
simd_shuffle8!(
145145
a,
146146
b,
147147
<const MASK: i32> [
@@ -463,7 +463,7 @@ pub unsafe fn _mm256_sqrt_pd(a: __m256d) -> __m256d {
463463
#[stable(feature = "simd_x86", since = "1.27.0")]
464464
pub unsafe fn _mm256_blend_pd<const IMM4: i32>(a: __m256d, b: __m256d) -> __m256d {
465465
static_assert_imm4!(IMM4);
466-
simd_shuffle4_param!(
466+
simd_shuffle4!(
467467
a,
468468
b,
469469
<const IMM4: i32> [
@@ -486,7 +486,7 @@ pub unsafe fn _mm256_blend_pd<const IMM4: i32>(a: __m256d, b: __m256d) -> __m256
486486
#[stable(feature = "simd_x86", since = "1.27.0")]
487487
pub unsafe fn _mm256_blend_ps<const IMM8: i32>(a: __m256, b: __m256) -> __m256 {
488488
static_assert_imm8!(IMM8);
489-
simd_shuffle8_param!(
489+
simd_shuffle8!(
490490
a,
491491
b,
492492
<const IMM8: i32> [
@@ -930,7 +930,7 @@ pub unsafe fn _mm256_cvttps_epi32(a: __m256) -> __m256i {
930930
#[stable(feature = "simd_x86", since = "1.27.0")]
931931
pub unsafe fn _mm256_extractf128_ps<const IMM1: i32>(a: __m256) -> __m128 {
932932
static_assert_imm1!(IMM1);
933-
simd_shuffle4_param!(
933+
simd_shuffle4!(
934934
a,
935935
_mm256_undefined_ps(),
936936
<const IMM1: i32> [[0, 1, 2, 3], [4, 5, 6, 7]][IMM1 as usize],
@@ -951,7 +951,7 @@ pub unsafe fn _mm256_extractf128_ps<const IMM1: i32>(a: __m256) -> __m128 {
951951
#[stable(feature = "simd_x86", since = "1.27.0")]
952952
pub unsafe fn _mm256_extractf128_pd<const IMM1: i32>(a: __m256d) -> __m128d {
953953
static_assert_imm1!(IMM1);
954-
simd_shuffle2_param!(a, _mm256_undefined_pd(), <const IMM1: i32> [[0, 1], [2, 3]][IMM1 as usize])
954+
simd_shuffle2!(a, _mm256_undefined_pd(), <const IMM1: i32> [[0, 1], [2, 3]][IMM1 as usize])
955955
}
956956

957957
/// Extracts 128 bits (composed of integer data) from `a`, selected with `imm8`.
@@ -967,7 +967,7 @@ pub unsafe fn _mm256_extractf128_pd<const IMM1: i32>(a: __m256d) -> __m128d {
967967
#[stable(feature = "simd_x86", since = "1.27.0")]
968968
pub unsafe fn _mm256_extractf128_si256<const IMM1: i32>(a: __m256i) -> __m128i {
969969
static_assert_imm1!(IMM1);
970-
let dst: i64x2 = simd_shuffle2_param!(
970+
let dst: i64x2 = simd_shuffle2!(
971971
a.as_i64x4(),
972972
_mm256_undefined_si256().as_i64x4(),
973973
<const IMM1: i32> [[0, 1], [2, 3]][IMM1 as usize],
@@ -1033,7 +1033,7 @@ pub unsafe fn _mm_permutevar_ps(a: __m128, b: __m128i) -> __m128 {
10331033
#[stable(feature = "simd_x86", since = "1.27.0")]
10341034
pub unsafe fn _mm256_permute_ps<const IMM8: i32>(a: __m256) -> __m256 {
10351035
static_assert_imm8!(IMM8);
1036-
simd_shuffle8_param!(
1036+
simd_shuffle8!(
10371037
a,
10381038
_mm256_undefined_ps(),
10391039
<const IMM8: i32> [
@@ -1060,7 +1060,7 @@ pub unsafe fn _mm256_permute_ps<const IMM8: i32>(a: __m256) -> __m256 {
10601060
#[stable(feature = "simd_x86", since = "1.27.0")]
10611061
pub unsafe fn _mm_permute_ps<const IMM8: i32>(a: __m128) -> __m128 {
10621062
static_assert_imm8!(IMM8);
1063-
simd_shuffle4_param!(
1063+
simd_shuffle4!(
10641064
a,
10651065
_mm_undefined_ps(),
10661066
<const IMM8: i32> [
@@ -1107,7 +1107,7 @@ pub unsafe fn _mm_permutevar_pd(a: __m128d, b: __m128i) -> __m128d {
11071107
#[stable(feature = "simd_x86", since = "1.27.0")]
11081108
pub unsafe fn _mm256_permute_pd<const IMM4: i32>(a: __m256d) -> __m256d {
11091109
static_assert_imm4!(IMM4);
1110-
simd_shuffle4_param!(
1110+
simd_shuffle4!(
11111111
a,
11121112
_mm256_undefined_pd(),
11131113
<const IMM4: i32> [
@@ -1130,7 +1130,7 @@ pub unsafe fn _mm256_permute_pd<const IMM4: i32>(a: __m256d) -> __m256d {
11301130
#[stable(feature = "simd_x86", since = "1.27.0")]
11311131
pub unsafe fn _mm_permute_pd<const IMM2: i32>(a: __m128d) -> __m128d {
11321132
static_assert_imm2!(IMM2);
1133-
simd_shuffle2_param!(
1133+
simd_shuffle2!(
11341134
a,
11351135
_mm_undefined_pd(),
11361136
<const IMM2: i32> [(IMM2 as u32) & 1, (IMM2 as u32 >> 1) & 1],
@@ -1257,7 +1257,7 @@ pub unsafe fn _mm256_broadcast_pd(a: &__m128d) -> __m256d {
12571257
#[stable(feature = "simd_x86", since = "1.27.0")]
12581258
pub unsafe fn _mm256_insertf128_ps<const IMM1: i32>(a: __m256, b: __m128) -> __m256 {
12591259
static_assert_imm1!(IMM1);
1260-
simd_shuffle8_param!(
1260+
simd_shuffle8!(
12611261
a,
12621262
_mm256_castps128_ps256(b),
12631263
<const IMM1: i32> [[8, 9, 10, 11, 4, 5, 6, 7], [0, 1, 2, 3, 8, 9, 10, 11]][IMM1 as usize],
@@ -1279,7 +1279,7 @@ pub unsafe fn _mm256_insertf128_ps<const IMM1: i32>(a: __m256, b: __m128) -> __m
12791279
#[stable(feature = "simd_x86", since = "1.27.0")]
12801280
pub unsafe fn _mm256_insertf128_pd<const IMM1: i32>(a: __m256d, b: __m128d) -> __m256d {
12811281
static_assert_imm1!(IMM1);
1282-
simd_shuffle4_param!(
1282+
simd_shuffle4!(
12831283
a,
12841284
_mm256_castpd128_pd256(b),
12851285
<const IMM1: i32> [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize],
@@ -1300,7 +1300,7 @@ pub unsafe fn _mm256_insertf128_pd<const IMM1: i32>(a: __m256d, b: __m128d) -> _
13001300
#[stable(feature = "simd_x86", since = "1.27.0")]
13011301
pub unsafe fn _mm256_insertf128_si256<const IMM1: i32>(a: __m256i, b: __m128i) -> __m256i {
13021302
static_assert_imm1!(IMM1);
1303-
let dst: i64x4 = simd_shuffle4_param!(
1303+
let dst: i64x4 = simd_shuffle4!(
13041304
a.as_i64x4(),
13051305
_mm256_castsi128_si256(b).as_i64x4(),
13061306
<const IMM1: i32> [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize],

crates/core_arch/src/x86/avx2.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub unsafe fn _mm_blend_epi32<const IMM4: i32>(a: __m128i, b: __m128i) -> __m128
370370
static_assert_imm4!(IMM4);
371371
let a = a.as_i32x4();
372372
let b = b.as_i32x4();
373-
let r: i32x4 = simd_shuffle4_param!(
373+
let r: i32x4 = simd_shuffle4!(
374374
a,
375375
b,
376376
<const IMM4: i32> [
@@ -395,7 +395,7 @@ pub unsafe fn _mm256_blend_epi32<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
395395
static_assert_imm8!(IMM8);
396396
let a = a.as_i32x8();
397397
let b = b.as_i32x8();
398-
let r: i32x8 = simd_shuffle8_param!(
398+
let r: i32x8 = simd_shuffle8!(
399399
a,
400400
b,
401401
<const IMM8: i32> [
@@ -425,7 +425,7 @@ pub unsafe fn _mm256_blend_epi16<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
425425
let a = a.as_i16x16();
426426
let b = b.as_i16x16();
427427

428-
let r: i16x16 = simd_shuffle16_param!(
428+
let r: i16x16 = simd_shuffle16!(
429429
a,
430430
b,
431431
<const IMM8: i32> [
@@ -890,7 +890,7 @@ pub unsafe fn _mm256_extracti128_si256<const IMM1: i32>(a: __m256i) -> __m128i {
890890
static_assert_imm1!(IMM1);
891891
let a = a.as_i64x4();
892892
let b = _mm256_undefined_si256().as_i64x4();
893-
let dst: i64x2 = simd_shuffle2_param!(a, b, <const IMM1: i32> [[0, 1], [2, 3]][IMM1 as usize]);
893+
let dst: i64x2 = simd_shuffle2!(a, b, <const IMM1: i32> [[0, 1], [2, 3]][IMM1 as usize]);
894894
transmute(dst)
895895
}
896896

@@ -1713,7 +1713,7 @@ pub unsafe fn _mm256_inserti128_si256<const IMM1: i32>(a: __m256i, b: __m128i) -
17131713
let a = a.as_i64x4();
17141714
let b = _mm256_castsi128_si256(b).as_i64x4();
17151715
let dst: i64x4 =
1716-
simd_shuffle4_param!(a, b, <const IMM1: i32> [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize]);
1716+
simd_shuffle4!(a, b, <const IMM1: i32> [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize]);
17171717
transmute(dst)
17181718
}
17191719

@@ -2202,7 +2202,7 @@ pub unsafe fn _mm256_permutevar8x32_epi32(a: __m256i, b: __m256i) -> __m256i {
22022202
pub unsafe fn _mm256_permute4x64_epi64<const IMM8: i32>(a: __m256i) -> __m256i {
22032203
static_assert_imm8!(IMM8);
22042204
let zero = _mm256_setzero_si256().as_i64x4();
2205-
let r: i64x4 = simd_shuffle4_param!(
2205+
let r: i64x4 = simd_shuffle4!(
22062206
a.as_i64x4(),
22072207
zero,
22082208
<const IMM8: i32> [
@@ -2239,7 +2239,7 @@ pub unsafe fn _mm256_permute2x128_si256<const IMM8: i32>(a: __m256i, b: __m256i)
22392239
#[stable(feature = "simd_x86", since = "1.27.0")]
22402240
pub unsafe fn _mm256_permute4x64_pd<const IMM8: i32>(a: __m256d) -> __m256d {
22412241
static_assert_imm8!(IMM8);
2242-
simd_shuffle4_param!(
2242+
simd_shuffle4!(
22432243
a,
22442244
_mm256_undefined_pd(),
22452245
<const IMM8: i32> [
@@ -2352,7 +2352,7 @@ pub unsafe fn _mm256_shuffle_epi8(a: __m256i, b: __m256i) -> __m256i {
23522352
#[stable(feature = "simd_x86", since = "1.27.0")]
23532353
pub unsafe fn _mm256_shuffle_epi32<const MASK: i32>(a: __m256i) -> __m256i {
23542354
static_assert_imm8!(MASK);
2355-
let r: i32x8 = simd_shuffle8_param!(
2355+
let r: i32x8 = simd_shuffle8!(
23562356
a.as_i32x8(),
23572357
a.as_i32x8(),
23582358
<const MASK: i32> [
@@ -2382,7 +2382,7 @@ pub unsafe fn _mm256_shuffle_epi32<const MASK: i32>(a: __m256i) -> __m256i {
23822382
pub unsafe fn _mm256_shufflehi_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
23832383
static_assert_imm8!(IMM8);
23842384
let a = a.as_i16x16();
2385-
let r: i16x16 = simd_shuffle16_param!(
2385+
let r: i16x16 = simd_shuffle16!(
23862386
a,
23872387
a,
23882388
<const IMM8: i32> [
@@ -2420,7 +2420,7 @@ pub unsafe fn _mm256_shufflehi_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
24202420
pub unsafe fn _mm256_shufflelo_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
24212421
static_assert_imm8!(IMM8);
24222422
let a = a.as_i16x16();
2423-
let r: i16x16 = simd_shuffle16_param!(
2423+
let r: i16x16 = simd_shuffle16!(
24242424
a,
24252425
a,
24262426
<const IMM8: i32> [
@@ -2587,7 +2587,7 @@ pub unsafe fn _mm256_bslli_epi128<const IMM8: i32>(a: __m256i) -> __m256i {
25872587
static_assert_imm8!(IMM8);
25882588
let a = a.as_i8x32();
25892589
let zero = _mm256_setzero_si256().as_i8x32();
2590-
let r: i8x32 = simd_shuffle32_param!(
2590+
let r: i8x32 = simd_shuffle32!(
25912591
zero,
25922592
a,
25932593
<const IMM8: i32> [

0 commit comments

Comments
 (0)