Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 1 | /*===---- 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 | #ifndef __SSE4A__ |
| 28 | #error "SSE4A instruction set not enabled" |
| 29 | #else |
| 30 | |
| 31 | #include <pmmintrin.h> |
| 32 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 33 | /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit |
| 34 | /// integer vector operand at the index idx and of the length len. |
| 35 | /// |
| 36 | /// \headerfile <x86intrin.h> |
| 37 | /// |
| 38 | /// \code |
| 39 | /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx); |
| 40 | /// \endcode |
| 41 | /// |
| 42 | /// \code |
| 43 | /// This intrinsic corresponds to the \c EXTRQ instruction. |
| 44 | /// \endcode |
| 45 | /// |
| 46 | /// \param x |
| 47 | /// The value from which bits are extracted. |
| 48 | /// \param len |
| 49 | /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] |
| 50 | /// are zero, the length is interpreted as 64. |
| 51 | /// \param idx |
| 52 | /// Bits [5:0] specify the index of the least significant bit; the other |
| 53 | /// bits are ignored. If the sum of the index and length is greater than |
| 54 | /// 64, the result is undefined. If the length and index are both zero, |
| 55 | /// bits [63:0] of parameter x are extracted. If the length is zero |
| 56 | /// but the index is non-zero, the result is undefined. |
| 57 | /// \returns A 128-bit integer vector whose lower 64 bits contain the bits |
| 58 | /// extracted from the source operand. |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 59 | #define _mm_extracti_si64(x, len, idx) \ |
| 60 | ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \ |
| 61 | (char)(len), (char)(idx))) |
| 62 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 63 | /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit |
| 64 | /// integer vector operand at the index and of the length specified by __y. |
| 65 | /// |
| 66 | /// \headerfile <x86intrin.h> |
| 67 | /// |
| 68 | /// \code |
| 69 | /// This intrinsic corresponds to the \c EXTRQ instruction. |
| 70 | /// \endcode |
| 71 | /// |
| 72 | /// \param __x |
| 73 | /// The value from which bits are extracted. |
| 74 | /// \param __y |
| 75 | /// Specifies the index of the least significant bit at [13:8] |
| 76 | /// and the length at [5:0]; all other bits are ignored. |
| 77 | /// If bits [5:0] are zero, the length is interpreted as 64. |
| 78 | /// If the sum of the index and length is greater than 64, the result is |
| 79 | /// undefined. If the length and index are both zero, bits [63:0] of |
| 80 | /// parameter __x are extracted. If the length is zero but the index is |
| 81 | /// non-zero, the result is undefined. |
| 82 | /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted |
| 83 | /// from the source operand. |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 84 | static __inline__ __m128i __attribute__((__always_inline__, __nodebug__)) |
| 85 | _mm_extract_si64(__m128i __x, __m128i __y) |
| 86 | { |
| 87 | return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y); |
| 88 | } |
| 89 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 90 | /// \brief Inserts bits of a specified length from the source integer vector |
| 91 | /// y into the lower 64 bits of the destination integer vector x at the |
| 92 | /// index idx and of the length len. |
| 93 | /// |
| 94 | /// \headerfile <x86intrin.h> |
| 95 | /// |
| 96 | /// \code |
| 97 | /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len, |
| 98 | /// const int idx); |
| 99 | /// \endcode |
| 100 | /// |
| 101 | /// \code |
| 102 | /// This intrinsic corresponds to the \c INSERTQ instruction. |
| 103 | /// \endcode |
| 104 | /// |
| 105 | /// \param x |
| 106 | /// The destination operand where bits will be inserted. The inserted bits |
| 107 | /// are defined by the length len and by the index idx specifying the least |
| 108 | /// significant bit. |
| 109 | /// \param y |
| 110 | /// The source operand containing the bits to be extracted. The extracted |
| 111 | /// bits are the least significant bits of operand y of length len. |
| 112 | /// \param len |
| 113 | /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] |
| 114 | /// are zero, the length is interpreted as 64. |
| 115 | /// \param idx |
| 116 | /// Bits [5:0] specify the index of the least significant bit; the other |
| 117 | /// bits are ignored. If the sum of the index and length is greater than |
| 118 | /// 64, the result is undefined. If the length and index are both zero, |
| 119 | /// bits [63:0] of parameter y are inserted into parameter x. If the |
| 120 | /// length is zero but the index is non-zero, the result is undefined. |
| 121 | /// \returns A 128-bit integer vector containing the original lower 64-bits |
| 122 | /// of destination operand x with the specified bitfields replaced by the |
| 123 | /// lower bits of source operand y. The upper 64 bits of the return value |
| 124 | /// are undefined. |
| 125 | |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 126 | #define _mm_inserti_si64(x, y, len, idx) \ |
| 127 | ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \ |
| 128 | (__v2di)(__m128i)(y), \ |
| 129 | (char)(len), (char)(idx))) |
| 130 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 131 | /// \brief Inserts bits of a specified length from the source integer vector |
| 132 | /// __y into the lower 64 bits of the destination integer vector __x at |
| 133 | /// the index and of the length specified by __y. |
| 134 | /// |
| 135 | /// \headerfile <x86intrin.h> |
| 136 | /// |
| 137 | /// \code |
| 138 | /// This intrinsic corresponds to the \c INSERTQ instruction. |
| 139 | /// \endcode |
| 140 | /// |
| 141 | /// \param __x |
| 142 | /// The destination operand where bits will be inserted. The inserted bits |
| 143 | /// are defined by the length and by the index of the least significant bit |
| 144 | /// specified by operand __y. |
| 145 | /// \param __y |
| 146 | /// The source operand containing the bits to be extracted. The extracted |
| 147 | /// bits are the least significant bits of operand __y with length specified |
| 148 | /// by bits [69:64]. These are inserted into the destination at the index |
| 149 | /// specified by bits [77:72]; all other bits are ignored. |
| 150 | /// If bits [69:64] are zero, the length is interpreted as 64. |
| 151 | /// If the sum of the index and length is greater than 64, the result is |
| 152 | /// undefined. If the length and index are both zero, bits [63:0] of |
| 153 | /// parameter __y are inserted into parameter __x. If the length |
| 154 | /// is zero but the index is non-zero, the result is undefined. |
| 155 | /// \returns A 128-bit integer vector containing the original lower 64-bits |
| 156 | /// of destination operand __x with the specified bitfields replaced by the |
| 157 | /// lower bits of source operand __y. The upper 64 bits of the return value |
| 158 | /// are undefined. |
| 159 | |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 160 | static __inline__ __m128i __attribute__((__always_inline__, __nodebug__)) |
| 161 | _mm_insert_si64(__m128i __x, __m128i __y) |
| 162 | { |
| 163 | return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y); |
| 164 | } |
| 165 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 166 | /// \brief Stores a 64-bit double-precision value in a 64-bit memory location. |
| 167 | /// To minimize caching, the data is flagged as non-temporal (unlikely to be |
| 168 | /// used again soon). |
| 169 | /// |
| 170 | /// \headerfile <x86intrin.h> |
| 171 | /// |
| 172 | /// \code |
| 173 | /// This intrinsic corresponds to the \c MOVNTSD instruction. |
| 174 | /// \endcode |
| 175 | /// |
| 176 | /// \param __p |
| 177 | /// The 64-bit memory location used to store the register value. |
| 178 | /// \param __a |
| 179 | /// The 64-bit double-precision floating-point register value to |
| 180 | /// be stored. |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 181 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 182 | _mm_stream_sd(double *__p, __m128d __a) |
| 183 | { |
| 184 | __builtin_ia32_movntsd(__p, (__v2df)__a); |
| 185 | } |
| 186 | |
Ekaterina Romanova | 2e81434 | 2015-05-28 01:25:25 +0000 | [diff] [blame^] | 187 | /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit |
| 188 | /// memory location. To minimize caching, the data is flagged as |
| 189 | /// non-temporal (unlikely to be used again soon). |
| 190 | /// |
| 191 | /// \headerfile <x86intrin.h> |
| 192 | /// |
| 193 | /// \code |
| 194 | /// This intrinsic corresponds to the \c MOVNTSS instruction. |
| 195 | /// \endcode |
| 196 | /// |
| 197 | /// \param __p |
| 198 | /// The 32-bit memory location used to store the register value. |
| 199 | /// \param __a |
| 200 | /// The 32-bit single-precision floating-point register value to |
| 201 | /// be stored. |
Benjamin Kramer | ba6e252 | 2012-05-29 19:10:17 +0000 | [diff] [blame] | 202 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
| 203 | _mm_stream_ss(float *__p, __m128 __a) |
| 204 | { |
| 205 | __builtin_ia32_movntss(__p, (__v4sf)__a); |
| 206 | } |
| 207 | |
| 208 | #endif /* __SSE4A__ */ |
| 209 | |
| 210 | #endif /* __AMMINTRIN_H */ |