1 /*===---- ammintrin.h - SSE4a intrinsics -----------------------------------===
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
21 *===-----------------------------------------------------------------------===
28 #error "SSE4A instruction set not enabled"
31 #include <pmmintrin.h>
33 /* Define the default attributes for the functions in this file. */
34 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
36 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
37 /// integer vector operand at the index idx and of the length len.
39 /// \headerfile <x86intrin.h>
42 /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx);
46 /// This intrinsic corresponds to the \c EXTRQ instruction.
50 /// The value from which bits are extracted.
52 /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
53 /// are zero, the length is interpreted as 64.
55 /// Bits [5:0] specify the index of the least significant bit; the other
56 /// bits are ignored. If the sum of the index and length is greater than
57 /// 64, the result is undefined. If the length and index are both zero,
58 /// bits [63:0] of parameter x are extracted. If the length is zero
59 /// but the index is non-zero, the result is undefined.
60 /// \returns A 128-bit integer vector whose lower 64 bits contain the bits
61 /// extracted from the source operand.
62 #define _mm_extracti_si64(x, len, idx) \
63 ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \
64 (char)(len), (char)(idx)))
66 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
67 /// integer vector operand at the index and of the length specified by __y.
69 /// \headerfile <x86intrin.h>
72 /// This intrinsic corresponds to the \c EXTRQ instruction.
76 /// The value from which bits are extracted.
78 /// Specifies the index of the least significant bit at [13:8]
79 /// and the length at [5:0]; all other bits are ignored.
80 /// If bits [5:0] are zero, the length is interpreted as 64.
81 /// If the sum of the index and length is greater than 64, the result is
82 /// undefined. If the length and index are both zero, bits [63:0] of
83 /// parameter __x are extracted. If the length is zero but the index is
84 /// non-zero, the result is undefined.
85 /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted
86 /// from the source operand.
87 static __inline__ __m128i __DEFAULT_FN_ATTRS
88 _mm_extract_si64(__m128i __x, __m128i __y)
90 return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y);
93 /// \brief Inserts bits of a specified length from the source integer vector
94 /// y into the lower 64 bits of the destination integer vector x at the
95 /// index idx and of the length len.
97 /// \headerfile <x86intrin.h>
100 /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len,
105 /// This intrinsic corresponds to the \c INSERTQ instruction.
109 /// The destination operand where bits will be inserted. The inserted bits
110 /// are defined by the length len and by the index idx specifying the least
113 /// The source operand containing the bits to be extracted. The extracted
114 /// bits are the least significant bits of operand y of length len.
116 /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
117 /// are zero, the length is interpreted as 64.
119 /// Bits [5:0] specify the index of the least significant bit; the other
120 /// bits are ignored. If the sum of the index and length is greater than
121 /// 64, the result is undefined. If the length and index are both zero,
122 /// bits [63:0] of parameter y are inserted into parameter x. If the
123 /// length is zero but the index is non-zero, the result is undefined.
124 /// \returns A 128-bit integer vector containing the original lower 64-bits
125 /// of destination operand x with the specified bitfields replaced by the
126 /// lower bits of source operand y. The upper 64 bits of the return value
129 #define _mm_inserti_si64(x, y, len, idx) \
130 ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
131 (__v2di)(__m128i)(y), \
132 (char)(len), (char)(idx)))
134 /// \brief Inserts bits of a specified length from the source integer vector
135 /// __y into the lower 64 bits of the destination integer vector __x at
136 /// the index and of the length specified by __y.
138 /// \headerfile <x86intrin.h>
141 /// This intrinsic corresponds to the \c INSERTQ instruction.
145 /// The destination operand where bits will be inserted. The inserted bits
146 /// are defined by the length and by the index of the least significant bit
147 /// specified by operand __y.
149 /// The source operand containing the bits to be extracted. The extracted
150 /// bits are the least significant bits of operand __y with length specified
151 /// by bits [69:64]. These are inserted into the destination at the index
152 /// specified by bits [77:72]; all other bits are ignored.
153 /// If bits [69:64] are zero, the length is interpreted as 64.
154 /// If the sum of the index and length is greater than 64, the result is
155 /// undefined. If the length and index are both zero, bits [63:0] of
156 /// parameter __y are inserted into parameter __x. If the length
157 /// is zero but the index is non-zero, the result is undefined.
158 /// \returns A 128-bit integer vector containing the original lower 64-bits
159 /// of destination operand __x with the specified bitfields replaced by the
160 /// lower bits of source operand __y. The upper 64 bits of the return value
163 static __inline__ __m128i __DEFAULT_FN_ATTRS
164 _mm_insert_si64(__m128i __x, __m128i __y)
166 return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y);
169 /// \brief Stores a 64-bit double-precision value in a 64-bit memory location.
170 /// To minimize caching, the data is flagged as non-temporal (unlikely to be
171 /// used again soon).
173 /// \headerfile <x86intrin.h>
176 /// This intrinsic corresponds to the \c MOVNTSD instruction.
180 /// The 64-bit memory location used to store the register value.
182 /// The 64-bit double-precision floating-point register value to
184 static __inline__ void __DEFAULT_FN_ATTRS
185 _mm_stream_sd(double *__p, __m128d __a)
187 __builtin_ia32_movntsd(__p, (__v2df)__a);
190 /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit
191 /// memory location. To minimize caching, the data is flagged as
192 /// non-temporal (unlikely to be used again soon).
194 /// \headerfile <x86intrin.h>
197 /// This intrinsic corresponds to the \c MOVNTSS instruction.
201 /// The 32-bit memory location used to store the register value.
203 /// The 32-bit single-precision floating-point register value to
205 static __inline__ void __DEFAULT_FN_ATTRS
206 _mm_stream_ss(float *__p, __m128 __a)
208 __builtin_ia32_movntss(__p, (__v4sf)__a);
211 #undef __DEFAULT_FN_ATTRS
213 #endif /* __SSE4A__ */
215 #endif /* __AMMINTRIN_H */