]> git.proxmox.com Git - rustc.git/blob - src/stdsimd/coresimd/ppsv/api/shifts.rs
New upstream version 1.28.0+dfsg1
[rustc.git] / src / stdsimd / coresimd / ppsv / api / shifts.rs
1 //! Implements integer shifts.
2 #![allow(unused)]
3
4 macro_rules! impl_vector_shifts {
5 ($id:ident, $elem_ty:ident) => {
6 impl ::ops::Shl<$id> for $id {
7 type Output = Self;
8 #[inline]
9 fn shl(self, other: Self) -> Self {
10 use coresimd::simd_llvm::simd_shl;
11 unsafe { simd_shl(self, other) }
12 }
13 }
14 impl ::ops::Shr<$id> for $id {
15 type Output = Self;
16 #[inline]
17 fn shr(self, other: Self) -> Self {
18 use coresimd::simd_llvm::simd_shr;
19 unsafe { simd_shr(self, other) }
20 }
21 }
22 impl ::ops::ShlAssign<$id> for $id {
23 #[inline]
24 fn shl_assign(&mut self, other: Self) {
25 *self = *self << other;
26 }
27 }
28 impl ::ops::ShrAssign<$id> for $id {
29 #[inline]
30 fn shr_assign(&mut self, other: Self) {
31 *self = *self >> other;
32 }
33 }
34 };
35 }
36
37 #[cfg(test)]
38 macro_rules! test_vector_shift_ops {
39 ($id:ident, $elem_ty:ident) => {
40 #[test]
41 fn shift_ops() {
42 use coresimd::simd::$id;
43 use std::mem;
44 let z = $id::splat(0 as $elem_ty);
45 let o = $id::splat(1 as $elem_ty);
46 let t = $id::splat(2 as $elem_ty);
47 let f = $id::splat(4 as $elem_ty);
48
49 let max =
50 $id::splat((mem::size_of::<$elem_ty>() * 8 - 1) as $elem_ty);
51
52 // shr
53 assert_eq!(z >> z, z);
54 assert_eq!(z >> o, z);
55 assert_eq!(z >> t, z);
56 assert_eq!(z >> t, z);
57
58 assert_eq!(o >> z, o);
59 assert_eq!(t >> z, t);
60 assert_eq!(f >> z, f);
61 assert_eq!(f >> max, z);
62
63 assert_eq!(o >> o, z);
64 assert_eq!(t >> o, o);
65 assert_eq!(t >> t, z);
66 assert_eq!(f >> o, t);
67 assert_eq!(f >> t, o);
68 assert_eq!(f >> max, z);
69
70 // shl
71 assert_eq!(z << z, z);
72 assert_eq!(o << z, o);
73 assert_eq!(t << z, t);
74 assert_eq!(f << z, f);
75 assert_eq!(f << max, z);
76
77 assert_eq!(o << o, t);
78 assert_eq!(o << t, f);
79 assert_eq!(t << o, f);
80
81 {
82 // shr_assign
83 let mut v = o;
84 v >>= o;
85 assert_eq!(v, z);
86 }
87 {
88 // shl_assign
89 let mut v = o;
90 v <<= o;
91 assert_eq!(v, t);
92 }
93 }
94 };
95 }