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.

2554 lines
129KB

  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. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "libavutil/cpu.h"
  25. #include "libavutil/x86/asm.h"
  26. #include "libavcodec/dsputil.h"
  27. #include "libavcodec/h264dsp.h"
  28. #include "libavcodec/mpegvideo.h"
  29. #include "libavcodec/simple_idct.h"
  30. #include "dsputil_mmx.h"
  31. #include "idct_xvid.h"
  32. //#undef NDEBUG
  33. //#include <assert.h>
  34. /* pixel operations */
  35. DECLARE_ALIGNED(8, const uint64_t, ff_bone) = 0x0101010101010101ULL;
  36. DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
  37. DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
  38. { 0x8000000080000000ULL, 0x8000000080000000ULL };
  39. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1) = { 0x0001000100010001ULL, 0x0001000100010001ULL };
  40. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2) = { 0x0002000200020002ULL, 0x0002000200020002ULL };
  41. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3) = { 0x0003000300030003ULL, 0x0003000300030003ULL };
  42. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4) = { 0x0004000400040004ULL, 0x0004000400040004ULL };
  43. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5) = { 0x0005000500050005ULL, 0x0005000500050005ULL };
  44. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_8) = { 0x0008000800080008ULL, 0x0008000800080008ULL };
  45. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_9) = { 0x0009000900090009ULL, 0x0009000900090009ULL };
  46. DECLARE_ALIGNED(8, const uint64_t, ff_pw_15) = 0x000F000F000F000FULL;
  47. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_16) = { 0x0010001000100010ULL, 0x0010001000100010ULL };
  48. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_17) = { 0x0011001100110011ULL, 0x0011001100110011ULL };
  49. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_18) = { 0x0012001200120012ULL, 0x0012001200120012ULL };
  50. DECLARE_ALIGNED(8, const uint64_t, ff_pw_20) = 0x0014001400140014ULL;
  51. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_27) = { 0x001B001B001B001BULL, 0x001B001B001B001BULL };
  52. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_28) = { 0x001C001C001C001CULL, 0x001C001C001C001CULL };
  53. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_32) = { 0x0020002000200020ULL, 0x0020002000200020ULL };
  54. DECLARE_ALIGNED(8, const uint64_t, ff_pw_42) = 0x002A002A002A002AULL;
  55. DECLARE_ALIGNED(8, const uint64_t, ff_pw_53) = 0x0035003500350035ULL;
  56. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_63) = { 0x003F003F003F003FULL, 0x003F003F003F003FULL };
  57. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64) = { 0x0040004000400040ULL, 0x0040004000400040ULL };
  58. DECLARE_ALIGNED(8, const uint64_t, ff_pw_96) = 0x0060006000600060ULL;
  59. DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
  60. DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
  61. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = { 0x0200020002000200ULL, 0x0200020002000200ULL };
  62. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019) = { 0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL };
  63. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0) = { 0x0000000000000000ULL, 0x0000000000000000ULL };
  64. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1) = { 0x0101010101010101ULL, 0x0101010101010101ULL };
  65. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_3) = { 0x0303030303030303ULL, 0x0303030303030303ULL };
  66. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_4) = { 0x0404040404040404ULL, 0x0404040404040404ULL };
  67. DECLARE_ALIGNED(8, const uint64_t, ff_pb_7) = 0x0707070707070707ULL;
  68. DECLARE_ALIGNED(8, const uint64_t, ff_pb_1F) = 0x1F1F1F1F1F1F1F1FULL;
  69. DECLARE_ALIGNED(8, const uint64_t, ff_pb_3F) = 0x3F3F3F3F3F3F3F3FULL;
  70. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_80) = { 0x8080808080808080ULL, 0x8080808080808080ULL };
  71. DECLARE_ALIGNED(8, const uint64_t, ff_pb_81) = 0x8181818181818181ULL;
  72. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_A1) = { 0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL };
  73. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_F8) = { 0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL };
  74. DECLARE_ALIGNED(8, const uint64_t, ff_pb_FC) = 0xFCFCFCFCFCFCFCFCULL;
  75. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_FE) = { 0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL };
  76. DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
  77. DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
  78. #if HAVE_INLINE_ASM
  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_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_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. #define SKIP_FOR_3DNOW
  176. #include "dsputil_avg_template.c"
  177. #undef DEF
  178. #undef PAVGB
  179. #undef OP_AVG
  180. #undef SKIP_FOR_3DNOW
  181. /***********************************/
  182. /* MMXEXT specific */
  183. #define DEF(x) x ## _mmxext
  184. /* Introduced only in MMXEXT set */
  185. #define PAVGB "pavgb"
  186. #define OP_AVG PAVGB
  187. #include "dsputil_avg_template.c"
  188. #undef DEF
  189. #undef PAVGB
  190. #undef OP_AVG
  191. #define put_no_rnd_pixels16_mmx put_pixels16_mmx
  192. #define put_no_rnd_pixels8_mmx put_pixels8_mmx
  193. #define put_pixels16_mmxext put_pixels16_mmx
  194. #define put_pixels8_mmxext put_pixels8_mmx
  195. #define put_pixels4_mmxext put_pixels4_mmx
  196. #define put_no_rnd_pixels16_mmxext put_no_rnd_pixels16_mmx
  197. #define put_no_rnd_pixels8_mmxext put_no_rnd_pixels8_mmx
  198. /***********************************/
  199. /* standard MMX */
  200. void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
  201. int line_size)
  202. {
  203. const DCTELEM *p;
  204. uint8_t *pix;
  205. /* read the pixels */
  206. p = block;
  207. pix = pixels;
  208. /* unrolled loop */
  209. __asm__ volatile (
  210. "movq (%3), %%mm0 \n\t"
  211. "movq 8(%3), %%mm1 \n\t"
  212. "movq 16(%3), %%mm2 \n\t"
  213. "movq 24(%3), %%mm3 \n\t"
  214. "movq 32(%3), %%mm4 \n\t"
  215. "movq 40(%3), %%mm5 \n\t"
  216. "movq 48(%3), %%mm6 \n\t"
  217. "movq 56(%3), %%mm7 \n\t"
  218. "packuswb %%mm1, %%mm0 \n\t"
  219. "packuswb %%mm3, %%mm2 \n\t"
  220. "packuswb %%mm5, %%mm4 \n\t"
  221. "packuswb %%mm7, %%mm6 \n\t"
  222. "movq %%mm0, (%0) \n\t"
  223. "movq %%mm2, (%0, %1) \n\t"
  224. "movq %%mm4, (%0, %1, 2) \n\t"
  225. "movq %%mm6, (%0, %2) \n\t"
  226. :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3),
  227. "r"(p)
  228. : "memory");
  229. pix += line_size * 4;
  230. p += 32;
  231. // if here would be an exact copy of the code above
  232. // compiler would generate some very strange code
  233. // thus using "r"
  234. __asm__ volatile (
  235. "movq (%3), %%mm0 \n\t"
  236. "movq 8(%3), %%mm1 \n\t"
  237. "movq 16(%3), %%mm2 \n\t"
  238. "movq 24(%3), %%mm3 \n\t"
  239. "movq 32(%3), %%mm4 \n\t"
  240. "movq 40(%3), %%mm5 \n\t"
  241. "movq 48(%3), %%mm6 \n\t"
  242. "movq 56(%3), %%mm7 \n\t"
  243. "packuswb %%mm1, %%mm0 \n\t"
  244. "packuswb %%mm3, %%mm2 \n\t"
  245. "packuswb %%mm5, %%mm4 \n\t"
  246. "packuswb %%mm7, %%mm6 \n\t"
  247. "movq %%mm0, (%0) \n\t"
  248. "movq %%mm2, (%0, %1) \n\t"
  249. "movq %%mm4, (%0, %1, 2) \n\t"
  250. "movq %%mm6, (%0, %2) \n\t"
  251. :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3), "r"(p)
  252. : "memory");
  253. }
  254. #define put_signed_pixels_clamped_mmx_half(off) \
  255. "movq "#off"(%2), %%mm1 \n\t" \
  256. "movq 16 + "#off"(%2), %%mm2 \n\t" \
  257. "movq 32 + "#off"(%2), %%mm3 \n\t" \
  258. "movq 48 + "#off"(%2), %%mm4 \n\t" \
  259. "packsswb 8 + "#off"(%2), %%mm1 \n\t" \
  260. "packsswb 24 + "#off"(%2), %%mm2 \n\t" \
  261. "packsswb 40 + "#off"(%2), %%mm3 \n\t" \
  262. "packsswb 56 + "#off"(%2), %%mm4 \n\t" \
  263. "paddb %%mm0, %%mm1 \n\t" \
  264. "paddb %%mm0, %%mm2 \n\t" \
  265. "paddb %%mm0, %%mm3 \n\t" \
  266. "paddb %%mm0, %%mm4 \n\t" \
  267. "movq %%mm1, (%0) \n\t" \
  268. "movq %%mm2, (%0, %3) \n\t" \
  269. "movq %%mm3, (%0, %3, 2) \n\t" \
  270. "movq %%mm4, (%0, %1) \n\t"
  271. void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
  272. 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,
  287. int line_size)
  288. {
  289. const DCTELEM *p;
  290. uint8_t *pix;
  291. int i;
  292. /* read the pixels */
  293. p = block;
  294. pix = pixels;
  295. MOVQ_ZERO(mm7);
  296. i = 4;
  297. do {
  298. __asm__ volatile (
  299. "movq (%2), %%mm0 \n\t"
  300. "movq 8(%2), %%mm1 \n\t"
  301. "movq 16(%2), %%mm2 \n\t"
  302. "movq 24(%2), %%mm3 \n\t"
  303. "movq %0, %%mm4 \n\t"
  304. "movq %1, %%mm6 \n\t"
  305. "movq %%mm4, %%mm5 \n\t"
  306. "punpcklbw %%mm7, %%mm4 \n\t"
  307. "punpckhbw %%mm7, %%mm5 \n\t"
  308. "paddsw %%mm4, %%mm0 \n\t"
  309. "paddsw %%mm5, %%mm1 \n\t"
  310. "movq %%mm6, %%mm5 \n\t"
  311. "punpcklbw %%mm7, %%mm6 \n\t"
  312. "punpckhbw %%mm7, %%mm5 \n\t"
  313. "paddsw %%mm6, %%mm2 \n\t"
  314. "paddsw %%mm5, %%mm3 \n\t"
  315. "packuswb %%mm1, %%mm0 \n\t"
  316. "packuswb %%mm3, %%mm2 \n\t"
  317. "movq %%mm0, %0 \n\t"
  318. "movq %%mm2, %1 \n\t"
  319. : "+m"(*pix), "+m"(*(pix + line_size))
  320. : "r"(p)
  321. : "memory");
  322. pix += line_size * 2;
  323. p += 16;
  324. } while (--i);
  325. }
  326. static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
  327. int line_size, int h)
  328. {
  329. __asm__ volatile (
  330. "lea (%3, %3), %%"REG_a" \n\t"
  331. ".p2align 3 \n\t"
  332. "1: \n\t"
  333. "movq (%1 ), %%mm0 \n\t"
  334. "movq (%1, %3), %%mm1 \n\t"
  335. "movq %%mm0, (%2) \n\t"
  336. "movq %%mm1, (%2, %3) \n\t"
  337. "add %%"REG_a", %1 \n\t"
  338. "add %%"REG_a", %2 \n\t"
  339. "movq (%1 ), %%mm0 \n\t"
  340. "movq (%1, %3), %%mm1 \n\t"
  341. "movq %%mm0, (%2) \n\t"
  342. "movq %%mm1, (%2, %3) \n\t"
  343. "add %%"REG_a", %1 \n\t"
  344. "add %%"REG_a", %2 \n\t"
  345. "subl $4, %0 \n\t"
  346. "jnz 1b \n\t"
  347. : "+g"(h), "+r"(pixels), "+r"(block)
  348. : "r"((x86_reg)line_size)
  349. : "%"REG_a, "memory"
  350. );
  351. }
  352. static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
  353. int line_size, int h)
  354. {
  355. __asm__ volatile (
  356. "lea (%3, %3), %%"REG_a" \n\t"
  357. ".p2align 3 \n\t"
  358. "1: \n\t"
  359. "movq (%1 ), %%mm0 \n\t"
  360. "movq 8(%1 ), %%mm4 \n\t"
  361. "movq (%1, %3), %%mm1 \n\t"
  362. "movq 8(%1, %3), %%mm5 \n\t"
  363. "movq %%mm0, (%2) \n\t"
  364. "movq %%mm4, 8(%2) \n\t"
  365. "movq %%mm1, (%2, %3) \n\t"
  366. "movq %%mm5, 8(%2, %3) \n\t"
  367. "add %%"REG_a", %1 \n\t"
  368. "add %%"REG_a", %2 \n\t"
  369. "movq (%1 ), %%mm0 \n\t"
  370. "movq 8(%1 ), %%mm4 \n\t"
  371. "movq (%1, %3), %%mm1 \n\t"
  372. "movq 8(%1, %3), %%mm5 \n\t"
  373. "movq %%mm0, (%2) \n\t"
  374. "movq %%mm4, 8(%2) \n\t"
  375. "movq %%mm1, (%2, %3) \n\t"
  376. "movq %%mm5, 8(%2, %3) \n\t"
  377. "add %%"REG_a", %1 \n\t"
  378. "add %%"REG_a", %2 \n\t"
  379. "subl $4, %0 \n\t"
  380. "jnz 1b \n\t"
  381. : "+g"(h), "+r"(pixels), "+r"(block)
  382. : "r"((x86_reg)line_size)
  383. : "%"REG_a, "memory"
  384. );
  385. }
  386. #define CLEAR_BLOCKS(name, n) \
  387. static void name(DCTELEM *blocks) \
  388. { \
  389. __asm__ volatile ( \
  390. "pxor %%mm7, %%mm7 \n\t" \
  391. "mov %1, %%"REG_a" \n\t" \
  392. "1: \n\t" \
  393. "movq %%mm7, (%0, %%"REG_a") \n\t" \
  394. "movq %%mm7, 8(%0, %%"REG_a") \n\t" \
  395. "movq %%mm7, 16(%0, %%"REG_a") \n\t" \
  396. "movq %%mm7, 24(%0, %%"REG_a") \n\t" \
  397. "add $32, %%"REG_a" \n\t" \
  398. "js 1b \n\t" \
  399. :: "r"(((uint8_t *)blocks) + 128 * n), \
  400. "i"(-128 * n) \
  401. : "%"REG_a \
  402. ); \
  403. }
  404. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  405. CLEAR_BLOCKS(clear_block_mmx, 1)
  406. static void clear_block_sse(DCTELEM *block)
  407. {
  408. __asm__ volatile (
  409. "xorps %%xmm0, %%xmm0 \n"
  410. "movaps %%xmm0, (%0) \n"
  411. "movaps %%xmm0, 16(%0) \n"
  412. "movaps %%xmm0, 32(%0) \n"
  413. "movaps %%xmm0, 48(%0) \n"
  414. "movaps %%xmm0, 64(%0) \n"
  415. "movaps %%xmm0, 80(%0) \n"
  416. "movaps %%xmm0, 96(%0) \n"
  417. "movaps %%xmm0, 112(%0) \n"
  418. :: "r"(block)
  419. : "memory"
  420. );
  421. }
  422. static void clear_blocks_sse(DCTELEM *blocks)
  423. {
  424. __asm__ volatile (
  425. "xorps %%xmm0, %%xmm0 \n"
  426. "mov %1, %%"REG_a" \n"
  427. "1: \n"
  428. "movaps %%xmm0, (%0, %%"REG_a") \n"
  429. "movaps %%xmm0, 16(%0, %%"REG_a") \n"
  430. "movaps %%xmm0, 32(%0, %%"REG_a") \n"
  431. "movaps %%xmm0, 48(%0, %%"REG_a") \n"
  432. "movaps %%xmm0, 64(%0, %%"REG_a") \n"
  433. "movaps %%xmm0, 80(%0, %%"REG_a") \n"
  434. "movaps %%xmm0, 96(%0, %%"REG_a") \n"
  435. "movaps %%xmm0, 112(%0, %%"REG_a") \n"
  436. "add $128, %%"REG_a" \n"
  437. "js 1b \n"
  438. :: "r"(((uint8_t *)blocks) + 128 * 6),
  439. "i"(-128 * 6)
  440. : "%"REG_a
  441. );
  442. }
  443. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w)
  444. {
  445. x86_reg i = 0;
  446. __asm__ volatile (
  447. "jmp 2f \n\t"
  448. "1: \n\t"
  449. "movq (%1, %0), %%mm0 \n\t"
  450. "movq (%2, %0), %%mm1 \n\t"
  451. "paddb %%mm0, %%mm1 \n\t"
  452. "movq %%mm1, (%2, %0) \n\t"
  453. "movq 8(%1, %0), %%mm0 \n\t"
  454. "movq 8(%2, %0), %%mm1 \n\t"
  455. "paddb %%mm0, %%mm1 \n\t"
  456. "movq %%mm1, 8(%2, %0) \n\t"
  457. "add $16, %0 \n\t"
  458. "2: \n\t"
  459. "cmp %3, %0 \n\t"
  460. "js 1b \n\t"
  461. : "+r"(i)
  462. : "r"(src), "r"(dst), "r"((x86_reg)w - 15)
  463. );
  464. for ( ; i < w; i++)
  465. dst[i + 0] += src[i + 0];
  466. }
  467. #if HAVE_7REGS
  468. static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top,
  469. const uint8_t *diff, int w,
  470. int *left, int *left_top)
  471. {
  472. x86_reg w2 = -w;
  473. x86_reg x;
  474. int l = *left & 0xff;
  475. int tl = *left_top & 0xff;
  476. int t;
  477. __asm__ volatile (
  478. "mov %7, %3 \n"
  479. "1: \n"
  480. "movzbl (%3, %4), %2 \n"
  481. "mov %2, %k3 \n"
  482. "sub %b1, %b3 \n"
  483. "add %b0, %b3 \n"
  484. "mov %2, %1 \n"
  485. "cmp %0, %2 \n"
  486. "cmovg %0, %2 \n"
  487. "cmovg %1, %0 \n"
  488. "cmp %k3, %0 \n"
  489. "cmovg %k3, %0 \n"
  490. "mov %7, %3 \n"
  491. "cmp %2, %0 \n"
  492. "cmovl %2, %0 \n"
  493. "add (%6, %4), %b0 \n"
  494. "mov %b0, (%5, %4) \n"
  495. "inc %4 \n"
  496. "jl 1b \n"
  497. : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  498. : "r"(dst + w), "r"(diff + w), "rm"(top + w)
  499. );
  500. *left = l;
  501. *left_top = tl;
  502. }
  503. #endif
  504. static inline void transpose4x4(uint8_t *dst, uint8_t *src, x86_reg dst_stride, x86_reg src_stride){
  505. __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
  506. "movd (%1), %%mm0 \n\t"
  507. "add %3, %1 \n\t"
  508. "movd (%1), %%mm1 \n\t"
  509. "movd (%1,%3,1), %%mm2 \n\t"
  510. "movd (%1,%3,2), %%mm3 \n\t"
  511. "punpcklbw %%mm1, %%mm0 \n\t"
  512. "punpcklbw %%mm3, %%mm2 \n\t"
  513. "movq %%mm0, %%mm1 \n\t"
  514. "punpcklwd %%mm2, %%mm0 \n\t"
  515. "punpckhwd %%mm2, %%mm1 \n\t"
  516. "movd %%mm0, (%0) \n\t"
  517. "add %2, %0 \n\t"
  518. "punpckhdq %%mm0, %%mm0 \n\t"
  519. "movd %%mm0, (%0) \n\t"
  520. "movd %%mm1, (%0,%2,1) \n\t"
  521. "punpckhdq %%mm1, %%mm1 \n\t"
  522. "movd %%mm1, (%0,%2,2) \n\t"
  523. : "+&r" (dst),
  524. "+&r" (src)
  525. : "r" (dst_stride),
  526. "r" (src_stride)
  527. : "memory"
  528. );
  529. }
  530. #define H263_LOOP_FILTER \
  531. "pxor %%mm7, %%mm7 \n\t" \
  532. "movq %0, %%mm0 \n\t" \
  533. "movq %0, %%mm1 \n\t" \
  534. "movq %3, %%mm2 \n\t" \
  535. "movq %3, %%mm3 \n\t" \
  536. "punpcklbw %%mm7, %%mm0 \n\t" \
  537. "punpckhbw %%mm7, %%mm1 \n\t" \
  538. "punpcklbw %%mm7, %%mm2 \n\t" \
  539. "punpckhbw %%mm7, %%mm3 \n\t" \
  540. "psubw %%mm2, %%mm0 \n\t" \
  541. "psubw %%mm3, %%mm1 \n\t" \
  542. "movq %1, %%mm2 \n\t" \
  543. "movq %1, %%mm3 \n\t" \
  544. "movq %2, %%mm4 \n\t" \
  545. "movq %2, %%mm5 \n\t" \
  546. "punpcklbw %%mm7, %%mm2 \n\t" \
  547. "punpckhbw %%mm7, %%mm3 \n\t" \
  548. "punpcklbw %%mm7, %%mm4 \n\t" \
  549. "punpckhbw %%mm7, %%mm5 \n\t" \
  550. "psubw %%mm2, %%mm4 \n\t" \
  551. "psubw %%mm3, %%mm5 \n\t" \
  552. "psllw $2, %%mm4 \n\t" \
  553. "psllw $2, %%mm5 \n\t" \
  554. "paddw %%mm0, %%mm4 \n\t" \
  555. "paddw %%mm1, %%mm5 \n\t" \
  556. "pxor %%mm6, %%mm6 \n\t" \
  557. "pcmpgtw %%mm4, %%mm6 \n\t" \
  558. "pcmpgtw %%mm5, %%mm7 \n\t" \
  559. "pxor %%mm6, %%mm4 \n\t" \
  560. "pxor %%mm7, %%mm5 \n\t" \
  561. "psubw %%mm6, %%mm4 \n\t" \
  562. "psubw %%mm7, %%mm5 \n\t" \
  563. "psrlw $3, %%mm4 \n\t" \
  564. "psrlw $3, %%mm5 \n\t" \
  565. "packuswb %%mm5, %%mm4 \n\t" \
  566. "packsswb %%mm7, %%mm6 \n\t" \
  567. "pxor %%mm7, %%mm7 \n\t" \
  568. "movd %4, %%mm2 \n\t" \
  569. "punpcklbw %%mm2, %%mm2 \n\t" \
  570. "punpcklbw %%mm2, %%mm2 \n\t" \
  571. "punpcklbw %%mm2, %%mm2 \n\t" \
  572. "psubusb %%mm4, %%mm2 \n\t" \
  573. "movq %%mm2, %%mm3 \n\t" \
  574. "psubusb %%mm4, %%mm3 \n\t" \
  575. "psubb %%mm3, %%mm2 \n\t" \
  576. "movq %1, %%mm3 \n\t" \
  577. "movq %2, %%mm4 \n\t" \
  578. "pxor %%mm6, %%mm3 \n\t" \
  579. "pxor %%mm6, %%mm4 \n\t" \
  580. "paddusb %%mm2, %%mm3 \n\t" \
  581. "psubusb %%mm2, %%mm4 \n\t" \
  582. "pxor %%mm6, %%mm3 \n\t" \
  583. "pxor %%mm6, %%mm4 \n\t" \
  584. "paddusb %%mm2, %%mm2 \n\t" \
  585. "packsswb %%mm1, %%mm0 \n\t" \
  586. "pcmpgtb %%mm0, %%mm7 \n\t" \
  587. "pxor %%mm7, %%mm0 \n\t" \
  588. "psubb %%mm7, %%mm0 \n\t" \
  589. "movq %%mm0, %%mm1 \n\t" \
  590. "psubusb %%mm2, %%mm0 \n\t" \
  591. "psubb %%mm0, %%mm1 \n\t" \
  592. "pand %5, %%mm1 \n\t" \
  593. "psrlw $2, %%mm1 \n\t" \
  594. "pxor %%mm7, %%mm1 \n\t" \
  595. "psubb %%mm7, %%mm1 \n\t" \
  596. "movq %0, %%mm5 \n\t" \
  597. "movq %3, %%mm6 \n\t" \
  598. "psubb %%mm1, %%mm5 \n\t" \
  599. "paddb %%mm1, %%mm6 \n\t"
  600. static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale)
  601. {
  602. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  603. const int strength = ff_h263_loop_filter_strength[qscale];
  604. __asm__ volatile (
  605. H263_LOOP_FILTER
  606. "movq %%mm3, %1 \n\t"
  607. "movq %%mm4, %2 \n\t"
  608. "movq %%mm5, %0 \n\t"
  609. "movq %%mm6, %3 \n\t"
  610. : "+m"(*(uint64_t*)(src - 2 * stride)),
  611. "+m"(*(uint64_t*)(src - 1 * stride)),
  612. "+m"(*(uint64_t*)(src + 0 * stride)),
  613. "+m"(*(uint64_t*)(src + 1 * stride))
  614. : "g"(2 * strength), "m"(ff_pb_FC)
  615. );
  616. }
  617. }
  618. static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale)
  619. {
  620. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  621. const int strength = ff_h263_loop_filter_strength[qscale];
  622. DECLARE_ALIGNED(8, uint64_t, temp)[4];
  623. uint8_t *btemp = (uint8_t*)temp;
  624. src -= 2;
  625. transpose4x4(btemp, src, 8, stride);
  626. transpose4x4(btemp + 4, src + 4 * stride, 8, stride);
  627. __asm__ volatile (
  628. H263_LOOP_FILTER // 5 3 4 6
  629. : "+m"(temp[0]),
  630. "+m"(temp[1]),
  631. "+m"(temp[2]),
  632. "+m"(temp[3])
  633. : "g"(2 * strength), "m"(ff_pb_FC)
  634. );
  635. __asm__ volatile (
  636. "movq %%mm5, %%mm1 \n\t"
  637. "movq %%mm4, %%mm0 \n\t"
  638. "punpcklbw %%mm3, %%mm5 \n\t"
  639. "punpcklbw %%mm6, %%mm4 \n\t"
  640. "punpckhbw %%mm3, %%mm1 \n\t"
  641. "punpckhbw %%mm6, %%mm0 \n\t"
  642. "movq %%mm5, %%mm3 \n\t"
  643. "movq %%mm1, %%mm6 \n\t"
  644. "punpcklwd %%mm4, %%mm5 \n\t"
  645. "punpcklwd %%mm0, %%mm1 \n\t"
  646. "punpckhwd %%mm4, %%mm3 \n\t"
  647. "punpckhwd %%mm0, %%mm6 \n\t"
  648. "movd %%mm5, (%0) \n\t"
  649. "punpckhdq %%mm5, %%mm5 \n\t"
  650. "movd %%mm5, (%0, %2) \n\t"
  651. "movd %%mm3, (%0, %2, 2) \n\t"
  652. "punpckhdq %%mm3, %%mm3 \n\t"
  653. "movd %%mm3, (%0, %3) \n\t"
  654. "movd %%mm1, (%1) \n\t"
  655. "punpckhdq %%mm1, %%mm1 \n\t"
  656. "movd %%mm1, (%1, %2) \n\t"
  657. "movd %%mm6, (%1, %2, 2) \n\t"
  658. "punpckhdq %%mm6, %%mm6 \n\t"
  659. "movd %%mm6, (%1, %3) \n\t"
  660. :: "r"(src),
  661. "r"(src + 4 * stride),
  662. "r"((x86_reg)stride),
  663. "r"((x86_reg)(3 * stride))
  664. );
  665. }
  666. }
  667. /* Draw the edges of width 'w' of an image of size width, height
  668. * this MMX version can only handle w == 8 || w == 16. */
  669. static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
  670. int w, int h, int sides)
  671. {
  672. uint8_t *ptr, *last_line;
  673. int i;
  674. last_line = buf + (height - 1) * wrap;
  675. /* left and right */
  676. ptr = buf;
  677. if (w == 8) {
  678. __asm__ volatile (
  679. "1: \n\t"
  680. "movd (%0), %%mm0 \n\t"
  681. "punpcklbw %%mm0, %%mm0 \n\t"
  682. "punpcklwd %%mm0, %%mm0 \n\t"
  683. "punpckldq %%mm0, %%mm0 \n\t"
  684. "movq %%mm0, -8(%0) \n\t"
  685. "movq -8(%0, %2), %%mm1 \n\t"
  686. "punpckhbw %%mm1, %%mm1 \n\t"
  687. "punpckhwd %%mm1, %%mm1 \n\t"
  688. "punpckhdq %%mm1, %%mm1 \n\t"
  689. "movq %%mm1, (%0, %2) \n\t"
  690. "add %1, %0 \n\t"
  691. "cmp %3, %0 \n\t"
  692. "jb 1b \n\t"
  693. : "+r"(ptr)
  694. : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
  695. );
  696. } else {
  697. __asm__ volatile (
  698. "1: \n\t"
  699. "movd (%0), %%mm0 \n\t"
  700. "punpcklbw %%mm0, %%mm0 \n\t"
  701. "punpcklwd %%mm0, %%mm0 \n\t"
  702. "punpckldq %%mm0, %%mm0 \n\t"
  703. "movq %%mm0, -8(%0) \n\t"
  704. "movq %%mm0, -16(%0) \n\t"
  705. "movq -8(%0, %2), %%mm1 \n\t"
  706. "punpckhbw %%mm1, %%mm1 \n\t"
  707. "punpckhwd %%mm1, %%mm1 \n\t"
  708. "punpckhdq %%mm1, %%mm1 \n\t"
  709. "movq %%mm1, (%0, %2) \n\t"
  710. "movq %%mm1, 8(%0, %2) \n\t"
  711. "add %1, %0 \n\t"
  712. "cmp %3, %0 \n\t"
  713. "jb 1b \n\t"
  714. : "+r"(ptr)
  715. : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
  716. );
  717. }
  718. /* top and bottom (and hopefully also the corners) */
  719. if (sides & EDGE_TOP) {
  720. for (i = 0; i < h; i += 4) {
  721. ptr = buf - (i + 1) * wrap - w;
  722. __asm__ volatile (
  723. "1: \n\t"
  724. "movq (%1, %0), %%mm0 \n\t"
  725. "movq %%mm0, (%0) \n\t"
  726. "movq %%mm0, (%0, %2) \n\t"
  727. "movq %%mm0, (%0, %2, 2) \n\t"
  728. "movq %%mm0, (%0, %3) \n\t"
  729. "add $8, %0 \n\t"
  730. "cmp %4, %0 \n\t"
  731. "jb 1b \n\t"
  732. : "+r"(ptr)
  733. : "r"((x86_reg)buf - (x86_reg)ptr - w), "r"((x86_reg) -wrap),
  734. "r"((x86_reg) -wrap * 3), "r"(ptr + width + 2 * w)
  735. );
  736. }
  737. }
  738. if (sides & EDGE_BOTTOM) {
  739. for (i = 0; i < h; i += 4) {
  740. ptr = last_line + (i + 1) * wrap - w;
  741. __asm__ volatile (
  742. "1: \n\t"
  743. "movq (%1, %0), %%mm0 \n\t"
  744. "movq %%mm0, (%0) \n\t"
  745. "movq %%mm0, (%0, %2) \n\t"
  746. "movq %%mm0, (%0, %2, 2) \n\t"
  747. "movq %%mm0, (%0, %3) \n\t"
  748. "add $8, %0 \n\t"
  749. "cmp %4, %0 \n\t"
  750. "jb 1b \n\t"
  751. : "+r"(ptr)
  752. : "r"((x86_reg)last_line - (x86_reg)ptr - w),
  753. "r"((x86_reg)wrap), "r"((x86_reg)wrap * 3),
  754. "r"(ptr + width + 2 * w)
  755. );
  756. }
  757. }
  758. }
  759. #define QPEL_V_LOW(m3, m4, m5, m6, pw_20, pw_3, rnd, \
  760. in0, in1, in2, in7, out, OP) \
  761. "paddw "#m4", "#m3" \n\t" /* x1 */ \
  762. "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */ \
  763. "pmullw "#m3", %%mm4 \n\t" /* 20x1 */ \
  764. "movq "#in7", "#m3" \n\t" /* d */ \
  765. "movq "#in0", %%mm5 \n\t" /* D */ \
  766. "paddw "#m3", %%mm5 \n\t" /* x4 */ \
  767. "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */ \
  768. "movq "#in1", %%mm5 \n\t" /* C */ \
  769. "movq "#in2", %%mm6 \n\t" /* B */ \
  770. "paddw "#m6", %%mm5 \n\t" /* x3 */ \
  771. "paddw "#m5", %%mm6 \n\t" /* x2 */ \
  772. "paddw %%mm6, %%mm6 \n\t" /* 2x2 */ \
  773. "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */ \
  774. "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */ \
  775. "paddw "#rnd", %%mm4 \n\t" /* x2 */ \
  776. "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */ \
  777. "psraw $5, %%mm5 \n\t" \
  778. "packuswb %%mm5, %%mm5 \n\t" \
  779. OP(%%mm5, out, %%mm7, d)
  780. #define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMXEXT) \
  781. static void OPNAME ## mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, \
  782. uint8_t *src, \
  783. int dstStride, \
  784. int srcStride, \
  785. int h) \
  786. { \
  787. uint64_t temp; \
  788. \
  789. __asm__ volatile ( \
  790. "pxor %%mm7, %%mm7 \n\t" \
  791. "1: \n\t" \
  792. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */ \
  793. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */ \
  794. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */ \
  795. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */ \
  796. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */ \
  797. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */ \
  798. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */ \
  799. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */ \
  800. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */ \
  801. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */ \
  802. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */ \
  803. "psllq $24, %%mm4 \n\t" /* 000ABCDE */ \
  804. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */ \
  805. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */ \
  806. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */ \
  807. "paddw %%mm3, %%mm5 \n\t" /* b */ \
  808. "paddw %%mm2, %%mm6 \n\t" /* c */ \
  809. "paddw %%mm5, %%mm5 \n\t" /* 2b */ \
  810. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */ \
  811. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */ \
  812. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */ \
  813. "paddw %%mm4, %%mm0 \n\t" /* a */ \
  814. "paddw %%mm1, %%mm5 \n\t" /* d */ \
  815. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */ \
  816. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */ \
  817. "paddw %6, %%mm6 \n\t" \
  818. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */ \
  819. "psraw $5, %%mm0 \n\t" \
  820. "movq %%mm0, %5 \n\t" \
  821. /* mm1 = EFGH, mm2 = DEFG, mm3 = CDEF, mm4 = BCDE, mm7 = 0 */ \
  822. \
  823. "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */ \
  824. "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */ \
  825. "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */ \
  826. "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */ \
  827. "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */ \
  828. "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */ \
  829. "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */ \
  830. "paddw %%mm0, %%mm2 \n\t" /* b */ \
  831. "paddw %%mm5, %%mm3 \n\t" /* c */ \
  832. "paddw %%mm2, %%mm2 \n\t" /* 2b */ \
  833. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */ \
  834. "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */ \
  835. "psrlq $24, %%mm6 \n\t" /* IJKLM000 */ \
  836. "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */ \
  837. "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */ \
  838. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */ \
  839. "paddw %%mm2, %%mm1 \n\t" /* a */ \
  840. "paddw %%mm6, %%mm4 \n\t" /* d */ \
  841. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */ \
  842. "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */ \
  843. "paddw %6, %%mm1 \n\t" \
  844. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */ \
  845. "psraw $5, %%mm3 \n\t" \
  846. "movq %5, %%mm1 \n\t" \
  847. "packuswb %%mm3, %%mm1 \n\t" \
  848. OP_MMXEXT(%%mm1, (%1), %%mm4, q) \
  849. /* mm0 = GHIJ, mm2 = FGHI, mm5 = HIJK, mm6 = IJKL, mm7 = 0 */ \
  850. \
  851. "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */ \
  852. "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */ \
  853. "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */ \
  854. "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */ \
  855. "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */ \
  856. "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */ \
  857. "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */ \
  858. "paddw %%mm1, %%mm5 \n\t" /* b */ \
  859. "paddw %%mm4, %%mm0 \n\t" /* c */ \
  860. "paddw %%mm5, %%mm5 \n\t" /* 2b */ \
  861. "psubw %%mm5, %%mm0 \n\t" /* c - 2b */ \
  862. "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */ \
  863. "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */ \
  864. "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */ \
  865. "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */ \
  866. "paddw %%mm3, %%mm2 \n\t" /* d */ \
  867. "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */ \
  868. "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */ \
  869. "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */ \
  870. "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */ \
  871. "paddw %%mm2, %%mm6 \n\t" /* a */ \
  872. "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */ \
  873. "paddw %6, %%mm0 \n\t" \
  874. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */ \
  875. "psraw $5, %%mm0 \n\t" \
  876. /* mm1 = KLMN, mm2 = JKLM, mm3 = MNOP, */ \
  877. /* mm4 = LMNO, mm5 = NOPQ mm7 = 0 */ \
  878. \
  879. "paddw %%mm5, %%mm3 \n\t" /* a */ \
  880. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */ \
  881. "paddw %%mm4, %%mm6 \n\t" /* b */ \
  882. "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */ \
  883. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */ \
  884. "paddw %%mm1, %%mm4 \n\t" /* c */ \
  885. "paddw %%mm2, %%mm5 \n\t" /* d */ \
  886. "paddw %%mm6, %%mm6 \n\t" /* 2b */ \
  887. "psubw %%mm6, %%mm4 \n\t" /* c - 2b */ \
  888. "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */ \
  889. "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */ \
  890. "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */ \
  891. "paddw %6, %%mm4 \n\t" \
  892. "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */ \
  893. "psraw $5, %%mm4 \n\t" \
  894. "packuswb %%mm4, %%mm0 \n\t" \
  895. OP_MMXEXT(%%mm0, 8(%1), %%mm4, q) \
  896. \
  897. "add %3, %0 \n\t" \
  898. "add %4, %1 \n\t" \
  899. "decl %2 \n\t" \
  900. "jnz 1b \n\t" \
  901. : "+a"(src), "+c"(dst), "+D"(h) \
  902. : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), \
  903. /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(temp), "m"(ROUNDER) \
  904. : "memory" \
  905. ); \
  906. } \
  907. \
  908. static void OPNAME ## mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, \
  909. uint8_t *src, \
  910. int dstStride, \
  911. int srcStride, \
  912. int h) \
  913. { \
  914. __asm__ volatile ( \
  915. "pxor %%mm7, %%mm7 \n\t" \
  916. "1: \n\t" \
  917. "movq (%0), %%mm0 \n\t" /* ABCDEFGH */ \
  918. "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */ \
  919. "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */ \
  920. "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */ \
  921. "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */ \
  922. "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */ \
  923. "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */ \
  924. "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */ \
  925. "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */ \
  926. "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */ \
  927. "psllq $16, %%mm3 \n\t" /* 00ABCDEF */ \
  928. "psllq $24, %%mm4 \n\t" /* 000ABCDE */ \
  929. "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */ \
  930. "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */ \
  931. "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */ \
  932. "paddw %%mm3, %%mm5 \n\t" /* b */ \
  933. "paddw %%mm2, %%mm6 \n\t" /* c */ \
  934. "paddw %%mm5, %%mm5 \n\t" /* 2b */ \
  935. "psubw %%mm5, %%mm6 \n\t" /* c - 2b */ \
  936. "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */ \
  937. "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */ \
  938. "paddw %%mm4, %%mm0 \n\t" /* a */ \
  939. "paddw %%mm1, %%mm5 \n\t" /* d */ \
  940. "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */ \
  941. "psubw %%mm5, %%mm0 \n\t" /* 20a - d */ \
  942. "paddw %5, %%mm6 \n\t" \
  943. "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */ \
  944. "psraw $5, %%mm0 \n\t" \
  945. /* mm1 = EFGH, mm2 = DEFG, mm3 = CDEF, mm4 = BCDE, mm7 = 0 */ \
  946. \
  947. "movd 5(%0), %%mm5 \n\t" /* FGHI */ \
  948. "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */ \
  949. "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */ \
  950. "paddw %%mm5, %%mm1 \n\t" /* a */ \
  951. "paddw %%mm6, %%mm2 \n\t" /* b */ \
  952. "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */ \
  953. "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */ \
  954. "paddw %%mm6, %%mm3 \n\t" /* c */ \
  955. "paddw %%mm5, %%mm4 \n\t" /* d */ \
  956. "paddw %%mm2, %%mm2 \n\t" /* 2b */ \
  957. "psubw %%mm2, %%mm3 \n\t" /* c - 2b */ \
  958. "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */ \
  959. "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */ \
  960. "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */ \
  961. "paddw %5, %%mm1 \n\t" \
  962. "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */ \
  963. "psraw $5, %%mm3 \n\t" \
  964. "packuswb %%mm3, %%mm0 \n\t" \
  965. OP_MMXEXT(%%mm0, (%1), %%mm4, q) \
  966. \
  967. "add %3, %0 \n\t" \
  968. "add %4, %1 \n\t" \
  969. "decl %2 \n\t" \
  970. "jnz 1b \n\t" \
  971. : "+a"(src), "+c"(dst), "+d"(h) \
  972. : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), \
  973. /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER) \
  974. : "memory" \
  975. ); \
  976. }
  977. #define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX) \
  978. static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, \
  979. uint8_t *src, \
  980. int dstStride, \
  981. int srcStride) \
  982. { \
  983. uint64_t temp[17 * 4]; \
  984. uint64_t *temp_ptr = temp; \
  985. int count = 17; \
  986. \
  987. /* FIXME unroll */ \
  988. __asm__ volatile ( \
  989. "pxor %%mm7, %%mm7 \n\t" \
  990. "1: \n\t" \
  991. "movq (%0), %%mm0 \n\t" \
  992. "movq (%0), %%mm1 \n\t" \
  993. "movq 8(%0), %%mm2 \n\t" \
  994. "movq 8(%0), %%mm3 \n\t" \
  995. "punpcklbw %%mm7, %%mm0 \n\t" \
  996. "punpckhbw %%mm7, %%mm1 \n\t" \
  997. "punpcklbw %%mm7, %%mm2 \n\t" \
  998. "punpckhbw %%mm7, %%mm3 \n\t" \
  999. "movq %%mm0, (%1) \n\t" \
  1000. "movq %%mm1, 17 * 8(%1) \n\t" \
  1001. "movq %%mm2, 2 * 17 * 8(%1) \n\t" \
  1002. "movq %%mm3, 3 * 17 * 8(%1) \n\t" \
  1003. "add $8, %1 \n\t" \
  1004. "add %3, %0 \n\t" \
  1005. "decl %2 \n\t" \
  1006. "jnz 1b \n\t" \
  1007. : "+r"(src), "+r"(temp_ptr), "+r"(count) \
  1008. : "r"((x86_reg)srcStride) \
  1009. : "memory" \
  1010. ); \
  1011. \
  1012. temp_ptr = temp; \
  1013. count = 4; \
  1014. \
  1015. /* FIXME reorder for speed */ \
  1016. __asm__ volatile ( \
  1017. /* "pxor %%mm7, %%mm7 \n\t" */ \
  1018. "1: \n\t" \
  1019. "movq (%0), %%mm0 \n\t" \
  1020. "movq 8(%0), %%mm1 \n\t" \
  1021. "movq 16(%0), %%mm2 \n\t" \
  1022. "movq 24(%0), %%mm3 \n\t" \
  1023. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP) \
  1024. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP) \
  1025. "add %4, %1 \n\t" \
  1026. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP) \
  1027. \
  1028. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP) \
  1029. "add %4, %1 \n\t" \
  1030. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP) \
  1031. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP) \
  1032. "add %4, %1 \n\t" \
  1033. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP) \
  1034. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP) \
  1035. "add %4, %1 \n\t" \
  1036. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP) \
  1037. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0), 104(%0), (%1, %3), OP) \
  1038. "add %4, %1 \n\t" \
  1039. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0), 112(%0), (%1), OP) \
  1040. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0), 120(%0), (%1, %3), OP) \
  1041. "add %4, %1 \n\t" \
  1042. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0), 128(%0), (%1), OP) \
  1043. \
  1044. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0), 128(%0), (%1, %3), OP) \
  1045. "add %4, %1 \n\t" \
  1046. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0), 104(%0), 120(%0), (%1), OP) \
  1047. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0), 104(%0), 112(%0), 112(%0), (%1, %3), OP) \
  1048. \
  1049. "add $136, %0 \n\t" \
  1050. "add %6, %1 \n\t" \
  1051. "decl %2 \n\t" \
  1052. "jnz 1b \n\t" \
  1053. \
  1054. : "+r"(temp_ptr), "+r"(dst), "+g"(count) \
  1055. : "r"((x86_reg)dstStride), "r"(2 * (x86_reg)dstStride), \
  1056. /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER), \
  1057. "g"(4 - 14 * (x86_reg)dstStride) \
  1058. : "memory" \
  1059. ); \
  1060. } \
  1061. \
  1062. static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, \
  1063. uint8_t *src, \
  1064. int dstStride, \
  1065. int srcStride) \
  1066. { \
  1067. uint64_t temp[9 * 2]; \
  1068. uint64_t *temp_ptr = temp; \
  1069. int count = 9; \
  1070. \
  1071. /* FIXME unroll */ \
  1072. __asm__ volatile ( \
  1073. "pxor %%mm7, %%mm7 \n\t" \
  1074. "1: \n\t" \
  1075. "movq (%0), %%mm0 \n\t" \
  1076. "movq (%0), %%mm1 \n\t" \
  1077. "punpcklbw %%mm7, %%mm0 \n\t" \
  1078. "punpckhbw %%mm7, %%mm1 \n\t" \
  1079. "movq %%mm0, (%1) \n\t" \
  1080. "movq %%mm1, 9*8(%1) \n\t" \
  1081. "add $8, %1 \n\t" \
  1082. "add %3, %0 \n\t" \
  1083. "decl %2 \n\t" \
  1084. "jnz 1b \n\t" \
  1085. : "+r"(src), "+r"(temp_ptr), "+r"(count) \
  1086. : "r"((x86_reg)srcStride) \
  1087. : "memory" \
  1088. ); \
  1089. \
  1090. temp_ptr = temp; \
  1091. count = 2; \
  1092. \
  1093. /* FIXME reorder for speed */ \
  1094. __asm__ volatile ( \
  1095. /* "pxor %%mm7, %%mm7 \n\t" */ \
  1096. "1: \n\t" \
  1097. "movq (%0), %%mm0 \n\t" \
  1098. "movq 8(%0), %%mm1 \n\t" \
  1099. "movq 16(%0), %%mm2 \n\t" \
  1100. "movq 24(%0), %%mm3 \n\t" \
  1101. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP) \
  1102. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP) \
  1103. "add %4, %1 \n\t" \
  1104. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP) \
  1105. \
  1106. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP) \
  1107. "add %4, %1 \n\t" \
  1108. QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP) \
  1109. \
  1110. QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP) \
  1111. "add %4, %1 \n\t" \
  1112. QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP) \
  1113. QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP) \
  1114. \
  1115. "add $72, %0 \n\t" \
  1116. "add %6, %1 \n\t" \
  1117. "decl %2 \n\t" \
  1118. "jnz 1b \n\t" \
  1119. \
  1120. : "+r"(temp_ptr), "+r"(dst), "+g"(count) \
  1121. : "r"((x86_reg)dstStride), "r"(2 * (x86_reg)dstStride), \
  1122. /* "m"(ff_pw_20), "m"(ff_pw_3), */ "m"(ROUNDER), \
  1123. "g"(4 - 6 * (x86_reg)dstStride) \
  1124. : "memory" \
  1125. ); \
  1126. } \
  1127. \
  1128. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  1129. int stride) \
  1130. { \
  1131. OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
  1132. } \
  1133. \
  1134. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  1135. int stride) \
  1136. { \
  1137. uint64_t temp[8]; \
  1138. uint8_t * const half = (uint8_t*)temp; \
  1139. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  1140. stride, 8); \
  1141. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8); \
  1142. } \
  1143. \
  1144. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  1145. int stride) \
  1146. { \
  1147. OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
  1148. stride, 8); \
  1149. } \
  1150. \
  1151. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  1152. int stride) \
  1153. { \
  1154. uint64_t temp[8]; \
  1155. uint8_t * const half = (uint8_t*)temp; \
  1156. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  1157. stride, 8); \
  1158. OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
  1159. stride, 8); \
  1160. } \
  1161. \
  1162. static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  1163. int stride) \
  1164. { \
  1165. uint64_t temp[8]; \
  1166. uint8_t * const half = (uint8_t*)temp; \
  1167. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride); \
  1168. OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8); \
  1169. } \
  1170. \
  1171. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  1172. int stride) \
  1173. { \
  1174. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride); \
  1175. } \
  1176. \
  1177. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  1178. int stride) \
  1179. { \
  1180. uint64_t temp[8]; \
  1181. uint8_t * const half = (uint8_t*)temp; \
  1182. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride); \
  1183. OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride, \
  1184. stride, 8); \
  1185. } \
  1186. \
  1187. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  1188. int stride) \
  1189. { \
  1190. uint64_t half[8 + 9]; \
  1191. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  1192. uint8_t * const halfHV = ((uint8_t*)half); \
  1193. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1194. stride, 9); \
  1195. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
  1196. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1197. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
  1198. } \
  1199. \
  1200. static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  1201. int stride) \
  1202. { \
  1203. uint64_t half[8 + 9]; \
  1204. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  1205. uint8_t * const halfHV = ((uint8_t*)half); \
  1206. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1207. stride, 9); \
  1208. put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  1209. stride, 9); \
  1210. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1211. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
  1212. } \
  1213. \
  1214. static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  1215. int stride) \
  1216. { \
  1217. uint64_t half[8 + 9]; \
  1218. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  1219. uint8_t * const halfHV = ((uint8_t*)half); \
  1220. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1221. stride, 9); \
  1222. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
  1223. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1224. OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
  1225. } \
  1226. \
  1227. static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  1228. int stride) \
  1229. { \
  1230. uint64_t half[8 + 9]; \
  1231. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  1232. uint8_t * const halfHV = ((uint8_t*)half); \
  1233. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1234. stride, 9); \
  1235. put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  1236. stride, 9); \
  1237. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1238. OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
  1239. } \
  1240. \
  1241. static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  1242. int stride) \
  1243. { \
  1244. uint64_t half[8 + 9]; \
  1245. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  1246. uint8_t * const halfHV = ((uint8_t*)half); \
  1247. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1248. stride, 9); \
  1249. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1250. OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
  1251. } \
  1252. \
  1253. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  1254. int stride) \
  1255. { \
  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, \
  1260. stride, 9); \
  1261. put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
  1262. OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
  1263. } \
  1264. \
  1265. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  1266. int stride) \
  1267. { \
  1268. uint64_t half[8 + 9]; \
  1269. uint8_t * const halfH = ((uint8_t*)half); \
  1270. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1271. stride, 9); \
  1272. put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
  1273. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
  1274. } \
  1275. \
  1276. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  1277. int stride) \
  1278. { \
  1279. uint64_t half[8 + 9]; \
  1280. uint8_t * const halfH = ((uint8_t*)half); \
  1281. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1282. stride, 9); \
  1283. put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  1284. stride, 9); \
  1285. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
  1286. } \
  1287. \
  1288. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  1289. int stride) \
  1290. { \
  1291. uint64_t half[9]; \
  1292. uint8_t * const halfH = ((uint8_t*)half); \
  1293. put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  1294. stride, 9); \
  1295. OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
  1296. } \
  1297. \
  1298. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  1299. int stride) \
  1300. { \
  1301. OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
  1302. } \
  1303. \
  1304. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  1305. int stride) \
  1306. { \
  1307. uint64_t temp[32]; \
  1308. uint8_t * const half = (uint8_t*)temp; \
  1309. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  1310. stride, 16); \
  1311. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16); \
  1312. } \
  1313. \
  1314. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  1315. int stride) \
  1316. { \
  1317. OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
  1318. stride, stride, 16); \
  1319. } \
  1320. \
  1321. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  1322. int stride) \
  1323. { \
  1324. uint64_t temp[32]; \
  1325. uint8_t * const half = (uint8_t*)temp; \
  1326. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  1327. stride, 16); \
  1328. OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
  1329. stride, stride, 16); \
  1330. } \
  1331. \
  1332. static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  1333. int stride) \
  1334. { \
  1335. uint64_t temp[32]; \
  1336. uint8_t * const half = (uint8_t*)temp; \
  1337. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  1338. stride); \
  1339. OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16); \
  1340. } \
  1341. \
  1342. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  1343. int stride) \
  1344. { \
  1345. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride); \
  1346. } \
  1347. \
  1348. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  1349. int stride) \
  1350. { \
  1351. uint64_t temp[32]; \
  1352. uint8_t * const half = (uint8_t*)temp; \
  1353. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  1354. stride); \
  1355. OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
  1356. stride, stride, 16); \
  1357. } \
  1358. \
  1359. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  1360. int stride) \
  1361. { \
  1362. uint64_t half[16 * 2 + 17 * 2]; \
  1363. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1364. uint8_t * const halfHV = ((uint8_t*)half); \
  1365. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1366. stride, 17); \
  1367. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  1368. stride, 17); \
  1369. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1370. 16, 16); \
  1371. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
  1372. } \
  1373. \
  1374. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  1375. int stride) \
  1376. { \
  1377. uint64_t half[16 * 2 + 17 * 2]; \
  1378. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1379. uint8_t * const halfHV = ((uint8_t*)half); \
  1380. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1381. stride, 17); \
  1382. put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  1383. stride, 17); \
  1384. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1385. 16, 16); \
  1386. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
  1387. } \
  1388. \
  1389. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  1390. int stride) \
  1391. { \
  1392. uint64_t half[16 * 2 + 17 * 2]; \
  1393. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1394. uint8_t * const halfHV = ((uint8_t*)half); \
  1395. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1396. stride, 17); \
  1397. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  1398. stride, 17); \
  1399. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1400. 16, 16); \
  1401. OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
  1402. 16, 16); \
  1403. } \
  1404. \
  1405. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  1406. int stride) \
  1407. { \
  1408. uint64_t half[16 * 2 + 17 * 2]; \
  1409. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1410. uint8_t * const halfHV = ((uint8_t*)half); \
  1411. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1412. stride, 17); \
  1413. put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  1414. stride, 17); \
  1415. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1416. 16, 16); \
  1417. OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
  1418. 16, 16); \
  1419. } \
  1420. \
  1421. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  1422. int stride) \
  1423. { \
  1424. uint64_t half[16 * 2 + 17 * 2]; \
  1425. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1426. uint8_t * const halfHV = ((uint8_t*)half); \
  1427. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1428. stride, 17); \
  1429. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1430. 16, 16); \
  1431. OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
  1432. } \
  1433. \
  1434. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  1435. int stride) \
  1436. { \
  1437. uint64_t half[16 * 2 + 17 * 2]; \
  1438. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1439. uint8_t * const halfHV = ((uint8_t*)half); \
  1440. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1441. stride, 17); \
  1442. put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1443. 16, 16); \
  1444. OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
  1445. 16, 16); \
  1446. } \
  1447. \
  1448. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  1449. int stride) \
  1450. { \
  1451. uint64_t half[17 * 2]; \
  1452. uint8_t * const halfH = ((uint8_t*)half); \
  1453. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1454. stride, 17); \
  1455. put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  1456. stride, 17); \
  1457. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
  1458. } \
  1459. \
  1460. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  1461. int stride) \
  1462. { \
  1463. uint64_t half[17 * 2]; \
  1464. uint8_t * const halfH = ((uint8_t*)half); \
  1465. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1466. stride, 17); \
  1467. put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  1468. stride, 17); \
  1469. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
  1470. } \
  1471. \
  1472. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  1473. int stride) \
  1474. { \
  1475. uint64_t half[17 * 2]; \
  1476. uint8_t * const halfH = ((uint8_t*)half); \
  1477. put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1478. stride, 17); \
  1479. OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
  1480. }
  1481. #define PUT_OP(a, b, temp, size) \
  1482. "mov"#size" "#a", "#b" \n\t"
  1483. #define AVG_MMXEXT_OP(a, b, temp, size) \
  1484. "mov"#size" "#b", "#temp" \n\t" \
  1485. "pavgb "#temp", "#a" \n\t" \
  1486. "mov"#size" "#a", "#b" \n\t"
  1487. QPEL_BASE(put_, ff_pw_16, _, PUT_OP)
  1488. QPEL_BASE(avg_, ff_pw_16, _, AVG_MMXEXT_OP)
  1489. QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP)
  1490. QPEL_OP(put_, ff_pw_16, _, PUT_OP, mmxext)
  1491. QPEL_OP(avg_, ff_pw_16, _, AVG_MMXEXT_OP, mmxext)
  1492. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmxext)
  1493. /***********************************/
  1494. /* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
  1495. #define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL) \
  1496. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
  1497. uint8_t *src, \
  1498. int stride) \
  1499. { \
  1500. OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE); \
  1501. }
  1502. #define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2) \
  1503. static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
  1504. uint8_t *src, \
  1505. int stride) \
  1506. { \
  1507. OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src + S0, stride, SIZE, \
  1508. S1, S2); \
  1509. }
  1510. #define QPEL_2TAP(OPNAME, SIZE, MMX) \
  1511. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX) \
  1512. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX) \
  1513. QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx) \
  1514. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX = \
  1515. OPNAME ## qpel ## SIZE ## _mc00_ ## MMX; \
  1516. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX = \
  1517. OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX; \
  1518. static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX = \
  1519. OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX; \
  1520. static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, \
  1521. uint8_t *src, \
  1522. int stride) \
  1523. { \
  1524. OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src + 1, stride, SIZE); \
  1525. } \
  1526. static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, \
  1527. uint8_t *src, \
  1528. int stride) \
  1529. { \
  1530. OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src + stride, \
  1531. stride, SIZE); \
  1532. } \
  1533. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0) \
  1534. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0) \
  1535. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0) \
  1536. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0) \
  1537. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1) \
  1538. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1) \
  1539. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1) \
  1540. QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride + 1, -stride, -1) \
  1541. QPEL_2TAP(put_, 16, mmxext)
  1542. QPEL_2TAP(avg_, 16, mmxext)
  1543. QPEL_2TAP(put_, 8, mmxext)
  1544. QPEL_2TAP(avg_, 8, mmxext)
  1545. void ff_put_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
  1546. {
  1547. put_pixels8_xy2_mmx(dst, src, stride, 8);
  1548. }
  1549. void ff_put_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
  1550. {
  1551. put_pixels16_xy2_mmx(dst, src, stride, 16);
  1552. }
  1553. void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
  1554. {
  1555. avg_pixels8_xy2_mmx(dst, src, stride, 8);
  1556. }
  1557. void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
  1558. {
  1559. avg_pixels16_xy2_mmx(dst, src, stride, 16);
  1560. }
  1561. static void gmc_mmx(uint8_t *dst, uint8_t *src,
  1562. int stride, int h, int ox, int oy,
  1563. int dxx, int dxy, int dyx, int dyy,
  1564. int shift, int r, int width, int height)
  1565. {
  1566. const int w = 8;
  1567. const int ix = ox >> (16 + shift);
  1568. const int iy = oy >> (16 + shift);
  1569. const int oxs = ox >> 4;
  1570. const int oys = oy >> 4;
  1571. const int dxxs = dxx >> 4;
  1572. const int dxys = dxy >> 4;
  1573. const int dyxs = dyx >> 4;
  1574. const int dyys = dyy >> 4;
  1575. const uint16_t r4[4] = { r, r, r, r };
  1576. const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };
  1577. const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };
  1578. const uint64_t shift2 = 2 * shift;
  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. (unsigned)ix >= width - w ||
  1590. (unsigned)iy >= height - h) {
  1591. // FIXME could still use mmx for some of the rows
  1592. ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,
  1593. shift, r, width, height);
  1594. return;
  1595. }
  1596. src += ix + iy * stride;
  1597. __asm__ volatile (
  1598. "movd %0, %%mm6 \n\t"
  1599. "pxor %%mm7, %%mm7 \n\t"
  1600. "punpcklwd %%mm6, %%mm6 \n\t"
  1601. "punpcklwd %%mm6, %%mm6 \n\t"
  1602. :: "r"(1<<shift)
  1603. );
  1604. for (x = 0; x < w; x += 4) {
  1605. uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),
  1606. oxs - dxys + dxxs * (x + 1),
  1607. oxs - dxys + dxxs * (x + 2),
  1608. oxs - dxys + dxxs * (x + 3) };
  1609. uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),
  1610. oys - dyys + dyxs * (x + 1),
  1611. oys - dyys + dyxs * (x + 2),
  1612. oys - dyys + dyxs * (x + 3) };
  1613. for (y = 0; y < h; y++) {
  1614. __asm__ volatile (
  1615. "movq %0, %%mm4 \n\t"
  1616. "movq %1, %%mm5 \n\t"
  1617. "paddw %2, %%mm4 \n\t"
  1618. "paddw %3, %%mm5 \n\t"
  1619. "movq %%mm4, %0 \n\t"
  1620. "movq %%mm5, %1 \n\t"
  1621. "psrlw $12, %%mm4 \n\t"
  1622. "psrlw $12, %%mm5 \n\t"
  1623. : "+m"(*dx4), "+m"(*dy4)
  1624. : "m"(*dxy4), "m"(*dyy4)
  1625. );
  1626. __asm__ volatile (
  1627. "movq %%mm6, %%mm2 \n\t"
  1628. "movq %%mm6, %%mm1 \n\t"
  1629. "psubw %%mm4, %%mm2 \n\t"
  1630. "psubw %%mm5, %%mm1 \n\t"
  1631. "movq %%mm2, %%mm0 \n\t"
  1632. "movq %%mm4, %%mm3 \n\t"
  1633. "pmullw %%mm1, %%mm0 \n\t" // (s - dx) * (s - dy)
  1634. "pmullw %%mm5, %%mm3 \n\t" // dx * dy
  1635. "pmullw %%mm5, %%mm2 \n\t" // (s - dx) * dy
  1636. "pmullw %%mm4, %%mm1 \n\t" // dx * (s - dy)
  1637. "movd %4, %%mm5 \n\t"
  1638. "movd %3, %%mm4 \n\t"
  1639. "punpcklbw %%mm7, %%mm5 \n\t"
  1640. "punpcklbw %%mm7, %%mm4 \n\t"
  1641. "pmullw %%mm5, %%mm3 \n\t" // src[1, 1] * dx * dy
  1642. "pmullw %%mm4, %%mm2 \n\t" // src[0, 1] * (s - dx) * dy
  1643. "movd %2, %%mm5 \n\t"
  1644. "movd %1, %%mm4 \n\t"
  1645. "punpcklbw %%mm7, %%mm5 \n\t"
  1646. "punpcklbw %%mm7, %%mm4 \n\t"
  1647. "pmullw %%mm5, %%mm1 \n\t" // src[1, 0] * dx * (s - dy)
  1648. "pmullw %%mm4, %%mm0 \n\t" // src[0, 0] * (s - dx) * (s - dy)
  1649. "paddw %5, %%mm1 \n\t"
  1650. "paddw %%mm3, %%mm2 \n\t"
  1651. "paddw %%mm1, %%mm0 \n\t"
  1652. "paddw %%mm2, %%mm0 \n\t"
  1653. "psrlw %6, %%mm0 \n\t"
  1654. "packuswb %%mm0, %%mm0 \n\t"
  1655. "movd %%mm0, %0 \n\t"
  1656. : "=m"(dst[x + y * stride])
  1657. : "m"(src[0]), "m"(src[1]),
  1658. "m"(src[stride]), "m"(src[stride + 1]),
  1659. "m"(*r4), "m"(shift2)
  1660. );
  1661. src += stride;
  1662. }
  1663. src += 4 - h * stride;
  1664. }
  1665. }
  1666. #endif /* HAVE_INLINE_ASM */
  1667. #include "h264_qpel.c"
  1668. void ff_put_h264_chroma_mc8_rnd_mmx (uint8_t *dst, uint8_t *src,
  1669. int stride, int h, int x, int y);
  1670. void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, uint8_t *src,
  1671. int stride, int h, int x, int y);
  1672. void ff_avg_h264_chroma_mc8_rnd_3dnow(uint8_t *dst, uint8_t *src,
  1673. int stride, int h, int x, int y);
  1674. void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  1675. int stride, int h, int x, int y);
  1676. void ff_avg_h264_chroma_mc4_mmxext (uint8_t *dst, uint8_t *src,
  1677. int stride, int h, int x, int y);
  1678. void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
  1679. int stride, int h, int x, int y);
  1680. void ff_put_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
  1681. int stride, int h, int x, int y);
  1682. void ff_avg_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
  1683. int stride, int h, int x, int y);
  1684. void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
  1685. int stride, int h, int x, int y);
  1686. void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1687. int stride, int h, int x, int y);
  1688. void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
  1689. int stride, int h, int x, int y);
  1690. void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1691. int stride, int h, int x, int y);
  1692. #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
  1693. void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
  1694. (uint8_t *dst, uint8_t *src, \
  1695. int stride, int h, int x, int y);
  1696. CHROMA_MC(put, 2, 10, mmxext)
  1697. CHROMA_MC(avg, 2, 10, mmxext)
  1698. CHROMA_MC(put, 4, 10, mmxext)
  1699. CHROMA_MC(avg, 4, 10, mmxext)
  1700. CHROMA_MC(put, 8, 10, sse2)
  1701. CHROMA_MC(avg, 8, 10, sse2)
  1702. CHROMA_MC(put, 8, 10, avx)
  1703. CHROMA_MC(avg, 8, 10, avx)
  1704. #if HAVE_INLINE_ASM
  1705. /* CAVS-specific */
  1706. void ff_put_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride)
  1707. {
  1708. put_pixels8_mmx(dst, src, stride, 8);
  1709. }
  1710. void ff_avg_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride)
  1711. {
  1712. avg_pixels8_mmx(dst, src, stride, 8);
  1713. }
  1714. void ff_put_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride)
  1715. {
  1716. put_pixels16_mmx(dst, src, stride, 16);
  1717. }
  1718. void ff_avg_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, int stride)
  1719. {
  1720. avg_pixels16_mmx(dst, src, stride, 16);
  1721. }
  1722. /* VC-1-specific */
  1723. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src,
  1724. int stride, int rnd)
  1725. {
  1726. put_pixels8_mmx(dst, src, stride, 8);
  1727. }
  1728. void ff_avg_vc1_mspel_mc00_mmxext(uint8_t *dst, const uint8_t *src,
  1729. int stride, int rnd)
  1730. {
  1731. avg_pixels8_mmxext(dst, src, stride, 8);
  1732. }
  1733. static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
  1734. {
  1735. int i;
  1736. __asm__ volatile ("pxor %%mm7, %%mm7":);
  1737. for (i = 0; i < blocksize; i += 2) {
  1738. __asm__ volatile (
  1739. "movq %0, %%mm0 \n\t"
  1740. "movq %1, %%mm1 \n\t"
  1741. "movq %%mm0, %%mm2 \n\t"
  1742. "movq %%mm1, %%mm3 \n\t"
  1743. "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
  1744. "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
  1745. "pslld $31, %%mm2 \n\t" // keep only the sign bit
  1746. "pxor %%mm2, %%mm1 \n\t"
  1747. "movq %%mm3, %%mm4 \n\t"
  1748. "pand %%mm1, %%mm3 \n\t"
  1749. "pandn %%mm1, %%mm4 \n\t"
  1750. "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a < 0) & (a ^ sign(m)))
  1751. "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a > 0) & (a ^ sign(m)))
  1752. "movq %%mm3, %1 \n\t"
  1753. "movq %%mm0, %0 \n\t"
  1754. : "+m"(mag[i]), "+m"(ang[i])
  1755. :: "memory"
  1756. );
  1757. }
  1758. __asm__ volatile ("femms");
  1759. }
  1760. static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
  1761. {
  1762. int i;
  1763. __asm__ volatile (
  1764. "movaps %0, %%xmm5 \n\t"
  1765. :: "m"(ff_pdw_80000000[0])
  1766. );
  1767. for (i = 0; i < blocksize; i += 4) {
  1768. __asm__ volatile (
  1769. "movaps %0, %%xmm0 \n\t"
  1770. "movaps %1, %%xmm1 \n\t"
  1771. "xorps %%xmm2, %%xmm2 \n\t"
  1772. "xorps %%xmm3, %%xmm3 \n\t"
  1773. "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
  1774. "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
  1775. "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
  1776. "xorps %%xmm2, %%xmm1 \n\t"
  1777. "movaps %%xmm3, %%xmm4 \n\t"
  1778. "andps %%xmm1, %%xmm3 \n\t"
  1779. "andnps %%xmm1, %%xmm4 \n\t"
  1780. "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a < 0) & (a ^ sign(m)))
  1781. "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a > 0) & (a ^ sign(m)))
  1782. "movaps %%xmm3, %1 \n\t"
  1783. "movaps %%xmm0, %0 \n\t"
  1784. : "+m"(mag[i]), "+m"(ang[i])
  1785. :: "memory"
  1786. );
  1787. }
  1788. }
  1789. #if HAVE_6REGS
  1790. static void vector_fmul_window_3dnowext(float *dst, const float *src0,
  1791. const float *src1, const float *win,
  1792. int len)
  1793. {
  1794. x86_reg i = -len * 4;
  1795. x86_reg j = len * 4 - 8;
  1796. __asm__ volatile (
  1797. "1: \n"
  1798. "pswapd (%5, %1), %%mm1 \n"
  1799. "movq (%5, %0), %%mm0 \n"
  1800. "pswapd (%4, %1), %%mm5 \n"
  1801. "movq (%3, %0), %%mm4 \n"
  1802. "movq %%mm0, %%mm2 \n"
  1803. "movq %%mm1, %%mm3 \n"
  1804. "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i]
  1805. "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j]
  1806. "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j]
  1807. "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i]
  1808. "pfadd %%mm3, %%mm2 \n"
  1809. "pfsub %%mm0, %%mm1 \n"
  1810. "pswapd %%mm2, %%mm2 \n"
  1811. "movq %%mm1, (%2, %0) \n"
  1812. "movq %%mm2, (%2, %1) \n"
  1813. "sub $8, %1 \n"
  1814. "add $8, %0 \n"
  1815. "jl 1b \n"
  1816. "femms \n"
  1817. : "+r"(i), "+r"(j)
  1818. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  1819. );
  1820. }
  1821. static void vector_fmul_window_sse(float *dst, const float *src0,
  1822. const float *src1, const float *win, int len)
  1823. {
  1824. x86_reg i = -len * 4;
  1825. x86_reg j = len * 4 - 16;
  1826. __asm__ volatile (
  1827. "1: \n"
  1828. "movaps (%5, %1), %%xmm1 \n"
  1829. "movaps (%5, %0), %%xmm0 \n"
  1830. "movaps (%4, %1), %%xmm5 \n"
  1831. "movaps (%3, %0), %%xmm4 \n"
  1832. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  1833. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  1834. "movaps %%xmm0, %%xmm2 \n"
  1835. "movaps %%xmm1, %%xmm3 \n"
  1836. "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i]
  1837. "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j]
  1838. "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j]
  1839. "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i]
  1840. "addps %%xmm3, %%xmm2 \n"
  1841. "subps %%xmm0, %%xmm1 \n"
  1842. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  1843. "movaps %%xmm1, (%2, %0) \n"
  1844. "movaps %%xmm2, (%2, %1) \n"
  1845. "sub $16, %1 \n"
  1846. "add $16, %0 \n"
  1847. "jl 1b \n"
  1848. : "+r"(i), "+r"(j)
  1849. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  1850. );
  1851. }
  1852. #endif /* HAVE_6REGS */
  1853. static void vector_clipf_sse(float *dst, const float *src,
  1854. float min, float max, int len)
  1855. {
  1856. x86_reg i = (len - 16) * 4;
  1857. __asm__ volatile (
  1858. "movss %3, %%xmm4 \n\t"
  1859. "movss %4, %%xmm5 \n\t"
  1860. "shufps $0, %%xmm4, %%xmm4 \n\t"
  1861. "shufps $0, %%xmm5, %%xmm5 \n\t"
  1862. "1: \n\t"
  1863. "movaps (%2, %0), %%xmm0 \n\t" // 3/1 on intel
  1864. "movaps 16(%2, %0), %%xmm1 \n\t"
  1865. "movaps 32(%2, %0), %%xmm2 \n\t"
  1866. "movaps 48(%2, %0), %%xmm3 \n\t"
  1867. "maxps %%xmm4, %%xmm0 \n\t"
  1868. "maxps %%xmm4, %%xmm1 \n\t"
  1869. "maxps %%xmm4, %%xmm2 \n\t"
  1870. "maxps %%xmm4, %%xmm3 \n\t"
  1871. "minps %%xmm5, %%xmm0 \n\t"
  1872. "minps %%xmm5, %%xmm1 \n\t"
  1873. "minps %%xmm5, %%xmm2 \n\t"
  1874. "minps %%xmm5, %%xmm3 \n\t"
  1875. "movaps %%xmm0, (%1, %0) \n\t"
  1876. "movaps %%xmm1, 16(%1, %0) \n\t"
  1877. "movaps %%xmm2, 32(%1, %0) \n\t"
  1878. "movaps %%xmm3, 48(%1, %0) \n\t"
  1879. "sub $64, %0 \n\t"
  1880. "jge 1b \n\t"
  1881. : "+&r"(i)
  1882. : "r"(dst), "r"(src), "m"(min), "m"(max)
  1883. : "memory"
  1884. );
  1885. }
  1886. #endif /* HAVE_INLINE_ASM */
  1887. int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
  1888. int order);
  1889. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
  1890. int order);
  1891. int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
  1892. const int16_t *v3,
  1893. int order, int mul);
  1894. int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
  1895. const int16_t *v3,
  1896. int order, int mul);
  1897. int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
  1898. const int16_t *v3,
  1899. int order, int mul);
  1900. void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
  1901. const int16_t *window, unsigned int len);
  1902. void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
  1903. const int16_t *window, unsigned int len);
  1904. void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
  1905. const int16_t *window, unsigned int len);
  1906. void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
  1907. const int16_t *window, unsigned int len);
  1908. void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
  1909. const int16_t *window, unsigned int len);
  1910. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  1911. const int16_t *window, unsigned int len);
  1912. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  1913. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  1914. void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
  1915. const uint8_t *diff, int w,
  1916. int *left, int *left_top);
  1917. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
  1918. int w, int left);
  1919. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
  1920. int w, int left);
  1921. float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
  1922. void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
  1923. const float *src1, int len);
  1924. void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
  1925. const float *src1, int len);
  1926. void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
  1927. const float *src2, int len);
  1928. void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
  1929. const float *src2, int len);
  1930. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
  1931. int32_t min, int32_t max, unsigned int len);
  1932. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
  1933. int32_t min, int32_t max, unsigned int len);
  1934. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
  1935. int32_t min, int32_t max, unsigned int len);
  1936. void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
  1937. int32_t min, int32_t max, unsigned int len);
  1938. extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0,
  1939. const float *src1, int len);
  1940. extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
  1941. const float *src1, int len);
  1942. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  1943. do { \
  1944. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  1945. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  1946. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  1947. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  1948. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  1949. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  1950. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  1951. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  1952. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  1953. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  1954. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  1955. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  1956. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  1957. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  1958. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  1959. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
  1960. } while (0)
  1961. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  1962. do { \
  1963. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  1964. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  1965. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  1966. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  1967. } while (0)
  1968. #define H264_QPEL_FUNCS(x, y, CPU) \
  1969. do { \
  1970. c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
  1971. c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc ## x ## y ## _ ## CPU; \
  1972. c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
  1973. c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc ## x ## y ## _ ## CPU; \
  1974. } while (0)
  1975. #define H264_QPEL_FUNCS_10(x, y, CPU) \
  1976. do { \
  1977. c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
  1978. c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
  1979. c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
  1980. c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
  1981. } while (0)
  1982. static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  1983. {
  1984. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  1985. #if HAVE_INLINE_ASM
  1986. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  1987. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  1988. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  1989. if (!high_bit_depth) {
  1990. c->clear_block = clear_block_mmx;
  1991. c->clear_blocks = clear_blocks_mmx;
  1992. c->draw_edges = draw_edges_mmx;
  1993. SET_HPEL_FUNCS(put, 0, 16, mmx);
  1994. SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
  1995. SET_HPEL_FUNCS(avg, 0, 16, mmx);
  1996. SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
  1997. SET_HPEL_FUNCS(put, 1, 8, mmx);
  1998. SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
  1999. SET_HPEL_FUNCS(avg, 1, 8, mmx);
  2000. SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
  2001. switch (avctx->idct_algo) {
  2002. case FF_IDCT_AUTO:
  2003. case FF_IDCT_SIMPLEMMX:
  2004. c->idct_put = ff_simple_idct_put_mmx;
  2005. c->idct_add = ff_simple_idct_add_mmx;
  2006. c->idct = ff_simple_idct_mmx;
  2007. c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
  2008. break;
  2009. case FF_IDCT_XVIDMMX:
  2010. c->idct_put = ff_idct_xvid_mmx_put;
  2011. c->idct_add = ff_idct_xvid_mmx_add;
  2012. c->idct = ff_idct_xvid_mmx;
  2013. break;
  2014. }
  2015. }
  2016. c->gmc = gmc_mmx;
  2017. c->add_bytes = add_bytes_mmx;
  2018. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2019. c->h263_v_loop_filter = h263_v_loop_filter_mmx;
  2020. c->h263_h_loop_filter = h263_h_loop_filter_mmx;
  2021. }
  2022. #endif /* HAVE_INLINE_ASM */
  2023. #if HAVE_YASM
  2024. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2025. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
  2026. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
  2027. }
  2028. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  2029. #endif
  2030. }
  2031. static void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
  2032. int mm_flags)
  2033. {
  2034. const int bit_depth = avctx->bits_per_raw_sample;
  2035. const int high_bit_depth = bit_depth > 8;
  2036. #if HAVE_INLINE_ASM
  2037. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
  2038. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
  2039. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmxext, );
  2040. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmxext, );
  2041. SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
  2042. SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
  2043. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmxext, );
  2044. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmxext, );
  2045. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
  2046. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
  2047. if (!high_bit_depth) {
  2048. c->put_pixels_tab[0][1] = put_pixels16_x2_mmxext;
  2049. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  2050. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  2051. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  2052. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  2053. c->put_pixels_tab[1][1] = put_pixels8_x2_mmxext;
  2054. c->put_pixels_tab[1][2] = put_pixels8_y2_mmxext;
  2055. c->avg_pixels_tab[1][0] = avg_pixels8_mmxext;
  2056. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmxext;
  2057. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmxext;
  2058. }
  2059. if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
  2060. if (!high_bit_depth) {
  2061. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  2062. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  2063. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmxext;
  2064. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmxext;
  2065. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  2066. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmxext;
  2067. }
  2068. }
  2069. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  2070. c->idct_put = ff_idct_xvid_mmxext_put;
  2071. c->idct_add = ff_idct_xvid_mmxext_add;
  2072. c->idct = ff_idct_xvid_mmxext;
  2073. }
  2074. if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
  2075. avctx->codec_id == AV_CODEC_ID_THEORA)) {
  2076. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmxext;
  2077. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmxext;
  2078. }
  2079. #endif /* HAVE_INLINE_ASM */
  2080. #if HAVE_MMXEXT_EXTERNAL
  2081. if (CONFIG_H264QPEL) {
  2082. if (!high_bit_depth) {
  2083. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, );
  2084. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmxext, );
  2085. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmxext, );
  2086. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, );
  2087. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmxext, );
  2088. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmxext, );
  2089. } else if (bit_depth == 10) {
  2090. #if !ARCH_X86_64
  2091. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
  2092. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
  2093. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
  2094. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
  2095. #endif
  2096. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
  2097. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
  2098. }
  2099. }
  2100. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2101. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
  2102. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
  2103. c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
  2104. c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
  2105. }
  2106. if (bit_depth == 10 && CONFIG_H264CHROMA) {
  2107. c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
  2108. c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
  2109. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
  2110. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
  2111. }
  2112. /* slower than cmov version on AMD */
  2113. if (!(mm_flags & AV_CPU_FLAG_3DNOW))
  2114. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
  2115. c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
  2116. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
  2117. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2118. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  2119. } else {
  2120. c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
  2121. }
  2122. #endif /* HAVE_MMXEXT_EXTERNAL */
  2123. }
  2124. static void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
  2125. int mm_flags)
  2126. {
  2127. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2128. #if HAVE_INLINE_ASM
  2129. if (!high_bit_depth) {
  2130. c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
  2131. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  2132. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  2133. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  2134. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  2135. c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
  2136. c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
  2137. c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
  2138. c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
  2139. c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
  2140. if (!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2141. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  2142. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  2143. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
  2144. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
  2145. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  2146. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
  2147. }
  2148. }
  2149. if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
  2150. avctx->codec_id == AV_CODEC_ID_THEORA)) {
  2151. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
  2152. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
  2153. }
  2154. c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
  2155. #endif /* HAVE_INLINE_ASM */
  2156. #if HAVE_YASM
  2157. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2158. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_3dnow;
  2159. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
  2160. }
  2161. #endif /* HAVE_YASM */
  2162. }
  2163. static void dsputil_init_3dnowext(DSPContext *c, AVCodecContext *avctx,
  2164. int mm_flags)
  2165. {
  2166. #if HAVE_AMD3DNOWEXT_INLINE && HAVE_6REGS
  2167. c->vector_fmul_window = vector_fmul_window_3dnowext;
  2168. #endif
  2169. }
  2170. static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  2171. {
  2172. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2173. #if HAVE_INLINE_ASM
  2174. if (!high_bit_depth) {
  2175. if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
  2176. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  2177. c->clear_block = clear_block_sse;
  2178. c->clear_blocks = clear_blocks_sse;
  2179. }
  2180. }
  2181. c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
  2182. #if HAVE_6REGS
  2183. c->vector_fmul_window = vector_fmul_window_sse;
  2184. #endif
  2185. c->vector_clipf = vector_clipf_sse;
  2186. #endif /* HAVE_INLINE_ASM */
  2187. #if HAVE_YASM
  2188. c->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
  2189. c->vector_fmul_add = ff_vector_fmul_add_sse;
  2190. c->scalarproduct_float = ff_scalarproduct_float_sse;
  2191. c->butterflies_float_interleave = ff_butterflies_float_interleave_sse;
  2192. #endif /* HAVE_YASM */
  2193. }
  2194. static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  2195. int mm_flags)
  2196. {
  2197. const int bit_depth = avctx->bits_per_raw_sample;
  2198. const int high_bit_depth = bit_depth > 8;
  2199. #if HAVE_SSE2_INLINE
  2200. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  2201. c->idct_put = ff_idct_xvid_sse2_put;
  2202. c->idct_add = ff_idct_xvid_sse2_add;
  2203. c->idct = ff_idct_xvid_sse2;
  2204. c->idct_permutation_type = FF_SSE2_IDCT_PERM;
  2205. }
  2206. #endif /* HAVE_SSE2_INLINE */
  2207. #if HAVE_SSE2_EXTERNAL
  2208. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  2209. // these functions are slower than mmx on AMD, but faster on Intel
  2210. if (!high_bit_depth) {
  2211. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  2212. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  2213. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  2214. if (CONFIG_H264QPEL)
  2215. H264_QPEL_FUNCS(0, 0, sse2);
  2216. }
  2217. }
  2218. if (!high_bit_depth && CONFIG_H264QPEL) {
  2219. H264_QPEL_FUNCS(0, 1, sse2);
  2220. H264_QPEL_FUNCS(0, 2, sse2);
  2221. H264_QPEL_FUNCS(0, 3, sse2);
  2222. H264_QPEL_FUNCS(1, 1, sse2);
  2223. H264_QPEL_FUNCS(1, 2, sse2);
  2224. H264_QPEL_FUNCS(1, 3, sse2);
  2225. H264_QPEL_FUNCS(2, 1, sse2);
  2226. H264_QPEL_FUNCS(2, 2, sse2);
  2227. H264_QPEL_FUNCS(2, 3, sse2);
  2228. H264_QPEL_FUNCS(3, 1, sse2);
  2229. H264_QPEL_FUNCS(3, 2, sse2);
  2230. H264_QPEL_FUNCS(3, 3, sse2);
  2231. }
  2232. if (bit_depth == 10) {
  2233. if (CONFIG_H264QPEL) {
  2234. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
  2235. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
  2236. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
  2237. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
  2238. H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
  2239. H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
  2240. H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
  2241. }
  2242. if (CONFIG_H264CHROMA) {
  2243. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
  2244. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
  2245. }
  2246. }
  2247. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  2248. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  2249. if (mm_flags & AV_CPU_FLAG_ATOM) {
  2250. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  2251. } else {
  2252. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  2253. }
  2254. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2255. c->apply_window_int16 = ff_apply_window_int16_sse2;
  2256. } else if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  2257. c->apply_window_int16 = ff_apply_window_int16_round_sse2;
  2258. }
  2259. c->bswap_buf = ff_bswap32_buf_sse2;
  2260. #endif /* HAVE_SSE2_EXTERNAL */
  2261. }
  2262. static void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  2263. int mm_flags)
  2264. {
  2265. #if HAVE_SSSE3_EXTERNAL
  2266. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  2267. const int bit_depth = avctx->bits_per_raw_sample;
  2268. if (!high_bit_depth && CONFIG_H264QPEL) {
  2269. H264_QPEL_FUNCS(1, 0, ssse3);
  2270. H264_QPEL_FUNCS(1, 1, ssse3);
  2271. H264_QPEL_FUNCS(1, 2, ssse3);
  2272. H264_QPEL_FUNCS(1, 3, ssse3);
  2273. H264_QPEL_FUNCS(2, 0, ssse3);
  2274. H264_QPEL_FUNCS(2, 1, ssse3);
  2275. H264_QPEL_FUNCS(2, 2, ssse3);
  2276. H264_QPEL_FUNCS(2, 3, ssse3);
  2277. H264_QPEL_FUNCS(3, 0, ssse3);
  2278. H264_QPEL_FUNCS(3, 1, ssse3);
  2279. H264_QPEL_FUNCS(3, 2, ssse3);
  2280. H264_QPEL_FUNCS(3, 3, ssse3);
  2281. }
  2282. if (bit_depth == 10 && CONFIG_H264QPEL) {
  2283. H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
  2284. H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
  2285. H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
  2286. }
  2287. if (!high_bit_depth && CONFIG_H264CHROMA) {
  2288. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_ssse3;
  2289. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_ssse3;
  2290. c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
  2291. c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
  2292. }
  2293. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  2294. if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
  2295. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  2296. if (mm_flags & AV_CPU_FLAG_ATOM)
  2297. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  2298. else
  2299. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  2300. if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) // cachesplit
  2301. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  2302. c->bswap_buf = ff_bswap32_buf_ssse3;
  2303. #endif /* HAVE_SSSE3_EXTERNAL */
  2304. }
  2305. static void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  2306. int mm_flags)
  2307. {
  2308. #if HAVE_SSE4_EXTERNAL
  2309. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  2310. #endif /* HAVE_SSE4_EXTERNAL */
  2311. }
  2312. static void dsputil_init_avx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
  2313. {
  2314. #if HAVE_AVX_EXTERNAL
  2315. const int bit_depth = avctx->bits_per_raw_sample;
  2316. if (bit_depth == 10) {
  2317. // AVX implies !cache64.
  2318. // TODO: Port cache(32|64) detection from x264.
  2319. if (CONFIG_H264QPEL) {
  2320. H264_QPEL_FUNCS_10(1, 0, sse2);
  2321. H264_QPEL_FUNCS_10(2, 0, sse2);
  2322. H264_QPEL_FUNCS_10(3, 0, sse2);
  2323. }
  2324. if (CONFIG_H264CHROMA) {
  2325. c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
  2326. c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
  2327. }
  2328. }
  2329. c->butterflies_float_interleave = ff_butterflies_float_interleave_avx;
  2330. c->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
  2331. c->vector_fmul_add = ff_vector_fmul_add_avx;
  2332. #endif /* HAVE_AVX_EXTERNAL */
  2333. }
  2334. void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
  2335. {
  2336. int mm_flags = av_get_cpu_flags();
  2337. #if HAVE_7REGS && HAVE_INLINE_ASM
  2338. if (mm_flags & AV_CPU_FLAG_CMOV)
  2339. c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
  2340. #endif
  2341. if (mm_flags & AV_CPU_FLAG_MMX)
  2342. dsputil_init_mmx(c, avctx, mm_flags);
  2343. if (mm_flags & AV_CPU_FLAG_MMXEXT)
  2344. dsputil_init_mmxext(c, avctx, mm_flags);
  2345. if (mm_flags & AV_CPU_FLAG_3DNOW)
  2346. dsputil_init_3dnow(c, avctx, mm_flags);
  2347. if (mm_flags & AV_CPU_FLAG_3DNOWEXT)
  2348. dsputil_init_3dnowext(c, avctx, mm_flags);
  2349. if (mm_flags & AV_CPU_FLAG_SSE)
  2350. dsputil_init_sse(c, avctx, mm_flags);
  2351. if (mm_flags & AV_CPU_FLAG_SSE2)
  2352. dsputil_init_sse2(c, avctx, mm_flags);
  2353. if (mm_flags & AV_CPU_FLAG_SSSE3)
  2354. dsputil_init_ssse3(c, avctx, mm_flags);
  2355. if (mm_flags & AV_CPU_FLAG_SSE4)
  2356. dsputil_init_sse4(c, avctx, mm_flags);
  2357. if (mm_flags & AV_CPU_FLAG_AVX)
  2358. dsputil_init_avx(c, avctx, mm_flags);
  2359. if (CONFIG_ENCODERS)
  2360. ff_dsputilenc_init_mmx(c, avctx);
  2361. }