sha1_smol/
simd.rs
1use core::ops::{Add, BitAnd, BitOr, BitXor, Shl, Shr, Sub};
29
30#[derive(Clone, Copy, PartialEq, Eq)]
31#[allow(non_camel_case_types)]
32pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
33
34impl Add for u32x4 {
35 type Output = u32x4;
36
37 fn add(self, rhs: u32x4) -> u32x4 {
38 u32x4(
39 self.0.wrapping_add(rhs.0),
40 self.1.wrapping_add(rhs.1),
41 self.2.wrapping_add(rhs.2),
42 self.3.wrapping_add(rhs.3),
43 )
44 }
45}
46
47impl Sub for u32x4 {
48 type Output = u32x4;
49
50 fn sub(self, rhs: u32x4) -> u32x4 {
51 u32x4(
52 self.0.wrapping_sub(rhs.0),
53 self.1.wrapping_sub(rhs.1),
54 self.2.wrapping_sub(rhs.2),
55 self.3.wrapping_sub(rhs.3),
56 )
57 }
58}
59
60impl BitAnd for u32x4 {
61 type Output = u32x4;
62
63 fn bitand(self, rhs: u32x4) -> u32x4 {
64 u32x4(
65 self.0 & rhs.0,
66 self.1 & rhs.1,
67 self.2 & rhs.2,
68 self.3 & rhs.3,
69 )
70 }
71}
72
73impl BitOr for u32x4 {
74 type Output = u32x4;
75
76 fn bitor(self, rhs: u32x4) -> u32x4 {
77 u32x4(
78 self.0 | rhs.0,
79 self.1 | rhs.1,
80 self.2 | rhs.2,
81 self.3 | rhs.3,
82 )
83 }
84}
85
86impl BitXor for u32x4 {
87 type Output = u32x4;
88
89 fn bitxor(self, rhs: u32x4) -> u32x4 {
90 u32x4(
91 self.0 ^ rhs.0,
92 self.1 ^ rhs.1,
93 self.2 ^ rhs.2,
94 self.3 ^ rhs.3,
95 )
96 }
97}
98
99impl Shl<usize> for u32x4 {
100 type Output = u32x4;
101
102 fn shl(self, amt: usize) -> u32x4 {
103 u32x4(self.0 << amt, self.1 << amt, self.2 << amt, self.3 << amt)
104 }
105}
106
107impl Shl<u32x4> for u32x4 {
108 type Output = u32x4;
109
110 fn shl(self, rhs: u32x4) -> u32x4 {
111 u32x4(
112 self.0 << rhs.0,
113 self.1 << rhs.1,
114 self.2 << rhs.2,
115 self.3 << rhs.3,
116 )
117 }
118}
119
120impl Shr<usize> for u32x4 {
121 type Output = u32x4;
122
123 fn shr(self, amt: usize) -> u32x4 {
124 u32x4(self.0 >> amt, self.1 >> amt, self.2 >> amt, self.3 >> amt)
125 }
126}
127
128impl Shr<u32x4> for u32x4 {
129 type Output = u32x4;
130
131 fn shr(self, rhs: u32x4) -> u32x4 {
132 u32x4(
133 self.0 >> rhs.0,
134 self.1 >> rhs.1,
135 self.2 >> rhs.2,
136 self.3 >> rhs.3,
137 )
138 }
139}
140
141#[derive(Clone, Copy)]
142#[allow(non_camel_case_types)]
143pub struct u64x2(pub u64, pub u64);
144
145impl Add for u64x2 {
146 type Output = u64x2;
147
148 fn add(self, rhs: u64x2) -> u64x2 {
149 u64x2(self.0.wrapping_add(rhs.0), self.1.wrapping_add(rhs.1))
150 }
151}