1  /* { dg-do run } */
       2  /* { dg-options "-mavxneconvert -O2" } */
       3  /* { dg-require-effective-target avxneconvert } */
       4  #define AVXNECONVERT
       5  #include <stdint.h>
       6  
       7  #ifndef CHECK
       8  #define CHECK "avx-check.h"
       9  #endif
      10  
      11  #ifndef TEST
      12  #define TEST avx_test
      13  #endif
      14  
      15  #include CHECK
      16  
      17  typedef union
      18  {
      19    uint32_t int32;
      20    float flt;
      21  } float_int_t;
      22  
      23  typedef union
      24  {
      25    __m128bh x;
      26    uint32_t a[4];
      27  } union128bf16_i;
      28  
      29  typedef union
      30  {
      31    __m256bh x;
      32    uint32_t a[8];
      33  } union256bf16_i;
      34  
      35  static uint16_t convert_fp32_to_bf16 (float fp)
      36  {
      37    float_int_t fi;
      38    fi.flt = fp;
      39    return ((fi.int32 >> 16) & 0xffff);
      40  }
      41  
      42  void TEST (void)
      43  {
      44    union128 dst_128;
      45    union256 dst_256;
      46    float res_ref_128[4], res_ref_256[8], fp32;
      47    uint16_t bf16;
      48    union128bf16_i src_128bh;
      49    union256bf16_i src_256bh;
      50  
      51    for (int i = 0; i < 4; i++)
      52    {
      53      fp32 = (float) 3 * i + 5 + i * 0.5;
      54      bf16 = convert_fp32_to_bf16 (fp32);
      55      src_128bh.a[i] = bf16; // store bf16 at the lower part of the dword
      56      res_ref_128[i] = fp32;
      57      dst_128.a[i] = 117;
      58    }
      59    for (int i = 0; i < 8; i++)
      60    {
      61      fp32 = (float) 3 * i + 5 + i * 0.5;
      62      bf16 = convert_fp32_to_bf16 (fp32);
      63      src_256bh.a[i] = bf16; // store bf16 at the lower part of the dword
      64      res_ref_256[i] = fp32;
      65      dst_256.a[i] = 117;
      66    }
      67    dst_128.x = _mm_cvtneebf16_ps (&src_128bh.x);
      68    dst_256.x = _mm256_cvtneebf16_ps (&src_256bh.x);
      69    if (check_union128 (dst_128, res_ref_128))
      70      abort();
      71    if (check_union256 (dst_256, res_ref_256))
      72      abort();
      73  }