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.

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