blob: b796cc84316f069bed12a928b678cfabd9f626b2 [file] [log] [blame]
Craig Topper61f71c32013-09-27 03:57:18 +00001/*===---- f16cintrin.h - F16C intrinsics -----------------------------------===
Manman Rena45358c2012-10-11 00:59:55 +00002 *
Craig Topper61f71c32013-09-27 03:57:18 +00003 * Permission is hereby granted, free of charge, to any person obtaining a copy
Manman Rena45358c2012-10-11 00:59:55 +00004 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 *
21 *===-----------------------------------------------------------------------===
22 */
23
Michael Kupersteina10dff92015-09-21 13:34:47 +000024#if !defined __X86INTRIN_H && !defined __EMMINTRIN_H && !defined __IMMINTRIN_H
25#error "Never use <f16cintrin.h> directly; include <emmintrin.h> instead."
Manman Rena45358c2012-10-11 00:59:55 +000026#endif
27
Manman Rena45358c2012-10-11 00:59:55 +000028#ifndef __F16CINTRIN_H
29#define __F16CINTRIN_H
30
Eric Christopher4d1851682015-06-17 07:09:20 +000031/* Define the default attributes for the functions in this file. */
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000032#define __DEFAULT_FN_ATTRS \
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000033 __attribute__((__always_inline__, __nodebug__, __target__("f16c")))
Eric Christopher4d1851682015-06-17 07:09:20 +000034
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000035/// \brief Converts a 16-bit half-precision float value into a 32-bit float
36/// value.
37///
38/// \headerfile <x86intrin.h>
39///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000040/// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000041///
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +000042/// \param __a
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000043/// A 16-bit half-precision float value.
44/// \returns The converted 32-bit float value.
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000045static __inline float __DEFAULT_FN_ATTRS
Eric Christopher0466c7c2016-02-12 00:32:23 +000046_cvtsh_ss(unsigned short __a)
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000047{
Eric Christopher0466c7c2016-02-12 00:32:23 +000048 __v8hi v = {(short)__a, 0, 0, 0, 0, 0, 0, 0};
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000049 __v4sf r = __builtin_ia32_vcvtph2ps(v);
50 return r[0];
51}
52
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000053/// \brief Converts a 32-bit single-precision float value to a 16-bit
54/// half-precision float value.
55///
56/// \headerfile <x86intrin.h>
57///
58/// \code
59/// unsigned short _cvtss_sh(float a, const int imm);
60/// \endcode
61///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000062/// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000063///
64/// \param a
65/// A 32-bit single-precision float value to be converted to a 16-bit
66/// half-precision float value.
67/// \param imm
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +000068/// An immediate value controlling rounding using bits [2:0]: \n
69/// 000: Nearest \n
70/// 001: Down \n
71/// 010: Up \n
72/// 011: Truncate \n
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000073/// 1XX: Use MXCSR.RC for rounding
74/// \returns The converted 16-bit half-precision float value.
Craig Topper01bba172017-04-03 22:59:30 +000075#define _cvtss_sh(a, imm) __extension__ ({ \
76 (unsigned short)(((__v8hi)__builtin_ia32_vcvtps2ph((__v4sf){a, 0, 0, 0}, \
77 (imm)))[0]); })
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000078
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000079/// \brief Converts a 128-bit vector containing 32-bit float values into a
80/// 128-bit vector containing 16-bit half-precision float values.
81///
82/// \headerfile <x86intrin.h>
83///
84/// \code
85/// __m128i _mm_cvtps_ph(__m128 a, const int imm);
86/// \endcode
87///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000088/// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000089///
90/// \param a
91/// A 128-bit vector containing 32-bit float values.
92/// \param imm
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +000093/// An immediate value controlling rounding using bits [2:0]: \n
94/// 000: Nearest \n
95/// 001: Down \n
96/// 010: Up \n
97/// 011: Truncate \n
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000098/// 1XX: Use MXCSR.RC for rounding
99/// \returns A 128-bit vector containing converted 16-bit half-precision float
100/// values. The lower 64 bits are used to store the converted 16-bit
101/// half-precision floating-point values.
Craig Topper01bba172017-04-03 22:59:30 +0000102#define _mm_cvtps_ph(a, imm) __extension__ ({ \
103 (__m128i)__builtin_ia32_vcvtps2ph((__v4sf)(__m128)(a), (imm)); })
Manman Rena45358c2012-10-11 00:59:55 +0000104
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +0000105/// \brief Converts a 128-bit vector containing 16-bit half-precision float
106/// values into a 128-bit vector containing 32-bit float values.
107///
108/// \headerfile <x86intrin.h>
109///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000110/// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +0000111///
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000112/// \param __a
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +0000113/// A 128-bit vector containing 16-bit half-precision float values. The lower
114/// 64 bits are used in the conversion.
115/// \returns A 128-bit vector of [4 x float] containing converted float values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000116static __inline __m128 __DEFAULT_FN_ATTRS
Eric Christopher0466c7c2016-02-12 00:32:23 +0000117_mm_cvtph_ps(__m128i __a)
Manman Rena45358c2012-10-11 00:59:55 +0000118{
Eric Christopher0466c7c2016-02-12 00:32:23 +0000119 return (__m128)__builtin_ia32_vcvtph2ps((__v8hi)__a);
Manman Rena45358c2012-10-11 00:59:55 +0000120}
121
Michael Kupersteine45af542015-06-30 13:36:19 +0000122#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000123
Manman Rena45358c2012-10-11 00:59:55 +0000124#endif /* __F16CINTRIN_H */