Bitcoin ABC  0.26.3
P2P Digital Currency
sha256_avx2.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifdef ENABLE_AVX2
6 
7 #include <cstdint>
8 #include <immintrin.h>
9 
10 #include <crypto/common.h>
11 
12 namespace sha256d64_avx2 {
13 namespace {
14 
15  __m256i inline K(uint32_t x) { return _mm256_set1_epi32(x); }
16 
17  __m256i inline Add(__m256i x, __m256i y) { return _mm256_add_epi32(x, y); }
18  __m256i inline Add(__m256i x, __m256i y, __m256i z) {
19  return Add(Add(x, y), z);
20  }
21  __m256i inline Add(__m256i x, __m256i y, __m256i z, __m256i w) {
22  return Add(Add(x, y), Add(z, w));
23  }
24  __m256i inline Add(__m256i x, __m256i y, __m256i z, __m256i w, __m256i v) {
25  return Add(Add(x, y, z), Add(w, v));
26  }
27  __m256i inline Inc(__m256i &x, __m256i y) {
28  x = Add(x, y);
29  return x;
30  }
31  __m256i inline Inc(__m256i &x, __m256i y, __m256i z) {
32  x = Add(x, y, z);
33  return x;
34  }
35  __m256i inline Inc(__m256i &x, __m256i y, __m256i z, __m256i w) {
36  x = Add(x, y, z, w);
37  return x;
38  }
39  __m256i inline Xor(__m256i x, __m256i y) { return _mm256_xor_si256(x, y); }
40  __m256i inline Xor(__m256i x, __m256i y, __m256i z) {
41  return Xor(Xor(x, y), z);
42  }
43  __m256i inline Or(__m256i x, __m256i y) { return _mm256_or_si256(x, y); }
44  __m256i inline And(__m256i x, __m256i y) { return _mm256_and_si256(x, y); }
45  __m256i inline ShR(__m256i x, int n) { return _mm256_srli_epi32(x, n); }
46  __m256i inline ShL(__m256i x, int n) { return _mm256_slli_epi32(x, n); }
47 
48  __m256i inline Ch(__m256i x, __m256i y, __m256i z) {
49  return Xor(z, And(x, Xor(y, z)));
50  }
51  __m256i inline Maj(__m256i x, __m256i y, __m256i z) {
52  return Or(And(x, y), And(z, Or(x, y)));
53  }
54  __m256i inline Sigma0(__m256i x) {
55  return Xor(Or(ShR(x, 2), ShL(x, 30)), Or(ShR(x, 13), ShL(x, 19)),
56  Or(ShR(x, 22), ShL(x, 10)));
57  }
58  __m256i inline Sigma1(__m256i x) {
59  return Xor(Or(ShR(x, 6), ShL(x, 26)), Or(ShR(x, 11), ShL(x, 21)),
60  Or(ShR(x, 25), ShL(x, 7)));
61  }
62  __m256i inline sigma0(__m256i x) {
63  return Xor(Or(ShR(x, 7), ShL(x, 25)), Or(ShR(x, 18), ShL(x, 14)),
64  ShR(x, 3));
65  }
66  __m256i inline sigma1(__m256i x) {
67  return Xor(Or(ShR(x, 17), ShL(x, 15)), Or(ShR(x, 19), ShL(x, 13)),
68  ShR(x, 10));
69  }
70 
72  inline void __attribute__((always_inline))
73  Round(__m256i a, __m256i b, __m256i c, __m256i &d, __m256i e, __m256i f,
74  __m256i g, __m256i &h, __m256i k) {
75  __m256i t1 = Add(h, Sigma1(e), Ch(e, f, g), k);
76  __m256i t2 = Add(Sigma0(a), Maj(a, b, c));
77  d = Add(d, t1);
78  h = Add(t1, t2);
79  }
80 
81  __m256i inline Read8(const uint8_t *chunk, int offset) {
82  __m256i ret = _mm256_set_epi32(
83  ReadLE32(chunk + 0 + offset), ReadLE32(chunk + 64 + offset),
84  ReadLE32(chunk + 128 + offset), ReadLE32(chunk + 192 + offset),
85  ReadLE32(chunk + 256 + offset), ReadLE32(chunk + 320 + offset),
86  ReadLE32(chunk + 384 + offset), ReadLE32(chunk + 448 + offset));
87  return _mm256_shuffle_epi8(
88  ret, _mm256_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL,
89  0x00010203UL, 0x0C0D0E0FUL, 0x08090A0BUL,
90  0x04050607UL, 0x00010203UL));
91  }
92 
93  inline void Write8(uint8_t *out, int offset, __m256i v) {
94  v = _mm256_shuffle_epi8(
95  v, _mm256_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL,
96  0x00010203UL, 0x0C0D0E0FUL, 0x08090A0BUL,
97  0x04050607UL, 0x00010203UL));
98  WriteLE32(out + 0 + offset, _mm256_extract_epi32(v, 7));
99  WriteLE32(out + 32 + offset, _mm256_extract_epi32(v, 6));
100  WriteLE32(out + 64 + offset, _mm256_extract_epi32(v, 5));
101  WriteLE32(out + 96 + offset, _mm256_extract_epi32(v, 4));
102  WriteLE32(out + 128 + offset, _mm256_extract_epi32(v, 3));
103  WriteLE32(out + 160 + offset, _mm256_extract_epi32(v, 2));
104  WriteLE32(out + 192 + offset, _mm256_extract_epi32(v, 1));
105  WriteLE32(out + 224 + offset, _mm256_extract_epi32(v, 0));
106  }
107 } // namespace
108 
109 void Transform_8way(uint8_t *out, const uint8_t *in) {
110  // Transform 1
111  __m256i a = K(0x6a09e667ul);
112  __m256i b = K(0xbb67ae85ul);
113  __m256i c = K(0x3c6ef372ul);
114  __m256i d = K(0xa54ff53aul);
115  __m256i e = K(0x510e527ful);
116  __m256i f = K(0x9b05688cul);
117  __m256i g = K(0x1f83d9abul);
118  __m256i h = K(0x5be0cd19ul);
119 
120  __m256i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14,
121  w15;
122 
123  Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0 = Read8(in, 0)));
124  Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1 = Read8(in, 4)));
125  Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2 = Read8(in, 8)));
126  Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3 = Read8(in, 12)));
127  Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4 = Read8(in, 16)));
128  Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5 = Read8(in, 20)));
129  Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6 = Read8(in, 24)));
130  Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7 = Read8(in, 28)));
131  Round(a, b, c, d, e, f, g, h, Add(K(0xd807aa98ul), w8 = Read8(in, 32)));
132  Round(h, a, b, c, d, e, f, g, Add(K(0x12835b01ul), w9 = Read8(in, 36)));
133  Round(g, h, a, b, c, d, e, f, Add(K(0x243185beul), w10 = Read8(in, 40)));
134  Round(f, g, h, a, b, c, d, e, Add(K(0x550c7dc3ul), w11 = Read8(in, 44)));
135  Round(e, f, g, h, a, b, c, d, Add(K(0x72be5d74ul), w12 = Read8(in, 48)));
136  Round(d, e, f, g, h, a, b, c, Add(K(0x80deb1feul), w13 = Read8(in, 52)));
137  Round(c, d, e, f, g, h, a, b, Add(K(0x9bdc06a7ul), w14 = Read8(in, 56)));
138  Round(b, c, d, e, f, g, h, a, Add(K(0xc19bf174ul), w15 = Read8(in, 60)));
139  Round(a, b, c, d, e, f, g, h,
140  Add(K(0xe49b69c1ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
141  Round(h, a, b, c, d, e, f, g,
142  Add(K(0xefbe4786ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
143  Round(g, h, a, b, c, d, e, f,
144  Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
145  Round(f, g, h, a, b, c, d, e,
146  Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
147  Round(e, f, g, h, a, b, c, d,
148  Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), w13, sigma0(w5))));
149  Round(d, e, f, g, h, a, b, c,
150  Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
151  Round(c, d, e, f, g, h, a, b,
152  Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
153  Round(b, c, d, e, f, g, h, a,
154  Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
155  Round(a, b, c, d, e, f, g, h,
156  Add(K(0x983e5152ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
157  Round(h, a, b, c, d, e, f, g,
158  Add(K(0xa831c66dul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
159  Round(g, h, a, b, c, d, e, f,
160  Add(K(0xb00327c8ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
161  Round(f, g, h, a, b, c, d, e,
162  Add(K(0xbf597fc7ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
163  Round(e, f, g, h, a, b, c, d,
164  Add(K(0xc6e00bf3ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
165  Round(d, e, f, g, h, a, b, c,
166  Add(K(0xd5a79147ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
167  Round(c, d, e, f, g, h, a, b,
168  Add(K(0x06ca6351ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
169  Round(b, c, d, e, f, g, h, a,
170  Add(K(0x14292967ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
171  Round(a, b, c, d, e, f, g, h,
172  Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
173  Round(h, a, b, c, d, e, f, g,
174  Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
175  Round(g, h, a, b, c, d, e, f,
176  Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
177  Round(f, g, h, a, b, c, d, e,
178  Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
179  Round(e, f, g, h, a, b, c, d,
180  Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
181  Round(d, e, f, g, h, a, b, c,
182  Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
183  Round(c, d, e, f, g, h, a, b,
184  Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
185  Round(b, c, d, e, f, g, h, a,
186  Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
187  Round(a, b, c, d, e, f, g, h,
188  Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
189  Round(h, a, b, c, d, e, f, g,
190  Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
191  Round(g, h, a, b, c, d, e, f,
192  Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
193  Round(f, g, h, a, b, c, d, e,
194  Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
195  Round(e, f, g, h, a, b, c, d,
196  Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
197  Round(d, e, f, g, h, a, b, c,
198  Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
199  Round(c, d, e, f, g, h, a, b,
200  Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
201  Round(b, c, d, e, f, g, h, a,
202  Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
203  Round(a, b, c, d, e, f, g, h,
204  Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
205  Round(h, a, b, c, d, e, f, g,
206  Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
207  Round(g, h, a, b, c, d, e, f,
208  Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
209  Round(f, g, h, a, b, c, d, e,
210  Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
211  Round(e, f, g, h, a, b, c, d,
212  Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
213  Round(d, e, f, g, h, a, b, c,
214  Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
215  Round(c, d, e, f, g, h, a, b,
216  Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
217  Round(b, c, d, e, f, g, h, a,
218  Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
219  Round(a, b, c, d, e, f, g, h,
220  Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
221  Round(h, a, b, c, d, e, f, g,
222  Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
223  Round(g, h, a, b, c, d, e, f,
224  Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
225  Round(f, g, h, a, b, c, d, e,
226  Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
227  Round(e, f, g, h, a, b, c, d,
228  Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
229  Round(d, e, f, g, h, a, b, c,
230  Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
231  Round(c, d, e, f, g, h, a, b,
232  Add(K(0xbef9a3f7ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
233  Round(b, c, d, e, f, g, h, a,
234  Add(K(0xc67178f2ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
235 
236  a = Add(a, K(0x6a09e667ul));
237  b = Add(b, K(0xbb67ae85ul));
238  c = Add(c, K(0x3c6ef372ul));
239  d = Add(d, K(0xa54ff53aul));
240  e = Add(e, K(0x510e527ful));
241  f = Add(f, K(0x9b05688cul));
242  g = Add(g, K(0x1f83d9abul));
243  h = Add(h, K(0x5be0cd19ul));
244 
245  __m256i t0 = a, t1 = b, t2 = c, t3 = d, t4 = e, t5 = f, t6 = g, t7 = h;
246 
247  // Transform 2
248  Round(a, b, c, d, e, f, g, h, K(0xc28a2f98ul));
249  Round(h, a, b, c, d, e, f, g, K(0x71374491ul));
250  Round(g, h, a, b, c, d, e, f, K(0xb5c0fbcful));
251  Round(f, g, h, a, b, c, d, e, K(0xe9b5dba5ul));
252  Round(e, f, g, h, a, b, c, d, K(0x3956c25bul));
253  Round(d, e, f, g, h, a, b, c, K(0x59f111f1ul));
254  Round(c, d, e, f, g, h, a, b, K(0x923f82a4ul));
255  Round(b, c, d, e, f, g, h, a, K(0xab1c5ed5ul));
256  Round(a, b, c, d, e, f, g, h, K(0xd807aa98ul));
257  Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
258  Round(g, h, a, b, c, d, e, f, K(0x243185beul));
259  Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
260  Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
261  Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
262  Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
263  Round(b, c, d, e, f, g, h, a, K(0xc19bf374ul));
264  Round(a, b, c, d, e, f, g, h, K(0x649b69c1ul));
265  Round(h, a, b, c, d, e, f, g, K(0xf0fe4786ul));
266  Round(g, h, a, b, c, d, e, f, K(0x0fe1edc6ul));
267  Round(f, g, h, a, b, c, d, e, K(0x240cf254ul));
268  Round(e, f, g, h, a, b, c, d, K(0x4fe9346ful));
269  Round(d, e, f, g, h, a, b, c, K(0x6cc984beul));
270  Round(c, d, e, f, g, h, a, b, K(0x61b9411eul));
271  Round(b, c, d, e, f, g, h, a, K(0x16f988faul));
272  Round(a, b, c, d, e, f, g, h, K(0xf2c65152ul));
273  Round(h, a, b, c, d, e, f, g, K(0xa88e5a6dul));
274  Round(g, h, a, b, c, d, e, f, K(0xb019fc65ul));
275  Round(f, g, h, a, b, c, d, e, K(0xb9d99ec7ul));
276  Round(e, f, g, h, a, b, c, d, K(0x9a1231c3ul));
277  Round(d, e, f, g, h, a, b, c, K(0xe70eeaa0ul));
278  Round(c, d, e, f, g, h, a, b, K(0xfdb1232bul));
279  Round(b, c, d, e, f, g, h, a, K(0xc7353eb0ul));
280  Round(a, b, c, d, e, f, g, h, K(0x3069bad5ul));
281  Round(h, a, b, c, d, e, f, g, K(0xcb976d5ful));
282  Round(g, h, a, b, c, d, e, f, K(0x5a0f118ful));
283  Round(f, g, h, a, b, c, d, e, K(0xdc1eeefdul));
284  Round(e, f, g, h, a, b, c, d, K(0x0a35b689ul));
285  Round(d, e, f, g, h, a, b, c, K(0xde0b7a04ul));
286  Round(c, d, e, f, g, h, a, b, K(0x58f4ca9dul));
287  Round(b, c, d, e, f, g, h, a, K(0xe15d5b16ul));
288  Round(a, b, c, d, e, f, g, h, K(0x007f3e86ul));
289  Round(h, a, b, c, d, e, f, g, K(0x37088980ul));
290  Round(g, h, a, b, c, d, e, f, K(0xa507ea32ul));
291  Round(f, g, h, a, b, c, d, e, K(0x6fab9537ul));
292  Round(e, f, g, h, a, b, c, d, K(0x17406110ul));
293  Round(d, e, f, g, h, a, b, c, K(0x0d8cd6f1ul));
294  Round(c, d, e, f, g, h, a, b, K(0xcdaa3b6dul));
295  Round(b, c, d, e, f, g, h, a, K(0xc0bbbe37ul));
296  Round(a, b, c, d, e, f, g, h, K(0x83613bdaul));
297  Round(h, a, b, c, d, e, f, g, K(0xdb48a363ul));
298  Round(g, h, a, b, c, d, e, f, K(0x0b02e931ul));
299  Round(f, g, h, a, b, c, d, e, K(0x6fd15ca7ul));
300  Round(e, f, g, h, a, b, c, d, K(0x521afacaul));
301  Round(d, e, f, g, h, a, b, c, K(0x31338431ul));
302  Round(c, d, e, f, g, h, a, b, K(0x6ed41a95ul));
303  Round(b, c, d, e, f, g, h, a, K(0x6d437890ul));
304  Round(a, b, c, d, e, f, g, h, K(0xc39c91f2ul));
305  Round(h, a, b, c, d, e, f, g, K(0x9eccabbdul));
306  Round(g, h, a, b, c, d, e, f, K(0xb5c9a0e6ul));
307  Round(f, g, h, a, b, c, d, e, K(0x532fb63cul));
308  Round(e, f, g, h, a, b, c, d, K(0xd2c741c6ul));
309  Round(d, e, f, g, h, a, b, c, K(0x07237ea3ul));
310  Round(c, d, e, f, g, h, a, b, K(0xa4954b68ul));
311  Round(b, c, d, e, f, g, h, a, K(0x4c191d76ul));
312 
313  w0 = Add(t0, a);
314  w1 = Add(t1, b);
315  w2 = Add(t2, c);
316  w3 = Add(t3, d);
317  w4 = Add(t4, e);
318  w5 = Add(t5, f);
319  w6 = Add(t6, g);
320  w7 = Add(t7, h);
321 
322  // Transform 3
323  a = K(0x6a09e667ul);
324  b = K(0xbb67ae85ul);
325  c = K(0x3c6ef372ul);
326  d = K(0xa54ff53aul);
327  e = K(0x510e527ful);
328  f = K(0x9b05688cul);
329  g = K(0x1f83d9abul);
330  h = K(0x5be0cd19ul);
331 
332  Round(a, b, c, d, e, f, g, h, Add(K(0x428a2f98ul), w0));
333  Round(h, a, b, c, d, e, f, g, Add(K(0x71374491ul), w1));
334  Round(g, h, a, b, c, d, e, f, Add(K(0xb5c0fbcful), w2));
335  Round(f, g, h, a, b, c, d, e, Add(K(0xe9b5dba5ul), w3));
336  Round(e, f, g, h, a, b, c, d, Add(K(0x3956c25bul), w4));
337  Round(d, e, f, g, h, a, b, c, Add(K(0x59f111f1ul), w5));
338  Round(c, d, e, f, g, h, a, b, Add(K(0x923f82a4ul), w6));
339  Round(b, c, d, e, f, g, h, a, Add(K(0xab1c5ed5ul), w7));
340  Round(a, b, c, d, e, f, g, h, K(0x5807aa98ul));
341  Round(h, a, b, c, d, e, f, g, K(0x12835b01ul));
342  Round(g, h, a, b, c, d, e, f, K(0x243185beul));
343  Round(f, g, h, a, b, c, d, e, K(0x550c7dc3ul));
344  Round(e, f, g, h, a, b, c, d, K(0x72be5d74ul));
345  Round(d, e, f, g, h, a, b, c, K(0x80deb1feul));
346  Round(c, d, e, f, g, h, a, b, K(0x9bdc06a7ul));
347  Round(b, c, d, e, f, g, h, a, K(0xc19bf274ul));
348  Round(a, b, c, d, e, f, g, h, Add(K(0xe49b69c1ul), Inc(w0, sigma0(w1))));
349  Round(h, a, b, c, d, e, f, g,
350  Add(K(0xefbe4786ul), Inc(w1, K(0xa00000ul), sigma0(w2))));
351  Round(g, h, a, b, c, d, e, f,
352  Add(K(0x0fc19dc6ul), Inc(w2, sigma1(w0), sigma0(w3))));
353  Round(f, g, h, a, b, c, d, e,
354  Add(K(0x240ca1ccul), Inc(w3, sigma1(w1), sigma0(w4))));
355  Round(e, f, g, h, a, b, c, d,
356  Add(K(0x2de92c6ful), Inc(w4, sigma1(w2), sigma0(w5))));
357  Round(d, e, f, g, h, a, b, c,
358  Add(K(0x4a7484aaul), Inc(w5, sigma1(w3), sigma0(w6))));
359  Round(c, d, e, f, g, h, a, b,
360  Add(K(0x5cb0a9dcul), Inc(w6, sigma1(w4), K(0x100ul), sigma0(w7))));
361  Round(b, c, d, e, f, g, h, a,
362  Add(K(0x76f988daul), Inc(w7, sigma1(w5), w0, K(0x11002000ul))));
363  Round(a, b, c, d, e, f, g, h,
364  Add(K(0x983e5152ul), w8 = Add(K(0x80000000ul), sigma1(w6), w1)));
365  Round(h, a, b, c, d, e, f, g,
366  Add(K(0xa831c66dul), w9 = Add(sigma1(w7), w2)));
367  Round(g, h, a, b, c, d, e, f,
368  Add(K(0xb00327c8ul), w10 = Add(sigma1(w8), w3)));
369  Round(f, g, h, a, b, c, d, e,
370  Add(K(0xbf597fc7ul), w11 = Add(sigma1(w9), w4)));
371  Round(e, f, g, h, a, b, c, d,
372  Add(K(0xc6e00bf3ul), w12 = Add(sigma1(w10), w5)));
373  Round(d, e, f, g, h, a, b, c,
374  Add(K(0xd5a79147ul), w13 = Add(sigma1(w11), w6)));
375  Round(c, d, e, f, g, h, a, b,
376  Add(K(0x06ca6351ul), w14 = Add(sigma1(w12), w7, K(0x400022ul))));
377  Round(b, c, d, e, f, g, h, a,
378  Add(K(0x14292967ul),
379  w15 = Add(K(0x100ul), sigma1(w13), w8, sigma0(w0))));
380  Round(a, b, c, d, e, f, g, h,
381  Add(K(0x27b70a85ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
382  Round(h, a, b, c, d, e, f, g,
383  Add(K(0x2e1b2138ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
384  Round(g, h, a, b, c, d, e, f,
385  Add(K(0x4d2c6dfcul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
386  Round(f, g, h, a, b, c, d, e,
387  Add(K(0x53380d13ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
388  Round(e, f, g, h, a, b, c, d,
389  Add(K(0x650a7354ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
390  Round(d, e, f, g, h, a, b, c,
391  Add(K(0x766a0abbul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
392  Round(c, d, e, f, g, h, a, b,
393  Add(K(0x81c2c92eul), Inc(w6, sigma1(w4), w15, sigma0(w7))));
394  Round(b, c, d, e, f, g, h, a,
395  Add(K(0x92722c85ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
396  Round(a, b, c, d, e, f, g, h,
397  Add(K(0xa2bfe8a1ul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
398  Round(h, a, b, c, d, e, f, g,
399  Add(K(0xa81a664bul), Inc(w9, sigma1(w7), w2, sigma0(w10))));
400  Round(g, h, a, b, c, d, e, f,
401  Add(K(0xc24b8b70ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
402  Round(f, g, h, a, b, c, d, e,
403  Add(K(0xc76c51a3ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
404  Round(e, f, g, h, a, b, c, d,
405  Add(K(0xd192e819ul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
406  Round(d, e, f, g, h, a, b, c,
407  Add(K(0xd6990624ul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
408  Round(c, d, e, f, g, h, a, b,
409  Add(K(0xf40e3585ul), Inc(w14, sigma1(w12), w7, sigma0(w15))));
410  Round(b, c, d, e, f, g, h, a,
411  Add(K(0x106aa070ul), Inc(w15, sigma1(w13), w8, sigma0(w0))));
412  Round(a, b, c, d, e, f, g, h,
413  Add(K(0x19a4c116ul), Inc(w0, sigma1(w14), w9, sigma0(w1))));
414  Round(h, a, b, c, d, e, f, g,
415  Add(K(0x1e376c08ul), Inc(w1, sigma1(w15), w10, sigma0(w2))));
416  Round(g, h, a, b, c, d, e, f,
417  Add(K(0x2748774cul), Inc(w2, sigma1(w0), w11, sigma0(w3))));
418  Round(f, g, h, a, b, c, d, e,
419  Add(K(0x34b0bcb5ul), Inc(w3, sigma1(w1), w12, sigma0(w4))));
420  Round(e, f, g, h, a, b, c, d,
421  Add(K(0x391c0cb3ul), Inc(w4, sigma1(w2), w13, sigma0(w5))));
422  Round(d, e, f, g, h, a, b, c,
423  Add(K(0x4ed8aa4aul), Inc(w5, sigma1(w3), w14, sigma0(w6))));
424  Round(c, d, e, f, g, h, a, b,
425  Add(K(0x5b9cca4ful), Inc(w6, sigma1(w4), w15, sigma0(w7))));
426  Round(b, c, d, e, f, g, h, a,
427  Add(K(0x682e6ff3ul), Inc(w7, sigma1(w5), w0, sigma0(w8))));
428  Round(a, b, c, d, e, f, g, h,
429  Add(K(0x748f82eeul), Inc(w8, sigma1(w6), w1, sigma0(w9))));
430  Round(h, a, b, c, d, e, f, g,
431  Add(K(0x78a5636ful), Inc(w9, sigma1(w7), w2, sigma0(w10))));
432  Round(g, h, a, b, c, d, e, f,
433  Add(K(0x84c87814ul), Inc(w10, sigma1(w8), w3, sigma0(w11))));
434  Round(f, g, h, a, b, c, d, e,
435  Add(K(0x8cc70208ul), Inc(w11, sigma1(w9), w4, sigma0(w12))));
436  Round(e, f, g, h, a, b, c, d,
437  Add(K(0x90befffaul), Inc(w12, sigma1(w10), w5, sigma0(w13))));
438  Round(d, e, f, g, h, a, b, c,
439  Add(K(0xa4506cebul), Inc(w13, sigma1(w11), w6, sigma0(w14))));
440  Round(c, d, e, f, g, h, a, b,
441  Add(K(0xbef9a3f7ul), w14, sigma1(w12), w7, sigma0(w15)));
442  Round(b, c, d, e, f, g, h, a,
443  Add(K(0xc67178f2ul), w15, sigma1(w13), w8, sigma0(w0)));
444 
445  // Output
446  Write8(out, 0, Add(a, K(0x6a09e667ul)));
447  Write8(out, 4, Add(b, K(0xbb67ae85ul)));
448  Write8(out, 8, Add(c, K(0x3c6ef372ul)));
449  Write8(out, 12, Add(d, K(0xa54ff53aul)));
450  Write8(out, 16, Add(e, K(0x510e527ful)));
451  Write8(out, 20, Add(f, K(0x9b05688cul)));
452  Write8(out, 24, Add(g, K(0x1f83d9abul)));
453  Write8(out, 28, Add(h, K(0x5be0cd19ul)));
454 }
455 } // namespace sha256d64_avx2
456 
457 #endif
static void WriteLE32(uint8_t *ptr, uint32_t x)
Definition: common.h:40
static uint32_t ReadLE32(const uint8_t *ptr)
Definition: common.h:23
#define sigma1(x)
Definition: hash_impl.h:22
#define Maj(x, y, z)
Definition: hash_impl.h:18
#define Round(a, b, c, d, e, f, g, h, k, w)
Definition: hash_impl.h:24
#define Sigma0(x)
Definition: hash_impl.h:19
#define sigma0(x)
Definition: hash_impl.h:21
#define Sigma1(x)
Definition: hash_impl.h:20
#define Ch(x, y, z)
Definition: hash_impl.h:17
void Transform_8way(uint8_t *out, const uint8_t *in)