Skip to content

Commit 1c2972b

Browse files
committed
Add generic_const_exprs variants.
They don't compile.
1 parent 94b2f08 commit 1c2972b

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

crates/core_simd/src/swizzle.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,38 @@ where
367367

368368
/// Splits a vector into its two halves.
369369
///
370+
/// Vector length must be even, or a compile error will be raised.
371+
///
372+
/// ```
373+
/// # #![feature(portable_simd)]
374+
/// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd;
375+
/// # #[cfg(not(feature = "as_crate"))] use core::simd::Simd;
376+
/// let x = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
377+
/// let [y, z] = x.split();
378+
/// assert_eq!(y.to_array(), [0, 1, 2, 3]);
379+
/// assert_eq!(z.to_array(), [4, 5, 6, 7]);
380+
/// ```
381+
#[inline]
382+
#[must_use = "method returns a new vector and does not mutate the original inputs"]
383+
#[cfg(feature = "generic_const_exprs")]
384+
pub fn split(self) -> [Simd<T, { LANES / 2 }>; 2]
385+
where
386+
LaneCount<{ LANES / 2 }>: SupportedLaneCount,
387+
{
388+
self.split_to::<{ LANES / 2 }>()
389+
}
390+
391+
/// Splits a vector into its two halves.
392+
///
393+
/// Vector length must be even, or a compile error will be raised.
394+
///
370395
/// Due to limitations in const generics, the length of the resulting vector cannot be inferred
371396
/// from the input vectors. You must specify it explicitly. A compile-time error will be raised
372397
/// if `HALF_LANES * 2 != LANES`.
373398
///
399+
/// When using the language feature and `std::simd` crate feature `generic_const_exprs`, prefer
400+
/// to use `Simd::split` which can infer the output length.
401+
///
374402
/// ```
375403
/// # #![feature(portable_simd)]
376404
/// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd;
@@ -409,11 +437,35 @@ where
409437
[Split::<false>::swizzle(self), Split::<true>::swizzle(self)]
410438
}
411439

440+
/// Concatenates two vectors of equal length.
441+
///
442+
/// ```
443+
/// # #![feature(portable_simd)]
444+
/// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd;
445+
/// # #[cfg(not(feature = "as_crate"))] use core::simd::Simd;
446+
/// let x = Simd::from_array([0, 1, 2, 3]);
447+
/// let y = Simd::from_array([4, 5, 6, 7]);
448+
/// let z = x.concat_to::<8>(y);
449+
/// assert_eq!(z.to_array(), [0, 1, 2, 3, 4, 5, 6, 7]);
450+
/// ```
451+
#[inline]
452+
#[must_use = "method returns a new vector and does not mutate the original inputs"]
453+
#[cfg(feature = "generic_const_exprs")]
454+
pub fn concat(self, other: Self) -> Simd<T, { LANES * 2 }>
455+
where
456+
LaneCount<{ LANES * 2 }>: SupportedLaneCount,
457+
{
458+
self.concat_to::<{ LANES * 2 }>(other)
459+
}
460+
412461
/// Concatenates two vectors of equal length.
413462
///
414463
/// Due to limitations in const generics, the length of the resulting vector cannot be inferred
415464
/// from the input vectors. You must specify it explicitly. A compile time error will be raised
416-
/// if `LANES * 2 != DOUBLE_LANES`
465+
/// if `LANES * 2 != DOUBLE_LANES`.
466+
///
467+
/// When using the language feature and `std::simd` crate feature `generic_const_exprs`, prefer
468+
/// to use `Simd::split` which can infer the output length.
417469
///
418470
/// ```
419471
/// # #![feature(portable_simd)]

crates/core_simd/tests/swizzle.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(portable_simd)]
2-
use core_simd::simd::{Simd, Swizzle};
2+
use core_simd::simd::{Simd, Swizzle, u32x4};
33

44
#[cfg(target_arch = "wasm32")]
55
use wasm_bindgen_test::*;
@@ -77,7 +77,7 @@ fn interleave_one() {
7777

7878
#[test]
7979
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
80-
fn slice() {
80+
fn split_to() {
8181
let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
8282
let [lo, hi] = a.split_to::<4>();
8383
assert_eq!(lo.to_array(), [0, 1, 2, 3]);
@@ -86,13 +86,31 @@ fn slice() {
8686

8787
#[test]
8888
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
89-
fn concat() {
89+
fn split() {
90+
let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
91+
let [lo, hi]: [u32x4] = a.split();
92+
assert_eq!(lo.to_array(), [0, 1, 2, 3]);
93+
assert_eq!(hi.to_array(), [4, 5, 6, 7]);
94+
}
95+
96+
#[test]
97+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
98+
fn concat_to() {
9099
let x = Simd::from_array([0, 1, 2, 3]);
91100
let y = Simd::from_array([4, 5, 6, 7]);
92101
let z = x.concat_to::<8>(y);
93102
assert_eq!(z.to_array(), [0, 1, 2, 3, 4, 5, 6, 7]);
94103
}
95104

105+
#[test]
106+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
107+
fn concat() {
108+
let x = Simd::from_array([0, 1, 2, 3]);
109+
let y = Simd::from_array([4, 5, 6, 7]);
110+
let z = x.concat(y);
111+
assert_eq!(z.to_array(), [0, 1, 2, 3, 4, 5, 6, 7]);
112+
}
113+
96114
#[test]
97115
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
98116
fn general_reverse() {

0 commit comments

Comments
 (0)