Skip to content

Commit 3183afb

Browse files
committed
Fix interleave/deinterleave for vectors with only one lane
1 parent b5f9d43 commit 3183afb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

crates/core_simd/src/swizzle.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ where
325325
const INDEX: [Which; LANES] = hi::<LANES>();
326326
}
327327

328-
(Lo::swizzle2(self, other), Hi::swizzle2(self, other))
328+
if LANES == 1 {
329+
(self, other)
330+
} else {
331+
(Lo::swizzle2(self, other), Hi::swizzle2(self, other))
332+
}
329333
}
330334

331335
/// Deinterleave two vectors.
@@ -380,6 +384,10 @@ where
380384
const INDEX: [Which; LANES] = odd::<LANES>();
381385
}
382386

383-
(Even::swizzle2(self, other), Odd::swizzle2(self, other))
387+
if LANES == 1 {
388+
(self, other)
389+
} else {
390+
(Even::swizzle2(self, other), Odd::swizzle2(self, other))
391+
}
384392
}
385393
}

crates/core_simd/tests/swizzle.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ fn interleave() {
6060
assert_eq!(even, a);
6161
assert_eq!(odd, b);
6262
}
63+
64+
// portable-simd#298
65+
#[test]
66+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
67+
fn interleave_one() {
68+
let a = Simd::from_array([0]);
69+
let b = Simd::from_array([1]);
70+
let (lo, hi) = a.interleave(b);
71+
assert_eq!(lo.to_array(), [0]);
72+
assert_eq!(hi.to_array(), [1]);
73+
let (even, odd) = lo.deinterleave(hi);
74+
assert_eq!(even, a);
75+
assert_eq!(odd, b);
76+
}

0 commit comments

Comments
 (0)