1  /* { dg-do run { target avx512fp16 } } */
       2  /* { dg-options "-O2 -mavx512fp16 -mavx512dq" } */
       3  
       4  
       5  #define AVX512FP16
       6  #include "avx512fp16-helper.h"
       7  
       8  #define N_ELEMS (AVX512F_LEN / 64)
       9  
      10  void NOINLINE
      11  EMULATE(cvtq2_ph) (V512 * dest, V512 op1, int n_el,
      12  		 __mmask32 k, int zero_mask)
      13  {
      14    V512 v1, v2, v3, v4, v5, v6, v7, v8;
      15    int i;
      16    __mmask16 m1, m2;
      17  
      18    m1 = k & 0xffff;
      19  
      20    unpack_ph_2twops(*dest, &v7, &v8);
      21  
      22    for (i = 0; i < n_el; i++) {
      23        if (((1 << i) & m1) == 0) {
      24  	  if (zero_mask) {
      25  	      v5.f32[i] = 0;
      26  	  }
      27  	  else {
      28  	      v5.u32[i] = v7.u32[i];
      29  	  }
      30        }
      31        else {
      32  	  v5.f32[i] = op1.u64[i];
      33        }
      34    }
      35  
      36    // The left part should be zero
      37    for (i = n_el; i < 16; i++)
      38      v5.f32[i] = 0;
      39  
      40    *dest = pack_twops_2ph(v5, v5);
      41  }
      42  
      43  void
      44  TEST (void)
      45  {
      46  
      47    V512 res;
      48    V512 exp;
      49  
      50    init_src();
      51  
      52    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, NET_MASK, 0);
      53    res.xmmh[0] = INTRINSIC (_cvtepi64_ph) (SI(src3));
      54    CHECK_RESULT (&res, &exp, 8, _cvtepi64_ph);
      55  
      56    init_dest(&res, &exp);
      57    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, 0xcc, 0);
      58    res.xmmh[0] = INTRINSIC (_mask_cvtepi64_ph) (res.xmmh[0], 0xcc, SI(src3));
      59    CHECK_RESULT (&res, &exp, 8, _mask_cvtepi64_ph);
      60  
      61    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, 0xf1, 1);
      62    res.xmmh[0] = INTRINSIC (_maskz_cvtepi64_ph) (0xf1, SI(src3));
      63    CHECK_RESULT (&res, &exp, 8, _maskz_cvtepi64_ph);
      64  
      65  #if AVX512F_LEN == 512
      66    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, NET_MASK, 0);
      67    res.xmmh[0] = INTRINSIC (_cvt_roundepi64_ph) (SI(src3), _ROUND_NINT);
      68    CHECK_RESULT (&res, &exp, 8, _cvt_roundepi64_ph);
      69  
      70    init_dest(&res, &exp);
      71    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, 0xcc, 0);
      72    res.xmmh[0] = INTRINSIC (_mask_cvt_roundepi64_ph) (res.xmmh[0], 0xcc, SI(src3), _ROUND_NINT);
      73    CHECK_RESULT (&res, &exp, 8, _mask_cvt_roundepi64_ph);
      74  
      75    EMULATE(cvtq2_ph)(&exp, src3, N_ELEMS, 0xf1, 1);
      76    res.xmmh[0] = INTRINSIC (_maskz_cvt_roundepi64_ph) (0xf1, SI(src3), _ROUND_NINT);
      77    CHECK_RESULT (&res, &exp, 8, _maskz_cvt_roundepi64_ph);
      78  #endif
      79  
      80    if (n_errs != 0) {
      81        abort ();
      82    }
      83  }
      84