-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathpermute.rs
57 lines (50 loc) · 1.72 KB
/
permute.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use core_simd::SimdU32;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn simple_shuffle() {
let a = SimdU32::from_array([2, 4, 1, 9]);
let b = a;
assert_eq!(a.shuffle::<{ [3, 1, 4, 6] }>(b).to_array(), [9, 4, 2, 1]);
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn reverse() {
let a = SimdU32::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(a.reverse().to_array(), [7, 6, 5, 4, 3, 2, 1, 0]);
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn interleave() {
let a = SimdU32::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
let b = SimdU32::from_array([8, 9, 10, 11, 12, 13, 14, 15]);
let (lo, hi) = a.interleave(b);
assert_eq!(lo.to_array(), [0, 8, 1, 9, 2, 10, 3, 11]);
assert_eq!(hi.to_array(), [4, 12, 5, 13, 6, 14, 7, 15]);
let (even, odd) = lo.deinterleave(hi);
assert_eq!(even, a);
assert_eq!(odd, b);
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn shift_left() {
let a = SimdU32::from_array([0, 1, 2, 3]);
let b = SimdU32::from_array([2, 3, 0, 0]);
assert_eq!(a.shift_left::<{ 2 }>(), b);
let b = SimdU32::from_array([0, 0, 0, 0]);
assert_eq!(a.shift_left::<{ 5 }>(), b);
assert_eq!(a.shift_left::<{ 0 }>(), a);
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn shift_right() {
let a = SimdU32::from_array([0, 1, 2, 3]);
let b = SimdU32::from_array([0, 0, 0, 1]);
assert_eq!(a.shift_right::<{ 2 }>(), b);
let b = SimdU32::from_array([0, 0, 0, 0]);
assert_eq!(a.shift_right::<{ 5 }>(), b);
assert_eq!(a.shift_right::<{ 0 }>(), a);
}