/* Copyright (c) 2018 ZAO "MCST". All rights reserved. */

#if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
# error "Never use <f16intrin.h> directly; include <x86intrin.h> or <immintrin.h> instead."
#endif

#ifndef _F16CINTRIN_H_INCLUDED
#define _F16CINTRIN_H_INCLUDED

#ifdef __F16C__

/* Define the default attributes for the functions in this file */
#define __DEFAULT_FUNCS_ATTRS __attribute__((/*__gnu_inline__,*/ __always_inline__, __artificial__))

__E2K_INLINE float __DEFAULT_FUNCS_ATTRS
_cvtsh_ss (unsigned short __S)
{
  type_union_32 __dst;
  __16F_TO_32F (__S, __dst.i);
  return __dst.f;
}

__E2K_INLINE __m128 __DEFAULT_FUNCS_ATTRS
_mm_cvtph_ps (__m128i __A)
{
  return (__m128) __builtin_ia32_vcvtph2ps ((__v8hi) __A);
}

__E2K_INLINE __m256 __DEFAULT_FUNCS_ATTRS
_mm256_cvtph_ps (__m128i __A)
{
  return (__m256) __builtin_ia32_vcvtph2ps256 ((__v8hi) __A);
}

#define _cvtss_sh(__F, __I) ({						\
  type_union_32 __dst;                                                  \
  int round;                                                            \
  if ((__I) & 4) {                                                      \
    __GETPFPFR (round);                                                 \
    round >>= 13;                                                       \
  }                                                                     \
  else round = (__I);                                                   \
  round &= 3;                                                           \
  __dst.f = (__F);                                                      \
  __32F_TO_16F (__dst.i, round, __dst.i);                               \
  (unsigned short) __dst.i;                                             \
})

#define _mm_cvtps_ph(A, I) \
  ((__m128i) __builtin_ia32_vcvtps2ph ((__v4sf)(__m128) A, (int) (I)))

#define _mm256_cvtps_ph(A, I) \
  ((__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf)(__m256) A, (int) (I)))

#undef __DEFAULT_FUNCS_ATTRS

#endif /* __F16C__ */

#endif /* _F16CINTRIN_H_INCLUDED */
