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 / 16)
       9  
      10  void NOINLINE
      11  EMULATE(roundscale_ph) (V512 * dest, V512 op1,
      12  		      __mmask32 k, int zero_mask, int round)
      13  {   
      14    V512 v1, v2, v3, v4, v5, v6, v7, v8;
      15    int i;
      16    __mmask16 m1, m2;
      17    V512 t1, t2;
      18    m1 = k & 0xffff; 
      19    m2 = (k >> 16) & 0xffff;
      20  
      21    unpack_ph_2twops(op1, &v1, &v2);
      22    unpack_ph_2twops(*dest, &v7, &v8);
      23    if (round==0)
      24    {
      25      t1.zmm = _mm512_maskz_roundscale_ps (0xffff, v1.zmm, 0x11);
      26      t2.zmm = _mm512_maskz_roundscale_ps (0xffff, v2.zmm, 0x11);
      27    }  
      28    else
      29    {
      30      t1.zmm = _mm512_maskz_roundscale_ps (0xffff, v1.zmm, 0x14);
      31      t2.zmm = _mm512_maskz_roundscale_ps (0xffff, v2.zmm, 0x14);
      32    }
      33    for (i = 0; i < 16; i++) 
      34    { 
      35      if (((1 << i) & m1) == 0) {
      36  	if (zero_mask) {
      37  	    v5.f32[i] = 0;
      38  	}
      39  	else {
      40  	    v5.u32[i] = v7.u32[i];
      41  	}
      42      }
      43      else {
      44  	v5.f32[i] = t1.f32[i];
      45      }
      46  
      47      if (((1 << i) & m2) == 0) {
      48  	if (zero_mask) {
      49  	    v6.f32[i] = 0;
      50  	}
      51  	else {
      52  	    v6.u32[i] = v8.u32[i];
      53  	}
      54      }
      55      else {
      56  	v6.f32[i] = t2.f32[i];
      57      }
      58    }
      59    *dest = pack_twops_2ph(v5, v6);
      60  }
      61  
      62  void
      63  TEST (void)
      64  {
      65    V512 res, exp;
      66  
      67    init_src();
      68  
      69    EMULATE(roundscale_ph) (&exp, src1,  NET_MASK, 0, 1);
      70    HF(res) = INTRINSIC (_roundscale_ph) (HF(src1), 0x13);
      71    CHECK_RESULT (&res, &exp, N_ELEMS, _roundscale_ph);
      72  
      73    init_dest(&res, &exp);
      74    EMULATE(roundscale_ph) (&exp, src1, MASK_VALUE, 0, 1);
      75    HF(res) = INTRINSIC (_mask_roundscale_ph) (HF(res), MASK_VALUE, HF(src1), 0x14);
      76    CHECK_RESULT (&res, &exp, N_ELEMS, _mask_roundscale_ph);
      77  
      78    EMULATE(roundscale_ph) (&exp, src1,  ZMASK_VALUE, 1, 1);
      79    HF(res) = INTRINSIC (_maskz_roundscale_ph) (ZMASK_VALUE, HF(src1), 0x14);
      80    CHECK_RESULT (&res, &exp, N_ELEMS, _maskz_roundscale_ph);
      81  
      82  #if AVX512F_LEN == 512
      83    EMULATE(roundscale_ph) (&exp, src1,  NET_MASK, 0, 1);
      84    HF(res) = INTRINSIC (_roundscale_round_ph) (HF(src1), 0x13, 0x08);
      85    CHECK_RESULT (&res, &exp, N_ELEMS, _roundscale_round_ph);
      86  
      87    init_dest(&res, &exp);
      88    EMULATE(roundscale_ph) (&exp, src1, MASK_VALUE, 0, 1);
      89    HF(res) = INTRINSIC (_mask_roundscale_round_ph) (HF(res), MASK_VALUE, HF(src1), 0x14, 0x08);
      90    CHECK_RESULT (&res, &exp, N_ELEMS, _mask_roundscale_round_ph);
      91  
      92    EMULATE(roundscale_ph) (&exp, src1,  ZMASK_VALUE, 1, 1);
      93    HF(res) = INTRINSIC (_maskz_roundscale_round_ph) (ZMASK_VALUE, HF(src1), 0x14, 0x08);
      94    CHECK_RESULT (&res, &exp, N_ELEMS, _maskz_roundscale_round_ph);
      95  #endif
      96  
      97    if (n_errs != 0) {
      98        abort ();
      99    }
     100  }
     101