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 <math.h>
10 #include <limits.h>
11 #include <float.h>
12 #include "avx512f-mask-type.h"
13 
14 #define NUM 32
15 
16 void
CALC(short * dst,short * src1,short * ind,short * src2)17 CALC (short *dst, short *src1, short *ind, short *src2)
18 {
19   int i;
20 
21   for (i = 0; i < SIZE; i++)
22     {
23       unsigned long long offset = ind[i] & (SIZE - 1);
24       unsigned long long cond = ind[i] & SIZE;
25 
26       dst[i] = cond ? src2[offset] : src1[offset];
27     }
28 }
29 
30 void
TEST(void)31 TEST (void)
32 {
33   int i, j;
34   UNION_TYPE (AVX512F_LEN, i_w) s1, s2, res1, res2, res3, ind;
35   short res_ref[SIZE];
36 
37   MASK_TYPE mask = MASK_VALUE;
38 
39   for (i = 0; i < NUM; i++)
40     {
41       for (j = 0; j < SIZE; j++)
42 	{
43 	  ind.a[j] = i * (j << 1);
44 	  s1.a[j] = DEFAULT_VALUE;
45 	  s2.a[j] = 1.5 * i * 2 * j;
46 
47 	  res1.a[j] = DEFAULT_VALUE;
48 	  res2.a[j] = DEFAULT_VALUE;
49 	  res3.a[j] = DEFAULT_VALUE;
50 	}
51 
52       CALC (res_ref, s1.a, ind.a, s2.a);
53 
54       res1.x = INTRINSIC (_permutex2var_epi16) (s1.x, ind.x, s2.x);
55       res2.x =
56 	INTRINSIC (_mask_permutex2var_epi16) (s1.x, mask, ind.x, s2.x);
57       res3.x =
58 	INTRINSIC (_maskz_permutex2var_epi16) (mask, s1.x, ind.x,
59 					       s2.x);
60 
61       if (UNION_CHECK (AVX512F_LEN, i_w) (res1, res_ref))
62 	abort ();
63 
64       MASK_MERGE (i_w) (res_ref, mask, SIZE);
65       if (UNION_CHECK (AVX512F_LEN, i_w) (res2, res_ref))
66 	abort ();
67 
68       MASK_ZERO (i_w) (res_ref, mask, SIZE);
69       if (UNION_CHECK (AVX512F_LEN, i_w) (res3, res_ref))
70 	abort ();
71     }
72 }
73