]> git.proxmox.com Git - rustc.git/blame - src/stdsimd/coresimd/ppsv/api/shifts.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / stdsimd / coresimd / ppsv / api / shifts.rs
CommitLineData
0531ce1d 1//! Implements integer shifts.
83c7162d 2#![allow(unused)]
0531ce1d 3
83c7162d
XL
4macro_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) }
0531ce1d 12 }
83c7162d
XL
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) }
0531ce1d 20 }
83c7162d
XL
21 }
22 impl ::ops::ShlAssign<$id> for $id {
23 #[inline]
24 fn shl_assign(&mut self, other: Self) {
25 *self = *self << other;
0531ce1d 26 }
83c7162d
XL
27 }
28 impl ::ops::ShrAssign<$id> for $id {
29 #[inline]
30 fn shr_assign(&mut self, other: Self) {
31 *self = *self >> other;
0531ce1d 32 }
83c7162d
XL
33 }
34 };
0531ce1d
XL
35}
36
37#[cfg(test)]
83c7162d
XL
38macro_rules! test_vector_shift_ops {
39 ($id:ident, $elem_ty:ident) => {
0531ce1d
XL
40 #[test]
41 fn shift_ops() {
83c7162d
XL
42 use coresimd::simd::$id;
43 use std::mem;
0531ce1d
XL
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
83c7162d
XL
49 let max =
50 $id::splat((mem::size_of::<$elem_ty>() * 8 - 1) as $elem_ty);
0531ce1d 51
83c7162d
XL
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);
0531ce1d 57
83c7162d
XL
58 assert_eq!(o >> z, o);
59 assert_eq!(t >> z, t);
60 assert_eq!(f >> z, f);
61 assert_eq!(f >> max, z);
0531ce1d 62
83c7162d
XL
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);
0531ce1d 69
83c7162d
XL
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);
0531ce1d 76
83c7162d
XL
77 assert_eq!(o << o, t);
78 assert_eq!(o << t, f);
79 assert_eq!(t << o, f);
0531ce1d 80
83c7162d
XL
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 }
0531ce1d
XL
93 }
94 };
95}