1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512bw" } */
3 /* { dg-require-effective-target avx512bw } */
4 
5 #define AVX512BW
6 #include "avx512f-helper.h"
7 
8 #define SIZE (AVX512F_LEN / 16)
9 #include "avx512f-mask-type.h"
10 
11 void
CALC(unsigned short * dst,unsigned char * src1,unsigned char * src2,int imm)12 CALC (unsigned short *dst, unsigned char *src1, unsigned char *src2,
13       int imm)
14 {
15   int i, j, k, part, power;
16   unsigned char tmp[2 * SIZE];;
17 
18   for (i = 0; i < 2 * SIZE; i += 16)
19     {
20       for (j = 0; j < 4; j++)
21 	{
22 	  power = 1;
23 	  for (k = 0; k < j; k++)
24 	    power *= 4;
25 	  part = (imm & (3 * power)) >> (2 * j);
26 	  for (k = 0; k < 4; k++)
27 	    tmp[i + 4 * j + k] = src2[i + 4 * part + k];
28 	}
29     }
30 
31   for (i = 0; i < SIZE; i += 4)
32     {
33       dst[i] = dst[i + 1] = dst[i + 2] = dst[i + 3] = 0;
34       for (j = 0; j < 4; j++)
35 	{
36 	  dst[i] += abs (src1[2 * i + j] - tmp[2 * i + j]);
37 	  dst[i + 1] += abs (src1[2 * i + j] - tmp[2 * i + j + 1]);
38 	  dst[i + 2] += abs (src1[2 * i + j + 4] - tmp[2 * i + j + 2]);
39 	  dst[i + 3] += abs (src1[2 * i + j + 4] - tmp[2 * i + j + 3]);
40 	}
41     }
42 }
43 
44 void
TEST(void)45 TEST (void)
46 {
47   int i, sign;
48   UNION_TYPE (AVX512F_LEN, i_w) res1, res2, res3;
49   UNION_TYPE (AVX512F_LEN, i_b) src1, src2;
50   MASK_TYPE mask = MASK_VALUE;
51   unsigned short res_ref[SIZE];
52   int imm = 0x22;
53 
54   sign = -1;
55   for (i = 0; i < 2*SIZE; i++)
56     {
57       src1.a[i] = 1 + 34 * i * sign;
58       src1.a[i] = 179 - i;
59       sign = sign * -1;
60     }
61 
62   for (i = 0; i < SIZE; i++)
63       res2.a[i] = DEFAULT_VALUE;
64 
65   res1.x = INTRINSIC (_dbsad_epu8) (src1.x, src2.x, imm);
66   res2.x = INTRINSIC (_mask_dbsad_epu8) (res2.x, mask, src1.x, src2.x, imm);
67   res3.x = INTRINSIC (_maskz_dbsad_epu8) (mask, src1.x, src2.x, imm);
68 
69   CALC (res_ref, src1.a, src2.a, imm);
70 
71   if (UNION_CHECK (AVX512F_LEN, i_w) (res1, res_ref))
72     abort ();
73 
74   MASK_MERGE (i_w) (res_ref, mask, SIZE);
75   if (UNION_CHECK (AVX512F_LEN, i_w) (res2, res_ref))
76     abort ();
77 
78   MASK_ZERO (i_w) (res_ref, mask, SIZE);
79   if (UNION_CHECK (AVX512F_LEN, i_w) (res3, res_ref))
80     abort ();
81 }
82