tmmintrin.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*===---- tmmintrin.h - SSSE3 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 __TMMINTRIN_H
  24. #define __TMMINTRIN_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__("ssse3"), __min_vector_width__(64)))
  28. #define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, __target__("mmx,ssse3"), __min_vector_width__(64)))
  29. /// Computes the absolute value of each of the packed 8-bit signed
  30. /// integers in the source operand and stores the 8-bit unsigned integer
  31. /// results in the destination.
  32. ///
  33. /// \headerfile <x86intrin.h>
  34. ///
  35. /// This intrinsic corresponds to the \c PABSB instruction.
  36. ///
  37. /// \param __a
  38. /// A 64-bit vector of [8 x i8].
  39. /// \returns A 64-bit integer vector containing the absolute values of the
  40. /// elements in the operand.
  41. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  42. _mm_abs_pi8(__m64 __a)
  43. {
  44. return (__m64)__builtin_ia32_pabsb((__v8qi)__a);
  45. }
  46. /// Computes the absolute value of each of the packed 8-bit signed
  47. /// integers in the source operand and stores the 8-bit unsigned integer
  48. /// results in the destination.
  49. ///
  50. /// \headerfile <x86intrin.h>
  51. ///
  52. /// This intrinsic corresponds to the \c VPABSB instruction.
  53. ///
  54. /// \param __a
  55. /// A 128-bit vector of [16 x i8].
  56. /// \returns A 128-bit integer vector containing the absolute values of the
  57. /// elements in the operand.
  58. static __inline__ __m128i __DEFAULT_FN_ATTRS
  59. _mm_abs_epi8(__m128i __a)
  60. {
  61. return (__m128i)__builtin_ia32_pabsb128((__v16qi)__a);
  62. }
  63. /// Computes the absolute value of each of the packed 16-bit signed
  64. /// integers in the source operand and stores the 16-bit unsigned integer
  65. /// results in the destination.
  66. ///
  67. /// \headerfile <x86intrin.h>
  68. ///
  69. /// This intrinsic corresponds to the \c PABSW instruction.
  70. ///
  71. /// \param __a
  72. /// A 64-bit vector of [4 x i16].
  73. /// \returns A 64-bit integer vector containing the absolute values of the
  74. /// elements in the operand.
  75. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  76. _mm_abs_pi16(__m64 __a)
  77. {
  78. return (__m64)__builtin_ia32_pabsw((__v4hi)__a);
  79. }
  80. /// Computes the absolute value of each of the packed 16-bit signed
  81. /// integers in the source operand and stores the 16-bit unsigned integer
  82. /// results in the destination.
  83. ///
  84. /// \headerfile <x86intrin.h>
  85. ///
  86. /// This intrinsic corresponds to the \c VPABSW instruction.
  87. ///
  88. /// \param __a
  89. /// A 128-bit vector of [8 x i16].
  90. /// \returns A 128-bit integer vector containing the absolute values of the
  91. /// elements in the operand.
  92. static __inline__ __m128i __DEFAULT_FN_ATTRS
  93. _mm_abs_epi16(__m128i __a)
  94. {
  95. return (__m128i)__builtin_ia32_pabsw128((__v8hi)__a);
  96. }
  97. /// Computes the absolute value of each of the packed 32-bit signed
  98. /// integers in the source operand and stores the 32-bit unsigned integer
  99. /// results in the destination.
  100. ///
  101. /// \headerfile <x86intrin.h>
  102. ///
  103. /// This intrinsic corresponds to the \c PABSD instruction.
  104. ///
  105. /// \param __a
  106. /// A 64-bit vector of [2 x i32].
  107. /// \returns A 64-bit integer vector containing the absolute values of the
  108. /// elements in the operand.
  109. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  110. _mm_abs_pi32(__m64 __a)
  111. {
  112. return (__m64)__builtin_ia32_pabsd((__v2si)__a);
  113. }
  114. /// Computes the absolute value of each of the packed 32-bit signed
  115. /// integers in the source operand and stores the 32-bit unsigned integer
  116. /// results in the destination.
  117. ///
  118. /// \headerfile <x86intrin.h>
  119. ///
  120. /// This intrinsic corresponds to the \c VPABSD instruction.
  121. ///
  122. /// \param __a
  123. /// A 128-bit vector of [4 x i32].
  124. /// \returns A 128-bit integer vector containing the absolute values of the
  125. /// elements in the operand.
  126. static __inline__ __m128i __DEFAULT_FN_ATTRS
  127. _mm_abs_epi32(__m128i __a)
  128. {
  129. return (__m128i)__builtin_ia32_pabsd128((__v4si)__a);
  130. }
  131. /// Concatenates the two 128-bit integer vector operands, and
  132. /// right-shifts the result by the number of bytes specified in the immediate
  133. /// operand.
  134. ///
  135. /// \headerfile <x86intrin.h>
  136. ///
  137. /// \code
  138. /// __m128i _mm_alignr_epi8(__m128i a, __m128i b, const int n);
  139. /// \endcode
  140. ///
  141. /// This intrinsic corresponds to the \c PALIGNR instruction.
  142. ///
  143. /// \param a
  144. /// A 128-bit vector of [16 x i8] containing one of the source operands.
  145. /// \param b
  146. /// A 128-bit vector of [16 x i8] containing one of the source operands.
  147. /// \param n
  148. /// An immediate operand specifying how many bytes to right-shift the result.
  149. /// \returns A 128-bit integer vector containing the concatenated right-shifted
  150. /// value.
  151. #define _mm_alignr_epi8(a, b, n) \
  152. (__m128i)__builtin_ia32_palignr128((__v16qi)(__m128i)(a), \
  153. (__v16qi)(__m128i)(b), (n))
  154. /// Concatenates the two 64-bit integer vector operands, and right-shifts
  155. /// the result by the number of bytes specified in the immediate operand.
  156. ///
  157. /// \headerfile <x86intrin.h>
  158. ///
  159. /// \code
  160. /// __m64 _mm_alignr_pi8(__m64 a, __m64 b, const int n);
  161. /// \endcode
  162. ///
  163. /// This intrinsic corresponds to the \c PALIGNR instruction.
  164. ///
  165. /// \param a
  166. /// A 64-bit vector of [8 x i8] containing one of the source operands.
  167. /// \param b
  168. /// A 64-bit vector of [8 x i8] containing one of the source operands.
  169. /// \param n
  170. /// An immediate operand specifying how many bytes to right-shift the result.
  171. /// \returns A 64-bit integer vector containing the concatenated right-shifted
  172. /// value.
  173. #define _mm_alignr_pi8(a, b, n) \
  174. (__m64)__builtin_ia32_palignr((__v8qi)(__m64)(a), (__v8qi)(__m64)(b), (n))
  175. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  176. /// 128-bit vectors of [8 x i16].
  177. ///
  178. /// \headerfile <x86intrin.h>
  179. ///
  180. /// This intrinsic corresponds to the \c VPHADDW instruction.
  181. ///
  182. /// \param __a
  183. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  184. /// horizontal sums of the values are stored in the lower bits of the
  185. /// destination.
  186. /// \param __b
  187. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  188. /// horizontal sums of the values are stored in the upper bits of the
  189. /// destination.
  190. /// \returns A 128-bit vector of [8 x i16] containing the horizontal sums of
  191. /// both operands.
  192. static __inline__ __m128i __DEFAULT_FN_ATTRS
  193. _mm_hadd_epi16(__m128i __a, __m128i __b)
  194. {
  195. return (__m128i)__builtin_ia32_phaddw128((__v8hi)__a, (__v8hi)__b);
  196. }
  197. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  198. /// 128-bit vectors of [4 x i32].
  199. ///
  200. /// \headerfile <x86intrin.h>
  201. ///
  202. /// This intrinsic corresponds to the \c VPHADDD instruction.
  203. ///
  204. /// \param __a
  205. /// A 128-bit vector of [4 x i32] containing one of the source operands. The
  206. /// horizontal sums of the values are stored in the lower bits of the
  207. /// destination.
  208. /// \param __b
  209. /// A 128-bit vector of [4 x i32] containing one of the source operands. The
  210. /// horizontal sums of the values are stored in the upper bits of the
  211. /// destination.
  212. /// \returns A 128-bit vector of [4 x i32] containing the horizontal sums of
  213. /// both operands.
  214. static __inline__ __m128i __DEFAULT_FN_ATTRS
  215. _mm_hadd_epi32(__m128i __a, __m128i __b)
  216. {
  217. return (__m128i)__builtin_ia32_phaddd128((__v4si)__a, (__v4si)__b);
  218. }
  219. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  220. /// 64-bit vectors of [4 x i16].
  221. ///
  222. /// \headerfile <x86intrin.h>
  223. ///
  224. /// This intrinsic corresponds to the \c PHADDW instruction.
  225. ///
  226. /// \param __a
  227. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  228. /// horizontal sums of the values are stored in the lower bits of the
  229. /// destination.
  230. /// \param __b
  231. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  232. /// horizontal sums of the values are stored in the upper bits of the
  233. /// destination.
  234. /// \returns A 64-bit vector of [4 x i16] containing the horizontal sums of both
  235. /// operands.
  236. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  237. _mm_hadd_pi16(__m64 __a, __m64 __b)
  238. {
  239. return (__m64)__builtin_ia32_phaddw((__v4hi)__a, (__v4hi)__b);
  240. }
  241. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  242. /// 64-bit vectors of [2 x i32].
  243. ///
  244. /// \headerfile <x86intrin.h>
  245. ///
  246. /// This intrinsic corresponds to the \c PHADDD instruction.
  247. ///
  248. /// \param __a
  249. /// A 64-bit vector of [2 x i32] containing one of the source operands. The
  250. /// horizontal sums of the values are stored in the lower bits of the
  251. /// destination.
  252. /// \param __b
  253. /// A 64-bit vector of [2 x i32] containing one of the source operands. The
  254. /// horizontal sums of the values are stored in the upper bits of the
  255. /// destination.
  256. /// \returns A 64-bit vector of [2 x i32] containing the horizontal sums of both
  257. /// operands.
  258. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  259. _mm_hadd_pi32(__m64 __a, __m64 __b)
  260. {
  261. return (__m64)__builtin_ia32_phaddd((__v2si)__a, (__v2si)__b);
  262. }
  263. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  264. /// 128-bit vectors of [8 x i16]. Positive sums greater than 0x7FFF are
  265. /// saturated to 0x7FFF. Negative sums less than 0x8000 are saturated to
  266. /// 0x8000.
  267. ///
  268. /// \headerfile <x86intrin.h>
  269. ///
  270. /// This intrinsic corresponds to the \c VPHADDSW instruction.
  271. ///
  272. /// \param __a
  273. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  274. /// horizontal sums of the values are stored in the lower bits of the
  275. /// destination.
  276. /// \param __b
  277. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  278. /// horizontal sums of the values are stored in the upper bits of the
  279. /// destination.
  280. /// \returns A 128-bit vector of [8 x i16] containing the horizontal saturated
  281. /// sums of both operands.
  282. static __inline__ __m128i __DEFAULT_FN_ATTRS
  283. _mm_hadds_epi16(__m128i __a, __m128i __b)
  284. {
  285. return (__m128i)__builtin_ia32_phaddsw128((__v8hi)__a, (__v8hi)__b);
  286. }
  287. /// Horizontally adds the adjacent pairs of values contained in 2 packed
  288. /// 64-bit vectors of [4 x i16]. Positive sums greater than 0x7FFF are
  289. /// saturated to 0x7FFF. Negative sums less than 0x8000 are saturated to
  290. /// 0x8000.
  291. ///
  292. /// \headerfile <x86intrin.h>
  293. ///
  294. /// This intrinsic corresponds to the \c PHADDSW instruction.
  295. ///
  296. /// \param __a
  297. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  298. /// horizontal sums of the values are stored in the lower bits of the
  299. /// destination.
  300. /// \param __b
  301. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  302. /// horizontal sums of the values are stored in the upper bits of the
  303. /// destination.
  304. /// \returns A 64-bit vector of [4 x i16] containing the horizontal saturated
  305. /// sums of both operands.
  306. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  307. _mm_hadds_pi16(__m64 __a, __m64 __b)
  308. {
  309. return (__m64)__builtin_ia32_phaddsw((__v4hi)__a, (__v4hi)__b);
  310. }
  311. /// Horizontally subtracts the adjacent pairs of values contained in 2
  312. /// packed 128-bit vectors of [8 x i16].
  313. ///
  314. /// \headerfile <x86intrin.h>
  315. ///
  316. /// This intrinsic corresponds to the \c VPHSUBW instruction.
  317. ///
  318. /// \param __a
  319. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  320. /// horizontal differences between the values are stored in the lower bits of
  321. /// the destination.
  322. /// \param __b
  323. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  324. /// horizontal differences between the values are stored in the upper bits of
  325. /// the destination.
  326. /// \returns A 128-bit vector of [8 x i16] containing the horizontal differences
  327. /// of both operands.
  328. static __inline__ __m128i __DEFAULT_FN_ATTRS
  329. _mm_hsub_epi16(__m128i __a, __m128i __b)
  330. {
  331. return (__m128i)__builtin_ia32_phsubw128((__v8hi)__a, (__v8hi)__b);
  332. }
  333. /// Horizontally subtracts the adjacent pairs of values contained in 2
  334. /// packed 128-bit vectors of [4 x i32].
  335. ///
  336. /// \headerfile <x86intrin.h>
  337. ///
  338. /// This intrinsic corresponds to the \c VPHSUBD instruction.
  339. ///
  340. /// \param __a
  341. /// A 128-bit vector of [4 x i32] containing one of the source operands. The
  342. /// horizontal differences between the values are stored in the lower bits of
  343. /// the destination.
  344. /// \param __b
  345. /// A 128-bit vector of [4 x i32] containing one of the source operands. The
  346. /// horizontal differences between the values are stored in the upper bits of
  347. /// the destination.
  348. /// \returns A 128-bit vector of [4 x i32] containing the horizontal differences
  349. /// of both operands.
  350. static __inline__ __m128i __DEFAULT_FN_ATTRS
  351. _mm_hsub_epi32(__m128i __a, __m128i __b)
  352. {
  353. return (__m128i)__builtin_ia32_phsubd128((__v4si)__a, (__v4si)__b);
  354. }
  355. /// Horizontally subtracts the adjacent pairs of values contained in 2
  356. /// packed 64-bit vectors of [4 x i16].
  357. ///
  358. /// \headerfile <x86intrin.h>
  359. ///
  360. /// This intrinsic corresponds to the \c PHSUBW instruction.
  361. ///
  362. /// \param __a
  363. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  364. /// horizontal differences between the values are stored in the lower bits of
  365. /// the destination.
  366. /// \param __b
  367. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  368. /// horizontal differences between the values are stored in the upper bits of
  369. /// the destination.
  370. /// \returns A 64-bit vector of [4 x i16] containing the horizontal differences
  371. /// of both operands.
  372. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  373. _mm_hsub_pi16(__m64 __a, __m64 __b)
  374. {
  375. return (__m64)__builtin_ia32_phsubw((__v4hi)__a, (__v4hi)__b);
  376. }
  377. /// Horizontally subtracts the adjacent pairs of values contained in 2
  378. /// packed 64-bit vectors of [2 x i32].
  379. ///
  380. /// \headerfile <x86intrin.h>
  381. ///
  382. /// This intrinsic corresponds to the \c PHSUBD instruction.
  383. ///
  384. /// \param __a
  385. /// A 64-bit vector of [2 x i32] containing one of the source operands. The
  386. /// horizontal differences between the values are stored in the lower bits of
  387. /// the destination.
  388. /// \param __b
  389. /// A 64-bit vector of [2 x i32] containing one of the source operands. The
  390. /// horizontal differences between the values are stored in the upper bits of
  391. /// the destination.
  392. /// \returns A 64-bit vector of [2 x i32] containing the horizontal differences
  393. /// of both operands.
  394. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  395. _mm_hsub_pi32(__m64 __a, __m64 __b)
  396. {
  397. return (__m64)__builtin_ia32_phsubd((__v2si)__a, (__v2si)__b);
  398. }
  399. /// Horizontally subtracts the adjacent pairs of values contained in 2
  400. /// packed 128-bit vectors of [8 x i16]. Positive differences greater than
  401. /// 0x7FFF are saturated to 0x7FFF. Negative differences less than 0x8000 are
  402. /// saturated to 0x8000.
  403. ///
  404. /// \headerfile <x86intrin.h>
  405. ///
  406. /// This intrinsic corresponds to the \c VPHSUBSW instruction.
  407. ///
  408. /// \param __a
  409. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  410. /// horizontal differences between the values are stored in the lower bits of
  411. /// the destination.
  412. /// \param __b
  413. /// A 128-bit vector of [8 x i16] containing one of the source operands. The
  414. /// horizontal differences between the values are stored in the upper bits of
  415. /// the destination.
  416. /// \returns A 128-bit vector of [8 x i16] containing the horizontal saturated
  417. /// differences of both operands.
  418. static __inline__ __m128i __DEFAULT_FN_ATTRS
  419. _mm_hsubs_epi16(__m128i __a, __m128i __b)
  420. {
  421. return (__m128i)__builtin_ia32_phsubsw128((__v8hi)__a, (__v8hi)__b);
  422. }
  423. /// Horizontally subtracts the adjacent pairs of values contained in 2
  424. /// packed 64-bit vectors of [4 x i16]. Positive differences greater than
  425. /// 0x7FFF are saturated to 0x7FFF. Negative differences less than 0x8000 are
  426. /// saturated to 0x8000.
  427. ///
  428. /// \headerfile <x86intrin.h>
  429. ///
  430. /// This intrinsic corresponds to the \c PHSUBSW instruction.
  431. ///
  432. /// \param __a
  433. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  434. /// horizontal differences between the values are stored in the lower bits of
  435. /// the destination.
  436. /// \param __b
  437. /// A 64-bit vector of [4 x i16] containing one of the source operands. The
  438. /// horizontal differences between the values are stored in the upper bits of
  439. /// the destination.
  440. /// \returns A 64-bit vector of [4 x i16] containing the horizontal saturated
  441. /// differences of both operands.
  442. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  443. _mm_hsubs_pi16(__m64 __a, __m64 __b)
  444. {
  445. return (__m64)__builtin_ia32_phsubsw((__v4hi)__a, (__v4hi)__b);
  446. }
  447. /// Multiplies corresponding pairs of packed 8-bit unsigned integer
  448. /// values contained in the first source operand and packed 8-bit signed
  449. /// integer values contained in the second source operand, adds pairs of
  450. /// contiguous products with signed saturation, and writes the 16-bit sums to
  451. /// the corresponding bits in the destination.
  452. ///
  453. /// For example, bits [7:0] of both operands are multiplied, bits [15:8] of
  454. /// both operands are multiplied, and the sum of both results is written to
  455. /// bits [15:0] of the destination.
  456. ///
  457. /// \headerfile <x86intrin.h>
  458. ///
  459. /// This intrinsic corresponds to the \c VPMADDUBSW instruction.
  460. ///
  461. /// \param __a
  462. /// A 128-bit integer vector containing the first source operand.
  463. /// \param __b
  464. /// A 128-bit integer vector containing the second source operand.
  465. /// \returns A 128-bit integer vector containing the sums of products of both
  466. /// operands: \n
  467. /// \a R0 := (\a __a0 * \a __b0) + (\a __a1 * \a __b1) \n
  468. /// \a R1 := (\a __a2 * \a __b2) + (\a __a3 * \a __b3) \n
  469. /// \a R2 := (\a __a4 * \a __b4) + (\a __a5 * \a __b5) \n
  470. /// \a R3 := (\a __a6 * \a __b6) + (\a __a7 * \a __b7) \n
  471. /// \a R4 := (\a __a8 * \a __b8) + (\a __a9 * \a __b9) \n
  472. /// \a R5 := (\a __a10 * \a __b10) + (\a __a11 * \a __b11) \n
  473. /// \a R6 := (\a __a12 * \a __b12) + (\a __a13 * \a __b13) \n
  474. /// \a R7 := (\a __a14 * \a __b14) + (\a __a15 * \a __b15)
  475. static __inline__ __m128i __DEFAULT_FN_ATTRS
  476. _mm_maddubs_epi16(__m128i __a, __m128i __b)
  477. {
  478. return (__m128i)__builtin_ia32_pmaddubsw128((__v16qi)__a, (__v16qi)__b);
  479. }
  480. /// Multiplies corresponding pairs of packed 8-bit unsigned integer
  481. /// values contained in the first source operand and packed 8-bit signed
  482. /// integer values contained in the second source operand, adds pairs of
  483. /// contiguous products with signed saturation, and writes the 16-bit sums to
  484. /// the corresponding bits in the destination.
  485. ///
  486. /// For example, bits [7:0] of both operands are multiplied, bits [15:8] of
  487. /// both operands are multiplied, and the sum of both results is written to
  488. /// bits [15:0] of the destination.
  489. ///
  490. /// \headerfile <x86intrin.h>
  491. ///
  492. /// This intrinsic corresponds to the \c PMADDUBSW instruction.
  493. ///
  494. /// \param __a
  495. /// A 64-bit integer vector containing the first source operand.
  496. /// \param __b
  497. /// A 64-bit integer vector containing the second source operand.
  498. /// \returns A 64-bit integer vector containing the sums of products of both
  499. /// operands: \n
  500. /// \a R0 := (\a __a0 * \a __b0) + (\a __a1 * \a __b1) \n
  501. /// \a R1 := (\a __a2 * \a __b2) + (\a __a3 * \a __b3) \n
  502. /// \a R2 := (\a __a4 * \a __b4) + (\a __a5 * \a __b5) \n
  503. /// \a R3 := (\a __a6 * \a __b6) + (\a __a7 * \a __b7)
  504. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  505. _mm_maddubs_pi16(__m64 __a, __m64 __b)
  506. {
  507. return (__m64)__builtin_ia32_pmaddubsw((__v8qi)__a, (__v8qi)__b);
  508. }
  509. /// Multiplies packed 16-bit signed integer values, truncates the 32-bit
  510. /// products to the 18 most significant bits by right-shifting, rounds the
  511. /// truncated value by adding 1, and writes bits [16:1] to the destination.
  512. ///
  513. /// \headerfile <x86intrin.h>
  514. ///
  515. /// This intrinsic corresponds to the \c VPMULHRSW instruction.
  516. ///
  517. /// \param __a
  518. /// A 128-bit vector of [8 x i16] containing one of the source operands.
  519. /// \param __b
  520. /// A 128-bit vector of [8 x i16] containing one of the source operands.
  521. /// \returns A 128-bit vector of [8 x i16] containing the rounded and scaled
  522. /// products of both operands.
  523. static __inline__ __m128i __DEFAULT_FN_ATTRS
  524. _mm_mulhrs_epi16(__m128i __a, __m128i __b)
  525. {
  526. return (__m128i)__builtin_ia32_pmulhrsw128((__v8hi)__a, (__v8hi)__b);
  527. }
  528. /// Multiplies packed 16-bit signed integer values, truncates the 32-bit
  529. /// products to the 18 most significant bits by right-shifting, rounds the
  530. /// truncated value by adding 1, and writes bits [16:1] to the destination.
  531. ///
  532. /// \headerfile <x86intrin.h>
  533. ///
  534. /// This intrinsic corresponds to the \c PMULHRSW instruction.
  535. ///
  536. /// \param __a
  537. /// A 64-bit vector of [4 x i16] containing one of the source operands.
  538. /// \param __b
  539. /// A 64-bit vector of [4 x i16] containing one of the source operands.
  540. /// \returns A 64-bit vector of [4 x i16] containing the rounded and scaled
  541. /// products of both operands.
  542. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  543. _mm_mulhrs_pi16(__m64 __a, __m64 __b)
  544. {
  545. return (__m64)__builtin_ia32_pmulhrsw((__v4hi)__a, (__v4hi)__b);
  546. }
  547. /// Copies the 8-bit integers from a 128-bit integer vector to the
  548. /// destination or clears 8-bit values in the destination, as specified by
  549. /// the second source operand.
  550. ///
  551. /// \headerfile <x86intrin.h>
  552. ///
  553. /// This intrinsic corresponds to the \c VPSHUFB instruction.
  554. ///
  555. /// \param __a
  556. /// A 128-bit integer vector containing the values to be copied.
  557. /// \param __b
  558. /// A 128-bit integer vector containing control bytes corresponding to
  559. /// positions in the destination:
  560. /// Bit 7: \n
  561. /// 1: Clear the corresponding byte in the destination. \n
  562. /// 0: Copy the selected source byte to the corresponding byte in the
  563. /// destination. \n
  564. /// Bits [6:4] Reserved. \n
  565. /// Bits [3:0] select the source byte to be copied.
  566. /// \returns A 128-bit integer vector containing the copied or cleared values.
  567. static __inline__ __m128i __DEFAULT_FN_ATTRS
  568. _mm_shuffle_epi8(__m128i __a, __m128i __b)
  569. {
  570. return (__m128i)__builtin_ia32_pshufb128((__v16qi)__a, (__v16qi)__b);
  571. }
  572. /// Copies the 8-bit integers from a 64-bit integer vector to the
  573. /// destination or clears 8-bit values in the destination, as specified by
  574. /// the second source operand.
  575. ///
  576. /// \headerfile <x86intrin.h>
  577. ///
  578. /// This intrinsic corresponds to the \c PSHUFB instruction.
  579. ///
  580. /// \param __a
  581. /// A 64-bit integer vector containing the values to be copied.
  582. /// \param __b
  583. /// A 64-bit integer vector containing control bytes corresponding to
  584. /// positions in the destination:
  585. /// Bit 7: \n
  586. /// 1: Clear the corresponding byte in the destination. \n
  587. /// 0: Copy the selected source byte to the corresponding byte in the
  588. /// destination. \n
  589. /// Bits [3:0] select the source byte to be copied.
  590. /// \returns A 64-bit integer vector containing the copied or cleared values.
  591. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  592. _mm_shuffle_pi8(__m64 __a, __m64 __b)
  593. {
  594. return (__m64)__builtin_ia32_pshufb((__v8qi)__a, (__v8qi)__b);
  595. }
  596. /// For each 8-bit integer in the first source operand, perform one of
  597. /// the following actions as specified by the second source operand.
  598. ///
  599. /// If the byte in the second source is negative, calculate the two's
  600. /// complement of the corresponding byte in the first source, and write that
  601. /// value to the destination. If the byte in the second source is positive,
  602. /// copy the corresponding byte from the first source to the destination. If
  603. /// the byte in the second source is zero, clear the corresponding byte in
  604. /// the destination.
  605. ///
  606. /// \headerfile <x86intrin.h>
  607. ///
  608. /// This intrinsic corresponds to the \c VPSIGNB instruction.
  609. ///
  610. /// \param __a
  611. /// A 128-bit integer vector containing the values to be copied.
  612. /// \param __b
  613. /// A 128-bit integer vector containing control bytes corresponding to
  614. /// positions in the destination.
  615. /// \returns A 128-bit integer vector containing the resultant values.
  616. static __inline__ __m128i __DEFAULT_FN_ATTRS
  617. _mm_sign_epi8(__m128i __a, __m128i __b)
  618. {
  619. return (__m128i)__builtin_ia32_psignb128((__v16qi)__a, (__v16qi)__b);
  620. }
  621. /// For each 16-bit integer in the first source operand, perform one of
  622. /// the following actions as specified by the second source operand.
  623. ///
  624. /// If the word in the second source is negative, calculate the two's
  625. /// complement of the corresponding word in the first source, and write that
  626. /// value to the destination. If the word in the second source is positive,
  627. /// copy the corresponding word from the first source to the destination. If
  628. /// the word in the second source is zero, clear the corresponding word in
  629. /// the destination.
  630. ///
  631. /// \headerfile <x86intrin.h>
  632. ///
  633. /// This intrinsic corresponds to the \c VPSIGNW instruction.
  634. ///
  635. /// \param __a
  636. /// A 128-bit integer vector containing the values to be copied.
  637. /// \param __b
  638. /// A 128-bit integer vector containing control words corresponding to
  639. /// positions in the destination.
  640. /// \returns A 128-bit integer vector containing the resultant values.
  641. static __inline__ __m128i __DEFAULT_FN_ATTRS
  642. _mm_sign_epi16(__m128i __a, __m128i __b)
  643. {
  644. return (__m128i)__builtin_ia32_psignw128((__v8hi)__a, (__v8hi)__b);
  645. }
  646. /// For each 32-bit integer in the first source operand, perform one of
  647. /// the following actions as specified by the second source operand.
  648. ///
  649. /// If the doubleword in the second source is negative, calculate the two's
  650. /// complement of the corresponding word in the first source, and write that
  651. /// value to the destination. If the doubleword in the second source is
  652. /// positive, copy the corresponding word from the first source to the
  653. /// destination. If the doubleword in the second source is zero, clear the
  654. /// corresponding word in the destination.
  655. ///
  656. /// \headerfile <x86intrin.h>
  657. ///
  658. /// This intrinsic corresponds to the \c VPSIGND instruction.
  659. ///
  660. /// \param __a
  661. /// A 128-bit integer vector containing the values to be copied.
  662. /// \param __b
  663. /// A 128-bit integer vector containing control doublewords corresponding to
  664. /// positions in the destination.
  665. /// \returns A 128-bit integer vector containing the resultant values.
  666. static __inline__ __m128i __DEFAULT_FN_ATTRS
  667. _mm_sign_epi32(__m128i __a, __m128i __b)
  668. {
  669. return (__m128i)__builtin_ia32_psignd128((__v4si)__a, (__v4si)__b);
  670. }
  671. /// For each 8-bit integer in the first source operand, perform one of
  672. /// the following actions as specified by the second source operand.
  673. ///
  674. /// If the byte in the second source is negative, calculate the two's
  675. /// complement of the corresponding byte in the first source, and write that
  676. /// value to the destination. If the byte in the second source is positive,
  677. /// copy the corresponding byte from the first source to the destination. If
  678. /// the byte in the second source is zero, clear the corresponding byte in
  679. /// the destination.
  680. ///
  681. /// \headerfile <x86intrin.h>
  682. ///
  683. /// This intrinsic corresponds to the \c PSIGNB instruction.
  684. ///
  685. /// \param __a
  686. /// A 64-bit integer vector containing the values to be copied.
  687. /// \param __b
  688. /// A 64-bit integer vector containing control bytes corresponding to
  689. /// positions in the destination.
  690. /// \returns A 64-bit integer vector containing the resultant values.
  691. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  692. _mm_sign_pi8(__m64 __a, __m64 __b)
  693. {
  694. return (__m64)__builtin_ia32_psignb((__v8qi)__a, (__v8qi)__b);
  695. }
  696. /// For each 16-bit integer in the first source operand, perform one of
  697. /// the following actions as specified by the second source operand.
  698. ///
  699. /// If the word in the second source is negative, calculate the two's
  700. /// complement of the corresponding word in the first source, and write that
  701. /// value to the destination. If the word in the second source is positive,
  702. /// copy the corresponding word from the first source to the destination. If
  703. /// the word in the second source is zero, clear the corresponding word in
  704. /// the destination.
  705. ///
  706. /// \headerfile <x86intrin.h>
  707. ///
  708. /// This intrinsic corresponds to the \c PSIGNW instruction.
  709. ///
  710. /// \param __a
  711. /// A 64-bit integer vector containing the values to be copied.
  712. /// \param __b
  713. /// A 64-bit integer vector containing control words corresponding to
  714. /// positions in the destination.
  715. /// \returns A 64-bit integer vector containing the resultant values.
  716. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  717. _mm_sign_pi16(__m64 __a, __m64 __b)
  718. {
  719. return (__m64)__builtin_ia32_psignw((__v4hi)__a, (__v4hi)__b);
  720. }
  721. /// For each 32-bit integer in the first source operand, perform one of
  722. /// the following actions as specified by the second source operand.
  723. ///
  724. /// If the doubleword in the second source is negative, calculate the two's
  725. /// complement of the corresponding doubleword in the first source, and
  726. /// write that value to the destination. If the doubleword in the second
  727. /// source is positive, copy the corresponding doubleword from the first
  728. /// source to the destination. If the doubleword in the second source is
  729. /// zero, clear the corresponding doubleword in the destination.
  730. ///
  731. /// \headerfile <x86intrin.h>
  732. ///
  733. /// This intrinsic corresponds to the \c PSIGND instruction.
  734. ///
  735. /// \param __a
  736. /// A 64-bit integer vector containing the values to be copied.
  737. /// \param __b
  738. /// A 64-bit integer vector containing two control doublewords corresponding
  739. /// to positions in the destination.
  740. /// \returns A 64-bit integer vector containing the resultant values.
  741. static __inline__ __m64 __DEFAULT_FN_ATTRS_MMX
  742. _mm_sign_pi32(__m64 __a, __m64 __b)
  743. {
  744. return (__m64)__builtin_ia32_psignd((__v2si)__a, (__v2si)__b);
  745. }
  746. #undef __DEFAULT_FN_ATTRS
  747. #undef __DEFAULT_FN_ATTRS_MMX
  748. #endif /* __TMMINTRIN_H */