Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / h264dsp_mmx.c @ 6da971f1

History | View | Annotate | Download (50.7 KB)

1
/*
2
 * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 */
18

    
19

    
20
/***********************************/
21
/* IDCT */
22

    
23
/* in/out: mma=mma+mmb, mmb=mmb-mma */
24
#define SUMSUB_BA( a, b ) \
25
    "paddw "#b", "#a" \n\t"\
26
    "paddw "#b", "#b" \n\t"\
27
    "psubw "#a", "#b" \n\t"
28

    
29
#define SUMSUB_BADC( a, b, c, d ) \
30
    "paddw "#b", "#a" \n\t"\
31
    "paddw "#d", "#c" \n\t"\
32
    "paddw "#b", "#b" \n\t"\
33
    "paddw "#d", "#d" \n\t"\
34
    "psubw "#a", "#b" \n\t"\
35
    "psubw "#c", "#d" \n\t"
36

    
37
#define SUMSUBD2_AB( a, b, t ) \
38
    "movq  "#b", "#t" \n\t"\
39
    "psraw  $1 , "#b" \n\t"\
40
    "paddw "#a", "#b" \n\t"\
41
    "psraw  $1 , "#a" \n\t"\
42
    "psubw "#t", "#a" \n\t"
43

    
44
#define IDCT4_1D( s02, s13, d02, d13, t ) \
45
    SUMSUB_BA  ( s02, d02 )\
46
    SUMSUBD2_AB( s13, d13, t )\
47
    SUMSUB_BADC( d13, s02, s13, d02 )
48

    
49
#define SBUTTERFLY(a,b,t,n)\
50
    "movq " #a ", " #t "                \n\t" /* abcd */\
51
    "punpckl" #n " " #b ", " #a "       \n\t" /* aebf */\
52
    "punpckh" #n " " #b ", " #t "       \n\t" /* cgdh */\
53

    
54
#define TRANSPOSE4(a,b,c,d,t)\
55
    SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
56
    SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
57
    SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
58
    SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
59

    
60
#define STORE_DIFF_4P( p, t, z ) \
61
    "psraw      $6,     "#p" \n\t"\
62
    "movd       (%0),   "#t" \n\t"\
63
    "punpcklbw "#z",    "#t" \n\t"\
64
    "paddsw    "#t",    "#p" \n\t"\
65
    "packuswb  "#z",    "#p" \n\t"\
66
    "movd      "#p",    (%0) \n\t"
67

    
68
static void ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride)
69
{
70
    /* Load dct coeffs */
71
    asm volatile(
72
        "movq   (%0), %%mm0 \n\t"
73
        "movq  8(%0), %%mm1 \n\t"
74
        "movq 16(%0), %%mm2 \n\t"
75
        "movq 24(%0), %%mm3 \n\t"
76
    :: "r"(block) );
77

    
78
    asm volatile(
79
        /* mm1=s02+s13  mm2=s02-s13  mm4=d02+d13  mm0=d02-d13 */
80
        IDCT4_1D( %%mm2, %%mm1, %%mm0, %%mm3, %%mm4 )
81

    
82
        "movq      %0,    %%mm6 \n\t"
83
        /* in: 1,4,0,2  out: 1,2,3,0 */
84
        TRANSPOSE4( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 )
85

    
86
        "paddw     %%mm6, %%mm3 \n\t"
87

    
88
        /* mm2=s02+s13  mm3=s02-s13  mm4=d02+d13  mm1=d02-d13 */
89
        IDCT4_1D( %%mm4, %%mm2, %%mm3, %%mm0, %%mm1 )
90

    
91
        "pxor %%mm7, %%mm7    \n\t"
92
    :: "m"(ff_pw_32));
93

    
94
    asm volatile(
95
    STORE_DIFF_4P( %%mm0, %%mm1, %%mm7)
96
        "add %1, %0             \n\t"
97
    STORE_DIFF_4P( %%mm2, %%mm1, %%mm7)
98
        "add %1, %0             \n\t"
99
    STORE_DIFF_4P( %%mm3, %%mm1, %%mm7)
100
        "add %1, %0             \n\t"
101
    STORE_DIFF_4P( %%mm4, %%mm1, %%mm7)
102
        : "+r"(dst)
103
        : "r" ((long)stride)
104
    );
105
}
106

    
107
static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
108
{
109
    int dc = (block[0] + 32) >> 6;
110
    asm volatile(
111
        "movd          %0, %%mm0 \n\t"
112
        "pshufw $0, %%mm0, %%mm0 \n\t"
113
        "pxor       %%mm1, %%mm1 \n\t"
114
        "psubw      %%mm0, %%mm1 \n\t"
115
        "packuswb   %%mm0, %%mm0 \n\t"
116
        "packuswb   %%mm1, %%mm1 \n\t"
117
        ::"r"(dc)
118
    );
119
    asm volatile(
120
        "movd          %0, %%mm2 \n\t"
121
        "movd          %1, %%mm3 \n\t"
122
        "movd          %2, %%mm4 \n\t"
123
        "movd          %3, %%mm5 \n\t"
124
        "paddusb    %%mm0, %%mm2 \n\t"
125
        "paddusb    %%mm0, %%mm3 \n\t"
126
        "paddusb    %%mm0, %%mm4 \n\t"
127
        "paddusb    %%mm0, %%mm5 \n\t"
128
        "psubusb    %%mm1, %%mm2 \n\t"
129
        "psubusb    %%mm1, %%mm3 \n\t"
130
        "psubusb    %%mm1, %%mm4 \n\t"
131
        "psubusb    %%mm1, %%mm5 \n\t"
132
        "movd       %%mm2, %0    \n\t"
133
        "movd       %%mm3, %1    \n\t"
134
        "movd       %%mm4, %2    \n\t"
135
        "movd       %%mm5, %3    \n\t"
136
        :"+m"(*(uint32_t*)(dst+0*stride)),
137
         "+m"(*(uint32_t*)(dst+1*stride)),
138
         "+m"(*(uint32_t*)(dst+2*stride)),
139
         "+m"(*(uint32_t*)(dst+3*stride))
140
    );
141
}
142

    
143
static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
144
{
145
    int dc = (block[0] + 32) >> 6;
146
    int y;
147
    asm volatile(
148
        "movd          %0, %%mm0 \n\t"
149
        "pshufw $0, %%mm0, %%mm0 \n\t"
150
        "pxor       %%mm1, %%mm1 \n\t"
151
        "psubw      %%mm0, %%mm1 \n\t"
152
        "packuswb   %%mm0, %%mm0 \n\t"
153
        "packuswb   %%mm1, %%mm1 \n\t"
154
        ::"r"(dc)
155
    );
156
    for(y=2; y--; dst += 4*stride){
157
    asm volatile(
158
        "movq          %0, %%mm2 \n\t"
159
        "movq          %1, %%mm3 \n\t"
160
        "movq          %2, %%mm4 \n\t"
161
        "movq          %3, %%mm5 \n\t"
162
        "paddusb    %%mm0, %%mm2 \n\t"
163
        "paddusb    %%mm0, %%mm3 \n\t"
164
        "paddusb    %%mm0, %%mm4 \n\t"
165
        "paddusb    %%mm0, %%mm5 \n\t"
166
        "psubusb    %%mm1, %%mm2 \n\t"
167
        "psubusb    %%mm1, %%mm3 \n\t"
168
        "psubusb    %%mm1, %%mm4 \n\t"
169
        "psubusb    %%mm1, %%mm5 \n\t"
170
        "movq       %%mm2, %0    \n\t"
171
        "movq       %%mm3, %1    \n\t"
172
        "movq       %%mm4, %2    \n\t"
173
        "movq       %%mm5, %3    \n\t"
174
        :"+m"(*(uint64_t*)(dst+0*stride)),
175
         "+m"(*(uint64_t*)(dst+1*stride)),
176
         "+m"(*(uint64_t*)(dst+2*stride)),
177
         "+m"(*(uint64_t*)(dst+3*stride))
178
    );
179
    }
180
}
181

    
182

    
183
/***********************************/
184
/* deblocking */
185

    
186
// out: o = |x-y|>a
187
// clobbers: t
188
#define DIFF_GT_MMX(x,y,a,o,t)\
189
    "movq     "#y", "#t"  \n\t"\
190
    "movq     "#x", "#o"  \n\t"\
191
    "psubusb  "#x", "#t"  \n\t"\
192
    "psubusb  "#y", "#o"  \n\t"\
193
    "por      "#t", "#o"  \n\t"\
194
    "psubusb  "#a", "#o"  \n\t"
195

    
196
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1
197
// out: mm5=beta-1, mm7=mask
198
// clobbers: mm4,mm6
199
#define H264_DEBLOCK_MASK(alpha1, beta1) \
200
    "pshufw $0, "#alpha1", %%mm4 \n\t"\
201
    "pshufw $0, "#beta1 ", %%mm5 \n\t"\
202
    "packuswb  %%mm4, %%mm4      \n\t"\
203
    "packuswb  %%mm5, %%mm5      \n\t"\
204
    DIFF_GT_MMX(%%mm1, %%mm2, %%mm4, %%mm7, %%mm6) /* |p0-q0| > alpha-1 */\
205
    DIFF_GT_MMX(%%mm0, %%mm1, %%mm5, %%mm4, %%mm6) /* |p1-p0| > beta-1 */\
206
    "por       %%mm4, %%mm7      \n\t"\
207
    DIFF_GT_MMX(%%mm3, %%mm2, %%mm5, %%mm4, %%mm6) /* |q1-q0| > beta-1 */\
208
    "por       %%mm4, %%mm7      \n\t"\
209
    "pxor      %%mm6, %%mm6      \n\t"\
210
    "pcmpeqb   %%mm6, %%mm7      \n\t"
211

    
212
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask)
213
// out: mm1=p0' mm2=q0'
214
// clobbers: mm0,3-6
215
#define H264_DEBLOCK_P0_Q0(pb_01, pb_3f)\
216
        /* a = q0^p0^((p1-q1)>>2) */\
217
        "movq    %%mm0, %%mm4  \n\t"\
218
        "psubb   %%mm3, %%mm4  \n\t"\
219
        "psrlw   $2,    %%mm4  \n\t"\
220
        "pxor    %%mm1, %%mm4  \n\t"\
221
        "pxor    %%mm2, %%mm4  \n\t"\
222
        /* b = p0^(q1>>2) */\
223
        "psrlw   $2,    %%mm3  \n\t"\
224
        "pand "#pb_3f", %%mm3  \n\t"\
225
        "movq    %%mm1, %%mm5  \n\t"\
226
        "pxor    %%mm3, %%mm5  \n\t"\
227
        /* c = q0^(p1>>2) */\
228
        "psrlw   $2,    %%mm0  \n\t"\
229
        "pand "#pb_3f", %%mm0  \n\t"\
230
        "movq    %%mm2, %%mm6  \n\t"\
231
        "pxor    %%mm0, %%mm6  \n\t"\
232
        /* d = (c^b) & ~(b^a) & 1 */\
233
        "pxor    %%mm5, %%mm6  \n\t"\
234
        "pxor    %%mm4, %%mm5  \n\t"\
235
        "pandn   %%mm6, %%mm5  \n\t"\
236
        "pand "#pb_01", %%mm5  \n\t"\
237
        /* delta = (avg(q0, p1>>2) + (d&a))
238
         *       - (avg(p0, q1>>2) + (d&~a)) */\
239
        "pavgb   %%mm2, %%mm0  \n\t"\
240
        "pand    %%mm5, %%mm4  \n\t"\
241
        "paddusb %%mm4, %%mm0  \n\t"\
242
        "pavgb   %%mm1, %%mm3  \n\t"\
243
        "pxor    %%mm5, %%mm4  \n\t"\
244
        "paddusb %%mm4, %%mm3  \n\t"\
245
        /* p0 += clip(delta, -tc0, tc0)
246
         * q0 -= clip(delta, -tc0, tc0) */\
247
        "movq    %%mm0, %%mm4  \n\t"\
248
        "psubusb %%mm3, %%mm0  \n\t"\
249
        "psubusb %%mm4, %%mm3  \n\t"\
250
        "pminub  %%mm7, %%mm0  \n\t"\
251
        "pminub  %%mm7, %%mm3  \n\t"\
252
        "paddusb %%mm0, %%mm1  \n\t"\
253
        "paddusb %%mm3, %%mm2  \n\t"\
254
        "psubusb %%mm3, %%mm1  \n\t"\
255
        "psubusb %%mm0, %%mm2  \n\t"
256

    
257
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=mm_bone
258
// out: (q1addr) = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
259
// clobbers: q2, tmp, tc0
260
#define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\
261
        "movq     %%mm1,  "#tmp"   \n\t"\
262
        "pavgb    %%mm2,  "#tmp"   \n\t"\
263
        "pavgb    "#tmp", "#q2"    \n\t" /* avg(p2,avg(p0,q0)) */\
264
        "pxor   "q2addr", "#tmp"   \n\t"\
265
        "pand     %8,     "#tmp"   \n\t" /* (p2^avg(p0,q0))&1 */\
266
        "psubusb  "#tmp", "#q2"    \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\
267
        "movq     "#p1",  "#tmp"   \n\t"\
268
        "psubusb  "#tc0", "#tmp"   \n\t"\
269
        "paddusb  "#p1",  "#tc0"   \n\t"\
270
        "pmaxub   "#tmp", "#q2"    \n\t"\
271
        "pminub   "#tc0", "#q2"    \n\t"\
272
        "movq     "#q2",  "q1addr" \n\t"
273

    
274
static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
275
{
276
    uint64_t tmp0;
277
    uint64_t tc = (uint8_t)tc0[1]*0x01010000 | (uint8_t)tc0[0]*0x0101;
278
    // with luma, tc0=0 doesn't mean no filtering, so we need a separate input mask
279
    uint32_t mask[2] = { (tc0[0]>=0)*0xffffffff, (tc0[1]>=0)*0xffffffff };
280

    
281
    asm volatile(
282
        "movq    (%1,%3), %%mm0    \n\t" //p1
283
        "movq    (%1,%3,2), %%mm1  \n\t" //p0
284
        "movq    (%2),    %%mm2    \n\t" //q0
285
        "movq    (%2,%3), %%mm3    \n\t" //q1
286
        H264_DEBLOCK_MASK(%6, %7)
287
        "pand     %5,     %%mm7    \n\t"
288
        "movq     %%mm7,  %0       \n\t"
289

    
290
        /* filter p1 */
291
        "movq     (%1),   %%mm3    \n\t" //p2
292
        DIFF_GT_MMX(%%mm1, %%mm3, %%mm5, %%mm6, %%mm4) // |p2-p0|>beta-1
293
        "pandn    %%mm7,  %%mm6    \n\t"
294
        "pcmpeqb  %%mm7,  %%mm6    \n\t"
295
        "pand     %%mm7,  %%mm6    \n\t" // mask & |p2-p0|<beta
296
        "pshufw  $80, %4, %%mm4    \n\t"
297
        "pand     %%mm7,  %%mm4    \n\t" // mask & tc0
298
        "movq     %8,     %%mm7    \n\t"
299
        "pand     %%mm6,  %%mm7    \n\t" // mask & |p2-p0|<beta & 1
300
        "pand     %%mm4,  %%mm6    \n\t" // mask & |p2-p0|<beta & tc0
301
        "paddb    %%mm4,  %%mm7    \n\t" // tc++
302
        H264_DEBLOCK_Q1(%%mm0, %%mm3, "(%1)", "(%1,%3)", %%mm6, %%mm4)
303

    
304
        /* filter q1 */
305
        "movq    (%2,%3,2), %%mm4  \n\t" //q2
306
        DIFF_GT_MMX(%%mm2, %%mm4, %%mm5, %%mm6, %%mm3) // |q2-q0|>beta-1
307
        "pandn    %0,     %%mm6    \n\t"
308
        "pcmpeqb  %0,     %%mm6    \n\t"
309
        "pand     %0,     %%mm6    \n\t"
310
        "pshufw  $80, %4, %%mm5    \n\t"
311
        "pand     %%mm6,  %%mm5    \n\t"
312
        "pand     %8,     %%mm6    \n\t"
313
        "paddb    %%mm6,  %%mm7    \n\t"
314
        "movq    (%2,%3), %%mm3    \n\t"
315
        H264_DEBLOCK_Q1(%%mm3, %%mm4, "(%2,%3,2)", "(%2,%3)", %%mm5, %%mm6)
316

    
317
        /* filter p0, q0 */
318
        H264_DEBLOCK_P0_Q0(%8, %9)
319
        "movq      %%mm1, (%1,%3,2) \n\t"
320
        "movq      %%mm2, (%2)      \n\t"
321

    
322
        : "=m"(tmp0)
323
        : "r"(pix-3*stride), "r"(pix), "r"((long)stride),
324
          "m"(tc), "m"(*(uint64_t*)mask), "m"(alpha1), "m"(beta1),
325
          "m"(mm_bone), "m"(ff_pb_3F)
326
    );
327
}
328

    
329
static void h264_v_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
330
{
331
    if((tc0[0] & tc0[1]) >= 0)
332
        h264_loop_filter_luma_mmx2(pix, stride, alpha-1, beta-1, tc0);
333
    if((tc0[2] & tc0[3]) >= 0)
334
        h264_loop_filter_luma_mmx2(pix+8, stride, alpha-1, beta-1, tc0+2);
335
}
336
static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
337
{
338
    //FIXME: could cut some load/stores by merging transpose with filter
339
    // also, it only needs to transpose 6x8
340
    uint8_t trans[8*8];
341
    int i;
342
    for(i=0; i<2; i++, pix+=8*stride, tc0+=2) {
343
        if((tc0[0] & tc0[1]) < 0)
344
            continue;
345
        transpose4x4(trans,       pix-4,          8, stride);
346
        transpose4x4(trans  +4*8, pix,            8, stride);
347
        transpose4x4(trans+4,     pix-4+4*stride, 8, stride);
348
        transpose4x4(trans+4+4*8, pix  +4*stride, 8, stride);
349
        h264_loop_filter_luma_mmx2(trans+4*8, 8, alpha-1, beta-1, tc0);
350
        transpose4x4(pix-2,          trans  +2*8, stride, 8);
351
        transpose4x4(pix-2+4*stride, trans+4+2*8, stride, 8);
352
    }
353
}
354

    
355
static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
356
{
357
    asm volatile(
358
        "movq    (%0),    %%mm0     \n\t" //p1
359
        "movq    (%0,%2), %%mm1     \n\t" //p0
360
        "movq    (%1),    %%mm2     \n\t" //q0
361
        "movq    (%1,%2), %%mm3     \n\t" //q1
362
        H264_DEBLOCK_MASK(%4, %5)
363
        "movd      %3,    %%mm6     \n\t"
364
        "punpcklbw %%mm6, %%mm6     \n\t"
365
        "pand      %%mm6, %%mm7     \n\t" // mm7 = tc&mask
366
        H264_DEBLOCK_P0_Q0(%6, %7)
367
        "movq      %%mm1, (%0,%2)   \n\t"
368
        "movq      %%mm2, (%1)      \n\t"
369

    
370
        :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
371
           "r"(*(uint32_t*)tc0),
372
           "m"(alpha1), "m"(beta1), "m"(mm_bone), "m"(ff_pb_3F)
373
    );
374
}
375

    
376
static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
377
{
378
    h264_loop_filter_chroma_mmx2(pix, stride, alpha-1, beta-1, tc0);
379
}
380

    
381
static void h264_h_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
382
{
383
    //FIXME: could cut some load/stores by merging transpose with filter
384
    uint8_t trans[8*4];
385
    transpose4x4(trans, pix-2, 8, stride);
386
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
387
    h264_loop_filter_chroma_mmx2(trans+2*8, 8, alpha-1, beta-1, tc0);
388
    transpose4x4(pix-2, trans, stride, 8);
389
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
390
}
391

    
392
// p0 = (p0 + q1 + 2*p1 + 2) >> 2
393
#define H264_FILTER_CHROMA4(p0, p1, q1, one) \
394
    "movq    "#p0", %%mm4  \n\t"\
395
    "pxor    "#q1", %%mm4  \n\t"\
396
    "pand   "#one", %%mm4  \n\t" /* mm4 = (p0^q1)&1 */\
397
    "pavgb   "#q1", "#p0"  \n\t"\
398
    "psubusb %%mm4, "#p0"  \n\t"\
399
    "pavgb   "#p1", "#p0"  \n\t" /* dst = avg(p1, avg(p0,q1) - ((p0^q1)&1)) */\
400

    
401
static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha1, int beta1)
402
{
403
    asm volatile(
404
        "movq    (%0),    %%mm0     \n\t"
405
        "movq    (%0,%2), %%mm1     \n\t"
406
        "movq    (%1),    %%mm2     \n\t"
407
        "movq    (%1,%2), %%mm3     \n\t"
408
        H264_DEBLOCK_MASK(%3, %4)
409
        "movq    %%mm1,   %%mm5     \n\t"
410
        "movq    %%mm2,   %%mm6     \n\t"
411
        H264_FILTER_CHROMA4(%%mm1, %%mm0, %%mm3, %5) //p0'
412
        H264_FILTER_CHROMA4(%%mm2, %%mm3, %%mm0, %5) //q0'
413
        "psubb   %%mm5,   %%mm1     \n\t"
414
        "psubb   %%mm6,   %%mm2     \n\t"
415
        "pand    %%mm7,   %%mm1     \n\t"
416
        "pand    %%mm7,   %%mm2     \n\t"
417
        "paddb   %%mm5,   %%mm1     \n\t"
418
        "paddb   %%mm6,   %%mm2     \n\t"
419
        "movq    %%mm1,   (%0,%2)   \n\t"
420
        "movq    %%mm2,   (%1)      \n\t"
421
        :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
422
           "m"(alpha1), "m"(beta1), "m"(mm_bone)
423
    );
424
}
425

    
426
static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
427
{
428
    h264_loop_filter_chroma_intra_mmx2(pix, stride, alpha-1, beta-1);
429
}
430

    
431
static void h264_h_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
432
{
433
    //FIXME: could cut some load/stores by merging transpose with filter
434
    uint8_t trans[8*4];
435
    transpose4x4(trans, pix-2, 8, stride);
436
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
437
    h264_loop_filter_chroma_intra_mmx2(trans+2*8, 8, alpha-1, beta-1);
438
    transpose4x4(pix-2, trans, stride, 8);
439
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
440
}
441

    
442

    
443
/***********************************/
444
/* motion compensation */
445

    
446
#define QPEL_H264V(A,B,C,D,E,F,OP)\
447
        "movd (%0), "#F"            \n\t"\
448
        "movq "#C", %%mm6           \n\t"\
449
        "paddw "#D", %%mm6          \n\t"\
450
        "psllw $2, %%mm6            \n\t"\
451
        "psubw "#B", %%mm6          \n\t"\
452
        "psubw "#E", %%mm6          \n\t"\
453
        "pmullw %4, %%mm6           \n\t"\
454
        "add %2, %0                 \n\t"\
455
        "punpcklbw %%mm7, "#F"      \n\t"\
456
        "paddw %5, "#A"             \n\t"\
457
        "paddw "#F", "#A"           \n\t"\
458
        "paddw "#A", %%mm6          \n\t"\
459
        "psraw $5, %%mm6            \n\t"\
460
        "packuswb %%mm6, %%mm6      \n\t"\
461
        OP(%%mm6, (%1), A, d)\
462
        "add %3, %1                 \n\t"
463

    
464
#define QPEL_H264HV(A,B,C,D,E,F,OF)\
465
        "movd (%0), "#F"            \n\t"\
466
        "movq "#C", %%mm6           \n\t"\
467
        "paddw "#D", %%mm6          \n\t"\
468
        "psllw $2, %%mm6            \n\t"\
469
        "psubw "#B", %%mm6          \n\t"\
470
        "psubw "#E", %%mm6          \n\t"\
471
        "pmullw %3, %%mm6           \n\t"\
472
        "add %2, %0                 \n\t"\
473
        "punpcklbw %%mm7, "#F"      \n\t"\
474
        "paddw "#F", "#A"           \n\t"\
475
        "paddw "#A", %%mm6          \n\t"\
476
        "movq %%mm6, "#OF"(%1)      \n\t"
477

    
478
#define QPEL_H264(OPNAME, OP, MMX)\
479
static void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
480
    int h=4;\
481
\
482
    asm volatile(\
483
        "pxor %%mm7, %%mm7          \n\t"\
484
        "movq %5, %%mm4             \n\t"\
485
        "movq %6, %%mm5             \n\t"\
486
        "1:                         \n\t"\
487
        "movd  -1(%0), %%mm1        \n\t"\
488
        "movd    (%0), %%mm2        \n\t"\
489
        "movd   1(%0), %%mm3        \n\t"\
490
        "movd   2(%0), %%mm0        \n\t"\
491
        "punpcklbw %%mm7, %%mm1     \n\t"\
492
        "punpcklbw %%mm7, %%mm2     \n\t"\
493
        "punpcklbw %%mm7, %%mm3     \n\t"\
494
        "punpcklbw %%mm7, %%mm0     \n\t"\
495
        "paddw %%mm0, %%mm1         \n\t"\
496
        "paddw %%mm3, %%mm2         \n\t"\
497
        "movd  -2(%0), %%mm0        \n\t"\
498
        "movd   3(%0), %%mm3        \n\t"\
499
        "punpcklbw %%mm7, %%mm0     \n\t"\
500
        "punpcklbw %%mm7, %%mm3     \n\t"\
501
        "paddw %%mm3, %%mm0         \n\t"\
502
        "psllw $2, %%mm2            \n\t"\
503
        "psubw %%mm1, %%mm2         \n\t"\
504
        "pmullw %%mm4, %%mm2        \n\t"\
505
        "paddw %%mm5, %%mm0         \n\t"\
506
        "paddw %%mm2, %%mm0         \n\t"\
507
        "psraw $5, %%mm0            \n\t"\
508
        "packuswb %%mm0, %%mm0      \n\t"\
509
        OP(%%mm0, (%1),%%mm6, d)\
510
        "add %3, %0                 \n\t"\
511
        "add %4, %1                 \n\t"\
512
        "decl %2                    \n\t"\
513
        " jnz 1b                    \n\t"\
514
        : "+a"(src), "+c"(dst), "+m"(h)\
515
        : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
516
        : "memory"\
517
    );\
518
}\
519
static void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
520
    int h=4;\
521
    asm volatile(\
522
        "pxor %%mm7, %%mm7          \n\t"\
523
        "movq %0, %%mm4             \n\t"\
524
        "movq %1, %%mm5             \n\t"\
525
        :: "m"(ff_pw_5), "m"(ff_pw_16)\
526
    );\
527
    do{\
528
    asm volatile(\
529
        "movd  -1(%0), %%mm1        \n\t"\
530
        "movd    (%0), %%mm2        \n\t"\
531
        "movd   1(%0), %%mm3        \n\t"\
532
        "movd   2(%0), %%mm0        \n\t"\
533
        "punpcklbw %%mm7, %%mm1     \n\t"\
534
        "punpcklbw %%mm7, %%mm2     \n\t"\
535
        "punpcklbw %%mm7, %%mm3     \n\t"\
536
        "punpcklbw %%mm7, %%mm0     \n\t"\
537
        "paddw %%mm0, %%mm1         \n\t"\
538
        "paddw %%mm3, %%mm2         \n\t"\
539
        "movd  -2(%0), %%mm0        \n\t"\
540
        "movd   3(%0), %%mm3        \n\t"\
541
        "punpcklbw %%mm7, %%mm0     \n\t"\
542
        "punpcklbw %%mm7, %%mm3     \n\t"\
543
        "paddw %%mm3, %%mm0         \n\t"\
544
        "psllw $2, %%mm2            \n\t"\
545
        "psubw %%mm1, %%mm2         \n\t"\
546
        "pmullw %%mm4, %%mm2        \n\t"\
547
        "paddw %%mm5, %%mm0         \n\t"\
548
        "paddw %%mm2, %%mm0         \n\t"\
549
        "movd   (%2), %%mm3         \n\t"\
550
        "psraw $5, %%mm0            \n\t"\
551
        "packuswb %%mm0, %%mm0      \n\t"\
552
        PAVGB" %%mm3, %%mm0         \n\t"\
553
        OP(%%mm0, (%1),%%mm6, d)\
554
        "add %4, %0                 \n\t"\
555
        "add %4, %1                 \n\t"\
556
        "add %3, %2                 \n\t"\
557
        : "+a"(src), "+c"(dst), "+d"(src2)\
558
        : "D"((long)src2Stride), "S"((long)dstStride)\
559
        : "memory"\
560
    );\
561
    }while(--h);\
562
}\
563
static void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
564
    src -= 2*srcStride;\
565
    asm volatile(\
566
        "pxor %%mm7, %%mm7          \n\t"\
567
        "movd (%0), %%mm0           \n\t"\
568
        "add %2, %0                 \n\t"\
569
        "movd (%0), %%mm1           \n\t"\
570
        "add %2, %0                 \n\t"\
571
        "movd (%0), %%mm2           \n\t"\
572
        "add %2, %0                 \n\t"\
573
        "movd (%0), %%mm3           \n\t"\
574
        "add %2, %0                 \n\t"\
575
        "movd (%0), %%mm4           \n\t"\
576
        "add %2, %0                 \n\t"\
577
        "punpcklbw %%mm7, %%mm0     \n\t"\
578
        "punpcklbw %%mm7, %%mm1     \n\t"\
579
        "punpcklbw %%mm7, %%mm2     \n\t"\
580
        "punpcklbw %%mm7, %%mm3     \n\t"\
581
        "punpcklbw %%mm7, %%mm4     \n\t"\
582
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
583
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
584
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
585
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
586
         \
587
        : "+a"(src), "+c"(dst)\
588
        : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
589
        : "memory"\
590
    );\
591
}\
592
static void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
593
    int h=4;\
594
    int w=3;\
595
    src -= 2*srcStride+2;\
596
    while(w--){\
597
        asm volatile(\
598
            "pxor %%mm7, %%mm7      \n\t"\
599
            "movd (%0), %%mm0       \n\t"\
600
            "add %2, %0             \n\t"\
601
            "movd (%0), %%mm1       \n\t"\
602
            "add %2, %0             \n\t"\
603
            "movd (%0), %%mm2       \n\t"\
604
            "add %2, %0             \n\t"\
605
            "movd (%0), %%mm3       \n\t"\
606
            "add %2, %0             \n\t"\
607
            "movd (%0), %%mm4       \n\t"\
608
            "add %2, %0             \n\t"\
609
            "punpcklbw %%mm7, %%mm0 \n\t"\
610
            "punpcklbw %%mm7, %%mm1 \n\t"\
611
            "punpcklbw %%mm7, %%mm2 \n\t"\
612
            "punpcklbw %%mm7, %%mm3 \n\t"\
613
            "punpcklbw %%mm7, %%mm4 \n\t"\
614
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\
615
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\
616
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\
617
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\
618
             \
619
            : "+a"(src)\
620
            : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
621
            : "memory"\
622
        );\
623
        tmp += 4;\
624
        src += 4 - 9*srcStride;\
625
    }\
626
    tmp -= 3*4;\
627
    asm volatile(\
628
        "movq %4, %%mm6             \n\t"\
629
        "1:                         \n\t"\
630
        "movq     (%0), %%mm0       \n\t"\
631
        "paddw  10(%0), %%mm0       \n\t"\
632
        "movq    2(%0), %%mm1       \n\t"\
633
        "paddw   8(%0), %%mm1       \n\t"\
634
        "movq    4(%0), %%mm2       \n\t"\
635
        "paddw   6(%0), %%mm2       \n\t"\
636
        "psubw %%mm1, %%mm0         \n\t"/*a-b   (abccba)*/\
637
        "psraw $2, %%mm0            \n\t"/*(a-b)/4 */\
638
        "psubw %%mm1, %%mm0         \n\t"/*(a-b)/4-b */\
639
        "paddsw %%mm2, %%mm0        \n\t"\
640
        "psraw $2, %%mm0            \n\t"/*((a-b)/4-b+c)/4 */\
641
        "paddw %%mm6, %%mm2         \n\t"\
642
        "paddw %%mm2, %%mm0         \n\t"/*(a-5*b+20*c)/16 +32 */\
643
        "psraw $6, %%mm0            \n\t"\
644
        "packuswb %%mm0, %%mm0      \n\t"\
645
        OP(%%mm0, (%1),%%mm7, d)\
646
        "add $24, %0                \n\t"\
647
        "add %3, %1                 \n\t"\
648
        "decl %2                    \n\t"\
649
        " jnz 1b                    \n\t"\
650
        : "+a"(tmp), "+c"(dst), "+m"(h)\
651
        : "S"((long)dstStride), "m"(ff_pw_32)\
652
        : "memory"\
653
    );\
654
}\
655
\
656
static void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
657
    int h=8;\
658
    asm volatile(\
659
        "pxor %%mm7, %%mm7          \n\t"\
660
        "movq %5, %%mm6             \n\t"\
661
        "1:                         \n\t"\
662
        "movq    (%0), %%mm0        \n\t"\
663
        "movq   1(%0), %%mm2        \n\t"\
664
        "movq %%mm0, %%mm1          \n\t"\
665
        "movq %%mm2, %%mm3          \n\t"\
666
        "punpcklbw %%mm7, %%mm0     \n\t"\
667
        "punpckhbw %%mm7, %%mm1     \n\t"\
668
        "punpcklbw %%mm7, %%mm2     \n\t"\
669
        "punpckhbw %%mm7, %%mm3     \n\t"\
670
        "paddw %%mm2, %%mm0         \n\t"\
671
        "paddw %%mm3, %%mm1         \n\t"\
672
        "psllw $2, %%mm0            \n\t"\
673
        "psllw $2, %%mm1            \n\t"\
674
        "movq   -1(%0), %%mm2       \n\t"\
675
        "movq    2(%0), %%mm4       \n\t"\
676
        "movq %%mm2, %%mm3          \n\t"\
677
        "movq %%mm4, %%mm5          \n\t"\
678
        "punpcklbw %%mm7, %%mm2     \n\t"\
679
        "punpckhbw %%mm7, %%mm3     \n\t"\
680
        "punpcklbw %%mm7, %%mm4     \n\t"\
681
        "punpckhbw %%mm7, %%mm5     \n\t"\
682
        "paddw %%mm4, %%mm2         \n\t"\
683
        "paddw %%mm3, %%mm5         \n\t"\
684
        "psubw %%mm2, %%mm0         \n\t"\
685
        "psubw %%mm5, %%mm1         \n\t"\
686
        "pmullw %%mm6, %%mm0        \n\t"\
687
        "pmullw %%mm6, %%mm1        \n\t"\
688
        "movd   -2(%0), %%mm2       \n\t"\
689
        "movd    7(%0), %%mm5       \n\t"\
690
        "punpcklbw %%mm7, %%mm2     \n\t"\
691
        "punpcklbw %%mm7, %%mm5     \n\t"\
692
        "paddw %%mm3, %%mm2         \n\t"\
693
        "paddw %%mm5, %%mm4         \n\t"\
694
        "movq %6, %%mm5             \n\t"\
695
        "paddw %%mm5, %%mm2         \n\t"\
696
        "paddw %%mm5, %%mm4         \n\t"\
697
        "paddw %%mm2, %%mm0         \n\t"\
698
        "paddw %%mm4, %%mm1         \n\t"\
699
        "psraw $5, %%mm0            \n\t"\
700
        "psraw $5, %%mm1            \n\t"\
701
        "packuswb %%mm1, %%mm0      \n\t"\
702
        OP(%%mm0, (%1),%%mm5, q)\
703
        "add %3, %0                 \n\t"\
704
        "add %4, %1                 \n\t"\
705
        "decl %2                    \n\t"\
706
        " jnz 1b                    \n\t"\
707
        : "+a"(src), "+c"(dst), "+m"(h)\
708
        : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
709
        : "memory"\
710
    );\
711
}\
712
\
713
static void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
714
    int h=8;\
715
    asm volatile(\
716
        "pxor %%mm7, %%mm7          \n\t"\
717
        "movq %0, %%mm6             \n\t"\
718
        :: "m"(ff_pw_5)\
719
    );\
720
    do{\
721
    asm volatile(\
722
        "movq    (%0), %%mm0        \n\t"\
723
        "movq   1(%0), %%mm2        \n\t"\
724
        "movq %%mm0, %%mm1          \n\t"\
725
        "movq %%mm2, %%mm3          \n\t"\
726
        "punpcklbw %%mm7, %%mm0     \n\t"\
727
        "punpckhbw %%mm7, %%mm1     \n\t"\
728
        "punpcklbw %%mm7, %%mm2     \n\t"\
729
        "punpckhbw %%mm7, %%mm3     \n\t"\
730
        "paddw %%mm2, %%mm0         \n\t"\
731
        "paddw %%mm3, %%mm1         \n\t"\
732
        "psllw $2, %%mm0            \n\t"\
733
        "psllw $2, %%mm1            \n\t"\
734
        "movq   -1(%0), %%mm2       \n\t"\
735
        "movq    2(%0), %%mm4       \n\t"\
736
        "movq %%mm2, %%mm3          \n\t"\
737
        "movq %%mm4, %%mm5          \n\t"\
738
        "punpcklbw %%mm7, %%mm2     \n\t"\
739
        "punpckhbw %%mm7, %%mm3     \n\t"\
740
        "punpcklbw %%mm7, %%mm4     \n\t"\
741
        "punpckhbw %%mm7, %%mm5     \n\t"\
742
        "paddw %%mm4, %%mm2         \n\t"\
743
        "paddw %%mm3, %%mm5         \n\t"\
744
        "psubw %%mm2, %%mm0         \n\t"\
745
        "psubw %%mm5, %%mm1         \n\t"\
746
        "pmullw %%mm6, %%mm0        \n\t"\
747
        "pmullw %%mm6, %%mm1        \n\t"\
748
        "movd   -2(%0), %%mm2       \n\t"\
749
        "movd    7(%0), %%mm5       \n\t"\
750
        "punpcklbw %%mm7, %%mm2     \n\t"\
751
        "punpcklbw %%mm7, %%mm5     \n\t"\
752
        "paddw %%mm3, %%mm2         \n\t"\
753
        "paddw %%mm5, %%mm4         \n\t"\
754
        "movq %5, %%mm5             \n\t"\
755
        "paddw %%mm5, %%mm2         \n\t"\
756
        "paddw %%mm5, %%mm4         \n\t"\
757
        "paddw %%mm2, %%mm0         \n\t"\
758
        "paddw %%mm4, %%mm1         \n\t"\
759
        "psraw $5, %%mm0            \n\t"\
760
        "psraw $5, %%mm1            \n\t"\
761
        "movq (%2), %%mm4           \n\t"\
762
        "packuswb %%mm1, %%mm0      \n\t"\
763
        PAVGB" %%mm4, %%mm0         \n\t"\
764
        OP(%%mm0, (%1),%%mm5, q)\
765
        "add %4, %0                 \n\t"\
766
        "add %4, %1                 \n\t"\
767
        "add %3, %2                 \n\t"\
768
        : "+a"(src), "+c"(dst), "+d"(src2)\
769
        : "D"((long)src2Stride), "S"((long)dstStride),\
770
          "m"(ff_pw_16)\
771
        : "memory"\
772
    );\
773
    }while(--h);\
774
}\
775
\
776
static inline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
777
    int w= 2;\
778
    src -= 2*srcStride;\
779
    \
780
    while(w--){\
781
      asm volatile(\
782
        "pxor %%mm7, %%mm7          \n\t"\
783
        "movd (%0), %%mm0           \n\t"\
784
        "add %2, %0                 \n\t"\
785
        "movd (%0), %%mm1           \n\t"\
786
        "add %2, %0                 \n\t"\
787
        "movd (%0), %%mm2           \n\t"\
788
        "add %2, %0                 \n\t"\
789
        "movd (%0), %%mm3           \n\t"\
790
        "add %2, %0                 \n\t"\
791
        "movd (%0), %%mm4           \n\t"\
792
        "add %2, %0                 \n\t"\
793
        "punpcklbw %%mm7, %%mm0     \n\t"\
794
        "punpcklbw %%mm7, %%mm1     \n\t"\
795
        "punpcklbw %%mm7, %%mm2     \n\t"\
796
        "punpcklbw %%mm7, %%mm3     \n\t"\
797
        "punpcklbw %%mm7, %%mm4     \n\t"\
798
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
799
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
800
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
801
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
802
        QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
803
        QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
804
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
805
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
806
         \
807
        : "+a"(src), "+c"(dst)\
808
        : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
809
        : "memory"\
810
     );\
811
     if(h==16){\
812
        asm volatile(\
813
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
814
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
815
            QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
816
            QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
817
            QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
818
            QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
819
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
820
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
821
            \
822
           : "+a"(src), "+c"(dst)\
823
           : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
824
           : "memory"\
825
        );\
826
     }\
827
     src += 4-(h+5)*srcStride;\
828
     dst += 4-h*dstStride;\
829
   }\
830
}\
831
static inline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
832
    int h = size;\
833
    int w = (size+8)>>2;\
834
    src -= 2*srcStride+2;\
835
    while(w--){\
836
        asm volatile(\
837
            "pxor %%mm7, %%mm7      \n\t"\
838
            "movd (%0), %%mm0       \n\t"\
839
            "add %2, %0             \n\t"\
840
            "movd (%0), %%mm1       \n\t"\
841
            "add %2, %0             \n\t"\
842
            "movd (%0), %%mm2       \n\t"\
843
            "add %2, %0             \n\t"\
844
            "movd (%0), %%mm3       \n\t"\
845
            "add %2, %0             \n\t"\
846
            "movd (%0), %%mm4       \n\t"\
847
            "add %2, %0             \n\t"\
848
            "punpcklbw %%mm7, %%mm0 \n\t"\
849
            "punpcklbw %%mm7, %%mm1 \n\t"\
850
            "punpcklbw %%mm7, %%mm2 \n\t"\
851
            "punpcklbw %%mm7, %%mm3 \n\t"\
852
            "punpcklbw %%mm7, %%mm4 \n\t"\
853
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\
854
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\
855
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\
856
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\
857
            QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\
858
            QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\
859
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\
860
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\
861
            : "+a"(src)\
862
            : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
863
            : "memory"\
864
        );\
865
        if(size==16){\
866
            asm volatile(\
867
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1,  8*48)\
868
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2,  9*48)\
869
                QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\
870
                QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\
871
                QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\
872
                QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\
873
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\
874
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
875
                : "+a"(src)\
876
                : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
877
                : "memory"\
878
            );\
879
        }\
880
        tmp += 4;\
881
        src += 4 - (size+5)*srcStride;\
882
    }\
883
    tmp -= size+8;\
884
    w = size>>4;\
885
    do{\
886
    h = size;\
887
    asm volatile(\
888
        "movq %4, %%mm6             \n\t"\
889
        "1:                         \n\t"\
890
        "movq     (%0), %%mm0       \n\t"\
891
        "movq    8(%0), %%mm3       \n\t"\
892
        "movq    2(%0), %%mm1       \n\t"\
893
        "movq   10(%0), %%mm4       \n\t"\
894
        "paddw   %%mm4, %%mm0       \n\t"\
895
        "paddw   %%mm3, %%mm1       \n\t"\
896
        "paddw  18(%0), %%mm3       \n\t"\
897
        "paddw  16(%0), %%mm4       \n\t"\
898
        "movq    4(%0), %%mm2       \n\t"\
899
        "movq   12(%0), %%mm5       \n\t"\
900
        "paddw   6(%0), %%mm2       \n\t"\
901
        "paddw  14(%0), %%mm5       \n\t"\
902
        "psubw %%mm1, %%mm0         \n\t"\
903
        "psubw %%mm4, %%mm3         \n\t"\
904
        "psraw $2, %%mm0            \n\t"\
905
        "psraw $2, %%mm3            \n\t"\
906
        "psubw %%mm1, %%mm0         \n\t"\
907
        "psubw %%mm4, %%mm3         \n\t"\
908
        "paddsw %%mm2, %%mm0        \n\t"\
909
        "paddsw %%mm5, %%mm3        \n\t"\
910
        "psraw $2, %%mm0            \n\t"\
911
        "psraw $2, %%mm3            \n\t"\
912
        "paddw %%mm6, %%mm2         \n\t"\
913
        "paddw %%mm6, %%mm5         \n\t"\
914
        "paddw %%mm2, %%mm0         \n\t"\
915
        "paddw %%mm5, %%mm3         \n\t"\
916
        "psraw $6, %%mm0            \n\t"\
917
        "psraw $6, %%mm3            \n\t"\
918
        "packuswb %%mm3, %%mm0      \n\t"\
919
        OP(%%mm0, (%1),%%mm7, q)\
920
        "add $48, %0                \n\t"\
921
        "add %3, %1                 \n\t"\
922
        "decl %2                    \n\t"\
923
        " jnz 1b                    \n\t"\
924
        : "+a"(tmp), "+c"(dst), "+m"(h)\
925
        : "S"((long)dstStride), "m"(ff_pw_32)\
926
        : "memory"\
927
    );\
928
    tmp += 8 - size*24;\
929
    dst += 8 - size*dstStride;\
930
    }while(w--);\
931
}\
932
\
933
static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
934
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 8);\
935
}\
936
static void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
937
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 16);\
938
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
939
}\
940
\
941
static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
942
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
943
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
944
    src += 8*srcStride;\
945
    dst += 8*dstStride;\
946
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
947
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
948
}\
949
\
950
static void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
951
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
952
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
953
    src += 8*dstStride;\
954
    dst += 8*dstStride;\
955
    src2 += 8*src2Stride;\
956
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
957
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
958
}\
959
\
960
static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
961
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 8);\
962
}\
963
\
964
static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
965
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 16);\
966
}\
967
\
968
static void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
969
{\
970
    asm volatile(\
971
        "movq       %5,  %%mm6          \n\t"\
972
        "movq      (%1), %%mm0          \n\t"\
973
        "movq    24(%1), %%mm1          \n\t"\
974
        "paddw    %%mm6, %%mm0          \n\t"\
975
        "paddw    %%mm6, %%mm1          \n\t"\
976
        "psraw      $5,  %%mm0          \n\t"\
977
        "psraw      $5,  %%mm1          \n\t"\
978
        "packuswb %%mm0, %%mm0          \n\t"\
979
        "packuswb %%mm1, %%mm1          \n\t"\
980
        PAVGB"     (%0), %%mm0          \n\t"\
981
        PAVGB"  (%0,%3), %%mm1          \n\t"\
982
        OP(%%mm0, (%2),    %%mm4, d)\
983
        OP(%%mm1, (%2,%4), %%mm5, d)\
984
        "lea  (%0,%3,2), %0             \n\t"\
985
        "lea  (%2,%4,2), %2             \n\t"\
986
        "movq    48(%1), %%mm0          \n\t"\
987
        "movq    72(%1), %%mm1          \n\t"\
988
        "paddw    %%mm6, %%mm0          \n\t"\
989
        "paddw    %%mm6, %%mm1          \n\t"\
990
        "psraw      $5,  %%mm0          \n\t"\
991
        "psraw      $5,  %%mm1          \n\t"\
992
        "packuswb %%mm0, %%mm0          \n\t"\
993
        "packuswb %%mm1, %%mm1          \n\t"\
994
        PAVGB"     (%0), %%mm0          \n\t"\
995
        PAVGB"  (%0,%3), %%mm1          \n\t"\
996
        OP(%%mm0, (%2),    %%mm4, d)\
997
        OP(%%mm1, (%2,%4), %%mm5, d)\
998
        :"+a"(src8), "+c"(src16), "+d"(dst)\
999
        :"S"((long)src8Stride), "D"((long)dstStride), "m"(ff_pw_16)\
1000
        :"memory");\
1001
}\
1002
static void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1003
{\
1004
    asm volatile(\
1005
        "movq       %0,  %%mm6          \n\t"\
1006
        ::"m"(ff_pw_16)\
1007
        );\
1008
    while(h--){\
1009
    asm volatile(\
1010
        "movq      (%1), %%mm0          \n\t"\
1011
        "movq     8(%1), %%mm1          \n\t"\
1012
        "paddw    %%mm6, %%mm0          \n\t"\
1013
        "paddw    %%mm6, %%mm1          \n\t"\
1014
        "psraw      $5,  %%mm0          \n\t"\
1015
        "psraw      $5,  %%mm1          \n\t"\
1016
        "packuswb %%mm1, %%mm0          \n\t"\
1017
        PAVGB"     (%0), %%mm0          \n\t"\
1018
        OP(%%mm0, (%2), %%mm5, q)\
1019
        ::"a"(src8), "c"(src16), "d"(dst)\
1020
        :"memory");\
1021
        src8 += src8Stride;\
1022
        src16 += 24;\
1023
        dst += dstStride;\
1024
    }\
1025
}\
1026
static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1027
{\
1028
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst  , src16  , src8  , dstStride, src8Stride, h);\
1029
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
1030
}\
1031

    
1032

    
1033
#define H264_MC(OPNAME, SIZE, MMX) \
1034
static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1035
    OPNAME ## pixels ## SIZE ## _mmx(dst, src, stride, SIZE);\
1036
}\
1037
\
1038
static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1039
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
1040
}\
1041
\
1042
static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1043
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
1044
}\
1045
\
1046
static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1047
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
1048
}\
1049
\
1050
static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1051
    uint64_t temp[SIZE*SIZE/8];\
1052
    uint8_t * const half= (uint8_t*)temp;\
1053
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
1054
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, half, stride, stride, SIZE);\
1055
}\
1056
\
1057
static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1058
    OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
1059
}\
1060
\
1061
static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1062
    uint64_t temp[SIZE*SIZE/8];\
1063
    uint8_t * const half= (uint8_t*)temp;\
1064
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
1065
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, half, stride, stride, SIZE);\
1066
}\
1067
\
1068
static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1069
    uint64_t temp[SIZE*SIZE/8];\
1070
    uint8_t * const halfV= (uint8_t*)temp;\
1071
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
1072
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
1073
}\
1074
\
1075
static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1076
    uint64_t temp[SIZE*SIZE/8];\
1077
    uint8_t * const halfV= (uint8_t*)temp;\
1078
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
1079
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
1080
}\
1081
\
1082
static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1083
    uint64_t temp[SIZE*SIZE/8];\
1084
    uint8_t * const halfV= (uint8_t*)temp;\
1085
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
1086
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
1087
}\
1088
\
1089
static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1090
    uint64_t temp[SIZE*SIZE/8];\
1091
    uint8_t * const halfV= (uint8_t*)temp;\
1092
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
1093
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
1094
}\
1095
\
1096
static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1097
    uint64_t temp[SIZE*(SIZE<8?12:24)/4];\
1098
    int16_t * const tmp= (int16_t*)temp;\
1099
    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, tmp, src, stride, SIZE, stride);\
1100
}\
1101
\
1102
static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1103
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1104
    uint8_t * const halfHV= (uint8_t*)temp;\
1105
    int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
1106
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
1107
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
1108
}\
1109
\
1110
static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1111
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1112
    uint8_t * const halfHV= (uint8_t*)temp;\
1113
    int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
1114
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
1115
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
1116
}\
1117
\
1118
static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1119
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1120
    int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
1121
    uint8_t * const halfHV= ((uint8_t*)temp);\
1122
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
1123
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
1124
}\
1125
\
1126
static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1127
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1128
    int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
1129
    uint8_t * const halfHV= ((uint8_t*)temp);\
1130
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
1131
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
1132
}\
1133

    
1134

    
1135
#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "    \n\t"
1136
#define AVG_3DNOW_OP(a,b,temp, size) \
1137
"mov" #size " " #b ", " #temp "   \n\t"\
1138
"pavgusb " #temp ", " #a "        \n\t"\
1139
"mov" #size " " #a ", " #b "      \n\t"
1140
#define AVG_MMX2_OP(a,b,temp, size) \
1141
"mov" #size " " #b ", " #temp "   \n\t"\
1142
"pavgb " #temp ", " #a "          \n\t"\
1143
"mov" #size " " #a ", " #b "      \n\t"
1144

    
1145
#define PAVGB "pavgusb"
1146
QPEL_H264(put_,       PUT_OP, 3dnow)
1147
QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow)
1148
#undef PAVGB
1149
#define PAVGB "pavgb"
1150
QPEL_H264(put_,       PUT_OP, mmx2)
1151
QPEL_H264(avg_,  AVG_MMX2_OP, mmx2)
1152
#undef PAVGB
1153

    
1154
H264_MC(put_, 4, 3dnow)
1155
H264_MC(put_, 8, 3dnow)
1156
H264_MC(put_, 16,3dnow)
1157
H264_MC(avg_, 4, 3dnow)
1158
H264_MC(avg_, 8, 3dnow)
1159
H264_MC(avg_, 16,3dnow)
1160
H264_MC(put_, 4, mmx2)
1161
H264_MC(put_, 8, mmx2)
1162
H264_MC(put_, 16,mmx2)
1163
H264_MC(avg_, 4, mmx2)
1164
H264_MC(avg_, 8, mmx2)
1165
H264_MC(avg_, 16,mmx2)
1166

    
1167

    
1168
#define H264_CHROMA_OP(S,D)
1169
#define H264_CHROMA_OP4(S,D,T)
1170
#define H264_CHROMA_MC8_TMPL put_h264_chroma_mc8_mmx
1171
#define H264_CHROMA_MC4_TMPL put_h264_chroma_mc4_mmx
1172
#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
1173
#include "dsputil_h264_template_mmx.c"
1174
#undef H264_CHROMA_OP
1175
#undef H264_CHROMA_OP4
1176
#undef H264_CHROMA_MC8_TMPL
1177
#undef H264_CHROMA_MC4_TMPL
1178
#undef H264_CHROMA_MC8_MV0
1179

    
1180
#define H264_CHROMA_OP(S,D) "pavgb " #S ", " #D " \n\t"
1181
#define H264_CHROMA_OP4(S,D,T) "movd  " #S ", " #T " \n\t"\
1182
                               "pavgb " #T ", " #D " \n\t"
1183
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_mmx2
1184
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_mmx2
1185
#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
1186
#include "dsputil_h264_template_mmx.c"
1187
#undef H264_CHROMA_OP
1188
#undef H264_CHROMA_OP4
1189
#undef H264_CHROMA_MC8_TMPL
1190
#undef H264_CHROMA_MC4_TMPL
1191
#undef H264_CHROMA_MC8_MV0
1192

    
1193
#define H264_CHROMA_OP(S,D) "pavgusb " #S ", " #D " \n\t"
1194
#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
1195
                               "pavgusb " #T ", " #D " \n\t"
1196
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_3dnow
1197
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_3dnow
1198
#define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow
1199
#include "dsputil_h264_template_mmx.c"
1200
#undef H264_CHROMA_OP
1201
#undef H264_CHROMA_OP4
1202
#undef H264_CHROMA_MC8_TMPL
1203
#undef H264_CHROMA_MC4_TMPL
1204
#undef H264_CHROMA_MC8_MV0
1205

    
1206
/***********************************/
1207
/* weighted prediction */
1208

    
1209
static inline void ff_h264_weight_WxH_mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset, int w, int h)
1210
{
1211
    int x, y;
1212
    offset <<= log2_denom;
1213
    offset += (1 << log2_denom) >> 1;
1214
    asm volatile(
1215
        "movd    %0, %%mm4        \n\t"
1216
        "movd    %1, %%mm5        \n\t"
1217
        "movd    %2, %%mm6        \n\t"
1218
        "pshufw  $0, %%mm4, %%mm4 \n\t"
1219
        "pshufw  $0, %%mm5, %%mm5 \n\t"
1220
        "pxor    %%mm7, %%mm7     \n\t"
1221
        :: "g"(weight), "g"(offset), "g"(log2_denom)
1222
    );
1223
    for(y=0; y<h; y+=2){
1224
        for(x=0; x<w; x+=4){
1225
            asm volatile(
1226
                "movd      %0,    %%mm0 \n\t"
1227
                "movd      %1,    %%mm1 \n\t"
1228
                "punpcklbw %%mm7, %%mm0 \n\t"
1229
                "punpcklbw %%mm7, %%mm1 \n\t"
1230
                "pmullw    %%mm4, %%mm0 \n\t"
1231
                "pmullw    %%mm4, %%mm1 \n\t"
1232
                "paddsw    %%mm5, %%mm0 \n\t"
1233
                "paddsw    %%mm5, %%mm1 \n\t"
1234
                "psraw     %%mm6, %%mm0 \n\t"
1235
                "psraw     %%mm6, %%mm1 \n\t"
1236
                "packuswb  %%mm7, %%mm0 \n\t"
1237
                "packuswb  %%mm7, %%mm1 \n\t"
1238
                "movd      %%mm0, %0    \n\t"
1239
                "movd      %%mm1, %1    \n\t"
1240
                : "+m"(*(uint32_t*)(dst+x)),
1241
                  "+m"(*(uint32_t*)(dst+x+stride))
1242
            );
1243
        }
1244
        dst += 2*stride;
1245
    }
1246
}
1247

    
1248
static inline void ff_h264_biweight_WxH_mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset, int w, int h)
1249
{
1250
    int x, y;
1251
    offset = ((offset + 1) | 1) << log2_denom;
1252
    asm volatile(
1253
        "movd    %0, %%mm3        \n\t"
1254
        "movd    %1, %%mm4        \n\t"
1255
        "movd    %2, %%mm5        \n\t"
1256
        "movd    %3, %%mm6        \n\t"
1257
        "pshufw  $0, %%mm3, %%mm3 \n\t"
1258
        "pshufw  $0, %%mm4, %%mm4 \n\t"
1259
        "pshufw  $0, %%mm5, %%mm5 \n\t"
1260
        "pxor    %%mm7, %%mm7     \n\t"
1261
        :: "g"(weightd), "g"(weights), "g"(offset), "g"(log2_denom+1)
1262
    );
1263
    for(y=0; y<h; y++){
1264
        for(x=0; x<w; x+=4){
1265
            asm volatile(
1266
                "movd      %0,    %%mm0 \n\t"
1267
                "movd      %1,    %%mm1 \n\t"
1268
                "punpcklbw %%mm7, %%mm0 \n\t"
1269
                "punpcklbw %%mm7, %%mm1 \n\t"
1270
                "pmullw    %%mm3, %%mm0 \n\t"
1271
                "pmullw    %%mm4, %%mm1 \n\t"
1272
                "paddsw    %%mm1, %%mm0 \n\t"
1273
                "paddsw    %%mm5, %%mm0 \n\t"
1274
                "psraw     %%mm6, %%mm0 \n\t"
1275
                "packuswb  %%mm0, %%mm0 \n\t"
1276
                "movd      %%mm0, %0    \n\t"
1277
                : "+m"(*(uint32_t*)(dst+x))
1278
                :  "m"(*(uint32_t*)(src+x))
1279
            );
1280
        }
1281
        src += stride;
1282
        dst += stride;
1283
    }
1284
}
1285

    
1286
#define H264_WEIGHT(W,H) \
1287
static void ff_h264_biweight_ ## W ## x ## H ## _mmx2(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
1288
    ff_h264_biweight_WxH_mmx2(dst, src, stride, log2_denom, weightd, weights, offset, W, H); \
1289
} \
1290
static void ff_h264_weight_ ## W ## x ## H ## _mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset){ \
1291
    ff_h264_weight_WxH_mmx2(dst, stride, log2_denom, weight, offset, W, H); \
1292
}
1293

    
1294
H264_WEIGHT(16,16)
1295
H264_WEIGHT(16, 8)
1296
H264_WEIGHT( 8,16)
1297
H264_WEIGHT( 8, 8)
1298
H264_WEIGHT( 8, 4)
1299
H264_WEIGHT( 4, 8)
1300
H264_WEIGHT( 4, 4)
1301
H264_WEIGHT( 4, 2)
1302