1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512f -mgfni -mavx512bw" } */
3 /* { dg-require-effective-target avx512f } */
4 /* { dg-require-effective-target gfni } */
5
6 #define AVX512F
7
8 #define GFNI
9 #include "avx512f-helper.h"
10
11 #define SIZE (AVX512F_LEN / 8)
12
13 #include "avx512f-mask-type.h"
14
15 static void
CALC(unsigned char * r,unsigned char * s1,unsigned char * s2)16 CALC (unsigned char *r, unsigned char *s1, unsigned char *s2)
17 {
18 for (int i = 0; i < SIZE; i++)
19 {
20 unsigned short result = 0;
21 for (int bit = 0; bit < 8; bit++)
22 {
23 if ((s1[i] >> bit) & 1)
24 {
25 result ^= s2[i] << bit;
26 }
27 }
28 // Reduce result by x^8 + x^4 + x^3 + x + 1
29 for (int bit = 14; bit > 7; bit--)
30 {
31 unsigned short p = 0x11B << (bit - 8);
32 if ((result >> bit) & 1)
33 result ^= p;
34 }
35 r[i] = result;
36 }
37 }
38
39 void
TEST(void)40 TEST (void)
41 {
42 int i;
43 UNION_TYPE (AVX512F_LEN, i_b) res1, res2, res3, src1, src2;
44 MASK_TYPE mask = MASK_VALUE;
45 unsigned char res_ref[SIZE];
46
47 for (i = 0; i < SIZE; i++)
48 {
49 src1.a[i] = 1 + i;
50 src2.a[i] = 2 + 2*i;
51 }
52
53 for (i = 0; i < SIZE; i++)
54 {
55 res1.a[i] = DEFAULT_VALUE;
56 res2.a[i] = DEFAULT_VALUE;
57 res3.a[i] = DEFAULT_VALUE;
58 }
59
60 CALC (res_ref, src1.a, src2.a);
61
62 res1.x = INTRINSIC (_gf2p8mul_epi8) (src1.x, src2.x);
63 res2.x = INTRINSIC (_mask_gf2p8mul_epi8) (res2.x, mask, src1.x, src2.x);
64 res3.x = INTRINSIC (_maskz_gf2p8mul_epi8) (mask, src1.x, src2.x);
65
66 if (UNION_CHECK (AVX512F_LEN, i_b) (res1, res_ref))
67 abort ();
68
69 MASK_MERGE (i_b) (res_ref, mask, SIZE);
70 if (UNION_CHECK (AVX512F_LEN, i_b) (res2, res_ref))
71 abort ();
72
73 MASK_ZERO (i_b) (res_ref, mask, SIZE);
74 if (UNION_CHECK (AVX512F_LEN, i_b) (res3, res_ref))
75 abort ();
76 }
77