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.

2821 lines
117KB

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