Skip to content

Commit 9e5f07e

Browse files
committed
Work around const argument issue for shuffling, per rust-lang/stdarch#1160.
1 parent 7e0dea8 commit 9e5f07e

File tree

3 files changed

+590
-530
lines changed

3 files changed

+590
-530
lines changed

simd/src/arm/mod.rs

+48-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ use std::ops::{Add, BitAnd, BitOr, Div, Index, IndexMut, Mul, Not, Shr, Sub};
1818
mod swizzle_f32x4;
1919
mod swizzle_i32x4;
2020

21+
macro_rules! simd_shuffle2 {
22+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
23+
struct ConstParam<$(const $imm: $ty),+>;
24+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
25+
const IDX: [u32; 2] = $idx;
26+
}
27+
28+
simd_shuffle2($x, $y, ConstParam::<$($imm),+>::IDX)
29+
}};
30+
($x:expr, $y:expr, $idx:expr $(,)?) => {{
31+
const IDX: [u32; 2] = $idx;
32+
simd_shuffle2($x, $y, IDX)
33+
}};
34+
}
35+
36+
macro_rules! simd_shuffle4 {
37+
($x:expr, $y:expr, <$(const $imm:ident : $ty:ty),+> $idx:expr $(,)?) => {{
38+
struct ConstParam<$(const $imm: $ty),+>;
39+
impl<$(const $imm: $ty),+> ConstParam<$($imm),+> {
40+
const IDX: [u32; 4] = $idx;
41+
}
42+
43+
simd_shuffle4($x, $y, ConstParam::<$($imm),+>::IDX)
44+
}};
45+
($x:expr, $y:expr, $idx:expr $(,)?) => {{
46+
const IDX: [u32; 4] = $idx;
47+
simd_shuffle4($x, $y, IDX)
48+
}};
49+
}
50+
2151
// Two 32-bit floats
2252

2353
#[derive(Clone, Copy)]
@@ -122,14 +152,14 @@ impl F32x2 {
122152

123153
#[inline]
124154
pub fn yx(self) -> F32x2 {
125-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [1, 0])) }
155+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [1, 0])) }
126156
}
127157

128158
// Concatenations
129159

130160
#[inline]
131161
pub fn concat_xy_xy(self, other: F32x2) -> F32x4 {
132-
unsafe { F32x4(simd_shuffle4(self.0, other.0, [0, 1, 2, 3])) }
162+
unsafe { F32x4(simd_shuffle4!(self.0, other.0, [0, 1, 2, 3])) }
133163
}
134164
}
135165

@@ -287,44 +317,44 @@ impl F32x4 {
287317

288318
#[inline]
289319
pub fn xy(self) -> F32x2 {
290-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [0, 1])) }
320+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [0, 1])) }
291321
}
292322

293323
#[inline]
294324
pub fn yx(self) -> F32x2 {
295-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [1, 0])) }
325+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [1, 0])) }
296326
}
297327

298328
#[inline]
299329
pub fn xw(self) -> F32x2 {
300-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [0, 3])) }
330+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [0, 3])) }
301331
}
302332

303333
#[inline]
304334
pub fn zy(self) -> F32x2 {
305-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [2, 1])) }
335+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [2, 1])) }
306336
}
307337

308338
#[inline]
309339
pub fn zw(self) -> F32x2 {
310-
unsafe { F32x2(simd_shuffle2(self.0, self.0, [2, 3])) }
340+
unsafe { F32x2(simd_shuffle2!(self.0, self.0, [2, 3])) }
311341
}
312342

313343
// Concatenations
314344

315345
#[inline]
316346
pub fn concat_xy_xy(self, other: F32x4) -> F32x4 {
317-
unsafe { F32x4(simd_shuffle4(self.0, other.0, [0, 1, 2, 3])) }
347+
unsafe { F32x4(simd_shuffle4!(self.0, other.0, [0, 1, 2, 3])) }
318348
}
319349

320350
#[inline]
321351
pub fn concat_xy_zw(self, other: F32x4) -> F32x4 {
322-
unsafe { F32x4(simd_shuffle4(self.0, other.0, [0, 1, 6, 7])) }
352+
unsafe { F32x4(simd_shuffle4!(self.0, other.0, [0, 1, 6, 7])) }
323353
}
324354

325355
#[inline]
326356
pub fn concat_zw_zw(self, other: F32x4) -> F32x4 {
327-
unsafe { F32x4(simd_shuffle4(self.0, other.0, [2, 3, 6, 7])) }
357+
unsafe { F32x4(simd_shuffle4!(self.0, other.0, [2, 3, 6, 7])) }
328358
}
329359

330360
// Conversions
@@ -461,7 +491,7 @@ impl I32x2 {
461491

462492
#[inline]
463493
pub fn concat_xy_xy(self, other: I32x2) -> I32x4 {
464-
unsafe { I32x4(simd_shuffle4(self.0, other.0, [0, 1, 2, 3])) }
494+
unsafe { I32x4(simd_shuffle4!(self.0, other.0, [0, 1, 2, 3])) }
465495
}
466496

467497
// Conversions
@@ -588,39 +618,39 @@ impl I32x4 {
588618

589619
#[inline]
590620
pub fn concat_xy_xy(self, other: I32x4) -> I32x4 {
591-
unsafe { I32x4(simd_shuffle4(self.0, other.0, [0, 1, 4, 5])) }
621+
unsafe { I32x4(simd_shuffle4!(self.0, other.0, [0, 1, 4, 5])) }
592622
}
593623

594624
#[inline]
595625
pub fn concat_zw_zw(self, other: I32x4) -> I32x4 {
596-
unsafe { I32x4(simd_shuffle4(self.0, other.0, [2, 3, 6, 7])) }
626+
unsafe { I32x4(simd_shuffle4!(self.0, other.0, [2, 3, 6, 7])) }
597627
}
598628

599629
// Swizzle conversions
600630

601631
#[inline]
602632
pub fn xy(self) -> I32x2 {
603-
unsafe { I32x2(simd_shuffle2(self.0, self.0, [0, 1])) }
633+
unsafe { I32x2(simd_shuffle2!(self.0, self.0, [0, 1])) }
604634
}
605635

606636
#[inline]
607637
pub fn yx(self) -> I32x2 {
608-
unsafe { I32x2(simd_shuffle2(self.0, self.0, [1, 0])) }
638+
unsafe { I32x2(simd_shuffle2!(self.0, self.0, [1, 0])) }
609639
}
610640

611641
#[inline]
612642
pub fn xw(self) -> I32x2 {
613-
unsafe { I32x2(simd_shuffle2(self.0, self.0, [0, 3])) }
643+
unsafe { I32x2(simd_shuffle2!(self.0, self.0, [0, 3])) }
614644
}
615645

616646
#[inline]
617647
pub fn zy(self) -> I32x2 {
618-
unsafe { I32x2(simd_shuffle2(self.0, self.0, [2, 1])) }
648+
unsafe { I32x2(simd_shuffle2!(self.0, self.0, [2, 1])) }
619649
}
620650

621651
#[inline]
622652
pub fn zw(self) -> I32x2 {
623-
unsafe { I32x2(simd_shuffle2(self.0, self.0, [2, 3])) }
653+
unsafe { I32x2(simd_shuffle2!(self.0, self.0, [2, 3])) }
624654
}
625655

626656
// Conversions

0 commit comments

Comments
 (0)