Debian Codegraph @

gcc/testsuite/gcc.target/i386/sha512rnds2-2.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2 -msha512" } */
3 /* { dg-require-effective-target sha512 } */
4
5 #include "sha512-check.h"
6 #include <emmintrin.h>
7 #include <immintrin.h>
8
9 static unsigned long long
10 ch (unsigned long long e, unsigned long long f, unsigned long long g)
11 {
12 return (e & f) ^ (~e & g);
13 }
14
15 static unsigned long long
16 maj (unsigned long long a, unsigned long long b, unsigned long long c)
17 {
18 return (a & b) ^ (a & c) ^ (b & c);
19 }
20
21 static unsigned long long
22 s0 (unsigned long long w)
23 {
24 return ror64 (w, 28) ^ ror64 (w, 34) ^ ror64 (w, 39);
25 }
26
27 static unsigned long long
28 s1 (unsigned long long w)
29 {
30 return ror64 (w, 14) ^ ror64 (w, 18) ^ ror64 (w, 41);
31 }
32
33 static void
34 compute_sha512rnds2(long long* src0, long long* src1, long long* src2, long long* res)
35 {
36 unsigned long long wk[2] = { src2[0], src2[1] };
37 unsigned long long a[3], b[3], c[3], d[3], e[3], f[3], g[3], h[3];
38
39 a[0] = src1[3];
40 b[0] = src1[2];
41 c[0] = src0[3];
42 d[0] = src0[2];
43 e[0] = src1[1];
44 f[0] = src1[0];
45 g[0] = src0[1];
46 h[0] = src0[0];
47
48 int i;
49 for (i = 0; i <= 1; i++)
50 {
51 a[i + 1] = ch (e[i], f[i], g[i]) + s1 (e[i]) + wk[i] + h[i]
52 + maj (a[i], b[i], c[i]) + s0 (a[i]);
53 b[i + 1] = a[i];
54 c[i + 1] = b[i];
55 d[i + 1] = c[i];
56 e[i + 1] = ch (e[i], f[i], g[i]) + s1 (e[i]) + wk[i] + h[i] + d[i];
57 f[i + 1] = e[i];
58 g[i + 1] = f[i];
59 h[i + 1] = g[i];
60 }
61
62 res[0] = f[2];
63 res[1] = e[2];
64 res[2] = b[2];
65 res[3] = a[2];
66 }
67
68 static void
69 sha512_test (void)
70 {
71 union256i_q s0, s1, res;
72 union128i_q s2;
73 long long res_ref[4];
74
75 s0.x = _mm256_set_epi64x (111, 222, 333, 444);
76 s1.x = _mm256_set_epi64x (555, 666, 777, 888);
77 s2.x = _mm_set_epi64x (999, 123);
78
79 res.x = _mm256_sha512rnds2_epi64 (s0.x, s1.x, s2.x);
80
81 compute_sha512rnds2 (s0.a, s1.a, s2.a, res_ref);
82
83 if (check_union256i_q (res, res_ref))
84 abort();
85 }