Fix interleave/deinterleave for vectors with only one lane

This commit is contained in:
Caleb Zulawski 2022-07-29 11:57:05 -04:00
parent b5f9d43ff1
commit 3183afb6b5
2 changed files with 24 additions and 2 deletions

View File

@ -325,7 +325,11 @@ where
const INDEX: [Which; LANES] = hi::<LANES>();
}
(Lo::swizzle2(self, other), Hi::swizzle2(self, other))
if LANES == 1 {
(self, other)
} else {
(Lo::swizzle2(self, other), Hi::swizzle2(self, other))
}
}
/// Deinterleave two vectors.
@ -380,6 +384,10 @@ where
const INDEX: [Which; LANES] = odd::<LANES>();
}
(Even::swizzle2(self, other), Odd::swizzle2(self, other))
if LANES == 1 {
(self, other)
} else {
(Even::swizzle2(self, other), Odd::swizzle2(self, other))
}
}
}

View File

@ -60,3 +60,17 @@ fn interleave() {
assert_eq!(even, a);
assert_eq!(odd, b);
}
// portable-simd#298
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn interleave_one() {
let a = Simd::from_array([0]);
let b = Simd::from_array([1]);
let (lo, hi) = a.interleave(b);
assert_eq!(lo.to_array(), [0]);
assert_eq!(hi.to_array(), [1]);
let (even, odd) = lo.deinterleave(hi);
assert_eq!(even, a);
assert_eq!(odd, b);
}