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 / 64)
10 #include "avx512f-mask-type.h"
11 #include "math.h"
12 
13 static void
CALC(double * s,double * r,int imm)14 CALC (double *s, double *r, int imm)
15 {
16   int i = 0, rc, m;
17   rc = imm & 0xf;
18   m = imm >> 4;
19   for (i = 0; i < SIZE; i++)
20     switch (rc)
21       {
22       case _MM_FROUND_FLOOR:
23 	r[i] = floor (s[i] * pow (2, m)) / pow (2, m);
24 	break;
25       case _MM_FROUND_CEIL:
26 	r[i] = ceil (s[i] * pow (2, m)) / pow (2, m);
27 	break;
28       default:
29 	abort ();
30 	break;
31       }
32 }
33 
34 void static
TEST(void)35 TEST (void)
36 {
37   int imm, i, j;
38   UNION_TYPE (AVX512F_LEN, d) res1,res2,res3,s;
39   double res_ref[SIZE];
40   double res_ref_mask[SIZE];
41 
42   MASK_TYPE mask = 6 ^ (0xff >> SIZE);
43 
44   imm = _MM_FROUND_FLOOR | (7 << 4);
45 
46   for (i = 0; i < 3; i++)
47     {
48 
49       for (j = 0; j < SIZE; j++)
50 	{
51 	  s.a[j] = j * (j + 12.0231);
52 	  res1.a[j] = DEFAULT_VALUE;
53 	  res2.a[j] = DEFAULT_VALUE;
54 	  res3.a[j] = DEFAULT_VALUE;
55 	}
56 
57       switch (i)
58 	{
59 	case 0:
60 	  imm = _MM_FROUND_FLOOR | (7 << 4);
61 	  res1.x = INTRINSIC (_roundscale_pd) (s.x, imm);
62 	  res2.x = INTRINSIC (_mask_roundscale_pd) (res2.x, mask, s.x, imm);
63 	  res3.x = INTRINSIC (_maskz_roundscale_pd) (mask, s.x, imm);
64 	  break;
65 	case 1:
66 	  imm = _MM_FROUND_FLOOR;
67 	  res1.x = INTRINSIC (_floor_pd) (s.x);
68 	  res2.x = INTRINSIC (_mask_floor_pd) (res2.x, mask, s.x);
69 	  break;
70 	case 2:
71 	  imm = _MM_FROUND_CEIL;
72 	  res1.x = INTRINSIC (_ceil_pd) (s.x);
73 	  res2.x = INTRINSIC (_mask_ceil_pd) (res2.x, mask, s.x);
74 	  break;
75 	}
76 
77       CALC (s.a, res_ref, imm);
78 
79       if (UNION_CHECK (AVX512F_LEN, d) (res1, res_ref))
80 	abort ();
81 
82       MASK_MERGE(d) (res_ref,mask,SIZE );
83 
84       if (UNION_CHECK (AVX512F_LEN, d) (res2, res_ref))
85 	abort ();
86 
87       MASK_ZERO(d) (res_ref,mask,SIZE );
88 
89       if (!i && UNION_CHECK (AVX512F_LEN, d) (res3, res_ref))
90 	abort ();
91 
92     }
93 }
94 
95