core/stdarch/crates/core_arch/src/s390x/
macros.rs

1#![allow(unused_macros)] // FIXME remove when more tests are added
2#![allow(unused_imports)] // FIXME remove when more tests are added
3
4macro_rules! test_impl {
5    ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, _]) => {
6        #[inline]
7        #[target_feature(enable = "vector")]
8        pub unsafe fn $fun ($($v : $ty),*) -> $r {
9            $call ($($v),*)
10        }
11    };
12    ($fun:ident +($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr:ident]) => {
13        #[inline]
14        #[target_feature(enable = "vector")]
15        #[cfg_attr(test, assert_instr($instr))]
16        pub unsafe fn $fun ($($v : $ty),*) -> $r {
17            transmute($call ($($v),*))
18        }
19    };
20    ($fun:ident +($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $tf:literal $instr:ident]) => {
21        #[inline]
22        #[target_feature(enable = "vector")]
23        #[cfg_attr(all(test, target_feature = $tf), assert_instr($instr))]
24        pub unsafe fn $fun ($($v : $ty),*) -> $r {
25            transmute($call ($($v),*))
26        }
27    };
28    ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $tf:literal $instr:ident]) => {
29        #[inline]
30        #[target_feature(enable = "vector")]
31        #[cfg_attr(all(test, target_feature = $tf), assert_instr($instr))]
32        pub unsafe fn $fun ($($v : $ty),*) -> $r {
33            $call ($($v),*)
34        }
35    };
36    ($fun:ident ($($v:ident : $ty:ty),*) -> $r:ty [$call:ident, $instr:ident]) => {
37        #[inline]
38        #[target_feature(enable = "vector")]
39        #[cfg_attr(test, assert_instr($instr))]
40        pub unsafe fn $fun ($($v : $ty),*) -> $r {
41            $call ($($v),*)
42        }
43    };
44}
45
46#[allow(unknown_lints, unused_macro_rules)]
47macro_rules! impl_vec_trait {
48    ([$Trait:ident $m:ident] $fun:ident ($a:ty)) => {
49        #[unstable(feature = "stdarch_s390x", issue = "135681")]
50        impl $Trait for $a {
51            #[inline]
52            #[target_feature(enable = "vector")]
53            unsafe fn $m(self) -> Self {
54                $fun(transmute(self))
55            }
56        }
57    };
58    ([$Trait:ident $m:ident]+ $fun:ident ($a:ty)) => {
59        #[unstable(feature = "stdarch_s390x", issue = "135681")]
60        impl $Trait for $a {
61            #[inline]
62            #[target_feature(enable = "vector")]
63            unsafe fn $m(self) -> Self {
64                transmute($fun(transmute(self)))
65            }
66        }
67    };
68    ([$Trait:ident $m:ident] $fun:ident ($a:ty) -> $r:ty) => {
69        #[unstable(feature = "stdarch_s390x", issue = "135681")]
70        impl $Trait for $a {
71            type Result = $r;
72            #[inline]
73            #[target_feature(enable = "vector")]
74            unsafe fn $m(self) -> Self::Result {
75                $fun(transmute(self))
76            }
77        }
78    };
79    ([$Trait:ident $m:ident]+ $fun:ident ($a:ty) -> $r:ty) => {
80        #[unstable(feature = "stdarch_s390x", issue = "135681")]
81        impl $Trait for $a {
82            type Result = $r;
83            #[inline]
84            #[target_feature(enable = "vector")]
85            unsafe fn $m(self) -> Self::Result {
86                transmute($fun(transmute(self)))
87            }
88        }
89    };
90    ([$Trait:ident $m:ident] 1 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $sf: ident)) => {
91        impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char) -> vector_unsigned_char }
92        impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char) -> vector_signed_char }
93        impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short) -> vector_unsigned_short }
94        impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short) -> vector_signed_short }
95        impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int) -> vector_unsigned_int }
96        impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int) -> vector_signed_int }
97        impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_long_long) -> vector_unsigned_long_long }
98        impl_vec_trait!{ [$Trait $m] $sw (vector_signed_long_long) -> vector_signed_long_long }
99        impl_vec_trait!{ [$Trait $m] $sf (vector_float) -> vector_float }
100        impl_vec_trait!{ [$Trait $m] $sf (vector_double) -> vector_double }
101    };
102    ([$Trait:ident $m:ident] $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
103        #[unstable(feature = "stdarch_s390x", issue = "135681")]
104        impl $Trait<$b> for $a {
105            type Result = $r;
106            #[inline]
107            #[target_feature(enable = "vector")]
108            unsafe fn $m(self, b: $b) -> Self::Result {
109                $fun(transmute(self), transmute(b))
110            }
111        }
112    };
113    ([$Trait:ident $m:ident]+ $fun:ident ($a:ty, $b:ty) -> $r:ty) => {
114        #[unstable(feature = "stdarch_s390x", issue = "135681")]
115        impl $Trait<$b> for $a {
116            type Result = $r;
117            #[inline]
118            #[target_feature(enable = "vector")]
119            unsafe fn $m(self, b: $b) -> Self::Result {
120                transmute($fun(transmute(self), transmute(b)))
121            }
122        }
123    };
124    ([$Trait:ident $m:ident] $fun:ident ($a:ty, ~$b:ty) -> $r:ty) => {
125        impl_vec_trait!{ [$Trait $m] $fun ($a, $a) -> $r }
126        impl_vec_trait!{ [$Trait $m] $fun ($a, $b) -> $r }
127        impl_vec_trait!{ [$Trait $m] $fun ($b, $a) -> $r }
128    };
129    ([$Trait:ident $m:ident] ~($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $ug:ident, $sg:ident)) => {
130        impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, ~vector_bool_char) -> vector_unsigned_char }
131        impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, ~vector_bool_char) -> vector_signed_char }
132        impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, ~vector_bool_short) -> vector_unsigned_short }
133        impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, ~vector_bool_short) -> vector_signed_short }
134        impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, ~vector_bool_int) -> vector_unsigned_int }
135        impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, ~vector_bool_int) -> vector_signed_int }
136        impl_vec_trait!{ [$Trait $m] $ug (vector_unsigned_long_long, ~vector_bool_long_long) -> vector_unsigned_long_long }
137        impl_vec_trait!{ [$Trait $m] $sg (vector_signed_long_long, ~vector_bool_long_long) -> vector_signed_long_long }
138    };
139    ([$Trait:ident $m:ident] ~($fn:ident)) => {
140        impl_vec_trait!{ [$Trait $m] ~($fn, $fn, $fn, $fn, $fn, $fn, $fn, $fn) }
141    };
142    ([$Trait:ident $m:ident] 2 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $ug:ident, $sg:ident)) => {
143        impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
144        impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char, vector_signed_char) -> vector_signed_char }
145        impl_vec_trait!{ [$Trait $m] $uh (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
146        impl_vec_trait!{ [$Trait $m] $sh (vector_signed_short, vector_signed_short) -> vector_signed_short }
147        impl_vec_trait!{ [$Trait $m] $uw (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
148        impl_vec_trait!{ [$Trait $m] $sw (vector_signed_int, vector_signed_int) -> vector_signed_int }
149        impl_vec_trait!{ [$Trait $m] $ug (vector_unsigned_long_long, vector_unsigned_long_long) -> vector_unsigned_long_long }
150        impl_vec_trait!{ [$Trait $m] $sg (vector_signed_long_long, vector_signed_long_long) -> vector_signed_long_long }
151    };
152    ([$Trait:ident $m:ident] 2 ($fn:ident)) => {
153        impl_vec_trait!{ [$Trait $m] ($fn, $fn, $fn, $fn, $fn, $fn, $fn, $fn) }
154    };
155    ([$Trait:ident $m:ident]+ 2b ($b:ident, $h:ident, $w:ident, $g:ident)) => {
156        impl_vec_trait!{ [$Trait $m]+ $b (vector_bool_char, vector_bool_char) -> vector_bool_char }
157        impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
158        impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_signed_char) -> vector_signed_char }
159        impl_vec_trait!{ [$Trait $m]+ $h (vector_bool_short, vector_bool_short) -> vector_bool_short }
160        impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
161        impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_signed_short) -> vector_signed_short }
162        impl_vec_trait!{ [$Trait $m]+ $w (vector_bool_int, vector_bool_int) -> vector_bool_int }
163        impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
164        impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_signed_int) -> vector_signed_int }
165        impl_vec_trait!{ [$Trait $m]+ $g (vector_unsigned_long_long, vector_unsigned_long_long) -> vector_unsigned_long_long }
166        impl_vec_trait!{ [$Trait $m]+ $g (vector_signed_long_long, vector_signed_long_long) -> vector_signed_long_long }
167    };
168    ([$Trait:ident $m:ident]+ 2b ($fn:ident)) => {
169        impl_vec_trait!{ [$Trait $m]+ 2b ($fn, $fn, $fn, $fn) }
170    };
171    ([$Trait:ident $m:ident]+ 2c ($b:ident, $h:ident, $w:ident, $g:ident, $s:ident, $d:ident)) => {
172        impl_vec_trait!{ [$Trait $m]+ $b (vector_bool_char, vector_bool_char) -> vector_bool_char }
173        impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
174        impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_signed_char) -> vector_signed_char }
175        impl_vec_trait!{ [$Trait $m]+ $h (vector_bool_short, vector_bool_short) -> vector_bool_short }
176        impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
177        impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_signed_short) -> vector_signed_short }
178        impl_vec_trait!{ [$Trait $m]+ $w (vector_bool_int, vector_bool_int) -> vector_bool_int }
179        impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
180        impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_signed_int) -> vector_signed_int }
181        impl_vec_trait!{ [$Trait $m]+ $g (vector_unsigned_long_long, vector_unsigned_long_long) -> vector_unsigned_long_long }
182        impl_vec_trait!{ [$Trait $m]+ $g (vector_signed_long_long, vector_signed_long_long) -> vector_signed_long_long }
183        impl_vec_trait!{ [$Trait $m]+ $s (vector_float, vector_float) -> vector_float }
184        impl_vec_trait!{ [$Trait $m]+ $d (vector_double, vector_double) -> vector_double }
185    };
186    ([$Trait:ident $m:ident]+ 2c ($fn:ident)) => {
187        impl_vec_trait!{ [$Trait $m]+ 2c ($fn, $fn, $fn, $fn, $fn, $fn) }
188    };
189}
190
191macro_rules! s_t_l {
192    (i64x2) => {
193        vector_signed_long_long
194    };
195    (i32x4) => {
196        vector_signed_int
197    };
198    (i16x8) => {
199        vector_signed_short
200    };
201    (i8x16) => {
202        vector_signed_char
203    };
204
205    (u64x2) => {
206        vector_unsigned_long_long
207    };
208    (u32x4) => {
209        vector_unsigned_int
210    };
211    (u16x8) => {
212        vector_unsigned_short
213    };
214    (u8x16) => {
215        vector_unsigned_char
216    };
217
218    (f32x4) => {
219        vector_float
220    };
221    (f64x2) => {
222        vector_double
223    };
224}
225
226macro_rules! l_t_t {
227    (vector_signed_long_long) => {
228        i64
229    };
230    (vector_signed_int) => {
231        i32
232    };
233    (vector_signed_short) => {
234        i16
235    };
236    (vector_signed_char) => {
237        i8
238    };
239
240    (vector_unsigned_long_long ) => {
241        u64
242    };
243    (vector_unsigned_int ) => {
244        u32
245    };
246    (vector_unsigned_short ) => {
247        u16
248    };
249    (vector_unsigned_char ) => {
250        u8
251    };
252
253    (vector_float) => {
254        f32
255    };
256    (vector_double) => {
257        f64
258    };
259}
260
261macro_rules! t_t_l {
262    (i64) => {
263        vector_signed_long_long
264    };
265    (i32) => {
266        vector_signed_int
267    };
268    (i16) => {
269        vector_signed_short
270    };
271    (i8) => {
272        vector_signed_char
273    };
274
275    (u64) => {
276        vector_unsigned_long_long
277    };
278    (u32) => {
279        vector_unsigned_int
280    };
281    (u16) => {
282        vector_unsigned_short
283    };
284    (u8) => {
285        vector_unsigned_char
286    };
287
288    (f32) => {
289        vector_float
290    };
291    (f64) => {
292        vector_double
293    };
294}
295
296macro_rules! t_t_s {
297    (i64) => {
298        i64x2
299    };
300    (i32) => {
301        i32x4
302    };
303    (i16) => {
304        i16x8
305    };
306    (i8) => {
307        i8x16
308    };
309
310    (u64) => {
311        u64x2
312    };
313    (u32) => {
314        u32x4
315    };
316    (u16) => {
317        u16x8
318    };
319    (u8) => {
320        u8x16
321    };
322
323    (f32) => {
324        f32x4
325    };
326    (f64) => {
327        f64x2
328    };
329}
330
331macro_rules! t_u {
332    (vector_bool_char) => {
333        vector_unsigned_char
334    };
335    (vector_bool_short) => {
336        vector_unsigned_short
337    };
338    (vector_bool_int) => {
339        vector_unsigned_int
340    };
341    (vector_unsigned_char) => {
342        vector_unsigned_char
343    };
344    (vector_unsigned_short) => {
345        vector_unsigned_short
346    };
347    (vector_unsigned_int) => {
348        vector_unsigned_int
349    };
350    (vector_unsigned_long_long) => {
351        vector_unsigned_long_long
352    };
353    (vector_signed_char) => {
354        vector_unsigned_char
355    };
356    (vector_signed_short) => {
357        vector_unsigned_short
358    };
359    (vector_signed_int) => {
360        vector_unsigned_int
361    };
362    (vector_signed_long_long) => {
363        vector_unsigned_long_long
364    };
365    (vector_float) => {
366        vector_unsigned_int
367    };
368    (vector_double) => {
369        vector_unsigned_long_long
370    };
371}
372
373macro_rules! t_b {
374    (vector_bool_char) => {
375        vector_bool_char
376    };
377    (vector_bool_short) => {
378        vector_bool_short
379    };
380    (vector_bool_int) => {
381        vector_bool_int
382    };
383    (vector_signed_char) => {
384        vector_bool_char
385    };
386    (vector_signed_short) => {
387        vector_bool_short
388    };
389    (vector_signed_int) => {
390        vector_bool_int
391    };
392    (vector_signed_long_long) => {
393        vector_bool_long_long
394    };
395    (vector_unsigned_char) => {
396        vector_bool_char
397    };
398    (vector_unsigned_short) => {
399        vector_bool_short
400    };
401    (vector_unsigned_int) => {
402        vector_bool_int
403    };
404    (vector_unsigned_long_long) => {
405        vector_bool_long_long
406    };
407    (vector_float) => {
408        vector_bool_int
409    };
410    (vector_double) => {
411        vector_bool_long_long
412    };
413}
414
415macro_rules! impl_from {
416    ($s: ident) => {
417        #[unstable(feature = "stdarch_s390x", issue = "135681")]
418        impl From<$s> for s_t_l!($s) {
419            fn from (v: $s) -> Self {
420                unsafe {
421                    transmute(v)
422                }
423            }
424        }
425    };
426    ($($s: ident),*) => {
427        $(
428            impl_from! { $s }
429        )*
430    };
431}
432
433macro_rules! impl_neg {
434    ($s: ident : $zero: expr) => {
435        #[unstable(feature = "stdarch_s390x", issue = "135681")]
436        impl crate::ops::Neg for s_t_l!($s) {
437            type Output = s_t_l!($s);
438            fn neg(self) -> Self::Output {
439                unsafe { simd_neg(self) }
440            }
441        }
442    };
443}
444
445pub(crate) use impl_from;
446pub(crate) use impl_neg;
447pub(crate) use impl_vec_trait;
448pub(crate) use l_t_t;
449pub(crate) use s_t_l;
450pub(crate) use t_b;
451pub(crate) use t_t_l;
452pub(crate) use t_t_s;
453pub(crate) use t_u;
454pub(crate) use test_impl;