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.

2931 lines
121KB

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