1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512f" } */
3 /* { dg-require-effective-target avx512f } */
4 
5 #define AVX512F
6 
7 #include "avx512f-helper.h"
8 
9 #define SIZE (AVX512F_LEN / 32)
10 #include "avx512f-mask-type.h"
11 #define MASK ((1 << SIZE) - 1)
12 #include <x86intrin.h>
13 
14 static void
CALC(float * s,float * r,MASK_TYPE mask)15 CALC (float *s, float *r, MASK_TYPE mask)
16 {
17   int i, k;
18 
19   for (i = 0, k = 0; i < SIZE; i++)
20     {
21       if (mask & (1 << i))
22 	r[k++] = s[i];
23     }
24 }
25 
26 void
TEST(void)27 TEST (void)
28 {
29   UNION_TYPE (AVX512F_LEN, ) s, res1, res2;
30   float res3[SIZE];
31   MASK_TYPE compressed_mask, mask = MASK_VALUE;
32   float res_ref[SIZE];
33   int i, mask_bit_count, sign = 1;
34 
35   for (i = 0; i < SIZE; i++)
36     {
37       s.a[i] = 12345 * (i + 200) * sign;
38       res1.a[i] = DEFAULT_VALUE;
39       res3[i] = DEFAULT_VALUE;
40       sign = -sign;
41     }
42 
43   res1.x = INTRINSIC (_mask_compress_ps) (res1.x, mask, s.x);
44   res2.x = INTRINSIC (_maskz_compress_ps) (mask, s.x);
45   INTRINSIC (_mask_compressstoreu_ps) (res3, mask, s.x);
46 
47   mask_bit_count = __popcntd (mask & MASK);
48   compressed_mask = (1 << mask_bit_count) - 1;
49   CALC (s.a, res_ref, mask);
50 
51   MASK_MERGE () (res_ref, compressed_mask, SIZE);
52   if (UNION_CHECK (AVX512F_LEN, ) (res1, res_ref))
53     abort ();
54 
55   MASK_ZERO () (res_ref, compressed_mask, SIZE);
56   if (UNION_CHECK (AVX512F_LEN, ) (res2, res_ref))
57     abort ();
58 
59   MASK_MERGE () (res_ref, compressed_mask, SIZE);
60   if (checkVf (res3, res_ref, SIZE))
61     abort ();
62 }
63