Path: blob/master/tools/android-sdk/renderscript/clang-include/f16cintrin.h
496 views
/*===---- f16cintrin.h - F16C intrinsics -----------------------------------===1*2* Permission is hereby granted, free of charge, to any person obtaining a copy3* of this software and associated documentation files (the "Software"), to deal4* in the Software without restriction, including without limitation the rights5* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6* copies of the Software, and to permit persons to whom the Software is7* furnished to do so, subject to the following conditions:8*9* The above copyright notice and this permission notice shall be included in10* all copies or substantial portions of the Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18* THE SOFTWARE.19*20*===-----------------------------------------------------------------------===21*/2223#if !defined __X86INTRIN_H && !defined __EMMINTRIN_H && !defined __IMMINTRIN_H24#error "Never use <f16cintrin.h> directly; include <emmintrin.h> instead."25#endif2627#ifndef __F16CINTRIN_H28#define __F16CINTRIN_H2930/* Define the default attributes for the functions in this file. */31#define __DEFAULT_FN_ATTRS \32__attribute__((__always_inline__, __nodebug__, __target__("f16c")))3334/// \brief Converts a 16-bit half-precision float value into a 32-bit float35/// value.36///37/// \headerfile <x86intrin.h>38///39/// This intrinsic corresponds to the \c VCVTPH2PS instruction.40///41/// \param __a42/// A 16-bit half-precision float value.43/// \returns The converted 32-bit float value.44static __inline float __DEFAULT_FN_ATTRS45_cvtsh_ss(unsigned short __a)46{47__v8hi v = {(short)__a, 0, 0, 0, 0, 0, 0, 0};48__v4sf r = __builtin_ia32_vcvtph2ps(v);49return r[0];50}5152/// \brief Converts a 32-bit single-precision float value to a 16-bit53/// half-precision float value.54///55/// \headerfile <x86intrin.h>56///57/// \code58/// unsigned short _cvtss_sh(float a, const int imm);59/// \endcode60///61/// This intrinsic corresponds to the \c VCVTPS2PH instruction.62///63/// \param a64/// A 32-bit single-precision float value to be converted to a 16-bit65/// half-precision float value.66/// \param imm67/// An immediate value controlling rounding using bits [2:0]:68/// 000: Nearest69/// 001: Down70/// 010: Up71/// 011: Truncate72/// 1XX: Use MXCSR.RC for rounding73/// \returns The converted 16-bit half-precision float value.74#define _cvtss_sh(a, imm) \75((unsigned short)(((__v8hi)__builtin_ia32_vcvtps2ph((__v4sf){a, 0, 0, 0}, \76(imm)))[0]))7778/// \brief Converts a 128-bit vector containing 32-bit float values into a79/// 128-bit vector containing 16-bit half-precision float values.80///81/// \headerfile <x86intrin.h>82///83/// \code84/// __m128i _mm_cvtps_ph(__m128 a, const int imm);85/// \endcode86///87/// This intrinsic corresponds to the \c VCVTPS2PH instruction.88///89/// \param a90/// A 128-bit vector containing 32-bit float values.91/// \param imm92/// An immediate value controlling rounding using bits [2:0]:93/// 000: Nearest94/// 001: Down95/// 010: Up96/// 011: Truncate97/// 1XX: Use MXCSR.RC for rounding98/// \returns A 128-bit vector containing converted 16-bit half-precision float99/// values. The lower 64 bits are used to store the converted 16-bit100/// half-precision floating-point values.101#define _mm_cvtps_ph(a, imm) \102((__m128i)__builtin_ia32_vcvtps2ph((__v4sf)(__m128)(a), (imm)))103104/// \brief Converts a 128-bit vector containing 16-bit half-precision float105/// values into a 128-bit vector containing 32-bit float values.106///107/// \headerfile <x86intrin.h>108///109/// This intrinsic corresponds to the \c VCVTPH2PS instruction.110///111/// \param __a112/// A 128-bit vector containing 16-bit half-precision float values. The lower113/// 64 bits are used in the conversion.114/// \returns A 128-bit vector of [4 x float] containing converted float values.115static __inline __m128 __DEFAULT_FN_ATTRS116_mm_cvtph_ps(__m128i __a)117{118return (__m128)__builtin_ia32_vcvtph2ps((__v8hi)__a);119}120121#undef __DEFAULT_FN_ATTRS122123#endif /* __F16CINTRIN_H */124125126