Fabcoin Core  0.16.2
P2P Digital Currency
blake2-round.h
Go to the documentation of this file.
1 #define _mm_roti_epi64(x, c) \
2  (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \
3  : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \
4  : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \
5  : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \
6  : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c))))
7 
8 #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
9  row1l = _mm_add_epi64(row1l, row2l); \
10  row1h = _mm_add_epi64(row1h, row2h); \
11  \
12  row4l = _mm_xor_si128(row4l, row1l); \
13  row4h = _mm_xor_si128(row4h, row1h); \
14  \
15  row4l = _mm_roti_epi64(row4l, -32); \
16  row4h = _mm_roti_epi64(row4h, -32); \
17  \
18  row3l = _mm_add_epi64(row3l, row4l); \
19  row3h = _mm_add_epi64(row3h, row4h); \
20  \
21  row2l = _mm_xor_si128(row2l, row3l); \
22  row2h = _mm_xor_si128(row2h, row3h); \
23  \
24  row2l = _mm_roti_epi64(row2l, -24); \
25  row2h = _mm_roti_epi64(row2h, -24); \
26 
27 #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
28  row1l = _mm_add_epi64(row1l, row2l); \
29  row1h = _mm_add_epi64(row1h, row2h); \
30  \
31  row4l = _mm_xor_si128(row4l, row1l); \
32  row4h = _mm_xor_si128(row4h, row1h); \
33  \
34  row4l = _mm_roti_epi64(row4l, -16); \
35  row4h = _mm_roti_epi64(row4h, -16); \
36  \
37  row3l = _mm_add_epi64(row3l, row4l); \
38  row3h = _mm_add_epi64(row3h, row4h); \
39  \
40  row2l = _mm_xor_si128(row2l, row3l); \
41  row2h = _mm_xor_si128(row2h, row3h); \
42  \
43  row2l = _mm_roti_epi64(row2l, -63); \
44  row2h = _mm_roti_epi64(row2h, -63); \
45 
46 #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
47  t0 = _mm_alignr_epi8(row2h, row2l, 8); \
48  t1 = _mm_alignr_epi8(row2l, row2h, 8); \
49  row2l = t0; \
50  row2h = t1; \
51  \
52  t0 = row3l; \
53  row3l = row3h; \
54  row3h = t0; \
55  \
56  t0 = _mm_alignr_epi8(row4h, row4l, 8); \
57  t1 = _mm_alignr_epi8(row4l, row4h, 8); \
58  row4l = t1; \
59  row4h = t0;
60 
61 #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
62  t0 = _mm_alignr_epi8(row2l, row2h, 8); \
63  t1 = _mm_alignr_epi8(row2h, row2l, 8); \
64  row2l = t0; \
65  row2h = t1; \
66  \
67  t0 = row3l; \
68  row3l = row3h; \
69  row3h = t0; \
70  \
71  t0 = _mm_alignr_epi8(row4l, row4h, 8); \
72  t1 = _mm_alignr_epi8(row4h, row4l, 8); \
73  row4l = t1; \
74  row4h = t0;
75 
76 #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \
77  G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
78  G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
79  \
80  DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
81  \
82  G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
83  G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
84  \
85  UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h);