1 /*===---- f16cintrin.h - F16C intrinsics -----------------------------------===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===-----------------------------------------------------------------------===
10 #if !defined __IMMINTRIN_H
11 #error "Never use <f16cintrin.h> directly; include <immintrin.h> instead."
14 #ifndef __F16CINTRIN_H
15 #define __F16CINTRIN_H
17 /* Define the default attributes for the functions in this file. */
18 #define __DEFAULT_FN_ATTRS128 \
19 __attribute__((__always_inline__, __nodebug__, __target__("f16c"), __min_vector_width__(128)))
20 #define __DEFAULT_FN_ATTRS256 \
21 __attribute__((__always_inline__, __nodebug__, __target__("f16c"), __min_vector_width__(256)))
23 /* NOTE: Intel documents the 128-bit versions of these as being in emmintrin.h,
24 * but that's because icc can emulate these without f16c using a library call.
25 * Since we don't do that let's leave these in f16cintrin.h.
28 /// Converts a 16-bit half-precision float value into a 32-bit float
31 /// \headerfile <x86intrin.h>
33 /// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
36 /// A 16-bit half-precision float value.
37 /// \returns The converted 32-bit float value.
38 static __inline
float __DEFAULT_FN_ATTRS128
39 _cvtsh_ss(unsigned short __a
)
41 __v8hi __v
= {(short)__a
, 0, 0, 0, 0, 0, 0, 0};
42 __v4sf __r
= __builtin_ia32_vcvtph2ps(__v
);
46 /// Converts a 32-bit single-precision float value to a 16-bit
47 /// half-precision float value.
49 /// \headerfile <x86intrin.h>
52 /// unsigned short _cvtss_sh(float a, const int imm);
55 /// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
58 /// A 32-bit single-precision float value to be converted to a 16-bit
59 /// half-precision float value.
61 /// An immediate value controlling rounding using bits [2:0]: \n
66 /// 1XX: Use MXCSR.RC for rounding
67 /// \returns The converted 16-bit half-precision float value.
68 #define _cvtss_sh(a, imm) __extension__ ({ \
69 (unsigned short)(((__v8hi)__builtin_ia32_vcvtps2ph((__v4sf){a, 0, 0, 0}, \
72 /// Converts a 128-bit vector containing 32-bit float values into a
73 /// 128-bit vector containing 16-bit half-precision float values.
75 /// \headerfile <x86intrin.h>
78 /// __m128i _mm_cvtps_ph(__m128 a, const int imm);
81 /// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
84 /// A 128-bit vector containing 32-bit float values.
86 /// An immediate value controlling rounding using bits [2:0]: \n
91 /// 1XX: Use MXCSR.RC for rounding
92 /// \returns A 128-bit vector containing converted 16-bit half-precision float
93 /// values. The lower 64 bits are used to store the converted 16-bit
94 /// half-precision floating-point values.
95 #define _mm_cvtps_ph(a, imm) \
96 ((__m128i)__builtin_ia32_vcvtps2ph((__v4sf)(__m128)(a), (imm)))
98 /// Converts a 128-bit vector containing 16-bit half-precision float
99 /// values into a 128-bit vector containing 32-bit float values.
101 /// \headerfile <x86intrin.h>
103 /// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
106 /// A 128-bit vector containing 16-bit half-precision float values. The lower
107 /// 64 bits are used in the conversion.
108 /// \returns A 128-bit vector of [4 x float] containing converted float values.
109 static __inline __m128 __DEFAULT_FN_ATTRS128
110 _mm_cvtph_ps(__m128i __a
)
112 return (__m128
)__builtin_ia32_vcvtph2ps((__v8hi
)__a
);
115 /// Converts a 256-bit vector of [8 x float] into a 128-bit vector
116 /// containing 16-bit half-precision float values.
118 /// \headerfile <x86intrin.h>
121 /// __m128i _mm256_cvtps_ph(__m256 a, const int imm);
124 /// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
127 /// A 256-bit vector containing 32-bit single-precision float values to be
128 /// converted to 16-bit half-precision float values.
130 /// An immediate value controlling rounding using bits [2:0]: \n
135 /// 1XX: Use MXCSR.RC for rounding
136 /// \returns A 128-bit vector containing the converted 16-bit half-precision
138 #define _mm256_cvtps_ph(a, imm) \
139 ((__m128i)__builtin_ia32_vcvtps2ph256((__v8sf)(__m256)(a), (imm)))
141 /// Converts a 128-bit vector containing 16-bit half-precision float
142 /// values into a 256-bit vector of [8 x float].
144 /// \headerfile <x86intrin.h>
146 /// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
149 /// A 128-bit vector containing 16-bit half-precision float values to be
150 /// converted to 32-bit single-precision float values.
151 /// \returns A vector of [8 x float] containing the converted 32-bit
152 /// single-precision float values.
153 static __inline __m256 __DEFAULT_FN_ATTRS256
154 _mm256_cvtph_ps(__m128i __a
)
156 return (__m256
)__builtin_ia32_vcvtph2ps256((__v8hi
)__a
);
159 #undef __DEFAULT_FN_ATTRS128
160 #undef __DEFAULT_FN_ATTRS256
162 #endif /* __F16CINTRIN_H */