Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 1 | /*===---- ammintrin.h - SSE4a intrinsics -----------------------------------=== |
| 2 | * |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 3 | * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | * See https://llvm.org/LICENSE.txt for license information. |
| 5 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 6 | * |
| 7 | *===-----------------------------------------------------------------------=== |
| 8 | */ |
| 9 | |
| 10 | #ifndef __AMMINTRIN_H |
| 11 | #define __AMMINTRIN_H |
| 12 | |
Pirama Arumuga Nainar | ec8c89d | 2022-02-23 09:26:16 -0800 | [diff] [blame] | 13 | #if !defined(__i386__) && !defined(__x86_64__) |
| 14 | #error "This header is only meant to be used on x86 and x64 architecture" |
| 15 | #endif |
| 16 | |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 17 | #include <pmmintrin.h> |
| 18 | |
| 19 | /* Define the default attributes for the functions in this file. */ |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 20 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse4a"), __min_vector_width__(128))) |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 21 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 22 | /// Extracts the specified bits from the lower 64 bits of the 128-bit |
| 23 | /// integer vector operand at the index \a idx and of the length \a len. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 24 | /// |
| 25 | /// \headerfile <x86intrin.h> |
| 26 | /// |
| 27 | /// \code |
| 28 | /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx); |
| 29 | /// \endcode |
| 30 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 31 | /// This intrinsic corresponds to the <c> EXTRQ </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 32 | /// |
| 33 | /// \param x |
| 34 | /// The value from which bits are extracted. |
| 35 | /// \param len |
| 36 | /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] |
| 37 | /// are zero, the length is interpreted as 64. |
| 38 | /// \param idx |
| 39 | /// Bits [5:0] specify the index of the least significant bit; the other |
| 40 | /// bits are ignored. If the sum of the index and length is greater than 64, |
| 41 | /// the result is undefined. If the length and index are both zero, bits |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 42 | /// [63:0] of parameter \a x are extracted. If the length is zero but the |
| 43 | /// index is non-zero, the result is undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 44 | /// \returns A 128-bit integer vector whose lower 64 bits contain the bits |
| 45 | /// extracted from the source operand. |
| 46 | #define _mm_extracti_si64(x, len, idx) \ |
| 47 | ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \ |
| 48 | (char)(len), (char)(idx))) |
| 49 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 50 | /// Extracts the specified bits from the lower 64 bits of the 128-bit |
| 51 | /// integer vector operand at the index and of the length specified by |
| 52 | /// \a __y. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 53 | /// |
| 54 | /// \headerfile <x86intrin.h> |
| 55 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 56 | /// This intrinsic corresponds to the <c> EXTRQ </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 57 | /// |
| 58 | /// \param __x |
| 59 | /// The value from which bits are extracted. |
| 60 | /// \param __y |
| 61 | /// Specifies the index of the least significant bit at [13:8] and the |
| 62 | /// length at [5:0]; all other bits are ignored. If bits [5:0] are zero, the |
| 63 | /// length is interpreted as 64. If the sum of the index and length is |
| 64 | /// greater than 64, the result is undefined. If the length and index are |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 65 | /// both zero, bits [63:0] of parameter \a __x are extracted. If the length |
| 66 | /// is zero but the index is non-zero, the result is undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 67 | /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted |
| 68 | /// from the source operand. |
| 69 | static __inline__ __m128i __DEFAULT_FN_ATTRS |
| 70 | _mm_extract_si64(__m128i __x, __m128i __y) |
| 71 | { |
| 72 | return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y); |
| 73 | } |
| 74 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 75 | /// Inserts bits of a specified length from the source integer vector |
| 76 | /// \a y into the lower 64 bits of the destination integer vector \a x at |
| 77 | /// the index \a idx and of the length \a len. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 78 | /// |
| 79 | /// \headerfile <x86intrin.h> |
| 80 | /// |
| 81 | /// \code |
| 82 | /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len, |
| 83 | /// const int idx); |
| 84 | /// \endcode |
| 85 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 86 | /// This intrinsic corresponds to the <c> INSERTQ </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 87 | /// |
| 88 | /// \param x |
| 89 | /// The destination operand where bits will be inserted. The inserted bits |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 90 | /// are defined by the length \a len and by the index \a idx specifying the |
| 91 | /// least significant bit. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 92 | /// \param y |
| 93 | /// The source operand containing the bits to be extracted. The extracted |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 94 | /// bits are the least significant bits of operand \a y of length \a len. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 95 | /// \param len |
| 96 | /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] |
| 97 | /// are zero, the length is interpreted as 64. |
| 98 | /// \param idx |
| 99 | /// Bits [5:0] specify the index of the least significant bit; the other |
| 100 | /// bits are ignored. If the sum of the index and length is greater than 64, |
| 101 | /// the result is undefined. If the length and index are both zero, bits |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 102 | /// [63:0] of parameter \a y are inserted into parameter \a x. If the length |
| 103 | /// is zero but the index is non-zero, the result is undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 104 | /// \returns A 128-bit integer vector containing the original lower 64-bits of |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 105 | /// destination operand \a x with the specified bitfields replaced by the |
| 106 | /// lower bits of source operand \a y. The upper 64 bits of the return value |
| 107 | /// are undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 108 | #define _mm_inserti_si64(x, y, len, idx) \ |
| 109 | ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \ |
| 110 | (__v2di)(__m128i)(y), \ |
| 111 | (char)(len), (char)(idx))) |
| 112 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 113 | /// Inserts bits of a specified length from the source integer vector |
| 114 | /// \a __y into the lower 64 bits of the destination integer vector \a __x |
| 115 | /// at the index and of the length specified by \a __y. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 116 | /// |
| 117 | /// \headerfile <x86intrin.h> |
| 118 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 119 | /// This intrinsic corresponds to the <c> INSERTQ </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 120 | /// |
| 121 | /// \param __x |
| 122 | /// The destination operand where bits will be inserted. The inserted bits |
| 123 | /// are defined by the length and by the index of the least significant bit |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 124 | /// specified by operand \a __y. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 125 | /// \param __y |
| 126 | /// The source operand containing the bits to be extracted. The extracted |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 127 | /// bits are the least significant bits of operand \a __y with length |
| 128 | /// specified by bits [69:64]. These are inserted into the destination at the |
| 129 | /// index specified by bits [77:72]; all other bits are ignored. If bits |
| 130 | /// [69:64] are zero, the length is interpreted as 64. If the sum of the |
| 131 | /// index and length is greater than 64, the result is undefined. If the |
| 132 | /// length and index are both zero, bits [63:0] of parameter \a __y are |
| 133 | /// inserted into parameter \a __x. If the length is zero but the index is |
| 134 | /// non-zero, the result is undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 135 | /// \returns A 128-bit integer vector containing the original lower 64-bits of |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 136 | /// destination operand \a __x with the specified bitfields replaced by the |
| 137 | /// lower bits of source operand \a __y. The upper 64 bits of the return |
| 138 | /// value are undefined. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 139 | static __inline__ __m128i __DEFAULT_FN_ATTRS |
| 140 | _mm_insert_si64(__m128i __x, __m128i __y) |
| 141 | { |
| 142 | return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y); |
| 143 | } |
| 144 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 145 | /// Stores a 64-bit double-precision value in a 64-bit memory location. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 146 | /// To minimize caching, the data is flagged as non-temporal (unlikely to be |
| 147 | /// used again soon). |
| 148 | /// |
| 149 | /// \headerfile <x86intrin.h> |
| 150 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 151 | /// This intrinsic corresponds to the <c> MOVNTSD </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 152 | /// |
| 153 | /// \param __p |
| 154 | /// The 64-bit memory location used to store the register value. |
| 155 | /// \param __a |
| 156 | /// The 64-bit double-precision floating-point register value to be stored. |
| 157 | static __inline__ void __DEFAULT_FN_ATTRS |
| 158 | _mm_stream_sd(double *__p, __m128d __a) |
| 159 | { |
| 160 | __builtin_ia32_movntsd(__p, (__v2df)__a); |
| 161 | } |
| 162 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 163 | /// Stores a 32-bit single-precision floating-point value in a 32-bit |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 164 | /// memory location. To minimize caching, the data is flagged as |
| 165 | /// non-temporal (unlikely to be used again soon). |
| 166 | /// |
| 167 | /// \headerfile <x86intrin.h> |
| 168 | /// |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 169 | /// This intrinsic corresponds to the <c> MOVNTSS </c> instruction. |
Logan Chien | 2833ffb | 2018-10-09 10:03:24 +0800 | [diff] [blame] | 170 | /// |
| 171 | /// \param __p |
| 172 | /// The 32-bit memory location used to store the register value. |
| 173 | /// \param __a |
| 174 | /// The 32-bit single-precision floating-point register value to be stored. |
| 175 | static __inline__ void __DEFAULT_FN_ATTRS |
| 176 | _mm_stream_ss(float *__p, __m128 __a) |
| 177 | { |
| 178 | __builtin_ia32_movntss(__p, (__v4sf)__a); |
| 179 | } |
| 180 | |
| 181 | #undef __DEFAULT_FN_ATTRS |
| 182 | |
| 183 | #endif /* __AMMINTRIN_H */ |