blob: 5f201fb53bd10e7a6a9d065079c598d4eb495aec [file] [log] [blame]
Anders Carlssond0d8c542009-02-11 06:39:50 +00001/*===---- pmmintrin.h - SSE3 intrinsics ------------------------------------===
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * 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 */
Sean Silvae4c37602015-09-12 02:55:19 +000023
Anders Carlssond0d8c542009-02-11 06:39:50 +000024#ifndef __PMMINTRIN_H
25#define __PMMINTRIN_H
26
Anders Carlssond0d8c542009-02-11 06:39:50 +000027#include <emmintrin.h>
28
Eric Christopher4d1851682015-06-17 07:09:20 +000029/* Define the default attributes for the functions in this file. */
Ekaterina Romanovad4167472016-02-08 22:35:09 +000030#define __DEFAULT_FN_ATTRS \
31 __attribute__((__always_inline__, __nodebug__, __target__("sse3")))
Eric Christopher4d1851682015-06-17 07:09:20 +000032
Ekaterina Romanovad4167472016-02-08 22:35:09 +000033/// \brief Loads data from an unaligned memory location to elements in a 128-bit
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000034/// vector. If the address of the data is not 16-byte aligned, the
35/// instruction may read two adjacent aligned blocks of memory to retrieve
36/// the requested data.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000037///
38/// \headerfile <x86intrin.h>
39///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000040/// This intrinsic corresponds to the <c> VLDDQU </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000041///
42/// \param __p
43/// A pointer to a 128-bit integer vector containing integer values.
44/// \returns A 128-bit vector containing the moved values.
Michael Kupersteine45af542015-06-30 13:36:19 +000045static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000046_mm_lddqu_si128(__m128i const *__p)
Anders Carlssond0d8c542009-02-11 06:39:50 +000047{
David Blaikie3302f2b2013-01-16 23:08:36 +000048 return (__m128i)__builtin_ia32_lddqu((char const *)__p);
Anders Carlssond0d8c542009-02-11 06:39:50 +000049}
50
Ekaterina Romanovad4167472016-02-08 22:35:09 +000051/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
52/// two 128-bit vectors of [4 x float].
53///
54/// \headerfile <x86intrin.h>
55///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000056/// This intrinsic corresponds to the <c> VADDSUBPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000057///
58/// \param __a
59/// A 128-bit vector of [4 x float] containing the left source operand.
60/// \param __b
61/// A 128-bit vector of [4 x float] containing the right source operand.
62/// \returns A 128-bit vector of [4 x float] containing the alternating sums and
63/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000064static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000065_mm_addsub_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +000066{
Craig Topper1aa231e2016-05-16 06:38:42 +000067 return __builtin_ia32_addsubps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +000068}
69
Ekaterina Romanovad4167472016-02-08 22:35:09 +000070/// \brief Horizontally adds the adjacent pairs of values contained in two
71/// 128-bit vectors of [4 x float].
72///
73/// \headerfile <x86intrin.h>
74///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000075/// This intrinsic corresponds to the <c> VHADDPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000076///
77/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000078/// A 128-bit vector of [4 x float] containing one of the source operands.
79/// The horizontal sums of the values are stored in the lower bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +000080/// destination.
81/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000082/// A 128-bit vector of [4 x float] containing one of the source operands.
83/// The horizontal sums of the values are stored in the upper bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +000084/// destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000085/// \returns A 128-bit vector of [4 x float] containing the horizontal sums of
Ekaterina Romanovad4167472016-02-08 22:35:09 +000086/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000087static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000088_mm_hadd_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +000089{
Craig Topper1aa231e2016-05-16 06:38:42 +000090 return __builtin_ia32_haddps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +000091}
92
Ekaterina Romanovad4167472016-02-08 22:35:09 +000093/// \brief Horizontally subtracts the adjacent pairs of values contained in two
94/// 128-bit vectors of [4 x float].
95///
96/// \headerfile <x86intrin.h>
97///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000098/// This intrinsic corresponds to the <c> VHSUBPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000099///
100/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000101/// A 128-bit vector of [4 x float] containing one of the source operands.
102/// The horizontal differences between the values are stored in the lower
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000103/// bits of the destination.
104/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000105/// A 128-bit vector of [4 x float] containing one of the source operands.
106/// The horizontal differences between the values are stored in the upper
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000107/// bits of the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000108/// \returns A 128-bit vector of [4 x float] containing the horizontal
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000109/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000110static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000111_mm_hsub_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000112{
Craig Topper1aa231e2016-05-16 06:38:42 +0000113 return __builtin_ia32_hsubps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000114}
115
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000116/// \brief Moves and duplicates high-order (odd-indexed) values from a 128-bit
117/// vector of [4 x float] to float values stored in a 128-bit vector of
118/// [4 x float].
119/// Bits [127:96] of the source are written to bits [127:96] and [95:64] of
120/// the destination.
121/// Bits [63:32] of the source are written to bits [63:32] and [31:0] of the
122/// destination.
123///
124/// \headerfile <x86intrin.h>
125///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000126/// This intrinsic corresponds to the <c> VMOVSHDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000127///
128/// \param __a
129/// A 128-bit vector of [4 x float].
130/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
131/// values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000132static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000133_mm_movehdup_ps(__m128 __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000134{
Craig Topper1aa231e2016-05-16 06:38:42 +0000135 return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 1, 1, 3, 3);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000136}
137
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000138/// \brief Duplicates low-order (even-indexed) values from a 128-bit
139/// vector of [4 x float] to float values stored in a 128-bit vector of
140/// [4 x float].
141/// Bits [95:64] of the source are written to bits [127:96] and [95:64] of
142/// the destination.
143/// Bits [31:0] of the source are written to bits [63:32] and [31:0] of the
144/// destination.
145///
146/// \headerfile <x86intrin.h>
147///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000148/// This intrinsic corresponds to the <c> VMOVSLDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000149///
150/// \param __a
151/// A 128-bit vector of [4 x float].
152/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
153/// values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000154static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000155_mm_moveldup_ps(__m128 __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000156{
Craig Topper1aa231e2016-05-16 06:38:42 +0000157 return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 0, 2, 2);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000158}
159
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000160/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
161/// two 128-bit vectors of [2 x double].
162///
163/// \headerfile <x86intrin.h>
164///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000165/// This intrinsic corresponds to the <c> VADDSUBPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000166///
167/// \param __a
168/// A 128-bit vector of [2 x double] containing the left source operand.
169/// \param __b
170/// A 128-bit vector of [2 x double] containing the right source operand.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000171/// \returns A 128-bit vector of [2 x double] containing the alternating sums
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000172/// and differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000173static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000174_mm_addsub_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000175{
Craig Topper1aa231e2016-05-16 06:38:42 +0000176 return __builtin_ia32_addsubpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000177}
178
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000179/// \brief Horizontally adds the pairs of values contained in two 128-bit
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000180/// vectors of [2 x double].
181///
182/// \headerfile <x86intrin.h>
183///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000184/// This intrinsic corresponds to the <c> VHADDPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000185///
186/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000187/// A 128-bit vector of [2 x double] containing one of the source operands.
188/// The horizontal sum of the values is stored in the lower bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000189/// destination.
190/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000191/// A 128-bit vector of [2 x double] containing one of the source operands.
192/// The horizontal sum of the values is stored in the upper bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000193/// destination.
194/// \returns A 128-bit vector of [2 x double] containing the horizontal sums of
195/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000196static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000197_mm_hadd_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000198{
Craig Topper1aa231e2016-05-16 06:38:42 +0000199 return __builtin_ia32_haddpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000200}
201
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000202/// \brief Horizontally subtracts the pairs of values contained in two 128-bit
203/// vectors of [2 x double].
204///
205/// \headerfile <x86intrin.h>
206///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000207/// This intrinsic corresponds to the <c> VHSUBPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000208///
209/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000210/// A 128-bit vector of [2 x double] containing one of the source operands.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000211/// The horizontal difference of the values is stored in the lower bits of
212/// the destination.
213/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000214/// A 128-bit vector of [2 x double] containing one of the source operands.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000215/// The horizontal difference of the values is stored in the upper bits of
216/// the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000217/// \returns A 128-bit vector of [2 x double] containing the horizontal
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000218/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000219static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000220_mm_hsub_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000221{
Craig Topper1aa231e2016-05-16 06:38:42 +0000222 return __builtin_ia32_hsubpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000223}
224
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000225/// \brief Moves and duplicates one double-precision value to double-precision
226/// values stored in a 128-bit vector of [2 x double].
227///
228/// \headerfile <x86intrin.h>
229///
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000230/// \code
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000231/// __m128d _mm_loaddup_pd(double const * dp);
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000232/// \endcode
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000233///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000234/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000235///
236/// \param dp
237/// A pointer to a double-precision value to be moved and duplicated.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000238/// \returns A 128-bit vector of [2 x double] containing the moved and
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000239/// duplicated values.
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000240#define _mm_loaddup_pd(dp) _mm_load1_pd(dp)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000241
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000242/// \brief Moves and duplicates the double-precision value in the lower bits of
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000243/// a 128-bit vector of [2 x double] to double-precision values stored in a
244/// 128-bit vector of [2 x double].
245///
246/// \headerfile <x86intrin.h>
247///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000248/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000249///
250/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000251/// A 128-bit vector of [2 x double]. Bits [63:0] are written to bits
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000252/// [127:64] and [63:0] of the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000253/// \returns A 128-bit vector of [2 x double] containing the moved and
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000254/// duplicated values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000255static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000256_mm_movedup_pd(__m128d __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000257{
Craig Topper1aa231e2016-05-16 06:38:42 +0000258 return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000259}
260
261#define _MM_DENORMALS_ZERO_ON (0x0040)
262#define _MM_DENORMALS_ZERO_OFF (0x0000)
263
264#define _MM_DENORMALS_ZERO_MASK (0x0040)
265
266#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
267#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (x)))
268
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000269/// \brief Establishes a linear address memory range to be monitored and puts
270/// the processor in the monitor event pending state. Data stored in the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000271/// monitored address range causes the processor to exit the pending state.
272///
273/// \headerfile <x86intrin.h>
274///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000275/// This intrinsic corresponds to the <c> MONITOR </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000276///
277/// \param __p
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000278/// The memory range to be monitored. The size of the range is determined by
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000279/// CPUID function 0000_0005h.
280/// \param __extensions
281/// Optional extensions for the monitoring state.
282/// \param __hints
283/// Optional hints for the monitoring state.
Michael Kupersteine45af542015-06-30 13:36:19 +0000284static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000285_mm_monitor(void const *__p, unsigned __extensions, unsigned __hints)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000286{
David Blaikie3302f2b2013-01-16 23:08:36 +0000287 __builtin_ia32_monitor((void *)__p, __extensions, __hints);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000288}
289
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000290/// \brief Used with the MONITOR instruction to wait while the processor is in
291/// the monitor event pending state. Data stored in the monitored address
292/// range causes the processor to exit the pending state.
293///
294/// \headerfile <x86intrin.h>
295///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000296/// This intrinsic corresponds to the <c> MWAIT </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000297///
298/// \param __extensions
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000299/// Optional extensions for the monitoring state, which may vary by
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000300/// processor.
301/// \param __hints
302/// Optional hints for the monitoring state, which may vary by processor.
Michael Kupersteine45af542015-06-30 13:36:19 +0000303static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000304_mm_mwait(unsigned __extensions, unsigned __hints)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000305{
David Blaikie3302f2b2013-01-16 23:08:36 +0000306 __builtin_ia32_mwait(__extensions, __hints);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000307}
308
Michael Kupersteine45af542015-06-30 13:36:19 +0000309#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000310
Anders Carlssond0d8c542009-02-11 06:39:50 +0000311#endif /* __PMMINTRIN_H */