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.

3086 lines
152KB

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