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 DST_SIZE (AVX512F_LEN / 16)
9 #define SRC_SIZE (AVX512F_LEN / 32)
10 
11 #include "limits.h"
12 
13 #include "avx512f-mask-type.h"
14 
15 static short
16 EVAL(int_to_short, AVX512F_LEN,) (int iVal)
17 {
18   short sVal;
19 
20   if (iVal < SHRT_MIN)
21     sVal = SHRT_MIN;
22   else if (iVal > SHRT_MAX)
23     sVal = SHRT_MAX;
24   else
25     sVal = iVal;
26 
27   return sVal;
28 }
29 
30 void
CALC(int * src1,int * src2,short * dst)31 CALC (int *src1, int *src2, short *dst)
32 {
33   int i;
34   int *ptr;
35 
36   for (i = 0; i < DST_SIZE; i++)
37     {
38       ptr = (i / 4) % 2 ? src2 : src1;
39       dst[i] = EVAL(int_to_short, AVX512F_LEN,) (ptr[i % 4 + (i / 8) * 4]);
40     }
41 }
42 
43 void
TEST(void)44 TEST (void)
45 {
46   UNION_TYPE (AVX512F_LEN, i_d) s1, s2;
47   UNION_TYPE (AVX512F_LEN, i_w) res1, res2, res3;
48   MASK_TYPE mask = MASK_VALUE;
49   short dst_ref[DST_SIZE];
50   int i;
51 
52   for (i = 0; i < DST_SIZE; i++)
53     res2.a[i] = DEFAULT_VALUE;
54 
55   for (i = 0; i < SRC_SIZE; i++)
56     {
57       s1.a[i] = i + 10;
58       s2.a[i] = i + 15;
59     }
60 
61   res1.x = INTRINSIC (_packs_epi32) (s1.x, s2.x);
62   res2.x = INTRINSIC (_mask_packs_epi32) (res2.x, mask, s1.x, s2.x);
63   res3.x = INTRINSIC (_maskz_packs_epi32) (mask, s1.x, s2.x);
64 
65   CALC (s1.a, s2.a, dst_ref);
66 
67   if (UNION_CHECK (AVX512F_LEN, i_w) (res1, dst_ref))
68     abort ();
69 
70   MASK_MERGE (i_w) (dst_ref, mask, DST_SIZE);
71   if (UNION_CHECK (AVX512F_LEN, i_w) (res2, dst_ref))
72     abort ();
73 
74   MASK_ZERO (i_w) (dst_ref, mask, DST_SIZE);
75   if (UNION_CHECK (AVX512F_LEN, i_w) (res3, dst_ref))
76     abort ();
77 
78 }
79