ammintrin.h 8.3 KB

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