blob: c6a1b50be19689b1e467a4b3fc08699d9e7a316b [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
Craig Topper34c8c0d2018-05-22 18:54:19 +000024#if !defined __IMMINTRIN_H
25#error "Never use <f16cintrin.h> directly; include <immintrin.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
Craig Topper34c8c0d2018-05-22 18:54:19 +000035/* The 256-bit versions of functions in f16cintrin.h.
36 Intel documents these as being in immintrin.h, and
37 they depend on typedefs from avxintrin.h. */
Ekaterina Romanova08d1f242016-01-22 06:50:50 +000038
Craig Topper34c8c0d2018-05-22 18:54:19 +000039/// Converts a 256-bit vector of [8 x float] into a 128-bit vector
40/// containing 16-bit half-precision float values.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000041///
42/// \headerfile <x86intrin.h>
43///
44/// \code
Craig Topper34c8c0d2018-05-22 18:54:19 +000045/// __m128i _mm256_cvtps_ph(__m256 a, const int imm);
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000046/// \endcode
47///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000048/// This intrinsic corresponds to the <c> VCVTPS2PH </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000049///
50/// \param a
Craig Topper34c8c0d2018-05-22 18:54:19 +000051/// A 256-bit vector containing 32-bit single-precision float values to be
52/// converted to 16-bit half-precision float values.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000053/// \param imm
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +000054/// An immediate value controlling rounding using bits [2:0]: \n
55/// 000: Nearest \n
56/// 001: Down \n
57/// 010: Up \n
58/// 011: Truncate \n
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000059/// 1XX: Use MXCSR.RC for rounding
Craig Topper34c8c0d2018-05-22 18:54:19 +000060/// \returns A 128-bit vector containing the converted 16-bit half-precision
61/// float values.
62#define _mm256_cvtps_ph(a, imm) __extension__ ({ \
63 (__m128i)__builtin_ia32_vcvtps2ph256((__v8sf)(__m256)(a), (imm)); })
Manman Rena45358c2012-10-11 00:59:55 +000064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000065/// Converts a 128-bit vector containing 16-bit half-precision float
Craig Topper34c8c0d2018-05-22 18:54:19 +000066/// values into a 256-bit vector of [8 x float].
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000067///
68/// \headerfile <x86intrin.h>
69///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000070/// This intrinsic corresponds to the <c> VCVTPH2PS </c> instruction.
Ekaterina Romanovaa61946d2016-02-10 00:12:24 +000071///
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +000072/// \param __a
Craig Topper34c8c0d2018-05-22 18:54:19 +000073/// A 128-bit vector containing 16-bit half-precision float values to be
74/// converted to 32-bit single-precision float values.
75/// \returns A vector of [8 x float] containing the converted 32-bit
76/// single-precision float values.
77static __inline __m256 __attribute__((__always_inline__, __nodebug__, __target__("f16c")))
78_mm256_cvtph_ps(__m128i __a)
Manman Rena45358c2012-10-11 00:59:55 +000079{
Craig Topper34c8c0d2018-05-22 18:54:19 +000080 return (__m256)__builtin_ia32_vcvtph2ps256((__v8hi)__a);
Manman Rena45358c2012-10-11 00:59:55 +000081}
82
Michael Kupersteine45af542015-06-30 13:36:19 +000083#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +000084
Manman Rena45358c2012-10-11 00:59:55 +000085#endif /* __F16CINTRIN_H */