core/stdarch/crates/core_arch/src/powerpc/
macros.rs
1macro_rules! test_impl {
2 ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr:ident]) => {
3 #[inline]
4 #[target_feature(enable = "altivec")]
5 #[cfg_attr(test, assert_instr($instr))]
6 pub unsafe fn $fun ($($v : $ty),*) -> $r {
7 $call ($($v),*)
8 }
9 };
10 ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr_altivec:ident / $instr_vsx:ident]) => {
11 test_impl! { $fun ($($v : $ty),*) -> $r [$call, $instr_altivec / $instr_vsx / $instr_vsx] }
12 };
13 ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr_altivec:ident / $instr_vsx:ident / $instr_pwr9:ident]) => {
14 #[inline]
15 #[target_feature(enable = "altivec")]
16 #[cfg_attr(all(test, not(target_feature="vsx"), not(target_feature = "power9-vector")), assert_instr($instr_altivec))]
17 #[cfg_attr(all(test, target_feature="vsx", not(target_feature = "power9-vector")), assert_instr($instr_vsx))]
18 #[cfg_attr(all(test, not(target_feature="vsx"), target_feature = "power9-vector"), assert_instr($instr_pwr9))]
19 pub unsafe fn $fun ($($v : $ty),*) -> $r {
20 $call ($($v),*)
21 }
22 }
23}
24
25#[allow(unknown_lints, unused_macro_rules)]
26macro_rules! impl_vec_trait {
27 ([$Trait:ident $m:ident] $fun:ident ($a:ty)) => {
28 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
29 impl $Trait for $a {
30 #[inline]
31 #[target_feature(enable = "altivec")]
32 unsafe fn $m(self) -> Self {
33 $fun(transmute(self))
34 }
35 }
36 };
37 ([$Trait:ident $m:ident] $fun:ident ($a:ty) -> $r:ty) => {
38 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
39 impl $Trait for $a {
40 type Result = $r;
41 #[inline]
42 #[target_feature(enable = "altivec")]
43 unsafe fn $m(self) -> Self::Result {
44 $fun(transmute(self))
45 }
46 }
47 };
48 ([$Trait:ident $m:ident]+ $fun:ident ($a:ty) -> $r:ty) => {
49 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
50 impl $Trait for $a {
51 type Result = $r;
52 #[inline]
53 #[target_feature(enable = "altivec")]
54 unsafe fn $m(self) -> Self::Result {
55 transmute($fun(transmute(self)))
56 }
57 }
58 };
59 ([$Trait:ident $m:ident] 1 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $sf: ident)) => {
60 impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char) -> vector_unsigned_char }
61 impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char) -> vector_signed_char }
62 impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short) -> vector_unsigned_short }
63 impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short) -> vector_signed_short }
64 impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int) -> vector_unsigned_int }
65 impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int) -> vector_signed_int }
66 impl_vec_trait!{ [$Trait $m] $sf (vector_float) -> vector_float }
67 };
68 ([$Trait:ident $m:ident] $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
69 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
70 impl $Trait<$b> for $a {
71 type Result = $r;
72 #[inline]
73 #[target_feature(enable = "altivec")]
74 unsafe fn $m(self, b: $b) -> Self::Result {
75 $fun(transmute(self), transmute(b))
76 }
77 }
78 };
79 ([$Trait:ident $m:ident]+ $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
80 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
81 impl $Trait<$b> for $a {
82 type Result = $r;
83 #[inline]
84 #[target_feature(enable = "altivec")]
85 unsafe fn $m(self, b: $b) -> Self::Result {
86 transmute($fun(transmute(self), transmute(b)))
87 }
88 }
89 };
90 ([$Trait:ident $m:ident] $fun:ident ($a:ty, ~$b:ty) -> $r:ty) => {
91 impl_vec_trait!{ [$Trait $m] $fun ($a, $a) -> $r }
92 impl_vec_trait!{ [$Trait $m] $fun ($a, $b) -> $r }
93 impl_vec_trait!{ [$Trait $m] $fun ($b, $a) -> $r }
94 };
95 ([$Trait:ident $m:ident] ~($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident)) => {
96 impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, ~vector_bool_char) -> vector_unsigned_char }
97 impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, ~vector_bool_char) -> vector_signed_char }
98 impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, ~vector_bool_short) -> vector_unsigned_short }
99 impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, ~vector_bool_short) -> vector_signed_short }
100 impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, ~vector_bool_int) -> vector_unsigned_int }
101 impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, ~vector_bool_int) -> vector_signed_int }
102 };
103 ([$Trait:ident $m:ident] ~($fn:ident)) => {
104 impl_vec_trait!{ [$Trait $m] ~($fn, $fn, $fn, $fn, $fn, $fn) }
105 };
106 ([$Trait:ident $m:ident] 2 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident)) => {
107 impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
108 impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, vector_signed_char) -> vector_signed_char }
109 impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
110 impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, vector_signed_short) -> vector_signed_short }
111 impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
112 impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, vector_signed_int) -> vector_signed_int }
113 };
114 ([$Trait:ident $m:ident] 2 ($fn:ident)) => {
115 impl_vec_trait!{ [$Trait $m] ($fn, $fn, $fn, $fn, $fn, $fn) }
116 };
117 ([$Trait:ident $m:ident]+ 2b ($b:ident, $h:ident, $w:ident)) => {
118 impl_vec_trait!{ [$Trait $m]+ $b (vector_bool_char, vector_bool_char) -> vector_bool_char }
119 impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
120 impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_signed_char) -> vector_signed_char }
121 impl_vec_trait!{ [$Trait $m]+ $h (vector_bool_short, vector_bool_short) -> vector_bool_short }
122 impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
123 impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_signed_short) -> vector_signed_short }
124 impl_vec_trait!{ [$Trait $m]+ $w (vector_bool_int, vector_bool_int) -> vector_bool_int }
125 impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
126 impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_signed_int) -> vector_signed_int }
127 };
128 ([$Trait:ident $m:ident]+ 2b ($fn:ident)) => {
129 impl_vec_trait!{ [$Trait $m]+ 2b ($fn, $fn, $fn) }
130 };
131}
132
133macro_rules! s_t_l {
134 (i32x4) => {
135 vector_signed_int
136 };
137 (i16x8) => {
138 vector_signed_short
139 };
140 (i8x16) => {
141 vector_signed_char
142 };
143
144 (u32x4) => {
145 vector_unsigned_int
146 };
147 (u16x8) => {
148 vector_unsigned_short
149 };
150 (u8x16) => {
151 vector_unsigned_char
152 };
153
154 (f32x4) => {
155 vector_float
156 };
157}
158
159macro_rules! t_t_l {
160 (i32) => {
161 vector_signed_int
162 };
163 (i16) => {
164 vector_signed_short
165 };
166 (i8) => {
167 vector_signed_char
168 };
169
170 (u32) => {
171 vector_unsigned_int
172 };
173 (u16) => {
174 vector_unsigned_short
175 };
176 (u8) => {
177 vector_unsigned_char
178 };
179
180 (f32) => {
181 vector_float
182 };
183}
184
185macro_rules! t_t_s {
186 (i32) => {
187 i32x4
188 };
189 (i16) => {
190 i16x8
191 };
192 (i8) => {
193 i8x16
194 };
195
196 (u32) => {
197 u32x4
198 };
199 (u16) => {
200 u16x8
201 };
202 (u8) => {
203 u8x16
204 };
205
206 (f32) => {
207 f32x4
208 };
209}
210
211macro_rules! t_u {
212 (vector_bool_char) => {
213 vector_unsigned_char
214 };
215 (vector_bool_short) => {
216 vector_unsigned_short
217 };
218 (vector_bool_int) => {
219 vector_unsigned_int
220 };
221 (vector_unsigned_char) => {
222 vector_unsigned_char
223 };
224 (vector_unsigned_short) => {
225 vector_unsigned_short
226 };
227 (vector_unsigned_int) => {
228 vector_unsigned_int
229 };
230 (vector_signed_char) => {
231 vector_unsigned_char
232 };
233 (vector_signed_short) => {
234 vector_unsigned_short
235 };
236 (vector_signed_int) => {
237 vector_unsigned_int
238 };
239 (vector_float) => {
240 vector_unsigned_int
241 };
242}
243
244macro_rules! t_b {
245 (vector_bool_char) => {
246 vector_bool_char
247 };
248 (vector_bool_short) => {
249 vector_bool_short
250 };
251 (vector_bool_int) => {
252 vector_bool_int
253 };
254 (vector_signed_char) => {
255 vector_bool_char
256 };
257 (vector_signed_short) => {
258 vector_bool_short
259 };
260 (vector_signed_int) => {
261 vector_bool_int
262 };
263 (vector_unsigned_char) => {
264 vector_bool_char
265 };
266 (vector_unsigned_short) => {
267 vector_bool_short
268 };
269 (vector_unsigned_int) => {
270 vector_bool_int
271 };
272 (vector_float) => {
273 vector_bool_int
274 };
275}
276
277macro_rules! impl_from {
278 ($s: ident) => {
279 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
280 impl From<$s> for s_t_l!($s) {
281 fn from (v: $s) -> Self {
282 unsafe {
283 transmute(v)
284 }
285 }
286 }
287 };
288 ($($s: ident),*) => {
289 $(
290 impl_from! { $s }
291 )*
292 };
293}
294
295macro_rules! impl_neg {
296 ($s: ident : $zero: expr) => {
297 #[unstable(feature = "stdarch_powerpc", issue = "111145")]
298 impl crate::ops::Neg for s_t_l!($s) {
299 type Output = s_t_l!($s);
300 fn neg(self) -> Self::Output {
301 let zero = $s::splat($zero);
302 unsafe { transmute(simd_sub(zero, transmute(self))) }
303 }
304 }
305 };
306}
307
308pub(crate) use impl_from;
309pub(crate) use impl_neg;
310pub(crate) use impl_vec_trait;
311pub(crate) use s_t_l;
312pub(crate) use t_b;
313pub(crate) use t_t_l;
314pub(crate) use t_t_s;
315pub(crate) use t_u;
316pub(crate) use test_impl;