blob: 8985bb404f477cf1d9c3e9daf2f163b4f0f1b9b5 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001/*===---- ammintrin.h - SSE4a 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 */
23
24#ifndef __AMMINTRIN_H
25#define __AMMINTRIN_H
26
27#include <pmmintrin.h>
28
29/* Define the default attributes for the functions in this file. */
30#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse4a")))
31
32/// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
33/// integer vector operand at the index idx and of the length len.
34///
35/// \headerfile <x86intrin.h>
36///
37/// \code
38/// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx);
39/// \endcode
40///
41/// This intrinsic corresponds to the \c EXTRQ instruction.
42///
43/// \param x
44/// The value from which bits are extracted.
45/// \param len
46/// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
47/// are zero, the length is interpreted as 64.
48/// \param idx
49/// Bits [5:0] specify the index of the least significant bit; the other
Ben Murdoch61f157c2016-09-16 13:49:30 +010050/// bits are ignored. If the sum of the index and length is greater than 64,
51/// the result is undefined. If the length and index are both zero, bits
52/// [63:0] of parameter x are extracted. If the length is zero but the index
53/// is non-zero, the result is undefined.
Ben Murdoch097c5b22016-05-18 11:27:45 +010054/// \returns A 128-bit integer vector whose lower 64 bits contain the bits
55/// extracted from the source operand.
56#define _mm_extracti_si64(x, len, idx) \
57 ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \
58 (char)(len), (char)(idx)))
59
60/// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
61/// integer vector operand at the index and of the length specified by __y.
62///
63/// \headerfile <x86intrin.h>
64///
65/// This intrinsic corresponds to the \c EXTRQ instruction.
66///
67/// \param __x
68/// The value from which bits are extracted.
69/// \param __y
Ben Murdoch61f157c2016-09-16 13:49:30 +010070/// Specifies the index of the least significant bit at [13:8] and the
71/// length at [5:0]; all other bits are ignored. If bits [5:0] are zero, the
72/// length is interpreted as 64. If the sum of the index and length is
73/// greater than 64, the result is undefined. If the length and index are
74/// both zero, bits [63:0] of parameter __x are extracted. If the length is
75/// zero but the index is non-zero, the result is undefined.
Ben Murdoch097c5b22016-05-18 11:27:45 +010076/// \returns A 128-bit vector whose lower 64 bits contain the bits extracted
77/// from the source operand.
78static __inline__ __m128i __DEFAULT_FN_ATTRS
79_mm_extract_si64(__m128i __x, __m128i __y)
80{
81 return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y);
82}
83
Ben Murdoch61f157c2016-09-16 13:49:30 +010084/// \brief Inserts bits of a specified length from the source integer vector y
85/// into the lower 64 bits of the destination integer vector x at the index
86/// idx and of the length len.
Ben Murdoch097c5b22016-05-18 11:27:45 +010087///
88/// \headerfile <x86intrin.h>
89///
90/// \code
91/// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len,
92/// const int idx);
93/// \endcode
94///
95/// This intrinsic corresponds to the \c INSERTQ instruction.
96///
97/// \param x
98/// The destination operand where bits will be inserted. The inserted bits
99/// are defined by the length len and by the index idx specifying the least
100/// significant bit.
101/// \param y
102/// The source operand containing the bits to be extracted. The extracted
103/// bits are the least significant bits of operand y of length len.
104/// \param len
105/// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
106/// are zero, the length is interpreted as 64.
107/// \param idx
108/// Bits [5:0] specify the index of the least significant bit; the other
Ben Murdoch61f157c2016-09-16 13:49:30 +0100109/// bits are ignored. If the sum of the index and length is greater than 64,
110/// the result is undefined. If the length and index are both zero, bits
111/// [63:0] of parameter y are inserted into parameter x. If the length is
112/// zero but the index is non-zero, the result is undefined.
113/// \returns A 128-bit integer vector containing the original lower 64-bits of
114/// destination operand x with the specified bitfields replaced by the lower
115/// bits of source operand y. The upper 64 bits of the return value are
116/// undefined.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100117
118#define _mm_inserti_si64(x, y, len, idx) \
119 ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
120 (__v2di)(__m128i)(y), \
121 (char)(len), (char)(idx)))
122
123/// \brief Inserts bits of a specified length from the source integer vector
Ben Murdoch61f157c2016-09-16 13:49:30 +0100124/// __y into the lower 64 bits of the destination integer vector __x at the
125/// index and of the length specified by __y.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100126///
127/// \headerfile <x86intrin.h>
128///
129/// This intrinsic corresponds to the \c INSERTQ instruction.
130///
131/// \param __x
132/// The destination operand where bits will be inserted. The inserted bits
133/// are defined by the length and by the index of the least significant bit
134/// specified by operand __y.
135/// \param __y
136/// The source operand containing the bits to be extracted. The extracted
137/// bits are the least significant bits of operand __y with length specified
138/// by bits [69:64]. These are inserted into the destination at the index
Ben Murdoch61f157c2016-09-16 13:49:30 +0100139/// specified by bits [77:72]; all other bits are ignored. If bits [69:64]
140/// are zero, the length is interpreted as 64. If the sum of the index and
141/// length is greater than 64, the result is undefined. If the length and
142/// index are both zero, bits [63:0] of parameter __y are inserted into
143/// parameter __x. If the length is zero but the index is non-zero, the
144/// result is undefined.
145/// \returns A 128-bit integer vector containing the original lower 64-bits of
146/// destination operand __x with the specified bitfields replaced by the
Ben Murdoch097c5b22016-05-18 11:27:45 +0100147/// lower bits of source operand __y. The upper 64 bits of the return value
148/// are undefined.
149
150static __inline__ __m128i __DEFAULT_FN_ATTRS
151_mm_insert_si64(__m128i __x, __m128i __y)
152{
153 return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y);
154}
155
156/// \brief Stores a 64-bit double-precision value in a 64-bit memory location.
157/// To minimize caching, the data is flagged as non-temporal (unlikely to be
158/// used again soon).
159///
160/// \headerfile <x86intrin.h>
161///
162/// This intrinsic corresponds to the \c MOVNTSD instruction.
163///
164/// \param __p
165/// The 64-bit memory location used to store the register value.
166/// \param __a
Ben Murdoch61f157c2016-09-16 13:49:30 +0100167/// The 64-bit double-precision floating-point register value to be stored.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100168static __inline__ void __DEFAULT_FN_ATTRS
169_mm_stream_sd(double *__p, __m128d __a)
170{
171 __builtin_ia32_movntsd(__p, (__v2df)__a);
172}
173
174/// \brief Stores a 32-bit single-precision floating-point value in a 32-bit
175/// memory location. To minimize caching, the data is flagged as
176/// non-temporal (unlikely to be used again soon).
177///
178/// \headerfile <x86intrin.h>
179///
180/// This intrinsic corresponds to the \c MOVNTSS instruction.
181///
182/// \param __p
183/// The 32-bit memory location used to store the register value.
184/// \param __a
Ben Murdoch61f157c2016-09-16 13:49:30 +0100185/// The 32-bit single-precision floating-point register value to be stored.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100186static __inline__ void __DEFAULT_FN_ATTRS
187_mm_stream_ss(float *__p, __m128 __a)
188{
189 __builtin_ia32_movntss(__p, (__v4sf)__a);
190}
191
192#undef __DEFAULT_FN_ATTRS
193
194#endif /* __AMMINTRIN_H */