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.

2959 lines
123KB

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