Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions crates/core_arch/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,10 @@ macro_rules! types {
pub struct $name($v [$elem_type; $len]);

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

/// Returns an array reference containing the entire SIMD vector.
Expand Down
6 changes: 3 additions & 3 deletions crates/core_arch/src/powerpc/altivec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,15 +1457,15 @@ mod sealed {
#[cfg_attr(test, assert_instr(vspltb, IMM4 = 15))]
unsafe fn vspltb<const IMM4: u32>(a: vector_signed_char) -> vector_signed_char {
static_assert_uimm_bits!(IMM4, 4);
simd_shuffle(a, a, const { u32x16::from_array([IMM4; 16]) })
simd_shuffle(a, a, const { u32x16::splat(IMM4) })
}

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

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

#[unstable(feature = "stdarch_powerpc", issue = "111145")]
Expand Down
16 changes: 4 additions & 12 deletions crates/core_arch/src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ impl<T: SimdElement, const N: usize> Simd<T, N> {
Self(elements)
}

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

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

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

#[inline]
Expand Down
18 changes: 6 additions & 12 deletions crates/core_arch/src/x86/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ pub const fn _mm256_setr_epi64x(a: i64, b: i64, c: i64, d: i64) -> __m256i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_pd(a: f64) -> __m256d {
_mm256_setr_pd(a, a, a, a)
f64x4::splat(a).as_m256d()
}

/// Broadcasts single-precision (32-bit) floating-point value `a` to all
Expand All @@ -2759,7 +2759,7 @@ pub const fn _mm256_set1_pd(a: f64) -> __m256d {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_ps(a: f32) -> __m256 {
_mm256_setr_ps(a, a, a, a, a, a, a, a)
f32x8::splat(a).as_m256()
}

/// Broadcasts 8-bit integer `a` to all elements of returned vector.
Expand All @@ -2772,13 +2772,7 @@ pub const fn _mm256_set1_ps(a: f32) -> __m256 {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_epi8(a: i8) -> __m256i {
#[rustfmt::skip]
_mm256_setr_epi8(
a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a,
a, a, a, a, a, a, a, a,
)
i8x32::splat(a).as_m256i()
}

/// Broadcasts 16-bit integer `a` to all elements of returned vector.
Expand All @@ -2793,7 +2787,7 @@ pub const fn _mm256_set1_epi8(a: i8) -> __m256i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_epi16(a: i16) -> __m256i {
_mm256_setr_epi16(a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a)
i16x16::splat(a).as_m256i()
}

/// Broadcasts 32-bit integer `a` to all elements of returned vector.
Expand All @@ -2806,7 +2800,7 @@ pub const fn _mm256_set1_epi16(a: i16) -> __m256i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_epi32(a: i32) -> __m256i {
_mm256_setr_epi32(a, a, a, a, a, a, a, a)
i32x8::splat(a).as_m256i()
}

/// Broadcasts 64-bit integer `a` to all elements of returned vector.
Expand All @@ -2821,7 +2815,7 @@ pub const fn _mm256_set1_epi32(a: i32) -> __m256i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm256_set1_epi64x(a: i64) -> __m256i {
_mm256_setr_epi64x(a, a, a, a)
i64x4::splat(a).as_m256i()
}

/// Cast vector of type __m256d to type __m256.
Expand Down
2 changes: 1 addition & 1 deletion crates/core_arch/src/x86/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ pub const fn _mm_set_ss(a: f32) -> __m128 {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm_set1_ps(a: f32) -> __m128 {
__m128([a, a, a, a])
f32x4::splat(a).as_m128()
}

/// Alias for [`_mm_set1_ps`](fn._mm_set1_ps.html)
Expand Down
8 changes: 4 additions & 4 deletions crates/core_arch/src/x86/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ pub const fn _mm_set_epi8(
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm_set1_epi64x(a: i64) -> __m128i {
_mm_set_epi64x(a, a)
i64x2::splat(a).as_m128i()
}

/// Broadcasts 32-bit integer `a` to all elements.
Expand All @@ -1188,7 +1188,7 @@ pub const fn _mm_set1_epi64x(a: i64) -> __m128i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm_set1_epi32(a: i32) -> __m128i {
_mm_set_epi32(a, a, a, a)
i32x4::splat(a).as_m128i()
}

/// Broadcasts 16-bit integer `a` to all elements.
Expand All @@ -1200,7 +1200,7 @@ pub const fn _mm_set1_epi32(a: i32) -> __m128i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm_set1_epi16(a: i16) -> __m128i {
_mm_set_epi16(a, a, a, a, a, a, a, a)
i16x8::splat(a).as_m128i()
}

/// Broadcasts 8-bit integer `a` to all elements.
Expand All @@ -1212,7 +1212,7 @@ pub const fn _mm_set1_epi16(a: i16) -> __m128i {
#[stable(feature = "simd_x86", since = "1.27.0")]
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
pub const fn _mm_set1_epi8(a: i8) -> __m128i {
_mm_set_epi8(a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a)
i8x16::splat(a).as_m128i()
}

/// Sets packed 32-bit integers with the supplied values in reverse order.
Expand Down