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
      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
      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  
      41    MASK_TYPE mask = 6 ^ (0xff >> SIZE);
      42  
      43    imm = _MM_FROUND_FLOOR | (7 << 4);
      44  
      45    for (i = 0; i < 3; i++)
      46      {
      47  
      48        for (j = 0; j < SIZE; j++)
      49  	{
      50  	  s.a[j] = j * (j + 12.0231);
      51  	  res1.a[j] = DEFAULT_VALUE;
      52  	  res2.a[j] = DEFAULT_VALUE;
      53  	  res3.a[j] = DEFAULT_VALUE;
      54  	}
      55  
      56        switch (i)
      57  	{
      58  	case 0:
      59  	  imm = _MM_FROUND_FLOOR | (7 << 4);
      60  	  res1.x = INTRINSIC (_roundscale_pd) (s.x, imm);
      61  	  res2.x = INTRINSIC (_mask_roundscale_pd) (res2.x, mask, s.x, imm);
      62  	  res3.x = INTRINSIC (_maskz_roundscale_pd) (mask, s.x, imm);
      63  	  break;
      64  	case 1:
      65  	  imm = _MM_FROUND_FLOOR;
      66  	  res1.x = INTRINSIC (_floor_pd) (s.x);
      67  	  #if AVX512F_LEN == 512
      68  	    res2.x = INTRINSIC (_mask_floor_pd) (res2.x, mask, s.x);
      69  	  #endif
      70  	  break;
      71  	case 2:
      72  	  imm = _MM_FROUND_CEIL;
      73  	  res1.x = INTRINSIC (_ceil_pd) (s.x);
      74  	  #if AVX512F_LEN == 512
      75  	    res2.x = INTRINSIC (_mask_ceil_pd) (res2.x, mask, s.x);
      76  	  #endif
      77  	  break;
      78  	}
      79  
      80        CALC (s.a, res_ref, imm);
      81  
      82        if (UNION_CHECK (AVX512F_LEN, d) (res1, res_ref))
      83  	abort ();
      84  
      85        MASK_MERGE(d) (res_ref,mask,SIZE );
      86  
      87        #if AVX512F_LEN == 512
      88  	if (UNION_CHECK (AVX512F_LEN, d) (res2, res_ref))
      89  	  abort ();
      90        #else
      91  	if (!i && UNION_CHECK (AVX512F_LEN, d) (res2, res_ref))
      92  	  abort ();
      93        #endif
      94  
      95        MASK_ZERO(d) (res_ref,mask,SIZE );
      96  
      97        if (!i && UNION_CHECK (AVX512F_LEN, d) (res3, res_ref))
      98  	abort ();
      99  
     100      }
     101  }
     102