1 #![feature(portable_simd)]
2 use core_simd::{Simd, Swizzle};
4 #[cfg(target_arch = "wasm32")]
5 use wasm_bindgen_test::*;
7 #[cfg(target_arch = "wasm32")]
8 wasm_bindgen_test_configure!(run_in_browser);
11 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
14 impl Swizzle<4, 4> for Index {
15 const INDEX: [usize; 4] = [2, 1, 3, 0];
17 impl Swizzle<4, 2> for Index {
18 const INDEX: [usize; 2] = [1, 1];
21 let vector = Simd::from_array([2, 4, 1, 9]);
22 assert_eq!(Index::swizzle(vector).to_array(), [1, 4, 9, 2]);
23 assert_eq!(Index::swizzle(vector).to_array(), [4, 4]);
27 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
29 let a = Simd::from_array([1, 2, 3, 4]);
30 assert_eq!(a.reverse().to_array(), [4, 3, 2, 1]);
34 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
36 let a = Simd::from_array([1, 2, 3, 4]);
37 assert_eq!(a.rotate_lanes_left::<0>().to_array(), [1, 2, 3, 4]);
38 assert_eq!(a.rotate_lanes_left::<1>().to_array(), [2, 3, 4, 1]);
39 assert_eq!(a.rotate_lanes_left::<2>().to_array(), [3, 4, 1, 2]);
40 assert_eq!(a.rotate_lanes_left::<3>().to_array(), [4, 1, 2, 3]);
41 assert_eq!(a.rotate_lanes_left::<4>().to_array(), [1, 2, 3, 4]);
42 assert_eq!(a.rotate_lanes_left::<5>().to_array(), [2, 3, 4, 1]);
43 assert_eq!(a.rotate_lanes_right::<0>().to_array(), [1, 2, 3, 4]);
44 assert_eq!(a.rotate_lanes_right::<1>().to_array(), [4, 1, 2, 3]);
45 assert_eq!(a.rotate_lanes_right::<2>().to_array(), [3, 4, 1, 2]);
46 assert_eq!(a.rotate_lanes_right::<3>().to_array(), [2, 3, 4, 1]);
47 assert_eq!(a.rotate_lanes_right::<4>().to_array(), [1, 2, 3, 4]);
48 assert_eq!(a.rotate_lanes_right::<5>().to_array(), [4, 1, 2, 3]);
52 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
54 let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
55 let b = Simd::from_array([8, 9, 10, 11, 12, 13, 14, 15]);
56 let (lo, hi) = a.interleave(b);
57 assert_eq!(lo.to_array(), [0, 8, 1, 9, 2, 10, 3, 11]);
58 assert_eq!(hi.to_array(), [4, 12, 5, 13, 6, 14, 7, 15]);
59 let (even, odd) = lo.deinterleave(hi);