| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2 -msm3" } */ |
| 3 |
/* { dg-require-effective-target sm3 } */ |
| 4 |
|
| 5 |
#include "sm3-check.h" |
| 6 |
#include <x86intrin.h> |
| 7 |
#include <immintrin.h> |
| 8 |
|
| 9 |
static unsigned |
| 10 |
p1 (unsigned w) |
| 11 |
{ |
| 12 |
return rol32 (w, 15) ^ rol32 (w, 23) ^ w; |
| 13 |
} |
| 14 |
|
| 15 |
static void |
| 16 |
compute_sm3msg1 (int *src0, int *src1, int *src2, int *res) |
| 17 |
{ |
| 18 |
unsigned w0, w1, w2, w3, w7, w8, w9, w10, w13, w14, w15; |
| 19 |
|
| 20 |
w0 = src2[0]; |
| 21 |
w1 = src2[1]; |
| 22 |
w2 = src2[2]; |
| 23 |
w3 = src2[3]; |
| 24 |
w7 = src0[0]; |
| 25 |
w8 = src0[1]; |
| 26 |
w9 = src0[2]; |
| 27 |
w10 = src0[3]; |
| 28 |
w13 = src1[0]; |
| 29 |
w14 = src1[1]; |
| 30 |
w15 = src1[2]; |
| 31 |
|
| 32 |
res[0] = p1 (w7 ^ w0 ^ rol32 (w13, 15)); |
| 33 |
res[1] = p1 (w8 ^ w1 ^ rol32 (w14, 15)); |
| 34 |
res[2] = p1 (w9 ^ w2 ^ rol32 (w15, 15)); |
| 35 |
res[3] = p1 (w10 ^ w3); |
| 36 |
} |
| 37 |
|
| 38 |
static void |
| 39 |
sm3_test (void) |
| 40 |
{ |
| 41 |
union128i_d s1, s2, s3, res; |
| 42 |
int res_ref[4]; |
| 43 |
|
| 44 |
s1.x = _mm_set_epi32 (111, 222, 333, 444); |
| 45 |
s2.x = _mm_set_epi32 (555, 666, 777, 888); |
| 46 |
s3.x = _mm_set_epi32 (999, 123, 456, 789); |
| 47 |
|
| 48 |
res.x = _mm_sm3msg1_epi32 (s1.x, s2.x, s3.x); |
| 49 |
|
| 50 |
compute_sm3msg1 (s1.a, s2.a, s3.a, res_ref); |
| 51 |
|
| 52 |
if (check_union128i_d (res, res_ref)) |
| 53 |
abort (); |
| 54 |
} |