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.

2864 lines
119KB

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