1 //! Implements integer shifts.
4 macro_rules
! impl_vector_shifts
{
5 ($id
:ident
, $elem_ty
:ident
) => {
6 impl ::ops
::Shl
<$id
> for $id
{
9 fn shl(self, other
: Self) -> Self {
10 use coresimd
::simd_llvm
::simd_shl
;
11 unsafe { simd_shl(self, other) }
14 impl ::ops
::Shr
<$id
> for $id
{
17 fn shr(self, other
: Self) -> Self {
18 use coresimd
::simd_llvm
::simd_shr
;
19 unsafe { simd_shr(self, other) }
22 impl ::ops
::ShlAssign
<$id
> for $id
{
24 fn shl_assign(&mut self, other
: Self) {
25 *self = *self << other
;
28 impl ::ops
::ShrAssign
<$id
> for $id
{
30 fn shr_assign(&mut self, other
: Self) {
31 *self = *self >> other
;
38 macro_rules
! test_vector_shift_ops
{
39 ($id
:ident
, $elem_ty
:ident
) => {
42 use coresimd
::simd
::$id
;
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
);
50 $id
::splat((mem
::size_of
::<$elem_ty
>() * 8 - 1) as $elem_ty
);
53 assert_eq
!(z
>> z
, z
);
54 assert_eq
!(z
>> o
, z
);
55 assert_eq
!(z
>> t
, z
);
56 assert_eq
!(z
>> t
, z
);
58 assert_eq
!(o
>> z
, o
);
59 assert_eq
!(t
>> z
, t
);
60 assert_eq
!(f
>> z
, f
);
61 assert_eq
!(f
>> max
, z
);
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
);
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
);
77 assert_eq
!(o
<< o
, t
);
78 assert_eq
!(o
<< t
, f
);
79 assert_eq
!(t
<< o
, f
);