1*67e74705SXin Li /*===---- ammintrin.h - SSE4a intrinsics -----------------------------------===
2*67e74705SXin Li *
3*67e74705SXin Li * Permission is hereby granted, free of charge, to any person obtaining a copy
4*67e74705SXin Li * of this software and associated documentation files (the "Software"), to deal
5*67e74705SXin Li * in the Software without restriction, including without limitation the rights
6*67e74705SXin Li * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*67e74705SXin Li * copies of the Software, and to permit persons to whom the Software is
8*67e74705SXin Li * furnished to do so, subject to the following conditions:
9*67e74705SXin Li *
10*67e74705SXin Li * The above copyright notice and this permission notice shall be included in
11*67e74705SXin Li * all copies or substantial portions of the Software.
12*67e74705SXin Li *
13*67e74705SXin Li * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*67e74705SXin Li * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*67e74705SXin Li * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*67e74705SXin Li * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*67e74705SXin Li * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*67e74705SXin Li * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*67e74705SXin Li * THE SOFTWARE.
20*67e74705SXin Li *
21*67e74705SXin Li *===-----------------------------------------------------------------------===
22*67e74705SXin Li */
23*67e74705SXin Li
24*67e74705SXin Li #ifndef __AMMINTRIN_H
25*67e74705SXin Li #define __AMMINTRIN_H
26*67e74705SXin Li
27*67e74705SXin Li #include <pmmintrin.h>
28*67e74705SXin Li
29*67e74705SXin Li /* Define the default attributes for the functions in this file. */
30*67e74705SXin Li #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse4a")))
31*67e74705SXin Li
32*67e74705SXin Li /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
33*67e74705SXin Li /// integer vector operand at the index idx and of the length len.
34*67e74705SXin Li ///
35*67e74705SXin Li /// \headerfile <x86intrin.h>
36*67e74705SXin Li ///
37*67e74705SXin Li /// \code
38*67e74705SXin Li /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx);
39*67e74705SXin Li /// \endcode
40*67e74705SXin Li ///
41*67e74705SXin Li /// This intrinsic corresponds to the \c EXTRQ instruction.
42*67e74705SXin Li ///
43*67e74705SXin Li /// \param x
44*67e74705SXin Li /// The value from which bits are extracted.
45*67e74705SXin Li /// \param len
46*67e74705SXin Li /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
47*67e74705SXin Li /// are zero, the length is interpreted as 64.
48*67e74705SXin Li /// \param idx
49*67e74705SXin Li /// Bits [5:0] specify the index of the least significant bit; the other
50*67e74705SXin Li /// bits are ignored. If the sum of the index and length is greater than 64,
51*67e74705SXin Li /// the result is undefined. If the length and index are both zero, bits
52*67e74705SXin Li /// [63:0] of parameter x are extracted. If the length is zero but the index
53*67e74705SXin Li /// is non-zero, the result is undefined.
54*67e74705SXin Li /// \returns A 128-bit integer vector whose lower 64 bits contain the bits
55*67e74705SXin Li /// extracted from the source operand.
56*67e74705SXin Li #define _mm_extracti_si64(x, len, idx) \
57*67e74705SXin Li ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \
58*67e74705SXin Li (char)(len), (char)(idx)))
59*67e74705SXin Li
60*67e74705SXin Li /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
61*67e74705SXin Li /// integer vector operand at the index and of the length specified by __y.
62*67e74705SXin Li ///
63*67e74705SXin Li /// \headerfile <x86intrin.h>
64*67e74705SXin Li ///
65*67e74705SXin Li /// This intrinsic corresponds to the \c EXTRQ instruction.
66*67e74705SXin Li ///
67*67e74705SXin Li /// \param __x
68*67e74705SXin Li /// The value from which bits are extracted.
69*67e74705SXin Li /// \param __y
70*67e74705SXin Li /// Specifies the index of the least significant bit at [13:8] and the
71*67e74705SXin Li /// length at [5:0]; all other bits are ignored. If bits [5:0] are zero, the
72*67e74705SXin Li /// length is interpreted as 64. If the sum of the index and length is
73*67e74705SXin Li /// greater than 64, the result is undefined. If the length and index are
74*67e74705SXin Li /// both zero, bits [63:0] of parameter __x are extracted. If the length is
75*67e74705SXin Li /// zero but the index is non-zero, the result is undefined.
76*67e74705SXin Li /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted
77*67e74705SXin Li /// from the source operand.
78*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_extract_si64(__m128i __x,__m128i __y)79*67e74705SXin Li _mm_extract_si64(__m128i __x, __m128i __y)
80*67e74705SXin Li {
81*67e74705SXin Li return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y);
82*67e74705SXin Li }
83*67e74705SXin Li
84*67e74705SXin Li /// \brief Inserts bits of a specified length from the source integer vector y
85*67e74705SXin Li /// into the lower 64 bits of the destination integer vector x at the index
86*67e74705SXin Li /// idx and of the length len.
87*67e74705SXin Li ///
88*67e74705SXin Li /// \headerfile <x86intrin.h>
89*67e74705SXin Li ///
90*67e74705SXin Li /// \code
91*67e74705SXin Li /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len,
92*67e74705SXin Li /// const int idx);
93*67e74705SXin Li /// \endcode
94*67e74705SXin Li ///
95*67e74705SXin Li /// This intrinsic corresponds to the \c INSERTQ instruction.
96*67e74705SXin Li ///
97*67e74705SXin Li /// \param x
98*67e74705SXin Li /// The destination operand where bits will be inserted. The inserted bits
99*67e74705SXin Li /// are defined by the length len and by the index idx specifying the least
100*67e74705SXin Li /// significant bit.
101*67e74705SXin Li /// \param y
102*67e74705SXin Li /// The source operand containing the bits to be extracted. The extracted
103*67e74705SXin Li /// bits are the least significant bits of operand y of length len.
104*67e74705SXin Li /// \param len
105*67e74705SXin Li /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
106*67e74705SXin Li /// are zero, the length is interpreted as 64.
107*67e74705SXin Li /// \param idx
108*67e74705SXin Li /// Bits [5:0] specify the index of the least significant bit; the other
109*67e74705SXin Li /// bits are ignored. If the sum of the index and length is greater than 64,
110*67e74705SXin Li /// the result is undefined. If the length and index are both zero, bits
111*67e74705SXin Li /// [63:0] of parameter y are inserted into parameter x. If the length is
112*67e74705SXin Li /// zero but the index is non-zero, the result is undefined.
113*67e74705SXin Li /// \returns A 128-bit integer vector containing the original lower 64-bits of
114*67e74705SXin Li /// destination operand x with the specified bitfields replaced by the lower
115*67e74705SXin Li /// bits of source operand y. The upper 64 bits of the return value are
116*67e74705SXin Li /// undefined.
117*67e74705SXin Li
118*67e74705SXin Li #define _mm_inserti_si64(x, y, len, idx) \
119*67e74705SXin Li ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
120*67e74705SXin Li (__v2di)(__m128i)(y), \
121*67e74705SXin Li (char)(len), (char)(idx)))
122*67e74705SXin Li
123*67e74705SXin Li /// \brief Inserts bits of a specified length from the source integer vector
124*67e74705SXin Li /// __y into the lower 64 bits of the destination integer vector __x at the
125*67e74705SXin Li /// index and of the length specified by __y.
126*67e74705SXin Li ///
127*67e74705SXin Li /// \headerfile <x86intrin.h>
128*67e74705SXin Li ///
129*67e74705SXin Li /// This intrinsic corresponds to the \c INSERTQ instruction.
130*67e74705SXin Li ///
131*67e74705SXin Li /// \param __x
132*67e74705SXin Li /// The destination operand where bits will be inserted. The inserted bits
133*67e74705SXin Li /// are defined by the length and by the index of the least significant bit
134*67e74705SXin Li /// specified by operand __y.
135*67e74705SXin Li /// \param __y
136*67e74705SXin Li /// The source operand containing the bits to be extracted. The extracted
137*67e74705SXin Li /// bits are the least significant bits of operand __y with length specified
138*67e74705SXin Li /// by bits [69:64]. These are inserted into the destination at the index
139*67e74705SXin Li /// specified by bits [77:72]; all other bits are ignored. If bits [69:64]
140*67e74705SXin Li /// are zero, the length is interpreted as 64. If the sum of the index and
141*67e74705SXin Li /// length is greater than 64, the result is undefined. If the length and
142*67e74705SXin Li /// index are both zero, bits [63:0] of parameter __y are inserted into
143*67e74705SXin Li /// parameter __x. If the length is zero but the index is non-zero, the
144*67e74705SXin Li /// result is undefined.
145*67e74705SXin Li /// \returns A 128-bit integer vector containing the original lower 64-bits of
146*67e74705SXin Li /// destination operand __x with the specified bitfields replaced by the
147*67e74705SXin Li /// lower bits of source operand __y. The upper 64 bits of the return value
148*67e74705SXin Li /// are undefined.
149*67e74705SXin Li
150*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_insert_si64(__m128i __x,__m128i __y)151*67e74705SXin Li _mm_insert_si64(__m128i __x, __m128i __y)
152*67e74705SXin Li {
153*67e74705SXin Li return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y);
154*67e74705SXin Li }
155*67e74705SXin Li
156*67e74705SXin Li /// \brief Stores a 64-bit double-precision value in a 64-bit memory location.
157*67e74705SXin Li /// To minimize caching, the data is flagged as non-temporal (unlikely to be
158*67e74705SXin Li /// used again soon).
159*67e74705SXin Li ///
160*67e74705SXin Li /// \headerfile <x86intrin.h>
161*67e74705SXin Li ///
162*67e74705SXin Li /// This intrinsic corresponds to the \c MOVNTSD instruction.
163*67e74705SXin Li ///
164*67e74705SXin Li /// \param __p
165*67e74705SXin Li /// The 64-bit memory location used to store the register value.
166*67e74705SXin Li /// \param __a
167*67e74705SXin Li /// The 64-bit double-precision floating-point register value to be stored.
168*67e74705SXin Li static __inline__ void __DEFAULT_FN_ATTRS
_mm_stream_sd(double * __p,__m128d __a)169*67e74705SXin Li _mm_stream_sd(double *__p, __m128d __a)
170*67e74705SXin Li {
171*67e74705SXin Li __builtin_ia32_movntsd(__p, (__v2df)__a);
172*67e74705SXin Li }
173*67e74705SXin Li
174*67e74705SXin Li /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit
175*67e74705SXin Li /// memory location. To minimize caching, the data is flagged as
176*67e74705SXin Li /// non-temporal (unlikely to be used again soon).
177*67e74705SXin Li ///
178*67e74705SXin Li /// \headerfile <x86intrin.h>
179*67e74705SXin Li ///
180*67e74705SXin Li /// This intrinsic corresponds to the \c MOVNTSS instruction.
181*67e74705SXin Li ///
182*67e74705SXin Li /// \param __p
183*67e74705SXin Li /// The 32-bit memory location used to store the register value.
184*67e74705SXin Li /// \param __a
185*67e74705SXin Li /// The 32-bit single-precision floating-point register value to be stored.
186*67e74705SXin Li static __inline__ void __DEFAULT_FN_ATTRS
_mm_stream_ss(float * __p,__m128 __a)187*67e74705SXin Li _mm_stream_ss(float *__p, __m128 __a)
188*67e74705SXin Li {
189*67e74705SXin Li __builtin_ia32_movntss(__p, (__v4sf)__a);
190*67e74705SXin Li }
191*67e74705SXin Li
192*67e74705SXin Li #undef __DEFAULT_FN_ATTRS
193*67e74705SXin Li
194*67e74705SXin Li #endif /* __AMMINTRIN_H */
195