]>
Commit | Line | Data |
---|---|---|
0531ce1d XL |
1 | //! Utilities used in testing the x86 intrinsics |
2 | ||
532ac7d7 | 3 | use crate::core_arch::x86::*; |
0531ce1d | 4 | |
0531ce1d XL |
5 | #[target_feature(enable = "sse2")] |
6 | pub unsafe fn assert_eq_m128i(a: __m128i, b: __m128i) { | |
7 | union A { | |
8 | a: __m128i, | |
9 | b: [u64; 2], | |
10 | } | |
11 | assert_eq!(A { a }.b, A { a: b }.b) | |
12 | } | |
13 | ||
14 | #[target_feature(enable = "sse2")] | |
15 | pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) { | |
16 | if _mm_movemask_pd(_mm_cmpeq_pd(a, b)) != 0b11 { | |
17 | panic!("{:?} != {:?}", a, b); | |
18 | } | |
19 | } | |
20 | ||
21 | #[target_feature(enable = "sse2")] | |
22 | pub unsafe fn get_m128d(a: __m128d, idx: usize) -> f64 { | |
23 | union A { | |
24 | a: __m128d, | |
25 | b: [f64; 2], | |
26 | }; | |
27 | A { a }.b[idx] | |
28 | } | |
29 | ||
30 | #[target_feature(enable = "sse")] | |
31 | pub unsafe fn assert_eq_m128(a: __m128, b: __m128) { | |
32 | let r = _mm_cmpeq_ps(a, b); | |
33 | if _mm_movemask_ps(r) != 0b1111 { | |
34 | panic!("{:?} != {:?}", a, b); | |
35 | } | |
36 | } | |
37 | ||
38 | #[target_feature(enable = "sse")] | |
39 | pub unsafe fn get_m128(a: __m128, idx: usize) -> f32 { | |
40 | union A { | |
41 | a: __m128, | |
42 | b: [f32; 4], | |
43 | }; | |
44 | A { a }.b[idx] | |
45 | } | |
46 | ||
47 | // not actually an intrinsic but useful in various tests as we proted from | |
48 | // `i64x2::new` which is backwards from `_mm_set_epi64x` | |
49 | #[target_feature(enable = "sse2")] | |
50 | pub unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i { | |
51 | _mm_set_epi64x(b, a) | |
52 | } | |
53 | ||
54 | #[target_feature(enable = "avx")] | |
55 | pub unsafe fn assert_eq_m256i(a: __m256i, b: __m256i) { | |
56 | union A { | |
57 | a: __m256i, | |
58 | b: [u64; 4], | |
59 | } | |
60 | assert_eq!(A { a }.b, A { a: b }.b) | |
61 | } | |
62 | ||
63 | #[target_feature(enable = "avx")] | |
64 | pub unsafe fn assert_eq_m256d(a: __m256d, b: __m256d) { | |
65 | let cmp = _mm256_cmp_pd(a, b, _CMP_EQ_OQ); | |
66 | if _mm256_movemask_pd(cmp) != 0b1111 { | |
67 | panic!("{:?} != {:?}", a, b); | |
68 | } | |
69 | } | |
70 | ||
71 | #[target_feature(enable = "avx")] | |
72 | pub unsafe fn get_m256d(a: __m256d, idx: usize) -> f64 { | |
73 | union A { | |
74 | a: __m256d, | |
75 | b: [f64; 4], | |
76 | }; | |
77 | A { a }.b[idx] | |
78 | } | |
79 | ||
80 | #[target_feature(enable = "avx")] | |
81 | pub unsafe fn assert_eq_m256(a: __m256, b: __m256) { | |
82 | let cmp = _mm256_cmp_ps(a, b, _CMP_EQ_OQ); | |
83 | if _mm256_movemask_ps(cmp) != 0b11111111 { | |
84 | panic!("{:?} != {:?}", a, b); | |
85 | } | |
86 | } | |
87 | ||
88 | #[target_feature(enable = "avx")] | |
89 | pub unsafe fn get_m256(a: __m256, idx: usize) -> f32 { | |
90 | union A { | |
91 | a: __m256, | |
92 | b: [f32; 8], | |
93 | }; | |
94 | A { a }.b[idx] | |
95 | } | |
96 | ||
97 | // These intrinsics doesn't exist on x86 b/c it requires a 64-bit register, | |
98 | // which doesn't exist on x86! | |
99 | #[cfg(target_arch = "x86")] | |
100 | mod x86_polyfill { | |
532ac7d7 | 101 | use crate::core_arch::x86::*; |
0531ce1d XL |
102 | |
103 | pub unsafe fn _mm_insert_epi64(a: __m128i, val: i64, idx: i32) -> __m128i { | |
104 | union A { | |
105 | a: __m128i, | |
106 | b: [i64; 2], | |
107 | }; | |
108 | let mut a = A { a }; | |
109 | a.b[idx as usize] = val; | |
110 | a.a | |
111 | } | |
112 | ||
113 | #[target_feature(enable = "avx2")] | |
0731742a | 114 | pub unsafe fn _mm256_insert_epi64(a: __m256i, val: i64, idx: i32) -> __m256i { |
0531ce1d XL |
115 | union A { |
116 | a: __m256i, | |
117 | b: [i64; 4], | |
118 | }; | |
119 | let mut a = A { a }; | |
120 | a.b[idx as usize] = val; | |
121 | a.a | |
122 | } | |
123 | } | |
124 | #[cfg(target_arch = "x86_64")] | |
125 | mod x86_polyfill { | |
532ac7d7 | 126 | pub use crate::core_arch::x86_64::{_mm256_insert_epi64, _mm_insert_epi64}; |
0531ce1d XL |
127 | } |
128 | pub use self::x86_polyfill::*; | |
0731742a XL |
129 | |
130 | pub unsafe fn assert_eq_m512i(a: __m512i, b: __m512i) { | |
131 | union A { | |
132 | a: __m512i, | |
133 | b: [i32; 16], | |
134 | } | |
135 | assert_eq!(A { a }.b, A { a: b }.b) | |
136 | } | |
3dfed10e XL |
137 | |
138 | pub unsafe fn assert_eq_m512(a: __m512, b: __m512) { | |
139 | let cmp = _mm512_cmp_ps_mask(a, b, _CMP_EQ_OQ); | |
140 | if cmp != 0b11111111_11111111 { | |
141 | panic!("{:?} != {:?}", a, b); | |
142 | } | |
143 | } | |
144 | ||
145 | pub unsafe fn assert_eq_m512d(a: __m512d, b: __m512d) { | |
146 | let cmp = _mm512_cmp_pd_mask(a, b, _CMP_EQ_OQ); | |
147 | if cmp != 0b11111111 { | |
148 | panic!("{:?} != {:?}", a, b); | |
149 | } | |
150 | } |