f16cintrin.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2011-2019 Free Software Foundation, Inc.
  2. This file is part of GCC.
  3. GCC is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. GCC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
  19. # error "Never use <f16intrin.h> directly; include <x86intrin.h> or <immintrin.h> instead."
  20. #endif
  21. #ifndef _F16CINTRIN_H_INCLUDED
  22. #define _F16CINTRIN_H_INCLUDED
  23. #ifndef __F16C__
  24. #pragma GCC push_options
  25. #pragma GCC target("f16c")
  26. #define __DISABLE_F16C__
  27. #endif /* __F16C__ */
  28. extern __inline float __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  29. _cvtsh_ss (unsigned short __S)
  30. {
  31. __v8hi __H = __extension__ (__v8hi){ (short) __S, 0, 0, 0, 0, 0, 0, 0 };
  32. __v4sf __A = __builtin_ia32_vcvtph2ps (__H);
  33. return __builtin_ia32_vec_ext_v4sf (__A, 0);
  34. }
  35. extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  36. _mm_cvtph_ps (__m128i __A)
  37. {
  38. return (__m128) __builtin_ia32_vcvtph2ps ((__v8hi) __A);
  39. }
  40. extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  41. _mm256_cvtph_ps (__m128i __A)
  42. {
  43. return (__m256) __builtin_ia32_vcvtph2ps256 ((__v8hi) __A);
  44. }
  45. #ifdef __OPTIMIZE__
  46. extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  47. _cvtss_sh (float __F, const int __I)
  48. {
  49. __v4sf __A = __extension__ (__v4sf){ __F, 0, 0, 0 };
  50. __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);
  51. return (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);
  52. }
  53. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  54. _mm_cvtps_ph (__m128 __A, const int __I)
  55. {
  56. return (__m128i) __builtin_ia32_vcvtps2ph ((__v4sf) __A, __I);
  57. }
  58. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  59. _mm256_cvtps_ph (__m256 __A, const int __I)
  60. {
  61. return (__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf) __A, __I);
  62. }
  63. #else
  64. #define _cvtss_sh(__F, __I) \
  65. (__extension__ \
  66. ({ \
  67. __v4sf __A = __extension__ (__v4sf){ __F, 0, 0, 0 }; \
  68. __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I); \
  69. (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0); \
  70. }))
  71. #define _mm_cvtps_ph(A, I) \
  72. ((__m128i) __builtin_ia32_vcvtps2ph ((__v4sf)(__m128) A, (int) (I)))
  73. #define _mm256_cvtps_ph(A, I) \
  74. ((__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf)(__m256) A, (int) (I)))
  75. #endif /* __OPTIMIZE */
  76. #ifdef __DISABLE_F16C__
  77. #undef __DISABLE_F16C__
  78. #pragma GCC pop_options
  79. #endif /* __DISABLE_F16C__ */
  80. #endif /* _F16CINTRIN_H_INCLUDED */