simply_simd/register/
integer.rs1use std::ops::*;
2
3use num_traits::NumCast;
4
5use crate::architectures::interface::*;
6use crate::register::Simd;
7use crate::simd_types::*;
8
9impl<T: SimdInteger, A: Arch> BitAnd for Simd<T, A> {
10 type Output = Self;
11 #[inline(always)]
12 fn bitand(self, rhs: Self) -> Self {
13 unsafe { Self::new(A::Vec::and(self.data, rhs.data)) }
14 }
15}
16
17impl<T: SimdInteger, A: Arch> BitOr for Simd<T, A> {
18 type Output = Self;
19 #[inline(always)]
20 fn bitor(self, rhs: Self) -> Self {
21 unsafe { Self::new(A::Vec::or(self.data, rhs.data)) }
22 }
23}
24
25impl<T: SimdInteger, A: Arch> BitXor for Simd<T, A> {
26 type Output = Self;
27 #[inline(always)]
28 fn bitxor(self, rhs: Self) -> Self {
29 unsafe { Self::new(A::Vec::xor(self.data, rhs.data)) }
30 }
31}
32
33impl<T: SimdInteger, A: Arch> Simd<T, A> {
34 #[inline(always)]
35 pub fn andnot(self, rhs: Self) -> Self {
36 unsafe { Self::new(A::Vec::and_not(self.data, rhs.data)) }
37 }
38}
39
40impl<T: SimdInteger, A: Arch> Not for Simd<T, A> {
41 type Output = Self;
42 #[inline(always)]
43 fn not(self) -> Self {
44 unsafe { Self::new(A::Vec::not(self.data)) }
45 }
46}
47
48impl<T: SimdIntegerNotByte, A: Arch> Shl<Simd<<T as SimdInteger>::Unsigned, A>>
50 for Simd<T, A>
51{
52 type Output = Self;
53 #[inline(always)]
54 fn shl(self, rhs: Simd<<T as SimdInteger>::Unsigned, A>) -> Self {
55 Self::new(unsafe {
56 match T::BIT_SIZE {
57 BitSize::Size64 => self.data.sllv_64(rhs.data),
58 BitSize::Size32 => self.data.sllv_32(rhs.data),
59 BitSize::Size16 => self.data.sllv_16(rhs.data),
60 _ => unreachable!(),
61 }
62 })
63 }
64}
65
66impl<T: SimdIntegerNotByte, A: Arch> Shr<Simd<<T as SimdInteger>::Unsigned, A>>
67 for Simd<T, A>
68{
69 type Output = Self;
70 #[inline(always)]
71 fn shr(self, rhs: Simd<<T as SimdInteger>::Unsigned, A>) -> Self {
72 unsafe {
73 Self::new(match T::TYPE {
74 SimdType::U64 => self.data.srlv_64(rhs.data),
75 SimdType::U32 => self.data.srlv_32(rhs.data),
76 SimdType::U16 => self.data.srlv_16(rhs.data),
77 SimdType::I64 => self.data.srav_64(rhs.data),
78 SimdType::I32 => self.data.srav_32(rhs.data),
79 SimdType::I16 => self.data.srav_16(rhs.data),
80 _ => unreachable!(),
81 })
82 }
83 }
84}
85
86impl<T: SimdIntegerNotByte, A: Arch> Shl<usize> for Simd<T, A> {
89 type Output = Self;
90 #[inline(always)]
91 fn shl(self, rhs: usize) -> Self {
92 let shift = Simd::<<T as SimdInteger>::Unsigned, A>::splat(NumCast::from(rhs).unwrap());
93 self << shift
94 }
95}
96
97impl<T: SimdIntegerNotByte, A: Arch> Shr<usize> for Simd<T, A> {
98 type Output = Self;
99 #[inline(always)]
100 fn shr(self, rhs: usize) -> Self {
101 let shift = Simd::<<T as SimdInteger>::Unsigned, A>::splat(NumCast::from(rhs).unwrap());
102 self >> shift
103 }
104}
105
106impl<T: SimdMulType, A: Arch> Mul for Simd<T, A> {
109 type Output = Self;
110 #[inline(always)]
111 fn mul(self, rhs: Self) -> Self {
112 unsafe {
113 Self::new(match T::TYPE {
114 SimdType::F64 => self.data.f64_mul(rhs.data),
115 SimdType::F32 => self.data.f32_mul(rhs.data),
116 SimdType::I32 => self.data.i32_mul(rhs.data),
117 SimdType::I16 => self.data.i16_mul(rhs.data),
118 SimdType::U32 => self.data.i32_mul(rhs.data),
119 SimdType::U16 => self.data.i16_mul(rhs.data),
120 _ => unreachable!(),
121 })
122 }
123 }
124}
125
126impl<T: SimdFloat, A: Arch> Div for Simd<T, A> {
127 type Output = Self;
128 #[inline(always)]
129 fn div(self, rhs: Self) -> Self {
130 unsafe {
131 Self::new(match T::TYPE {
132 SimdType::F64 => self.data.f64_div(rhs.data),
133 SimdType::F32 => self.data.f32_div(rhs.data),
134 _ => unreachable!(),
135 })
136 }
137 }
138}
139
140impl<T: SimdInteger + HasSigned, A: Arch> Simd<T, A> {
165 #[inline(always)]
166 pub fn cast_signed(self) -> Simd<<T as SimdInteger>::Signed, A> {
167 Simd::new(self.data)
168 }
169}
170
171impl<T: SimdInteger + HasUnsigned, A: Arch> Simd<T, A> {
172 #[inline(always)]
173 pub fn cast_unsigned(self) -> Simd<<T as SimdInteger>::Unsigned, A> {
174 Simd::new(self.data)
175 }
176}
177
178impl<T: SimdInteger + HasFloat, A: Arch> Simd<T, A> {
179 #[inline(always)]
180 pub fn cast_float(self) -> Simd<<T as HasFloat>::Float, A> {
181 unsafe { Simd::new(self.data.int_to_float()) }
182 }
183}
184
185