You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2907 lines
119KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "libavutil/cpu.h"
  25. #include "libavutil/x86_cpu.h"
  26. #include "libavcodec/dsputil.h"
  27. #include "libavcodec/h264dsp.h"
  28. #include "libavcodec/mpegvideo.h"
  29. #include "libavcodec/simple_idct.h"
  30. #include "libavcodec/ac3dec.h"
  31. #include "dsputil_mmx.h"
  32. #include "idct_xvid.h"
  33. //#undef NDEBUG
  34. //#include <assert.h>
  35. /* pixel operations */
  36. DECLARE_ALIGNED(8, const uint64_t, ff_bone) = 0x0101010101010101ULL;
  37. DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
  38. DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
  39. {0x8000000080000000ULL, 0x8000000080000000ULL};
  40. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1 ) = {0x0001000100010001ULL, 0x0001000100010001ULL};
  41. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2 ) = {0x0002000200020002ULL, 0x0002000200020002ULL};
  42. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3 ) = {0x0003000300030003ULL, 0x0003000300030003ULL};
  43. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4 ) = {0x0004000400040004ULL, 0x0004000400040004ULL};
  44. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL};
  45. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_8 ) = {0x0008000800080008ULL, 0x0008000800080008ULL};
  46. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_9 ) = {0x0009000900090009ULL, 0x0009000900090009ULL};
  47. DECLARE_ALIGNED(8, const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL;
  48. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL};
  49. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_17 ) = {0x0011001100110011ULL, 0x0011001100110011ULL};
  50. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_18 ) = {0x0012001200120012ULL, 0x0012001200120012ULL};
  51. DECLARE_ALIGNED(8, const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL;
  52. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_27 ) = {0x001B001B001B001BULL, 0x001B001B001B001BULL};
  53. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL};
  54. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL};
  55. DECLARE_ALIGNED(8, const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL;
  56. DECLARE_ALIGNED(8, const uint64_t, ff_pw_53 ) = 0x0035003500350035ULL;
  57. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_63 ) = {0x003F003F003F003FULL, 0x003F003F003F003FULL};
  58. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL};
  59. DECLARE_ALIGNED(8, const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
  60. DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
  61. DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
  62. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = {0x0200020002000200ULL, 0x0200020002000200ULL};
  63. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019)= {0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL};
  64. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0 ) = {0x0000000000000000ULL, 0x0000000000000000ULL};
  65. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1 ) = {0x0101010101010101ULL, 0x0101010101010101ULL};
  66. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_3 ) = {0x0303030303030303ULL, 0x0303030303030303ULL};
  67. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_4 ) = {0x0404040404040404ULL, 0x0404040404040404ULL};
  68. DECLARE_ALIGNED(8, const uint64_t, ff_pb_7 ) = 0x0707070707070707ULL;
  69. DECLARE_ALIGNED(8, const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL;
  70. DECLARE_ALIGNED(8, const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL;
  71. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_80 ) = {0x8080808080808080ULL, 0x8080808080808080ULL};
  72. DECLARE_ALIGNED(8, const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL;
  73. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_A1 ) = {0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL};
  74. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_F8 ) = {0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL};
  75. DECLARE_ALIGNED(8, const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL;
  76. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_FE ) = {0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL};
  77. DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
  78. DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
  79. #define JUMPALIGN() __asm__ volatile (".p2align 3"::)
  80. #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
  81. #define MOVQ_BFE(regd) \
  82. __asm__ volatile ( \
  83. "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
  84. "paddb %%" #regd ", %%" #regd " \n\t" ::)
  85. #ifndef PIC
  86. #define MOVQ_BONE(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
  87. #define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
  88. #else
  89. // for shared library it's better to use this way for accessing constants
  90. // pcmpeqd -> -1
  91. #define MOVQ_BONE(regd) \
  92. __asm__ volatile ( \
  93. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  94. "psrlw $15, %%" #regd " \n\t" \
  95. "packuswb %%" #regd ", %%" #regd " \n\t" ::)
  96. #define MOVQ_WTWO(regd) \
  97. __asm__ volatile ( \
  98. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  99. "psrlw $15, %%" #regd " \n\t" \
  100. "psllw $1, %%" #regd " \n\t"::)
  101. #endif
  102. // using regr as temporary and for the output result
  103. // first argument is unmodifed and second is trashed
  104. // regfe is supposed to contain 0xfefefefefefefefe
  105. #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
  106. "movq " #rega ", " #regr " \n\t"\
  107. "pand " #regb ", " #regr " \n\t"\
  108. "pxor " #rega ", " #regb " \n\t"\
  109. "pand " #regfe "," #regb " \n\t"\
  110. "psrlq $1, " #regb " \n\t"\
  111. "paddb " #regb ", " #regr " \n\t"
  112. #define PAVGB_MMX(rega, regb, regr, regfe) \
  113. "movq " #rega ", " #regr " \n\t"\
  114. "por " #regb ", " #regr " \n\t"\
  115. "pxor " #rega ", " #regb " \n\t"\
  116. "pand " #regfe "," #regb " \n\t"\
  117. "psrlq $1, " #regb " \n\t"\
  118. "psubb " #regb ", " #regr " \n\t"
  119. // mm6 is supposed to contain 0xfefefefefefefefe
  120. #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
  121. "movq " #rega ", " #regr " \n\t"\
  122. "movq " #regc ", " #regp " \n\t"\
  123. "pand " #regb ", " #regr " \n\t"\
  124. "pand " #regd ", " #regp " \n\t"\
  125. "pxor " #rega ", " #regb " \n\t"\
  126. "pxor " #regc ", " #regd " \n\t"\
  127. "pand %%mm6, " #regb " \n\t"\
  128. "pand %%mm6, " #regd " \n\t"\
  129. "psrlq $1, " #regb " \n\t"\
  130. "psrlq $1, " #regd " \n\t"\
  131. "paddb " #regb ", " #regr " \n\t"\
  132. "paddb " #regd ", " #regp " \n\t"
  133. #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
  134. "movq " #rega ", " #regr " \n\t"\
  135. "movq " #regc ", " #regp " \n\t"\
  136. "por " #regb ", " #regr " \n\t"\
  137. "por " #regd ", " #regp " \n\t"\
  138. "pxor " #rega ", " #regb " \n\t"\
  139. "pxor " #regc ", " #regd " \n\t"\
  140. "pand %%mm6, " #regb " \n\t"\
  141. "pand %%mm6, " #regd " \n\t"\
  142. "psrlq $1, " #regd " \n\t"\
  143. "psrlq $1, " #regb " \n\t"\
  144. "psubb " #regb ", " #regr " \n\t"\
  145. "psubb " #regd ", " #regp " \n\t"
  146. /***********************************/
  147. /* MMX no rounding */
  148. #define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
  149. #define SET_RND MOVQ_WONE
  150. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  151. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  152. #define OP_AVG(a, b, c, e) PAVGB_MMX(a, b, c, e)
  153. #include "dsputil_mmx_rnd_template.c"
  154. #undef DEF
  155. #undef SET_RND
  156. #undef PAVGBP
  157. #undef PAVGB
  158. /***********************************/
  159. /* MMX rounding */
  160. #define DEF(x, y) x ## _ ## y ##_mmx
  161. #define SET_RND MOVQ_WTWO
  162. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  163. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  164. #include "dsputil_mmx_rnd_template.c"
  165. #undef DEF
  166. #undef SET_RND
  167. #undef PAVGBP
  168. #undef PAVGB
  169. #undef OP_AVG
  170. /***********************************/
  171. /* 3Dnow specific */
  172. #define DEF(x) x ## _3dnow
  173. #define PAVGB "pavgusb"
  174. #define OP_AVG PAVGB
  175. #include "dsputil_mmx_avg_template.c"
  176. #undef DEF
  177. #undef PAVGB
  178. #undef OP_AVG
  179. /***********************************/
  180. /* MMX2 specific */
  181. #define DEF(x) x ## _mmx2
  182. /* Introduced only in MMX2 set */
  183. #define PAVGB "pavgb"
  184. #define OP_AVG PAVGB
  185. #include "dsputil_mmx_avg_template.c"
  186. #undef DEF
  187. #undef PAVGB
  188. #undef OP_AVG
  189. #define put_no_rnd_pixels16_mmx put_pixels16_mmx
  190. #define put_no_rnd_pixels8_mmx put_pixels8_mmx
  191. #define put_pixels16_mmx2 put_pixels16_mmx
  192. #define put_pixels8_mmx2 put_pixels8_mmx
  193. #define put_pixels4_mmx2 put_pixels4_mmx
  194. #define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
  195. #define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
  196. #define put_pixels16_3dnow put_pixels16_mmx
  197. #define put_pixels8_3dnow put_pixels8_mmx
  198. #define put_pixels4_3dnow put_pixels4_mmx
  199. #define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
  200. #define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
  201. /***********************************/
  202. /* standard MMX */
  203. void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  204. {
  205. const DCTELEM *p;
  206. uint8_t *pix;
  207. /* read the pixels */
  208. p = block;
  209. pix = pixels;
  210. /* unrolled loop */
  211. __asm__ volatile(
  212. "movq %3, %%mm0 \n\t"
  213. "movq 8%3, %%mm1 \n\t"
  214. "movq 16%3, %%mm2 \n\t"
  215. "movq 24%3, %%mm3 \n\t"
  216. "movq 32%3, %%mm4 \n\t"
  217. "movq 40%3, %%mm5 \n\t"
  218. "movq 48%3, %%mm6 \n\t"
  219. "movq 56%3, %%mm7 \n\t"
  220. "packuswb %%mm1, %%mm0 \n\t"
  221. "packuswb %%mm3, %%mm2 \n\t"
  222. "packuswb %%mm5, %%mm4 \n\t"
  223. "packuswb %%mm7, %%mm6 \n\t"
  224. "movq %%mm0, (%0) \n\t"
  225. "movq %%mm2, (%0, %1) \n\t"
  226. "movq %%mm4, (%0, %1, 2) \n\t"
  227. "movq %%mm6, (%0, %2) \n\t"
  228. ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
  229. :"memory");
  230. pix += line_size*4;
  231. p += 32;
  232. // if here would be an exact copy of the code above
  233. // compiler would generate some very strange code
  234. // thus using "r"
  235. __asm__ volatile(
  236. "movq (%3), %%mm0 \n\t"
  237. "movq 8(%3), %%mm1 \n\t"
  238. "movq 16(%3), %%mm2 \n\t"
  239. "movq 24(%3), %%mm3 \n\t"
  240. "movq 32(%3), %%mm4 \n\t"
  241. "movq 40(%3), %%mm5 \n\t"
  242. "movq 48(%3), %%mm6 \n\t"
  243. "movq 56(%3), %%mm7 \n\t"
  244. "packuswb %%mm1, %%mm0 \n\t"
  245. "packuswb %%mm3, %%mm2 \n\t"
  246. "packuswb %%mm5, %%mm4 \n\t"
  247. "packuswb %%mm7, %%mm6 \n\t"
  248. "movq %%mm0, (%0) \n\t"
  249. "movq %%mm2, (%0, %1) \n\t"
  250. "movq %%mm4, (%0, %1, 2) \n\t"
  251. "movq %%mm6, (%0, %2) \n\t"
  252. ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
  253. :"memory");
  254. }
  255. #define put_signed_pixels_clamped_mmx_half(off) \
  256. "movq "#off"(%2), %%mm1 \n\t"\
  257. "movq 16+"#off"(%2), %%mm2 \n\t"\
  258. "movq 32+"#off"(%2), %%mm3 \n\t"\
  259. "movq 48+"#off"(%2), %%mm4 \n\t"\
  260. "packsswb 8+"#off"(%2), %%mm1 \n\t"\
  261. "packsswb 24+"#off"(%2), %%mm2 \n\t"\
  262. "packsswb 40+"#off"(%2), %%mm3 \n\t"\
  263. "packsswb 56+"#off"(%2), %%mm4 \n\t"\
  264. "paddb %%mm0, %%mm1 \n\t"\
  265. "paddb %%mm0, %%mm2 \n\t"\
  266. "paddb %%mm0, %%mm3 \n\t"\
  267. "paddb %%mm0, %%mm4 \n\t"\
  268. "movq %%mm1, (%0) \n\t"\
  269. "movq %%mm2, (%0, %3) \n\t"\
  270. "movq %%mm3, (%0, %3, 2) \n\t"\
  271. "movq %%mm4, (%0, %1) \n\t"
  272. void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  273. {
  274. x86_reg line_skip = line_size;
  275. x86_reg line_skip3;
  276. __asm__ volatile (
  277. "movq "MANGLE(ff_pb_80)", %%mm0 \n\t"
  278. "lea (%3, %3, 2), %1 \n\t"
  279. put_signed_pixels_clamped_mmx_half(0)
  280. "lea (%0, %3, 4), %0 \n\t"
  281. put_signed_pixels_clamped_mmx_half(64)
  282. :"+&r" (pixels), "=&r" (line_skip3)
  283. :"r" (block), "r"(line_skip)
  284. :"memory");
  285. }
  286. void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
  287. {
  288. const DCTELEM *p;
  289. uint8_t *pix;
  290. int i;
  291. /* read the pixels */
  292. p = block;
  293. pix = pixels;
  294. MOVQ_ZERO(mm7);
  295. i = 4;
  296. do {
  297. __asm__ volatile(
  298. "movq (%2), %%mm0 \n\t"
  299. "movq 8(%2), %%mm1 \n\t"
  300. "movq 16(%2), %%mm2 \n\t"
  301. "movq 24(%2), %%mm3 \n\t"
  302. "movq %0, %%mm4 \n\t"
  303. "movq %1, %%mm6 \n\t"
  304. "movq %%mm4, %%mm5 \n\t"
  305. "punpcklbw %%mm7, %%mm4 \n\t"
  306. "punpckhbw %%mm7, %%mm5 \n\t"
  307. "paddsw %%mm4, %%mm0 \n\t"
  308. "paddsw %%mm5, %%mm1 \n\t"
  309. "movq %%mm6, %%mm5 \n\t"
  310. "punpcklbw %%mm7, %%mm6 \n\t"
  311. "punpckhbw %%mm7, %%mm5 \n\t"
  312. "paddsw %%mm6, %%mm2 \n\t"
  313. "paddsw %%mm5, %%mm3 \n\t"
  314. "packuswb %%mm1, %%mm0 \n\t"
  315. "packuswb %%mm3, %%mm2 \n\t"
  316. "movq %%mm0, %0 \n\t"
  317. "movq %%mm2, %1 \n\t"
  318. :"+m"(*pix), "+m"(*(pix+line_size))
  319. :"r"(p)
  320. :"memory");
  321. pix += line_size*2;
  322. p += 16;
  323. } while (--i);
  324. }
  325. static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  326. {
  327. __asm__ volatile(
  328. "lea (%3, %3), %%"REG_a" \n\t"
  329. ".p2align 3 \n\t"
  330. "1: \n\t"
  331. "movd (%1), %%mm0 \n\t"
  332. "movd (%1, %3), %%mm1 \n\t"
  333. "movd %%mm0, (%2) \n\t"
  334. "movd %%mm1, (%2, %3) \n\t"
  335. "add %%"REG_a", %1 \n\t"
  336. "add %%"REG_a", %2 \n\t"
  337. "movd (%1), %%mm0 \n\t"
  338. "movd (%1, %3), %%mm1 \n\t"
  339. "movd %%mm0, (%2) \n\t"
  340. "movd %%mm1, (%2, %3) \n\t"
  341. "add %%"REG_a", %1 \n\t"
  342. "add %%"REG_a", %2 \n\t"
  343. "subl $4, %0 \n\t"
  344. "jnz 1b \n\t"
  345. : "+g"(h), "+r" (pixels), "+r" (block)
  346. : "r"((x86_reg)line_size)
  347. : "%"REG_a, "memory"
  348. );
  349. }
  350. static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  351. {
  352. __asm__ volatile(
  353. "lea (%3, %3), %%"REG_a" \n\t"
  354. ".p2align 3 \n\t"
  355. "1: \n\t"
  356. "movq (%1), %%mm0 \n\t"
  357. "movq (%1, %3), %%mm1 \n\t"
  358. "movq %%mm0, (%2) \n\t"
  359. "movq %%mm1, (%2, %3) \n\t"
  360. "add %%"REG_a", %1 \n\t"
  361. "add %%"REG_a", %2 \n\t"
  362. "movq (%1), %%mm0 \n\t"
  363. "movq (%1, %3), %%mm1 \n\t"
  364. "movq %%mm0, (%2) \n\t"
  365. "movq %%mm1, (%2, %3) \n\t"
  366. "add %%"REG_a", %1 \n\t"
  367. "add %%"REG_a", %2 \n\t"
  368. "subl $4, %0 \n\t"
  369. "jnz 1b \n\t"
  370. : "+g"(h), "+r" (pixels), "+r" (block)
  371. : "r"((x86_reg)line_size)
  372. : "%"REG_a, "memory"
  373. );
  374. }
  375. static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  376. {
  377. __asm__ volatile(
  378. "lea (%3, %3), %%"REG_a" \n\t"
  379. ".p2align 3 \n\t"
  380. "1: \n\t"
  381. "movq (%1), %%mm0 \n\t"
  382. "movq 8(%1), %%mm4 \n\t"
  383. "movq (%1, %3), %%mm1 \n\t"
  384. "movq 8(%1, %3), %%mm5 \n\t"
  385. "movq %%mm0, (%2) \n\t"
  386. "movq %%mm4, 8(%2) \n\t"
  387. "movq %%mm1, (%2, %3) \n\t"
  388. "movq %%mm5, 8(%2, %3) \n\t"
  389. "add %%"REG_a", %1 \n\t"
  390. "add %%"REG_a", %2 \n\t"
  391. "movq (%1), %%mm0 \n\t"
  392. "movq 8(%1), %%mm4 \n\t"
  393. "movq (%1, %3), %%mm1 \n\t"
  394. "movq 8(%1, %3), %%mm5 \n\t"
  395. "movq %%mm0, (%2) \n\t"
  396. "movq %%mm4, 8(%2) \n\t"
  397. "movq %%mm1, (%2, %3) \n\t"
  398. "movq %%mm5, 8(%2, %3) \n\t"
  399. "add %%"REG_a", %1 \n\t"
  400. "add %%"REG_a", %2 \n\t"
  401. "subl $4, %0 \n\t"
  402. "jnz 1b \n\t"
  403. : "+g"(h), "+r" (pixels), "+r" (block)
  404. : "r"((x86_reg)line_size)
  405. : "%"REG_a, "memory"
  406. );
  407. }
  408. static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  409. {
  410. __asm__ volatile(
  411. "1: \n\t"
  412. "movdqu (%1), %%xmm0 \n\t"
  413. "movdqu (%1,%3), %%xmm1 \n\t"
  414. "movdqu (%1,%3,2), %%xmm2 \n\t"
  415. "movdqu (%1,%4), %%xmm3 \n\t"
  416. "lea (%1,%3,4), %1 \n\t"
  417. "movdqa %%xmm0, (%2) \n\t"
  418. "movdqa %%xmm1, (%2,%3) \n\t"
  419. "movdqa %%xmm2, (%2,%3,2) \n\t"
  420. "movdqa %%xmm3, (%2,%4) \n\t"
  421. "subl $4, %0 \n\t"
  422. "lea (%2,%3,4), %2 \n\t"
  423. "jnz 1b \n\t"
  424. : "+g"(h), "+r" (pixels), "+r" (block)
  425. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  426. : "memory"
  427. );
  428. }
  429. static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  430. {
  431. __asm__ volatile(
  432. "1: \n\t"
  433. "movdqu (%1), %%xmm0 \n\t"
  434. "movdqu (%1,%3), %%xmm1 \n\t"
  435. "movdqu (%1,%3,2), %%xmm2 \n\t"
  436. "movdqu (%1,%4), %%xmm3 \n\t"
  437. "lea (%1,%3,4), %1 \n\t"
  438. "pavgb (%2), %%xmm0 \n\t"
  439. "pavgb (%2,%3), %%xmm1 \n\t"
  440. "pavgb (%2,%3,2), %%xmm2 \n\t"
  441. "pavgb (%2,%4), %%xmm3 \n\t"
  442. "movdqa %%xmm0, (%2) \n\t"
  443. "movdqa %%xmm1, (%2,%3) \n\t"
  444. "movdqa %%xmm2, (%2,%3,2) \n\t"
  445. "movdqa %%xmm3, (%2,%4) \n\t"
  446. "subl $4, %0 \n\t"
  447. "lea (%2,%3,4), %2 \n\t"
  448. "jnz 1b \n\t"
  449. : "+g"(h), "+r" (pixels), "+r" (block)
  450. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  451. : "memory"
  452. );
  453. }
  454. #define CLEAR_BLOCKS(name,n) \
  455. static void name(DCTELEM *blocks)\
  456. {\
  457. __asm__ volatile(\
  458. "pxor %%mm7, %%mm7 \n\t"\
  459. "mov %1, %%"REG_a" \n\t"\
  460. "1: \n\t"\
  461. "movq %%mm7, (%0, %%"REG_a") \n\t"\
  462. "movq %%mm7, 8(%0, %%"REG_a") \n\t"\
  463. "movq %%mm7, 16(%0, %%"REG_a") \n\t"\
  464. "movq %%mm7, 24(%0, %%"REG_a") \n\t"\
  465. "add $32, %%"REG_a" \n\t"\
  466. " js 1b \n\t"\
  467. : : "r" (((uint8_t *)blocks)+128*n),\
  468. "i" (-128*n)\
  469. : "%"REG_a\
  470. );\
  471. }
  472. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  473. CLEAR_BLOCKS(clear_block_mmx, 1)
  474. static void clear_block_sse(DCTELEM *block)
  475. {
  476. __asm__ volatile(
  477. "xorps %%xmm0, %%xmm0 \n"
  478. "movaps %%xmm0, (%0) \n"
  479. "movaps %%xmm0, 16(%0) \n"
  480. "movaps %%xmm0, 32(%0) \n"
  481. "movaps %%xmm0, 48(%0) \n"
  482. "movaps %%xmm0, 64(%0) \n"
  483. "movaps %%xmm0, 80(%0) \n"
  484. "movaps %%xmm0, 96(%0) \n"
  485. "movaps %%xmm0, 112(%0) \n"
  486. :: "r"(block)
  487. : "memory"
  488. );
  489. }
  490. static void clear_blocks_sse(DCTELEM *blocks)
  491. {\
  492. __asm__ volatile(
  493. "xorps %%xmm0, %%xmm0 \n"
  494. "mov %1, %%"REG_a" \n"
  495. "1: \n"
  496. "movaps %%xmm0, (%0, %%"REG_a") \n"
  497. "movaps %%xmm0, 16(%0, %%"REG_a") \n"
  498. "movaps %%xmm0, 32(%0, %%"REG_a") \n"
  499. "movaps %%xmm0, 48(%0, %%"REG_a") \n"
  500. "movaps %%xmm0, 64(%0, %%"REG_a") \n"
  501. "movaps %%xmm0, 80(%0, %%"REG_a") \n"
  502. "movaps %%xmm0, 96(%0, %%"REG_a") \n"
  503. "movaps %%xmm0, 112(%0, %%"REG_a") \n"
  504. "add $128, %%"REG_a" \n"
  505. " js 1b \n"
  506. : : "r" (((uint8_t *)blocks)+128*6),
  507. "i" (-128*6)
  508. : "%"REG_a
  509. );
  510. }
  511. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
  512. x86_reg i=0;
  513. __asm__ volatile(
  514. "jmp 2f \n\t"
  515. "1: \n\t"
  516. "movq (%1, %0), %%mm0 \n\t"
  517. "movq (%2, %0), %%mm1 \n\t"
  518. "paddb %%mm0, %%mm1 \n\t"
  519. "movq %%mm1, (%2, %0) \n\t"
  520. "movq 8(%1, %0), %%mm0 \n\t"
  521. "movq 8(%2, %0), %%mm1 \n\t"
  522. "paddb %%mm0, %%mm1 \n\t"
  523. "movq %%mm1, 8(%2, %0) \n\t"
  524. "add $16, %0 \n\t"
  525. "2: \n\t"
  526. "cmp %3, %0 \n\t"
  527. " js 1b \n\t"
  528. : "+r" (i)
  529. : "r"(src), "r"(dst), "r"((x86_reg)w-15)
  530. );
  531. for(; i<w; i++)
  532. dst[i+0] += src[i+0];
  533. }
  534. #if HAVE_7REGS
  535. static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top) {
  536. x86_reg w2 = -w;
  537. x86_reg x;
  538. int l = *left & 0xff;
  539. int tl = *left_top & 0xff;
  540. int t;
  541. __asm__ volatile(
  542. "mov %7, %3 \n"
  543. "1: \n"
  544. "movzbl (%3,%4), %2 \n"
  545. "mov %2, %k3 \n"
  546. "sub %b1, %b3 \n"
  547. "add %b0, %b3 \n"
  548. "mov %2, %1 \n"
  549. "cmp %0, %2 \n"
  550. "cmovg %0, %2 \n"
  551. "cmovg %1, %0 \n"
  552. "cmp %k3, %0 \n"
  553. "cmovg %k3, %0 \n"
  554. "mov %7, %3 \n"
  555. "cmp %2, %0 \n"
  556. "cmovl %2, %0 \n"
  557. "add (%6,%4), %b0 \n"
  558. "mov %b0, (%5,%4) \n"
  559. "inc %4 \n"
  560. "jl 1b \n"
  561. :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  562. :"r"(dst+w), "r"(diff+w), "rm"(top+w)
  563. );
  564. *left = l;
  565. *left_top = tl;
  566. }
  567. #endif
  568. #define H263_LOOP_FILTER \
  569. "pxor %%mm7, %%mm7 \n\t"\
  570. "movq %0, %%mm0 \n\t"\
  571. "movq %0, %%mm1 \n\t"\
  572. "movq %3, %%mm2 \n\t"\
  573. "movq %3, %%mm3 \n\t"\
  574. "punpcklbw %%mm7, %%mm0 \n\t"\
  575. "punpckhbw %%mm7, %%mm1 \n\t"\
  576. "punpcklbw %%mm7, %%mm2 \n\t"\
  577. "punpckhbw %%mm7, %%mm3 \n\t"\
  578. "psubw %%mm2, %%mm0 \n\t"\
  579. "psubw %%mm3, %%mm1 \n\t"\
  580. "movq %1, %%mm2 \n\t"\
  581. "movq %1, %%mm3 \n\t"\
  582. "movq %2, %%mm4 \n\t"\
  583. "movq %2, %%mm5 \n\t"\
  584. "punpcklbw %%mm7, %%mm2 \n\t"\
  585. "punpckhbw %%mm7, %%mm3 \n\t"\
  586. "punpcklbw %%mm7, %%mm4 \n\t"\
  587. "punpckhbw %%mm7, %%mm5 \n\t"\
  588. "psubw %%mm2, %%mm4 \n\t"\
  589. "psubw %%mm3, %%mm5 \n\t"\
  590. "psllw $2, %%mm4 \n\t"\
  591. "psllw $2, %%mm5 \n\t"\
  592. "paddw %%mm0, %%mm4 \n\t"\
  593. "paddw %%mm1, %%mm5 \n\t"\
  594. "pxor %%mm6, %%mm6 \n\t"\
  595. "pcmpgtw %%mm4, %%mm6 \n\t"\
  596. "pcmpgtw %%mm5, %%mm7 \n\t"\
  597. "pxor %%mm6, %%mm4 \n\t"\
  598. "pxor %%mm7, %%mm5 \n\t"\
  599. "psubw %%mm6, %%mm4 \n\t"\
  600. "psubw %%mm7, %%mm5 \n\t"\
  601. "psrlw $3, %%mm4 \n\t"\
  602. "psrlw $3, %%mm5 \n\t"\
  603. "packuswb %%mm5, %%mm4 \n\t"\
  604. "packsswb %%mm7, %%mm6 \n\t"\
  605. "pxor %%mm7, %%mm7 \n\t"\
  606. "movd %4, %%mm2 \n\t"\
  607. "punpcklbw %%mm2, %%mm2 \n\t"\
  608. "punpcklbw %%mm2, %%mm2 \n\t"\
  609. "punpcklbw %%mm2, %%mm2 \n\t"\
  610. "psubusb %%mm4, %%mm2 \n\t"\
  611. "movq %%mm2, %%mm3 \n\t"\
  612. "psubusb %%mm4, %%mm3 \n\t"\
  613. "psubb %%mm3, %%mm2 \n\t"\
  614. "movq %1, %%mm3 \n\t"\
  615. "movq %2, %%mm4 \n\t"\
  616. "pxor %%mm6, %%mm3 \n\t"\
  617. "pxor %%mm6, %%mm4 \n\t"\
  618. "paddusb %%mm2, %%mm3 \n\t"\
  619. "psubusb %%mm2, %%mm4 \n\t"\
  620. "pxor %%mm6, %%mm3 \n\t"\
  621. "pxor %%mm6, %%mm4 \n\t"\
  622. "paddusb %%mm2, %%mm2 \n\t"\
  623. "packsswb %%mm1, %%mm0 \n\t"\
  624. "pcmpgtb %%mm0, %%mm7 \n\t"\
  625. "pxor %%mm7, %%mm0 \n\t"\
  626. "psubb %%mm7, %%mm0 \n\t"\
  627. "movq %%mm0, %%mm1 \n\t"\
  628. "psubusb %%mm2, %%mm0 \n\t"\
  629. "psubb %%mm0, %%mm1 \n\t"\
  630. "pand %5, %%mm1 \n\t"\
  631. "psrlw $2, %%mm1 \n\t"\
  632. "pxor %%mm7, %%mm1 \n\t"\
  633. "psubb %%mm7, %%mm1 \n\t"\
  634. "movq %0, %%mm5 \n\t"\
  635. "movq %3, %%mm6 \n\t"\
  636. "psubb %%mm1, %%mm5 \n\t"\
  637. "paddb %%mm1, %%mm6 \n\t"
  638. static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
  639. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  640. const int strength= ff_h263_loop_filter_strength[qscale];
  641. __asm__ volatile(
  642. H263_LOOP_FILTER
  643. "movq %%mm3, %1 \n\t"
  644. "movq %%mm4, %2 \n\t"
  645. "movq %%mm5, %0 \n\t"
  646. "movq %%mm6, %3 \n\t"
  647. : "+m" (*(uint64_t*)(src - 2*stride)),
  648. "+m" (*(uint64_t*)(src - 1*stride)),
  649. "+m" (*(uint64_t*)(src + 0*stride)),
  650. "+m" (*(uint64_t*)(src + 1*stride))
  651. : "g" (2*strength), "m"(ff_pb_FC)
  652. );
  653. }
  654. }
  655. static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
  656. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  657. const int strength= ff_h263_loop_filter_strength[qscale];
  658. DECLARE_ALIGNED(8, uint64_t, temp)[4];
  659. uint8_t *btemp= (uint8_t*)temp;
  660. src -= 2;
  661. transpose4x4(btemp , src , 8, stride);
  662. transpose4x4(btemp+4, src + 4*stride, 8, stride);
  663. __asm__ volatile(
  664. H263_LOOP_FILTER // 5 3 4 6
  665. : "+m" (temp[0]),
  666. "+m" (temp[1]),
  667. "+m" (temp[2]),
  668. "+m" (temp[3])
  669. : "g" (2*strength), "m"(ff_pb_FC)
  670. );
  671. __asm__ volatile(
  672. "movq %%mm5, %%mm1 \n\t"
  673. "movq %%mm4, %%mm0 \n\t"
  674. "punpcklbw %%mm3, %%mm5 \n\t"
  675. "punpcklbw %%mm6, %%mm4 \n\t"
  676. "punpckhbw %%mm3, %%mm1 \n\t"
  677. "punpckhbw %%mm6, %%mm0 \n\t"
  678. "movq %%mm5, %%mm3 \n\t"
  679. "movq %%mm1, %%mm6 \n\t"
  680. "punpcklwd %%mm4, %%mm5 \n\t"
  681. "punpcklwd %%mm0, %%mm1 \n\t"
  682. "punpckhwd %%mm4, %%mm3 \n\t"
  683. "punpckhwd %%mm0, %%mm6 \n\t"
  684. "movd %%mm5, (%0) \n\t"
  685. "punpckhdq %%mm5, %%mm5 \n\t"
  686. "movd %%mm5, (%0,%2) \n\t"
  687. "movd %%mm3, (%0,%2,2) \n\t"
  688. "punpckhdq %%mm3, %%mm3 \n\t"
  689. "movd %%mm3, (%0,%3) \n\t"
  690. "movd %%mm1, (%1) \n\t"
  691. "punpckhdq %%mm1, %%mm1 \n\t"
  692. "movd %%mm1, (%1,%2) \n\t"
  693. "movd %%mm6, (%1,%2,2) \n\t"
  694. "punpckhdq %%mm6, %%mm6 \n\t"
  695. "movd %%mm6, (%1,%3) \n\t"
  696. :: "r" (src),
  697. "r" (src + 4*stride),
  698. "r" ((x86_reg) stride ),
  699. "r" ((x86_reg)(3*stride))
  700. );
  701. }
  702. }
  703. /* draw the edges of width 'w' of an image of size width, height
  704. this mmx version can only handle w==8 || w==16 */
  705. static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides)
  706. {
  707. uint8_t *ptr, *last_line;
  708. int i;
  709. last_line = buf + (height - 1) * wrap;
  710. /* left and right */
  711. ptr = buf;
  712. if(w==8)
  713. {
  714. __asm__ volatile(
  715. "1: \n\t"
  716. "movd (%0), %%mm0 \n\t"
  717. "punpcklbw %%mm0, %%mm0 \n\t"
  718. "punpcklwd %%mm0, %%mm0 \n\t"
  719. "punpckldq %%mm0, %%mm0 \n\t"
  720. "movq %%mm0, -8(%0) \n\t"
  721. "movq -8(%0, %2), %%mm1 \n\t"
  722. "punpckhbw %%mm1, %%mm1 \n\t"
  723. "punpckhwd %%mm1, %%mm1 \n\t"
  724. "punpckhdq %%mm1, %%mm1 \n\t"
  725. "movq %%mm1, (%0, %2) \n\t"
  726. "add %1, %0 \n\t"
  727. "cmp %3, %0 \n\t"
  728. " jb 1b \n\t"
  729. : "+r" (ptr)
  730. : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
  731. );
  732. }
  733. else
  734. {
  735. __asm__ volatile(
  736. "1: \n\t"
  737. "movd (%0), %%mm0 \n\t"
  738. "punpcklbw %%mm0, %%mm0 \n\t"
  739. "punpcklwd %%mm0, %%mm0 \n\t"
  740. "punpckldq %%mm0, %%mm0 \n\t"
  741. "movq %%mm0, -8(%0) \n\t"
  742. "movq %%mm0, -16(%0) \n\t"
  743. "movq -8(%0, %2), %%mm1 \n\t"
  744. "punpckhbw %%mm1, %%mm1 \n\t"
  745. "punpckhwd %%mm1, %%mm1 \n\t"
  746. "punpckhdq %%mm1, %%mm1 \n\t"
  747. "movq %%mm1, (%0, %2) \n\t"
  748. "movq %%mm1, 8(%0, %2) \n\t"
  749. "add %1, %0 \n\t"
  750. "cmp %3, %0 \n\t"
  751. " jb 1b \n\t"
  752. : "+r" (ptr)
  753. : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
  754. );
  755. }
  756. /* top and bottom (and hopefully also the corners) */
  757. if (sides&EDGE_TOP) {
  758. for(i = 0; i < h; i += 4) {
  759. ptr= buf - (i + 1) * wrap - w;
  760. __asm__ volatile(
  761. "1: \n\t"
  762. "movq (%1, %0), %%mm0 \n\t"
  763. "movq %%mm0, (%0) \n\t"
  764. "movq %%mm0, (%0, %2) \n\t"
  765. "movq %%mm0, (%0, %2, 2) \n\t"
  766. "movq %%mm0, (%0, %3) \n\t"
  767. "add $8, %0 \n\t"
  768. "cmp %4, %0 \n\t"
  769. " jb 1b \n\t"
  770. : "+r" (ptr)
  771. : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
  772. );
  773. }
  774. }
  775. if (sides&EDGE_BOTTOM) {
  776. for(i = 0; i < h; i += 4) {
  777. ptr= last_line + (i + 1) * wrap - w;
  778. __asm__ volatile(
  779. "1: \n\t"
  780. "movq (%1, %0), %%mm0 \n\t"
  781. "movq %%mm0, (%0) \n\t"
  782. "movq %%mm0, (%0, %2) \n\t"
  783. "movq %%mm0, (%0, %2, 2) \n\t"
  784. "movq %%mm0, (%0, %3) \n\t"
  785. "add $8, %0 \n\t"
  786. "cmp %4, %0 \n\t"
  787. " jb 1b \n\t"
  788. : "+r" (ptr)
  789. : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
  790. );
  791. }
  792. }
  793. }
  794. #define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
  795. "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
  796. "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
  797. "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
  798. "movq "#in7", " #m3 " \n\t" /* d */\
  799. "movq "#in0", %%mm5 \n\t" /* D */\
  800. "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
  801. "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
  802. "movq "#in1", %%mm5 \n\t" /* C */\
  803. "movq "#in2", %%mm6 \n\t" /* B */\
  804. "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
  805. "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
  806. "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
  807. "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
  808. "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
  809. "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
  810. "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
  811. "psraw $5, %%mm5 \n\t"\
  812. "packuswb %%mm5, %%mm5 \n\t"\
  813. OP(%%mm5, out, %%mm7, d)
  814. #define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
  815. static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  816. uint64_t temp;\
  817. \
  818. __asm__ volatile(\
  819. "pxor %%mm7, %%mm7 \n\t"\
  820. "1: \n\t"\
  821. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
  822. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
  823. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
  824. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
  825. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
  826. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
  827. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
  828. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
  829. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
  830. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
  831. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
  832. "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
  833. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
  834. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
  835. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
  836. "paddw %%mm3, %%mm5 \n\t" /* b */\
  837. "paddw %%mm2, %%mm6 \n\t" /* c */\
  838. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  839. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
  840. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
  841. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
  842. "paddw %%mm4, %%mm0 \n\t" /* a */\
  843. "paddw %%mm1, %%mm5 \n\t" /* d */\
  844. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
  845. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
  846. "paddw %6, %%mm6 \n\t"\
  847. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  848. "psraw $5, %%mm0 \n\t"\
  849. "movq %%mm0, %5 \n\t"\
  850. /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
  851. \
  852. "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
  853. "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
  854. "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
  855. "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
  856. "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
  857. "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
  858. "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
  859. "paddw %%mm0, %%mm2 \n\t" /* b */\
  860. "paddw %%mm5, %%mm3 \n\t" /* c */\
  861. "paddw %%mm2, %%mm2 \n\t" /* 2b */\
  862. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
  863. "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
  864. "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
  865. "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
  866. "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
  867. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
  868. "paddw %%mm2, %%mm1 \n\t" /* a */\
  869. "paddw %%mm6, %%mm4 \n\t" /* d */\
  870. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
  871. "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
  872. "paddw %6, %%mm1 \n\t"\
  873. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
  874. "psraw $5, %%mm3 \n\t"\
  875. "movq %5, %%mm1 \n\t"\
  876. "packuswb %%mm3, %%mm1 \n\t"\
  877. OP_MMX2(%%mm1, (%1),%%mm4, q)\
  878. /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
  879. \
  880. "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
  881. "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
  882. "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
  883. "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
  884. "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
  885. "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
  886. "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
  887. "paddw %%mm1, %%mm5 \n\t" /* b */\
  888. "paddw %%mm4, %%mm0 \n\t" /* c */\
  889. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  890. "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
  891. "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
  892. "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
  893. "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
  894. "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
  895. "paddw %%mm3, %%mm2 \n\t" /* d */\
  896. "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
  897. "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
  898. "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
  899. "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
  900. "paddw %%mm2, %%mm6 \n\t" /* a */\
  901. "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
  902. "paddw %6, %%mm0 \n\t"\
  903. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  904. "psraw $5, %%mm0 \n\t"\
  905. /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
  906. \
  907. "paddw %%mm5, %%mm3 \n\t" /* a */\
  908. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
  909. "paddw %%mm4, %%mm6 \n\t" /* b */\
  910. "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
  911. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
  912. "paddw %%mm1, %%mm4 \n\t" /* c */\
  913. "paddw %%mm2, %%mm5 \n\t" /* d */\
  914. "paddw %%mm6, %%mm6 \n\t" /* 2b */\
  915. "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
  916. "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
  917. "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
  918. "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
  919. "paddw %6, %%mm4 \n\t"\
  920. "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
  921. "psraw $5, %%mm4 \n\t"\
  922. "packuswb %%mm4, %%mm0 \n\t"\
  923. OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
  924. \
  925. "add %3, %0 \n\t"\
  926. "add %4, %1 \n\t"\
  927. "decl %2 \n\t"\
  928. " jnz 1b \n\t"\
  929. : "+a"(src), "+c"(dst), "+D"(h)\
  930. : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
  931. : "memory"\
  932. );\
  933. }\
  934. \
  935. static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  936. int i;\
  937. int16_t temp[16];\
  938. /* quick HACK, XXX FIXME MUST be optimized */\
  939. for(i=0; i<h; i++)\
  940. {\
  941. temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
  942. temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
  943. temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
  944. temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
  945. temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
  946. temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
  947. temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
  948. temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
  949. temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
  950. temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
  951. temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
  952. temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
  953. temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
  954. temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
  955. temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
  956. temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
  957. __asm__ volatile(\
  958. "movq (%0), %%mm0 \n\t"\
  959. "movq 8(%0), %%mm1 \n\t"\
  960. "paddw %2, %%mm0 \n\t"\
  961. "paddw %2, %%mm1 \n\t"\
  962. "psraw $5, %%mm0 \n\t"\
  963. "psraw $5, %%mm1 \n\t"\
  964. "packuswb %%mm1, %%mm0 \n\t"\
  965. OP_3DNOW(%%mm0, (%1), %%mm1, q)\
  966. "movq 16(%0), %%mm0 \n\t"\
  967. "movq 24(%0), %%mm1 \n\t"\
  968. "paddw %2, %%mm0 \n\t"\
  969. "paddw %2, %%mm1 \n\t"\
  970. "psraw $5, %%mm0 \n\t"\
  971. "psraw $5, %%mm1 \n\t"\
  972. "packuswb %%mm1, %%mm0 \n\t"\
  973. OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
  974. :: "r"(temp), "r"(dst), "m"(ROUNDER)\
  975. : "memory"\
  976. );\
  977. dst+=dstStride;\
  978. src+=srcStride;\
  979. }\
  980. }\
  981. \
  982. static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  983. __asm__ volatile(\
  984. "pxor %%mm7, %%mm7 \n\t"\
  985. "1: \n\t"\
  986. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
  987. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
  988. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
  989. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
  990. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
  991. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
  992. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
  993. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
  994. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
  995. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
  996. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
  997. "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
  998. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
  999. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
  1000. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
  1001. "paddw %%mm3, %%mm5 \n\t" /* b */\
  1002. "paddw %%mm2, %%mm6 \n\t" /* c */\
  1003. "paddw %%mm5, %%mm5 \n\t" /* 2b */\
  1004. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
  1005. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
  1006. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
  1007. "paddw %%mm4, %%mm0 \n\t" /* a */\
  1008. "paddw %%mm1, %%mm5 \n\t" /* d */\
  1009. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
  1010. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
  1011. "paddw %5, %%mm6 \n\t"\
  1012. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
  1013. "psraw $5, %%mm0 \n\t"\
  1014. /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
  1015. \
  1016. "movd 5(%0), %%mm5 \n\t" /* FGHI */\
  1017. "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
  1018. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
  1019. "paddw %%mm5, %%mm1 \n\t" /* a */\
  1020. "paddw %%mm6, %%mm2 \n\t" /* b */\
  1021. "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
  1022. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
  1023. "paddw %%mm6, %%mm3 \n\t" /* c */\
  1024. "paddw %%mm5, %%mm4 \n\t" /* d */\
  1025. "paddw %%mm2, %%mm2 \n\t" /* 2b */\
  1026. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
  1027. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
  1028. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
  1029. "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
  1030. "paddw %5, %%mm1 \n\t"\
  1031. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
  1032. "psraw $5, %%mm3 \n\t"\
  1033. "packuswb %%mm3, %%mm0 \n\t"\
  1034. OP_MMX2(%%mm0, (%1), %%mm4, q)\
  1035. \
  1036. "add %3, %0 \n\t"\
  1037. "add %4, %1 \n\t"\
  1038. "decl %2 \n\t"\
  1039. " jnz 1b \n\t"\
  1040. : "+a"(src), "+c"(dst), "+d"(h)\
  1041. : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
  1042. : "memory"\
  1043. );\
  1044. }\
  1045. \
  1046. static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1047. int i;\
  1048. int16_t temp[8];\
  1049. /* quick HACK, XXX FIXME MUST be optimized */\
  1050. for(i=0; i<h; i++)\
  1051. {\
  1052. temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
  1053. temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
  1054. temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
  1055. temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
  1056. temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
  1057. temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
  1058. temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
  1059. temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
  1060. __asm__ volatile(\
  1061. "movq (%0), %%mm0 \n\t"\
  1062. "movq 8(%0), %%mm1 \n\t"\
  1063. "paddw %2, %%mm0 \n\t"\
  1064. "paddw %2, %%mm1 \n\t"\
  1065. "psraw $5, %%mm0 \n\t"\
  1066. "psraw $5, %%mm1 \n\t"\
  1067. "packuswb %%mm1, %%mm0 \n\t"\
  1068. OP_3DNOW(%%mm0, (%1), %%mm1, q)\
  1069. :: "r"(temp), "r"(dst), "m"(ROUNDER)\
  1070. :"memory"\
  1071. );\
  1072. dst+=dstStride;\
  1073. src+=srcStride;\
  1074. }\
  1075. }
  1076. #define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
  1077. \
  1078. static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1079. uint64_t temp[17*4];\
  1080. uint64_t *temp_ptr= temp;\
  1081. int count= 17;\
  1082. \
  1083. /*FIXME unroll */\
  1084. __asm__ volatile(\
  1085. "pxor %%mm7, %%mm7 \n\t"\
  1086. "1: \n\t"\
  1087. "movq (%0), %%mm0 \n\t"\
  1088. "movq (%0), %%mm1 \n\t"\
  1089. "movq 8(%0), %%mm2 \n\t"\
  1090. "movq 8(%0), %%mm3 \n\t"\
  1091. "punpcklbw %%mm7, %%mm0 \n\t"\
  1092. "punpckhbw %%mm7, %%mm1 \n\t"\
  1093. "punpcklbw %%mm7, %%mm2 \n\t"\
  1094. "punpckhbw %%mm7, %%mm3 \n\t"\
  1095. "movq %%mm0, (%1) \n\t"\
  1096. "movq %%mm1, 17*8(%1) \n\t"\
  1097. "movq %%mm2, 2*17*8(%1) \n\t"\
  1098. "movq %%mm3, 3*17*8(%1) \n\t"\
  1099. "add $8, %1 \n\t"\
  1100. "add %3, %0 \n\t"\
  1101. "decl %2 \n\t"\
  1102. " jnz 1b \n\t"\
  1103. : "+r" (src), "+r" (temp_ptr), "+r"(count)\
  1104. : "r" ((x86_reg)srcStride)\
  1105. : "memory"\
  1106. );\
  1107. \
  1108. temp_ptr= temp;\
  1109. count=4;\
  1110. \
  1111. /*FIXME reorder for speed */\
  1112. __asm__ volatile(\
  1113. /*"pxor %%mm7, %%mm7 \n\t"*/\
  1114. "1: \n\t"\
  1115. "movq (%0), %%mm0 \n\t"\
  1116. "movq 8(%0), %%mm1 \n\t"\
  1117. "movq 16(%0), %%mm2 \n\t"\
  1118. "movq 24(%0), %%mm3 \n\t"\
  1119. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
  1120. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
  1121. "add %4, %1 \n\t"\
  1122. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
  1123. \
  1124. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
  1125. "add %4, %1 \n\t"\
  1126. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
  1127. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
  1128. "add %4, %1 \n\t"\
  1129. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
  1130. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
  1131. "add %4, %1 \n\t"\
  1132. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
  1133. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
  1134. "add %4, %1 \n\t"\
  1135. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
  1136. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
  1137. "add %4, %1 \n\t"\
  1138. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
  1139. \
  1140. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
  1141. "add %4, %1 \n\t" \
  1142. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
  1143. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
  1144. \
  1145. "add $136, %0 \n\t"\
  1146. "add %6, %1 \n\t"\
  1147. "decl %2 \n\t"\
  1148. " jnz 1b \n\t"\
  1149. \
  1150. : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
  1151. : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(x86_reg)dstStride)\
  1152. :"memory"\
  1153. );\
  1154. }\
  1155. \
  1156. static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1157. uint64_t temp[9*2];\
  1158. uint64_t *temp_ptr= temp;\
  1159. int count= 9;\
  1160. \
  1161. /*FIXME unroll */\
  1162. __asm__ volatile(\
  1163. "pxor %%mm7, %%mm7 \n\t"\
  1164. "1: \n\t"\
  1165. "movq (%0), %%mm0 \n\t"\
  1166. "movq (%0), %%mm1 \n\t"\
  1167. "punpcklbw %%mm7, %%mm0 \n\t"\
  1168. "punpckhbw %%mm7, %%mm1 \n\t"\
  1169. "movq %%mm0, (%1) \n\t"\
  1170. "movq %%mm1, 9*8(%1) \n\t"\
  1171. "add $8, %1 \n\t"\
  1172. "add %3, %0 \n\t"\
  1173. "decl %2 \n\t"\
  1174. " jnz 1b \n\t"\
  1175. : "+r" (src), "+r" (temp_ptr), "+r"(count)\
  1176. : "r" ((x86_reg)srcStride)\
  1177. : "memory"\
  1178. );\
  1179. \
  1180. temp_ptr= temp;\
  1181. count=2;\
  1182. \
  1183. /*FIXME reorder for speed */\
  1184. __asm__ volatile(\
  1185. /*"pxor %%mm7, %%mm7 \n\t"*/\
  1186. "1: \n\t"\
  1187. "movq (%0), %%mm0 \n\t"\
  1188. "movq 8(%0), %%mm1 \n\t"\
  1189. "movq 16(%0), %%mm2 \n\t"\
  1190. "movq 24(%0), %%mm3 \n\t"\
  1191. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
  1192. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
  1193. "add %4, %1 \n\t"\
  1194. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
  1195. \
  1196. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
  1197. "add %4, %1 \n\t"\
  1198. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
  1199. \
  1200. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
  1201. "add %4, %1 \n\t"\
  1202. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
  1203. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
  1204. \
  1205. "add $72, %0 \n\t"\
  1206. "add %6, %1 \n\t"\
  1207. "decl %2 \n\t"\
  1208. " jnz 1b \n\t"\
  1209. \
  1210. : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
  1211. : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(x86_reg)dstStride)\
  1212. : "memory"\
  1213. );\
  1214. }\
  1215. \
  1216. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
  1217. OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);\
  1218. }\
  1219. \
  1220. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1221. uint64_t temp[8];\
  1222. uint8_t * const half= (uint8_t*)temp;\
  1223. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
  1224. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
  1225. }\
  1226. \
  1227. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1228. OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
  1229. }\
  1230. \
  1231. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1232. uint64_t temp[8];\
  1233. uint8_t * const half= (uint8_t*)temp;\
  1234. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
  1235. OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
  1236. }\
  1237. \
  1238. static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1239. uint64_t temp[8];\
  1240. uint8_t * const half= (uint8_t*)temp;\
  1241. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
  1242. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
  1243. }\
  1244. \
  1245. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1246. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
  1247. }\
  1248. \
  1249. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1250. uint64_t temp[8];\
  1251. uint8_t * const half= (uint8_t*)temp;\
  1252. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
  1253. OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
  1254. }\
  1255. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1256. uint64_t half[8 + 9];\
  1257. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1258. uint8_t * const halfHV= ((uint8_t*)half);\
  1259. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1260. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1261. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1262. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1263. }\
  1264. static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1265. uint64_t half[8 + 9];\
  1266. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1267. uint8_t * const halfHV= ((uint8_t*)half);\
  1268. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1269. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1270. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1271. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1272. }\
  1273. static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1274. uint64_t half[8 + 9];\
  1275. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1276. uint8_t * const halfHV= ((uint8_t*)half);\
  1277. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1278. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1279. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1280. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1281. }\
  1282. static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1283. uint64_t half[8 + 9];\
  1284. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1285. uint8_t * const halfHV= ((uint8_t*)half);\
  1286. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1287. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1288. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1289. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1290. }\
  1291. static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1292. uint64_t half[8 + 9];\
  1293. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1294. uint8_t * const halfHV= ((uint8_t*)half);\
  1295. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1296. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1297. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
  1298. }\
  1299. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1300. uint64_t half[8 + 9];\
  1301. uint8_t * const halfH= ((uint8_t*)half) + 64;\
  1302. uint8_t * const halfHV= ((uint8_t*)half);\
  1303. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1304. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  1305. OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
  1306. }\
  1307. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1308. uint64_t half[8 + 9];\
  1309. uint8_t * const halfH= ((uint8_t*)half);\
  1310. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1311. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
  1312. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1313. }\
  1314. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1315. uint64_t half[8 + 9];\
  1316. uint8_t * const halfH= ((uint8_t*)half);\
  1317. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1318. put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
  1319. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1320. }\
  1321. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1322. uint64_t half[9];\
  1323. uint8_t * const halfH= ((uint8_t*)half);\
  1324. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
  1325. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
  1326. }\
  1327. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
  1328. OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);\
  1329. }\
  1330. \
  1331. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1332. uint64_t temp[32];\
  1333. uint8_t * const half= (uint8_t*)temp;\
  1334. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
  1335. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
  1336. }\
  1337. \
  1338. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1339. OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
  1340. }\
  1341. \
  1342. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1343. uint64_t temp[32];\
  1344. uint8_t * const half= (uint8_t*)temp;\
  1345. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
  1346. OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
  1347. }\
  1348. \
  1349. static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1350. uint64_t temp[32];\
  1351. uint8_t * const half= (uint8_t*)temp;\
  1352. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
  1353. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
  1354. }\
  1355. \
  1356. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1357. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
  1358. }\
  1359. \
  1360. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1361. uint64_t temp[32];\
  1362. uint8_t * const half= (uint8_t*)temp;\
  1363. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
  1364. OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
  1365. }\
  1366. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1367. uint64_t half[16*2 + 17*2];\
  1368. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1369. uint8_t * const halfHV= ((uint8_t*)half);\
  1370. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1371. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1372. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1373. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1374. }\
  1375. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1376. uint64_t half[16*2 + 17*2];\
  1377. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1378. uint8_t * const halfHV= ((uint8_t*)half);\
  1379. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1380. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1381. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1382. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1383. }\
  1384. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1385. uint64_t half[16*2 + 17*2];\
  1386. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1387. uint8_t * const halfHV= ((uint8_t*)half);\
  1388. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1389. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1390. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1391. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1392. }\
  1393. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1394. uint64_t half[16*2 + 17*2];\
  1395. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1396. uint8_t * const halfHV= ((uint8_t*)half);\
  1397. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1398. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1399. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1400. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1401. }\
  1402. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1403. uint64_t half[16*2 + 17*2];\
  1404. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1405. uint8_t * const halfHV= ((uint8_t*)half);\
  1406. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1407. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1408. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
  1409. }\
  1410. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1411. uint64_t half[16*2 + 17*2];\
  1412. uint8_t * const halfH= ((uint8_t*)half) + 256;\
  1413. uint8_t * const halfHV= ((uint8_t*)half);\
  1414. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1415. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
  1416. OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
  1417. }\
  1418. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1419. uint64_t half[17*2];\
  1420. uint8_t * const halfH= ((uint8_t*)half);\
  1421. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1422. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
  1423. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1424. }\
  1425. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1426. uint64_t half[17*2];\
  1427. uint8_t * const halfH= ((uint8_t*)half);\
  1428. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1429. put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
  1430. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1431. }\
  1432. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1433. uint64_t half[17*2];\
  1434. uint8_t * const halfH= ((uint8_t*)half);\
  1435. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
  1436. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
  1437. }
  1438. #define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
  1439. #define AVG_3DNOW_OP(a,b,temp, size) \
  1440. "mov" #size " " #b ", " #temp " \n\t"\
  1441. "pavgusb " #temp ", " #a " \n\t"\
  1442. "mov" #size " " #a ", " #b " \n\t"
  1443. #define AVG_MMX2_OP(a,b,temp, size) \
  1444. "mov" #size " " #b ", " #temp " \n\t"\
  1445. "pavgb " #temp ", " #a " \n\t"\
  1446. "mov" #size " " #a ", " #b " \n\t"
  1447. QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
  1448. QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
  1449. QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
  1450. QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
  1451. QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
  1452. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
  1453. QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
  1454. QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
  1455. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
  1456. /***********************************/
  1457. /* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
  1458. #define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
  1459. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1460. OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
  1461. }
  1462. #define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
  1463. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1464. OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
  1465. }
  1466. #define QPEL_2TAP(OPNAME, SIZE, MMX)\
  1467. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
  1468. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
  1469. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
  1470. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
  1471. OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
  1472. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
  1473. OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
  1474. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
  1475. OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
  1476. static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1477. OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
  1478. }\
  1479. static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
  1480. OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
  1481. }\
  1482. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0)\
  1483. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0)\
  1484. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0)\
  1485. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0)\
  1486. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1)\
  1487. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1)\
  1488. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1)\
  1489. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
  1490. QPEL_2TAP(put_, 16, mmx2)
  1491. QPEL_2TAP(avg_, 16, mmx2)
  1492. QPEL_2TAP(put_, 8, mmx2)
  1493. QPEL_2TAP(avg_, 8, mmx2)
  1494. QPEL_2TAP(put_, 16, 3dnow)
  1495. QPEL_2TAP(avg_, 16, 3dnow)
  1496. QPEL_2TAP(put_, 8, 3dnow)
  1497. QPEL_2TAP(avg_, 8, 3dnow)
  1498. #if HAVE_YASM
  1499. typedef void emu_edge_core_func (uint8_t *buf, const uint8_t *src,
  1500. x86_reg linesize, x86_reg start_y,
  1501. x86_reg end_y, x86_reg block_h,
  1502. x86_reg start_x, x86_reg end_x,
  1503. x86_reg block_w);
  1504. extern emu_edge_core_func ff_emu_edge_core_mmx;
  1505. extern emu_edge_core_func ff_emu_edge_core_sse;
  1506. static av_always_inline
  1507. void emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize,
  1508. int block_w, int block_h,
  1509. int src_x, int src_y, int w, int h,
  1510. emu_edge_core_func *core_fn)
  1511. {
  1512. int start_y, start_x, end_y, end_x, src_y_add=0;
  1513. if(src_y>= h){
  1514. src_y_add = h-1-src_y;
  1515. src_y=h-1;
  1516. }else if(src_y<=-block_h){
  1517. src_y_add = 1-block_h-src_y;
  1518. src_y=1-block_h;
  1519. }
  1520. if(src_x>= w){
  1521. src+= (w-1-src_x);
  1522. src_x=w-1;
  1523. }else if(src_x<=-block_w){
  1524. src+= (1-block_w-src_x);
  1525. src_x=1-block_w;
  1526. }
  1527. start_y= FFMAX(0, -src_y);
  1528. start_x= FFMAX(0, -src_x);
  1529. end_y= FFMIN(block_h, h-src_y);
  1530. end_x= FFMIN(block_w, w-src_x);
  1531. assert(start_x < end_x && block_w > 0);
  1532. assert(start_y < end_y && block_h > 0);
  1533. // fill in the to-be-copied part plus all above/below
  1534. src += (src_y_add+start_y)*linesize + start_x;
  1535. buf += start_x;
  1536. core_fn(buf, src, linesize, start_y, end_y, block_h, start_x, end_x, block_w);
  1537. }
  1538. #if ARCH_X86_32
  1539. static av_noinline
  1540. void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src, int linesize,
  1541. int block_w, int block_h,
  1542. int src_x, int src_y, int w, int h)
  1543. {
  1544. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  1545. w, h, &ff_emu_edge_core_mmx);
  1546. }
  1547. #endif
  1548. static av_noinline
  1549. void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src, int linesize,
  1550. int block_w, int block_h,
  1551. int src_x, int src_y, int w, int h)
  1552. {
  1553. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  1554. w, h, &ff_emu_edge_core_sse);
  1555. }
  1556. #endif /* HAVE_YASM */
  1557. typedef void emulated_edge_mc_func (uint8_t *dst, const uint8_t *src,
  1558. int linesize, int block_w, int block_h,
  1559. int src_x, int src_y, int w, int h);
  1560. static av_always_inline
  1561. void gmc(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1562. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height,
  1563. emulated_edge_mc_func *emu_edge_fn)
  1564. {
  1565. const int w = 8;
  1566. const int ix = ox>>(16+shift);
  1567. const int iy = oy>>(16+shift);
  1568. const int oxs = ox>>4;
  1569. const int oys = oy>>4;
  1570. const int dxxs = dxx>>4;
  1571. const int dxys = dxy>>4;
  1572. const int dyxs = dyx>>4;
  1573. const int dyys = dyy>>4;
  1574. const uint16_t r4[4] = {r,r,r,r};
  1575. const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
  1576. const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
  1577. const uint64_t shift2 = 2*shift;
  1578. uint8_t edge_buf[(h+1)*stride];
  1579. int x, y;
  1580. const int dxw = (dxx-(1<<(16+shift)))*(w-1);
  1581. const int dyh = (dyy-(1<<(16+shift)))*(h-1);
  1582. const int dxh = dxy*(h-1);
  1583. const int dyw = dyx*(w-1);
  1584. if( // non-constant fullpel offset (3% of blocks)
  1585. ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
  1586. (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
  1587. // uses more than 16 bits of subpel mv (only at huge resolution)
  1588. || (dxx|dxy|dyx|dyy)&15 )
  1589. {
  1590. //FIXME could still use mmx for some of the rows
  1591. ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
  1592. return;
  1593. }
  1594. src += ix + iy*stride;
  1595. if( (unsigned)ix >= width-w ||
  1596. (unsigned)iy >= height-h )
  1597. {
  1598. emu_edge_fn(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
  1599. src = edge_buf;
  1600. }
  1601. __asm__ volatile(
  1602. "movd %0, %%mm6 \n\t"
  1603. "pxor %%mm7, %%mm7 \n\t"
  1604. "punpcklwd %%mm6, %%mm6 \n\t"
  1605. "punpcklwd %%mm6, %%mm6 \n\t"
  1606. :: "r"(1<<shift)
  1607. );
  1608. for(x=0; x<w; x+=4){
  1609. uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
  1610. oxs - dxys + dxxs*(x+1),
  1611. oxs - dxys + dxxs*(x+2),
  1612. oxs - dxys + dxxs*(x+3) };
  1613. uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
  1614. oys - dyys + dyxs*(x+1),
  1615. oys - dyys + dyxs*(x+2),
  1616. oys - dyys + dyxs*(x+3) };
  1617. for(y=0; y<h; y++){
  1618. __asm__ volatile(
  1619. "movq %0, %%mm4 \n\t"
  1620. "movq %1, %%mm5 \n\t"
  1621. "paddw %2, %%mm4 \n\t"
  1622. "paddw %3, %%mm5 \n\t"
  1623. "movq %%mm4, %0 \n\t"
  1624. "movq %%mm5, %1 \n\t"
  1625. "psrlw $12, %%mm4 \n\t"
  1626. "psrlw $12, %%mm5 \n\t"
  1627. : "+m"(*dx4), "+m"(*dy4)
  1628. : "m"(*dxy4), "m"(*dyy4)
  1629. );
  1630. __asm__ volatile(
  1631. "movq %%mm6, %%mm2 \n\t"
  1632. "movq %%mm6, %%mm1 \n\t"
  1633. "psubw %%mm4, %%mm2 \n\t"
  1634. "psubw %%mm5, %%mm1 \n\t"
  1635. "movq %%mm2, %%mm0 \n\t"
  1636. "movq %%mm4, %%mm3 \n\t"
  1637. "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
  1638. "pmullw %%mm5, %%mm3 \n\t" // dx*dy
  1639. "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
  1640. "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
  1641. "movd %4, %%mm5 \n\t"
  1642. "movd %3, %%mm4 \n\t"
  1643. "punpcklbw %%mm7, %%mm5 \n\t"
  1644. "punpcklbw %%mm7, %%mm4 \n\t"
  1645. "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
  1646. "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
  1647. "movd %2, %%mm5 \n\t"
  1648. "movd %1, %%mm4 \n\t"
  1649. "punpcklbw %%mm7, %%mm5 \n\t"
  1650. "punpcklbw %%mm7, %%mm4 \n\t"
  1651. "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
  1652. "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
  1653. "paddw %5, %%mm1 \n\t"
  1654. "paddw %%mm3, %%mm2 \n\t"
  1655. "paddw %%mm1, %%mm0 \n\t"
  1656. "paddw %%mm2, %%mm0 \n\t"
  1657. "psrlw %6, %%mm0 \n\t"
  1658. "packuswb %%mm0, %%mm0 \n\t"
  1659. "movd %%mm0, %0 \n\t"
  1660. : "=m"(dst[x+y*stride])
  1661. : "m"(src[0]), "m"(src[1]),
  1662. "m"(src[stride]), "m"(src[stride+1]),
  1663. "m"(*r4), "m"(shift2)
  1664. );
  1665. src += stride;
  1666. }
  1667. src += 4-h*stride;
  1668. }
  1669. }
  1670. #if HAVE_YASM
  1671. #if ARCH_X86_32
  1672. static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1673. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1674. {
  1675. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1676. width, height, &emulated_edge_mc_mmx);
  1677. }
  1678. #endif
  1679. static void gmc_sse(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1680. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1681. {
  1682. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1683. width, height, &emulated_edge_mc_sse);
  1684. }
  1685. #else
  1686. static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1687. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1688. {
  1689. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1690. width, height, &ff_emulated_edge_mc_8);
  1691. }
  1692. #endif
  1693. #define PREFETCH(name, op) \
  1694. static void name(void *mem, int stride, int h){\
  1695. const uint8_t *p= mem;\
  1696. do{\
  1697. __asm__ volatile(#op" %0" :: "m"(*p));\
  1698. p+= stride;\
  1699. }while(--h);\
  1700. }
  1701. PREFETCH(prefetch_mmx2, prefetcht0)
  1702. PREFETCH(prefetch_3dnow, prefetch)
  1703. #undef PREFETCH
  1704. #include "h264_qpel_mmx.c"
  1705. void ff_put_h264_chroma_mc8_mmx_rnd (uint8_t *dst, uint8_t *src,
  1706. int stride, int h, int x, int y);
  1707. void ff_avg_h264_chroma_mc8_mmx2_rnd (uint8_t *dst, uint8_t *src,
  1708. int stride, int h, int x, int y);
  1709. void ff_avg_h264_chroma_mc8_3dnow_rnd (uint8_t *dst, uint8_t *src,
  1710. int stride, int h, int x, int y);
  1711. void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  1712. int stride, int h, int x, int y);
  1713. void ff_avg_h264_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
  1714. int stride, int h, int x, int y);
  1715. void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
  1716. int stride, int h, int x, int y);
  1717. void ff_put_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
  1718. int stride, int h, int x, int y);
  1719. void ff_avg_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
  1720. int stride, int h, int x, int y);
  1721. void ff_put_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
  1722. int stride, int h, int x, int y);
  1723. void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1724. int stride, int h, int x, int y);
  1725. void ff_avg_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
  1726. int stride, int h, int x, int y);
  1727. void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1728. int stride, int h, int x, int y);
  1729. #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
  1730. void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
  1731. (uint8_t *dst, uint8_t *src,\
  1732. int stride, int h, int x, int y);
  1733. CHROMA_MC(put, 2, 10, mmxext)
  1734. CHROMA_MC(avg, 2, 10, mmxext)
  1735. CHROMA_MC(put, 4, 10, mmxext)
  1736. CHROMA_MC(avg, 4, 10, mmxext)
  1737. CHROMA_MC(put, 8, 10, sse2)
  1738. CHROMA_MC(avg, 8, 10, sse2)
  1739. CHROMA_MC(put, 8, 10, avx)
  1740. CHROMA_MC(avg, 8, 10, avx)
  1741. /* CAVS specific */
  1742. void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1743. put_pixels8_mmx(dst, src, stride, 8);
  1744. }
  1745. void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1746. avg_pixels8_mmx(dst, src, stride, 8);
  1747. }
  1748. void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1749. put_pixels16_mmx(dst, src, stride, 16);
  1750. }
  1751. void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1752. avg_pixels16_mmx(dst, src, stride, 16);
  1753. }
  1754. /* VC1 specific */
  1755. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  1756. put_pixels8_mmx(dst, src, stride, 8);
  1757. }
  1758. void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  1759. avg_pixels8_mmx2(dst, src, stride, 8);
  1760. }
  1761. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  1762. converted */
  1763. #if CONFIG_GPL
  1764. static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1765. {
  1766. ff_mmx_idct (block);
  1767. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1768. }
  1769. static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1770. {
  1771. ff_mmx_idct (block);
  1772. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1773. }
  1774. static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1775. {
  1776. ff_mmxext_idct (block);
  1777. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1778. }
  1779. static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1780. {
  1781. ff_mmxext_idct (block);
  1782. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1783. }
  1784. #endif
  1785. static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
  1786. {
  1787. ff_idct_xvid_mmx (block);
  1788. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1789. }
  1790. static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
  1791. {
  1792. ff_idct_xvid_mmx (block);
  1793. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1794. }
  1795. static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
  1796. {
  1797. ff_idct_xvid_mmx2 (block);
  1798. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1799. }
  1800. static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
  1801. {
  1802. ff_idct_xvid_mmx2 (block);
  1803. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1804. }
  1805. static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
  1806. {
  1807. int i;
  1808. __asm__ volatile("pxor %%mm7, %%mm7":);
  1809. for(i=0; i<blocksize; i+=2) {
  1810. __asm__ volatile(
  1811. "movq %0, %%mm0 \n\t"
  1812. "movq %1, %%mm1 \n\t"
  1813. "movq %%mm0, %%mm2 \n\t"
  1814. "movq %%mm1, %%mm3 \n\t"
  1815. "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
  1816. "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
  1817. "pslld $31, %%mm2 \n\t" // keep only the sign bit
  1818. "pxor %%mm2, %%mm1 \n\t"
  1819. "movq %%mm3, %%mm4 \n\t"
  1820. "pand %%mm1, %%mm3 \n\t"
  1821. "pandn %%mm1, %%mm4 \n\t"
  1822. "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1823. "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1824. "movq %%mm3, %1 \n\t"
  1825. "movq %%mm0, %0 \n\t"
  1826. :"+m"(mag[i]), "+m"(ang[i])
  1827. ::"memory"
  1828. );
  1829. }
  1830. __asm__ volatile("femms");
  1831. }
  1832. static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
  1833. {
  1834. int i;
  1835. __asm__ volatile(
  1836. "movaps %0, %%xmm5 \n\t"
  1837. ::"m"(ff_pdw_80000000[0])
  1838. );
  1839. for(i=0; i<blocksize; i+=4) {
  1840. __asm__ volatile(
  1841. "movaps %0, %%xmm0 \n\t"
  1842. "movaps %1, %%xmm1 \n\t"
  1843. "xorps %%xmm2, %%xmm2 \n\t"
  1844. "xorps %%xmm3, %%xmm3 \n\t"
  1845. "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
  1846. "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
  1847. "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
  1848. "xorps %%xmm2, %%xmm1 \n\t"
  1849. "movaps %%xmm3, %%xmm4 \n\t"
  1850. "andps %%xmm1, %%xmm3 \n\t"
  1851. "andnps %%xmm1, %%xmm4 \n\t"
  1852. "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1853. "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1854. "movaps %%xmm3, %1 \n\t"
  1855. "movaps %%xmm0, %0 \n\t"
  1856. :"+m"(mag[i]), "+m"(ang[i])
  1857. ::"memory"
  1858. );
  1859. }
  1860. }
  1861. #define IF1(x) x
  1862. #define IF0(x)
  1863. #define MIX5(mono,stereo)\
  1864. __asm__ volatile(\
  1865. "movss 0(%2), %%xmm5 \n"\
  1866. "movss 8(%2), %%xmm6 \n"\
  1867. "movss 24(%2), %%xmm7 \n"\
  1868. "shufps $0, %%xmm5, %%xmm5 \n"\
  1869. "shufps $0, %%xmm6, %%xmm6 \n"\
  1870. "shufps $0, %%xmm7, %%xmm7 \n"\
  1871. "1: \n"\
  1872. "movaps (%0,%1), %%xmm0 \n"\
  1873. "movaps 0x400(%0,%1), %%xmm1 \n"\
  1874. "movaps 0x800(%0,%1), %%xmm2 \n"\
  1875. "movaps 0xc00(%0,%1), %%xmm3 \n"\
  1876. "movaps 0x1000(%0,%1), %%xmm4 \n"\
  1877. "mulps %%xmm5, %%xmm0 \n"\
  1878. "mulps %%xmm6, %%xmm1 \n"\
  1879. "mulps %%xmm5, %%xmm2 \n"\
  1880. "mulps %%xmm7, %%xmm3 \n"\
  1881. "mulps %%xmm7, %%xmm4 \n"\
  1882. stereo("addps %%xmm1, %%xmm0 \n")\
  1883. "addps %%xmm1, %%xmm2 \n"\
  1884. "addps %%xmm3, %%xmm0 \n"\
  1885. "addps %%xmm4, %%xmm2 \n"\
  1886. mono("addps %%xmm2, %%xmm0 \n")\
  1887. "movaps %%xmm0, (%0,%1) \n"\
  1888. stereo("movaps %%xmm2, 0x400(%0,%1) \n")\
  1889. "add $16, %0 \n"\
  1890. "jl 1b \n"\
  1891. :"+&r"(i)\
  1892. :"r"(samples[0]+len), "r"(matrix)\
  1893. :XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
  1894. "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\
  1895. "memory"\
  1896. );
  1897. #define MIX_MISC(stereo)\
  1898. __asm__ volatile(\
  1899. "1: \n"\
  1900. "movaps (%3,%0), %%xmm0 \n"\
  1901. stereo("movaps %%xmm0, %%xmm1 \n")\
  1902. "mulps %%xmm4, %%xmm0 \n"\
  1903. stereo("mulps %%xmm5, %%xmm1 \n")\
  1904. "lea 1024(%3,%0), %1 \n"\
  1905. "mov %5, %2 \n"\
  1906. "2: \n"\
  1907. "movaps (%1), %%xmm2 \n"\
  1908. stereo("movaps %%xmm2, %%xmm3 \n")\
  1909. "mulps (%4,%2), %%xmm2 \n"\
  1910. stereo("mulps 16(%4,%2), %%xmm3 \n")\
  1911. "addps %%xmm2, %%xmm0 \n"\
  1912. stereo("addps %%xmm3, %%xmm1 \n")\
  1913. "add $1024, %1 \n"\
  1914. "add $32, %2 \n"\
  1915. "jl 2b \n"\
  1916. "movaps %%xmm0, (%3,%0) \n"\
  1917. stereo("movaps %%xmm1, 1024(%3,%0) \n")\
  1918. "add $16, %0 \n"\
  1919. "jl 1b \n"\
  1920. :"+&r"(i), "=&r"(j), "=&r"(k)\
  1921. :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
  1922. :"memory"\
  1923. );
  1924. static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
  1925. {
  1926. int (*matrix_cmp)[2] = (int(*)[2])matrix;
  1927. intptr_t i,j,k;
  1928. i = -len*sizeof(float);
  1929. if(in_ch == 5 && out_ch == 2 && !(matrix_cmp[0][1]|matrix_cmp[2][0]|matrix_cmp[3][1]|matrix_cmp[4][0]|(matrix_cmp[1][0]^matrix_cmp[1][1])|(matrix_cmp[0][0]^matrix_cmp[2][1]))) {
  1930. MIX5(IF0,IF1);
  1931. } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
  1932. MIX5(IF1,IF0);
  1933. } else {
  1934. DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
  1935. j = 2*in_ch*sizeof(float);
  1936. __asm__ volatile(
  1937. "1: \n"
  1938. "sub $8, %0 \n"
  1939. "movss (%2,%0), %%xmm4 \n"
  1940. "movss 4(%2,%0), %%xmm5 \n"
  1941. "shufps $0, %%xmm4, %%xmm4 \n"
  1942. "shufps $0, %%xmm5, %%xmm5 \n"
  1943. "movaps %%xmm4, (%1,%0,4) \n"
  1944. "movaps %%xmm5, 16(%1,%0,4) \n"
  1945. "jg 1b \n"
  1946. :"+&r"(j)
  1947. :"r"(matrix_simd), "r"(matrix)
  1948. :"memory"
  1949. );
  1950. if(out_ch == 2) {
  1951. MIX_MISC(IF1);
  1952. } else {
  1953. MIX_MISC(IF0);
  1954. }
  1955. }
  1956. }
  1957. static void vector_fmul_3dnow(float *dst, const float *src0, const float *src1, int len){
  1958. x86_reg i = (len-4)*4;
  1959. __asm__ volatile(
  1960. "1: \n\t"
  1961. "movq (%2,%0), %%mm0 \n\t"
  1962. "movq 8(%2,%0), %%mm1 \n\t"
  1963. "pfmul (%3,%0), %%mm0 \n\t"
  1964. "pfmul 8(%3,%0), %%mm1 \n\t"
  1965. "movq %%mm0, (%1,%0) \n\t"
  1966. "movq %%mm1, 8(%1,%0) \n\t"
  1967. "sub $16, %0 \n\t"
  1968. "jge 1b \n\t"
  1969. "femms \n\t"
  1970. :"+r"(i)
  1971. :"r"(dst), "r"(src0), "r"(src1)
  1972. :"memory"
  1973. );
  1974. }
  1975. static void vector_fmul_sse(float *dst, const float *src0, const float *src1, int len){
  1976. x86_reg i = (len-8)*4;
  1977. __asm__ volatile(
  1978. "1: \n\t"
  1979. "movaps (%2,%0), %%xmm0 \n\t"
  1980. "movaps 16(%2,%0), %%xmm1 \n\t"
  1981. "mulps (%3,%0), %%xmm0 \n\t"
  1982. "mulps 16(%3,%0), %%xmm1 \n\t"
  1983. "movaps %%xmm0, (%1,%0) \n\t"
  1984. "movaps %%xmm1, 16(%1,%0) \n\t"
  1985. "sub $32, %0 \n\t"
  1986. "jge 1b \n\t"
  1987. :"+r"(i)
  1988. :"r"(dst), "r"(src0), "r"(src1)
  1989. :"memory"
  1990. );
  1991. }
  1992. static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
  1993. x86_reg i = len*4-16;
  1994. __asm__ volatile(
  1995. "1: \n\t"
  1996. "pswapd 8(%1), %%mm0 \n\t"
  1997. "pswapd (%1), %%mm1 \n\t"
  1998. "pfmul (%3,%0), %%mm0 \n\t"
  1999. "pfmul 8(%3,%0), %%mm1 \n\t"
  2000. "movq %%mm0, (%2,%0) \n\t"
  2001. "movq %%mm1, 8(%2,%0) \n\t"
  2002. "add $16, %1 \n\t"
  2003. "sub $16, %0 \n\t"
  2004. "jge 1b \n\t"
  2005. :"+r"(i), "+r"(src1)
  2006. :"r"(dst), "r"(src0)
  2007. );
  2008. __asm__ volatile("femms");
  2009. }
  2010. static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
  2011. x86_reg i = len*4-32;
  2012. __asm__ volatile(
  2013. "1: \n\t"
  2014. "movaps 16(%1), %%xmm0 \n\t"
  2015. "movaps (%1), %%xmm1 \n\t"
  2016. "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
  2017. "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
  2018. "mulps (%3,%0), %%xmm0 \n\t"
  2019. "mulps 16(%3,%0), %%xmm1 \n\t"
  2020. "movaps %%xmm0, (%2,%0) \n\t"
  2021. "movaps %%xmm1, 16(%2,%0) \n\t"
  2022. "add $32, %1 \n\t"
  2023. "sub $32, %0 \n\t"
  2024. "jge 1b \n\t"
  2025. :"+r"(i), "+r"(src1)
  2026. :"r"(dst), "r"(src0)
  2027. );
  2028. }
  2029. static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1,
  2030. const float *src2, int len){
  2031. x86_reg i = (len-4)*4;
  2032. __asm__ volatile(
  2033. "1: \n\t"
  2034. "movq (%2,%0), %%mm0 \n\t"
  2035. "movq 8(%2,%0), %%mm1 \n\t"
  2036. "pfmul (%3,%0), %%mm0 \n\t"
  2037. "pfmul 8(%3,%0), %%mm1 \n\t"
  2038. "pfadd (%4,%0), %%mm0 \n\t"
  2039. "pfadd 8(%4,%0), %%mm1 \n\t"
  2040. "movq %%mm0, (%1,%0) \n\t"
  2041. "movq %%mm1, 8(%1,%0) \n\t"
  2042. "sub $16, %0 \n\t"
  2043. "jge 1b \n\t"
  2044. :"+r"(i)
  2045. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2046. :"memory"
  2047. );
  2048. __asm__ volatile("femms");
  2049. }
  2050. static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
  2051. const float *src2, int len){
  2052. x86_reg i = (len-8)*4;
  2053. __asm__ volatile(
  2054. "1: \n\t"
  2055. "movaps (%2,%0), %%xmm0 \n\t"
  2056. "movaps 16(%2,%0), %%xmm1 \n\t"
  2057. "mulps (%3,%0), %%xmm0 \n\t"
  2058. "mulps 16(%3,%0), %%xmm1 \n\t"
  2059. "addps (%4,%0), %%xmm0 \n\t"
  2060. "addps 16(%4,%0), %%xmm1 \n\t"
  2061. "movaps %%xmm0, (%1,%0) \n\t"
  2062. "movaps %%xmm1, 16(%1,%0) \n\t"
  2063. "sub $32, %0 \n\t"
  2064. "jge 1b \n\t"
  2065. :"+r"(i)
  2066. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2067. :"memory"
  2068. );
  2069. }
  2070. #if HAVE_6REGS
  2071. static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
  2072. const float *win, int len){
  2073. x86_reg i = -len*4;
  2074. x86_reg j = len*4-8;
  2075. __asm__ volatile(
  2076. "1: \n"
  2077. "pswapd (%5,%1), %%mm1 \n"
  2078. "movq (%5,%0), %%mm0 \n"
  2079. "pswapd (%4,%1), %%mm5 \n"
  2080. "movq (%3,%0), %%mm4 \n"
  2081. "movq %%mm0, %%mm2 \n"
  2082. "movq %%mm1, %%mm3 \n"
  2083. "pfmul %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
  2084. "pfmul %%mm5, %%mm3 \n" // src1[ j]*win[len+j]
  2085. "pfmul %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
  2086. "pfmul %%mm5, %%mm0 \n" // src1[ j]*win[len+i]
  2087. "pfadd %%mm3, %%mm2 \n"
  2088. "pfsub %%mm0, %%mm1 \n"
  2089. "pswapd %%mm2, %%mm2 \n"
  2090. "movq %%mm1, (%2,%0) \n"
  2091. "movq %%mm2, (%2,%1) \n"
  2092. "sub $8, %1 \n"
  2093. "add $8, %0 \n"
  2094. "jl 1b \n"
  2095. "femms \n"
  2096. :"+r"(i), "+r"(j)
  2097. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2098. );
  2099. }
  2100. static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
  2101. const float *win, int len){
  2102. x86_reg i = -len*4;
  2103. x86_reg j = len*4-16;
  2104. __asm__ volatile(
  2105. "1: \n"
  2106. "movaps (%5,%1), %%xmm1 \n"
  2107. "movaps (%5,%0), %%xmm0 \n"
  2108. "movaps (%4,%1), %%xmm5 \n"
  2109. "movaps (%3,%0), %%xmm4 \n"
  2110. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  2111. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  2112. "movaps %%xmm0, %%xmm2 \n"
  2113. "movaps %%xmm1, %%xmm3 \n"
  2114. "mulps %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
  2115. "mulps %%xmm5, %%xmm3 \n" // src1[ j]*win[len+j]
  2116. "mulps %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
  2117. "mulps %%xmm5, %%xmm0 \n" // src1[ j]*win[len+i]
  2118. "addps %%xmm3, %%xmm2 \n"
  2119. "subps %%xmm0, %%xmm1 \n"
  2120. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  2121. "movaps %%xmm1, (%2,%0) \n"
  2122. "movaps %%xmm2, (%2,%1) \n"
  2123. "sub $16, %1 \n"
  2124. "add $16, %0 \n"
  2125. "jl 1b \n"
  2126. :"+r"(i), "+r"(j)
  2127. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2128. );
  2129. }
  2130. #endif /* HAVE_6REGS */
  2131. static void vector_clipf_sse(float *dst, const float *src, float min, float max,
  2132. int len)
  2133. {
  2134. x86_reg i = (len-16)*4;
  2135. __asm__ volatile(
  2136. "movss %3, %%xmm4 \n"
  2137. "movss %4, %%xmm5 \n"
  2138. "shufps $0, %%xmm4, %%xmm4 \n"
  2139. "shufps $0, %%xmm5, %%xmm5 \n"
  2140. "1: \n\t"
  2141. "movaps (%2,%0), %%xmm0 \n\t" // 3/1 on intel
  2142. "movaps 16(%2,%0), %%xmm1 \n\t"
  2143. "movaps 32(%2,%0), %%xmm2 \n\t"
  2144. "movaps 48(%2,%0), %%xmm3 \n\t"
  2145. "maxps %%xmm4, %%xmm0 \n\t"
  2146. "maxps %%xmm4, %%xmm1 \n\t"
  2147. "maxps %%xmm4, %%xmm2 \n\t"
  2148. "maxps %%xmm4, %%xmm3 \n\t"
  2149. "minps %%xmm5, %%xmm0 \n\t"
  2150. "minps %%xmm5, %%xmm1 \n\t"
  2151. "minps %%xmm5, %%xmm2 \n\t"
  2152. "minps %%xmm5, %%xmm3 \n\t"
  2153. "movaps %%xmm0, (%1,%0) \n\t"
  2154. "movaps %%xmm1, 16(%1,%0) \n\t"
  2155. "movaps %%xmm2, 32(%1,%0) \n\t"
  2156. "movaps %%xmm3, 48(%1,%0) \n\t"
  2157. "sub $64, %0 \n\t"
  2158. "jge 1b \n\t"
  2159. :"+&r"(i)
  2160. :"r"(dst), "r"(src), "m"(min), "m"(max)
  2161. :"memory"
  2162. );
  2163. }
  2164. void ff_vp3_idct_mmx(int16_t *input_data);
  2165. void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
  2166. void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
  2167. void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block);
  2168. void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
  2169. void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
  2170. void ff_vp3_idct_sse2(int16_t *input_data);
  2171. void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
  2172. void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
  2173. int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2, int order, int shift);
  2174. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2, int order, int shift);
  2175. int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2176. int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2177. int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2178. void ff_apply_window_int16_mmxext (int16_t *output, const int16_t *input,
  2179. const int16_t *window, unsigned int len);
  2180. void ff_apply_window_int16_mmxext_ba (int16_t *output, const int16_t *input,
  2181. const int16_t *window, unsigned int len);
  2182. void ff_apply_window_int16_sse2 (int16_t *output, const int16_t *input,
  2183. const int16_t *window, unsigned int len);
  2184. void ff_apply_window_int16_sse2_ba (int16_t *output, const int16_t *input,
  2185. const int16_t *window, unsigned int len);
  2186. void ff_apply_window_int16_ssse3 (int16_t *output, const int16_t *input,
  2187. const int16_t *window, unsigned int len);
  2188. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  2189. const int16_t *window, unsigned int len);
  2190. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  2191. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  2192. void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
  2193. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left);
  2194. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left);
  2195. float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
  2196. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src, int32_t min,
  2197. int32_t max, unsigned int len);
  2198. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src, int32_t min,
  2199. int32_t max, unsigned int len);
  2200. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src, int32_t min,
  2201. int32_t max, unsigned int len);
  2202. void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src, int32_t min,
  2203. int32_t max, unsigned int len);
  2204. extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0,
  2205. const float *src1, int len);
  2206. extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
  2207. const float *src1, int len);
  2208. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  2209. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  2210. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  2211. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  2212. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  2213. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  2214. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  2215. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  2216. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  2217. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  2218. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  2219. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  2220. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  2221. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  2222. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  2223. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  2224. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU
  2225. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  2226. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  2227. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  2228. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  2229. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
  2230. #define H264_QPEL_FUNCS(x, y, CPU) \
  2231. c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU; \
  2232. c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU; \
  2233. c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU; \
  2234. c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU
  2235. #define H264_QPEL_FUNCS_10(x, y, CPU) \
  2236. c->put_h264_qpel_pixels_tab[0][x+y*4] = ff_put_h264_qpel16_mc##x##y##_10_##CPU; \
  2237. c->put_h264_qpel_pixels_tab[1][x+y*4] = ff_put_h264_qpel8_mc##x##y##_10_##CPU; \
  2238. c->avg_h264_qpel_pixels_tab[0][x+y*4] = ff_avg_h264_qpel16_mc##x##y##_10_##CPU; \
  2239. c->avg_h264_qpel_pixels_tab[1][x+y*4] = ff_avg_h264_qpel8_mc##x##y##_10_##CPU;
  2240. static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  2241. {
  2242. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2243. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  2244. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  2245. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  2246. if (!high_bit_depth) {
  2247. c->clear_block = clear_block_mmx;
  2248. c->clear_blocks = clear_blocks_mmx;
  2249. c->draw_edges = draw_edges_mmx;
  2250. SET_HPEL_FUNCS(put, 0, 16, mmx);
  2251. SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
  2252. SET_HPEL_FUNCS(avg, 0, 16, mmx);
  2253. SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
  2254. SET_HPEL_FUNCS(put, 1, 8, mmx);
  2255. SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
  2256. SET_HPEL_FUNCS(avg, 1, 8, mmx);
  2257. SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
  2258. }
  2259. #if ARCH_X86_32 || !HAVE_YASM
  2260. c->gmc= gmc_mmx;
  2261. #endif
  2262. #if ARCH_X86_32 && HAVE_YASM
  2263. if (!high_bit_depth)
  2264. c->emulated_edge_mc = emulated_edge_mc_mmx;
  2265. #endif
  2266. c->add_bytes = add_bytes_mmx;
  2267. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2268. c->h263_v_loop_filter = h263_v_loop_filter_mmx;
  2269. c->h263_h_loop_filter = h263_h_loop_filter_mmx;
  2270. }
  2271. #if HAVE_YASM
  2272. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2273. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_mmx_rnd;
  2274. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
  2275. }
  2276. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  2277. #endif
  2278. }
  2279. static void dsputil_init_mmx2(DSPContext *c, AVCodecContext *avctx,
  2280. int mm_flags)
  2281. {
  2282. const int bit_depth = avctx->bits_per_raw_sample;
  2283. const int high_bit_depth = bit_depth > 8;
  2284. c->prefetch = prefetch_mmx2;
  2285. if (!high_bit_depth) {
  2286. c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
  2287. c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
  2288. c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
  2289. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
  2290. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
  2291. c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
  2292. c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
  2293. c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
  2294. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
  2295. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
  2296. }
  2297. if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
  2298. if (!high_bit_depth) {
  2299. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
  2300. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
  2301. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
  2302. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
  2303. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
  2304. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
  2305. }
  2306. if (CONFIG_VP3_DECODER && HAVE_YASM) {
  2307. c->vp3_v_loop_filter = ff_vp3_v_loop_filter_mmx2;
  2308. c->vp3_h_loop_filter = ff_vp3_h_loop_filter_mmx2;
  2309. }
  2310. }
  2311. if (CONFIG_VP3_DECODER && HAVE_YASM) {
  2312. c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
  2313. }
  2314. if (CONFIG_VP3_DECODER
  2315. && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
  2316. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
  2317. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
  2318. }
  2319. SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2, );
  2320. SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2, );
  2321. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2, );
  2322. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2, );
  2323. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2, );
  2324. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2, );
  2325. if (!high_bit_depth) {
  2326. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2, );
  2327. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2, );
  2328. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2, );
  2329. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2, );
  2330. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2, );
  2331. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2, );
  2332. } else if (bit_depth == 10) {
  2333. #if HAVE_YASM
  2334. #if !ARCH_X86_64
  2335. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
  2336. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
  2337. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
  2338. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
  2339. #endif
  2340. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
  2341. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
  2342. #endif
  2343. }
  2344. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2, );
  2345. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2, );
  2346. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2, );
  2347. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2, );
  2348. #if HAVE_YASM
  2349. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2350. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_mmx2_rnd;
  2351. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmx2;
  2352. c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmx2;
  2353. c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmx2;
  2354. }
  2355. if (bit_depth == 10 && CONFIG_H264CHROMA) {
  2356. c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
  2357. c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
  2358. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
  2359. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
  2360. }
  2361. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
  2362. c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
  2363. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
  2364. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2365. c->apply_window_int16 = ff_apply_window_int16_mmxext_ba;
  2366. } else {
  2367. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  2368. }
  2369. #endif
  2370. }
  2371. static void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
  2372. int mm_flags)
  2373. {
  2374. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2375. c->prefetch = prefetch_3dnow;
  2376. if (!high_bit_depth) {
  2377. c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
  2378. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  2379. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  2380. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  2381. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  2382. c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
  2383. c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
  2384. c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
  2385. c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
  2386. c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
  2387. if (!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2388. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  2389. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  2390. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
  2391. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
  2392. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  2393. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
  2394. }
  2395. }
  2396. if (CONFIG_VP3_DECODER
  2397. && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
  2398. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
  2399. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
  2400. }
  2401. SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow, );
  2402. SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow, );
  2403. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow, );
  2404. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow, );
  2405. SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow, );
  2406. SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow, );
  2407. if (!high_bit_depth) {
  2408. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow, );
  2409. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow, );
  2410. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow, );
  2411. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow, );
  2412. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow, );
  2413. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow, );
  2414. }
  2415. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow, );
  2416. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow, );
  2417. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow, );
  2418. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow, );
  2419. #if HAVE_YASM
  2420. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2421. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_3dnow_rnd;
  2422. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
  2423. }
  2424. #endif
  2425. c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
  2426. c->vector_fmul = vector_fmul_3dnow;
  2427. c->vector_fmul_add = vector_fmul_add_3dnow;
  2428. #if HAVE_7REGS
  2429. c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
  2430. #endif
  2431. }
  2432. static void dsputil_init_3dnow2(DSPContext *c, AVCodecContext *avctx,
  2433. int mm_flags)
  2434. {
  2435. c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
  2436. #if HAVE_6REGS
  2437. c->vector_fmul_window = vector_fmul_window_3dnow2;
  2438. #endif
  2439. }
  2440. static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  2441. {
  2442. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2443. if (!high_bit_depth) {
  2444. if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){
  2445. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  2446. c->clear_block = clear_block_sse;
  2447. c->clear_blocks = clear_blocks_sse;
  2448. }
  2449. }
  2450. c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
  2451. c->ac3_downmix = ac3_downmix_sse;
  2452. c->vector_fmul = vector_fmul_sse;
  2453. c->vector_fmul_reverse = vector_fmul_reverse_sse;
  2454. if (!(mm_flags & AV_CPU_FLAG_3DNOW))
  2455. c->vector_fmul_add = vector_fmul_add_sse;
  2456. #if HAVE_6REGS
  2457. c->vector_fmul_window = vector_fmul_window_sse;
  2458. #endif
  2459. c->vector_clipf = vector_clipf_sse;
  2460. #if HAVE_YASM
  2461. c->scalarproduct_float = ff_scalarproduct_float_sse;
  2462. c->butterflies_float_interleave = ff_butterflies_float_interleave_sse;
  2463. if (!high_bit_depth)
  2464. c->emulated_edge_mc = emulated_edge_mc_sse;
  2465. c->gmc = gmc_sse;
  2466. #endif
  2467. }
  2468. static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  2469. int mm_flags)
  2470. {
  2471. const int bit_depth = avctx->bits_per_raw_sample;
  2472. const int high_bit_depth = bit_depth > 8;
  2473. if (mm_flags & AV_CPU_FLAG_3DNOW) {
  2474. // these functions are slower than mmx on AMD, but faster on Intel
  2475. if (!high_bit_depth) {
  2476. c->put_pixels_tab[0][0] = put_pixels16_sse2;
  2477. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2;
  2478. c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
  2479. H264_QPEL_FUNCS(0, 0, sse2);
  2480. }
  2481. }
  2482. if (!high_bit_depth) {
  2483. H264_QPEL_FUNCS(0, 1, sse2);
  2484. H264_QPEL_FUNCS(0, 2, sse2);
  2485. H264_QPEL_FUNCS(0, 3, sse2);
  2486. H264_QPEL_FUNCS(1, 1, sse2);
  2487. H264_QPEL_FUNCS(1, 2, sse2);
  2488. H264_QPEL_FUNCS(1, 3, sse2);
  2489. H264_QPEL_FUNCS(2, 1, sse2);
  2490. H264_QPEL_FUNCS(2, 2, sse2);
  2491. H264_QPEL_FUNCS(2, 3, sse2);
  2492. H264_QPEL_FUNCS(3, 1, sse2);
  2493. H264_QPEL_FUNCS(3, 2, sse2);
  2494. H264_QPEL_FUNCS(3, 3, sse2);
  2495. }
  2496. #if HAVE_YASM
  2497. if (bit_depth == 10) {
  2498. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
  2499. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
  2500. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
  2501. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
  2502. H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
  2503. H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
  2504. H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
  2505. if (CONFIG_H264CHROMA) {
  2506. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
  2507. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
  2508. }
  2509. }
  2510. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  2511. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  2512. if (mm_flags & AV_CPU_FLAG_ATOM) {
  2513. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  2514. } else {
  2515. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  2516. }
  2517. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2518. c->apply_window_int16 = ff_apply_window_int16_sse2_ba;
  2519. } else if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  2520. c->apply_window_int16 = ff_apply_window_int16_sse2;
  2521. }
  2522. c->bswap_buf = ff_bswap32_buf_sse2;
  2523. #endif
  2524. }
  2525. static void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  2526. int mm_flags)
  2527. {
  2528. #if HAVE_SSSE3
  2529. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2530. const int bit_depth = avctx->bits_per_raw_sample;
  2531. if (!high_bit_depth) {
  2532. H264_QPEL_FUNCS(1, 0, ssse3);
  2533. H264_QPEL_FUNCS(1, 1, ssse3);
  2534. H264_QPEL_FUNCS(1, 2, ssse3);
  2535. H264_QPEL_FUNCS(1, 3, ssse3);
  2536. H264_QPEL_FUNCS(2, 0, ssse3);
  2537. H264_QPEL_FUNCS(2, 1, ssse3);
  2538. H264_QPEL_FUNCS(2, 2, ssse3);
  2539. H264_QPEL_FUNCS(2, 3, ssse3);
  2540. H264_QPEL_FUNCS(3, 0, ssse3);
  2541. H264_QPEL_FUNCS(3, 1, ssse3);
  2542. H264_QPEL_FUNCS(3, 2, ssse3);
  2543. H264_QPEL_FUNCS(3, 3, ssse3);
  2544. }
  2545. #if HAVE_YASM
  2546. else if (bit_depth == 10) {
  2547. H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
  2548. H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
  2549. H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
  2550. }
  2551. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2552. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_ssse3_rnd;
  2553. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_ssse3_rnd;
  2554. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
  2555. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
  2556. }
  2557. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  2558. if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
  2559. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  2560. if (mm_flags & AV_CPU_FLAG_ATOM) {
  2561. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  2562. } else {
  2563. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  2564. }
  2565. if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) { // cachesplit
  2566. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  2567. }
  2568. c->bswap_buf = ff_bswap32_buf_ssse3;
  2569. #endif
  2570. #endif
  2571. }
  2572. static void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  2573. int mm_flags)
  2574. {
  2575. #if HAVE_YASM
  2576. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  2577. #endif
  2578. }
  2579. static void dsputil_init_avx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  2580. {
  2581. #if HAVE_AVX && HAVE_YASM
  2582. const int bit_depth = avctx->bits_per_raw_sample;
  2583. if (bit_depth == 10) {
  2584. // AVX implies !cache64.
  2585. // TODO: Port cache(32|64) detection from x264.
  2586. H264_QPEL_FUNCS_10(1, 0, sse2);
  2587. H264_QPEL_FUNCS_10(2, 0, sse2);
  2588. H264_QPEL_FUNCS_10(3, 0, sse2);
  2589. if (CONFIG_H264CHROMA) {
  2590. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
  2591. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
  2592. }
  2593. }
  2594. c->butterflies_float_interleave = ff_butterflies_float_interleave_avx;
  2595. #endif
  2596. }
  2597. void ff_dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
  2598. {
  2599. int mm_flags = av_get_cpu_flags();
  2600. if (avctx->dsp_mask) {
  2601. if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
  2602. mm_flags |= (avctx->dsp_mask & 0xffff);
  2603. else
  2604. mm_flags &= ~(avctx->dsp_mask & 0xffff);
  2605. }
  2606. #if 0
  2607. av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
  2608. if (mm_flags & AV_CPU_FLAG_MMX)
  2609. av_log(avctx, AV_LOG_INFO, " mmx");
  2610. if (mm_flags & AV_CPU_FLAG_MMX2)
  2611. av_log(avctx, AV_LOG_INFO, " mmx2");
  2612. if (mm_flags & AV_CPU_FLAG_3DNOW)
  2613. av_log(avctx, AV_LOG_INFO, " 3dnow");
  2614. if (mm_flags & AV_CPU_FLAG_SSE)
  2615. av_log(avctx, AV_LOG_INFO, " sse");
  2616. if (mm_flags & AV_CPU_FLAG_SSE2)
  2617. av_log(avctx, AV_LOG_INFO, " sse2");
  2618. av_log(avctx, AV_LOG_INFO, "\n");
  2619. #endif
  2620. if (mm_flags & AV_CPU_FLAG_MMX) {
  2621. const int idct_algo= avctx->idct_algo;
  2622. if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
  2623. if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
  2624. c->idct_put= ff_simple_idct_put_mmx;
  2625. c->idct_add= ff_simple_idct_add_mmx;
  2626. c->idct = ff_simple_idct_mmx;
  2627. c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
  2628. #if CONFIG_GPL
  2629. }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
  2630. if(mm_flags & AV_CPU_FLAG_MMX2){
  2631. c->idct_put= ff_libmpeg2mmx2_idct_put;
  2632. c->idct_add= ff_libmpeg2mmx2_idct_add;
  2633. c->idct = ff_mmxext_idct;
  2634. }else{
  2635. c->idct_put= ff_libmpeg2mmx_idct_put;
  2636. c->idct_add= ff_libmpeg2mmx_idct_add;
  2637. c->idct = ff_mmx_idct;
  2638. }
  2639. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2640. #endif
  2641. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
  2642. idct_algo==FF_IDCT_VP3 && HAVE_YASM){
  2643. if(mm_flags & AV_CPU_FLAG_SSE2){
  2644. c->idct_put= ff_vp3_idct_put_sse2;
  2645. c->idct_add= ff_vp3_idct_add_sse2;
  2646. c->idct = ff_vp3_idct_sse2;
  2647. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2648. }else{
  2649. c->idct_put= ff_vp3_idct_put_mmx;
  2650. c->idct_add= ff_vp3_idct_add_mmx;
  2651. c->idct = ff_vp3_idct_mmx;
  2652. c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
  2653. }
  2654. }else if(idct_algo==FF_IDCT_CAVS){
  2655. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2656. }else if(idct_algo==FF_IDCT_XVIDMMX){
  2657. if(mm_flags & AV_CPU_FLAG_SSE2){
  2658. c->idct_put= ff_idct_xvid_sse2_put;
  2659. c->idct_add= ff_idct_xvid_sse2_add;
  2660. c->idct = ff_idct_xvid_sse2;
  2661. c->idct_permutation_type= FF_SSE2_IDCT_PERM;
  2662. }else if(mm_flags & AV_CPU_FLAG_MMX2){
  2663. c->idct_put= ff_idct_xvid_mmx2_put;
  2664. c->idct_add= ff_idct_xvid_mmx2_add;
  2665. c->idct = ff_idct_xvid_mmx2;
  2666. }else{
  2667. c->idct_put= ff_idct_xvid_mmx_put;
  2668. c->idct_add= ff_idct_xvid_mmx_add;
  2669. c->idct = ff_idct_xvid_mmx;
  2670. }
  2671. }
  2672. }
  2673. dsputil_init_mmx(c, avctx, mm_flags);
  2674. }
  2675. if (mm_flags & AV_CPU_FLAG_MMX2)
  2676. dsputil_init_mmx2(c, avctx, mm_flags);
  2677. if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW))
  2678. dsputil_init_3dnow(c, avctx, mm_flags);
  2679. if (HAVE_AMD3DNOWEXT && (mm_flags & AV_CPU_FLAG_3DNOWEXT))
  2680. dsputil_init_3dnow2(c, avctx, mm_flags);
  2681. if (HAVE_SSE && (mm_flags & AV_CPU_FLAG_SSE))
  2682. dsputil_init_sse(c, avctx, mm_flags);
  2683. if (mm_flags & AV_CPU_FLAG_SSE2)
  2684. dsputil_init_sse2(c, avctx, mm_flags);
  2685. if (mm_flags & AV_CPU_FLAG_SSSE3)
  2686. dsputil_init_ssse3(c, avctx, mm_flags);
  2687. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE)
  2688. dsputil_init_sse4(c, avctx, mm_flags);
  2689. if (mm_flags & AV_CPU_FLAG_AVX)
  2690. dsputil_init_avx(c, avctx, mm_flags);
  2691. if (CONFIG_ENCODERS)
  2692. ff_dsputilenc_init_mmx(c, avctx);
  2693. }