/rust/registry/src/index.crates.io-6f17d22bba15001f/sha1_smol-1.0.1/src/simd.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2006-2009 Graydon Hoare |
2 | | // Copyright (c) 2009-2013 Mozilla Foundation |
3 | | |
4 | | // Permission is hereby granted, free of charge, to any |
5 | | // person obtaining a copy of this software and associated |
6 | | // documentation files (the "Software"), to deal in the |
7 | | // Software without restriction, including without |
8 | | // limitation the rights to use, copy, modify, merge, |
9 | | // publish, distribute, sublicense, and/or sell copies of |
10 | | // the Software, and to permit persons to whom the Software |
11 | | // is furnished to do so, subject to the following |
12 | | // conditions: |
13 | | |
14 | | // The above copyright notice and this permission notice |
15 | | // shall be included in all copies or substantial portions |
16 | | // of the Software. |
17 | | |
18 | | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF |
19 | | // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
20 | | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
21 | | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
22 | | // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
23 | | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
24 | | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
25 | | // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
26 | | // DEALINGS IN THE SOFTWARE. |
27 | | |
28 | | use core::ops::{Add, BitAnd, BitOr, BitXor, Shl, Shr, Sub}; |
29 | | |
30 | | #[derive(Clone, Copy, PartialEq, Eq)] |
31 | | #[allow(non_camel_case_types)] |
32 | | pub struct u32x4(pub u32, pub u32, pub u32, pub u32); |
33 | | |
34 | | impl Add for u32x4 { |
35 | | type Output = u32x4; |
36 | | |
37 | 0 | fn add(self, rhs: u32x4) -> u32x4 { |
38 | 0 | u32x4( |
39 | 0 | self.0.wrapping_add(rhs.0), |
40 | 0 | self.1.wrapping_add(rhs.1), |
41 | 0 | self.2.wrapping_add(rhs.2), |
42 | 0 | self.3.wrapping_add(rhs.3), |
43 | 0 | ) |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl Sub for u32x4 { |
48 | | type Output = u32x4; |
49 | | |
50 | 0 | fn sub(self, rhs: u32x4) -> u32x4 { |
51 | 0 | u32x4( |
52 | 0 | self.0.wrapping_sub(rhs.0), |
53 | 0 | self.1.wrapping_sub(rhs.1), |
54 | 0 | self.2.wrapping_sub(rhs.2), |
55 | 0 | self.3.wrapping_sub(rhs.3), |
56 | 0 | ) |
57 | 0 | } |
58 | | } |
59 | | |
60 | | impl BitAnd for u32x4 { |
61 | | type Output = u32x4; |
62 | | |
63 | 0 | fn bitand(self, rhs: u32x4) -> u32x4 { |
64 | 0 | u32x4( |
65 | 0 | self.0 & rhs.0, |
66 | 0 | self.1 & rhs.1, |
67 | 0 | self.2 & rhs.2, |
68 | 0 | self.3 & rhs.3, |
69 | 0 | ) |
70 | 0 | } |
71 | | } |
72 | | |
73 | | impl BitOr for u32x4 { |
74 | | type Output = u32x4; |
75 | | |
76 | 0 | fn bitor(self, rhs: u32x4) -> u32x4 { |
77 | 0 | u32x4( |
78 | 0 | self.0 | rhs.0, |
79 | 0 | self.1 | rhs.1, |
80 | 0 | self.2 | rhs.2, |
81 | 0 | self.3 | rhs.3, |
82 | 0 | ) |
83 | 0 | } |
84 | | } |
85 | | |
86 | | impl BitXor for u32x4 { |
87 | | type Output = u32x4; |
88 | | |
89 | 0 | fn bitxor(self, rhs: u32x4) -> u32x4 { |
90 | 0 | u32x4( |
91 | 0 | self.0 ^ rhs.0, |
92 | 0 | self.1 ^ rhs.1, |
93 | 0 | self.2 ^ rhs.2, |
94 | 0 | self.3 ^ rhs.3, |
95 | 0 | ) |
96 | 0 | } |
97 | | } |
98 | | |
99 | | impl Shl<usize> for u32x4 { |
100 | | type Output = u32x4; |
101 | | |
102 | 0 | fn shl(self, amt: usize) -> u32x4 { |
103 | 0 | u32x4(self.0 << amt, self.1 << amt, self.2 << amt, self.3 << amt) |
104 | 0 | } |
105 | | } |
106 | | |
107 | | impl Shl<u32x4> for u32x4 { |
108 | | type Output = u32x4; |
109 | | |
110 | 0 | fn shl(self, rhs: u32x4) -> u32x4 { |
111 | 0 | u32x4( |
112 | 0 | self.0 << rhs.0, |
113 | 0 | self.1 << rhs.1, |
114 | 0 | self.2 << rhs.2, |
115 | 0 | self.3 << rhs.3, |
116 | 0 | ) |
117 | 0 | } |
118 | | } |
119 | | |
120 | | impl Shr<usize> for u32x4 { |
121 | | type Output = u32x4; |
122 | | |
123 | 0 | fn shr(self, amt: usize) -> u32x4 { |
124 | 0 | u32x4(self.0 >> amt, self.1 >> amt, self.2 >> amt, self.3 >> amt) |
125 | 0 | } |
126 | | } |
127 | | |
128 | | impl Shr<u32x4> for u32x4 { |
129 | | type Output = u32x4; |
130 | | |
131 | 0 | fn shr(self, rhs: u32x4) -> u32x4 { |
132 | 0 | u32x4( |
133 | 0 | self.0 >> rhs.0, |
134 | 0 | self.1 >> rhs.1, |
135 | 0 | self.2 >> rhs.2, |
136 | 0 | self.3 >> rhs.3, |
137 | 0 | ) |
138 | 0 | } |
139 | | } |
140 | | |
141 | | #[derive(Clone, Copy)] |
142 | | #[allow(non_camel_case_types)] |
143 | | pub struct u64x2(pub u64, pub u64); |
144 | | |
145 | | impl Add for u64x2 { |
146 | | type Output = u64x2; |
147 | | |
148 | 0 | fn add(self, rhs: u64x2) -> u64x2 { |
149 | 0 | u64x2(self.0.wrapping_add(rhs.0), self.1.wrapping_add(rhs.1)) |
150 | 0 | } |
151 | | } |