1 /* { dg-do run } */
2 /* { dg-options "-O2 -msha" } */
3 /* { dg-require-effective-target sha } */
4 
5 #include "sha-check.h"
6 #include "m128-check.h"
7 #include <x86intrin.h>
8 #include <immintrin.h>
9 
10 static int
s1(int w)11 s1 (int w)
12 {
13   return __rord (w, 17) ^ __rord (w, 19) ^ (w >> 10);
14 }
15 
16 static void
compute_sha256msg2(int * src1,int * src2,int * res)17 compute_sha256msg2 (int *src1, int *src2, int *res)
18 {
19   int w14, w15, w16, w17, w18, w19;
20 
21   w14 = src2[2];
22   w15 = src2[3];
23   w16 = src1[0] + s1 (w14);
24   w17 = src1[1] + s1 (w15);
25   w18 = src1[2] + s1 (w16);
26   w19 = src1[3] + s1 (w17);
27 
28   res[0] = w16;
29   res[1] = w17;
30   res[2] = w18;
31   res[3] = w19;
32 }
33 
34 static void
sha_test(void)35 sha_test (void)
36 {
37   union128i_d s1, s2, res;
38   int res_ref[4];
39 
40   s1.x = _mm_set_epi32 (111, 222, 333, 444);
41   s2.x = _mm_set_epi32 (555, 666, 0, 0);
42 
43   res.x = _mm_sha256msg2_epu32 (s1.x, s2.x);
44 
45   compute_sha256msg2 (s1.a, s2.a, res_ref);
46 
47   if (check_union128i_d (res, res_ref))
48     abort ();
49 }
50