Skip to content

Commit c963615

Browse files
Change Simd::splat to not generate a loop
This fixes poor codegen in some circumstances for `u16x8::splat` on x86_64 https://rust-lang.zulipchat.com/#narrow/stream/257879-project-portable-simd/topic/Very.20bad.20.60u16x8.3A.3Asplat.60.20codegen.20on.20x86_64
1 parent f237f13 commit c963615

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/core_simd/src/vector.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ pub use uint::*;
99
// Vectors of pointers are not for public use at the current time.
1010
pub(crate) mod ptr;
1111

12-
use crate::simd::intrinsics;
13-
use crate::simd::{LaneCount, Mask, MaskElement, SimdPartialOrd, SupportedLaneCount};
12+
use crate::simd::{
13+
intrinsics, LaneCount, Mask, MaskElement, SimdPartialOrd, SupportedLaneCount, Swizzle,
14+
};
1415

1516
/// A SIMD vector of `LANES` elements of type `T`. `Simd<T, N>` has the same shape as [`[T; N]`](array), but operates like `T`.
1617
///
@@ -123,8 +124,12 @@ where
123124
/// let v = u32x4::splat(8);
124125
/// assert_eq!(v.as_array(), &[8, 8, 8, 8]);
125126
/// ```
126-
pub const fn splat(value: T) -> Self {
127-
Self([value; LANES])
127+
pub fn splat(value: T) -> Self {
128+
struct Splat;
129+
impl<const LANES: usize> Swizzle<1, LANES> for Splat {
130+
const INDEX: [usize; LANES] = [0; LANES];
131+
}
132+
Splat::swizzle(Simd::<T, 1>::from([value]))
128133
}
129134

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

0 commit comments

Comments
 (0)