blob: 559ece2e3974ff321266c214c25f4ed877ba787d [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 Romanova1d4a0f22017-05-15 03:25:04 +000034/// vector.
35///
36/// If the address of the data is not 16-byte aligned, the instruction may
37/// read two adjacent aligned blocks of memory to retrieve the requested
38/// data.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000039///
40/// \headerfile <x86intrin.h>
41///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000042/// This intrinsic corresponds to the <c> VLDDQU </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000043///
44/// \param __p
45/// A pointer to a 128-bit integer vector containing integer values.
46/// \returns A 128-bit vector containing the moved values.
Michael Kupersteine45af542015-06-30 13:36:19 +000047static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000048_mm_lddqu_si128(__m128i const *__p)
Anders Carlssond0d8c542009-02-11 06:39:50 +000049{
David Blaikie3302f2b2013-01-16 23:08:36 +000050 return (__m128i)__builtin_ia32_lddqu((char const *)__p);
Anders Carlssond0d8c542009-02-11 06:39:50 +000051}
52
Ekaterina Romanovad4167472016-02-08 22:35:09 +000053/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
54/// two 128-bit vectors of [4 x float].
55///
56/// \headerfile <x86intrin.h>
57///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000058/// This intrinsic corresponds to the <c> VADDSUBPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000059///
60/// \param __a
61/// A 128-bit vector of [4 x float] containing the left source operand.
62/// \param __b
63/// A 128-bit vector of [4 x float] containing the right source operand.
64/// \returns A 128-bit vector of [4 x float] containing the alternating sums and
65/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000066static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000067_mm_addsub_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +000068{
Craig Topper1aa231e2016-05-16 06:38:42 +000069 return __builtin_ia32_addsubps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +000070}
71
Ekaterina Romanovad4167472016-02-08 22:35:09 +000072/// \brief Horizontally adds the adjacent pairs of values contained in two
73/// 128-bit vectors of [4 x float].
74///
75/// \headerfile <x86intrin.h>
76///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +000077/// This intrinsic corresponds to the <c> VHADDPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +000078///
79/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000080/// 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 lower bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +000082/// destination.
83/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000084/// A 128-bit vector of [4 x float] containing one of the source operands.
85/// The horizontal sums of the values are stored in the upper bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +000086/// destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +000087/// \returns A 128-bit vector of [4 x float] containing the horizontal sums of
Ekaterina Romanovad4167472016-02-08 22:35:09 +000088/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000089static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000090_mm_hadd_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +000091{
Craig Topper1aa231e2016-05-16 06:38:42 +000092 return __builtin_ia32_haddps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +000093}
94
Ekaterina Romanovad4167472016-02-08 22:35:09 +000095/// \brief Horizontally subtracts the adjacent pairs of values contained in two
96/// 128-bit vectors of [4 x float].
97///
98/// \headerfile <x86intrin.h>
99///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000100/// This intrinsic corresponds to the <c> VHSUBPS </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000101///
102/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000103/// A 128-bit vector of [4 x float] containing one of the source operands.
104/// The horizontal differences between the values are stored in the lower
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000105/// bits of the destination.
106/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000107/// A 128-bit vector of [4 x float] containing one of the source operands.
108/// The horizontal differences between the values are stored in the upper
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000109/// bits of the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000110/// \returns A 128-bit vector of [4 x float] containing the horizontal
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000111/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000112static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000113_mm_hsub_ps(__m128 __a, __m128 __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000114{
Craig Topper1aa231e2016-05-16 06:38:42 +0000115 return __builtin_ia32_hsubps((__v4sf)__a, (__v4sf)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000116}
117
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000118/// \brief Moves and duplicates high-order (odd-indexed) values from a 128-bit
119/// vector of [4 x float] to float values stored in a 128-bit vector of
Ekaterina Romanova2e041c92017-01-13 01:14:08 +0000120/// [4 x float].
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000121///
122/// \headerfile <x86intrin.h>
123///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000124/// This intrinsic corresponds to the <c> VMOVSHDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000125///
126/// \param __a
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +0000127/// A 128-bit vector of [4 x float]. \n
128/// Bits [127:96] of the source are written to bits [127:96] and [95:64] of
129/// the destination. \n
130/// Bits [63:32] of the source are written to bits [63:32] and [31:0] of the
131/// destination.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000132/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
133/// values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000134static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000135_mm_movehdup_ps(__m128 __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000136{
Craig Topper1aa231e2016-05-16 06:38:42 +0000137 return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 1, 1, 3, 3);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000138}
139
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +0000140/// \brief Duplicates low-order (even-indexed) values from a 128-bit vector of
Ekaterina Romanova2e041c92017-01-13 01:14:08 +0000141/// [4 x float] to float values stored in a 128-bit vector of [4 x float].
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000142///
143/// \headerfile <x86intrin.h>
144///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000145/// This intrinsic corresponds to the <c> VMOVSLDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000146///
147/// \param __a
Ekaterina Romanovadffe45b2016-12-27 00:49:38 +0000148/// A 128-bit vector of [4 x float] \n
149/// Bits [95:64] of the source are written to bits [127:96] and [95:64] of
150/// the destination. \n
151/// Bits [31:0] of the source are written to bits [63:32] and [31:0] of the
152/// destination.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000153/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
154/// values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000155static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000156_mm_moveldup_ps(__m128 __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000157{
Craig Topper1aa231e2016-05-16 06:38:42 +0000158 return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 0, 2, 2);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000159}
160
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000161/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
162/// two 128-bit vectors of [2 x double].
163///
164/// \headerfile <x86intrin.h>
165///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000166/// This intrinsic corresponds to the <c> VADDSUBPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000167///
168/// \param __a
169/// A 128-bit vector of [2 x double] containing the left source operand.
170/// \param __b
171/// A 128-bit vector of [2 x double] containing the right source operand.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000172/// \returns A 128-bit vector of [2 x double] containing the alternating sums
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000173/// and differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000174static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000175_mm_addsub_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000176{
Craig Topper1aa231e2016-05-16 06:38:42 +0000177 return __builtin_ia32_addsubpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000178}
179
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000180/// \brief Horizontally adds the pairs of values contained in two 128-bit
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000181/// vectors of [2 x double].
182///
183/// \headerfile <x86intrin.h>
184///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000185/// This intrinsic corresponds to the <c> VHADDPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000186///
187/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000188/// A 128-bit vector of [2 x double] containing one of the source operands.
189/// The horizontal sum of the values is stored in the lower bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000190/// destination.
191/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000192/// A 128-bit vector of [2 x double] containing one of the source operands.
193/// The horizontal sum of the values is stored in the upper bits of the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000194/// destination.
195/// \returns A 128-bit vector of [2 x double] containing the horizontal sums of
196/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000197static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000198_mm_hadd_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000199{
Craig Topper1aa231e2016-05-16 06:38:42 +0000200 return __builtin_ia32_haddpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000201}
202
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000203/// \brief Horizontally subtracts the pairs of values contained in two 128-bit
204/// vectors of [2 x double].
205///
206/// \headerfile <x86intrin.h>
207///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000208/// This intrinsic corresponds to the <c> VHSUBPD </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000209///
210/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000211/// A 128-bit vector of [2 x double] containing one of the source operands.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000212/// The horizontal difference of the values is stored in the lower bits of
213/// the destination.
214/// \param __b
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000215/// A 128-bit vector of [2 x double] containing one of the source operands.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000216/// The horizontal difference of the values is stored in the upper bits of
217/// the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000218/// \returns A 128-bit vector of [2 x double] containing the horizontal
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000219/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000220static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000221_mm_hsub_pd(__m128d __a, __m128d __b)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000222{
Craig Topper1aa231e2016-05-16 06:38:42 +0000223 return __builtin_ia32_hsubpd((__v2df)__a, (__v2df)__b);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000224}
225
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000226/// \brief Moves and duplicates one double-precision value to double-precision
227/// values stored in a 128-bit vector of [2 x double].
228///
229/// \headerfile <x86intrin.h>
230///
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000231/// \code
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000232/// __m128d _mm_loaddup_pd(double const * dp);
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000233/// \endcode
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000234///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000235/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000236///
237/// \param dp
238/// A pointer to a double-precision value to be moved and duplicated.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000239/// \returns A 128-bit vector of [2 x double] containing the moved and
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000240/// duplicated values.
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000241#define _mm_loaddup_pd(dp) _mm_load1_pd(dp)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000242
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000243/// \brief Moves and duplicates the double-precision value in the lower bits of
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000244/// a 128-bit vector of [2 x double] to double-precision values stored in a
245/// 128-bit vector of [2 x double].
246///
247/// \headerfile <x86intrin.h>
248///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000249/// This intrinsic corresponds to the <c> VMOVDDUP </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000250///
251/// \param __a
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000252/// A 128-bit vector of [2 x double]. Bits [63:0] are written to bits
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000253/// [127:64] and [63:0] of the destination.
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000254/// \returns A 128-bit vector of [2 x double] containing the moved and
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000255/// duplicated values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000256static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000257_mm_movedup_pd(__m128d __a)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000258{
Craig Topper1aa231e2016-05-16 06:38:42 +0000259 return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000260}
261
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000262/// \brief Establishes a linear address memory range to be monitored and puts
263/// the processor in the monitor event pending state. Data stored in the
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000264/// monitored address range causes the processor to exit the pending state.
265///
266/// \headerfile <x86intrin.h>
267///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000268/// This intrinsic corresponds to the <c> MONITOR </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000269///
270/// \param __p
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000271/// The memory range to be monitored. The size of the range is determined by
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000272/// CPUID function 0000_0005h.
273/// \param __extensions
274/// Optional extensions for the monitoring state.
275/// \param __hints
276/// Optional hints for the monitoring state.
Michael Kupersteine45af542015-06-30 13:36:19 +0000277static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000278_mm_monitor(void const *__p, unsigned __extensions, unsigned __hints)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000279{
David Blaikie3302f2b2013-01-16 23:08:36 +0000280 __builtin_ia32_monitor((void *)__p, __extensions, __hints);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000281}
282
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000283/// \brief Used with the MONITOR instruction to wait while the processor is in
284/// the monitor event pending state. Data stored in the monitored address
285/// range causes the processor to exit the pending state.
286///
287/// \headerfile <x86intrin.h>
288///
Ekaterina Romanova0c1c3bb2016-12-09 18:35:50 +0000289/// This intrinsic corresponds to the <c> MWAIT </c> instruction.
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000290///
291/// \param __extensions
Ekaterina Romanova5a7f09c2016-05-28 00:18:59 +0000292/// Optional extensions for the monitoring state, which may vary by
Ekaterina Romanovad4167472016-02-08 22:35:09 +0000293/// processor.
294/// \param __hints
295/// Optional hints for the monitoring state, which may vary by processor.
Michael Kupersteine45af542015-06-30 13:36:19 +0000296static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000297_mm_mwait(unsigned __extensions, unsigned __hints)
Anders Carlssond0d8c542009-02-11 06:39:50 +0000298{
David Blaikie3302f2b2013-01-16 23:08:36 +0000299 __builtin_ia32_mwait(__extensions, __hints);
Anders Carlssond0d8c542009-02-11 06:39:50 +0000300}
301
Michael Kupersteine45af542015-06-30 13:36:19 +0000302#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000303
Anders Carlssond0d8c542009-02-11 06:39:50 +0000304#endif /* __PMMINTRIN_H */