1 /*===---- pmmintrin.h - SSE3 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 *===-----------------------------------------------------------------------===
13 #if !defined(__i386__) && !defined(__x86_64__)
14 #error "This header is only meant to be used on x86 and x64 architecture"
17 #include <emmintrin.h>
19 /* Define the default attributes for the functions in this file. */
20 #define __DEFAULT_FN_ATTRS \
21 __attribute__((__always_inline__, __nodebug__, __target__("sse3"), __min_vector_width__(128)))
23 /// Loads data from an unaligned memory location to elements in a 128-bit
26 /// If the address of the data is not 16-byte aligned, the instruction may
27 /// read two adjacent aligned blocks of memory to retrieve the requested
30 /// \headerfile <x86intrin.h>
32 /// This intrinsic corresponds to the <c> VLDDQU </c> instruction.
35 /// A pointer to a 128-bit integer vector containing integer values.
36 /// \returns A 128-bit vector containing the moved values.
37 static __inline__ __m128i __DEFAULT_FN_ATTRS
38 _mm_lddqu_si128(__m128i_u
const *__p
)
40 return (__m128i
)__builtin_ia32_lddqu((char const *)__p
);
43 /// Adds the even-indexed values and subtracts the odd-indexed values of
44 /// two 128-bit vectors of [4 x float].
46 /// \headerfile <x86intrin.h>
48 /// This intrinsic corresponds to the <c> VADDSUBPS </c> instruction.
51 /// A 128-bit vector of [4 x float] containing the left source operand.
53 /// A 128-bit vector of [4 x float] containing the right source operand.
54 /// \returns A 128-bit vector of [4 x float] containing the alternating sums and
55 /// differences of both operands.
56 static __inline__ __m128 __DEFAULT_FN_ATTRS
57 _mm_addsub_ps(__m128 __a
, __m128 __b
)
59 return __builtin_ia32_addsubps((__v4sf
)__a
, (__v4sf
)__b
);
62 /// Horizontally adds the adjacent pairs of values contained in two
63 /// 128-bit vectors of [4 x float].
65 /// \headerfile <x86intrin.h>
67 /// This intrinsic corresponds to the <c> VHADDPS </c> instruction.
70 /// A 128-bit vector of [4 x float] containing one of the source operands.
71 /// The horizontal sums of the values are stored in the lower bits of the
74 /// A 128-bit vector of [4 x float] containing one of the source operands.
75 /// The horizontal sums of the values are stored in the upper bits of the
77 /// \returns A 128-bit vector of [4 x float] containing the horizontal sums of
79 static __inline__ __m128 __DEFAULT_FN_ATTRS
80 _mm_hadd_ps(__m128 __a
, __m128 __b
)
82 return __builtin_ia32_haddps((__v4sf
)__a
, (__v4sf
)__b
);
85 /// Horizontally subtracts the adjacent pairs of values contained in two
86 /// 128-bit vectors of [4 x float].
88 /// \headerfile <x86intrin.h>
90 /// This intrinsic corresponds to the <c> VHSUBPS </c> instruction.
93 /// A 128-bit vector of [4 x float] containing one of the source operands.
94 /// The horizontal differences between the values are stored in the lower
95 /// bits of the destination.
97 /// A 128-bit vector of [4 x float] containing one of the source operands.
98 /// The horizontal differences between the values are stored in the upper
99 /// bits of the destination.
100 /// \returns A 128-bit vector of [4 x float] containing the horizontal
101 /// differences of both operands.
102 static __inline__ __m128 __DEFAULT_FN_ATTRS
103 _mm_hsub_ps(__m128 __a
, __m128 __b
)
105 return __builtin_ia32_hsubps((__v4sf
)__a
, (__v4sf
)__b
);
108 /// Moves and duplicates odd-indexed values from a 128-bit vector
109 /// of [4 x float] to float values stored in a 128-bit vector of
112 /// \headerfile <x86intrin.h>
114 /// This intrinsic corresponds to the <c> VMOVSHDUP </c> instruction.
117 /// A 128-bit vector of [4 x float]. \n
118 /// Bits [127:96] of the source are written to bits [127:96] and [95:64] of
119 /// the destination. \n
120 /// Bits [63:32] of the source are written to bits [63:32] and [31:0] of the
122 /// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
124 static __inline__ __m128 __DEFAULT_FN_ATTRS
125 _mm_movehdup_ps(__m128 __a
)
127 return __builtin_shufflevector((__v4sf
)__a
, (__v4sf
)__a
, 1, 1, 3, 3);
130 /// Duplicates even-indexed values from a 128-bit vector of
131 /// [4 x float] to float values stored in a 128-bit vector of [4 x float].
133 /// \headerfile <x86intrin.h>
135 /// This intrinsic corresponds to the <c> VMOVSLDUP </c> instruction.
138 /// A 128-bit vector of [4 x float] \n
139 /// Bits [95:64] of the source are written to bits [127:96] and [95:64] of
140 /// the destination. \n
141 /// Bits [31:0] of the source are written to bits [63:32] and [31:0] of the
143 /// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
145 static __inline__ __m128 __DEFAULT_FN_ATTRS
146 _mm_moveldup_ps(__m128 __a
)
148 return __builtin_shufflevector((__v4sf
)__a
, (__v4sf
)__a
, 0, 0, 2, 2);
151 /// Adds the even-indexed values and subtracts the odd-indexed values of
152 /// two 128-bit vectors of [2 x double].
154 /// \headerfile <x86intrin.h>
156 /// This intrinsic corresponds to the <c> VADDSUBPD </c> instruction.
159 /// A 128-bit vector of [2 x double] containing the left source operand.
161 /// A 128-bit vector of [2 x double] containing the right source operand.
162 /// \returns A 128-bit vector of [2 x double] containing the alternating sums
163 /// and differences of both operands.
164 static __inline__ __m128d __DEFAULT_FN_ATTRS
165 _mm_addsub_pd(__m128d __a
, __m128d __b
)
167 return __builtin_ia32_addsubpd((__v2df
)__a
, (__v2df
)__b
);
170 /// Horizontally adds the pairs of values contained in two 128-bit
171 /// vectors of [2 x double].
173 /// \headerfile <x86intrin.h>
175 /// This intrinsic corresponds to the <c> VHADDPD </c> instruction.
178 /// A 128-bit vector of [2 x double] containing one of the source operands.
179 /// The horizontal sum of the values is stored in the lower bits of the
182 /// A 128-bit vector of [2 x double] containing one of the source operands.
183 /// The horizontal sum of the values is stored in the upper bits of the
185 /// \returns A 128-bit vector of [2 x double] containing the horizontal sums of
187 static __inline__ __m128d __DEFAULT_FN_ATTRS
188 _mm_hadd_pd(__m128d __a
, __m128d __b
)
190 return __builtin_ia32_haddpd((__v2df
)__a
, (__v2df
)__b
);
193 /// Horizontally subtracts the pairs of values contained in two 128-bit
194 /// vectors of [2 x double].
196 /// \headerfile <x86intrin.h>
198 /// This intrinsic corresponds to the <c> VHSUBPD </c> instruction.
201 /// A 128-bit vector of [2 x double] containing one of the source operands.
202 /// The horizontal difference of the values is stored in the lower bits of
205 /// A 128-bit vector of [2 x double] containing one of the source operands.
206 /// The horizontal difference of the values is stored in the upper bits of
208 /// \returns A 128-bit vector of [2 x double] containing the horizontal
209 /// differences of both operands.
210 static __inline__ __m128d __DEFAULT_FN_ATTRS
211 _mm_hsub_pd(__m128d __a
, __m128d __b
)
213 return __builtin_ia32_hsubpd((__v2df
)__a
, (__v2df
)__b
);
216 /// Moves and duplicates one double-precision value to double-precision
217 /// values stored in a 128-bit vector of [2 x double].
219 /// \headerfile <x86intrin.h>
222 /// __m128d _mm_loaddup_pd(double const *dp);
225 /// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
228 /// A pointer to a double-precision value to be moved and duplicated.
229 /// \returns A 128-bit vector of [2 x double] containing the moved and
230 /// duplicated values.
231 #define _mm_loaddup_pd(dp) _mm_load1_pd(dp)
233 /// Moves and duplicates the double-precision value in the lower bits of
234 /// a 128-bit vector of [2 x double] to double-precision values stored in a
235 /// 128-bit vector of [2 x double].
237 /// \headerfile <x86intrin.h>
239 /// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
242 /// A 128-bit vector of [2 x double]. Bits [63:0] are written to bits
243 /// [127:64] and [63:0] of the destination.
244 /// \returns A 128-bit vector of [2 x double] containing the moved and
245 /// duplicated values.
246 static __inline__ __m128d __DEFAULT_FN_ATTRS
247 _mm_movedup_pd(__m128d __a
)
249 return __builtin_shufflevector((__v2df
)__a
, (__v2df
)__a
, 0, 0);
252 /// Establishes a linear address memory range to be monitored and puts
253 /// the processor in the monitor event pending state. Data stored in the
254 /// monitored address range causes the processor to exit the pending state.
256 /// The \c MONITOR instruction can be used in kernel mode, and in other modes
257 /// if MSR <c> C001_0015h[MonMwaitUserEn] </c> is set.
259 /// \headerfile <x86intrin.h>
261 /// This intrinsic corresponds to the \c MONITOR instruction.
264 /// The memory range to be monitored. The size of the range is determined by
265 /// CPUID function 0000_0005h.
266 /// \param __extensions
267 /// Optional extensions for the monitoring state.
269 /// Optional hints for the monitoring state.
270 static __inline__
void __DEFAULT_FN_ATTRS
271 _mm_monitor(void const *__p
, unsigned __extensions
, unsigned __hints
)
273 __builtin_ia32_monitor(__p
, __extensions
, __hints
);
276 /// Used with the \c MONITOR instruction to wait while the processor is in
277 /// the monitor event pending state. Data stored in the monitored address
278 /// range, or an interrupt, causes the processor to exit the pending state.
280 /// The \c MWAIT instruction can be used in kernel mode, and in other modes if
281 /// MSR <c> C001_0015h[MonMwaitUserEn] </c> is set.
283 /// \headerfile <x86intrin.h>
285 /// This intrinsic corresponds to the \c MWAIT instruction.
287 /// \param __extensions
288 /// Optional extensions for the monitoring state, which can vary by
291 /// Optional hints for the monitoring state, which can vary by processor.
292 static __inline__
void __DEFAULT_FN_ATTRS
293 _mm_mwait(unsigned __extensions
, unsigned __hints
)
295 __builtin_ia32_mwait(__extensions
, __hints
);
298 #undef __DEFAULT_FN_ATTRS
300 #endif /* __PMMINTRIN_H */