brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.0 KiB · a9a6544 Raw
303 lines · c
1/*===---- pmmintrin.h - SSE3 intrinsics ------------------------------------===2 *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-exception6 *7 *===-----------------------------------------------------------------------===8 */9 10#ifndef __PMMINTRIN_H11#define __PMMINTRIN_H12 13#if !defined(__i386__) && !defined(__x86_64__)14#error "This header is only meant to be used on x86 and x64 architecture"15#endif16 17#include <emmintrin.h>18 19/* Define the default attributes for the functions in this file. */20#define __DEFAULT_FN_ATTRS                                                     \21  __attribute__((__always_inline__, __nodebug__, __target__("sse3"),           \22                 __min_vector_width__(128)))23 24#if defined(__cplusplus) && (__cplusplus >= 201103L)25#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr26#else27#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS28#endif29 30/// Loads data from an unaligned memory location to elements in a 128-bit31///    vector.32///33///    If the address of the data is not 16-byte aligned, the instruction may34///    read two adjacent aligned blocks of memory to retrieve the requested35///    data.36///37/// \headerfile <x86intrin.h>38///39/// This intrinsic corresponds to the <c> VLDDQU </c> instruction.40///41/// \param __p42///    A pointer to a 128-bit integer vector containing integer values.43/// \returns A 128-bit vector containing the moved values.44static __inline__ __m128i __DEFAULT_FN_ATTRS45_mm_lddqu_si128(__m128i_u const *__p)46{47  return (__m128i)__builtin_ia32_lddqu((char const *)__p);48}49 50/// Adds the even-indexed values and subtracts the odd-indexed values of51///    two 128-bit vectors of [4 x float].52///53/// \headerfile <x86intrin.h>54///55/// This intrinsic corresponds to the <c> VADDSUBPS </c> instruction.56///57/// \param __a58///    A 128-bit vector of [4 x float] containing the left source operand.59/// \param __b60///    A 128-bit vector of [4 x float] containing the right source operand.61/// \returns A 128-bit vector of [4 x float] containing the alternating sums and62///    differences of both operands.63static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR64_mm_addsub_ps(__m128 __a, __m128 __b) {65  return __builtin_ia32_addsubps((__v4sf)__a, (__v4sf)__b);66}67 68/// Horizontally adds the adjacent pairs of values contained in two69///    128-bit vectors of [4 x float].70///71/// \headerfile <x86intrin.h>72///73/// This intrinsic corresponds to the <c> VHADDPS </c> instruction.74///75/// \param __a76///    A 128-bit vector of [4 x float] containing one of the source operands.77///    The horizontal sums of the values are stored in the lower bits of the78///    destination.79/// \param __b80///    A 128-bit vector of [4 x float] containing one of the source operands.81///    The horizontal sums of the values are stored in the upper bits of the82///    destination.83/// \returns A 128-bit vector of [4 x float] containing the horizontal sums of84///    both operands.85static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_hadd_ps(__m128 __a,86                                                                  __m128 __b) {87  return __builtin_ia32_haddps((__v4sf)__a, (__v4sf)__b);88}89 90/// Horizontally subtracts the adjacent pairs of values contained in two91///    128-bit vectors of [4 x float].92///93/// \headerfile <x86intrin.h>94///95/// This intrinsic corresponds to the <c> VHSUBPS </c> instruction.96///97/// \param __a98///    A 128-bit vector of [4 x float] containing one of the source operands.99///    The horizontal differences between the values are stored in the lower100///    bits of the destination.101/// \param __b102///    A 128-bit vector of [4 x float] containing one of the source operands.103///    The horizontal differences between the values are stored in the upper104///    bits of the destination.105/// \returns A 128-bit vector of [4 x float] containing the horizontal106///    differences of both operands.107static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_hsub_ps(__m128 __a,108                                                                  __m128 __b) {109  return __builtin_ia32_hsubps((__v4sf)__a, (__v4sf)__b);110}111 112/// Moves and duplicates odd-indexed values from a 128-bit vector113///    of [4 x float] to float values stored in a 128-bit vector of114///    [4 x float].115///116/// \headerfile <x86intrin.h>117///118/// This intrinsic corresponds to the <c> VMOVSHDUP </c> instruction.119///120/// \param __a121///    A 128-bit vector of [4 x float]. \n122///    Bits [127:96] of the source are written to bits [127:96] and [95:64] of123///    the destination. \n124///    Bits [63:32] of the source are written to bits [63:32] and [31:0] of the125///    destination.126/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated127///    values.128static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR129_mm_movehdup_ps(__m128 __a)130{131  return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 1, 1, 3, 3);132}133 134/// Duplicates even-indexed values from a 128-bit vector of135///    [4 x float] to float values stored in a 128-bit vector of [4 x float].136///137/// \headerfile <x86intrin.h>138///139/// This intrinsic corresponds to the <c> VMOVSLDUP </c> instruction.140///141/// \param __a142///    A 128-bit vector of [4 x float] \n143///    Bits [95:64] of the source are written to bits [127:96] and [95:64] of144///    the destination. \n145///    Bits [31:0] of the source are written to bits [63:32] and [31:0] of the146///    destination.147/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated148///    values.149static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR150_mm_moveldup_ps(__m128 __a)151{152  return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 0, 2, 2);153}154 155/// Adds the even-indexed values and subtracts the odd-indexed values of156///    two 128-bit vectors of [2 x double].157///158/// \headerfile <x86intrin.h>159///160/// This intrinsic corresponds to the <c> VADDSUBPD </c> instruction.161///162/// \param __a163///    A 128-bit vector of [2 x double] containing the left source operand.164/// \param __b165///    A 128-bit vector of [2 x double] containing the right source operand.166/// \returns A 128-bit vector of [2 x double] containing the alternating sums167///    and differences of both operands.168static __inline__ __m128d __DEFAULT_FN_ATTRS_CONSTEXPR169_mm_addsub_pd(__m128d __a, __m128d __b) {170  return __builtin_ia32_addsubpd((__v2df)__a, (__v2df)__b);171}172 173/// Horizontally adds the pairs of values contained in two 128-bit174///    vectors of [2 x double].175///176/// \headerfile <x86intrin.h>177///178/// This intrinsic corresponds to the <c> VHADDPD </c> instruction.179///180/// \param __a181///    A 128-bit vector of [2 x double] containing one of the source operands.182///    The horizontal sum of the values is stored in the lower bits of the183///    destination.184/// \param __b185///    A 128-bit vector of [2 x double] containing one of the source operands.186///    The horizontal sum of the values is stored in the upper bits of the187///    destination.188/// \returns A 128-bit vector of [2 x double] containing the horizontal sums of189///    both operands.190static __inline__ __m128d __DEFAULT_FN_ATTRS_CONSTEXPR191_mm_hadd_pd(__m128d __a, __m128d __b) {192  return __builtin_ia32_haddpd((__v2df)__a, (__v2df)__b);193}194 195/// Horizontally subtracts the pairs of values contained in two 128-bit196///    vectors of [2 x double].197///198/// \headerfile <x86intrin.h>199///200/// This intrinsic corresponds to the <c> VHSUBPD </c> instruction.201///202/// \param __a203///    A 128-bit vector of [2 x double] containing one of the source operands.204///    The horizontal difference of the values is stored in the lower bits of205///    the destination.206/// \param __b207///    A 128-bit vector of [2 x double] containing one of the source operands.208///    The horizontal difference of the values is stored in the upper bits of209///    the destination.210/// \returns A 128-bit vector of [2 x double] containing the horizontal211///    differences of both operands.212static __inline__ __m128d __DEFAULT_FN_ATTRS_CONSTEXPR213_mm_hsub_pd(__m128d __a, __m128d __b) {214  return __builtin_ia32_hsubpd((__v2df)__a, (__v2df)__b);215}216 217/// Moves and duplicates one double-precision value to double-precision218///    values stored in a 128-bit vector of [2 x double].219///220/// \headerfile <x86intrin.h>221///222/// \code223/// __m128d _mm_loaddup_pd(double const *dp);224/// \endcode225///226/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.227///228/// \param dp229///    A pointer to a double-precision value to be moved and duplicated.230/// \returns A 128-bit vector of [2 x double] containing the moved and231///    duplicated values.232#define        _mm_loaddup_pd(dp)        _mm_load1_pd(dp)233 234/// Moves and duplicates the double-precision value in the lower bits of235///    a 128-bit vector of [2 x double] to double-precision values stored in a236///    128-bit vector of [2 x double].237///238/// \headerfile <x86intrin.h>239///240/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.241///242/// \param __a243///    A 128-bit vector of [2 x double]. Bits [63:0] are written to bits244///    [127:64] and [63:0] of the destination.245/// \returns A 128-bit vector of [2 x double] containing the moved and246///    duplicated values.247static __inline__ __m128d __DEFAULT_FN_ATTRS_CONSTEXPR248_mm_movedup_pd(__m128d __a)249{250  return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);251}252 253/// Establishes a linear address memory range to be monitored and puts254///    the processor in the monitor event pending state. Data stored in the255///    monitored address range causes the processor to exit the pending state.256///257/// The \c MONITOR instruction can be used in kernel mode, and in other modes258/// if MSR <c> C001_0015h[MonMwaitUserEn] </c> is set.259///260/// \headerfile <x86intrin.h>261///262/// This intrinsic corresponds to the \c MONITOR instruction.263///264/// \param __p265///    The memory range to be monitored. The size of the range is determined by266///    CPUID function 0000_0005h.267/// \param __extensions268///    Optional extensions for the monitoring state.269/// \param __hints270///    Optional hints for the monitoring state.271static __inline__ void __DEFAULT_FN_ATTRS272_mm_monitor(void const *__p, unsigned __extensions, unsigned __hints)273{274  __builtin_ia32_monitor(__p, __extensions, __hints);275}276 277/// Used with the \c MONITOR instruction to wait while the processor is in278///    the monitor event pending state. Data stored in the monitored address279///    range, or an interrupt, causes the processor to exit the pending state.280///281/// The \c MWAIT instruction can be used in kernel mode, and in other modes if282/// MSR <c> C001_0015h[MonMwaitUserEn] </c> is set.283///284/// \headerfile <x86intrin.h>285///286/// This intrinsic corresponds to the \c MWAIT instruction.287///288/// \param __extensions289///    Optional extensions for the monitoring state, which can vary by290///    processor.291/// \param __hints292///    Optional hints for the monitoring state, which can vary by processor.293static __inline__ void __DEFAULT_FN_ATTRS294_mm_mwait(unsigned __extensions, unsigned __hints)295{296  __builtin_ia32_mwait(__extensions, __hints);297}298 299#undef __DEFAULT_FN_ATTRS300#undef __DEFAULT_FN_ATTRS_CONSTEXPR301 302#endif /* __PMMINTRIN_H */303