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.

2891 lines
121KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of 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. "movdqa %%xmm0, (%2) \n\t"
  415. "movdqa %%xmm1, (%2,%3) \n\t"
  416. "movdqa %%xmm2, (%2,%3,2) \n\t"
  417. "movdqa %%xmm3, (%2,%4) \n\t"
  418. "subl $4, %0 \n\t"
  419. "lea (%1,%3,4), %1 \n\t"
  420. "lea (%2,%3,4), %2 \n\t"
  421. "jnz 1b \n\t"
  422. : "+g"(h), "+r" (pixels), "+r" (block)
  423. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  424. : "memory"
  425. );
  426. }
  427. static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  428. {
  429. __asm__ volatile(
  430. "1: \n\t"
  431. "movdqu (%1), %%xmm0 \n\t"
  432. "movdqu (%1,%3), %%xmm1 \n\t"
  433. "movdqu (%1,%3,2), %%xmm2 \n\t"
  434. "movdqu (%1,%4), %%xmm3 \n\t"
  435. "pavgb (%2), %%xmm0 \n\t"
  436. "pavgb (%2,%3), %%xmm1 \n\t"
  437. "pavgb (%2,%3,2), %%xmm2 \n\t"
  438. "pavgb (%2,%4), %%xmm3 \n\t"
  439. "movdqa %%xmm0, (%2) \n\t"
  440. "movdqa %%xmm1, (%2,%3) \n\t"
  441. "movdqa %%xmm2, (%2,%3,2) \n\t"
  442. "movdqa %%xmm3, (%2,%4) \n\t"
  443. "subl $4, %0 \n\t"
  444. "lea (%1,%3,4), %1 \n\t"
  445. "lea (%2,%3,4), %2 \n\t"
  446. "jnz 1b \n\t"
  447. : "+g"(h), "+r" (pixels), "+r" (block)
  448. : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
  449. : "memory"
  450. );
  451. }
  452. #define CLEAR_BLOCKS(name,n) \
  453. static void name(DCTELEM *blocks)\
  454. {\
  455. __asm__ volatile(\
  456. "pxor %%mm7, %%mm7 \n\t"\
  457. "mov %1, %%"REG_a" \n\t"\
  458. "1: \n\t"\
  459. "movq %%mm7, (%0, %%"REG_a") \n\t"\
  460. "movq %%mm7, 8(%0, %%"REG_a") \n\t"\
  461. "movq %%mm7, 16(%0, %%"REG_a") \n\t"\
  462. "movq %%mm7, 24(%0, %%"REG_a") \n\t"\
  463. "add $32, %%"REG_a" \n\t"\
  464. " js 1b \n\t"\
  465. : : "r" (((uint8_t *)blocks)+128*n),\
  466. "i" (-128*n)\
  467. : "%"REG_a\
  468. );\
  469. }
  470. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  471. CLEAR_BLOCKS(clear_block_mmx, 1)
  472. static void clear_block_sse(DCTELEM *block)
  473. {
  474. __asm__ volatile(
  475. "xorps %%xmm0, %%xmm0 \n"
  476. "movaps %%xmm0, (%0) \n"
  477. "movaps %%xmm0, 16(%0) \n"
  478. "movaps %%xmm0, 32(%0) \n"
  479. "movaps %%xmm0, 48(%0) \n"
  480. "movaps %%xmm0, 64(%0) \n"
  481. "movaps %%xmm0, 80(%0) \n"
  482. "movaps %%xmm0, 96(%0) \n"
  483. "movaps %%xmm0, 112(%0) \n"
  484. :: "r"(block)
  485. : "memory"
  486. );
  487. }
  488. static void clear_blocks_sse(DCTELEM *blocks)
  489. {\
  490. __asm__ volatile(
  491. "xorps %%xmm0, %%xmm0 \n"
  492. "mov %1, %%"REG_a" \n"
  493. "1: \n"
  494. "movaps %%xmm0, (%0, %%"REG_a") \n"
  495. "movaps %%xmm0, 16(%0, %%"REG_a") \n"
  496. "movaps %%xmm0, 32(%0, %%"REG_a") \n"
  497. "movaps %%xmm0, 48(%0, %%"REG_a") \n"
  498. "movaps %%xmm0, 64(%0, %%"REG_a") \n"
  499. "movaps %%xmm0, 80(%0, %%"REG_a") \n"
  500. "movaps %%xmm0, 96(%0, %%"REG_a") \n"
  501. "movaps %%xmm0, 112(%0, %%"REG_a") \n"
  502. "add $128, %%"REG_a" \n"
  503. " js 1b \n"
  504. : : "r" (((uint8_t *)blocks)+128*6),
  505. "i" (-128*6)
  506. : "%"REG_a
  507. );
  508. }
  509. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
  510. x86_reg i=0;
  511. __asm__ volatile(
  512. "jmp 2f \n\t"
  513. "1: \n\t"
  514. "movq (%1, %0), %%mm0 \n\t"
  515. "movq (%2, %0), %%mm1 \n\t"
  516. "paddb %%mm0, %%mm1 \n\t"
  517. "movq %%mm1, (%2, %0) \n\t"
  518. "movq 8(%1, %0), %%mm0 \n\t"
  519. "movq 8(%2, %0), %%mm1 \n\t"
  520. "paddb %%mm0, %%mm1 \n\t"
  521. "movq %%mm1, 8(%2, %0) \n\t"
  522. "add $16, %0 \n\t"
  523. "2: \n\t"
  524. "cmp %3, %0 \n\t"
  525. " js 1b \n\t"
  526. : "+r" (i)
  527. : "r"(src), "r"(dst), "r"((x86_reg)w-15)
  528. );
  529. for(; i<w; i++)
  530. dst[i+0] += src[i+0];
  531. }
  532. #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 0
  1497. static void just_return(void) { return; }
  1498. #endif
  1499. #if HAVE_YASM
  1500. typedef void emu_edge_core_func (uint8_t *buf, const uint8_t *src,
  1501. x86_reg linesize, x86_reg start_y,
  1502. x86_reg end_y, x86_reg block_h,
  1503. x86_reg start_x, x86_reg end_x,
  1504. x86_reg block_w);
  1505. extern emu_edge_core_func ff_emu_edge_core_mmx;
  1506. extern emu_edge_core_func ff_emu_edge_core_sse;
  1507. static av_always_inline
  1508. void emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize,
  1509. int block_w, int block_h,
  1510. int src_x, int src_y, int w, int h,
  1511. emu_edge_core_func *core_fn)
  1512. {
  1513. int start_y, start_x, end_y, end_x, src_y_add=0;
  1514. if(src_y>= h){
  1515. src_y_add = h-1-src_y;
  1516. src_y=h-1;
  1517. }else if(src_y<=-block_h){
  1518. src_y_add = 1-block_h-src_y;
  1519. src_y=1-block_h;
  1520. }
  1521. if(src_x>= w){
  1522. src+= (w-1-src_x);
  1523. src_x=w-1;
  1524. }else if(src_x<=-block_w){
  1525. src+= (1-block_w-src_x);
  1526. src_x=1-block_w;
  1527. }
  1528. start_y= FFMAX(0, -src_y);
  1529. start_x= FFMAX(0, -src_x);
  1530. end_y= FFMIN(block_h, h-src_y);
  1531. end_x= FFMIN(block_w, w-src_x);
  1532. assert(start_x < end_x && block_w > 0);
  1533. assert(start_y < end_y && block_h > 0);
  1534. // fill in the to-be-copied part plus all above/below
  1535. src += (src_y_add+start_y)*linesize + start_x;
  1536. buf += start_x;
  1537. core_fn(buf, src, linesize, start_y, end_y, block_h, start_x, end_x, block_w);
  1538. }
  1539. #if ARCH_X86_32
  1540. static av_noinline
  1541. void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src, int linesize,
  1542. int block_w, int block_h,
  1543. int src_x, int src_y, int w, int h)
  1544. {
  1545. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  1546. w, h, &ff_emu_edge_core_mmx);
  1547. }
  1548. #endif
  1549. static av_noinline
  1550. void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src, int linesize,
  1551. int block_w, int block_h,
  1552. int src_x, int src_y, int w, int h)
  1553. {
  1554. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  1555. w, h, &ff_emu_edge_core_sse);
  1556. }
  1557. #endif /* HAVE_YASM */
  1558. typedef void emulated_edge_mc_func (uint8_t *dst, const uint8_t *src,
  1559. int linesize, int block_w, int block_h,
  1560. int src_x, int src_y, int w, int h);
  1561. static av_always_inline
  1562. void gmc(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1563. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height,
  1564. emulated_edge_mc_func *emu_edge_fn)
  1565. {
  1566. const int w = 8;
  1567. const int ix = ox>>(16+shift);
  1568. const int iy = oy>>(16+shift);
  1569. const int oxs = ox>>4;
  1570. const int oys = oy>>4;
  1571. const int dxxs = dxx>>4;
  1572. const int dxys = dxy>>4;
  1573. const int dyxs = dyx>>4;
  1574. const int dyys = dyy>>4;
  1575. const uint16_t r4[4] = {r,r,r,r};
  1576. const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
  1577. const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
  1578. const uint64_t shift2 = 2*shift;
  1579. uint8_t edge_buf[(h+1)*stride];
  1580. int x, y;
  1581. const int dxw = (dxx-(1<<(16+shift)))*(w-1);
  1582. const int dyh = (dyy-(1<<(16+shift)))*(h-1);
  1583. const int dxh = dxy*(h-1);
  1584. const int dyw = dyx*(w-1);
  1585. if( // non-constant fullpel offset (3% of blocks)
  1586. ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
  1587. (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
  1588. // uses more than 16 bits of subpel mv (only at huge resolution)
  1589. || (dxx|dxy|dyx|dyy)&15 )
  1590. {
  1591. //FIXME could still use mmx for some of the rows
  1592. ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
  1593. return;
  1594. }
  1595. src += ix + iy*stride;
  1596. if( (unsigned)ix >= width-w ||
  1597. (unsigned)iy >= height-h )
  1598. {
  1599. emu_edge_fn(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
  1600. src = edge_buf;
  1601. }
  1602. __asm__ volatile(
  1603. "movd %0, %%mm6 \n\t"
  1604. "pxor %%mm7, %%mm7 \n\t"
  1605. "punpcklwd %%mm6, %%mm6 \n\t"
  1606. "punpcklwd %%mm6, %%mm6 \n\t"
  1607. :: "r"(1<<shift)
  1608. );
  1609. for(x=0; x<w; x+=4){
  1610. uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
  1611. oxs - dxys + dxxs*(x+1),
  1612. oxs - dxys + dxxs*(x+2),
  1613. oxs - dxys + dxxs*(x+3) };
  1614. uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
  1615. oys - dyys + dyxs*(x+1),
  1616. oys - dyys + dyxs*(x+2),
  1617. oys - dyys + dyxs*(x+3) };
  1618. for(y=0; y<h; y++){
  1619. __asm__ volatile(
  1620. "movq %0, %%mm4 \n\t"
  1621. "movq %1, %%mm5 \n\t"
  1622. "paddw %2, %%mm4 \n\t"
  1623. "paddw %3, %%mm5 \n\t"
  1624. "movq %%mm4, %0 \n\t"
  1625. "movq %%mm5, %1 \n\t"
  1626. "psrlw $12, %%mm4 \n\t"
  1627. "psrlw $12, %%mm5 \n\t"
  1628. : "+m"(*dx4), "+m"(*dy4)
  1629. : "m"(*dxy4), "m"(*dyy4)
  1630. );
  1631. __asm__ volatile(
  1632. "movq %%mm6, %%mm2 \n\t"
  1633. "movq %%mm6, %%mm1 \n\t"
  1634. "psubw %%mm4, %%mm2 \n\t"
  1635. "psubw %%mm5, %%mm1 \n\t"
  1636. "movq %%mm2, %%mm0 \n\t"
  1637. "movq %%mm4, %%mm3 \n\t"
  1638. "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
  1639. "pmullw %%mm5, %%mm3 \n\t" // dx*dy
  1640. "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
  1641. "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
  1642. "movd %4, %%mm5 \n\t"
  1643. "movd %3, %%mm4 \n\t"
  1644. "punpcklbw %%mm7, %%mm5 \n\t"
  1645. "punpcklbw %%mm7, %%mm4 \n\t"
  1646. "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
  1647. "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
  1648. "movd %2, %%mm5 \n\t"
  1649. "movd %1, %%mm4 \n\t"
  1650. "punpcklbw %%mm7, %%mm5 \n\t"
  1651. "punpcklbw %%mm7, %%mm4 \n\t"
  1652. "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
  1653. "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
  1654. "paddw %5, %%mm1 \n\t"
  1655. "paddw %%mm3, %%mm2 \n\t"
  1656. "paddw %%mm1, %%mm0 \n\t"
  1657. "paddw %%mm2, %%mm0 \n\t"
  1658. "psrlw %6, %%mm0 \n\t"
  1659. "packuswb %%mm0, %%mm0 \n\t"
  1660. "movd %%mm0, %0 \n\t"
  1661. : "=m"(dst[x+y*stride])
  1662. : "m"(src[0]), "m"(src[1]),
  1663. "m"(src[stride]), "m"(src[stride+1]),
  1664. "m"(*r4), "m"(shift2)
  1665. );
  1666. src += stride;
  1667. }
  1668. src += 4-h*stride;
  1669. }
  1670. }
  1671. #if HAVE_YASM
  1672. #if ARCH_X86_32
  1673. static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1674. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1675. {
  1676. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1677. width, height, &emulated_edge_mc_mmx);
  1678. }
  1679. #endif
  1680. static void gmc_sse(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1681. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1682. {
  1683. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1684. width, height, &emulated_edge_mc_sse);
  1685. }
  1686. #else
  1687. static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1688. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1689. {
  1690. gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
  1691. width, height, &ff_emulated_edge_mc);
  1692. }
  1693. #endif
  1694. #define PREFETCH(name, op) \
  1695. static void name(void *mem, int stride, int h){\
  1696. const uint8_t *p= mem;\
  1697. do{\
  1698. __asm__ volatile(#op" %0" :: "m"(*p));\
  1699. p+= stride;\
  1700. }while(--h);\
  1701. }
  1702. PREFETCH(prefetch_mmx2, prefetcht0)
  1703. PREFETCH(prefetch_3dnow, prefetch)
  1704. #undef PREFETCH
  1705. #include "h264_qpel_mmx.c"
  1706. void ff_put_h264_chroma_mc8_mmx_rnd (uint8_t *dst, uint8_t *src,
  1707. int stride, int h, int x, int y);
  1708. void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src,
  1709. int stride, int h, int x, int y);
  1710. void ff_avg_h264_chroma_mc8_mmx2_rnd (uint8_t *dst, uint8_t *src,
  1711. int stride, int h, int x, int y);
  1712. void ff_avg_rv40_chroma_mc8_mmx2 (uint8_t *dst, uint8_t *src,
  1713. int stride, int h, int x, int y);
  1714. void ff_avg_h264_chroma_mc8_3dnow_rnd (uint8_t *dst, uint8_t *src,
  1715. int stride, int h, int x, int y);
  1716. void ff_avg_rv40_chroma_mc8_3dnow (uint8_t *dst, uint8_t *src,
  1717. int stride, int h, int x, int y);
  1718. void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  1719. int stride, int h, int x, int y);
  1720. void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  1721. int stride, int h, int x, int y);
  1722. void ff_avg_h264_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
  1723. int stride, int h, int x, int y);
  1724. void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
  1725. int stride, int h, int x, int y);
  1726. void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
  1727. int stride, int h, int x, int y);
  1728. void ff_avg_rv40_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
  1729. int stride, int h, int x, int y);
  1730. void ff_put_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
  1731. int stride, int h, int x, int y);
  1732. void ff_avg_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
  1733. int stride, int h, int x, int y);
  1734. void ff_put_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
  1735. int stride, int h, int x, int y);
  1736. void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1737. int stride, int h, int x, int y);
  1738. void ff_avg_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
  1739. int stride, int h, int x, int y);
  1740. void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
  1741. int stride, int h, int x, int y);
  1742. #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
  1743. void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
  1744. (uint8_t *dst, uint8_t *src,\
  1745. int stride, int h, int x, int y);
  1746. CHROMA_MC(put, 2, 10, mmxext)
  1747. CHROMA_MC(avg, 2, 10, mmxext)
  1748. CHROMA_MC(put, 4, 10, mmxext)
  1749. CHROMA_MC(avg, 4, 10, mmxext)
  1750. CHROMA_MC(put, 8, 10, sse2)
  1751. CHROMA_MC(avg, 8, 10, sse2)
  1752. CHROMA_MC(put, 8, 10, avx)
  1753. CHROMA_MC(avg, 8, 10, avx)
  1754. /* CAVS specific */
  1755. void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1756. put_pixels8_mmx(dst, src, stride, 8);
  1757. }
  1758. void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1759. avg_pixels8_mmx(dst, src, stride, 8);
  1760. }
  1761. void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1762. put_pixels16_mmx(dst, src, stride, 16);
  1763. }
  1764. void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
  1765. avg_pixels16_mmx(dst, src, stride, 16);
  1766. }
  1767. /* VC1 specific */
  1768. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  1769. put_pixels8_mmx(dst, src, stride, 8);
  1770. }
  1771. void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  1772. avg_pixels8_mmx2(dst, src, stride, 8);
  1773. }
  1774. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  1775. converted */
  1776. #if CONFIG_GPL
  1777. static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1778. {
  1779. ff_mmx_idct (block);
  1780. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1781. }
  1782. static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1783. {
  1784. ff_mmx_idct (block);
  1785. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1786. }
  1787. static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  1788. {
  1789. ff_mmxext_idct (block);
  1790. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1791. }
  1792. static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  1793. {
  1794. ff_mmxext_idct (block);
  1795. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1796. }
  1797. #endif
  1798. static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
  1799. {
  1800. ff_idct_xvid_mmx (block);
  1801. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1802. }
  1803. static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
  1804. {
  1805. ff_idct_xvid_mmx (block);
  1806. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1807. }
  1808. static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
  1809. {
  1810. ff_idct_xvid_mmx2 (block);
  1811. ff_put_pixels_clamped_mmx(block, dest, line_size);
  1812. }
  1813. static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
  1814. {
  1815. ff_idct_xvid_mmx2 (block);
  1816. ff_add_pixels_clamped_mmx(block, dest, line_size);
  1817. }
  1818. static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
  1819. {
  1820. int i;
  1821. __asm__ volatile("pxor %%mm7, %%mm7":);
  1822. for(i=0; i<blocksize; i+=2) {
  1823. __asm__ volatile(
  1824. "movq %0, %%mm0 \n\t"
  1825. "movq %1, %%mm1 \n\t"
  1826. "movq %%mm0, %%mm2 \n\t"
  1827. "movq %%mm1, %%mm3 \n\t"
  1828. "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
  1829. "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
  1830. "pslld $31, %%mm2 \n\t" // keep only the sign bit
  1831. "pxor %%mm2, %%mm1 \n\t"
  1832. "movq %%mm3, %%mm4 \n\t"
  1833. "pand %%mm1, %%mm3 \n\t"
  1834. "pandn %%mm1, %%mm4 \n\t"
  1835. "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1836. "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1837. "movq %%mm3, %1 \n\t"
  1838. "movq %%mm0, %0 \n\t"
  1839. :"+m"(mag[i]), "+m"(ang[i])
  1840. ::"memory"
  1841. );
  1842. }
  1843. __asm__ volatile("femms");
  1844. }
  1845. static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
  1846. {
  1847. int i;
  1848. __asm__ volatile(
  1849. "movaps %0, %%xmm5 \n\t"
  1850. ::"m"(ff_pdw_80000000[0])
  1851. );
  1852. for(i=0; i<blocksize; i+=4) {
  1853. __asm__ volatile(
  1854. "movaps %0, %%xmm0 \n\t"
  1855. "movaps %1, %%xmm1 \n\t"
  1856. "xorps %%xmm2, %%xmm2 \n\t"
  1857. "xorps %%xmm3, %%xmm3 \n\t"
  1858. "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
  1859. "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
  1860. "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
  1861. "xorps %%xmm2, %%xmm1 \n\t"
  1862. "movaps %%xmm3, %%xmm4 \n\t"
  1863. "andps %%xmm1, %%xmm3 \n\t"
  1864. "andnps %%xmm1, %%xmm4 \n\t"
  1865. "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
  1866. "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
  1867. "movaps %%xmm3, %1 \n\t"
  1868. "movaps %%xmm0, %0 \n\t"
  1869. :"+m"(mag[i]), "+m"(ang[i])
  1870. ::"memory"
  1871. );
  1872. }
  1873. }
  1874. #define IF1(x) x
  1875. #define IF0(x)
  1876. #define MIX5(mono,stereo)\
  1877. __asm__ volatile(\
  1878. "movss 0(%2), %%xmm5 \n"\
  1879. "movss 8(%2), %%xmm6 \n"\
  1880. "movss 24(%2), %%xmm7 \n"\
  1881. "shufps $0, %%xmm5, %%xmm5 \n"\
  1882. "shufps $0, %%xmm6, %%xmm6 \n"\
  1883. "shufps $0, %%xmm7, %%xmm7 \n"\
  1884. "1: \n"\
  1885. "movaps (%0,%1), %%xmm0 \n"\
  1886. "movaps 0x400(%0,%1), %%xmm1 \n"\
  1887. "movaps 0x800(%0,%1), %%xmm2 \n"\
  1888. "movaps 0xc00(%0,%1), %%xmm3 \n"\
  1889. "movaps 0x1000(%0,%1), %%xmm4 \n"\
  1890. "mulps %%xmm5, %%xmm0 \n"\
  1891. "mulps %%xmm6, %%xmm1 \n"\
  1892. "mulps %%xmm5, %%xmm2 \n"\
  1893. "mulps %%xmm7, %%xmm3 \n"\
  1894. "mulps %%xmm7, %%xmm4 \n"\
  1895. stereo("addps %%xmm1, %%xmm0 \n")\
  1896. "addps %%xmm1, %%xmm2 \n"\
  1897. "addps %%xmm3, %%xmm0 \n"\
  1898. "addps %%xmm4, %%xmm2 \n"\
  1899. mono("addps %%xmm2, %%xmm0 \n")\
  1900. "movaps %%xmm0, (%0,%1) \n"\
  1901. stereo("movaps %%xmm2, 0x400(%0,%1) \n")\
  1902. "add $16, %0 \n"\
  1903. "jl 1b \n"\
  1904. :"+&r"(i)\
  1905. :"r"(samples[0]+len), "r"(matrix)\
  1906. :XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
  1907. "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\
  1908. "memory"\
  1909. );
  1910. #define MIX_MISC(stereo)\
  1911. __asm__ volatile(\
  1912. "1: \n"\
  1913. "movaps (%3,%0), %%xmm0 \n"\
  1914. stereo("movaps %%xmm0, %%xmm1 \n")\
  1915. "mulps %%xmm4, %%xmm0 \n"\
  1916. stereo("mulps %%xmm5, %%xmm1 \n")\
  1917. "lea 1024(%3,%0), %1 \n"\
  1918. "mov %5, %2 \n"\
  1919. "2: \n"\
  1920. "movaps (%1), %%xmm2 \n"\
  1921. stereo("movaps %%xmm2, %%xmm3 \n")\
  1922. "mulps (%4,%2), %%xmm2 \n"\
  1923. stereo("mulps 16(%4,%2), %%xmm3 \n")\
  1924. "addps %%xmm2, %%xmm0 \n"\
  1925. stereo("addps %%xmm3, %%xmm1 \n")\
  1926. "add $1024, %1 \n"\
  1927. "add $32, %2 \n"\
  1928. "jl 2b \n"\
  1929. "movaps %%xmm0, (%3,%0) \n"\
  1930. stereo("movaps %%xmm1, 1024(%3,%0) \n")\
  1931. "add $16, %0 \n"\
  1932. "jl 1b \n"\
  1933. :"+&r"(i), "=&r"(j), "=&r"(k)\
  1934. :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
  1935. :"memory"\
  1936. );
  1937. static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
  1938. {
  1939. int (*matrix_cmp)[2] = (int(*)[2])matrix;
  1940. intptr_t i,j,k;
  1941. i = -len*sizeof(float);
  1942. 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]))) {
  1943. MIX5(IF0,IF1);
  1944. } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
  1945. MIX5(IF1,IF0);
  1946. } else {
  1947. DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
  1948. j = 2*in_ch*sizeof(float);
  1949. __asm__ volatile(
  1950. "1: \n"
  1951. "sub $8, %0 \n"
  1952. "movss (%2,%0), %%xmm4 \n"
  1953. "movss 4(%2,%0), %%xmm5 \n"
  1954. "shufps $0, %%xmm4, %%xmm4 \n"
  1955. "shufps $0, %%xmm5, %%xmm5 \n"
  1956. "movaps %%xmm4, (%1,%0,4) \n"
  1957. "movaps %%xmm5, 16(%1,%0,4) \n"
  1958. "jg 1b \n"
  1959. :"+&r"(j)
  1960. :"r"(matrix_simd), "r"(matrix)
  1961. :"memory"
  1962. );
  1963. if(out_ch == 2) {
  1964. MIX_MISC(IF1);
  1965. } else {
  1966. MIX_MISC(IF0);
  1967. }
  1968. }
  1969. }
  1970. static void vector_fmul_3dnow(float *dst, const float *src0, const float *src1, int len){
  1971. x86_reg i = (len-4)*4;
  1972. __asm__ volatile(
  1973. "1: \n\t"
  1974. "movq (%2,%0), %%mm0 \n\t"
  1975. "movq 8(%2,%0), %%mm1 \n\t"
  1976. "pfmul (%3,%0), %%mm0 \n\t"
  1977. "pfmul 8(%3,%0), %%mm1 \n\t"
  1978. "movq %%mm0, (%1,%0) \n\t"
  1979. "movq %%mm1, 8(%1,%0) \n\t"
  1980. "sub $16, %0 \n\t"
  1981. "jge 1b \n\t"
  1982. "femms \n\t"
  1983. :"+r"(i)
  1984. :"r"(dst), "r"(src0), "r"(src1)
  1985. :"memory"
  1986. );
  1987. }
  1988. static void vector_fmul_sse(float *dst, const float *src0, const float *src1, int len){
  1989. x86_reg i = (len-8)*4;
  1990. __asm__ volatile(
  1991. "1: \n\t"
  1992. "movaps (%2,%0), %%xmm0 \n\t"
  1993. "movaps 16(%2,%0), %%xmm1 \n\t"
  1994. "mulps (%3,%0), %%xmm0 \n\t"
  1995. "mulps 16(%3,%0), %%xmm1 \n\t"
  1996. "movaps %%xmm0, (%1,%0) \n\t"
  1997. "movaps %%xmm1, 16(%1,%0) \n\t"
  1998. "sub $32, %0 \n\t"
  1999. "jge 1b \n\t"
  2000. :"+r"(i)
  2001. :"r"(dst), "r"(src0), "r"(src1)
  2002. :"memory"
  2003. );
  2004. }
  2005. static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
  2006. x86_reg i = len*4-16;
  2007. __asm__ volatile(
  2008. "1: \n\t"
  2009. "pswapd 8(%1), %%mm0 \n\t"
  2010. "pswapd (%1), %%mm1 \n\t"
  2011. "pfmul (%3,%0), %%mm0 \n\t"
  2012. "pfmul 8(%3,%0), %%mm1 \n\t"
  2013. "movq %%mm0, (%2,%0) \n\t"
  2014. "movq %%mm1, 8(%2,%0) \n\t"
  2015. "add $16, %1 \n\t"
  2016. "sub $16, %0 \n\t"
  2017. "jge 1b \n\t"
  2018. :"+r"(i), "+r"(src1)
  2019. :"r"(dst), "r"(src0)
  2020. );
  2021. __asm__ volatile("femms");
  2022. }
  2023. static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
  2024. x86_reg i = len*4-32;
  2025. __asm__ volatile(
  2026. "1: \n\t"
  2027. "movaps 16(%1), %%xmm0 \n\t"
  2028. "movaps (%1), %%xmm1 \n\t"
  2029. "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
  2030. "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
  2031. "mulps (%3,%0), %%xmm0 \n\t"
  2032. "mulps 16(%3,%0), %%xmm1 \n\t"
  2033. "movaps %%xmm0, (%2,%0) \n\t"
  2034. "movaps %%xmm1, 16(%2,%0) \n\t"
  2035. "add $32, %1 \n\t"
  2036. "sub $32, %0 \n\t"
  2037. "jge 1b \n\t"
  2038. :"+r"(i), "+r"(src1)
  2039. :"r"(dst), "r"(src0)
  2040. );
  2041. }
  2042. static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1,
  2043. const float *src2, int len){
  2044. x86_reg i = (len-4)*4;
  2045. __asm__ volatile(
  2046. "1: \n\t"
  2047. "movq (%2,%0), %%mm0 \n\t"
  2048. "movq 8(%2,%0), %%mm1 \n\t"
  2049. "pfmul (%3,%0), %%mm0 \n\t"
  2050. "pfmul 8(%3,%0), %%mm1 \n\t"
  2051. "pfadd (%4,%0), %%mm0 \n\t"
  2052. "pfadd 8(%4,%0), %%mm1 \n\t"
  2053. "movq %%mm0, (%1,%0) \n\t"
  2054. "movq %%mm1, 8(%1,%0) \n\t"
  2055. "sub $16, %0 \n\t"
  2056. "jge 1b \n\t"
  2057. :"+r"(i)
  2058. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2059. :"memory"
  2060. );
  2061. __asm__ volatile("femms");
  2062. }
  2063. static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
  2064. const float *src2, int len){
  2065. x86_reg i = (len-8)*4;
  2066. __asm__ volatile(
  2067. "1: \n\t"
  2068. "movaps (%2,%0), %%xmm0 \n\t"
  2069. "movaps 16(%2,%0), %%xmm1 \n\t"
  2070. "mulps (%3,%0), %%xmm0 \n\t"
  2071. "mulps 16(%3,%0), %%xmm1 \n\t"
  2072. "addps (%4,%0), %%xmm0 \n\t"
  2073. "addps 16(%4,%0), %%xmm1 \n\t"
  2074. "movaps %%xmm0, (%1,%0) \n\t"
  2075. "movaps %%xmm1, 16(%1,%0) \n\t"
  2076. "sub $32, %0 \n\t"
  2077. "jge 1b \n\t"
  2078. :"+r"(i)
  2079. :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
  2080. :"memory"
  2081. );
  2082. }
  2083. #if HAVE_6REGS
  2084. static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
  2085. const float *win, int len){
  2086. x86_reg i = -len*4;
  2087. x86_reg j = len*4-8;
  2088. __asm__ volatile(
  2089. "1: \n"
  2090. "pswapd (%5,%1), %%mm1 \n"
  2091. "movq (%5,%0), %%mm0 \n"
  2092. "pswapd (%4,%1), %%mm5 \n"
  2093. "movq (%3,%0), %%mm4 \n"
  2094. "movq %%mm0, %%mm2 \n"
  2095. "movq %%mm1, %%mm3 \n"
  2096. "pfmul %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
  2097. "pfmul %%mm5, %%mm3 \n" // src1[ j]*win[len+j]
  2098. "pfmul %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
  2099. "pfmul %%mm5, %%mm0 \n" // src1[ j]*win[len+i]
  2100. "pfadd %%mm3, %%mm2 \n"
  2101. "pfsub %%mm0, %%mm1 \n"
  2102. "pswapd %%mm2, %%mm2 \n"
  2103. "movq %%mm1, (%2,%0) \n"
  2104. "movq %%mm2, (%2,%1) \n"
  2105. "sub $8, %1 \n"
  2106. "add $8, %0 \n"
  2107. "jl 1b \n"
  2108. "femms \n"
  2109. :"+r"(i), "+r"(j)
  2110. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2111. );
  2112. }
  2113. static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
  2114. const float *win, int len){
  2115. x86_reg i = -len*4;
  2116. x86_reg j = len*4-16;
  2117. __asm__ volatile(
  2118. "1: \n"
  2119. "movaps (%5,%1), %%xmm1 \n"
  2120. "movaps (%5,%0), %%xmm0 \n"
  2121. "movaps (%4,%1), %%xmm5 \n"
  2122. "movaps (%3,%0), %%xmm4 \n"
  2123. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  2124. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  2125. "movaps %%xmm0, %%xmm2 \n"
  2126. "movaps %%xmm1, %%xmm3 \n"
  2127. "mulps %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
  2128. "mulps %%xmm5, %%xmm3 \n" // src1[ j]*win[len+j]
  2129. "mulps %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
  2130. "mulps %%xmm5, %%xmm0 \n" // src1[ j]*win[len+i]
  2131. "addps %%xmm3, %%xmm2 \n"
  2132. "subps %%xmm0, %%xmm1 \n"
  2133. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  2134. "movaps %%xmm1, (%2,%0) \n"
  2135. "movaps %%xmm2, (%2,%1) \n"
  2136. "sub $16, %1 \n"
  2137. "add $16, %0 \n"
  2138. "jl 1b \n"
  2139. :"+r"(i), "+r"(j)
  2140. :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
  2141. );
  2142. }
  2143. #endif /* HAVE_6REGS */
  2144. static void vector_clipf_sse(float *dst, const float *src, float min, float max,
  2145. int len)
  2146. {
  2147. x86_reg i = (len-16)*4;
  2148. __asm__ volatile(
  2149. "movss %3, %%xmm4 \n"
  2150. "movss %4, %%xmm5 \n"
  2151. "shufps $0, %%xmm4, %%xmm4 \n"
  2152. "shufps $0, %%xmm5, %%xmm5 \n"
  2153. "1: \n\t"
  2154. "movaps (%2,%0), %%xmm0 \n\t" // 3/1 on intel
  2155. "movaps 16(%2,%0), %%xmm1 \n\t"
  2156. "movaps 32(%2,%0), %%xmm2 \n\t"
  2157. "movaps 48(%2,%0), %%xmm3 \n\t"
  2158. "maxps %%xmm4, %%xmm0 \n\t"
  2159. "maxps %%xmm4, %%xmm1 \n\t"
  2160. "maxps %%xmm4, %%xmm2 \n\t"
  2161. "maxps %%xmm4, %%xmm3 \n\t"
  2162. "minps %%xmm5, %%xmm0 \n\t"
  2163. "minps %%xmm5, %%xmm1 \n\t"
  2164. "minps %%xmm5, %%xmm2 \n\t"
  2165. "minps %%xmm5, %%xmm3 \n\t"
  2166. "movaps %%xmm0, (%1,%0) \n\t"
  2167. "movaps %%xmm1, 16(%1,%0) \n\t"
  2168. "movaps %%xmm2, 32(%1,%0) \n\t"
  2169. "movaps %%xmm3, 48(%1,%0) \n\t"
  2170. "sub $64, %0 \n\t"
  2171. "jge 1b \n\t"
  2172. :"+&r"(i)
  2173. :"r"(dst), "r"(src), "m"(min), "m"(max)
  2174. :"memory"
  2175. );
  2176. }
  2177. void ff_vp3_idct_mmx(int16_t *input_data);
  2178. void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
  2179. void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
  2180. void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block);
  2181. void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
  2182. void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
  2183. void ff_vp3_idct_sse2(int16_t *input_data);
  2184. void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
  2185. void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
  2186. int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2, int order, int shift);
  2187. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2, int order, int shift);
  2188. int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2189. int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2190. int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
  2191. void ff_apply_window_int16_mmxext (int16_t *output, const int16_t *input,
  2192. const int16_t *window, unsigned int len);
  2193. void ff_apply_window_int16_mmxext_ba (int16_t *output, const int16_t *input,
  2194. const int16_t *window, unsigned int len);
  2195. void ff_apply_window_int16_sse2 (int16_t *output, const int16_t *input,
  2196. const int16_t *window, unsigned int len);
  2197. void ff_apply_window_int16_sse2_ba (int16_t *output, const int16_t *input,
  2198. const int16_t *window, unsigned int len);
  2199. void ff_apply_window_int16_ssse3 (int16_t *output, const int16_t *input,
  2200. const int16_t *window, unsigned int len);
  2201. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  2202. const int16_t *window, unsigned int len);
  2203. 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);
  2204. int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left);
  2205. int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left);
  2206. float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
  2207. void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src, int32_t min,
  2208. int32_t max, unsigned int len);
  2209. void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src, int32_t min,
  2210. int32_t max, unsigned int len);
  2211. void ff_vector_clip_int32_sse2_int(int32_t *dst, const int32_t *src, int32_t min,
  2212. int32_t max, unsigned int len);
  2213. void ff_vector_clip_int32_sse41 (int32_t *dst, const int32_t *src, int32_t min,
  2214. int32_t max, unsigned int len);
  2215. void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
  2216. {
  2217. int mm_flags = av_get_cpu_flags();
  2218. const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
  2219. const int bit_depth = avctx->bits_per_raw_sample;
  2220. if (avctx->dsp_mask) {
  2221. if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
  2222. mm_flags |= (avctx->dsp_mask & 0xffff);
  2223. else
  2224. mm_flags &= ~(avctx->dsp_mask & 0xffff);
  2225. }
  2226. #if 0
  2227. av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
  2228. if (mm_flags & AV_CPU_FLAG_MMX)
  2229. av_log(avctx, AV_LOG_INFO, " mmx");
  2230. if (mm_flags & AV_CPU_FLAG_MMX2)
  2231. av_log(avctx, AV_LOG_INFO, " mmx2");
  2232. if (mm_flags & AV_CPU_FLAG_3DNOW)
  2233. av_log(avctx, AV_LOG_INFO, " 3dnow");
  2234. if (mm_flags & AV_CPU_FLAG_SSE)
  2235. av_log(avctx, AV_LOG_INFO, " sse");
  2236. if (mm_flags & AV_CPU_FLAG_SSE2)
  2237. av_log(avctx, AV_LOG_INFO, " sse2");
  2238. av_log(avctx, AV_LOG_INFO, "\n");
  2239. #endif
  2240. if (mm_flags & AV_CPU_FLAG_MMX) {
  2241. const int idct_algo= avctx->idct_algo;
  2242. if(avctx->lowres==0){
  2243. if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
  2244. c->idct_put= ff_simple_idct_put_mmx;
  2245. c->idct_add= ff_simple_idct_add_mmx;
  2246. c->idct = ff_simple_idct_mmx;
  2247. c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
  2248. #if CONFIG_GPL
  2249. }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
  2250. if(mm_flags & AV_CPU_FLAG_MMX2){
  2251. c->idct_put= ff_libmpeg2mmx2_idct_put;
  2252. c->idct_add= ff_libmpeg2mmx2_idct_add;
  2253. c->idct = ff_mmxext_idct;
  2254. }else{
  2255. c->idct_put= ff_libmpeg2mmx_idct_put;
  2256. c->idct_add= ff_libmpeg2mmx_idct_add;
  2257. c->idct = ff_mmx_idct;
  2258. }
  2259. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2260. #endif
  2261. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
  2262. idct_algo==FF_IDCT_VP3 && HAVE_YASM){
  2263. if(mm_flags & AV_CPU_FLAG_SSE2){
  2264. c->idct_put= ff_vp3_idct_put_sse2;
  2265. c->idct_add= ff_vp3_idct_add_sse2;
  2266. c->idct = ff_vp3_idct_sse2;
  2267. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2268. }else{
  2269. c->idct_put= ff_vp3_idct_put_mmx;
  2270. c->idct_add= ff_vp3_idct_add_mmx;
  2271. c->idct = ff_vp3_idct_mmx;
  2272. c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
  2273. }
  2274. }else if(idct_algo==FF_IDCT_CAVS){
  2275. c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
  2276. }else if(idct_algo==FF_IDCT_XVIDMMX){
  2277. if(mm_flags & AV_CPU_FLAG_SSE2){
  2278. c->idct_put= ff_idct_xvid_sse2_put;
  2279. c->idct_add= ff_idct_xvid_sse2_add;
  2280. c->idct = ff_idct_xvid_sse2;
  2281. c->idct_permutation_type= FF_SSE2_IDCT_PERM;
  2282. }else if(mm_flags & AV_CPU_FLAG_MMX2){
  2283. c->idct_put= ff_idct_xvid_mmx2_put;
  2284. c->idct_add= ff_idct_xvid_mmx2_add;
  2285. c->idct = ff_idct_xvid_mmx2;
  2286. }else{
  2287. c->idct_put= ff_idct_xvid_mmx_put;
  2288. c->idct_add= ff_idct_xvid_mmx_add;
  2289. c->idct = ff_idct_xvid_mmx;
  2290. }
  2291. }
  2292. }
  2293. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  2294. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  2295. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  2296. if (!high_bit_depth) {
  2297. c->clear_block = clear_block_mmx;
  2298. c->clear_blocks = clear_blocks_mmx;
  2299. if ((mm_flags & AV_CPU_FLAG_SSE) &&
  2300. !(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){
  2301. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  2302. c->clear_block = clear_block_sse;
  2303. c->clear_blocks = clear_blocks_sse;
  2304. }
  2305. }
  2306. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  2307. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  2308. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  2309. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  2310. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
  2311. if (!high_bit_depth) {
  2312. SET_HPEL_FUNCS(put, 0, 16, mmx);
  2313. SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
  2314. SET_HPEL_FUNCS(avg, 0, 16, mmx);
  2315. SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
  2316. SET_HPEL_FUNCS(put, 1, 8, mmx);
  2317. SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
  2318. SET_HPEL_FUNCS(avg, 1, 8, mmx);
  2319. SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
  2320. }
  2321. #if ARCH_X86_32 || !HAVE_YASM
  2322. c->gmc= gmc_mmx;
  2323. #endif
  2324. #if ARCH_X86_32 && HAVE_YASM
  2325. if (!high_bit_depth)
  2326. c->emulated_edge_mc = emulated_edge_mc_mmx;
  2327. #endif
  2328. c->add_bytes= add_bytes_mmx;
  2329. if (!high_bit_depth)
  2330. c->draw_edges = draw_edges_mmx;
  2331. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2332. c->h263_v_loop_filter= h263_v_loop_filter_mmx;
  2333. c->h263_h_loop_filter= h263_h_loop_filter_mmx;
  2334. }
  2335. #if HAVE_YASM
  2336. if (!high_bit_depth) {
  2337. c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_mmx_rnd;
  2338. c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_mmx;
  2339. }
  2340. c->put_rv40_chroma_pixels_tab[0]= ff_put_rv40_chroma_mc8_mmx;
  2341. c->put_rv40_chroma_pixels_tab[1]= ff_put_rv40_chroma_mc4_mmx;
  2342. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  2343. #endif
  2344. if (mm_flags & AV_CPU_FLAG_MMX2) {
  2345. c->prefetch = prefetch_mmx2;
  2346. if (!high_bit_depth) {
  2347. c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
  2348. c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
  2349. c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
  2350. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
  2351. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
  2352. c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
  2353. c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
  2354. c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
  2355. c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
  2356. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
  2357. }
  2358. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2359. if (!high_bit_depth) {
  2360. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
  2361. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
  2362. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
  2363. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
  2364. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
  2365. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
  2366. }
  2367. if (CONFIG_VP3_DECODER && HAVE_YASM) {
  2368. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
  2369. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
  2370. }
  2371. }
  2372. if (CONFIG_VP3_DECODER && HAVE_YASM) {
  2373. c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
  2374. }
  2375. if (CONFIG_VP3_DECODER
  2376. && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
  2377. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
  2378. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
  2379. }
  2380. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  2381. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  2382. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  2383. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  2384. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  2385. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  2386. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  2387. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  2388. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  2389. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  2390. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  2391. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  2392. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  2393. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  2394. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  2395. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  2396. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU
  2397. SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2, );
  2398. SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2, );
  2399. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2, );
  2400. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2, );
  2401. SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2, );
  2402. SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2, );
  2403. if (!high_bit_depth) {
  2404. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2, );
  2405. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2, );
  2406. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2, );
  2407. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2, );
  2408. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2, );
  2409. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2, );
  2410. }
  2411. else if (bit_depth == 10) {
  2412. #if HAVE_YASM
  2413. #if !ARCH_X86_64
  2414. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
  2415. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
  2416. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
  2417. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
  2418. #endif
  2419. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
  2420. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
  2421. #endif
  2422. }
  2423. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2, );
  2424. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2, );
  2425. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2, );
  2426. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2, );
  2427. #if HAVE_YASM
  2428. c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_mmx2;
  2429. c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_mmx2;
  2430. if (!high_bit_depth) {
  2431. c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_mmx2_rnd;
  2432. c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_mmx2;
  2433. c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_mmx2;
  2434. c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_mmx2;
  2435. }
  2436. if (bit_depth == 10) {
  2437. c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_10_mmxext;
  2438. c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_10_mmxext;
  2439. c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_10_mmxext;
  2440. c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_10_mmxext;
  2441. }
  2442. c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
  2443. #endif
  2444. #if HAVE_7REGS
  2445. if( mm_flags&AV_CPU_FLAG_3DNOW )
  2446. c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
  2447. #endif
  2448. } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
  2449. c->prefetch = prefetch_3dnow;
  2450. if (!high_bit_depth) {
  2451. c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
  2452. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  2453. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  2454. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  2455. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  2456. c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
  2457. c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
  2458. c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
  2459. c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
  2460. c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
  2461. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  2462. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  2463. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  2464. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
  2465. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
  2466. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  2467. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
  2468. }
  2469. }
  2470. if (CONFIG_VP3_DECODER
  2471. && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
  2472. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
  2473. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
  2474. }
  2475. SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow, );
  2476. SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow, );
  2477. SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow, );
  2478. SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow, );
  2479. SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow, );
  2480. SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow, );
  2481. if (!high_bit_depth) {
  2482. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow, );
  2483. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow, );
  2484. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow, );
  2485. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow, );
  2486. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow, );
  2487. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow, );
  2488. }
  2489. SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow, );
  2490. SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow, );
  2491. SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow, );
  2492. SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow, );
  2493. #if HAVE_YASM
  2494. if (!high_bit_depth) {
  2495. c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_3dnow_rnd;
  2496. c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_3dnow;
  2497. }
  2498. c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_3dnow;
  2499. c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_3dnow;
  2500. #endif
  2501. }
  2502. #define H264_QPEL_FUNCS(x, y, CPU)\
  2503. c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\
  2504. c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\
  2505. c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\
  2506. c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU;
  2507. if((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW)){
  2508. // these functions are slower than mmx on AMD, but faster on Intel
  2509. if (!high_bit_depth) {
  2510. c->put_pixels_tab[0][0] = put_pixels16_sse2;
  2511. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2;
  2512. c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
  2513. H264_QPEL_FUNCS(0, 0, sse2);
  2514. }
  2515. }
  2516. if(mm_flags & AV_CPU_FLAG_SSE2){
  2517. if (!high_bit_depth) {
  2518. H264_QPEL_FUNCS(0, 1, sse2);
  2519. H264_QPEL_FUNCS(0, 2, sse2);
  2520. H264_QPEL_FUNCS(0, 3, sse2);
  2521. H264_QPEL_FUNCS(1, 1, sse2);
  2522. H264_QPEL_FUNCS(1, 2, sse2);
  2523. H264_QPEL_FUNCS(1, 3, sse2);
  2524. H264_QPEL_FUNCS(2, 1, sse2);
  2525. H264_QPEL_FUNCS(2, 2, sse2);
  2526. H264_QPEL_FUNCS(2, 3, sse2);
  2527. H264_QPEL_FUNCS(3, 1, sse2);
  2528. H264_QPEL_FUNCS(3, 2, sse2);
  2529. H264_QPEL_FUNCS(3, 3, sse2);
  2530. }
  2531. #if HAVE_YASM
  2532. #define H264_QPEL_FUNCS_10(x, y, CPU)\
  2533. c->put_h264_qpel_pixels_tab[0][x+y*4] = ff_put_h264_qpel16_mc##x##y##_10_##CPU;\
  2534. c->put_h264_qpel_pixels_tab[1][x+y*4] = ff_put_h264_qpel8_mc##x##y##_10_##CPU;\
  2535. c->avg_h264_qpel_pixels_tab[0][x+y*4] = ff_avg_h264_qpel16_mc##x##y##_10_##CPU;\
  2536. c->avg_h264_qpel_pixels_tab[1][x+y*4] = ff_avg_h264_qpel8_mc##x##y##_10_##CPU;
  2537. if (bit_depth == 10) {
  2538. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
  2539. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
  2540. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
  2541. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
  2542. H264_QPEL_FUNCS_10(1, 0, sse2_cache64)
  2543. H264_QPEL_FUNCS_10(2, 0, sse2_cache64)
  2544. H264_QPEL_FUNCS_10(3, 0, sse2_cache64)
  2545. c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_10_sse2;
  2546. c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_10_sse2;
  2547. }
  2548. #endif
  2549. }
  2550. #if HAVE_SSSE3
  2551. if(mm_flags & AV_CPU_FLAG_SSSE3){
  2552. if (!high_bit_depth) {
  2553. H264_QPEL_FUNCS(1, 0, ssse3);
  2554. H264_QPEL_FUNCS(1, 1, ssse3);
  2555. H264_QPEL_FUNCS(1, 2, ssse3);
  2556. H264_QPEL_FUNCS(1, 3, ssse3);
  2557. H264_QPEL_FUNCS(2, 0, ssse3);
  2558. H264_QPEL_FUNCS(2, 1, ssse3);
  2559. H264_QPEL_FUNCS(2, 2, ssse3);
  2560. H264_QPEL_FUNCS(2, 3, ssse3);
  2561. H264_QPEL_FUNCS(3, 0, ssse3);
  2562. H264_QPEL_FUNCS(3, 1, ssse3);
  2563. H264_QPEL_FUNCS(3, 2, ssse3);
  2564. H264_QPEL_FUNCS(3, 3, ssse3);
  2565. }
  2566. #if HAVE_YASM
  2567. else if (bit_depth == 10) {
  2568. H264_QPEL_FUNCS_10(1, 0, ssse3_cache64)
  2569. H264_QPEL_FUNCS_10(2, 0, ssse3_cache64)
  2570. H264_QPEL_FUNCS_10(3, 0, ssse3_cache64)
  2571. }
  2572. if (!high_bit_depth) {
  2573. c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_ssse3_rnd;
  2574. c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_ssse3_rnd;
  2575. c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_ssse3;
  2576. c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_ssse3;
  2577. }
  2578. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
  2579. if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
  2580. c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
  2581. #endif
  2582. }
  2583. #endif
  2584. if(mm_flags & AV_CPU_FLAG_3DNOW){
  2585. c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
  2586. c->vector_fmul = vector_fmul_3dnow;
  2587. }
  2588. if(mm_flags & AV_CPU_FLAG_3DNOWEXT){
  2589. c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
  2590. #if HAVE_6REGS
  2591. c->vector_fmul_window = vector_fmul_window_3dnow2;
  2592. #endif
  2593. }
  2594. if(mm_flags & AV_CPU_FLAG_MMX2){
  2595. #if HAVE_YASM
  2596. c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
  2597. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
  2598. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2599. c->apply_window_int16 = ff_apply_window_int16_mmxext_ba;
  2600. } else {
  2601. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  2602. }
  2603. #endif
  2604. }
  2605. if(mm_flags & AV_CPU_FLAG_SSE){
  2606. c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
  2607. c->ac3_downmix = ac3_downmix_sse;
  2608. c->vector_fmul = vector_fmul_sse;
  2609. c->vector_fmul_reverse = vector_fmul_reverse_sse;
  2610. c->vector_fmul_add = vector_fmul_add_sse;
  2611. #if HAVE_6REGS
  2612. c->vector_fmul_window = vector_fmul_window_sse;
  2613. #endif
  2614. c->vector_clipf = vector_clipf_sse;
  2615. #if HAVE_YASM
  2616. c->scalarproduct_float = ff_scalarproduct_float_sse;
  2617. #endif
  2618. }
  2619. if(mm_flags & AV_CPU_FLAG_3DNOW)
  2620. c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse
  2621. if(mm_flags & AV_CPU_FLAG_SSE2){
  2622. #if HAVE_YASM
  2623. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  2624. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
  2625. if (mm_flags & AV_CPU_FLAG_ATOM) {
  2626. c->vector_clip_int32 = ff_vector_clip_int32_sse2_int;
  2627. } else {
  2628. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  2629. }
  2630. if (avctx->flags & CODEC_FLAG_BITEXACT) {
  2631. c->apply_window_int16 = ff_apply_window_int16_sse2_ba;
  2632. } else {
  2633. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  2634. c->apply_window_int16 = ff_apply_window_int16_sse2;
  2635. }
  2636. }
  2637. if (!high_bit_depth)
  2638. c->emulated_edge_mc = emulated_edge_mc_sse;
  2639. c->gmc= gmc_sse;
  2640. #endif
  2641. }
  2642. if (mm_flags & AV_CPU_FLAG_SSSE3) {
  2643. #if HAVE_YASM
  2644. if (mm_flags & AV_CPU_FLAG_ATOM) {
  2645. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  2646. } else {
  2647. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  2648. }
  2649. if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) { // cachesplit
  2650. c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
  2651. }
  2652. #endif
  2653. }
  2654. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
  2655. #if HAVE_YASM
  2656. c->vector_clip_int32 = ff_vector_clip_int32_sse41;
  2657. #endif
  2658. }
  2659. #if HAVE_AVX && HAVE_YASM
  2660. if (mm_flags & AV_CPU_FLAG_AVX) {
  2661. if (bit_depth == 10) {
  2662. //AVX implies !cache64.
  2663. //TODO: Port cache(32|64) detection from x264.
  2664. H264_QPEL_FUNCS_10(1, 0, sse2)
  2665. H264_QPEL_FUNCS_10(2, 0, sse2)
  2666. H264_QPEL_FUNCS_10(3, 0, sse2)
  2667. c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_10_avx;
  2668. c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_10_avx;
  2669. }
  2670. }
  2671. #endif
  2672. }
  2673. if (CONFIG_ENCODERS)
  2674. dsputilenc_init_mmx(c, avctx);
  2675. #if 0
  2676. // for speed testing
  2677. get_pixels = just_return;
  2678. put_pixels_clamped = just_return;
  2679. add_pixels_clamped = just_return;
  2680. pix_abs16x16 = just_return;
  2681. pix_abs16x16_x2 = just_return;
  2682. pix_abs16x16_y2 = just_return;
  2683. pix_abs16x16_xy2 = just_return;
  2684. put_pixels_tab[0] = just_return;
  2685. put_pixels_tab[1] = just_return;
  2686. put_pixels_tab[2] = just_return;
  2687. put_pixels_tab[3] = just_return;
  2688. put_no_rnd_pixels_tab[0] = just_return;
  2689. put_no_rnd_pixels_tab[1] = just_return;
  2690. put_no_rnd_pixels_tab[2] = just_return;
  2691. put_no_rnd_pixels_tab[3] = just_return;
  2692. avg_pixels_tab[0] = just_return;
  2693. avg_pixels_tab[1] = just_return;
  2694. avg_pixels_tab[2] = just_return;
  2695. avg_pixels_tab[3] = just_return;
  2696. avg_no_rnd_pixels_tab[0] = just_return;
  2697. avg_no_rnd_pixels_tab[1] = just_return;
  2698. avg_no_rnd_pixels_tab[2] = just_return;
  2699. avg_no_rnd_pixels_tab[3] = just_return;
  2700. //av_fdct = just_return;
  2701. //ff_idct = just_return;
  2702. #endif
  2703. }