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.

1706 lines
83KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "libavcodec/dsputil.h"
  28. #include "libavcodec/h264dsp.h"
  29. #include "libavcodec/mpegvideo.h"
  30. #include "libavcodec/simple_idct.h"
  31. #include "dsputil_mmx.h"
  32. #include "idct_xvid.h"
  33. //#undef NDEBUG
  34. //#include <assert.h>
  35. /* pixel operations */
  36. DECLARE_ALIGNED(8, const uint64_t, ff_bone) = 0x0101010101010101ULL;
  37. DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
  38. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1) = { 0x0001000100010001ULL, 0x0001000100010001ULL };
  39. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2) = { 0x0002000200020002ULL, 0x0002000200020002ULL };
  40. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3) = { 0x0003000300030003ULL, 0x0003000300030003ULL };
  41. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4) = { 0x0004000400040004ULL, 0x0004000400040004ULL };
  42. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5) = { 0x0005000500050005ULL, 0x0005000500050005ULL };
  43. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_8) = { 0x0008000800080008ULL, 0x0008000800080008ULL };
  44. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_9) = { 0x0009000900090009ULL, 0x0009000900090009ULL };
  45. DECLARE_ALIGNED(8, const uint64_t, ff_pw_15) = 0x000F000F000F000FULL;
  46. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_16) = { 0x0010001000100010ULL, 0x0010001000100010ULL };
  47. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_17) = { 0x0011001100110011ULL, 0x0011001100110011ULL };
  48. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_18) = { 0x0012001200120012ULL, 0x0012001200120012ULL };
  49. DECLARE_ALIGNED(8, const uint64_t, ff_pw_20) = 0x0014001400140014ULL;
  50. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_27) = { 0x001B001B001B001BULL, 0x001B001B001B001BULL };
  51. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_28) = { 0x001C001C001C001CULL, 0x001C001C001C001CULL };
  52. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_32) = { 0x0020002000200020ULL, 0x0020002000200020ULL };
  53. DECLARE_ALIGNED(8, const uint64_t, ff_pw_42) = 0x002A002A002A002AULL;
  54. DECLARE_ALIGNED(8, const uint64_t, ff_pw_53) = 0x0035003500350035ULL;
  55. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_63) = { 0x003F003F003F003FULL, 0x003F003F003F003FULL };
  56. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64) = { 0x0040004000400040ULL, 0x0040004000400040ULL };
  57. DECLARE_ALIGNED(8, const uint64_t, ff_pw_96) = 0x0060006000600060ULL;
  58. DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
  59. DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
  60. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = { 0x0200020002000200ULL, 0x0200020002000200ULL };
  61. DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019) = { 0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL };
  62. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0) = { 0x0000000000000000ULL, 0x0000000000000000ULL };
  63. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1) = { 0x0101010101010101ULL, 0x0101010101010101ULL };
  64. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_3) = { 0x0303030303030303ULL, 0x0303030303030303ULL };
  65. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_4) = { 0x0404040404040404ULL, 0x0404040404040404ULL };
  66. DECLARE_ALIGNED(8, const uint64_t, ff_pb_7) = 0x0707070707070707ULL;
  67. DECLARE_ALIGNED(8, const uint64_t, ff_pb_1F) = 0x1F1F1F1F1F1F1F1FULL;
  68. DECLARE_ALIGNED(8, const uint64_t, ff_pb_3F) = 0x3F3F3F3F3F3F3F3FULL;
  69. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_80) = { 0x8080808080808080ULL, 0x8080808080808080ULL };
  70. DECLARE_ALIGNED(8, const uint64_t, ff_pb_81) = 0x8181818181818181ULL;
  71. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_A1) = { 0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL };
  72. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_F8) = { 0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL };
  73. DECLARE_ALIGNED(8, const uint64_t, ff_pb_FC) = 0xFCFCFCFCFCFCFCFCULL;
  74. DECLARE_ALIGNED(16, const xmm_reg, ff_pb_FE) = { 0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL };
  75. DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
  76. DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
  77. #if HAVE_YASM
  78. void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  79. ptrdiff_t line_size, int h);
  80. void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  81. ptrdiff_t line_size, int h);
  82. void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  83. int dstStride, int src1Stride, int h);
  84. void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
  85. uint8_t *src2, int dstStride,
  86. int src1Stride, int h);
  87. void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  88. int dstStride, int src1Stride, int h);
  89. void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  90. ptrdiff_t line_size, int h);
  91. void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  92. ptrdiff_t line_size, int h);
  93. void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  94. int dstStride, int src1Stride, int h);
  95. void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  96. int dstStride, int src1Stride, int h);
  97. void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
  98. int dstStride, int src1Stride, int h);
  99. void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  100. ptrdiff_t line_size, int h);
  101. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  102. ptrdiff_t line_size, int h);
  103. void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
  104. const uint8_t *pixels,
  105. ptrdiff_t line_size, int h);
  106. void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
  107. const uint8_t *pixels,
  108. ptrdiff_t line_size, int h);
  109. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  110. ptrdiff_t line_size, int h);
  111. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  112. ptrdiff_t line_size, int h);
  113. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  114. ptrdiff_t line_size, int h);
  115. void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  116. ptrdiff_t line_size, int h);
  117. void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
  118. const uint8_t *pixels,
  119. ptrdiff_t line_size, int h);
  120. void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
  121. const uint8_t *pixels,
  122. ptrdiff_t line_size, int h);
  123. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  124. ptrdiff_t line_size, int h);
  125. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  126. ptrdiff_t line_size, int h);
  127. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  128. ptrdiff_t line_size, int h);
  129. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  130. ptrdiff_t line_size, int h);
  131. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  132. ptrdiff_t line_size, int h);
  133. void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  134. ptrdiff_t line_size, int h);
  135. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  136. ptrdiff_t line_size, int h);
  137. void ff_put_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h);
  138. static void ff_put_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
  139. ptrdiff_t line_size, int h)
  140. {
  141. ff_put_pixels8_mmxext(block, pixels, line_size, h);
  142. ff_put_pixels8_mmxext(block + 8, pixels + 8, line_size, h);
  143. }
  144. void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  145. int dstStride, int srcStride, int h);
  146. void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  147. int dstStride, int srcStride, int h);
  148. void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  149. int dstStride, int srcStride,
  150. int h);
  151. void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  152. int dstStride, int srcStride, int h);
  153. void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  154. int dstStride, int srcStride, int h);
  155. void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  156. int dstStride, int srcStride,
  157. int h);
  158. void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  159. int dstStride, int srcStride);
  160. void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  161. int dstStride, int srcStride);
  162. void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  163. int dstStride, int srcStride);
  164. void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  165. int dstStride, int srcStride);
  166. void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  167. int dstStride, int srcStride);
  168. void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
  169. int dstStride, int srcStride);
  170. #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
  171. #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
  172. #endif /* HAVE_YASM */
  173. #if HAVE_INLINE_ASM
  174. #define JUMPALIGN() __asm__ volatile (".p2align 3"::)
  175. #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%"#regd", %%"#regd ::)
  176. #define MOVQ_BFE(regd) \
  177. __asm__ volatile ( \
  178. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  179. "paddb %%"#regd", %%"#regd" \n\t" ::)
  180. #ifndef PIC
  181. #define MOVQ_BONE(regd) __asm__ volatile ("movq %0, %%"#regd" \n\t" :: "m"(ff_bone))
  182. #define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%"#regd" \n\t" :: "m"(ff_wtwo))
  183. #else
  184. // for shared library it's better to use this way for accessing constants
  185. // pcmpeqd -> -1
  186. #define MOVQ_BONE(regd) \
  187. __asm__ volatile ( \
  188. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  189. "psrlw $15, %%"#regd" \n\t" \
  190. "packuswb %%"#regd", %%"#regd" \n\t" ::)
  191. #define MOVQ_WTWO(regd) \
  192. __asm__ volatile ( \
  193. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  194. "psrlw $15, %%"#regd" \n\t" \
  195. "psllw $1, %%"#regd" \n\t"::)
  196. #endif
  197. // using regr as temporary and for the output result
  198. // first argument is unmodifed and second is trashed
  199. // regfe is supposed to contain 0xfefefefefefefefe
  200. #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
  201. "movq "#rega", "#regr" \n\t" \
  202. "pand "#regb", "#regr" \n\t" \
  203. "pxor "#rega", "#regb" \n\t" \
  204. "pand "#regfe", "#regb" \n\t" \
  205. "psrlq $1, "#regb" \n\t" \
  206. "paddb "#regb", "#regr" \n\t"
  207. #define PAVGB_MMX(rega, regb, regr, regfe) \
  208. "movq "#rega", "#regr" \n\t" \
  209. "por "#regb", "#regr" \n\t" \
  210. "pxor "#rega", "#regb" \n\t" \
  211. "pand "#regfe", "#regb" \n\t" \
  212. "psrlq $1, "#regb" \n\t" \
  213. "psubb "#regb", "#regr" \n\t"
  214. // mm6 is supposed to contain 0xfefefefefefefefe
  215. #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
  216. "movq "#rega", "#regr" \n\t" \
  217. "movq "#regc", "#regp" \n\t" \
  218. "pand "#regb", "#regr" \n\t" \
  219. "pand "#regd", "#regp" \n\t" \
  220. "pxor "#rega", "#regb" \n\t" \
  221. "pxor "#regc", "#regd" \n\t" \
  222. "pand %%mm6, "#regb" \n\t" \
  223. "pand %%mm6, "#regd" \n\t" \
  224. "psrlq $1, "#regb" \n\t" \
  225. "psrlq $1, "#regd" \n\t" \
  226. "paddb "#regb", "#regr" \n\t" \
  227. "paddb "#regd", "#regp" \n\t"
  228. #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
  229. "movq "#rega", "#regr" \n\t" \
  230. "movq "#regc", "#regp" \n\t" \
  231. "por "#regb", "#regr" \n\t" \
  232. "por "#regd", "#regp" \n\t" \
  233. "pxor "#rega", "#regb" \n\t" \
  234. "pxor "#regc", "#regd" \n\t" \
  235. "pand %%mm6, "#regb" \n\t" \
  236. "pand %%mm6, "#regd" \n\t" \
  237. "psrlq $1, "#regd" \n\t" \
  238. "psrlq $1, "#regb" \n\t" \
  239. "psubb "#regb", "#regr" \n\t" \
  240. "psubb "#regd", "#regp" \n\t"
  241. /***********************************/
  242. /* MMX no rounding */
  243. #define NO_RND 1
  244. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  245. #define SET_RND MOVQ_WONE
  246. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  247. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  248. #define OP_AVG(a, b, c, e) PAVGB_MMX(a, b, c, e)
  249. #include "dsputil_rnd_template.c"
  250. #undef DEF
  251. #undef SET_RND
  252. #undef PAVGBP
  253. #undef PAVGB
  254. #undef NO_RND
  255. /***********************************/
  256. /* MMX rounding */
  257. #define DEF(x, y) x ## _ ## y ## _mmx
  258. #define SET_RND MOVQ_WTWO
  259. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  260. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  261. #include "dsputil_rnd_template.c"
  262. #undef DEF
  263. #undef SET_RND
  264. #undef PAVGBP
  265. #undef PAVGB
  266. #undef OP_AVG
  267. #endif /* HAVE_INLINE_ASM */
  268. #if HAVE_YASM
  269. /***********************************/
  270. /* 3Dnow specific */
  271. #define DEF(x) x ## _3dnow
  272. #include "dsputil_avg_template.c"
  273. #undef DEF
  274. /***********************************/
  275. /* MMXEXT specific */
  276. #define DEF(x) x ## _mmxext
  277. #include "dsputil_avg_template.c"
  278. #undef DEF
  279. #endif /* HAVE_YASM */
  280. #if HAVE_INLINE_ASM
  281. #define put_no_rnd_pixels16_mmx put_pixels16_mmx
  282. #define put_no_rnd_pixels8_mmx put_pixels8_mmx
  283. /***********************************/
  284. /* standard MMX */
  285. void ff_put_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
  286. int line_size)
  287. {
  288. const int16_t *p;
  289. uint8_t *pix;
  290. /* read the pixels */
  291. p = block;
  292. pix = pixels;
  293. /* unrolled loop */
  294. __asm__ volatile (
  295. "movq (%3), %%mm0 \n\t"
  296. "movq 8(%3), %%mm1 \n\t"
  297. "movq 16(%3), %%mm2 \n\t"
  298. "movq 24(%3), %%mm3 \n\t"
  299. "movq 32(%3), %%mm4 \n\t"
  300. "movq 40(%3), %%mm5 \n\t"
  301. "movq 48(%3), %%mm6 \n\t"
  302. "movq 56(%3), %%mm7 \n\t"
  303. "packuswb %%mm1, %%mm0 \n\t"
  304. "packuswb %%mm3, %%mm2 \n\t"
  305. "packuswb %%mm5, %%mm4 \n\t"
  306. "packuswb %%mm7, %%mm6 \n\t"
  307. "movq %%mm0, (%0) \n\t"
  308. "movq %%mm2, (%0, %1) \n\t"
  309. "movq %%mm4, (%0, %1, 2) \n\t"
  310. "movq %%mm6, (%0, %2) \n\t"
  311. :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3),
  312. "r"(p)
  313. : "memory");
  314. pix += line_size * 4;
  315. p += 32;
  316. // if here would be an exact copy of the code above
  317. // compiler would generate some very strange code
  318. // thus using "r"
  319. __asm__ volatile (
  320. "movq (%3), %%mm0 \n\t"
  321. "movq 8(%3), %%mm1 \n\t"
  322. "movq 16(%3), %%mm2 \n\t"
  323. "movq 24(%3), %%mm3 \n\t"
  324. "movq 32(%3), %%mm4 \n\t"
  325. "movq 40(%3), %%mm5 \n\t"
  326. "movq 48(%3), %%mm6 \n\t"
  327. "movq 56(%3), %%mm7 \n\t"
  328. "packuswb %%mm1, %%mm0 \n\t"
  329. "packuswb %%mm3, %%mm2 \n\t"
  330. "packuswb %%mm5, %%mm4 \n\t"
  331. "packuswb %%mm7, %%mm6 \n\t"
  332. "movq %%mm0, (%0) \n\t"
  333. "movq %%mm2, (%0, %1) \n\t"
  334. "movq %%mm4, (%0, %1, 2) \n\t"
  335. "movq %%mm6, (%0, %2) \n\t"
  336. :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3), "r"(p)
  337. : "memory");
  338. }
  339. #define put_signed_pixels_clamped_mmx_half(off) \
  340. "movq "#off"(%2), %%mm1 \n\t" \
  341. "movq 16 + "#off"(%2), %%mm2 \n\t" \
  342. "movq 32 + "#off"(%2), %%mm3 \n\t" \
  343. "movq 48 + "#off"(%2), %%mm4 \n\t" \
  344. "packsswb 8 + "#off"(%2), %%mm1 \n\t" \
  345. "packsswb 24 + "#off"(%2), %%mm2 \n\t" \
  346. "packsswb 40 + "#off"(%2), %%mm3 \n\t" \
  347. "packsswb 56 + "#off"(%2), %%mm4 \n\t" \
  348. "paddb %%mm0, %%mm1 \n\t" \
  349. "paddb %%mm0, %%mm2 \n\t" \
  350. "paddb %%mm0, %%mm3 \n\t" \
  351. "paddb %%mm0, %%mm4 \n\t" \
  352. "movq %%mm1, (%0) \n\t" \
  353. "movq %%mm2, (%0, %3) \n\t" \
  354. "movq %%mm3, (%0, %3, 2) \n\t" \
  355. "movq %%mm4, (%0, %1) \n\t"
  356. void ff_put_signed_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
  357. int line_size)
  358. {
  359. x86_reg line_skip = line_size;
  360. x86_reg line_skip3;
  361. __asm__ volatile (
  362. "movq "MANGLE(ff_pb_80)", %%mm0 \n\t"
  363. "lea (%3, %3, 2), %1 \n\t"
  364. put_signed_pixels_clamped_mmx_half(0)
  365. "lea (%0, %3, 4), %0 \n\t"
  366. put_signed_pixels_clamped_mmx_half(64)
  367. : "+&r"(pixels), "=&r"(line_skip3)
  368. : "r"(block), "r"(line_skip)
  369. : "memory");
  370. }
  371. void ff_add_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
  372. int line_size)
  373. {
  374. const int16_t *p;
  375. uint8_t *pix;
  376. int i;
  377. /* read the pixels */
  378. p = block;
  379. pix = pixels;
  380. MOVQ_ZERO(mm7);
  381. i = 4;
  382. do {
  383. __asm__ volatile (
  384. "movq (%2), %%mm0 \n\t"
  385. "movq 8(%2), %%mm1 \n\t"
  386. "movq 16(%2), %%mm2 \n\t"
  387. "movq 24(%2), %%mm3 \n\t"
  388. "movq %0, %%mm4 \n\t"
  389. "movq %1, %%mm6 \n\t"
  390. "movq %%mm4, %%mm5 \n\t"
  391. "punpcklbw %%mm7, %%mm4 \n\t"
  392. "punpckhbw %%mm7, %%mm5 \n\t"
  393. "paddsw %%mm4, %%mm0 \n\t"
  394. "paddsw %%mm5, %%mm1 \n\t"
  395. "movq %%mm6, %%mm5 \n\t"
  396. "punpcklbw %%mm7, %%mm6 \n\t"
  397. "punpckhbw %%mm7, %%mm5 \n\t"
  398. "paddsw %%mm6, %%mm2 \n\t"
  399. "paddsw %%mm5, %%mm3 \n\t"
  400. "packuswb %%mm1, %%mm0 \n\t"
  401. "packuswb %%mm3, %%mm2 \n\t"
  402. "movq %%mm0, %0 \n\t"
  403. "movq %%mm2, %1 \n\t"
  404. : "+m"(*pix), "+m"(*(pix + line_size))
  405. : "r"(p)
  406. : "memory");
  407. pix += line_size * 2;
  408. p += 16;
  409. } while (--i);
  410. }
  411. static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
  412. ptrdiff_t line_size, int h)
  413. {
  414. __asm__ volatile (
  415. "lea (%3, %3), %%"REG_a" \n\t"
  416. ".p2align 3 \n\t"
  417. "1: \n\t"
  418. "movq (%1 ), %%mm0 \n\t"
  419. "movq (%1, %3), %%mm1 \n\t"
  420. "movq %%mm0, (%2) \n\t"
  421. "movq %%mm1, (%2, %3) \n\t"
  422. "add %%"REG_a", %1 \n\t"
  423. "add %%"REG_a", %2 \n\t"
  424. "movq (%1 ), %%mm0 \n\t"
  425. "movq (%1, %3), %%mm1 \n\t"
  426. "movq %%mm0, (%2) \n\t"
  427. "movq %%mm1, (%2, %3) \n\t"
  428. "add %%"REG_a", %1 \n\t"
  429. "add %%"REG_a", %2 \n\t"
  430. "subl $4, %0 \n\t"
  431. "jnz 1b \n\t"
  432. : "+g"(h), "+r"(pixels), "+r"(block)
  433. : "r"((x86_reg)line_size)
  434. : "%"REG_a, "memory"
  435. );
  436. }
  437. static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
  438. ptrdiff_t line_size, int h)
  439. {
  440. __asm__ volatile (
  441. "lea (%3, %3), %%"REG_a" \n\t"
  442. ".p2align 3 \n\t"
  443. "1: \n\t"
  444. "movq (%1 ), %%mm0 \n\t"
  445. "movq 8(%1 ), %%mm4 \n\t"
  446. "movq (%1, %3), %%mm1 \n\t"
  447. "movq 8(%1, %3), %%mm5 \n\t"
  448. "movq %%mm0, (%2) \n\t"
  449. "movq %%mm4, 8(%2) \n\t"
  450. "movq %%mm1, (%2, %3) \n\t"
  451. "movq %%mm5, 8(%2, %3) \n\t"
  452. "add %%"REG_a", %1 \n\t"
  453. "add %%"REG_a", %2 \n\t"
  454. "movq (%1 ), %%mm0 \n\t"
  455. "movq 8(%1 ), %%mm4 \n\t"
  456. "movq (%1, %3), %%mm1 \n\t"
  457. "movq 8(%1, %3), %%mm5 \n\t"
  458. "movq %%mm0, (%2) \n\t"
  459. "movq %%mm4, 8(%2) \n\t"
  460. "movq %%mm1, (%2, %3) \n\t"
  461. "movq %%mm5, 8(%2, %3) \n\t"
  462. "add %%"REG_a", %1 \n\t"
  463. "add %%"REG_a", %2 \n\t"
  464. "subl $4, %0 \n\t"
  465. "jnz 1b \n\t"
  466. : "+g"(h), "+r"(pixels), "+r"(block)
  467. : "r"((x86_reg)line_size)
  468. : "%"REG_a, "memory"
  469. );
  470. }
  471. #define CLEAR_BLOCKS(name, n) \
  472. static void name(int16_t *blocks) \
  473. { \
  474. __asm__ volatile ( \
  475. "pxor %%mm7, %%mm7 \n\t" \
  476. "mov %1, %%"REG_a" \n\t" \
  477. "1: \n\t" \
  478. "movq %%mm7, (%0, %%"REG_a") \n\t" \
  479. "movq %%mm7, 8(%0, %%"REG_a") \n\t" \
  480. "movq %%mm7, 16(%0, %%"REG_a") \n\t" \
  481. "movq %%mm7, 24(%0, %%"REG_a") \n\t" \
  482. "add $32, %%"REG_a" \n\t" \
  483. "js 1b \n\t" \
  484. :: "r"(((uint8_t *)blocks) + 128 * n), \
  485. "i"(-128 * n) \
  486. : "%"REG_a \
  487. ); \
  488. }
  489. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  490. CLEAR_BLOCKS(clear_block_mmx, 1)
  491. static void clear_block_sse(int16_t *block)
  492. {
  493. __asm__ volatile (
  494. "xorps %%xmm0, %%xmm0 \n"
  495. "movaps %%xmm0, (%0) \n"
  496. "movaps %%xmm0, 16(%0) \n"
  497. "movaps %%xmm0, 32(%0) \n"
  498. "movaps %%xmm0, 48(%0) \n"
  499. "movaps %%xmm0, 64(%0) \n"
  500. "movaps %%xmm0, 80(%0) \n"
  501. "movaps %%xmm0, 96(%0) \n"
  502. "movaps %%xmm0, 112(%0) \n"
  503. :: "r"(block)
  504. : "memory"
  505. );
  506. }
  507. static void clear_blocks_sse(int16_t *blocks)
  508. {
  509. __asm__ volatile (
  510. "xorps %%xmm0, %%xmm0 \n"
  511. "mov %1, %%"REG_a" \n"
  512. "1: \n"
  513. "movaps %%xmm0, (%0, %%"REG_a") \n"
  514. "movaps %%xmm0, 16(%0, %%"REG_a") \n"
  515. "movaps %%xmm0, 32(%0, %%"REG_a") \n"
  516. "movaps %%xmm0, 48(%0, %%"REG_a") \n"
  517. "movaps %%xmm0, 64(%0, %%"REG_a") \n"
  518. "movaps %%xmm0, 80(%0, %%"REG_a") \n"
  519. "movaps %%xmm0, 96(%0, %%"REG_a") \n"
  520. "movaps %%xmm0, 112(%0, %%"REG_a") \n"
  521. "add $128, %%"REG_a" \n"
  522. "js 1b \n"
  523. :: "r"(((uint8_t *)blocks) + 128 * 6),
  524. "i"(-128 * 6)
  525. : "%"REG_a
  526. );
  527. }
  528. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w)
  529. {
  530. x86_reg i = 0;
  531. __asm__ volatile (
  532. "jmp 2f \n\t"
  533. "1: \n\t"
  534. "movq (%1, %0), %%mm0 \n\t"
  535. "movq (%2, %0), %%mm1 \n\t"
  536. "paddb %%mm0, %%mm1 \n\t"
  537. "movq %%mm1, (%2, %0) \n\t"
  538. "movq 8(%1, %0), %%mm0 \n\t"
  539. "movq 8(%2, %0), %%mm1 \n\t"
  540. "paddb %%mm0, %%mm1 \n\t"
  541. "movq %%mm1, 8(%2, %0) \n\t"
  542. "add $16, %0 \n\t"
  543. "2: \n\t"
  544. "cmp %3, %0 \n\t"
  545. "js 1b \n\t"
  546. : "+r"(i)
  547. : "r"(src), "r"(dst), "r"((x86_reg)w - 15)
  548. );
  549. for ( ; i < w; i++)
  550. dst[i + 0] += src[i + 0];
  551. }
  552. #if HAVE_7REGS
  553. static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top,
  554. const uint8_t *diff, int w,
  555. int *left, int *left_top)
  556. {
  557. x86_reg w2 = -w;
  558. x86_reg x;
  559. int l = *left & 0xff;
  560. int tl = *left_top & 0xff;
  561. int t;
  562. __asm__ volatile (
  563. "mov %7, %3 \n"
  564. "1: \n"
  565. "movzbl (%3, %4), %2 \n"
  566. "mov %2, %k3 \n"
  567. "sub %b1, %b3 \n"
  568. "add %b0, %b3 \n"
  569. "mov %2, %1 \n"
  570. "cmp %0, %2 \n"
  571. "cmovg %0, %2 \n"
  572. "cmovg %1, %0 \n"
  573. "cmp %k3, %0 \n"
  574. "cmovg %k3, %0 \n"
  575. "mov %7, %3 \n"
  576. "cmp %2, %0 \n"
  577. "cmovl %2, %0 \n"
  578. "add (%6, %4), %b0 \n"
  579. "mov %b0, (%5, %4) \n"
  580. "inc %4 \n"
  581. "jl 1b \n"
  582. : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  583. : "r"(dst + w), "r"(diff + w), "rm"(top + w)
  584. );
  585. *left = l;
  586. *left_top = tl;
  587. }
  588. #endif
  589. #endif /* HAVE_INLINE_ASM */
  590. void ff_h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale);
  591. void ff_h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale);
  592. #if HAVE_INLINE_ASM
  593. /* Draw the edges of width 'w' of an image of size width, height
  594. * this MMX version can only handle w == 8 || w == 16. */
  595. static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
  596. int w, int h, int sides)
  597. {
  598. uint8_t *ptr, *last_line;
  599. int i;
  600. last_line = buf + (height - 1) * wrap;
  601. /* left and right */
  602. ptr = buf;
  603. if (w == 8) {
  604. __asm__ volatile (
  605. "1: \n\t"
  606. "movd (%0), %%mm0 \n\t"
  607. "punpcklbw %%mm0, %%mm0 \n\t"
  608. "punpcklwd %%mm0, %%mm0 \n\t"
  609. "punpckldq %%mm0, %%mm0 \n\t"
  610. "movq %%mm0, -8(%0) \n\t"
  611. "movq -8(%0, %2), %%mm1 \n\t"
  612. "punpckhbw %%mm1, %%mm1 \n\t"
  613. "punpckhwd %%mm1, %%mm1 \n\t"
  614. "punpckhdq %%mm1, %%mm1 \n\t"
  615. "movq %%mm1, (%0, %2) \n\t"
  616. "add %1, %0 \n\t"
  617. "cmp %3, %0 \n\t"
  618. "jb 1b \n\t"
  619. : "+r"(ptr)
  620. : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
  621. );
  622. } else {
  623. __asm__ volatile (
  624. "1: \n\t"
  625. "movd (%0), %%mm0 \n\t"
  626. "punpcklbw %%mm0, %%mm0 \n\t"
  627. "punpcklwd %%mm0, %%mm0 \n\t"
  628. "punpckldq %%mm0, %%mm0 \n\t"
  629. "movq %%mm0, -8(%0) \n\t"
  630. "movq %%mm0, -16(%0) \n\t"
  631. "movq -8(%0, %2), %%mm1 \n\t"
  632. "punpckhbw %%mm1, %%mm1 \n\t"
  633. "punpckhwd %%mm1, %%mm1 \n\t"
  634. "punpckhdq %%mm1, %%mm1 \n\t"
  635. "movq %%mm1, (%0, %2) \n\t"
  636. "movq %%mm1, 8(%0, %2) \n\t"
  637. "add %1, %0 \n\t"
  638. "cmp %3, %0 \n\t"
  639. "jb 1b \n\t"
  640. : "+r"(ptr)
  641. : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
  642. );
  643. }
  644. /* top and bottom (and hopefully also the corners) */
  645. if (sides & EDGE_TOP) {
  646. for (i = 0; i < h; i += 4) {
  647. ptr = buf - (i + 1) * wrap - w;
  648. __asm__ volatile (
  649. "1: \n\t"
  650. "movq (%1, %0), %%mm0 \n\t"
  651. "movq %%mm0, (%0) \n\t"
  652. "movq %%mm0, (%0, %2) \n\t"
  653. "movq %%mm0, (%0, %2, 2) \n\t"
  654. "movq %%mm0, (%0, %3) \n\t"
  655. "add $8, %0 \n\t"
  656. "cmp %4, %0 \n\t"
  657. "jb 1b \n\t"
  658. : "+r"(ptr)
  659. : "r"((x86_reg)buf - (x86_reg)ptr - w), "r"((x86_reg) -wrap),
  660. "r"((x86_reg) -wrap * 3), "r"(ptr + width + 2 * w)
  661. );
  662. }
  663. }
  664. if (sides & EDGE_BOTTOM) {
  665. for (i = 0; i < h; i += 4) {
  666. ptr = last_line + (i + 1) * wrap - w;
  667. __asm__ volatile (
  668. "1: \n\t"
  669. "movq (%1, %0), %%mm0 \n\t"
  670. "movq %%mm0, (%0) \n\t"
  671. "movq %%mm0, (%0, %2) \n\t"
  672. "movq %%mm0, (%0, %2, 2) \n\t"
  673. "movq %%mm0, (%0, %3) \n\t"
  674. "add $8, %0 \n\t"
  675. "cmp %4, %0 \n\t"
  676. "jb 1b \n\t"
  677. : "+r"(ptr)
  678. : "r"((x86_reg)last_line - (x86_reg)ptr - w),
  679. "r"((x86_reg)wrap), "r"((x86_reg)wrap * 3),
  680. "r"(ptr + width + 2 * w)
  681. );
  682. }
  683. }
  684. }
  685. #endif /* HAVE_INLINE_ASM */
  686. #if HAVE_YASM
  687. #define QPEL_OP(OPNAME, ROUNDER, RND, MMX) \
  688. static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  689. ptrdiff_t stride) \
  690. { \
  691. ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
  692. } \
  693. \
  694. static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  695. ptrdiff_t stride) \
  696. { \
  697. uint64_t temp[8]; \
  698. uint8_t * const half = (uint8_t*)temp; \
  699. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  700. stride, 8); \
  701. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  702. stride, stride, 8); \
  703. } \
  704. \
  705. static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  706. ptrdiff_t stride) \
  707. { \
  708. ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
  709. stride, 8); \
  710. } \
  711. \
  712. static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  713. ptrdiff_t stride) \
  714. { \
  715. uint64_t temp[8]; \
  716. uint8_t * const half = (uint8_t*)temp; \
  717. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
  718. stride, 8); \
  719. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
  720. stride, 8); \
  721. } \
  722. \
  723. static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  724. ptrdiff_t stride) \
  725. { \
  726. uint64_t temp[8]; \
  727. uint8_t * const half = (uint8_t*)temp; \
  728. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
  729. 8, stride); \
  730. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
  731. stride, stride, 8); \
  732. } \
  733. \
  734. static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  735. ptrdiff_t stride) \
  736. { \
  737. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
  738. stride, stride); \
  739. } \
  740. \
  741. static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  742. ptrdiff_t stride) \
  743. { \
  744. uint64_t temp[8]; \
  745. uint8_t * const half = (uint8_t*)temp; \
  746. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
  747. 8, stride); \
  748. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
  749. stride, 8); \
  750. } \
  751. \
  752. static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  753. ptrdiff_t stride) \
  754. { \
  755. uint64_t half[8 + 9]; \
  756. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  757. uint8_t * const halfHV = ((uint8_t*)half); \
  758. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  759. stride, 9); \
  760. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
  761. stride, 9); \
  762. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  763. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  764. stride, 8, 8); \
  765. } \
  766. \
  767. static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  768. ptrdiff_t stride) \
  769. { \
  770. uint64_t half[8 + 9]; \
  771. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  772. uint8_t * const halfHV = ((uint8_t*)half); \
  773. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  774. stride, 9); \
  775. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  776. stride, 9); \
  777. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  778. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  779. stride, 8, 8); \
  780. } \
  781. \
  782. static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  783. ptrdiff_t stride) \
  784. { \
  785. uint64_t half[8 + 9]; \
  786. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  787. uint8_t * const halfHV = ((uint8_t*)half); \
  788. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  789. stride, 9); \
  790. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
  791. stride, 9); \
  792. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  793. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  794. stride, 8, 8); \
  795. } \
  796. \
  797. static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  798. ptrdiff_t stride) \
  799. { \
  800. uint64_t half[8 + 9]; \
  801. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  802. uint8_t * const halfHV = ((uint8_t*)half); \
  803. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  804. stride, 9); \
  805. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  806. stride, 9); \
  807. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  808. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  809. stride, 8, 8); \
  810. } \
  811. \
  812. static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  813. ptrdiff_t stride) \
  814. { \
  815. uint64_t half[8 + 9]; \
  816. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  817. uint8_t * const halfHV = ((uint8_t*)half); \
  818. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  819. stride, 9); \
  820. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  821. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
  822. stride, 8, 8); \
  823. } \
  824. \
  825. static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  826. ptrdiff_t stride) \
  827. { \
  828. uint64_t half[8 + 9]; \
  829. uint8_t * const halfH = ((uint8_t*)half) + 64; \
  830. uint8_t * const halfHV = ((uint8_t*)half); \
  831. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  832. stride, 9); \
  833. ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
  834. ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
  835. stride, 8, 8); \
  836. } \
  837. \
  838. static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  839. ptrdiff_t stride) \
  840. { \
  841. uint64_t half[8 + 9]; \
  842. uint8_t * const halfH = ((uint8_t*)half); \
  843. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  844. stride, 9); \
  845. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
  846. 8, stride, 9); \
  847. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  848. stride, 8); \
  849. } \
  850. \
  851. static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  852. ptrdiff_t stride) \
  853. { \
  854. uint64_t half[8 + 9]; \
  855. uint8_t * const halfH = ((uint8_t*)half); \
  856. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  857. stride, 9); \
  858. ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
  859. stride, 9); \
  860. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  861. stride, 8); \
  862. } \
  863. \
  864. static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  865. ptrdiff_t stride) \
  866. { \
  867. uint64_t half[9]; \
  868. uint8_t * const halfH = ((uint8_t*)half); \
  869. ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
  870. stride, 9); \
  871. ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
  872. stride, 8); \
  873. } \
  874. \
  875. static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
  876. ptrdiff_t stride) \
  877. { \
  878. ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
  879. } \
  880. \
  881. static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
  882. ptrdiff_t stride) \
  883. { \
  884. uint64_t temp[32]; \
  885. uint8_t * const half = (uint8_t*)temp; \
  886. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  887. stride, 16); \
  888. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  889. stride, 16); \
  890. } \
  891. \
  892. static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
  893. ptrdiff_t stride) \
  894. { \
  895. ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
  896. stride, stride, 16);\
  897. } \
  898. \
  899. static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
  900. ptrdiff_t stride) \
  901. { \
  902. uint64_t temp[32]; \
  903. uint8_t * const half = (uint8_t*)temp; \
  904. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
  905. stride, 16); \
  906. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
  907. stride, stride, 16); \
  908. } \
  909. \
  910. static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
  911. ptrdiff_t stride) \
  912. { \
  913. uint64_t temp[32]; \
  914. uint8_t * const half = (uint8_t*)temp; \
  915. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  916. stride); \
  917. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
  918. stride, 16); \
  919. } \
  920. \
  921. static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
  922. ptrdiff_t stride) \
  923. { \
  924. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
  925. stride, stride); \
  926. } \
  927. \
  928. static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
  929. ptrdiff_t stride) \
  930. { \
  931. uint64_t temp[32]; \
  932. uint8_t * const half = (uint8_t*)temp; \
  933. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
  934. stride); \
  935. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
  936. stride, stride, 16); \
  937. } \
  938. \
  939. static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
  940. ptrdiff_t stride) \
  941. { \
  942. uint64_t half[16 * 2 + 17 * 2]; \
  943. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  944. uint8_t * const halfHV = ((uint8_t*)half); \
  945. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  946. stride, 17); \
  947. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  948. stride, 17); \
  949. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  950. 16, 16); \
  951. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  952. stride, 16, 16); \
  953. } \
  954. \
  955. static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
  956. ptrdiff_t stride) \
  957. { \
  958. uint64_t half[16 * 2 + 17 * 2]; \
  959. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  960. uint8_t * const halfHV = ((uint8_t*)half); \
  961. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  962. stride, 17); \
  963. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  964. stride, 17); \
  965. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  966. 16, 16); \
  967. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  968. stride, 16, 16); \
  969. } \
  970. \
  971. static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
  972. ptrdiff_t stride) \
  973. { \
  974. uint64_t half[16 * 2 + 17 * 2]; \
  975. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  976. uint8_t * const halfHV = ((uint8_t*)half); \
  977. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  978. stride, 17); \
  979. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  980. stride, 17); \
  981. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  982. 16, 16); \
  983. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  984. stride, 16, 16); \
  985. } \
  986. \
  987. static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
  988. ptrdiff_t stride) \
  989. { \
  990. uint64_t half[16 * 2 + 17 * 2]; \
  991. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  992. uint8_t * const halfHV = ((uint8_t*)half); \
  993. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  994. stride, 17); \
  995. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  996. stride, 17); \
  997. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  998. 16, 16); \
  999. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  1000. stride, 16, 16); \
  1001. } \
  1002. \
  1003. static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
  1004. ptrdiff_t stride) \
  1005. { \
  1006. uint64_t half[16 * 2 + 17 * 2]; \
  1007. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1008. uint8_t * const halfHV = ((uint8_t*)half); \
  1009. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1010. stride, 17); \
  1011. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1012. 16, 16); \
  1013. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
  1014. stride, 16, 16); \
  1015. } \
  1016. \
  1017. static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
  1018. ptrdiff_t stride) \
  1019. { \
  1020. uint64_t half[16 * 2 + 17 * 2]; \
  1021. uint8_t * const halfH = ((uint8_t*)half) + 256; \
  1022. uint8_t * const halfHV = ((uint8_t*)half); \
  1023. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1024. stride, 17); \
  1025. ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
  1026. 16, 16); \
  1027. ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
  1028. stride, 16, 16); \
  1029. } \
  1030. \
  1031. static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
  1032. ptrdiff_t stride) \
  1033. { \
  1034. uint64_t half[17 * 2]; \
  1035. uint8_t * const halfH = ((uint8_t*)half); \
  1036. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1037. stride, 17); \
  1038. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
  1039. stride, 17); \
  1040. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  1041. stride, 16); \
  1042. } \
  1043. \
  1044. static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
  1045. ptrdiff_t stride) \
  1046. { \
  1047. uint64_t half[17 * 2]; \
  1048. uint8_t * const halfH = ((uint8_t*)half); \
  1049. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1050. stride, 17); \
  1051. ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
  1052. stride, 17); \
  1053. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  1054. stride, 16); \
  1055. } \
  1056. \
  1057. static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
  1058. ptrdiff_t stride) \
  1059. { \
  1060. uint64_t half[17 * 2]; \
  1061. uint8_t * const halfH = ((uint8_t*)half); \
  1062. ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
  1063. stride, 17); \
  1064. ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
  1065. stride, 16); \
  1066. }
  1067. QPEL_OP(put_, ff_pw_16, _, mmxext)
  1068. QPEL_OP(avg_, ff_pw_16, _, mmxext)
  1069. QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, mmxext)
  1070. #endif /* HAVE_YASM */
  1071. #if HAVE_INLINE_ASM
  1072. void ff_put_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1073. {
  1074. put_pixels8_xy2_mmx(dst, src, stride, 8);
  1075. }
  1076. void ff_put_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1077. {
  1078. put_pixels16_xy2_mmx(dst, src, stride, 16);
  1079. }
  1080. void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1081. {
  1082. avg_pixels8_xy2_mmx(dst, src, stride, 8);
  1083. }
  1084. void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1085. {
  1086. avg_pixels16_xy2_mmx(dst, src, stride, 16);
  1087. }
  1088. static void gmc_mmx(uint8_t *dst, uint8_t *src,
  1089. int stride, int h, int ox, int oy,
  1090. int dxx, int dxy, int dyx, int dyy,
  1091. int shift, int r, int width, int height)
  1092. {
  1093. const int w = 8;
  1094. const int ix = ox >> (16 + shift);
  1095. const int iy = oy >> (16 + shift);
  1096. const int oxs = ox >> 4;
  1097. const int oys = oy >> 4;
  1098. const int dxxs = dxx >> 4;
  1099. const int dxys = dxy >> 4;
  1100. const int dyxs = dyx >> 4;
  1101. const int dyys = dyy >> 4;
  1102. const uint16_t r4[4] = { r, r, r, r };
  1103. const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };
  1104. const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };
  1105. const uint64_t shift2 = 2 * shift;
  1106. int x, y;
  1107. const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);
  1108. const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);
  1109. const int dxh = dxy * (h - 1);
  1110. const int dyw = dyx * (w - 1);
  1111. if ( // non-constant fullpel offset (3% of blocks)
  1112. ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |
  1113. (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift)
  1114. // uses more than 16 bits of subpel mv (only at huge resolution)
  1115. || (dxx | dxy | dyx | dyy) & 15 ||
  1116. (unsigned)ix >= width - w ||
  1117. (unsigned)iy >= height - h) {
  1118. // FIXME could still use mmx for some of the rows
  1119. ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,
  1120. shift, r, width, height);
  1121. return;
  1122. }
  1123. src += ix + iy * stride;
  1124. __asm__ volatile (
  1125. "movd %0, %%mm6 \n\t"
  1126. "pxor %%mm7, %%mm7 \n\t"
  1127. "punpcklwd %%mm6, %%mm6 \n\t"
  1128. "punpcklwd %%mm6, %%mm6 \n\t"
  1129. :: "r"(1<<shift)
  1130. );
  1131. for (x = 0; x < w; x += 4) {
  1132. uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),
  1133. oxs - dxys + dxxs * (x + 1),
  1134. oxs - dxys + dxxs * (x + 2),
  1135. oxs - dxys + dxxs * (x + 3) };
  1136. uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),
  1137. oys - dyys + dyxs * (x + 1),
  1138. oys - dyys + dyxs * (x + 2),
  1139. oys - dyys + dyxs * (x + 3) };
  1140. for (y = 0; y < h; y++) {
  1141. __asm__ volatile (
  1142. "movq %0, %%mm4 \n\t"
  1143. "movq %1, %%mm5 \n\t"
  1144. "paddw %2, %%mm4 \n\t"
  1145. "paddw %3, %%mm5 \n\t"
  1146. "movq %%mm4, %0 \n\t"
  1147. "movq %%mm5, %1 \n\t"
  1148. "psrlw $12, %%mm4 \n\t"
  1149. "psrlw $12, %%mm5 \n\t"
  1150. : "+m"(*dx4), "+m"(*dy4)
  1151. : "m"(*dxy4), "m"(*dyy4)
  1152. );
  1153. __asm__ volatile (
  1154. "movq %%mm6, %%mm2 \n\t"
  1155. "movq %%mm6, %%mm1 \n\t"
  1156. "psubw %%mm4, %%mm2 \n\t"
  1157. "psubw %%mm5, %%mm1 \n\t"
  1158. "movq %%mm2, %%mm0 \n\t"
  1159. "movq %%mm4, %%mm3 \n\t"
  1160. "pmullw %%mm1, %%mm0 \n\t" // (s - dx) * (s - dy)
  1161. "pmullw %%mm5, %%mm3 \n\t" // dx * dy
  1162. "pmullw %%mm5, %%mm2 \n\t" // (s - dx) * dy
  1163. "pmullw %%mm4, %%mm1 \n\t" // dx * (s - dy)
  1164. "movd %4, %%mm5 \n\t"
  1165. "movd %3, %%mm4 \n\t"
  1166. "punpcklbw %%mm7, %%mm5 \n\t"
  1167. "punpcklbw %%mm7, %%mm4 \n\t"
  1168. "pmullw %%mm5, %%mm3 \n\t" // src[1, 1] * dx * dy
  1169. "pmullw %%mm4, %%mm2 \n\t" // src[0, 1] * (s - dx) * dy
  1170. "movd %2, %%mm5 \n\t"
  1171. "movd %1, %%mm4 \n\t"
  1172. "punpcklbw %%mm7, %%mm5 \n\t"
  1173. "punpcklbw %%mm7, %%mm4 \n\t"
  1174. "pmullw %%mm5, %%mm1 \n\t" // src[1, 0] * dx * (s - dy)
  1175. "pmullw %%mm4, %%mm0 \n\t" // src[0, 0] * (s - dx) * (s - dy)
  1176. "paddw %5, %%mm1 \n\t"
  1177. "paddw %%mm3, %%mm2 \n\t"
  1178. "paddw %%mm1, %%mm0 \n\t"
  1179. "paddw %%mm2, %%mm0 \n\t"
  1180. "psrlw %6, %%mm0 \n\t"
  1181. "packuswb %%mm0, %%mm0 \n\t"
  1182. "movd %%mm0, %0 \n\t"
  1183. : "=m"(dst[x + y * stride])
  1184. : "m"(src[0]), "m"(src[1]),
  1185. "m"(src[stride]), "m"(src[stride + 1]),
  1186. "m"(*r4), "m"(shift2)
  1187. );
  1188. src += stride;
  1189. }
  1190. src += 4 - h * stride;
  1191. }
  1192. }
  1193. #endif /* HAVE_INLINE_ASM */
  1194. void ff_put_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
  1195. ptrdiff_t line_size, int h);
  1196. void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
  1197. ptrdiff_t line_size, int h);
  1198. #if HAVE_INLINE_ASM
  1199. /* CAVS-specific */
  1200. void ff_put_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1201. {
  1202. put_pixels8_mmx(dst, src, stride, 8);
  1203. }
  1204. void ff_avg_cavs_qpel8_mc00_mmxext(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1205. {
  1206. avg_pixels8_mmx(dst, src, stride, 8);
  1207. }
  1208. void ff_put_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1209. {
  1210. put_pixels16_mmx(dst, src, stride, 16);
  1211. }
  1212. void ff_avg_cavs_qpel16_mc00_mmxext(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
  1213. {
  1214. avg_pixels16_mmx(dst, src, stride, 16);
  1215. }
  1216. /* VC-1-specific */
  1217. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src,
  1218. ptrdiff_t stride, int rnd)
  1219. {
  1220. put_pixels8_mmx(dst, src, stride, 8);
  1221. }
  1222. static void vector_clipf_sse(float *dst, const float *src,
  1223. float min, float max, int len)
  1224. {
  1225. x86_reg i = (len - 16) * 4;
  1226. __asm__ volatile (
  1227. "movss %3, %%xmm4 \n\t"
  1228. "movss %4, %%xmm5 \n\t"
  1229. "shufps $0, %%xmm4, %%xmm4 \n\t"
  1230. "shufps $0, %%xmm5, %%xmm5 \n\t"
  1231. "1: \n\t"
  1232. "movaps (%2, %0), %%xmm0 \n\t" // 3/1 on intel
  1233. "movaps 16(%2, %0), %%xmm1 \n\t"
  1234. "movaps 32(%2, %0), %%xmm2 \n\t"
  1235. "movaps 48(%2, %0), %%xmm3 \n\t"
  1236. "maxps %%xmm4, %%xmm0 \n\t"
  1237. "maxps %%xmm4, %%xmm1 \n\t"
  1238. "maxps %%xmm4, %%xmm2 \n\t"
  1239. "maxps %%xmm4, %%xmm3 \n\t"
  1240. "minps %%xmm5, %%xmm0 \n\t"
  1241. "minps %%xmm5, %%xmm1 \n\t"
  1242. "minps %%xmm5, %%xmm2 \n\t"
  1243. "minps %%xmm5, %%xmm3 \n\t"
  1244. "movaps %%xmm0, (%1, %0) \n\t"
  1245. "movaps %%xmm1, 16(%1, %0) \n\t"
  1246. "movaps %%xmm2, 32(%1, %0) \n\t"
  1247. "movaps %%xmm3, 48(%1, %0) \n\t"
  1248. "sub $64, %0 \n\t"
  1249. "jge 1b \n\t"
  1250. : "+&r"(i)
  1251. : "r"(dst), "r"(src), "m"(min), "m"(max)
  1252. : "memory"
  1253. );
  1254. }
  1255. #endif /* HAVE_INLINE_ASM */
  1256. int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
  1257. int order);
  1258. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
  1259. int order);
  1260. int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
  1261. const int16_t *v3,
  1262. int order, int mul);
  1263. int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
  1264. const int16_t *v3,
  1265. int order, int mul);
  1266. int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
  1267. const int16_t *v3,
  1268. int order, int mul);
  1269. void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
  1270. const int16_t *window, unsigned int len);
  1271. void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
  1272. const int16_t *window, unsigned int len);
  1273. void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
  1274. const int16_t *window, unsigned int len);
  1275. void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
  1276. const int16_t *window, unsigned int len);
  1277. void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
  1278. const int16_t *window, unsigned int len);
  1279. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  1280. const int16_t *window, unsigned int len);
  1281. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  1282. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  1283. void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
  1284. const uint8_t *diff, int w,
  1285. int *left, int *left_top);
  1286. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
  1287. int w, int left);
  1288. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
  1289. int w, int left);
  1290. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
  1291. int32_t min, int32_t max, unsigned int len);
  1292. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
  1293. int32_t min, int32_t max, unsigned int len);
  1294. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
  1295. int32_t min, int32_t max, unsigned int len);
  1296. void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
  1297. int32_t min, int32_t max, unsigned int len);
  1298. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  1299. do { \
  1300. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  1301. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  1302. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  1303. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  1304. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  1305. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  1306. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  1307. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  1308. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  1309. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  1310. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  1311. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  1312. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  1313. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  1314. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  1315. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
  1316. } while (0)
  1317. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  1318. do { \
  1319. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  1320. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  1321. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  1322. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  1323. } while (0)
  1324. static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
  1325. int mm_flags)
  1326. {
  1327. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  1328. #if HAVE_INLINE_ASM
  1329. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  1330. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  1331. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  1332. if (!high_bit_depth) {
  1333. c->clear_block = clear_block_mmx;
  1334. c->clear_blocks = clear_blocks_mmx;
  1335. c->draw_edges = draw_edges_mmx;
  1336. SET_HPEL_FUNCS(put, [0], 16, mmx);
  1337. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  1338. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  1339. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  1340. SET_HPEL_FUNCS(put, [1], 8, mmx);
  1341. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  1342. SET_HPEL_FUNCS(avg, [1], 8, mmx);
  1343. switch (avctx->idct_algo) {
  1344. case FF_IDCT_AUTO:
  1345. case FF_IDCT_SIMPLEMMX:
  1346. c->idct_put = ff_simple_idct_put_mmx;
  1347. c->idct_add = ff_simple_idct_add_mmx;
  1348. c->idct = ff_simple_idct_mmx;
  1349. c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
  1350. break;
  1351. case FF_IDCT_XVIDMMX:
  1352. c->idct_put = ff_idct_xvid_mmx_put;
  1353. c->idct_add = ff_idct_xvid_mmx_add;
  1354. c->idct = ff_idct_xvid_mmx;
  1355. break;
  1356. }
  1357. }
  1358. c->gmc = gmc_mmx;
  1359. c->add_bytes = add_bytes_mmx;
  1360. #endif /* HAVE_INLINE_ASM */
  1361. #if HAVE_YASM
  1362. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1363. c->h263_v_loop_filter = ff_h263_v_loop_filter_mmx;
  1364. c->h263_h_loop_filter = ff_h263_h_loop_filter_mmx;
  1365. }
  1366. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  1367. #endif
  1368. }
  1369. static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
  1370. int mm_flags)
  1371. {
  1372. const int bit_depth = avctx->bits_per_raw_sample;
  1373. const int high_bit_depth = bit_depth > 8;
  1374. #if HAVE_YASM
  1375. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
  1376. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
  1377. SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
  1378. SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
  1379. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
  1380. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
  1381. if (!high_bit_depth) {
  1382. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  1383. c->put_pixels_tab[0][2] = ff_put_pixels16_y2_mmxext;
  1384. c->avg_pixels_tab[0][0] = ff_avg_pixels16_mmxext;
  1385. c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_mmxext;
  1386. c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_mmxext;
  1387. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  1388. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  1389. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  1390. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  1391. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  1392. }
  1393. if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
  1394. if (!high_bit_depth) {
  1395. c->put_no_rnd_pixels_tab[0][1] = ff_put_no_rnd_pixels16_x2_mmxext;
  1396. c->put_no_rnd_pixels_tab[0][2] = ff_put_no_rnd_pixels16_y2_mmxext;
  1397. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  1398. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  1399. c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_mmxext;
  1400. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  1401. }
  1402. }
  1403. #endif /* HAVE_YASM */
  1404. #if HAVE_INLINE_ASM
  1405. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  1406. c->idct_put = ff_idct_xvid_mmxext_put;
  1407. c->idct_add = ff_idct_xvid_mmxext_add;
  1408. c->idct = ff_idct_xvid_mmxext;
  1409. }
  1410. #endif /* HAVE_INLINE_ASM */
  1411. #if HAVE_MMXEXT_EXTERNAL
  1412. if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
  1413. avctx->codec_id == AV_CODEC_ID_THEORA)) {
  1414. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
  1415. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
  1416. }
  1417. /* slower than cmov version on AMD */
  1418. if (!(mm_flags & AV_CPU_FLAG_3DNOW))
  1419. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
  1420. c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
  1421. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
  1422. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  1423. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  1424. } else {
  1425. c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
  1426. }
  1427. #endif /* HAVE_MMXEXT_EXTERNAL */
  1428. }
  1429. static av_cold void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
  1430. int mm_flags)
  1431. {
  1432. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  1433. #if HAVE_YASM
  1434. if (!high_bit_depth) {
  1435. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  1436. c->put_pixels_tab[0][2] = ff_put_pixels16_y2_3dnow;
  1437. c->avg_pixels_tab[0][0] = ff_avg_pixels16_3dnow;
  1438. c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_3dnow;
  1439. c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_3dnow;
  1440. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  1441. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  1442. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  1443. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  1444. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  1445. if (!(avctx->flags & CODEC_FLAG_BITEXACT)){
  1446. c->put_no_rnd_pixels_tab[0][1] = ff_put_no_rnd_pixels16_x2_3dnow;
  1447. c->put_no_rnd_pixels_tab[0][2] = ff_put_no_rnd_pixels16_y2_3dnow;
  1448. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  1449. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  1450. c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_3dnow;
  1451. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  1452. }
  1453. }
  1454. if (CONFIG_VP3_DECODER && (avctx->codec_id == AV_CODEC_ID_VP3 ||
  1455. avctx->codec_id == AV_CODEC_ID_THEORA)) {
  1456. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
  1457. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
  1458. }
  1459. #endif /* HAVE_YASM */
  1460. }
  1461. static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
  1462. int mm_flags)
  1463. {
  1464. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  1465. #if HAVE_INLINE_ASM
  1466. if (!high_bit_depth) {
  1467. if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
  1468. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  1469. c->clear_block = clear_block_sse;
  1470. c->clear_blocks = clear_blocks_sse;
  1471. }
  1472. }
  1473. c->vector_clipf = vector_clipf_sse;
  1474. #endif /* HAVE_INLINE_ASM */
  1475. }
  1476. static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  1477. int mm_flags)
  1478. {
  1479. const int bit_depth = avctx->bits_per_raw_sample;
  1480. const int high_bit_depth = bit_depth > 8;
  1481. #if HAVE_SSE2_INLINE
  1482. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
  1483. c->idct_put = ff_idct_xvid_sse2_put;
  1484. c->idct_add = ff_idct_xvid_sse2_add;
  1485. c->idct = ff_idct_xvid_sse2;
  1486. c->idct_permutation_type = FF_SSE2_IDCT_PERM;
  1487. }
  1488. #endif /* HAVE_SSE2_INLINE */
  1489. #if HAVE_SSE2_EXTERNAL
  1490. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  1491. // these functions are slower than mmx on AMD, but faster on Intel
  1492. if (!high_bit_depth) {
  1493. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  1494. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  1495. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  1496. }
  1497. }
  1498. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  1499. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  1500. if (mm_flags & AV_CPU_FLAG_ATOM) {
  1501. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  1502. } else {
  1503. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  1504. }
  1505. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  1506. c->apply_window_int16 = ff_apply_window_int16_sse2;
  1507. } else if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  1508. c->apply_window_int16 = ff_apply_window_int16_round_sse2;
  1509. }
  1510. c->bswap_buf = ff_bswap32_buf_sse2;
  1511. #endif /* HAVE_SSE2_EXTERNAL */
  1512. }
  1513. static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  1514. int mm_flags)
  1515. {
  1516. #if HAVE_SSSE3_EXTERNAL
  1517. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  1518. if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
  1519. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  1520. if (mm_flags & AV_CPU_FLAG_ATOM)
  1521. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  1522. else
  1523. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  1524. if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) // cachesplit
  1525. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  1526. c->bswap_buf = ff_bswap32_buf_ssse3;
  1527. #endif /* HAVE_SSSE3_EXTERNAL */
  1528. }
  1529. static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  1530. int mm_flags)
  1531. {
  1532. #if HAVE_SSE4_EXTERNAL
  1533. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  1534. #endif /* HAVE_SSE4_EXTERNAL */
  1535. }
  1536. av_cold void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
  1537. {
  1538. int mm_flags = av_get_cpu_flags();
  1539. #if HAVE_7REGS && HAVE_INLINE_ASM
  1540. if (mm_flags & AV_CPU_FLAG_CMOV)
  1541. c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
  1542. #endif
  1543. if (mm_flags & AV_CPU_FLAG_MMX)
  1544. dsputil_init_mmx(c, avctx, mm_flags);
  1545. if (mm_flags & AV_CPU_FLAG_MMXEXT)
  1546. dsputil_init_mmxext(c, avctx, mm_flags);
  1547. if (mm_flags & AV_CPU_FLAG_3DNOW)
  1548. dsputil_init_3dnow(c, avctx, mm_flags);
  1549. if (mm_flags & AV_CPU_FLAG_SSE)
  1550. dsputil_init_sse(c, avctx, mm_flags);
  1551. if (mm_flags & AV_CPU_FLAG_SSE2)
  1552. dsputil_init_sse2(c, avctx, mm_flags);
  1553. if (mm_flags & AV_CPU_FLAG_SSSE3)
  1554. dsputil_init_ssse3(c, avctx, mm_flags);
  1555. if (mm_flags & AV_CPU_FLAG_SSE4)
  1556. dsputil_init_sse4(c, avctx, mm_flags);
  1557. if (CONFIG_ENCODERS)
  1558. ff_dsputilenc_init_mmx(c, avctx);
  1559. }