Libav 0.7.1
libavcodec/x86/dsputil_mmx.c
Go to the documentation of this file.
00001 /*
00002  * MMX optimized DSP utils
00003  * Copyright (c) 2000, 2001 Fabrice Bellard
00004  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  *
00022  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
00023  */
00024 
00025 #include "libavutil/cpu.h"
00026 #include "libavutil/x86_cpu.h"
00027 #include "libavcodec/dsputil.h"
00028 #include "libavcodec/h264dsp.h"
00029 #include "libavcodec/mpegvideo.h"
00030 #include "libavcodec/simple_idct.h"
00031 #include "libavcodec/ac3dec.h"
00032 #include "dsputil_mmx.h"
00033 #include "idct_xvid.h"
00034 
00035 //#undef NDEBUG
00036 //#include <assert.h>
00037 
00038 /* pixel operations */
00039 DECLARE_ALIGNED(8,  const uint64_t, ff_bone) = 0x0101010101010101ULL;
00040 DECLARE_ALIGNED(8,  const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
00041 
00042 DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
00043 {0x8000000080000000ULL, 0x8000000080000000ULL};
00044 
00045 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_1  ) = 0x0001000100010001ULL;
00046 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_2  ) = {0x0002000200020002ULL, 0x0002000200020002ULL};
00047 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_3  ) = {0x0003000300030003ULL, 0x0003000300030003ULL};
00048 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_4  ) = {0x0004000400040004ULL, 0x0004000400040004ULL};
00049 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_5  ) = {0x0005000500050005ULL, 0x0005000500050005ULL};
00050 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_8  ) = {0x0008000800080008ULL, 0x0008000800080008ULL};
00051 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_9  ) = {0x0009000900090009ULL, 0x0009000900090009ULL};
00052 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL;
00053 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL};
00054 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_17 ) = {0x0011001100110011ULL, 0x0011001100110011ULL};
00055 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_18 ) = {0x0012001200120012ULL, 0x0012001200120012ULL};
00056 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL;
00057 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_27 ) = {0x001B001B001B001BULL, 0x001B001B001B001BULL};
00058 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL};
00059 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL};
00060 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL;
00061 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_53 ) = 0x0035003500350035ULL;
00062 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_63 ) = {0x003F003F003F003FULL, 0x003F003F003F003FULL};
00063 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL};
00064 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
00065 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
00066 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
00067 
00068 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_0  ) = {0x0000000000000000ULL, 0x0000000000000000ULL};
00069 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_1  ) = {0x0101010101010101ULL, 0x0101010101010101ULL};
00070 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_3  ) = {0x0303030303030303ULL, 0x0303030303030303ULL};
00071 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_4  ) = {0x0404040404040404ULL, 0x0404040404040404ULL};
00072 DECLARE_ALIGNED(8,  const uint64_t, ff_pb_7  ) = 0x0707070707070707ULL;
00073 DECLARE_ALIGNED(8,  const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL;
00074 DECLARE_ALIGNED(8,  const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL;
00075 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_80 ) = {0x8080808080808080ULL, 0x8080808080808080ULL};
00076 DECLARE_ALIGNED(8,  const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL;
00077 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_A1 ) = {0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL};
00078 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_F8 ) = {0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL};
00079 DECLARE_ALIGNED(8,  const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL;
00080 DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_FE ) = {0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL};
00081 
00082 DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
00083 DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
00084 
00085 #define JUMPALIGN() __asm__ volatile (".p2align 3"::)
00086 #define MOVQ_ZERO(regd)  __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
00087 
00088 #define MOVQ_BFE(regd) \
00089     __asm__ volatile ( \
00090     "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
00091     "paddb %%" #regd ", %%" #regd " \n\t" ::)
00092 
00093 #ifndef PIC
00094 #define MOVQ_BONE(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
00095 #define MOVQ_WTWO(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
00096 #else
00097 // for shared library it's better to use this way for accessing constants
00098 // pcmpeqd -> -1
00099 #define MOVQ_BONE(regd) \
00100     __asm__ volatile ( \
00101     "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
00102     "psrlw $15, %%" #regd " \n\t" \
00103     "packuswb %%" #regd ", %%" #regd " \n\t" ::)
00104 
00105 #define MOVQ_WTWO(regd) \
00106     __asm__ volatile ( \
00107     "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
00108     "psrlw $15, %%" #regd " \n\t" \
00109     "psllw $1, %%" #regd " \n\t"::)
00110 
00111 #endif
00112 
00113 // using regr as temporary and for the output result
00114 // first argument is unmodifed and second is trashed
00115 // regfe is supposed to contain 0xfefefefefefefefe
00116 #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
00117     "movq " #rega ", " #regr "  \n\t"\
00118     "pand " #regb ", " #regr "  \n\t"\
00119     "pxor " #rega ", " #regb "  \n\t"\
00120     "pand " #regfe "," #regb "  \n\t"\
00121     "psrlq $1, " #regb "        \n\t"\
00122     "paddb " #regb ", " #regr " \n\t"
00123 
00124 #define PAVGB_MMX(rega, regb, regr, regfe) \
00125     "movq " #rega ", " #regr "  \n\t"\
00126     "por  " #regb ", " #regr "  \n\t"\
00127     "pxor " #rega ", " #regb "  \n\t"\
00128     "pand " #regfe "," #regb "  \n\t"\
00129     "psrlq $1, " #regb "        \n\t"\
00130     "psubb " #regb ", " #regr " \n\t"
00131 
00132 // mm6 is supposed to contain 0xfefefefefefefefe
00133 #define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp) \
00134     "movq " #rega ", " #regr "  \n\t"\
00135     "movq " #regc ", " #regp "  \n\t"\
00136     "pand " #regb ", " #regr "  \n\t"\
00137     "pand " #regd ", " #regp "  \n\t"\
00138     "pxor " #rega ", " #regb "  \n\t"\
00139     "pxor " #regc ", " #regd "  \n\t"\
00140     "pand %%mm6, " #regb "      \n\t"\
00141     "pand %%mm6, " #regd "      \n\t"\
00142     "psrlq $1, " #regb "        \n\t"\
00143     "psrlq $1, " #regd "        \n\t"\
00144     "paddb " #regb ", " #regr " \n\t"\
00145     "paddb " #regd ", " #regp " \n\t"
00146 
00147 #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
00148     "movq " #rega ", " #regr "  \n\t"\
00149     "movq " #regc ", " #regp "  \n\t"\
00150     "por  " #regb ", " #regr "  \n\t"\
00151     "por  " #regd ", " #regp "  \n\t"\
00152     "pxor " #rega ", " #regb "  \n\t"\
00153     "pxor " #regc ", " #regd "  \n\t"\
00154     "pand %%mm6, " #regb "      \n\t"\
00155     "pand %%mm6, " #regd "      \n\t"\
00156     "psrlq $1, " #regd "        \n\t"\
00157     "psrlq $1, " #regb "        \n\t"\
00158     "psubb " #regb ", " #regr " \n\t"\
00159     "psubb " #regd ", " #regp " \n\t"
00160 
00161 /***********************************/
00162 /* MMX no rounding */
00163 #define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
00164 #define SET_RND  MOVQ_WONE
00165 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
00166 #define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
00167 #define OP_AVG(a, b, c, e)              PAVGB_MMX(a, b, c, e)
00168 
00169 #include "dsputil_mmx_rnd_template.c"
00170 
00171 #undef DEF
00172 #undef SET_RND
00173 #undef PAVGBP
00174 #undef PAVGB
00175 /***********************************/
00176 /* MMX rounding */
00177 
00178 #define DEF(x, y) x ## _ ## y ##_mmx
00179 #define SET_RND  MOVQ_WTWO
00180 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
00181 #define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
00182 
00183 #include "dsputil_mmx_rnd_template.c"
00184 
00185 #undef DEF
00186 #undef SET_RND
00187 #undef PAVGBP
00188 #undef PAVGB
00189 #undef OP_AVG
00190 
00191 /***********************************/
00192 /* 3Dnow specific */
00193 
00194 #define DEF(x) x ## _3dnow
00195 #define PAVGB "pavgusb"
00196 #define OP_AVG PAVGB
00197 
00198 #include "dsputil_mmx_avg_template.c"
00199 
00200 #undef DEF
00201 #undef PAVGB
00202 #undef OP_AVG
00203 
00204 /***********************************/
00205 /* MMX2 specific */
00206 
00207 #define DEF(x) x ## _mmx2
00208 
00209 /* Introduced only in MMX2 set */
00210 #define PAVGB "pavgb"
00211 #define OP_AVG PAVGB
00212 
00213 #include "dsputil_mmx_avg_template.c"
00214 
00215 #undef DEF
00216 #undef PAVGB
00217 #undef OP_AVG
00218 
00219 #define put_no_rnd_pixels16_mmx put_pixels16_mmx
00220 #define put_no_rnd_pixels8_mmx put_pixels8_mmx
00221 #define put_pixels16_mmx2 put_pixels16_mmx
00222 #define put_pixels8_mmx2 put_pixels8_mmx
00223 #define put_pixels4_mmx2 put_pixels4_mmx
00224 #define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
00225 #define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
00226 #define put_pixels16_3dnow put_pixels16_mmx
00227 #define put_pixels8_3dnow put_pixels8_mmx
00228 #define put_pixels4_3dnow put_pixels4_mmx
00229 #define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
00230 #define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
00231 
00232 /***********************************/
00233 /* standard MMX */
00234 
00235 void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
00236 {
00237     const DCTELEM *p;
00238     uint8_t *pix;
00239 
00240     /* read the pixels */
00241     p = block;
00242     pix = pixels;
00243     /* unrolled loop */
00244         __asm__ volatile(
00245                 "movq   %3, %%mm0               \n\t"
00246                 "movq   8%3, %%mm1              \n\t"
00247                 "movq   16%3, %%mm2             \n\t"
00248                 "movq   24%3, %%mm3             \n\t"
00249                 "movq   32%3, %%mm4             \n\t"
00250                 "movq   40%3, %%mm5             \n\t"
00251                 "movq   48%3, %%mm6             \n\t"
00252                 "movq   56%3, %%mm7             \n\t"
00253                 "packuswb %%mm1, %%mm0          \n\t"
00254                 "packuswb %%mm3, %%mm2          \n\t"
00255                 "packuswb %%mm5, %%mm4          \n\t"
00256                 "packuswb %%mm7, %%mm6          \n\t"
00257                 "movq   %%mm0, (%0)             \n\t"
00258                 "movq   %%mm2, (%0, %1)         \n\t"
00259                 "movq   %%mm4, (%0, %1, 2)      \n\t"
00260                 "movq   %%mm6, (%0, %2)         \n\t"
00261                 ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
00262                 :"memory");
00263         pix += line_size*4;
00264         p += 32;
00265 
00266     // if here would be an exact copy of the code above
00267     // compiler would generate some very strange code
00268     // thus using "r"
00269     __asm__ volatile(
00270             "movq       (%3), %%mm0             \n\t"
00271             "movq       8(%3), %%mm1            \n\t"
00272             "movq       16(%3), %%mm2           \n\t"
00273             "movq       24(%3), %%mm3           \n\t"
00274             "movq       32(%3), %%mm4           \n\t"
00275             "movq       40(%3), %%mm5           \n\t"
00276             "movq       48(%3), %%mm6           \n\t"
00277             "movq       56(%3), %%mm7           \n\t"
00278             "packuswb %%mm1, %%mm0              \n\t"
00279             "packuswb %%mm3, %%mm2              \n\t"
00280             "packuswb %%mm5, %%mm4              \n\t"
00281             "packuswb %%mm7, %%mm6              \n\t"
00282             "movq       %%mm0, (%0)             \n\t"
00283             "movq       %%mm2, (%0, %1)         \n\t"
00284             "movq       %%mm4, (%0, %1, 2)      \n\t"
00285             "movq       %%mm6, (%0, %2)         \n\t"
00286             ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
00287             :"memory");
00288 }
00289 
00290 #define put_signed_pixels_clamped_mmx_half(off) \
00291             "movq    "#off"(%2), %%mm1          \n\t"\
00292             "movq 16+"#off"(%2), %%mm2          \n\t"\
00293             "movq 32+"#off"(%2), %%mm3          \n\t"\
00294             "movq 48+"#off"(%2), %%mm4          \n\t"\
00295             "packsswb  8+"#off"(%2), %%mm1      \n\t"\
00296             "packsswb 24+"#off"(%2), %%mm2      \n\t"\
00297             "packsswb 40+"#off"(%2), %%mm3      \n\t"\
00298             "packsswb 56+"#off"(%2), %%mm4      \n\t"\
00299             "paddb %%mm0, %%mm1                 \n\t"\
00300             "paddb %%mm0, %%mm2                 \n\t"\
00301             "paddb %%mm0, %%mm3                 \n\t"\
00302             "paddb %%mm0, %%mm4                 \n\t"\
00303             "movq %%mm1, (%0)                   \n\t"\
00304             "movq %%mm2, (%0, %3)               \n\t"\
00305             "movq %%mm3, (%0, %3, 2)            \n\t"\
00306             "movq %%mm4, (%0, %1)               \n\t"
00307 
00308 void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
00309 {
00310     x86_reg line_skip = line_size;
00311     x86_reg line_skip3;
00312 
00313     __asm__ volatile (
00314             "movq "MANGLE(ff_pb_80)", %%mm0 \n\t"
00315             "lea (%3, %3, 2), %1                \n\t"
00316             put_signed_pixels_clamped_mmx_half(0)
00317             "lea (%0, %3, 4), %0                \n\t"
00318             put_signed_pixels_clamped_mmx_half(64)
00319             :"+&r" (pixels), "=&r" (line_skip3)
00320             :"r" (block), "r"(line_skip)
00321             :"memory");
00322 }
00323 
00324 void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
00325 {
00326     const DCTELEM *p;
00327     uint8_t *pix;
00328     int i;
00329 
00330     /* read the pixels */
00331     p = block;
00332     pix = pixels;
00333     MOVQ_ZERO(mm7);
00334     i = 4;
00335     do {
00336         __asm__ volatile(
00337                 "movq   (%2), %%mm0     \n\t"
00338                 "movq   8(%2), %%mm1    \n\t"
00339                 "movq   16(%2), %%mm2   \n\t"
00340                 "movq   24(%2), %%mm3   \n\t"
00341                 "movq   %0, %%mm4       \n\t"
00342                 "movq   %1, %%mm6       \n\t"
00343                 "movq   %%mm4, %%mm5    \n\t"
00344                 "punpcklbw %%mm7, %%mm4 \n\t"
00345                 "punpckhbw %%mm7, %%mm5 \n\t"
00346                 "paddsw %%mm4, %%mm0    \n\t"
00347                 "paddsw %%mm5, %%mm1    \n\t"
00348                 "movq   %%mm6, %%mm5    \n\t"
00349                 "punpcklbw %%mm7, %%mm6 \n\t"
00350                 "punpckhbw %%mm7, %%mm5 \n\t"
00351                 "paddsw %%mm6, %%mm2    \n\t"
00352                 "paddsw %%mm5, %%mm3    \n\t"
00353                 "packuswb %%mm1, %%mm0  \n\t"
00354                 "packuswb %%mm3, %%mm2  \n\t"
00355                 "movq   %%mm0, %0       \n\t"
00356                 "movq   %%mm2, %1       \n\t"
00357                 :"+m"(*pix), "+m"(*(pix+line_size))
00358                 :"r"(p)
00359                 :"memory");
00360         pix += line_size*2;
00361         p += 16;
00362     } while (--i);
00363 }
00364 
00365 static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00366 {
00367     __asm__ volatile(
00368          "lea (%3, %3), %%"REG_a"       \n\t"
00369          ".p2align 3                    \n\t"
00370          "1:                            \n\t"
00371          "movd (%1), %%mm0              \n\t"
00372          "movd (%1, %3), %%mm1          \n\t"
00373          "movd %%mm0, (%2)              \n\t"
00374          "movd %%mm1, (%2, %3)          \n\t"
00375          "add %%"REG_a", %1             \n\t"
00376          "add %%"REG_a", %2             \n\t"
00377          "movd (%1), %%mm0              \n\t"
00378          "movd (%1, %3), %%mm1          \n\t"
00379          "movd %%mm0, (%2)              \n\t"
00380          "movd %%mm1, (%2, %3)          \n\t"
00381          "add %%"REG_a", %1             \n\t"
00382          "add %%"REG_a", %2             \n\t"
00383          "subl $4, %0                   \n\t"
00384          "jnz 1b                        \n\t"
00385          : "+g"(h), "+r" (pixels),  "+r" (block)
00386          : "r"((x86_reg)line_size)
00387          : "%"REG_a, "memory"
00388         );
00389 }
00390 
00391 static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00392 {
00393     __asm__ volatile(
00394          "lea (%3, %3), %%"REG_a"       \n\t"
00395          ".p2align 3                    \n\t"
00396          "1:                            \n\t"
00397          "movq (%1), %%mm0              \n\t"
00398          "movq (%1, %3), %%mm1          \n\t"
00399          "movq %%mm0, (%2)              \n\t"
00400          "movq %%mm1, (%2, %3)          \n\t"
00401          "add %%"REG_a", %1             \n\t"
00402          "add %%"REG_a", %2             \n\t"
00403          "movq (%1), %%mm0              \n\t"
00404          "movq (%1, %3), %%mm1          \n\t"
00405          "movq %%mm0, (%2)              \n\t"
00406          "movq %%mm1, (%2, %3)          \n\t"
00407          "add %%"REG_a", %1             \n\t"
00408          "add %%"REG_a", %2             \n\t"
00409          "subl $4, %0                   \n\t"
00410          "jnz 1b                        \n\t"
00411          : "+g"(h), "+r" (pixels),  "+r" (block)
00412          : "r"((x86_reg)line_size)
00413          : "%"REG_a, "memory"
00414         );
00415 }
00416 
00417 static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00418 {
00419     __asm__ volatile(
00420          "lea (%3, %3), %%"REG_a"       \n\t"
00421          ".p2align 3                    \n\t"
00422          "1:                            \n\t"
00423          "movq (%1), %%mm0              \n\t"
00424          "movq 8(%1), %%mm4             \n\t"
00425          "movq (%1, %3), %%mm1          \n\t"
00426          "movq 8(%1, %3), %%mm5         \n\t"
00427          "movq %%mm0, (%2)              \n\t"
00428          "movq %%mm4, 8(%2)             \n\t"
00429          "movq %%mm1, (%2, %3)          \n\t"
00430          "movq %%mm5, 8(%2, %3)         \n\t"
00431          "add %%"REG_a", %1             \n\t"
00432          "add %%"REG_a", %2             \n\t"
00433          "movq (%1), %%mm0              \n\t"
00434          "movq 8(%1), %%mm4             \n\t"
00435          "movq (%1, %3), %%mm1          \n\t"
00436          "movq 8(%1, %3), %%mm5         \n\t"
00437          "movq %%mm0, (%2)              \n\t"
00438          "movq %%mm4, 8(%2)             \n\t"
00439          "movq %%mm1, (%2, %3)          \n\t"
00440          "movq %%mm5, 8(%2, %3)         \n\t"
00441          "add %%"REG_a", %1             \n\t"
00442          "add %%"REG_a", %2             \n\t"
00443          "subl $4, %0                   \n\t"
00444          "jnz 1b                        \n\t"
00445          : "+g"(h), "+r" (pixels),  "+r" (block)
00446          : "r"((x86_reg)line_size)
00447          : "%"REG_a, "memory"
00448         );
00449 }
00450 
00451 static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00452 {
00453     __asm__ volatile(
00454          "1:                            \n\t"
00455          "movdqu (%1), %%xmm0           \n\t"
00456          "movdqu (%1,%3), %%xmm1        \n\t"
00457          "movdqu (%1,%3,2), %%xmm2      \n\t"
00458          "movdqu (%1,%4), %%xmm3        \n\t"
00459          "movdqa %%xmm0, (%2)           \n\t"
00460          "movdqa %%xmm1, (%2,%3)        \n\t"
00461          "movdqa %%xmm2, (%2,%3,2)      \n\t"
00462          "movdqa %%xmm3, (%2,%4)        \n\t"
00463          "subl $4, %0                   \n\t"
00464          "lea (%1,%3,4), %1             \n\t"
00465          "lea (%2,%3,4), %2             \n\t"
00466          "jnz 1b                        \n\t"
00467          : "+g"(h), "+r" (pixels),  "+r" (block)
00468          : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
00469          : "memory"
00470         );
00471 }
00472 
00473 static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00474 {
00475     __asm__ volatile(
00476          "1:                            \n\t"
00477          "movdqu (%1), %%xmm0           \n\t"
00478          "movdqu (%1,%3), %%xmm1        \n\t"
00479          "movdqu (%1,%3,2), %%xmm2      \n\t"
00480          "movdqu (%1,%4), %%xmm3        \n\t"
00481          "pavgb  (%2), %%xmm0           \n\t"
00482          "pavgb  (%2,%3), %%xmm1        \n\t"
00483          "pavgb  (%2,%3,2), %%xmm2      \n\t"
00484          "pavgb  (%2,%4), %%xmm3        \n\t"
00485          "movdqa %%xmm0, (%2)           \n\t"
00486          "movdqa %%xmm1, (%2,%3)        \n\t"
00487          "movdqa %%xmm2, (%2,%3,2)      \n\t"
00488          "movdqa %%xmm3, (%2,%4)        \n\t"
00489          "subl $4, %0                   \n\t"
00490          "lea (%1,%3,4), %1             \n\t"
00491          "lea (%2,%3,4), %2             \n\t"
00492          "jnz 1b                        \n\t"
00493          : "+g"(h), "+r" (pixels),  "+r" (block)
00494          : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
00495          : "memory"
00496         );
00497 }
00498 
00499 #define CLEAR_BLOCKS(name,n) \
00500 static void name(DCTELEM *blocks)\
00501 {\
00502     __asm__ volatile(\
00503                 "pxor %%mm7, %%mm7              \n\t"\
00504                 "mov     %1, %%"REG_a"          \n\t"\
00505                 "1:                             \n\t"\
00506                 "movq %%mm7, (%0, %%"REG_a")    \n\t"\
00507                 "movq %%mm7, 8(%0, %%"REG_a")   \n\t"\
00508                 "movq %%mm7, 16(%0, %%"REG_a")  \n\t"\
00509                 "movq %%mm7, 24(%0, %%"REG_a")  \n\t"\
00510                 "add $32, %%"REG_a"             \n\t"\
00511                 " js 1b                         \n\t"\
00512                 : : "r" (((uint8_t *)blocks)+128*n),\
00513                     "i" (-128*n)\
00514                 : "%"REG_a\
00515         );\
00516 }
00517 CLEAR_BLOCKS(clear_blocks_mmx, 6)
00518 CLEAR_BLOCKS(clear_block_mmx, 1)
00519 
00520 static void clear_block_sse(DCTELEM *block)
00521 {
00522     __asm__ volatile(
00523         "xorps  %%xmm0, %%xmm0  \n"
00524         "movaps %%xmm0,    (%0) \n"
00525         "movaps %%xmm0,  16(%0) \n"
00526         "movaps %%xmm0,  32(%0) \n"
00527         "movaps %%xmm0,  48(%0) \n"
00528         "movaps %%xmm0,  64(%0) \n"
00529         "movaps %%xmm0,  80(%0) \n"
00530         "movaps %%xmm0,  96(%0) \n"
00531         "movaps %%xmm0, 112(%0) \n"
00532         :: "r"(block)
00533         : "memory"
00534     );
00535 }
00536 
00537 static void clear_blocks_sse(DCTELEM *blocks)
00538 {\
00539     __asm__ volatile(
00540         "xorps  %%xmm0, %%xmm0  \n"
00541         "mov     %1, %%"REG_a"  \n"
00542         "1:                     \n"
00543         "movaps %%xmm0,    (%0, %%"REG_a") \n"
00544         "movaps %%xmm0,  16(%0, %%"REG_a") \n"
00545         "movaps %%xmm0,  32(%0, %%"REG_a") \n"
00546         "movaps %%xmm0,  48(%0, %%"REG_a") \n"
00547         "movaps %%xmm0,  64(%0, %%"REG_a") \n"
00548         "movaps %%xmm0,  80(%0, %%"REG_a") \n"
00549         "movaps %%xmm0,  96(%0, %%"REG_a") \n"
00550         "movaps %%xmm0, 112(%0, %%"REG_a") \n"
00551         "add $128, %%"REG_a"    \n"
00552         " js 1b                 \n"
00553         : : "r" (((uint8_t *)blocks)+128*6),
00554             "i" (-128*6)
00555         : "%"REG_a
00556     );
00557 }
00558 
00559 static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
00560     x86_reg i=0;
00561     __asm__ volatile(
00562         "jmp 2f                         \n\t"
00563         "1:                             \n\t"
00564         "movq  (%1, %0), %%mm0          \n\t"
00565         "movq  (%2, %0), %%mm1          \n\t"
00566         "paddb %%mm0, %%mm1             \n\t"
00567         "movq %%mm1, (%2, %0)           \n\t"
00568         "movq 8(%1, %0), %%mm0          \n\t"
00569         "movq 8(%2, %0), %%mm1          \n\t"
00570         "paddb %%mm0, %%mm1             \n\t"
00571         "movq %%mm1, 8(%2, %0)          \n\t"
00572         "add $16, %0                    \n\t"
00573         "2:                             \n\t"
00574         "cmp %3, %0                     \n\t"
00575         " js 1b                         \n\t"
00576         : "+r" (i)
00577         : "r"(src), "r"(dst), "r"((x86_reg)w-15)
00578     );
00579     for(; i<w; i++)
00580         dst[i+0] += src[i+0];
00581 }
00582 
00583 static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
00584     x86_reg i=0;
00585     __asm__ volatile(
00586         "jmp 2f                         \n\t"
00587         "1:                             \n\t"
00588         "movq   (%2, %0), %%mm0         \n\t"
00589         "movq  8(%2, %0), %%mm1         \n\t"
00590         "paddb  (%3, %0), %%mm0         \n\t"
00591         "paddb 8(%3, %0), %%mm1         \n\t"
00592         "movq %%mm0,  (%1, %0)          \n\t"
00593         "movq %%mm1, 8(%1, %0)          \n\t"
00594         "add $16, %0                    \n\t"
00595         "2:                             \n\t"
00596         "cmp %4, %0                     \n\t"
00597         " js 1b                         \n\t"
00598         : "+r" (i)
00599         : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
00600     );
00601     for(; i<w; i++)
00602         dst[i] = src1[i] + src2[i];
00603 }
00604 
00605 #if HAVE_7REGS && HAVE_TEN_OPERANDS
00606 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) {
00607     x86_reg w2 = -w;
00608     x86_reg x;
00609     int l = *left & 0xff;
00610     int tl = *left_top & 0xff;
00611     int t;
00612     __asm__ volatile(
00613         "mov    %7, %3 \n"
00614         "1: \n"
00615         "movzbl (%3,%4), %2 \n"
00616         "mov    %2, %k3 \n"
00617         "sub   %b1, %b3 \n"
00618         "add   %b0, %b3 \n"
00619         "mov    %2, %1 \n"
00620         "cmp    %0, %2 \n"
00621         "cmovg  %0, %2 \n"
00622         "cmovg  %1, %0 \n"
00623         "cmp   %k3, %0 \n"
00624         "cmovg %k3, %0 \n"
00625         "mov    %7, %3 \n"
00626         "cmp    %2, %0 \n"
00627         "cmovl  %2, %0 \n"
00628         "add (%6,%4), %b0 \n"
00629         "mov   %b0, (%5,%4) \n"
00630         "inc    %4 \n"
00631         "jl 1b \n"
00632         :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
00633         :"r"(dst+w), "r"(diff+w), "rm"(top+w)
00634     );
00635     *left = l;
00636     *left_top = tl;
00637 }
00638 #endif
00639 
00640 #define H263_LOOP_FILTER \
00641         "pxor %%mm7, %%mm7              \n\t"\
00642         "movq  %0, %%mm0                \n\t"\
00643         "movq  %0, %%mm1                \n\t"\
00644         "movq  %3, %%mm2                \n\t"\
00645         "movq  %3, %%mm3                \n\t"\
00646         "punpcklbw %%mm7, %%mm0         \n\t"\
00647         "punpckhbw %%mm7, %%mm1         \n\t"\
00648         "punpcklbw %%mm7, %%mm2         \n\t"\
00649         "punpckhbw %%mm7, %%mm3         \n\t"\
00650         "psubw %%mm2, %%mm0             \n\t"\
00651         "psubw %%mm3, %%mm1             \n\t"\
00652         "movq  %1, %%mm2                \n\t"\
00653         "movq  %1, %%mm3                \n\t"\
00654         "movq  %2, %%mm4                \n\t"\
00655         "movq  %2, %%mm5                \n\t"\
00656         "punpcklbw %%mm7, %%mm2         \n\t"\
00657         "punpckhbw %%mm7, %%mm3         \n\t"\
00658         "punpcklbw %%mm7, %%mm4         \n\t"\
00659         "punpckhbw %%mm7, %%mm5         \n\t"\
00660         "psubw %%mm2, %%mm4             \n\t"\
00661         "psubw %%mm3, %%mm5             \n\t"\
00662         "psllw $2, %%mm4                \n\t"\
00663         "psllw $2, %%mm5                \n\t"\
00664         "paddw %%mm0, %%mm4             \n\t"\
00665         "paddw %%mm1, %%mm5             \n\t"\
00666         "pxor %%mm6, %%mm6              \n\t"\
00667         "pcmpgtw %%mm4, %%mm6           \n\t"\
00668         "pcmpgtw %%mm5, %%mm7           \n\t"\
00669         "pxor %%mm6, %%mm4              \n\t"\
00670         "pxor %%mm7, %%mm5              \n\t"\
00671         "psubw %%mm6, %%mm4             \n\t"\
00672         "psubw %%mm7, %%mm5             \n\t"\
00673         "psrlw $3, %%mm4                \n\t"\
00674         "psrlw $3, %%mm5                \n\t"\
00675         "packuswb %%mm5, %%mm4          \n\t"\
00676         "packsswb %%mm7, %%mm6          \n\t"\
00677         "pxor %%mm7, %%mm7              \n\t"\
00678         "movd %4, %%mm2                 \n\t"\
00679         "punpcklbw %%mm2, %%mm2         \n\t"\
00680         "punpcklbw %%mm2, %%mm2         \n\t"\
00681         "punpcklbw %%mm2, %%mm2         \n\t"\
00682         "psubusb %%mm4, %%mm2           \n\t"\
00683         "movq %%mm2, %%mm3              \n\t"\
00684         "psubusb %%mm4, %%mm3           \n\t"\
00685         "psubb %%mm3, %%mm2             \n\t"\
00686         "movq %1, %%mm3                 \n\t"\
00687         "movq %2, %%mm4                 \n\t"\
00688         "pxor %%mm6, %%mm3              \n\t"\
00689         "pxor %%mm6, %%mm4              \n\t"\
00690         "paddusb %%mm2, %%mm3           \n\t"\
00691         "psubusb %%mm2, %%mm4           \n\t"\
00692         "pxor %%mm6, %%mm3              \n\t"\
00693         "pxor %%mm6, %%mm4              \n\t"\
00694         "paddusb %%mm2, %%mm2           \n\t"\
00695         "packsswb %%mm1, %%mm0          \n\t"\
00696         "pcmpgtb %%mm0, %%mm7           \n\t"\
00697         "pxor %%mm7, %%mm0              \n\t"\
00698         "psubb %%mm7, %%mm0             \n\t"\
00699         "movq %%mm0, %%mm1              \n\t"\
00700         "psubusb %%mm2, %%mm0           \n\t"\
00701         "psubb %%mm0, %%mm1             \n\t"\
00702         "pand %5, %%mm1                 \n\t"\
00703         "psrlw $2, %%mm1                \n\t"\
00704         "pxor %%mm7, %%mm1              \n\t"\
00705         "psubb %%mm7, %%mm1             \n\t"\
00706         "movq %0, %%mm5                 \n\t"\
00707         "movq %3, %%mm6                 \n\t"\
00708         "psubb %%mm1, %%mm5             \n\t"\
00709         "paddb %%mm1, %%mm6             \n\t"
00710 
00711 static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
00712     if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
00713     const int strength= ff_h263_loop_filter_strength[qscale];
00714 
00715     __asm__ volatile(
00716 
00717         H263_LOOP_FILTER
00718 
00719         "movq %%mm3, %1                 \n\t"
00720         "movq %%mm4, %2                 \n\t"
00721         "movq %%mm5, %0                 \n\t"
00722         "movq %%mm6, %3                 \n\t"
00723         : "+m" (*(uint64_t*)(src - 2*stride)),
00724           "+m" (*(uint64_t*)(src - 1*stride)),
00725           "+m" (*(uint64_t*)(src + 0*stride)),
00726           "+m" (*(uint64_t*)(src + 1*stride))
00727         : "g" (2*strength), "m"(ff_pb_FC)
00728     );
00729     }
00730 }
00731 
00732 static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
00733     if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
00734     const int strength= ff_h263_loop_filter_strength[qscale];
00735     DECLARE_ALIGNED(8, uint64_t, temp)[4];
00736     uint8_t *btemp= (uint8_t*)temp;
00737 
00738     src -= 2;
00739 
00740     transpose4x4(btemp  , src           , 8, stride);
00741     transpose4x4(btemp+4, src + 4*stride, 8, stride);
00742     __asm__ volatile(
00743         H263_LOOP_FILTER // 5 3 4 6
00744 
00745         : "+m" (temp[0]),
00746           "+m" (temp[1]),
00747           "+m" (temp[2]),
00748           "+m" (temp[3])
00749         : "g" (2*strength), "m"(ff_pb_FC)
00750     );
00751 
00752     __asm__ volatile(
00753         "movq %%mm5, %%mm1              \n\t"
00754         "movq %%mm4, %%mm0              \n\t"
00755         "punpcklbw %%mm3, %%mm5         \n\t"
00756         "punpcklbw %%mm6, %%mm4         \n\t"
00757         "punpckhbw %%mm3, %%mm1         \n\t"
00758         "punpckhbw %%mm6, %%mm0         \n\t"
00759         "movq %%mm5, %%mm3              \n\t"
00760         "movq %%mm1, %%mm6              \n\t"
00761         "punpcklwd %%mm4, %%mm5         \n\t"
00762         "punpcklwd %%mm0, %%mm1         \n\t"
00763         "punpckhwd %%mm4, %%mm3         \n\t"
00764         "punpckhwd %%mm0, %%mm6         \n\t"
00765         "movd %%mm5, (%0)               \n\t"
00766         "punpckhdq %%mm5, %%mm5         \n\t"
00767         "movd %%mm5, (%0,%2)            \n\t"
00768         "movd %%mm3, (%0,%2,2)          \n\t"
00769         "punpckhdq %%mm3, %%mm3         \n\t"
00770         "movd %%mm3, (%0,%3)            \n\t"
00771         "movd %%mm1, (%1)               \n\t"
00772         "punpckhdq %%mm1, %%mm1         \n\t"
00773         "movd %%mm1, (%1,%2)            \n\t"
00774         "movd %%mm6, (%1,%2,2)          \n\t"
00775         "punpckhdq %%mm6, %%mm6         \n\t"
00776         "movd %%mm6, (%1,%3)            \n\t"
00777         :: "r" (src),
00778            "r" (src + 4*stride),
00779            "r" ((x86_reg)   stride ),
00780            "r" ((x86_reg)(3*stride))
00781     );
00782     }
00783 }
00784 
00785 /* draw the edges of width 'w' of an image of size width, height
00786    this mmx version can only handle w==8 || w==16 */
00787 static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides)
00788 {
00789     uint8_t *ptr, *last_line;
00790     int i;
00791 
00792     last_line = buf + (height - 1) * wrap;
00793     /* left and right */
00794     ptr = buf;
00795     if(w==8)
00796     {
00797         __asm__ volatile(
00798                 "1:                             \n\t"
00799                 "movd (%0), %%mm0               \n\t"
00800                 "punpcklbw %%mm0, %%mm0         \n\t"
00801                 "punpcklwd %%mm0, %%mm0         \n\t"
00802                 "punpckldq %%mm0, %%mm0         \n\t"
00803                 "movq %%mm0, -8(%0)             \n\t"
00804                 "movq -8(%0, %2), %%mm1         \n\t"
00805                 "punpckhbw %%mm1, %%mm1         \n\t"
00806                 "punpckhwd %%mm1, %%mm1         \n\t"
00807                 "punpckhdq %%mm1, %%mm1         \n\t"
00808                 "movq %%mm1, (%0, %2)           \n\t"
00809                 "add %1, %0                     \n\t"
00810                 "cmp %3, %0                     \n\t"
00811                 " jb 1b                         \n\t"
00812                 : "+r" (ptr)
00813                 : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
00814         );
00815     }
00816     else
00817     {
00818         __asm__ volatile(
00819                 "1:                             \n\t"
00820                 "movd (%0), %%mm0               \n\t"
00821                 "punpcklbw %%mm0, %%mm0         \n\t"
00822                 "punpcklwd %%mm0, %%mm0         \n\t"
00823                 "punpckldq %%mm0, %%mm0         \n\t"
00824                 "movq %%mm0, -8(%0)             \n\t"
00825                 "movq %%mm0, -16(%0)            \n\t"
00826                 "movq -8(%0, %2), %%mm1         \n\t"
00827                 "punpckhbw %%mm1, %%mm1         \n\t"
00828                 "punpckhwd %%mm1, %%mm1         \n\t"
00829                 "punpckhdq %%mm1, %%mm1         \n\t"
00830                 "movq %%mm1, (%0, %2)           \n\t"
00831                 "movq %%mm1, 8(%0, %2)          \n\t"
00832                 "add %1, %0                     \n\t"
00833                 "cmp %3, %0                     \n\t"
00834                 " jb 1b                         \n\t"
00835                 : "+r" (ptr)
00836                 : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
00837         );
00838     }
00839 
00840     /* top and bottom (and hopefully also the corners) */
00841     if (sides&EDGE_TOP) {
00842         for(i = 0; i < h; i += 4) {
00843             ptr= buf - (i + 1) * wrap - w;
00844             __asm__ volatile(
00845                     "1:                             \n\t"
00846                     "movq (%1, %0), %%mm0           \n\t"
00847                     "movq %%mm0, (%0)               \n\t"
00848                     "movq %%mm0, (%0, %2)           \n\t"
00849                     "movq %%mm0, (%0, %2, 2)        \n\t"
00850                     "movq %%mm0, (%0, %3)           \n\t"
00851                     "add $8, %0                     \n\t"
00852                     "cmp %4, %0                     \n\t"
00853                     " jb 1b                         \n\t"
00854                     : "+r" (ptr)
00855                     : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
00856             );
00857         }
00858     }
00859 
00860     if (sides&EDGE_BOTTOM) {
00861         for(i = 0; i < w; i += 4) {
00862             ptr= last_line + (i + 1) * wrap - w;
00863             __asm__ volatile(
00864                     "1:                             \n\t"
00865                     "movq (%1, %0), %%mm0           \n\t"
00866                     "movq %%mm0, (%0)               \n\t"
00867                     "movq %%mm0, (%0, %2)           \n\t"
00868                     "movq %%mm0, (%0, %2, 2)        \n\t"
00869                     "movq %%mm0, (%0, %3)           \n\t"
00870                     "add $8, %0                     \n\t"
00871                     "cmp %4, %0                     \n\t"
00872                     " jb 1b                         \n\t"
00873                     : "+r" (ptr)
00874                     : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
00875             );
00876         }
00877     }
00878 }
00879 
00880 #define PAETH(cpu, abs3)\
00881 static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
00882 {\
00883     x86_reg i = -bpp;\
00884     x86_reg end = w-3;\
00885     __asm__ volatile(\
00886         "pxor      %%mm7, %%mm7 \n"\
00887         "movd    (%1,%0), %%mm0 \n"\
00888         "movd    (%2,%0), %%mm1 \n"\
00889         "punpcklbw %%mm7, %%mm0 \n"\
00890         "punpcklbw %%mm7, %%mm1 \n"\
00891         "add       %4, %0 \n"\
00892         "1: \n"\
00893         "movq      %%mm1, %%mm2 \n"\
00894         "movd    (%2,%0), %%mm1 \n"\
00895         "movq      %%mm2, %%mm3 \n"\
00896         "punpcklbw %%mm7, %%mm1 \n"\
00897         "movq      %%mm2, %%mm4 \n"\
00898         "psubw     %%mm1, %%mm3 \n"\
00899         "psubw     %%mm0, %%mm4 \n"\
00900         "movq      %%mm3, %%mm5 \n"\
00901         "paddw     %%mm4, %%mm5 \n"\
00902         abs3\
00903         "movq      %%mm4, %%mm6 \n"\
00904         "pminsw    %%mm5, %%mm6 \n"\
00905         "pcmpgtw   %%mm6, %%mm3 \n"\
00906         "pcmpgtw   %%mm5, %%mm4 \n"\
00907         "movq      %%mm4, %%mm6 \n"\
00908         "pand      %%mm3, %%mm4 \n"\
00909         "pandn     %%mm3, %%mm6 \n"\
00910         "pandn     %%mm0, %%mm3 \n"\
00911         "movd    (%3,%0), %%mm0 \n"\
00912         "pand      %%mm1, %%mm6 \n"\
00913         "pand      %%mm4, %%mm2 \n"\
00914         "punpcklbw %%mm7, %%mm0 \n"\
00915         "movq      %6,    %%mm5 \n"\
00916         "paddw     %%mm6, %%mm0 \n"\
00917         "paddw     %%mm2, %%mm3 \n"\
00918         "paddw     %%mm3, %%mm0 \n"\
00919         "pand      %%mm5, %%mm0 \n"\
00920         "movq      %%mm0, %%mm3 \n"\
00921         "packuswb  %%mm3, %%mm3 \n"\
00922         "movd      %%mm3, (%1,%0) \n"\
00923         "add       %4, %0 \n"\
00924         "cmp       %5, %0 \n"\
00925         "jle 1b \n"\
00926         :"+r"(i)\
00927         :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
00928          "m"(ff_pw_255)\
00929         :"memory"\
00930     );\
00931 }
00932 
00933 #define ABS3_MMX2\
00934         "psubw     %%mm5, %%mm7 \n"\
00935         "pmaxsw    %%mm7, %%mm5 \n"\
00936         "pxor      %%mm6, %%mm6 \n"\
00937         "pxor      %%mm7, %%mm7 \n"\
00938         "psubw     %%mm3, %%mm6 \n"\
00939         "psubw     %%mm4, %%mm7 \n"\
00940         "pmaxsw    %%mm6, %%mm3 \n"\
00941         "pmaxsw    %%mm7, %%mm4 \n"\
00942         "pxor      %%mm7, %%mm7 \n"
00943 
00944 #define ABS3_SSSE3\
00945         "pabsw     %%mm3, %%mm3 \n"\
00946         "pabsw     %%mm4, %%mm4 \n"\
00947         "pabsw     %%mm5, %%mm5 \n"
00948 
00949 PAETH(mmx2, ABS3_MMX2)
00950 #if HAVE_SSSE3
00951 PAETH(ssse3, ABS3_SSSE3)
00952 #endif
00953 
00954 #define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
00955         "paddw " #m4 ", " #m3 "           \n\t" /* x1 */\
00956         "movq "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */\
00957         "pmullw " #m3 ", %%mm4            \n\t" /* 20x1 */\
00958         "movq "#in7", " #m3 "             \n\t" /* d */\
00959         "movq "#in0", %%mm5               \n\t" /* D */\
00960         "paddw " #m3 ", %%mm5             \n\t" /* x4 */\
00961         "psubw %%mm5, %%mm4               \n\t" /* 20x1 - x4 */\
00962         "movq "#in1", %%mm5               \n\t" /* C */\
00963         "movq "#in2", %%mm6               \n\t" /* B */\
00964         "paddw " #m6 ", %%mm5             \n\t" /* x3 */\
00965         "paddw " #m5 ", %%mm6             \n\t" /* x2 */\
00966         "paddw %%mm6, %%mm6               \n\t" /* 2x2 */\
00967         "psubw %%mm6, %%mm5               \n\t" /* -2x2 + x3 */\
00968         "pmullw "MANGLE(ff_pw_3)", %%mm5  \n\t" /* -6x2 + 3x3 */\
00969         "paddw " #rnd ", %%mm4            \n\t" /* x2 */\
00970         "paddw %%mm4, %%mm5               \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
00971         "psraw $5, %%mm5                  \n\t"\
00972         "packuswb %%mm5, %%mm5            \n\t"\
00973         OP(%%mm5, out, %%mm7, d)
00974 
00975 #define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
00976 static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
00977     uint64_t temp;\
00978 \
00979     __asm__ volatile(\
00980         "pxor %%mm7, %%mm7                \n\t"\
00981         "1:                               \n\t"\
00982         "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
00983         "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
00984         "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
00985         "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
00986         "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
00987         "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
00988         "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
00989         "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
00990         "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
00991         "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
00992         "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
00993         "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
00994         "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
00995         "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
00996         "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
00997         "paddw %%mm3, %%mm5               \n\t" /* b */\
00998         "paddw %%mm2, %%mm6               \n\t" /* c */\
00999         "paddw %%mm5, %%mm5               \n\t" /* 2b */\
01000         "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
01001         "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
01002         "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
01003         "paddw %%mm4, %%mm0               \n\t" /* a */\
01004         "paddw %%mm1, %%mm5               \n\t" /* d */\
01005         "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
01006         "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
01007         "paddw %6, %%mm6                  \n\t"\
01008         "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
01009         "psraw $5, %%mm0                  \n\t"\
01010         "movq %%mm0, %5                   \n\t"\
01011         /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
01012         \
01013         "movq 5(%0), %%mm0                \n\t" /* FGHIJKLM */\
01014         "movq %%mm0, %%mm5                \n\t" /* FGHIJKLM */\
01015         "movq %%mm0, %%mm6                \n\t" /* FGHIJKLM */\
01016         "psrlq $8, %%mm0                  \n\t" /* GHIJKLM0 */\
01017         "psrlq $16, %%mm5                 \n\t" /* HIJKLM00 */\
01018         "punpcklbw %%mm7, %%mm0           \n\t" /* 0G0H0I0J */\
01019         "punpcklbw %%mm7, %%mm5           \n\t" /* 0H0I0J0K */\
01020         "paddw %%mm0, %%mm2               \n\t" /* b */\
01021         "paddw %%mm5, %%mm3               \n\t" /* c */\
01022         "paddw %%mm2, %%mm2               \n\t" /* 2b */\
01023         "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
01024         "movq %%mm6, %%mm2                \n\t" /* FGHIJKLM */\
01025         "psrlq $24, %%mm6                 \n\t" /* IJKLM000 */\
01026         "punpcklbw %%mm7, %%mm2           \n\t" /* 0F0G0H0I */\
01027         "punpcklbw %%mm7, %%mm6           \n\t" /* 0I0J0K0L */\
01028         "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
01029         "paddw %%mm2, %%mm1               \n\t" /* a */\
01030         "paddw %%mm6, %%mm4               \n\t" /* d */\
01031         "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
01032         "psubw %%mm4, %%mm3               \n\t" /* - 6b +3c - d */\
01033         "paddw %6, %%mm1                  \n\t"\
01034         "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b +3c - d */\
01035         "psraw $5, %%mm3                  \n\t"\
01036         "movq %5, %%mm1                   \n\t"\
01037         "packuswb %%mm3, %%mm1            \n\t"\
01038         OP_MMX2(%%mm1, (%1),%%mm4, q)\
01039         /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
01040         \
01041         "movq 9(%0), %%mm1                \n\t" /* JKLMNOPQ */\
01042         "movq %%mm1, %%mm4                \n\t" /* JKLMNOPQ */\
01043         "movq %%mm1, %%mm3                \n\t" /* JKLMNOPQ */\
01044         "psrlq $8, %%mm1                  \n\t" /* KLMNOPQ0 */\
01045         "psrlq $16, %%mm4                 \n\t" /* LMNOPQ00 */\
01046         "punpcklbw %%mm7, %%mm1           \n\t" /* 0K0L0M0N */\
01047         "punpcklbw %%mm7, %%mm4           \n\t" /* 0L0M0N0O */\
01048         "paddw %%mm1, %%mm5               \n\t" /* b */\
01049         "paddw %%mm4, %%mm0               \n\t" /* c */\
01050         "paddw %%mm5, %%mm5               \n\t" /* 2b */\
01051         "psubw %%mm5, %%mm0               \n\t" /* c - 2b */\
01052         "movq %%mm3, %%mm5                \n\t" /* JKLMNOPQ */\
01053         "psrlq $24, %%mm3                 \n\t" /* MNOPQ000 */\
01054         "pmullw "MANGLE(ff_pw_3)", %%mm0  \n\t" /* 3c - 6b */\
01055         "punpcklbw %%mm7, %%mm3           \n\t" /* 0M0N0O0P */\
01056         "paddw %%mm3, %%mm2               \n\t" /* d */\
01057         "psubw %%mm2, %%mm0               \n\t" /* -6b + 3c - d */\
01058         "movq %%mm5, %%mm2                \n\t" /* JKLMNOPQ */\
01059         "punpcklbw %%mm7, %%mm2           \n\t" /* 0J0K0L0M */\
01060         "punpckhbw %%mm7, %%mm5           \n\t" /* 0N0O0P0Q */\
01061         "paddw %%mm2, %%mm6               \n\t" /* a */\
01062         "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
01063         "paddw %6, %%mm0                  \n\t"\
01064         "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
01065         "psraw $5, %%mm0                  \n\t"\
01066         /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
01067         \
01068         "paddw %%mm5, %%mm3               \n\t" /* a */\
01069         "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0O0P0Q0Q */\
01070         "paddw %%mm4, %%mm6               \n\t" /* b */\
01071         "pshufw $0xBE, %%mm5, %%mm4       \n\t" /* 0P0Q0Q0P */\
01072         "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0Q0Q0P0O */\
01073         "paddw %%mm1, %%mm4               \n\t" /* c */\
01074         "paddw %%mm2, %%mm5               \n\t" /* d */\
01075         "paddw %%mm6, %%mm6               \n\t" /* 2b */\
01076         "psubw %%mm6, %%mm4               \n\t" /* c - 2b */\
01077         "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
01078         "pmullw "MANGLE(ff_pw_3)", %%mm4  \n\t" /* 3c - 6b */\
01079         "psubw %%mm5, %%mm3               \n\t" /* -6b + 3c - d */\
01080         "paddw %6, %%mm4                  \n\t"\
01081         "paddw %%mm3, %%mm4               \n\t" /* 20a - 6b + 3c - d */\
01082         "psraw $5, %%mm4                  \n\t"\
01083         "packuswb %%mm4, %%mm0            \n\t"\
01084         OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
01085         \
01086         "add %3, %0                       \n\t"\
01087         "add %4, %1                       \n\t"\
01088         "decl %2                          \n\t"\
01089         " jnz 1b                          \n\t"\
01090         : "+a"(src), "+c"(dst), "+D"(h)\
01091         : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
01092         : "memory"\
01093     );\
01094 }\
01095 \
01096 static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
01097     int i;\
01098     int16_t temp[16];\
01099     /* quick HACK, XXX FIXME MUST be optimized */\
01100     for(i=0; i<h; i++)\
01101     {\
01102         temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
01103         temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
01104         temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
01105         temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
01106         temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
01107         temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
01108         temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
01109         temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
01110         temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
01111         temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
01112         temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
01113         temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
01114         temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
01115         temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
01116         temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
01117         temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
01118         __asm__ volatile(\
01119             "movq (%0), %%mm0               \n\t"\
01120             "movq 8(%0), %%mm1              \n\t"\
01121             "paddw %2, %%mm0                \n\t"\
01122             "paddw %2, %%mm1                \n\t"\
01123             "psraw $5, %%mm0                \n\t"\
01124             "psraw $5, %%mm1                \n\t"\
01125             "packuswb %%mm1, %%mm0          \n\t"\
01126             OP_3DNOW(%%mm0, (%1), %%mm1, q)\
01127             "movq 16(%0), %%mm0             \n\t"\
01128             "movq 24(%0), %%mm1             \n\t"\
01129             "paddw %2, %%mm0                \n\t"\
01130             "paddw %2, %%mm1                \n\t"\
01131             "psraw $5, %%mm0                \n\t"\
01132             "psraw $5, %%mm1                \n\t"\
01133             "packuswb %%mm1, %%mm0          \n\t"\
01134             OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
01135             :: "r"(temp), "r"(dst), "m"(ROUNDER)\
01136             : "memory"\
01137         );\
01138         dst+=dstStride;\
01139         src+=srcStride;\
01140     }\
01141 }\
01142 \
01143 static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
01144     __asm__ volatile(\
01145         "pxor %%mm7, %%mm7                \n\t"\
01146         "1:                               \n\t"\
01147         "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
01148         "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
01149         "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
01150         "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
01151         "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
01152         "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
01153         "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
01154         "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
01155         "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
01156         "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
01157         "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
01158         "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
01159         "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
01160         "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
01161         "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
01162         "paddw %%mm3, %%mm5               \n\t" /* b */\
01163         "paddw %%mm2, %%mm6               \n\t" /* c */\
01164         "paddw %%mm5, %%mm5               \n\t" /* 2b */\
01165         "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
01166         "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
01167         "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
01168         "paddw %%mm4, %%mm0               \n\t" /* a */\
01169         "paddw %%mm1, %%mm5               \n\t" /* d */\
01170         "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
01171         "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
01172         "paddw %5, %%mm6                  \n\t"\
01173         "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
01174         "psraw $5, %%mm0                  \n\t"\
01175         /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
01176         \
01177         "movd 5(%0), %%mm5                \n\t" /* FGHI */\
01178         "punpcklbw %%mm7, %%mm5           \n\t" /* 0F0G0H0I */\
01179         "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0G0H0I0I */\
01180         "paddw %%mm5, %%mm1               \n\t" /* a */\
01181         "paddw %%mm6, %%mm2               \n\t" /* b */\
01182         "pshufw $0xBE, %%mm5, %%mm6       \n\t" /* 0H0I0I0H */\
01183         "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0I0I0H0G */\
01184         "paddw %%mm6, %%mm3               \n\t" /* c */\
01185         "paddw %%mm5, %%mm4               \n\t" /* d */\
01186         "paddw %%mm2, %%mm2               \n\t" /* 2b */\
01187         "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
01188         "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
01189         "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
01190         "psubw %%mm4, %%mm3               \n\t" /* -6b + 3c - d */\
01191         "paddw %5, %%mm1                  \n\t"\
01192         "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b + 3c - d */\
01193         "psraw $5, %%mm3                  \n\t"\
01194         "packuswb %%mm3, %%mm0            \n\t"\
01195         OP_MMX2(%%mm0, (%1), %%mm4, q)\
01196         \
01197         "add %3, %0                       \n\t"\
01198         "add %4, %1                       \n\t"\
01199         "decl %2                          \n\t"\
01200         " jnz 1b                          \n\t"\
01201         : "+a"(src), "+c"(dst), "+d"(h)\
01202         : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
01203         : "memory"\
01204     );\
01205 }\
01206 \
01207 static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
01208     int i;\
01209     int16_t temp[8];\
01210     /* quick HACK, XXX FIXME MUST be optimized */\
01211     for(i=0; i<h; i++)\
01212     {\
01213         temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
01214         temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
01215         temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
01216         temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
01217         temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
01218         temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
01219         temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
01220         temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
01221         __asm__ volatile(\
01222             "movq (%0), %%mm0           \n\t"\
01223             "movq 8(%0), %%mm1          \n\t"\
01224             "paddw %2, %%mm0            \n\t"\
01225             "paddw %2, %%mm1            \n\t"\
01226             "psraw $5, %%mm0            \n\t"\
01227             "psraw $5, %%mm1            \n\t"\
01228             "packuswb %%mm1, %%mm0      \n\t"\
01229             OP_3DNOW(%%mm0, (%1), %%mm1, q)\
01230             :: "r"(temp), "r"(dst), "m"(ROUNDER)\
01231             :"memory"\
01232         );\
01233         dst+=dstStride;\
01234         src+=srcStride;\
01235     }\
01236 }
01237 
01238 #define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
01239 \
01240 static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
01241     uint64_t temp[17*4];\
01242     uint64_t *temp_ptr= temp;\
01243     int count= 17;\
01244 \
01245     /*FIXME unroll */\
01246     __asm__ volatile(\
01247         "pxor %%mm7, %%mm7              \n\t"\
01248         "1:                             \n\t"\
01249         "movq (%0), %%mm0               \n\t"\
01250         "movq (%0), %%mm1               \n\t"\
01251         "movq 8(%0), %%mm2              \n\t"\
01252         "movq 8(%0), %%mm3              \n\t"\
01253         "punpcklbw %%mm7, %%mm0         \n\t"\
01254         "punpckhbw %%mm7, %%mm1         \n\t"\
01255         "punpcklbw %%mm7, %%mm2         \n\t"\
01256         "punpckhbw %%mm7, %%mm3         \n\t"\
01257         "movq %%mm0, (%1)               \n\t"\
01258         "movq %%mm1, 17*8(%1)           \n\t"\
01259         "movq %%mm2, 2*17*8(%1)         \n\t"\
01260         "movq %%mm3, 3*17*8(%1)         \n\t"\
01261         "add $8, %1                     \n\t"\
01262         "add %3, %0                     \n\t"\
01263         "decl %2                        \n\t"\
01264         " jnz 1b                        \n\t"\
01265         : "+r" (src), "+r" (temp_ptr), "+r"(count)\
01266         : "r" ((x86_reg)srcStride)\
01267         : "memory"\
01268     );\
01269     \
01270     temp_ptr= temp;\
01271     count=4;\
01272     \
01273 /*FIXME reorder for speed */\
01274     __asm__ volatile(\
01275         /*"pxor %%mm7, %%mm7              \n\t"*/\
01276         "1:                             \n\t"\
01277         "movq (%0), %%mm0               \n\t"\
01278         "movq 8(%0), %%mm1              \n\t"\
01279         "movq 16(%0), %%mm2             \n\t"\
01280         "movq 24(%0), %%mm3             \n\t"\
01281         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
01282         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
01283         "add %4, %1                     \n\t"\
01284         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
01285         \
01286         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
01287         "add %4, %1                     \n\t"\
01288         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
01289         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
01290         "add %4, %1                     \n\t"\
01291         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
01292         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
01293         "add %4, %1                     \n\t"\
01294         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
01295         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
01296         "add %4, %1                     \n\t"\
01297         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
01298         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
01299         "add %4, %1                     \n\t"\
01300         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
01301         \
01302         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
01303         "add %4, %1                     \n\t"  \
01304         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
01305         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
01306         \
01307         "add $136, %0                   \n\t"\
01308         "add %6, %1                     \n\t"\
01309         "decl %2                        \n\t"\
01310         " jnz 1b                        \n\t"\
01311         \
01312         : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
01313         : "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)\
01314         :"memory"\
01315     );\
01316 }\
01317 \
01318 static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
01319     uint64_t temp[9*2];\
01320     uint64_t *temp_ptr= temp;\
01321     int count= 9;\
01322 \
01323     /*FIXME unroll */\
01324     __asm__ volatile(\
01325         "pxor %%mm7, %%mm7              \n\t"\
01326         "1:                             \n\t"\
01327         "movq (%0), %%mm0               \n\t"\
01328         "movq (%0), %%mm1               \n\t"\
01329         "punpcklbw %%mm7, %%mm0         \n\t"\
01330         "punpckhbw %%mm7, %%mm1         \n\t"\
01331         "movq %%mm0, (%1)               \n\t"\
01332         "movq %%mm1, 9*8(%1)            \n\t"\
01333         "add $8, %1                     \n\t"\
01334         "add %3, %0                     \n\t"\
01335         "decl %2                        \n\t"\
01336         " jnz 1b                        \n\t"\
01337         : "+r" (src), "+r" (temp_ptr), "+r"(count)\
01338         : "r" ((x86_reg)srcStride)\
01339         : "memory"\
01340     );\
01341     \
01342     temp_ptr= temp;\
01343     count=2;\
01344     \
01345 /*FIXME reorder for speed */\
01346     __asm__ volatile(\
01347         /*"pxor %%mm7, %%mm7              \n\t"*/\
01348         "1:                             \n\t"\
01349         "movq (%0), %%mm0               \n\t"\
01350         "movq 8(%0), %%mm1              \n\t"\
01351         "movq 16(%0), %%mm2             \n\t"\
01352         "movq 24(%0), %%mm3             \n\t"\
01353         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
01354         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
01355         "add %4, %1                     \n\t"\
01356         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
01357         \
01358         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
01359         "add %4, %1                     \n\t"\
01360         QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
01361         \
01362         QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
01363         "add %4, %1                     \n\t"\
01364         QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
01365         QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
01366                 \
01367         "add $72, %0                    \n\t"\
01368         "add %6, %1                     \n\t"\
01369         "decl %2                        \n\t"\
01370         " jnz 1b                        \n\t"\
01371          \
01372         : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
01373         : "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)\
01374         : "memory"\
01375    );\
01376 }\
01377 \
01378 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
01379     OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);\
01380 }\
01381 \
01382 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01383     uint64_t temp[8];\
01384     uint8_t * const half= (uint8_t*)temp;\
01385     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
01386     OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
01387 }\
01388 \
01389 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01390     OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
01391 }\
01392 \
01393 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01394     uint64_t temp[8];\
01395     uint8_t * const half= (uint8_t*)temp;\
01396     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
01397     OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
01398 }\
01399 \
01400 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01401     uint64_t temp[8];\
01402     uint8_t * const half= (uint8_t*)temp;\
01403     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
01404     OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
01405 }\
01406 \
01407 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01408     OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
01409 }\
01410 \
01411 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01412     uint64_t temp[8];\
01413     uint8_t * const half= (uint8_t*)temp;\
01414     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
01415     OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
01416 }\
01417 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01418     uint64_t half[8 + 9];\
01419     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01420     uint8_t * const halfHV= ((uint8_t*)half);\
01421     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01422     put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
01423     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01424     OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
01425 }\
01426 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01427     uint64_t half[8 + 9];\
01428     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01429     uint8_t * const halfHV= ((uint8_t*)half);\
01430     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01431     put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
01432     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01433     OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
01434 }\
01435 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01436     uint64_t half[8 + 9];\
01437     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01438     uint8_t * const halfHV= ((uint8_t*)half);\
01439     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01440     put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
01441     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01442     OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
01443 }\
01444 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01445     uint64_t half[8 + 9];\
01446     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01447     uint8_t * const halfHV= ((uint8_t*)half);\
01448     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01449     put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
01450     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01451     OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
01452 }\
01453 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01454     uint64_t half[8 + 9];\
01455     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01456     uint8_t * const halfHV= ((uint8_t*)half);\
01457     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01458     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01459     OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
01460 }\
01461 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01462     uint64_t half[8 + 9];\
01463     uint8_t * const halfH= ((uint8_t*)half) + 64;\
01464     uint8_t * const halfHV= ((uint8_t*)half);\
01465     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01466     put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
01467     OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
01468 }\
01469 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01470     uint64_t half[8 + 9];\
01471     uint8_t * const halfH= ((uint8_t*)half);\
01472     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01473     put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
01474     OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
01475 }\
01476 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01477     uint64_t half[8 + 9];\
01478     uint8_t * const halfH= ((uint8_t*)half);\
01479     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01480     put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
01481     OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
01482 }\
01483 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01484     uint64_t half[9];\
01485     uint8_t * const halfH= ((uint8_t*)half);\
01486     put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
01487     OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
01488 }\
01489 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
01490     OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);\
01491 }\
01492 \
01493 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01494     uint64_t temp[32];\
01495     uint8_t * const half= (uint8_t*)temp;\
01496     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
01497     OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
01498 }\
01499 \
01500 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01501     OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
01502 }\
01503 \
01504 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01505     uint64_t temp[32];\
01506     uint8_t * const half= (uint8_t*)temp;\
01507     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
01508     OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
01509 }\
01510 \
01511 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01512     uint64_t temp[32];\
01513     uint8_t * const half= (uint8_t*)temp;\
01514     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
01515     OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
01516 }\
01517 \
01518 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01519     OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
01520 }\
01521 \
01522 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01523     uint64_t temp[32];\
01524     uint8_t * const half= (uint8_t*)temp;\
01525     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
01526     OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
01527 }\
01528 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01529     uint64_t half[16*2 + 17*2];\
01530     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01531     uint8_t * const halfHV= ((uint8_t*)half);\
01532     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01533     put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
01534     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01535     OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
01536 }\
01537 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01538     uint64_t half[16*2 + 17*2];\
01539     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01540     uint8_t * const halfHV= ((uint8_t*)half);\
01541     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01542     put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
01543     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01544     OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
01545 }\
01546 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01547     uint64_t half[16*2 + 17*2];\
01548     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01549     uint8_t * const halfHV= ((uint8_t*)half);\
01550     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01551     put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
01552     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01553     OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
01554 }\
01555 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01556     uint64_t half[16*2 + 17*2];\
01557     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01558     uint8_t * const halfHV= ((uint8_t*)half);\
01559     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01560     put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
01561     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01562     OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
01563 }\
01564 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01565     uint64_t half[16*2 + 17*2];\
01566     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01567     uint8_t * const halfHV= ((uint8_t*)half);\
01568     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01569     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01570     OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
01571 }\
01572 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01573     uint64_t half[16*2 + 17*2];\
01574     uint8_t * const halfH= ((uint8_t*)half) + 256;\
01575     uint8_t * const halfHV= ((uint8_t*)half);\
01576     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01577     put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
01578     OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
01579 }\
01580 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01581     uint64_t half[17*2];\
01582     uint8_t * const halfH= ((uint8_t*)half);\
01583     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01584     put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
01585     OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
01586 }\
01587 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01588     uint64_t half[17*2];\
01589     uint8_t * const halfH= ((uint8_t*)half);\
01590     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01591     put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
01592     OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
01593 }\
01594 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01595     uint64_t half[17*2];\
01596     uint8_t * const halfH= ((uint8_t*)half);\
01597     put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
01598     OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
01599 }
01600 
01601 #define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "        \n\t"
01602 #define AVG_3DNOW_OP(a,b,temp, size) \
01603 "mov" #size " " #b ", " #temp "   \n\t"\
01604 "pavgusb " #temp ", " #a "        \n\t"\
01605 "mov" #size " " #a ", " #b "      \n\t"
01606 #define AVG_MMX2_OP(a,b,temp, size) \
01607 "mov" #size " " #b ", " #temp "   \n\t"\
01608 "pavgb " #temp ", " #a "          \n\t"\
01609 "mov" #size " " #a ", " #b "      \n\t"
01610 
01611 QPEL_BASE(put_       , ff_pw_16, _       , PUT_OP, PUT_OP)
01612 QPEL_BASE(avg_       , ff_pw_16, _       , AVG_MMX2_OP, AVG_3DNOW_OP)
01613 QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
01614 QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, 3dnow)
01615 QPEL_OP(avg_       , ff_pw_16, _       , AVG_3DNOW_OP, 3dnow)
01616 QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
01617 QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, mmx2)
01618 QPEL_OP(avg_       , ff_pw_16, _       , AVG_MMX2_OP, mmx2)
01619 QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
01620 
01621 /***********************************/
01622 /* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
01623 
01624 #define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
01625 static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01626     OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
01627 }
01628 #define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
01629 static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01630     OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
01631 }
01632 
01633 #define QPEL_2TAP(OPNAME, SIZE, MMX)\
01634 QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
01635 QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
01636 QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
01637 static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
01638                           OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
01639 static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
01640                           OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
01641 static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
01642                           OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
01643 static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01644     OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
01645 }\
01646 static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
01647     OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
01648 }\
01649 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0,         1,       0)\
01650 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1,        -1,       0)\
01651 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0,         stride,  0)\
01652 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride,   -stride,  0)\
01653 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0,         stride,  1)\
01654 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1,         stride, -1)\
01655 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride,   -stride,  1)\
01656 QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
01657 
01658 QPEL_2TAP(put_, 16, mmx2)
01659 QPEL_2TAP(avg_, 16, mmx2)
01660 QPEL_2TAP(put_,  8, mmx2)
01661 QPEL_2TAP(avg_,  8, mmx2)
01662 QPEL_2TAP(put_, 16, 3dnow)
01663 QPEL_2TAP(avg_, 16, 3dnow)
01664 QPEL_2TAP(put_,  8, 3dnow)
01665 QPEL_2TAP(avg_,  8, 3dnow)
01666 
01667 
01668 #if 0
01669 static void just_return(void) { return; }
01670 #endif
01671 
01672 #if HAVE_YASM
01673 typedef void emu_edge_core_func (uint8_t *buf, const uint8_t *src,
01674                                  x86_reg linesize, x86_reg start_y,
01675                                  x86_reg end_y, x86_reg block_h,
01676                                  x86_reg start_x, x86_reg end_x,
01677                                  x86_reg block_w);
01678 extern emu_edge_core_func ff_emu_edge_core_mmx;
01679 extern emu_edge_core_func ff_emu_edge_core_sse;
01680 
01681 static av_always_inline
01682 void emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize,
01683                       int block_w, int block_h,
01684                       int src_x, int src_y, int w, int h,
01685                       emu_edge_core_func *core_fn)
01686 {
01687     int start_y, start_x, end_y, end_x, src_y_add=0;
01688 
01689     if(src_y>= h){
01690         src_y_add = h-1-src_y;
01691         src_y=h-1;
01692     }else if(src_y<=-block_h){
01693         src_y_add = 1-block_h-src_y;
01694         src_y=1-block_h;
01695     }
01696     if(src_x>= w){
01697         src+= (w-1-src_x);
01698         src_x=w-1;
01699     }else if(src_x<=-block_w){
01700         src+= (1-block_w-src_x);
01701         src_x=1-block_w;
01702     }
01703 
01704     start_y= FFMAX(0, -src_y);
01705     start_x= FFMAX(0, -src_x);
01706     end_y= FFMIN(block_h, h-src_y);
01707     end_x= FFMIN(block_w, w-src_x);
01708     assert(start_x < end_x && block_w > 0);
01709     assert(start_y < end_y && block_h > 0);
01710 
01711     // fill in the to-be-copied part plus all above/below
01712     src += (src_y_add+start_y)*linesize + start_x;
01713     buf += start_x;
01714     core_fn(buf, src, linesize, start_y, end_y, block_h, start_x, end_x, block_w);
01715 }
01716 
01717 #if ARCH_X86_32
01718 static av_noinline
01719 void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src, int linesize,
01720                           int block_w, int block_h,
01721                           int src_x, int src_y, int w, int h)
01722 {
01723     emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
01724                      w, h, &ff_emu_edge_core_mmx);
01725 }
01726 #endif
01727 static av_noinline
01728 void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src, int linesize,
01729                           int block_w, int block_h,
01730                           int src_x, int src_y, int w, int h)
01731 {
01732     emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
01733                      w, h, &ff_emu_edge_core_sse);
01734 }
01735 #endif /* HAVE_YASM */
01736 
01737 typedef void emulated_edge_mc_func (uint8_t *dst, const uint8_t *src,
01738                                     int linesize, int block_w, int block_h,
01739                                     int src_x, int src_y, int w, int h);
01740 
01741 static av_always_inline
01742 void gmc(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
01743          int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height,
01744          emulated_edge_mc_func *emu_edge_fn)
01745 {
01746     const int w = 8;
01747     const int ix = ox>>(16+shift);
01748     const int iy = oy>>(16+shift);
01749     const int oxs = ox>>4;
01750     const int oys = oy>>4;
01751     const int dxxs = dxx>>4;
01752     const int dxys = dxy>>4;
01753     const int dyxs = dyx>>4;
01754     const int dyys = dyy>>4;
01755     const uint16_t r4[4] = {r,r,r,r};
01756     const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
01757     const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
01758     const uint64_t shift2 = 2*shift;
01759     uint8_t edge_buf[(h+1)*stride];
01760     int x, y;
01761 
01762     const int dxw = (dxx-(1<<(16+shift)))*(w-1);
01763     const int dyh = (dyy-(1<<(16+shift)))*(h-1);
01764     const int dxh = dxy*(h-1);
01765     const int dyw = dyx*(w-1);
01766     if( // non-constant fullpel offset (3% of blocks)
01767         ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
01768          (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
01769         // uses more than 16 bits of subpel mv (only at huge resolution)
01770         || (dxx|dxy|dyx|dyy)&15 )
01771     {
01772         //FIXME could still use mmx for some of the rows
01773         ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
01774         return;
01775     }
01776 
01777     src += ix + iy*stride;
01778     if( (unsigned)ix >= width-w ||
01779         (unsigned)iy >= height-h )
01780     {
01781         emu_edge_fn(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
01782         src = edge_buf;
01783     }
01784 
01785     __asm__ volatile(
01786         "movd         %0, %%mm6 \n\t"
01787         "pxor      %%mm7, %%mm7 \n\t"
01788         "punpcklwd %%mm6, %%mm6 \n\t"
01789         "punpcklwd %%mm6, %%mm6 \n\t"
01790         :: "r"(1<<shift)
01791     );
01792 
01793     for(x=0; x<w; x+=4){
01794         uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
01795                             oxs - dxys + dxxs*(x+1),
01796                             oxs - dxys + dxxs*(x+2),
01797                             oxs - dxys + dxxs*(x+3) };
01798         uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
01799                             oys - dyys + dyxs*(x+1),
01800                             oys - dyys + dyxs*(x+2),
01801                             oys - dyys + dyxs*(x+3) };
01802 
01803         for(y=0; y<h; y++){
01804             __asm__ volatile(
01805                 "movq   %0,  %%mm4 \n\t"
01806                 "movq   %1,  %%mm5 \n\t"
01807                 "paddw  %2,  %%mm4 \n\t"
01808                 "paddw  %3,  %%mm5 \n\t"
01809                 "movq   %%mm4, %0  \n\t"
01810                 "movq   %%mm5, %1  \n\t"
01811                 "psrlw  $12, %%mm4 \n\t"
01812                 "psrlw  $12, %%mm5 \n\t"
01813                 : "+m"(*dx4), "+m"(*dy4)
01814                 : "m"(*dxy4), "m"(*dyy4)
01815             );
01816 
01817             __asm__ volatile(
01818                 "movq   %%mm6, %%mm2 \n\t"
01819                 "movq   %%mm6, %%mm1 \n\t"
01820                 "psubw  %%mm4, %%mm2 \n\t"
01821                 "psubw  %%mm5, %%mm1 \n\t"
01822                 "movq   %%mm2, %%mm0 \n\t"
01823                 "movq   %%mm4, %%mm3 \n\t"
01824                 "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
01825                 "pmullw %%mm5, %%mm3 \n\t" // dx*dy
01826                 "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
01827                 "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
01828 
01829                 "movd   %4,    %%mm5 \n\t"
01830                 "movd   %3,    %%mm4 \n\t"
01831                 "punpcklbw %%mm7, %%mm5 \n\t"
01832                 "punpcklbw %%mm7, %%mm4 \n\t"
01833                 "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
01834                 "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
01835 
01836                 "movd   %2,    %%mm5 \n\t"
01837                 "movd   %1,    %%mm4 \n\t"
01838                 "punpcklbw %%mm7, %%mm5 \n\t"
01839                 "punpcklbw %%mm7, %%mm4 \n\t"
01840                 "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
01841                 "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
01842                 "paddw  %5,    %%mm1 \n\t"
01843                 "paddw  %%mm3, %%mm2 \n\t"
01844                 "paddw  %%mm1, %%mm0 \n\t"
01845                 "paddw  %%mm2, %%mm0 \n\t"
01846 
01847                 "psrlw    %6,    %%mm0 \n\t"
01848                 "packuswb %%mm0, %%mm0 \n\t"
01849                 "movd     %%mm0, %0    \n\t"
01850 
01851                 : "=m"(dst[x+y*stride])
01852                 : "m"(src[0]), "m"(src[1]),
01853                   "m"(src[stride]), "m"(src[stride+1]),
01854                   "m"(*r4), "m"(shift2)
01855             );
01856             src += stride;
01857         }
01858         src += 4-h*stride;
01859     }
01860 }
01861 
01862 #if HAVE_YASM
01863 #if ARCH_X86_32
01864 static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
01865                     int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
01866 {
01867     gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
01868         width, height, &emulated_edge_mc_mmx);
01869 }
01870 #endif
01871 static void gmc_sse(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
01872                     int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
01873 {
01874     gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
01875         width, height, &emulated_edge_mc_sse);
01876 }
01877 #else
01878 static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
01879                     int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
01880 {
01881     gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
01882         width, height, &ff_emulated_edge_mc);
01883 }
01884 #endif
01885 
01886 #define PREFETCH(name, op) \
01887 static void name(void *mem, int stride, int h){\
01888     const uint8_t *p= mem;\
01889     do{\
01890         __asm__ volatile(#op" %0" :: "m"(*p));\
01891         p+= stride;\
01892     }while(--h);\
01893 }
01894 PREFETCH(prefetch_mmx2,  prefetcht0)
01895 PREFETCH(prefetch_3dnow, prefetch)
01896 #undef PREFETCH
01897 
01898 #include "h264_qpel_mmx.c"
01899 
01900 void ff_put_h264_chroma_mc8_mmx_rnd   (uint8_t *dst, uint8_t *src,
01901                                        int stride, int h, int x, int y);
01902 void ff_put_rv40_chroma_mc8_mmx       (uint8_t *dst, uint8_t *src,
01903                                        int stride, int h, int x, int y);
01904 void ff_avg_h264_chroma_mc8_mmx2_rnd  (uint8_t *dst, uint8_t *src,
01905                                        int stride, int h, int x, int y);
01906 void ff_avg_rv40_chroma_mc8_mmx2      (uint8_t *dst, uint8_t *src,
01907                                        int stride, int h, int x, int y);
01908 void ff_avg_h264_chroma_mc8_3dnow_rnd (uint8_t *dst, uint8_t *src,
01909                                        int stride, int h, int x, int y);
01910 void ff_avg_rv40_chroma_mc8_3dnow     (uint8_t *dst, uint8_t *src,
01911                                        int stride, int h, int x, int y);
01912 
01913 void ff_put_h264_chroma_mc4_mmx       (uint8_t *dst, uint8_t *src,
01914                                        int stride, int h, int x, int y);
01915 void ff_put_rv40_chroma_mc4_mmx       (uint8_t *dst, uint8_t *src,
01916                                        int stride, int h, int x, int y);
01917 void ff_avg_h264_chroma_mc4_mmx2      (uint8_t *dst, uint8_t *src,
01918                                        int stride, int h, int x, int y);
01919 void ff_avg_rv40_chroma_mc4_mmx2      (uint8_t *dst, uint8_t *src,
01920                                        int stride, int h, int x, int y);
01921 void ff_avg_h264_chroma_mc4_3dnow     (uint8_t *dst, uint8_t *src,
01922                                        int stride, int h, int x, int y);
01923 void ff_avg_rv40_chroma_mc4_3dnow     (uint8_t *dst, uint8_t *src,
01924                                        int stride, int h, int x, int y);
01925 
01926 void ff_put_h264_chroma_mc2_mmx2      (uint8_t *dst, uint8_t *src,
01927                                        int stride, int h, int x, int y);
01928 void ff_avg_h264_chroma_mc2_mmx2      (uint8_t *dst, uint8_t *src,
01929                                        int stride, int h, int x, int y);
01930 
01931 void ff_put_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
01932                                        int stride, int h, int x, int y);
01933 void ff_put_h264_chroma_mc4_ssse3     (uint8_t *dst, uint8_t *src,
01934                                        int stride, int h, int x, int y);
01935 
01936 void ff_avg_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
01937                                        int stride, int h, int x, int y);
01938 void ff_avg_h264_chroma_mc4_ssse3     (uint8_t *dst, uint8_t *src,
01939                                        int stride, int h, int x, int y);
01940 
01941 #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
01942 void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
01943                                       (uint8_t *dst, uint8_t *src,\
01944                                        int stride, int h, int x, int y);
01945 
01946 CHROMA_MC(put, 2, 10, mmxext)
01947 CHROMA_MC(avg, 2, 10, mmxext)
01948 CHROMA_MC(put, 4, 10, mmxext)
01949 CHROMA_MC(avg, 4, 10, mmxext)
01950 CHROMA_MC(put, 8, 10, sse2)
01951 CHROMA_MC(avg, 8, 10, sse2)
01952 CHROMA_MC(put, 8, 10, avx)
01953 CHROMA_MC(avg, 8, 10, avx)
01954 
01955 /* CAVS specific */
01956 void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
01957     put_pixels8_mmx(dst, src, stride, 8);
01958 }
01959 void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
01960     avg_pixels8_mmx(dst, src, stride, 8);
01961 }
01962 void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
01963     put_pixels16_mmx(dst, src, stride, 16);
01964 }
01965 void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
01966     avg_pixels16_mmx(dst, src, stride, 16);
01967 }
01968 
01969 /* VC1 specific */
01970 void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
01971     put_pixels8_mmx(dst, src, stride, 8);
01972 }
01973 void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
01974     avg_pixels8_mmx2(dst, src, stride, 8);
01975 }
01976 
01977 /* XXX: those functions should be suppressed ASAP when all IDCTs are
01978    converted */
01979 #if CONFIG_GPL
01980 static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
01981 {
01982     ff_mmx_idct (block);
01983     ff_put_pixels_clamped_mmx(block, dest, line_size);
01984 }
01985 static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
01986 {
01987     ff_mmx_idct (block);
01988     ff_add_pixels_clamped_mmx(block, dest, line_size);
01989 }
01990 static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
01991 {
01992     ff_mmxext_idct (block);
01993     ff_put_pixels_clamped_mmx(block, dest, line_size);
01994 }
01995 static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
01996 {
01997     ff_mmxext_idct (block);
01998     ff_add_pixels_clamped_mmx(block, dest, line_size);
01999 }
02000 #endif
02001 static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
02002 {
02003     ff_idct_xvid_mmx (block);
02004     ff_put_pixels_clamped_mmx(block, dest, line_size);
02005 }
02006 static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
02007 {
02008     ff_idct_xvid_mmx (block);
02009     ff_add_pixels_clamped_mmx(block, dest, line_size);
02010 }
02011 static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
02012 {
02013     ff_idct_xvid_mmx2 (block);
02014     ff_put_pixels_clamped_mmx(block, dest, line_size);
02015 }
02016 static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
02017 {
02018     ff_idct_xvid_mmx2 (block);
02019     ff_add_pixels_clamped_mmx(block, dest, line_size);
02020 }
02021 
02022 static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
02023 {
02024     int i;
02025     __asm__ volatile("pxor %%mm7, %%mm7":);
02026     for(i=0; i<blocksize; i+=2) {
02027         __asm__ volatile(
02028             "movq    %0,    %%mm0 \n\t"
02029             "movq    %1,    %%mm1 \n\t"
02030             "movq    %%mm0, %%mm2 \n\t"
02031             "movq    %%mm1, %%mm3 \n\t"
02032             "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
02033             "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
02034             "pslld   $31,   %%mm2 \n\t" // keep only the sign bit
02035             "pxor    %%mm2, %%mm1 \n\t"
02036             "movq    %%mm3, %%mm4 \n\t"
02037             "pand    %%mm1, %%mm3 \n\t"
02038             "pandn   %%mm1, %%mm4 \n\t"
02039             "pfadd   %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
02040             "pfsub   %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
02041             "movq    %%mm3, %1    \n\t"
02042             "movq    %%mm0, %0    \n\t"
02043             :"+m"(mag[i]), "+m"(ang[i])
02044             ::"memory"
02045         );
02046     }
02047     __asm__ volatile("femms");
02048 }
02049 static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
02050 {
02051     int i;
02052 
02053     __asm__ volatile(
02054             "movaps  %0,     %%xmm5 \n\t"
02055         ::"m"(ff_pdw_80000000[0])
02056     );
02057     for(i=0; i<blocksize; i+=4) {
02058         __asm__ volatile(
02059             "movaps  %0,     %%xmm0 \n\t"
02060             "movaps  %1,     %%xmm1 \n\t"
02061             "xorps   %%xmm2, %%xmm2 \n\t"
02062             "xorps   %%xmm3, %%xmm3 \n\t"
02063             "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
02064             "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
02065             "andps   %%xmm5, %%xmm2 \n\t" // keep only the sign bit
02066             "xorps   %%xmm2, %%xmm1 \n\t"
02067             "movaps  %%xmm3, %%xmm4 \n\t"
02068             "andps   %%xmm1, %%xmm3 \n\t"
02069             "andnps  %%xmm1, %%xmm4 \n\t"
02070             "addps   %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
02071             "subps   %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
02072             "movaps  %%xmm3, %1     \n\t"
02073             "movaps  %%xmm0, %0     \n\t"
02074             :"+m"(mag[i]), "+m"(ang[i])
02075             ::"memory"
02076         );
02077     }
02078 }
02079 
02080 #define IF1(x) x
02081 #define IF0(x)
02082 
02083 #define MIX5(mono,stereo)\
02084     __asm__ volatile(\
02085         "movss          0(%2), %%xmm5 \n"\
02086         "movss          8(%2), %%xmm6 \n"\
02087         "movss         24(%2), %%xmm7 \n"\
02088         "shufps    $0, %%xmm5, %%xmm5 \n"\
02089         "shufps    $0, %%xmm6, %%xmm6 \n"\
02090         "shufps    $0, %%xmm7, %%xmm7 \n"\
02091         "1: \n"\
02092         "movaps       (%0,%1), %%xmm0 \n"\
02093         "movaps  0x400(%0,%1), %%xmm1 \n"\
02094         "movaps  0x800(%0,%1), %%xmm2 \n"\
02095         "movaps  0xc00(%0,%1), %%xmm3 \n"\
02096         "movaps 0x1000(%0,%1), %%xmm4 \n"\
02097         "mulps         %%xmm5, %%xmm0 \n"\
02098         "mulps         %%xmm6, %%xmm1 \n"\
02099         "mulps         %%xmm5, %%xmm2 \n"\
02100         "mulps         %%xmm7, %%xmm3 \n"\
02101         "mulps         %%xmm7, %%xmm4 \n"\
02102  stereo("addps         %%xmm1, %%xmm0 \n")\
02103         "addps         %%xmm1, %%xmm2 \n"\
02104         "addps         %%xmm3, %%xmm0 \n"\
02105         "addps         %%xmm4, %%xmm2 \n"\
02106    mono("addps         %%xmm2, %%xmm0 \n")\
02107         "movaps  %%xmm0,      (%0,%1) \n"\
02108  stereo("movaps  %%xmm2, 0x400(%0,%1) \n")\
02109         "add $16, %0 \n"\
02110         "jl 1b \n"\
02111         :"+&r"(i)\
02112         :"r"(samples[0]+len), "r"(matrix)\
02113         :XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
02114                       "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\
02115          "memory"\
02116     );
02117 
02118 #define MIX_MISC(stereo)\
02119     __asm__ volatile(\
02120         "1: \n"\
02121         "movaps  (%3,%0), %%xmm0 \n"\
02122  stereo("movaps   %%xmm0, %%xmm1 \n")\
02123         "mulps    %%xmm4, %%xmm0 \n"\
02124  stereo("mulps    %%xmm5, %%xmm1 \n")\
02125         "lea 1024(%3,%0), %1 \n"\
02126         "mov %5, %2 \n"\
02127         "2: \n"\
02128         "movaps   (%1),   %%xmm2 \n"\
02129  stereo("movaps   %%xmm2, %%xmm3 \n")\
02130         "mulps   (%4,%2), %%xmm2 \n"\
02131  stereo("mulps 16(%4,%2), %%xmm3 \n")\
02132         "addps    %%xmm2, %%xmm0 \n"\
02133  stereo("addps    %%xmm3, %%xmm1 \n")\
02134         "add $1024, %1 \n"\
02135         "add $32, %2 \n"\
02136         "jl 2b \n"\
02137         "movaps   %%xmm0,     (%3,%0) \n"\
02138  stereo("movaps   %%xmm1, 1024(%3,%0) \n")\
02139         "add $16, %0 \n"\
02140         "jl 1b \n"\
02141         :"+&r"(i), "=&r"(j), "=&r"(k)\
02142         :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
02143         :"memory"\
02144     );
02145 
02146 static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
02147 {
02148     int (*matrix_cmp)[2] = (int(*)[2])matrix;
02149     intptr_t i,j,k;
02150 
02151     i = -len*sizeof(float);
02152     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]))) {
02153         MIX5(IF0,IF1);
02154     } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
02155         MIX5(IF1,IF0);
02156     } else {
02157         DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
02158         j = 2*in_ch*sizeof(float);
02159         __asm__ volatile(
02160             "1: \n"
02161             "sub $8, %0 \n"
02162             "movss     (%2,%0), %%xmm4 \n"
02163             "movss    4(%2,%0), %%xmm5 \n"
02164             "shufps $0, %%xmm4, %%xmm4 \n"
02165             "shufps $0, %%xmm5, %%xmm5 \n"
02166             "movaps %%xmm4,   (%1,%0,4) \n"
02167             "movaps %%xmm5, 16(%1,%0,4) \n"
02168             "jg 1b \n"
02169             :"+&r"(j)
02170             :"r"(matrix_simd), "r"(matrix)
02171             :"memory"
02172         );
02173         if(out_ch == 2) {
02174             MIX_MISC(IF1);
02175         } else {
02176             MIX_MISC(IF0);
02177         }
02178     }
02179 }
02180 
02181 static void vector_fmul_3dnow(float *dst, const float *src0, const float *src1, int len){
02182     x86_reg i = (len-4)*4;
02183     __asm__ volatile(
02184         "1: \n\t"
02185         "movq    (%2,%0), %%mm0 \n\t"
02186         "movq   8(%2,%0), %%mm1 \n\t"
02187         "pfmul   (%3,%0), %%mm0 \n\t"
02188         "pfmul  8(%3,%0), %%mm1 \n\t"
02189         "movq   %%mm0,  (%1,%0) \n\t"
02190         "movq   %%mm1, 8(%1,%0) \n\t"
02191         "sub  $16, %0 \n\t"
02192         "jge 1b \n\t"
02193         "femms  \n\t"
02194         :"+r"(i)
02195         :"r"(dst), "r"(src0), "r"(src1)
02196         :"memory"
02197     );
02198 }
02199 static void vector_fmul_sse(float *dst, const float *src0, const float *src1, int len){
02200     x86_reg i = (len-8)*4;
02201     __asm__ volatile(
02202         "1: \n\t"
02203         "movaps    (%2,%0), %%xmm0 \n\t"
02204         "movaps  16(%2,%0), %%xmm1 \n\t"
02205         "mulps     (%3,%0), %%xmm0 \n\t"
02206         "mulps   16(%3,%0), %%xmm1 \n\t"
02207         "movaps  %%xmm0,   (%1,%0) \n\t"
02208         "movaps  %%xmm1, 16(%1,%0) \n\t"
02209         "sub  $32, %0 \n\t"
02210         "jge 1b \n\t"
02211         :"+r"(i)
02212         :"r"(dst), "r"(src0), "r"(src1)
02213         :"memory"
02214     );
02215 }
02216 
02217 static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
02218     x86_reg i = len*4-16;
02219     __asm__ volatile(
02220         "1: \n\t"
02221         "pswapd   8(%1), %%mm0 \n\t"
02222         "pswapd    (%1), %%mm1 \n\t"
02223         "pfmul  (%3,%0), %%mm0 \n\t"
02224         "pfmul 8(%3,%0), %%mm1 \n\t"
02225         "movq  %%mm0,  (%2,%0) \n\t"
02226         "movq  %%mm1, 8(%2,%0) \n\t"
02227         "add   $16, %1 \n\t"
02228         "sub   $16, %0 \n\t"
02229         "jge   1b \n\t"
02230         :"+r"(i), "+r"(src1)
02231         :"r"(dst), "r"(src0)
02232     );
02233     __asm__ volatile("femms");
02234 }
02235 static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
02236     x86_reg i = len*4-32;
02237     __asm__ volatile(
02238         "1: \n\t"
02239         "movaps        16(%1), %%xmm0 \n\t"
02240         "movaps          (%1), %%xmm1 \n\t"
02241         "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
02242         "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
02243         "mulps        (%3,%0), %%xmm0 \n\t"
02244         "mulps      16(%3,%0), %%xmm1 \n\t"
02245         "movaps     %%xmm0,   (%2,%0) \n\t"
02246         "movaps     %%xmm1, 16(%2,%0) \n\t"
02247         "add    $32, %1 \n\t"
02248         "sub    $32, %0 \n\t"
02249         "jge    1b \n\t"
02250         :"+r"(i), "+r"(src1)
02251         :"r"(dst), "r"(src0)
02252     );
02253 }
02254 
02255 static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1,
02256                                   const float *src2, int len){
02257     x86_reg i = (len-4)*4;
02258     __asm__ volatile(
02259         "1: \n\t"
02260         "movq    (%2,%0), %%mm0 \n\t"
02261         "movq   8(%2,%0), %%mm1 \n\t"
02262         "pfmul   (%3,%0), %%mm0 \n\t"
02263         "pfmul  8(%3,%0), %%mm1 \n\t"
02264         "pfadd   (%4,%0), %%mm0 \n\t"
02265         "pfadd  8(%4,%0), %%mm1 \n\t"
02266         "movq  %%mm0,   (%1,%0) \n\t"
02267         "movq  %%mm1,  8(%1,%0) \n\t"
02268         "sub  $16, %0 \n\t"
02269         "jge  1b \n\t"
02270         :"+r"(i)
02271         :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
02272         :"memory"
02273     );
02274     __asm__ volatile("femms");
02275 }
02276 static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
02277                                 const float *src2, int len){
02278     x86_reg i = (len-8)*4;
02279     __asm__ volatile(
02280         "1: \n\t"
02281         "movaps   (%2,%0), %%xmm0 \n\t"
02282         "movaps 16(%2,%0), %%xmm1 \n\t"
02283         "mulps    (%3,%0), %%xmm0 \n\t"
02284         "mulps  16(%3,%0), %%xmm1 \n\t"
02285         "addps    (%4,%0), %%xmm0 \n\t"
02286         "addps  16(%4,%0), %%xmm1 \n\t"
02287         "movaps %%xmm0,   (%1,%0) \n\t"
02288         "movaps %%xmm1, 16(%1,%0) \n\t"
02289         "sub  $32, %0 \n\t"
02290         "jge  1b \n\t"
02291         :"+r"(i)
02292         :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
02293         :"memory"
02294     );
02295 }
02296 
02297 #if HAVE_6REGS
02298 static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
02299                                       const float *win, int len){
02300     x86_reg i = -len*4;
02301     x86_reg j = len*4-8;
02302     __asm__ volatile(
02303         "1: \n"
02304         "pswapd  (%5,%1), %%mm1 \n"
02305         "movq    (%5,%0), %%mm0 \n"
02306         "pswapd  (%4,%1), %%mm5 \n"
02307         "movq    (%3,%0), %%mm4 \n"
02308         "movq      %%mm0, %%mm2 \n"
02309         "movq      %%mm1, %%mm3 \n"
02310         "pfmul     %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
02311         "pfmul     %%mm5, %%mm3 \n" // src1[    j]*win[len+j]
02312         "pfmul     %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
02313         "pfmul     %%mm5, %%mm0 \n" // src1[    j]*win[len+i]
02314         "pfadd     %%mm3, %%mm2 \n"
02315         "pfsub     %%mm0, %%mm1 \n"
02316         "pswapd    %%mm2, %%mm2 \n"
02317         "movq      %%mm1, (%2,%0) \n"
02318         "movq      %%mm2, (%2,%1) \n"
02319         "sub $8, %1 \n"
02320         "add $8, %0 \n"
02321         "jl 1b \n"
02322         "femms \n"
02323         :"+r"(i), "+r"(j)
02324         :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
02325     );
02326 }
02327 
02328 static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
02329                                    const float *win, int len){
02330     x86_reg i = -len*4;
02331     x86_reg j = len*4-16;
02332     __asm__ volatile(
02333         "1: \n"
02334         "movaps       (%5,%1), %%xmm1 \n"
02335         "movaps       (%5,%0), %%xmm0 \n"
02336         "movaps       (%4,%1), %%xmm5 \n"
02337         "movaps       (%3,%0), %%xmm4 \n"
02338         "shufps $0x1b, %%xmm1, %%xmm1 \n"
02339         "shufps $0x1b, %%xmm5, %%xmm5 \n"
02340         "movaps        %%xmm0, %%xmm2 \n"
02341         "movaps        %%xmm1, %%xmm3 \n"
02342         "mulps         %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
02343         "mulps         %%xmm5, %%xmm3 \n" // src1[    j]*win[len+j]
02344         "mulps         %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
02345         "mulps         %%xmm5, %%xmm0 \n" // src1[    j]*win[len+i]
02346         "addps         %%xmm3, %%xmm2 \n"
02347         "subps         %%xmm0, %%xmm1 \n"
02348         "shufps $0x1b, %%xmm2, %%xmm2 \n"
02349         "movaps        %%xmm1, (%2,%0) \n"
02350         "movaps        %%xmm2, (%2,%1) \n"
02351         "sub $16, %1 \n"
02352         "add $16, %0 \n"
02353         "jl 1b \n"
02354         :"+r"(i), "+r"(j)
02355         :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
02356     );
02357 }
02358 #endif /* HAVE_6REGS */
02359 
02360 static void vector_clipf_sse(float *dst, const float *src, float min, float max,
02361                              int len)
02362 {
02363     x86_reg i = (len-16)*4;
02364     __asm__ volatile(
02365         "movss  %3, %%xmm4 \n"
02366         "movss  %4, %%xmm5 \n"
02367         "shufps $0, %%xmm4, %%xmm4 \n"
02368         "shufps $0, %%xmm5, %%xmm5 \n"
02369         "1: \n\t"
02370         "movaps    (%2,%0), %%xmm0 \n\t" // 3/1 on intel
02371         "movaps  16(%2,%0), %%xmm1 \n\t"
02372         "movaps  32(%2,%0), %%xmm2 \n\t"
02373         "movaps  48(%2,%0), %%xmm3 \n\t"
02374         "maxps      %%xmm4, %%xmm0 \n\t"
02375         "maxps      %%xmm4, %%xmm1 \n\t"
02376         "maxps      %%xmm4, %%xmm2 \n\t"
02377         "maxps      %%xmm4, %%xmm3 \n\t"
02378         "minps      %%xmm5, %%xmm0 \n\t"
02379         "minps      %%xmm5, %%xmm1 \n\t"
02380         "minps      %%xmm5, %%xmm2 \n\t"
02381         "minps      %%xmm5, %%xmm3 \n\t"
02382         "movaps  %%xmm0,   (%1,%0) \n\t"
02383         "movaps  %%xmm1, 16(%1,%0) \n\t"
02384         "movaps  %%xmm2, 32(%1,%0) \n\t"
02385         "movaps  %%xmm3, 48(%1,%0) \n\t"
02386         "sub  $64, %0 \n\t"
02387         "jge 1b \n\t"
02388         :"+&r"(i)
02389         :"r"(dst), "r"(src), "m"(min), "m"(max)
02390         :"memory"
02391     );
02392 }
02393 
02394 void ff_vp3_idct_mmx(int16_t *input_data);
02395 void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
02396 void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
02397 
02398 void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block);
02399 
02400 void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
02401 void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
02402 
02403 void ff_vp3_idct_sse2(int16_t *input_data);
02404 void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
02405 void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
02406 
02407 int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2, int order, int shift);
02408 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2, int order, int shift);
02409 int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
02410 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
02411 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
02412 
02413 void ff_apply_window_int16_mmxext    (int16_t *output, const int16_t *input,
02414                                       const int16_t *window, unsigned int len);
02415 void ff_apply_window_int16_mmxext_ba (int16_t *output, const int16_t *input,
02416                                       const int16_t *window, unsigned int len);
02417 void ff_apply_window_int16_sse2      (int16_t *output, const int16_t *input,
02418                                       const int16_t *window, unsigned int len);
02419 void ff_apply_window_int16_sse2_ba   (int16_t *output, const int16_t *input,
02420                                       const int16_t *window, unsigned int len);
02421 void ff_apply_window_int16_ssse3     (int16_t *output, const int16_t *input,
02422                                       const int16_t *window, unsigned int len);
02423 void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
02424                                       const int16_t *window, unsigned int len);
02425 
02426 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);
02427 int  ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left);
02428 int  ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left);
02429 
02430 float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
02431 
02432 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
02433 {
02434     int mm_flags = av_get_cpu_flags();
02435     const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
02436     const int bit_depth = avctx->bits_per_raw_sample;
02437 
02438     if (avctx->dsp_mask) {
02439         if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
02440             mm_flags |= (avctx->dsp_mask & 0xffff);
02441         else
02442             mm_flags &= ~(avctx->dsp_mask & 0xffff);
02443     }
02444 
02445 #if 0
02446     av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
02447     if (mm_flags & AV_CPU_FLAG_MMX)
02448         av_log(avctx, AV_LOG_INFO, " mmx");
02449     if (mm_flags & AV_CPU_FLAG_MMX2)
02450         av_log(avctx, AV_LOG_INFO, " mmx2");
02451     if (mm_flags & AV_CPU_FLAG_3DNOW)
02452         av_log(avctx, AV_LOG_INFO, " 3dnow");
02453     if (mm_flags & AV_CPU_FLAG_SSE)
02454         av_log(avctx, AV_LOG_INFO, " sse");
02455     if (mm_flags & AV_CPU_FLAG_SSE2)
02456         av_log(avctx, AV_LOG_INFO, " sse2");
02457     av_log(avctx, AV_LOG_INFO, "\n");
02458 #endif
02459 
02460     if (mm_flags & AV_CPU_FLAG_MMX) {
02461         const int idct_algo= avctx->idct_algo;
02462 
02463         if(avctx->lowres==0){
02464             if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
02465                 c->idct_put= ff_simple_idct_put_mmx;
02466                 c->idct_add= ff_simple_idct_add_mmx;
02467                 c->idct    = ff_simple_idct_mmx;
02468                 c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
02469 #if CONFIG_GPL
02470             }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
02471                 if(mm_flags & AV_CPU_FLAG_MMX2){
02472                     c->idct_put= ff_libmpeg2mmx2_idct_put;
02473                     c->idct_add= ff_libmpeg2mmx2_idct_add;
02474                     c->idct    = ff_mmxext_idct;
02475                 }else{
02476                     c->idct_put= ff_libmpeg2mmx_idct_put;
02477                     c->idct_add= ff_libmpeg2mmx_idct_add;
02478                     c->idct    = ff_mmx_idct;
02479                 }
02480                 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
02481 #endif
02482             }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
02483                      idct_algo==FF_IDCT_VP3 && HAVE_YASM){
02484                 if(mm_flags & AV_CPU_FLAG_SSE2){
02485                     c->idct_put= ff_vp3_idct_put_sse2;
02486                     c->idct_add= ff_vp3_idct_add_sse2;
02487                     c->idct    = ff_vp3_idct_sse2;
02488                     c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
02489                 }else{
02490                     c->idct_put= ff_vp3_idct_put_mmx;
02491                     c->idct_add= ff_vp3_idct_add_mmx;
02492                     c->idct    = ff_vp3_idct_mmx;
02493                     c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
02494                 }
02495             }else if(idct_algo==FF_IDCT_CAVS){
02496                     c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
02497             }else if(idct_algo==FF_IDCT_XVIDMMX){
02498                 if(mm_flags & AV_CPU_FLAG_SSE2){
02499                     c->idct_put= ff_idct_xvid_sse2_put;
02500                     c->idct_add= ff_idct_xvid_sse2_add;
02501                     c->idct    = ff_idct_xvid_sse2;
02502                     c->idct_permutation_type= FF_SSE2_IDCT_PERM;
02503                 }else if(mm_flags & AV_CPU_FLAG_MMX2){
02504                     c->idct_put= ff_idct_xvid_mmx2_put;
02505                     c->idct_add= ff_idct_xvid_mmx2_add;
02506                     c->idct    = ff_idct_xvid_mmx2;
02507                 }else{
02508                     c->idct_put= ff_idct_xvid_mmx_put;
02509                     c->idct_add= ff_idct_xvid_mmx_add;
02510                     c->idct    = ff_idct_xvid_mmx;
02511                 }
02512             }
02513         }
02514 
02515         c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
02516         c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
02517         c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
02518         if (!high_bit_depth) {
02519         c->clear_block  = clear_block_mmx;
02520         c->clear_blocks = clear_blocks_mmx;
02521         if ((mm_flags & AV_CPU_FLAG_SSE) &&
02522             !(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){
02523             /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
02524             c->clear_block  = clear_block_sse;
02525             c->clear_blocks = clear_blocks_sse;
02526         }
02527         }
02528 
02529 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
02530         c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
02531         c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
02532         c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
02533         c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
02534 
02535         if (!high_bit_depth) {
02536         SET_HPEL_FUNCS(put, 0, 16, mmx);
02537         SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
02538         SET_HPEL_FUNCS(avg, 0, 16, mmx);
02539         SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
02540         SET_HPEL_FUNCS(put, 1, 8, mmx);
02541         SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
02542         SET_HPEL_FUNCS(avg, 1, 8, mmx);
02543         SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
02544         }
02545 
02546 #if ARCH_X86_32 || !HAVE_YASM
02547         c->gmc= gmc_mmx;
02548 #endif
02549 #if ARCH_X86_32 && HAVE_YASM
02550         if (!high_bit_depth)
02551         c->emulated_edge_mc = emulated_edge_mc_mmx;
02552 #endif
02553 
02554         c->add_bytes= add_bytes_mmx;
02555         c->add_bytes_l2= add_bytes_l2_mmx;
02556 
02557         if (!high_bit_depth)
02558         c->draw_edges = draw_edges_mmx;
02559 
02560         if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
02561             c->h263_v_loop_filter= h263_v_loop_filter_mmx;
02562             c->h263_h_loop_filter= h263_h_loop_filter_mmx;
02563         }
02564 
02565 #if HAVE_YASM
02566         if (!high_bit_depth) {
02567         c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_mmx_rnd;
02568         c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_mmx;
02569         }
02570 
02571         c->put_rv40_chroma_pixels_tab[0]= ff_put_rv40_chroma_mc8_mmx;
02572         c->put_rv40_chroma_pixels_tab[1]= ff_put_rv40_chroma_mc4_mmx;
02573 #endif
02574 
02575         if (mm_flags & AV_CPU_FLAG_MMX2) {
02576             c->prefetch = prefetch_mmx2;
02577 
02578             if (!high_bit_depth) {
02579             c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
02580             c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
02581 
02582             c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
02583             c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
02584             c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
02585 
02586             c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
02587             c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
02588 
02589             c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
02590             c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
02591             c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
02592             }
02593 
02594             if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
02595                 if (!high_bit_depth) {
02596                 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
02597                 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
02598                 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
02599                 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
02600                 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
02601                 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
02602                 }
02603 
02604                 if (CONFIG_VP3_DECODER && HAVE_YASM) {
02605                     c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
02606                     c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
02607                 }
02608             }
02609             if (CONFIG_VP3_DECODER && HAVE_YASM) {
02610                 c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
02611             }
02612 
02613             if (CONFIG_VP3_DECODER
02614                 && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
02615                 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
02616                 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
02617             }
02618 
02619 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \
02620             c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \
02621             c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \
02622             c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \
02623             c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \
02624             c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \
02625             c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \
02626             c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \
02627             c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \
02628             c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \
02629             c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \
02630             c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \
02631             c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \
02632             c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \
02633             c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \
02634             c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \
02635             c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU
02636 
02637             SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2);
02638             SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2);
02639             SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2);
02640             SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2);
02641             SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2);
02642             SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2);
02643 
02644             if (!high_bit_depth) {
02645             SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2);
02646             SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2);
02647             SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2);
02648             SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2);
02649             SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2);
02650             SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2);
02651             }
02652 
02653             SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2);
02654             SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2);
02655             SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2);
02656             SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2);
02657 
02658 #if HAVE_YASM
02659             c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_mmx2;
02660             c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_mmx2;
02661 
02662             if (!high_bit_depth) {
02663             c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_mmx2_rnd;
02664             c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_mmx2;
02665             c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_mmx2;
02666             c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_mmx2;
02667             }
02668             if (bit_depth == 10) {
02669                 c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_10_mmxext;
02670                 c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_10_mmxext;
02671                 c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_10_mmxext;
02672                 c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_10_mmxext;
02673             }
02674 
02675             c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
02676 #endif
02677 #if HAVE_7REGS && HAVE_TEN_OPERANDS
02678             if( mm_flags&AV_CPU_FLAG_3DNOW )
02679                 c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
02680 #endif
02681 
02682             c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
02683         } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
02684             c->prefetch = prefetch_3dnow;
02685 
02686             if (!high_bit_depth) {
02687             c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
02688             c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
02689 
02690             c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
02691             c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
02692             c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
02693 
02694             c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
02695             c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
02696 
02697             c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
02698             c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
02699             c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
02700 
02701             if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
02702                 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
02703                 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
02704                 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
02705                 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
02706                 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
02707                 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
02708             }
02709             }
02710 
02711             if (CONFIG_VP3_DECODER
02712                 && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
02713                 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
02714                 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
02715             }
02716 
02717             SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow);
02718             SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow);
02719             SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow);
02720             SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow);
02721             SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow);
02722             SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow);
02723 
02724             if (!high_bit_depth) {
02725             SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow);
02726             SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow);
02727             SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow);
02728             SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow);
02729             SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow);
02730             SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow);
02731             }
02732 
02733             SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow);
02734             SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow);
02735             SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow);
02736             SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow);
02737 
02738 #if HAVE_YASM
02739             if (!high_bit_depth) {
02740             c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_3dnow_rnd;
02741             c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_3dnow;
02742             }
02743 
02744             c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_3dnow;
02745             c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_3dnow;
02746 #endif
02747         }
02748 
02749 
02750 #define H264_QPEL_FUNCS(x, y, CPU)\
02751             c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\
02752             c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\
02753             c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\
02754             c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU;
02755         if((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW)){
02756             // these functions are slower than mmx on AMD, but faster on Intel
02757             if (!high_bit_depth) {
02758             c->put_pixels_tab[0][0] = put_pixels16_sse2;
02759             c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2;
02760             c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
02761             H264_QPEL_FUNCS(0, 0, sse2);
02762             }
02763         }
02764         if(mm_flags & AV_CPU_FLAG_SSE2){
02765             if (!high_bit_depth) {
02766             H264_QPEL_FUNCS(0, 1, sse2);
02767             H264_QPEL_FUNCS(0, 2, sse2);
02768             H264_QPEL_FUNCS(0, 3, sse2);
02769             H264_QPEL_FUNCS(1, 1, sse2);
02770             H264_QPEL_FUNCS(1, 2, sse2);
02771             H264_QPEL_FUNCS(1, 3, sse2);
02772             H264_QPEL_FUNCS(2, 1, sse2);
02773             H264_QPEL_FUNCS(2, 2, sse2);
02774             H264_QPEL_FUNCS(2, 3, sse2);
02775             H264_QPEL_FUNCS(3, 1, sse2);
02776             H264_QPEL_FUNCS(3, 2, sse2);
02777             H264_QPEL_FUNCS(3, 3, sse2);
02778             }
02779 #if HAVE_YASM
02780             if (bit_depth == 10) {
02781                 c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_10_sse2;
02782                 c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_10_sse2;
02783             }
02784 #endif
02785         }
02786 #if HAVE_SSSE3
02787         if(mm_flags & AV_CPU_FLAG_SSSE3){
02788             if (!high_bit_depth) {
02789             H264_QPEL_FUNCS(1, 0, ssse3);
02790             H264_QPEL_FUNCS(1, 1, ssse3);
02791             H264_QPEL_FUNCS(1, 2, ssse3);
02792             H264_QPEL_FUNCS(1, 3, ssse3);
02793             H264_QPEL_FUNCS(2, 0, ssse3);
02794             H264_QPEL_FUNCS(2, 1, ssse3);
02795             H264_QPEL_FUNCS(2, 2, ssse3);
02796             H264_QPEL_FUNCS(2, 3, ssse3);
02797             H264_QPEL_FUNCS(3, 0, ssse3);
02798             H264_QPEL_FUNCS(3, 1, ssse3);
02799             H264_QPEL_FUNCS(3, 2, ssse3);
02800             H264_QPEL_FUNCS(3, 3, ssse3);
02801             }
02802             c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3;
02803 #if HAVE_YASM
02804             if (!high_bit_depth) {
02805             c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_ssse3_rnd;
02806             c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_ssse3_rnd;
02807             c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_ssse3;
02808             c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_ssse3;
02809             }
02810             c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
02811             if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
02812                 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
02813 #endif
02814         }
02815 #endif
02816 
02817         if(mm_flags & AV_CPU_FLAG_3DNOW){
02818             c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
02819             c->vector_fmul = vector_fmul_3dnow;
02820         }
02821         if(mm_flags & AV_CPU_FLAG_3DNOWEXT){
02822             c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
02823 #if HAVE_6REGS
02824             c->vector_fmul_window = vector_fmul_window_3dnow2;
02825 #endif
02826         }
02827         if(mm_flags & AV_CPU_FLAG_MMX2){
02828 #if HAVE_YASM
02829             c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
02830             c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
02831             if (avctx->flags & CODEC_FLAG_BITEXACT) {
02832                 c->apply_window_int16 = ff_apply_window_int16_mmxext_ba;
02833             } else {
02834                 c->apply_window_int16 = ff_apply_window_int16_mmxext;
02835             }
02836 #endif
02837         }
02838         if(mm_flags & AV_CPU_FLAG_SSE){
02839             c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
02840             c->ac3_downmix = ac3_downmix_sse;
02841             c->vector_fmul = vector_fmul_sse;
02842             c->vector_fmul_reverse = vector_fmul_reverse_sse;
02843             c->vector_fmul_add = vector_fmul_add_sse;
02844 #if HAVE_6REGS
02845             c->vector_fmul_window = vector_fmul_window_sse;
02846 #endif
02847             c->vector_clipf = vector_clipf_sse;
02848 #if HAVE_YASM
02849             c->scalarproduct_float = ff_scalarproduct_float_sse;
02850 #endif
02851         }
02852         if(mm_flags & AV_CPU_FLAG_3DNOW)
02853             c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse
02854         if(mm_flags & AV_CPU_FLAG_SSE2){
02855 #if HAVE_YASM
02856             c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
02857             c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
02858             if (avctx->flags & CODEC_FLAG_BITEXACT) {
02859                 c->apply_window_int16 = ff_apply_window_int16_sse2_ba;
02860             } else {
02861                 if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
02862                     c->apply_window_int16 = ff_apply_window_int16_sse2;
02863                 }
02864             }
02865 
02866             if (!high_bit_depth)
02867             c->emulated_edge_mc = emulated_edge_mc_sse;
02868             c->gmc= gmc_sse;
02869 #endif
02870         }
02871         if (mm_flags & AV_CPU_FLAG_SSSE3) {
02872 #if HAVE_YASM
02873             if (mm_flags & AV_CPU_FLAG_ATOM) {
02874                 c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
02875             } else {
02876                 c->apply_window_int16 = ff_apply_window_int16_ssse3;
02877             }
02878             if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) { // cachesplit
02879                 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
02880             }
02881 #endif
02882         }
02883 #if HAVE_AVX && HAVE_YASM
02884         if (mm_flags & AV_CPU_FLAG_AVX) {
02885             if (bit_depth == 10) {
02886                 c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_10_avx;
02887                 c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_10_avx;
02888             }
02889         }
02890 #endif
02891     }
02892 
02893     if (CONFIG_ENCODERS)
02894         dsputilenc_init_mmx(c, avctx);
02895 
02896 #if 0
02897     // for speed testing
02898     get_pixels = just_return;
02899     put_pixels_clamped = just_return;
02900     add_pixels_clamped = just_return;
02901 
02902     pix_abs16x16 = just_return;
02903     pix_abs16x16_x2 = just_return;
02904     pix_abs16x16_y2 = just_return;
02905     pix_abs16x16_xy2 = just_return;
02906 
02907     put_pixels_tab[0] = just_return;
02908     put_pixels_tab[1] = just_return;
02909     put_pixels_tab[2] = just_return;
02910     put_pixels_tab[3] = just_return;
02911 
02912     put_no_rnd_pixels_tab[0] = just_return;
02913     put_no_rnd_pixels_tab[1] = just_return;
02914     put_no_rnd_pixels_tab[2] = just_return;
02915     put_no_rnd_pixels_tab[3] = just_return;
02916 
02917     avg_pixels_tab[0] = just_return;
02918     avg_pixels_tab[1] = just_return;
02919     avg_pixels_tab[2] = just_return;
02920     avg_pixels_tab[3] = just_return;
02921 
02922     avg_no_rnd_pixels_tab[0] = just_return;
02923     avg_no_rnd_pixels_tab[1] = just_return;
02924     avg_no_rnd_pixels_tab[2] = just_return;
02925     avg_no_rnd_pixels_tab[3] = just_return;
02926 
02927     //av_fdct = just_return;
02928     //ff_idct = just_return;
02929 #endif
02930 }