ammintrin.h 8.5 KB

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