Skip to content

Commit 246399c

Browse files
committed
use simd_splat
1 parent 464b309 commit 246399c

3 files changed

Lines changed: 9 additions & 24 deletions

File tree

library/stdarch/crates/core_arch/src/macros.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,10 @@ macro_rules! types {
9090
pub struct $name($v [$elem_type; $len]);
9191

9292
impl $name {
93-
/// Using `my_simd([x; N])` seemingly fails tests,
94-
/// so use this internal helper for it instead.
93+
/// Put the same value in every lane.
9594
#[inline(always)]
9695
$v fn splat(value: $elem_type) -> $name {
97-
#[derive(Copy, Clone)]
98-
#[repr(simd)]
99-
struct JustOne([$elem_type; 1]);
100-
let one = JustOne([value]);
101-
// SAFETY: 0 is always in-bounds because we're shuffling
102-
// a simd type with exactly one element.
103-
unsafe { simd_shuffle!(one, one, [0; $len]) }
96+
unsafe { $crate::intrinsics::simd::simd_splat(value) }
10497
}
10598

10699
/// Returns an array reference containing the entire SIMD vector.

library/stdarch/crates/core_arch/src/powerpc/altivec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,15 +1457,15 @@ mod sealed {
14571457
#[cfg_attr(test, assert_instr(vspltb, IMM4 = 15))]
14581458
unsafe fn vspltb<const IMM4: u32>(a: vector_signed_char) -> vector_signed_char {
14591459
static_assert_uimm_bits!(IMM4, 4);
1460-
simd_shuffle(a, a, const { u32x16::from_array([IMM4; 16]) })
1460+
simd_shuffle(a, a, const { u32x16::splat(IMM4) })
14611461
}
14621462

14631463
#[inline]
14641464
#[target_feature(enable = "altivec")]
14651465
#[cfg_attr(test, assert_instr(vsplth, IMM3 = 7))]
14661466
unsafe fn vsplth<const IMM3: u32>(a: vector_signed_short) -> vector_signed_short {
14671467
static_assert_uimm_bits!(IMM3, 3);
1468-
simd_shuffle(a, a, const { u32x8::from_array([IMM3; 8]) })
1468+
simd_shuffle(a, a, const { u32x8::splat(IMM3) })
14691469
}
14701470

14711471
#[inline]
@@ -1474,7 +1474,7 @@ mod sealed {
14741474
#[cfg_attr(all(test, target_feature = "vsx"), assert_instr(xxspltw, IMM2 = 3))]
14751475
unsafe fn vspltw<const IMM2: u32>(a: vector_signed_int) -> vector_signed_int {
14761476
static_assert_uimm_bits!(IMM2, 2);
1477-
simd_shuffle(a, a, const { u32x4::from_array([IMM2; 4]) })
1477+
simd_shuffle(a, a, const { u32x4::splat(IMM2) })
14781478
}
14791479

14801480
#[unstable(feature = "stdarch_powerpc", issue = "111145")]

library/stdarch/crates/core_arch/src/simd.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@ impl<T: SimdElement, const N: usize> Simd<T, N> {
5050
Self(elements)
5151
}
5252

53-
// FIXME: Workaround rust@60637
54-
#[inline(always)]
53+
#[inline]
5554
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
5655
pub(crate) const fn splat(value: T) -> Self {
57-
let one = Simd([value]);
58-
// SAFETY: 0 is always in-bounds because we're shuffling
59-
// a simd type with exactly one element.
60-
unsafe { simd_shuffle!(one, one, [0; N]) }
56+
unsafe { crate::intrinsics::simd::simd_splat(value) }
6157
}
6258

6359
/// Extract the element at position `index`. Note that `index` is not a constant so this
@@ -182,14 +178,10 @@ impl<T: SimdElement, const N: usize> SimdM<T, N> {
182178
[zeros, ones][x as usize]
183179
}
184180

185-
// FIXME: Workaround rust@60637
186-
#[inline(always)]
181+
#[inline]
187182
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
188183
pub(crate) const fn splat(value: bool) -> Self {
189-
let one = SimdM([Self::bool_to_internal(value)]);
190-
// SAFETY: 0 is always in-bounds because we're shuffling
191-
// a simd type with exactly one element.
192-
unsafe { simd_shuffle!(one, one, [0; N]) }
184+
unsafe { crate::intrinsics::simd::simd_splat(value) }
193185
}
194186

195187
#[inline]

0 commit comments

Comments
 (0)