Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / h264dsp_mmx.c @ bda2203d

History | View | Annotate | Download (57.7 KB)

1 d2bb7db1 Loren Merritt
/*
2
 * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 d2bb7db1 Loren Merritt
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 d2bb7db1 Loren Merritt
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 d2bb7db1 Loren Merritt
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 d2bb7db1 Loren Merritt
 */
20
21
22
/***********************************/
23
/* IDCT */
24
25
/* in/out: mma=mma+mmb, mmb=mmb-mma */
26
#define SUMSUB_BA( a, b ) \
27
    "paddw "#b", "#a" \n\t"\
28
    "paddw "#b", "#b" \n\t"\
29
    "psubw "#a", "#b" \n\t"
30
31
#define SUMSUB_BADC( a, b, c, d ) \
32
    "paddw "#b", "#a" \n\t"\
33
    "paddw "#d", "#c" \n\t"\
34
    "paddw "#b", "#b" \n\t"\
35
    "paddw "#d", "#d" \n\t"\
36
    "psubw "#a", "#b" \n\t"\
37
    "psubw "#c", "#d" \n\t"
38
39
#define SUMSUBD2_AB( a, b, t ) \
40
    "movq  "#b", "#t" \n\t"\
41
    "psraw  $1 , "#b" \n\t"\
42
    "paddw "#a", "#b" \n\t"\
43
    "psraw  $1 , "#a" \n\t"\
44
    "psubw "#t", "#a" \n\t"
45
46
#define IDCT4_1D( s02, s13, d02, d13, t ) \
47
    SUMSUB_BA  ( s02, d02 )\
48
    SUMSUBD2_AB( s13, d13, t )\
49
    SUMSUB_BADC( d13, s02, s13, d02 )
50
51
#define TRANSPOSE4(a,b,c,d,t)\
52
    SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
53
    SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
54
    SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
55
    SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
56
57
#define STORE_DIFF_4P( p, t, z ) \
58
    "psraw      $6,     "#p" \n\t"\
59
    "movd       (%0),   "#t" \n\t"\
60
    "punpcklbw "#z",    "#t" \n\t"\
61
    "paddsw    "#t",    "#p" \n\t"\
62
    "packuswb  "#z",    "#p" \n\t"\
63
    "movd      "#p",    (%0) \n\t"
64
65 6da971f1 Loren Merritt
static void ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride)
66 d2bb7db1 Loren Merritt
{
67
    /* Load dct coeffs */
68
    asm volatile(
69
        "movq   (%0), %%mm0 \n\t"
70
        "movq  8(%0), %%mm1 \n\t"
71
        "movq 16(%0), %%mm2 \n\t"
72
        "movq 24(%0), %%mm3 \n\t"
73
    :: "r"(block) );
74
75
    asm volatile(
76
        /* mm1=s02+s13  mm2=s02-s13  mm4=d02+d13  mm0=d02-d13 */
77
        IDCT4_1D( %%mm2, %%mm1, %%mm0, %%mm3, %%mm4 )
78
79
        "movq      %0,    %%mm6 \n\t"
80
        /* in: 1,4,0,2  out: 1,2,3,0 */
81
        TRANSPOSE4( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 )
82
83
        "paddw     %%mm6, %%mm3 \n\t"
84
85
        /* mm2=s02+s13  mm3=s02-s13  mm4=d02+d13  mm1=d02-d13 */
86
        IDCT4_1D( %%mm4, %%mm2, %%mm3, %%mm0, %%mm1 )
87
88
        "pxor %%mm7, %%mm7    \n\t"
89
    :: "m"(ff_pw_32));
90
91
    asm volatile(
92
    STORE_DIFF_4P( %%mm0, %%mm1, %%mm7)
93
        "add %1, %0             \n\t"
94
    STORE_DIFF_4P( %%mm2, %%mm1, %%mm7)
95
        "add %1, %0             \n\t"
96
    STORE_DIFF_4P( %%mm3, %%mm1, %%mm7)
97
        "add %1, %0             \n\t"
98
    STORE_DIFF_4P( %%mm4, %%mm1, %%mm7)
99
        : "+r"(dst)
100
        : "r" ((long)stride)
101
    );
102
}
103
104 548a1c8a Loren Merritt
static inline void h264_idct8_1d(int16_t *block)
105
{
106
    asm volatile(
107
        "movq 112(%0), %%mm7  \n\t"
108
        "movq  80(%0), %%mm5  \n\t"
109
        "movq  48(%0), %%mm3  \n\t"
110
        "movq  16(%0), %%mm1  \n\t"
111
112
        "movq   %%mm7, %%mm4  \n\t"
113
        "movq   %%mm3, %%mm6  \n\t"
114
        "movq   %%mm5, %%mm0  \n\t"
115
        "movq   %%mm7, %%mm2  \n\t"
116
        "psraw  $1,    %%mm4  \n\t"
117
        "psraw  $1,    %%mm6  \n\t"
118
        "psubw  %%mm7, %%mm0  \n\t"
119
        "psubw  %%mm6, %%mm2  \n\t"
120
        "psubw  %%mm4, %%mm0  \n\t"
121
        "psubw  %%mm3, %%mm2  \n\t"
122
        "psubw  %%mm3, %%mm0  \n\t"
123
        "paddw  %%mm1, %%mm2  \n\t"
124
125
        "movq   %%mm5, %%mm4  \n\t"
126
        "movq   %%mm1, %%mm6  \n\t"
127
        "psraw  $1,    %%mm4  \n\t"
128
        "psraw  $1,    %%mm6  \n\t"
129
        "paddw  %%mm5, %%mm4  \n\t"
130
        "paddw  %%mm1, %%mm6  \n\t"
131
        "paddw  %%mm7, %%mm4  \n\t"
132
        "paddw  %%mm5, %%mm6  \n\t"
133
        "psubw  %%mm1, %%mm4  \n\t"
134
        "paddw  %%mm3, %%mm6  \n\t"
135
136
        "movq   %%mm0, %%mm1  \n\t"
137
        "movq   %%mm4, %%mm3  \n\t"
138
        "movq   %%mm2, %%mm5  \n\t"
139
        "movq   %%mm6, %%mm7  \n\t"
140
        "psraw  $2,    %%mm6  \n\t"
141
        "psraw  $2,    %%mm3  \n\t"
142
        "psraw  $2,    %%mm5  \n\t"
143
        "psraw  $2,    %%mm0  \n\t"
144
        "paddw  %%mm6, %%mm1  \n\t"
145
        "paddw  %%mm2, %%mm3  \n\t"
146
        "psubw  %%mm4, %%mm5  \n\t"
147
        "psubw  %%mm0, %%mm7  \n\t"
148
149
        "movq  32(%0), %%mm2  \n\t"
150
        "movq  96(%0), %%mm6  \n\t"
151
        "movq   %%mm2, %%mm4  \n\t"
152
        "movq   %%mm6, %%mm0  \n\t"
153
        "psraw  $1,    %%mm4  \n\t"
154
        "psraw  $1,    %%mm6  \n\t"
155
        "psubw  %%mm0, %%mm4  \n\t"
156
        "paddw  %%mm2, %%mm6  \n\t"
157
158
        "movq    (%0), %%mm2  \n\t"
159
        "movq  64(%0), %%mm0  \n\t"
160
        SUMSUB_BA( %%mm0, %%mm2 )
161
        SUMSUB_BA( %%mm6, %%mm0 )
162
        SUMSUB_BA( %%mm4, %%mm2 )
163
        SUMSUB_BA( %%mm7, %%mm6 )
164
        SUMSUB_BA( %%mm5, %%mm4 )
165
        SUMSUB_BA( %%mm3, %%mm2 )
166
        SUMSUB_BA( %%mm1, %%mm0 )
167
        :: "r"(block)
168
    );
169
}
170
171
static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
172
{
173
    int i;
174
    int16_t __attribute__ ((aligned(8))) b2[64];
175
176
    block[0] += 32;
177
178
    for(i=0; i<2; i++){
179
        uint64_t tmp;
180
181
        h264_idct8_1d(block+4*i);
182
183
        asm volatile(
184
            "movq   %%mm7,    %0   \n\t"
185
            TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
186
            "movq   %%mm0,  8(%1)  \n\t"
187
            "movq   %%mm6, 24(%1)  \n\t"
188
            "movq   %%mm7, 40(%1)  \n\t"
189
            "movq   %%mm4, 56(%1)  \n\t"
190
            "movq    %0,    %%mm7  \n\t"
191
            TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
192
            "movq   %%mm7,   (%1)  \n\t"
193
            "movq   %%mm1, 16(%1)  \n\t"
194
            "movq   %%mm0, 32(%1)  \n\t"
195
            "movq   %%mm3, 48(%1)  \n\t"
196
            : "=m"(tmp)
197
            : "r"(b2+32*i)
198
            : "memory"
199
        );
200
    }
201
202
    for(i=0; i<2; i++){
203
        h264_idct8_1d(b2+4*i);
204
205
        asm volatile(
206
            "psraw     $6, %%mm7  \n\t"
207
            "psraw     $6, %%mm6  \n\t"
208
            "psraw     $6, %%mm5  \n\t"
209
            "psraw     $6, %%mm4  \n\t"
210
            "psraw     $6, %%mm3  \n\t"
211
            "psraw     $6, %%mm2  \n\t"
212
            "psraw     $6, %%mm1  \n\t"
213
            "psraw     $6, %%mm0  \n\t"
214
215
            "movq   %%mm7,    (%0)  \n\t"
216
            "movq   %%mm5,  16(%0)  \n\t"
217
            "movq   %%mm3,  32(%0)  \n\t"
218
            "movq   %%mm1,  48(%0)  \n\t"
219
            "movq   %%mm0,  64(%0)  \n\t"
220
            "movq   %%mm2,  80(%0)  \n\t"
221
            "movq   %%mm4,  96(%0)  \n\t"
222
            "movq   %%mm6, 112(%0)  \n\t"
223
            :: "r"(b2+4*i)
224
            : "memory"
225
        );
226
    }
227
228
    add_pixels_clamped_mmx(b2, dst, stride);
229
}
230
231 6da971f1 Loren Merritt
static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
232 ef9d1d15 Loren Merritt
{
233
    int dc = (block[0] + 32) >> 6;
234
    asm volatile(
235
        "movd          %0, %%mm0 \n\t"
236
        "pshufw $0, %%mm0, %%mm0 \n\t"
237
        "pxor       %%mm1, %%mm1 \n\t"
238
        "psubw      %%mm0, %%mm1 \n\t"
239
        "packuswb   %%mm0, %%mm0 \n\t"
240
        "packuswb   %%mm1, %%mm1 \n\t"
241
        ::"r"(dc)
242
    );
243
    asm volatile(
244
        "movd          %0, %%mm2 \n\t"
245
        "movd          %1, %%mm3 \n\t"
246
        "movd          %2, %%mm4 \n\t"
247
        "movd          %3, %%mm5 \n\t"
248
        "paddusb    %%mm0, %%mm2 \n\t"
249
        "paddusb    %%mm0, %%mm3 \n\t"
250
        "paddusb    %%mm0, %%mm4 \n\t"
251
        "paddusb    %%mm0, %%mm5 \n\t"
252
        "psubusb    %%mm1, %%mm2 \n\t"
253
        "psubusb    %%mm1, %%mm3 \n\t"
254
        "psubusb    %%mm1, %%mm4 \n\t"
255
        "psubusb    %%mm1, %%mm5 \n\t"
256
        "movd       %%mm2, %0    \n\t"
257
        "movd       %%mm3, %1    \n\t"
258
        "movd       %%mm4, %2    \n\t"
259
        "movd       %%mm5, %3    \n\t"
260
        :"+m"(*(uint32_t*)(dst+0*stride)),
261
         "+m"(*(uint32_t*)(dst+1*stride)),
262
         "+m"(*(uint32_t*)(dst+2*stride)),
263
         "+m"(*(uint32_t*)(dst+3*stride))
264
    );
265
}
266
267 6da971f1 Loren Merritt
static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride)
268 ef9d1d15 Loren Merritt
{
269
    int dc = (block[0] + 32) >> 6;
270
    int y;
271
    asm volatile(
272
        "movd          %0, %%mm0 \n\t"
273
        "pshufw $0, %%mm0, %%mm0 \n\t"
274
        "pxor       %%mm1, %%mm1 \n\t"
275
        "psubw      %%mm0, %%mm1 \n\t"
276
        "packuswb   %%mm0, %%mm0 \n\t"
277
        "packuswb   %%mm1, %%mm1 \n\t"
278
        ::"r"(dc)
279
    );
280
    for(y=2; y--; dst += 4*stride){
281
    asm volatile(
282
        "movq          %0, %%mm2 \n\t"
283
        "movq          %1, %%mm3 \n\t"
284
        "movq          %2, %%mm4 \n\t"
285
        "movq          %3, %%mm5 \n\t"
286
        "paddusb    %%mm0, %%mm2 \n\t"
287
        "paddusb    %%mm0, %%mm3 \n\t"
288
        "paddusb    %%mm0, %%mm4 \n\t"
289
        "paddusb    %%mm0, %%mm5 \n\t"
290
        "psubusb    %%mm1, %%mm2 \n\t"
291
        "psubusb    %%mm1, %%mm3 \n\t"
292
        "psubusb    %%mm1, %%mm4 \n\t"
293
        "psubusb    %%mm1, %%mm5 \n\t"
294
        "movq       %%mm2, %0    \n\t"
295
        "movq       %%mm3, %1    \n\t"
296
        "movq       %%mm4, %2    \n\t"
297
        "movq       %%mm5, %3    \n\t"
298
        :"+m"(*(uint64_t*)(dst+0*stride)),
299
         "+m"(*(uint64_t*)(dst+1*stride)),
300
         "+m"(*(uint64_t*)(dst+2*stride)),
301
         "+m"(*(uint64_t*)(dst+3*stride))
302
    );
303
    }
304
}
305
306 d2bb7db1 Loren Merritt
307
/***********************************/
308
/* deblocking */
309
310
// out: o = |x-y|>a
311
// clobbers: t
312
#define DIFF_GT_MMX(x,y,a,o,t)\
313
    "movq     "#y", "#t"  \n\t"\
314
    "movq     "#x", "#o"  \n\t"\
315
    "psubusb  "#x", "#t"  \n\t"\
316
    "psubusb  "#y", "#o"  \n\t"\
317
    "por      "#t", "#o"  \n\t"\
318
    "psubusb  "#a", "#o"  \n\t"
319
320
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1
321
// out: mm5=beta-1, mm7=mask
322
// clobbers: mm4,mm6
323
#define H264_DEBLOCK_MASK(alpha1, beta1) \
324
    "pshufw $0, "#alpha1", %%mm4 \n\t"\
325
    "pshufw $0, "#beta1 ", %%mm5 \n\t"\
326
    "packuswb  %%mm4, %%mm4      \n\t"\
327
    "packuswb  %%mm5, %%mm5      \n\t"\
328
    DIFF_GT_MMX(%%mm1, %%mm2, %%mm4, %%mm7, %%mm6) /* |p0-q0| > alpha-1 */\
329
    DIFF_GT_MMX(%%mm0, %%mm1, %%mm5, %%mm4, %%mm6) /* |p1-p0| > beta-1 */\
330
    "por       %%mm4, %%mm7      \n\t"\
331
    DIFF_GT_MMX(%%mm3, %%mm2, %%mm5, %%mm4, %%mm6) /* |q1-q0| > beta-1 */\
332
    "por       %%mm4, %%mm7      \n\t"\
333
    "pxor      %%mm6, %%mm6      \n\t"\
334
    "pcmpeqb   %%mm6, %%mm7      \n\t"
335
336
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask)
337
// out: mm1=p0' mm2=q0'
338
// clobbers: mm0,3-6
339
#define H264_DEBLOCK_P0_Q0(pb_01, pb_3f)\
340 e9f1885c Michael Niedermayer
        "movq    %%mm1              , %%mm5 \n\t"\
341
        "pxor    %%mm2              , %%mm5 \n\t" /* p0^q0*/\
342
        "pand    "#pb_01"           , %%mm5 \n\t" /* (p0^q0)&1*/\
343
        "pcmpeqb %%mm4              , %%mm4 \n\t"\
344
        "pxor    %%mm4              , %%mm3 \n\t"\
345
        "pavgb   %%mm0              , %%mm3 \n\t" /* (p1 - q1 + 256)>>1*/\
346
        "pavgb   "MANGLE(ff_pb_3)"  , %%mm3 \n\t" /*(((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2*/\
347
        "pxor    %%mm1              , %%mm4 \n\t"\
348
        "pavgb   %%mm2              , %%mm4 \n\t" /* (q0 - p0 + 256)>>1*/\
349
        "pavgb   %%mm5              , %%mm3 \n\t"\
350 bda2203d Michael Niedermayer
        "paddusb %%mm4              , %%mm3 \n\t" /* d+128+33*/\
351 5a1553de Michael Niedermayer
        "movq    "MANGLE(ff_pb_A1)" , %%mm6 \n\t"\
352
        "psubusb %%mm3              , %%mm6 \n\t"\
353 e9f1885c Michael Niedermayer
        "psubusb "MANGLE(ff_pb_A1)" , %%mm3 \n\t"\
354
        "pminub  %%mm7              , %%mm6 \n\t"\
355 5a1553de Michael Niedermayer
        "pminub  %%mm7              , %%mm3 \n\t"\
356 e9f1885c Michael Niedermayer
        "psubusb %%mm6              , %%mm1 \n\t"\
357 5a1553de Michael Niedermayer
        "psubusb %%mm3              , %%mm2 \n\t"\
358
        "paddusb %%mm3              , %%mm1 \n\t"\
359
        "paddusb %%mm6              , %%mm2 \n\t"
360 d2bb7db1 Loren Merritt
361
// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=mm_bone
362
// out: (q1addr) = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
363
// clobbers: q2, tmp, tc0
364
#define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\
365
        "movq     %%mm1,  "#tmp"   \n\t"\
366
        "pavgb    %%mm2,  "#tmp"   \n\t"\
367
        "pavgb    "#tmp", "#q2"    \n\t" /* avg(p2,avg(p0,q0)) */\
368
        "pxor   "q2addr", "#tmp"   \n\t"\
369
        "pand     %8,     "#tmp"   \n\t" /* (p2^avg(p0,q0))&1 */\
370
        "psubusb  "#tmp", "#q2"    \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\
371
        "movq     "#p1",  "#tmp"   \n\t"\
372
        "psubusb  "#tc0", "#tmp"   \n\t"\
373
        "paddusb  "#p1",  "#tc0"   \n\t"\
374
        "pmaxub   "#tmp", "#q2"    \n\t"\
375
        "pminub   "#tc0", "#q2"    \n\t"\
376
        "movq     "#q2",  "q1addr" \n\t"
377
378
static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
379
{
380
    uint64_t tmp0;
381
    uint64_t tc = (uint8_t)tc0[1]*0x01010000 | (uint8_t)tc0[0]*0x0101;
382
    // with luma, tc0=0 doesn't mean no filtering, so we need a separate input mask
383
    uint32_t mask[2] = { (tc0[0]>=0)*0xffffffff, (tc0[1]>=0)*0xffffffff };
384
385
    asm volatile(
386
        "movq    (%1,%3), %%mm0    \n\t" //p1
387
        "movq    (%1,%3,2), %%mm1  \n\t" //p0
388
        "movq    (%2),    %%mm2    \n\t" //q0
389
        "movq    (%2,%3), %%mm3    \n\t" //q1
390
        H264_DEBLOCK_MASK(%6, %7)
391
        "pand     %5,     %%mm7    \n\t"
392
        "movq     %%mm7,  %0       \n\t"
393
394
        /* filter p1 */
395
        "movq     (%1),   %%mm3    \n\t" //p2
396
        DIFF_GT_MMX(%%mm1, %%mm3, %%mm5, %%mm6, %%mm4) // |p2-p0|>beta-1
397
        "pandn    %%mm7,  %%mm6    \n\t"
398
        "pcmpeqb  %%mm7,  %%mm6    \n\t"
399
        "pand     %%mm7,  %%mm6    \n\t" // mask & |p2-p0|<beta
400
        "pshufw  $80, %4, %%mm4    \n\t"
401
        "pand     %%mm7,  %%mm4    \n\t" // mask & tc0
402
        "movq     %8,     %%mm7    \n\t"
403
        "pand     %%mm6,  %%mm7    \n\t" // mask & |p2-p0|<beta & 1
404
        "pand     %%mm4,  %%mm6    \n\t" // mask & |p2-p0|<beta & tc0
405
        "paddb    %%mm4,  %%mm7    \n\t" // tc++
406
        H264_DEBLOCK_Q1(%%mm0, %%mm3, "(%1)", "(%1,%3)", %%mm6, %%mm4)
407
408
        /* filter q1 */
409
        "movq    (%2,%3,2), %%mm4  \n\t" //q2
410
        DIFF_GT_MMX(%%mm2, %%mm4, %%mm5, %%mm6, %%mm3) // |q2-q0|>beta-1
411
        "pandn    %0,     %%mm6    \n\t"
412
        "pcmpeqb  %0,     %%mm6    \n\t"
413
        "pand     %0,     %%mm6    \n\t"
414
        "pshufw  $80, %4, %%mm5    \n\t"
415
        "pand     %%mm6,  %%mm5    \n\t"
416
        "pand     %8,     %%mm6    \n\t"
417
        "paddb    %%mm6,  %%mm7    \n\t"
418
        "movq    (%2,%3), %%mm3    \n\t"
419
        H264_DEBLOCK_Q1(%%mm3, %%mm4, "(%2,%3,2)", "(%2,%3)", %%mm5, %%mm6)
420
421
        /* filter p0, q0 */
422
        H264_DEBLOCK_P0_Q0(%8, %9)
423
        "movq      %%mm1, (%1,%3,2) \n\t"
424
        "movq      %%mm2, (%2)      \n\t"
425
426
        : "=m"(tmp0)
427
        : "r"(pix-3*stride), "r"(pix), "r"((long)stride),
428
          "m"(tc), "m"(*(uint64_t*)mask), "m"(alpha1), "m"(beta1),
429
          "m"(mm_bone), "m"(ff_pb_3F)
430
    );
431
}
432
433
static void h264_v_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
434
{
435
    if((tc0[0] & tc0[1]) >= 0)
436
        h264_loop_filter_luma_mmx2(pix, stride, alpha-1, beta-1, tc0);
437
    if((tc0[2] & tc0[3]) >= 0)
438
        h264_loop_filter_luma_mmx2(pix+8, stride, alpha-1, beta-1, tc0+2);
439
}
440
static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
441
{
442
    //FIXME: could cut some load/stores by merging transpose with filter
443
    // also, it only needs to transpose 6x8
444
    uint8_t trans[8*8];
445
    int i;
446
    for(i=0; i<2; i++, pix+=8*stride, tc0+=2) {
447
        if((tc0[0] & tc0[1]) < 0)
448
            continue;
449
        transpose4x4(trans,       pix-4,          8, stride);
450
        transpose4x4(trans  +4*8, pix,            8, stride);
451
        transpose4x4(trans+4,     pix-4+4*stride, 8, stride);
452
        transpose4x4(trans+4+4*8, pix  +4*stride, 8, stride);
453
        h264_loop_filter_luma_mmx2(trans+4*8, 8, alpha-1, beta-1, tc0);
454
        transpose4x4(pix-2,          trans  +2*8, stride, 8);
455
        transpose4x4(pix-2+4*stride, trans+4+2*8, stride, 8);
456
    }
457
}
458
459
static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)
460
{
461
    asm volatile(
462
        "movq    (%0),    %%mm0     \n\t" //p1
463
        "movq    (%0,%2), %%mm1     \n\t" //p0
464
        "movq    (%1),    %%mm2     \n\t" //q0
465
        "movq    (%1,%2), %%mm3     \n\t" //q1
466
        H264_DEBLOCK_MASK(%4, %5)
467
        "movd      %3,    %%mm6     \n\t"
468
        "punpcklbw %%mm6, %%mm6     \n\t"
469
        "pand      %%mm6, %%mm7     \n\t" // mm7 = tc&mask
470
        H264_DEBLOCK_P0_Q0(%6, %7)
471
        "movq      %%mm1, (%0,%2)   \n\t"
472
        "movq      %%mm2, (%1)      \n\t"
473
474
        :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
475
           "r"(*(uint32_t*)tc0),
476
           "m"(alpha1), "m"(beta1), "m"(mm_bone), "m"(ff_pb_3F)
477
    );
478
}
479
480
static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
481
{
482
    h264_loop_filter_chroma_mmx2(pix, stride, alpha-1, beta-1, tc0);
483
}
484
485
static void h264_h_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
486
{
487
    //FIXME: could cut some load/stores by merging transpose with filter
488
    uint8_t trans[8*4];
489
    transpose4x4(trans, pix-2, 8, stride);
490
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
491
    h264_loop_filter_chroma_mmx2(trans+2*8, 8, alpha-1, beta-1, tc0);
492
    transpose4x4(pix-2, trans, stride, 8);
493
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
494
}
495
496
// p0 = (p0 + q1 + 2*p1 + 2) >> 2
497
#define H264_FILTER_CHROMA4(p0, p1, q1, one) \
498
    "movq    "#p0", %%mm4  \n\t"\
499
    "pxor    "#q1", %%mm4  \n\t"\
500
    "pand   "#one", %%mm4  \n\t" /* mm4 = (p0^q1)&1 */\
501
    "pavgb   "#q1", "#p0"  \n\t"\
502
    "psubusb %%mm4, "#p0"  \n\t"\
503
    "pavgb   "#p1", "#p0"  \n\t" /* dst = avg(p1, avg(p0,q1) - ((p0^q1)&1)) */\
504
505
static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha1, int beta1)
506
{
507
    asm volatile(
508
        "movq    (%0),    %%mm0     \n\t"
509
        "movq    (%0,%2), %%mm1     \n\t"
510
        "movq    (%1),    %%mm2     \n\t"
511
        "movq    (%1,%2), %%mm3     \n\t"
512
        H264_DEBLOCK_MASK(%3, %4)
513
        "movq    %%mm1,   %%mm5     \n\t"
514
        "movq    %%mm2,   %%mm6     \n\t"
515
        H264_FILTER_CHROMA4(%%mm1, %%mm0, %%mm3, %5) //p0'
516
        H264_FILTER_CHROMA4(%%mm2, %%mm3, %%mm0, %5) //q0'
517
        "psubb   %%mm5,   %%mm1     \n\t"
518
        "psubb   %%mm6,   %%mm2     \n\t"
519
        "pand    %%mm7,   %%mm1     \n\t"
520
        "pand    %%mm7,   %%mm2     \n\t"
521
        "paddb   %%mm5,   %%mm1     \n\t"
522
        "paddb   %%mm6,   %%mm2     \n\t"
523
        "movq    %%mm1,   (%0,%2)   \n\t"
524
        "movq    %%mm2,   (%1)      \n\t"
525
        :: "r"(pix-2*stride), "r"(pix), "r"((long)stride),
526
           "m"(alpha1), "m"(beta1), "m"(mm_bone)
527
    );
528
}
529
530
static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
531
{
532
    h264_loop_filter_chroma_intra_mmx2(pix, stride, alpha-1, beta-1);
533
}
534
535
static void h264_h_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta)
536
{
537
    //FIXME: could cut some load/stores by merging transpose with filter
538
    uint8_t trans[8*4];
539
    transpose4x4(trans, pix-2, 8, stride);
540
    transpose4x4(trans+4, pix-2+4*stride, 8, stride);
541
    h264_loop_filter_chroma_intra_mmx2(trans+2*8, 8, alpha-1, beta-1);
542
    transpose4x4(pix-2, trans, stride, 8);
543
    transpose4x4(pix-2+4*stride, trans+4, stride, 8);
544
}
545
546 3e20143e Loren Merritt
static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
547
                                            int bidir, int edges, int step, int mask_mv0, int mask_mv1 ) {
548
    int dir;
549
    asm volatile(
550
        "pxor %%mm7, %%mm7 \n\t"
551
        "movq %0, %%mm6 \n\t"
552
        "movq %1, %%mm5 \n\t"
553
        "movq %2, %%mm4 \n\t"
554
        ::"m"(ff_pb_1), "m"(ff_pb_3), "m"(ff_pb_7)
555
    );
556
    // could do a special case for dir==0 && edges==1, but it only reduces the
557
    // average filter time by 1.2%
558
    for( dir=1; dir>=0; dir-- ) {
559
        const int d_idx = dir ? -8 : -1;
560
        const int mask_mv = dir ? mask_mv1 : mask_mv0;
561
        const uint64_t mask_dir = dir ? 0 : 0xffffffffffffffffULL;
562
        int b_idx, edge, l;
563
        for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) {
564
            asm volatile(
565
                "pand %0, %%mm0 \n\t"
566
                ::"m"(mask_dir)
567
            );
568
            if(!(mask_mv & edge)) {
569
                asm volatile("pxor %%mm0, %%mm0 \n\t":);
570
                for( l = bidir; l >= 0; l-- ) {
571
                    asm volatile(
572
                        "movd %0, %%mm1 \n\t"
573
                        "punpckldq %1, %%mm1 \n\t"
574
                        "movq %%mm1, %%mm2 \n\t"
575
                        "psrlw $7, %%mm2 \n\t"
576
                        "pand %%mm6, %%mm2 \n\t"
577
                        "por %%mm2, %%mm1 \n\t" // ref_cache with -2 mapped to -1
578
                        "punpckldq %%mm1, %%mm2 \n\t"
579
                        "pcmpeqb %%mm2, %%mm1 \n\t"
580
                        "paddb %%mm6, %%mm1 \n\t"
581
                        "punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn]
582
                        "por %%mm1, %%mm0 \n\t"
583
584
                        "movq %2, %%mm1 \n\t"
585
                        "movq %3, %%mm2 \n\t"
586
                        "psubw %4, %%mm1 \n\t"
587
                        "psubw %5, %%mm2 \n\t"
588
                        "packsswb %%mm2, %%mm1 \n\t"
589
                        "paddb %%mm5, %%mm1 \n\t"
590
                        "pminub %%mm4, %%mm1 \n\t"
591
                        "pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit
592
                        "por %%mm1, %%mm0 \n\t"
593
                        ::"m"(ref[l][b_idx]),
594
                          "m"(ref[l][b_idx+d_idx]),
595
                          "m"(mv[l][b_idx][0]),
596
                          "m"(mv[l][b_idx+2][0]),
597
                          "m"(mv[l][b_idx+d_idx][0]),
598
                          "m"(mv[l][b_idx+d_idx+2][0])
599
                    );
600
                }
601
            }
602
            asm volatile(
603
                "movd %0, %%mm1 \n\t"
604
                "por  %1, %%mm1 \n\t"
605
                "punpcklbw %%mm7, %%mm1 \n\t"
606
                "pcmpgtw %%mm7, %%mm1 \n\t" // nnz[b] || nnz[bn]
607
                ::"m"(nnz[b_idx]),
608
                  "m"(nnz[b_idx+d_idx])
609
            );
610
            asm volatile(
611
                "pcmpeqw %%mm7, %%mm0 \n\t"
612
                "pcmpeqw %%mm7, %%mm0 \n\t"
613
                "psrlw $15, %%mm0 \n\t" // nonzero -> 1
614
                "psrlw $14, %%mm1 \n\t"
615
                "movq %%mm0, %%mm2 \n\t"
616
                "por %%mm1, %%mm2 \n\t"
617
                "psrlw $1, %%mm1 \n\t"
618
                "pandn %%mm2, %%mm1 \n\t"
619
                "movq %%mm1, %0 \n\t"
620
                :"=m"(*bS[dir][edge])
621
                ::"memory"
622
            );
623
        }
624
        edges = 4;
625
        step = 1;
626
    }
627
    asm volatile(
628
        "movq   (%0), %%mm0 \n\t"
629
        "movq  8(%0), %%mm1 \n\t"
630
        "movq 16(%0), %%mm2 \n\t"
631
        "movq 24(%0), %%mm3 \n\t"
632
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4)
633
        "movq %%mm0,   (%0) \n\t"
634
        "movq %%mm3,  8(%0) \n\t"
635
        "movq %%mm4, 16(%0) \n\t"
636
        "movq %%mm2, 24(%0) \n\t"
637
        ::"r"(bS[0])
638
        :"memory"
639
    );
640
}
641 d2bb7db1 Loren Merritt
642
/***********************************/
643
/* motion compensation */
644
645
#define QPEL_H264V(A,B,C,D,E,F,OP)\
646 bb270c08 Diego Biurrun
        "movd (%0), "#F"            \n\t"\
647
        "movq "#C", %%mm6           \n\t"\
648
        "paddw "#D", %%mm6          \n\t"\
649
        "psllw $2, %%mm6            \n\t"\
650
        "psubw "#B", %%mm6          \n\t"\
651
        "psubw "#E", %%mm6          \n\t"\
652
        "pmullw %4, %%mm6           \n\t"\
653
        "add %2, %0                 \n\t"\
654
        "punpcklbw %%mm7, "#F"      \n\t"\
655
        "paddw %5, "#A"             \n\t"\
656
        "paddw "#F", "#A"           \n\t"\
657
        "paddw "#A", %%mm6          \n\t"\
658
        "psraw $5, %%mm6            \n\t"\
659
        "packuswb %%mm6, %%mm6      \n\t"\
660 d2bb7db1 Loren Merritt
        OP(%%mm6, (%1), A, d)\
661 bb270c08 Diego Biurrun
        "add %3, %1                 \n\t"
662 d2bb7db1 Loren Merritt
663
#define QPEL_H264HV(A,B,C,D,E,F,OF)\
664 bb270c08 Diego Biurrun
        "movd (%0), "#F"            \n\t"\
665
        "movq "#C", %%mm6           \n\t"\
666
        "paddw "#D", %%mm6          \n\t"\
667
        "psllw $2, %%mm6            \n\t"\
668
        "psubw "#B", %%mm6          \n\t"\
669
        "psubw "#E", %%mm6          \n\t"\
670
        "pmullw %3, %%mm6           \n\t"\
671
        "add %2, %0                 \n\t"\
672
        "punpcklbw %%mm7, "#F"      \n\t"\
673
        "paddw "#F", "#A"           \n\t"\
674
        "paddw "#A", %%mm6          \n\t"\
675
        "movq %%mm6, "#OF"(%1)      \n\t"
676 115329f1 Diego Biurrun
677 d2bb7db1 Loren Merritt
#define QPEL_H264(OPNAME, OP, MMX)\
678
static void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
679
    int h=4;\
680
\
681
    asm volatile(\
682 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
683
        "movq %5, %%mm4             \n\t"\
684
        "movq %6, %%mm5             \n\t"\
685
        "1:                         \n\t"\
686
        "movd  -1(%0), %%mm1        \n\t"\
687
        "movd    (%0), %%mm2        \n\t"\
688
        "movd   1(%0), %%mm3        \n\t"\
689
        "movd   2(%0), %%mm0        \n\t"\
690
        "punpcklbw %%mm7, %%mm1     \n\t"\
691
        "punpcklbw %%mm7, %%mm2     \n\t"\
692
        "punpcklbw %%mm7, %%mm3     \n\t"\
693
        "punpcklbw %%mm7, %%mm0     \n\t"\
694
        "paddw %%mm0, %%mm1         \n\t"\
695
        "paddw %%mm3, %%mm2         \n\t"\
696
        "movd  -2(%0), %%mm0        \n\t"\
697
        "movd   3(%0), %%mm3        \n\t"\
698
        "punpcklbw %%mm7, %%mm0     \n\t"\
699
        "punpcklbw %%mm7, %%mm3     \n\t"\
700
        "paddw %%mm3, %%mm0         \n\t"\
701
        "psllw $2, %%mm2            \n\t"\
702
        "psubw %%mm1, %%mm2         \n\t"\
703
        "pmullw %%mm4, %%mm2        \n\t"\
704
        "paddw %%mm5, %%mm0         \n\t"\
705
        "paddw %%mm2, %%mm0         \n\t"\
706
        "psraw $5, %%mm0            \n\t"\
707
        "packuswb %%mm0, %%mm0      \n\t"\
708 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm6, d)\
709 bb270c08 Diego Biurrun
        "add %3, %0                 \n\t"\
710
        "add %4, %1                 \n\t"\
711
        "decl %2                    \n\t"\
712
        " jnz 1b                    \n\t"\
713 d2bb7db1 Loren Merritt
        : "+a"(src), "+c"(dst), "+m"(h)\
714
        : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
715
        : "memory"\
716
    );\
717
}\
718 6a8eb0f4 Loren Merritt
static void OPNAME ## h264_qpel4_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
719
    int h=4;\
720
    asm volatile(\
721
        "pxor %%mm7, %%mm7          \n\t"\
722 d84f7c61 Loren Merritt
        "movq %0, %%mm4             \n\t"\
723
        "movq %1, %%mm5             \n\t"\
724
        :: "m"(ff_pw_5), "m"(ff_pw_16)\
725
    );\
726
    do{\
727
    asm volatile(\
728 6a8eb0f4 Loren Merritt
        "movd  -1(%0), %%mm1        \n\t"\
729
        "movd    (%0), %%mm2        \n\t"\
730
        "movd   1(%0), %%mm3        \n\t"\
731
        "movd   2(%0), %%mm0        \n\t"\
732
        "punpcklbw %%mm7, %%mm1     \n\t"\
733
        "punpcklbw %%mm7, %%mm2     \n\t"\
734
        "punpcklbw %%mm7, %%mm3     \n\t"\
735
        "punpcklbw %%mm7, %%mm0     \n\t"\
736
        "paddw %%mm0, %%mm1         \n\t"\
737
        "paddw %%mm3, %%mm2         \n\t"\
738
        "movd  -2(%0), %%mm0        \n\t"\
739
        "movd   3(%0), %%mm3        \n\t"\
740
        "punpcklbw %%mm7, %%mm0     \n\t"\
741
        "punpcklbw %%mm7, %%mm3     \n\t"\
742
        "paddw %%mm3, %%mm0         \n\t"\
743
        "psllw $2, %%mm2            \n\t"\
744
        "psubw %%mm1, %%mm2         \n\t"\
745
        "pmullw %%mm4, %%mm2        \n\t"\
746
        "paddw %%mm5, %%mm0         \n\t"\
747
        "paddw %%mm2, %%mm0         \n\t"\
748
        "movd   (%2), %%mm3         \n\t"\
749
        "psraw $5, %%mm0            \n\t"\
750
        "packuswb %%mm0, %%mm0      \n\t"\
751
        PAVGB" %%mm3, %%mm0         \n\t"\
752
        OP(%%mm0, (%1),%%mm6, d)\
753 d84f7c61 Loren Merritt
        "add %4, %0                 \n\t"\
754
        "add %4, %1                 \n\t"\
755
        "add %3, %2                 \n\t"\
756
        : "+a"(src), "+c"(dst), "+d"(src2)\
757
        : "D"((long)src2Stride), "S"((long)dstStride)\
758 6a8eb0f4 Loren Merritt
        : "memory"\
759
    );\
760 d84f7c61 Loren Merritt
    }while(--h);\
761 6a8eb0f4 Loren Merritt
}\
762 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel4_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
763
    src -= 2*srcStride;\
764
    asm volatile(\
765 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
766
        "movd (%0), %%mm0           \n\t"\
767
        "add %2, %0                 \n\t"\
768
        "movd (%0), %%mm1           \n\t"\
769
        "add %2, %0                 \n\t"\
770
        "movd (%0), %%mm2           \n\t"\
771
        "add %2, %0                 \n\t"\
772
        "movd (%0), %%mm3           \n\t"\
773
        "add %2, %0                 \n\t"\
774
        "movd (%0), %%mm4           \n\t"\
775
        "add %2, %0                 \n\t"\
776
        "punpcklbw %%mm7, %%mm0     \n\t"\
777
        "punpcklbw %%mm7, %%mm1     \n\t"\
778
        "punpcklbw %%mm7, %%mm2     \n\t"\
779
        "punpcklbw %%mm7, %%mm3     \n\t"\
780
        "punpcklbw %%mm7, %%mm4     \n\t"\
781 d2bb7db1 Loren Merritt
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
782
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
783
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
784
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
785
         \
786
        : "+a"(src), "+c"(dst)\
787
        : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
788
        : "memory"\
789
    );\
790
}\
791
static void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
792
    int h=4;\
793
    int w=3;\
794
    src -= 2*srcStride+2;\
795
    while(w--){\
796
        asm volatile(\
797 bb270c08 Diego Biurrun
            "pxor %%mm7, %%mm7      \n\t"\
798
            "movd (%0), %%mm0       \n\t"\
799
            "add %2, %0             \n\t"\
800
            "movd (%0), %%mm1       \n\t"\
801
            "add %2, %0             \n\t"\
802
            "movd (%0), %%mm2       \n\t"\
803
            "add %2, %0             \n\t"\
804
            "movd (%0), %%mm3       \n\t"\
805
            "add %2, %0             \n\t"\
806
            "movd (%0), %%mm4       \n\t"\
807
            "add %2, %0             \n\t"\
808
            "punpcklbw %%mm7, %%mm0 \n\t"\
809
            "punpcklbw %%mm7, %%mm1 \n\t"\
810
            "punpcklbw %%mm7, %%mm2 \n\t"\
811
            "punpcklbw %%mm7, %%mm3 \n\t"\
812
            "punpcklbw %%mm7, %%mm4 \n\t"\
813 d2bb7db1 Loren Merritt
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*8*3)\
814
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*8*3)\
815
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*8*3)\
816
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\
817
             \
818
            : "+a"(src)\
819
            : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
820
            : "memory"\
821
        );\
822
        tmp += 4;\
823
        src += 4 - 9*srcStride;\
824
    }\
825
    tmp -= 3*4;\
826
    asm volatile(\
827 bb270c08 Diego Biurrun
        "movq %4, %%mm6             \n\t"\
828
        "1:                         \n\t"\
829
        "movq     (%0), %%mm0       \n\t"\
830
        "paddw  10(%0), %%mm0       \n\t"\
831
        "movq    2(%0), %%mm1       \n\t"\
832
        "paddw   8(%0), %%mm1       \n\t"\
833
        "movq    4(%0), %%mm2       \n\t"\
834
        "paddw   6(%0), %%mm2       \n\t"\
835
        "psubw %%mm1, %%mm0         \n\t"/*a-b   (abccba)*/\
836
        "psraw $2, %%mm0            \n\t"/*(a-b)/4 */\
837
        "psubw %%mm1, %%mm0         \n\t"/*(a-b)/4-b */\
838
        "paddsw %%mm2, %%mm0        \n\t"\
839 cec93959 Loren Merritt
        "psraw $2, %%mm0            \n\t"/*((a-b)/4-b+c)/4 */\
840 bb270c08 Diego Biurrun
        "paddw %%mm6, %%mm2         \n\t"\
841 cec93959 Loren Merritt
        "paddw %%mm2, %%mm0         \n\t"/*(a-5*b+20*c)/16 +32 */\
842 bb270c08 Diego Biurrun
        "psraw $6, %%mm0            \n\t"\
843
        "packuswb %%mm0, %%mm0      \n\t"\
844 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm7, d)\
845 bb270c08 Diego Biurrun
        "add $24, %0                \n\t"\
846
        "add %3, %1                 \n\t"\
847
        "decl %2                    \n\t"\
848
        " jnz 1b                    \n\t"\
849 d2bb7db1 Loren Merritt
        : "+a"(tmp), "+c"(dst), "+m"(h)\
850
        : "S"((long)dstStride), "m"(ff_pw_32)\
851
        : "memory"\
852
    );\
853
}\
854
\
855
static void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
856
    int h=8;\
857
    asm volatile(\
858 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
859
        "movq %5, %%mm6             \n\t"\
860
        "1:                         \n\t"\
861
        "movq    (%0), %%mm0        \n\t"\
862
        "movq   1(%0), %%mm2        \n\t"\
863
        "movq %%mm0, %%mm1          \n\t"\
864
        "movq %%mm2, %%mm3          \n\t"\
865
        "punpcklbw %%mm7, %%mm0     \n\t"\
866
        "punpckhbw %%mm7, %%mm1     \n\t"\
867
        "punpcklbw %%mm7, %%mm2     \n\t"\
868
        "punpckhbw %%mm7, %%mm3     \n\t"\
869
        "paddw %%mm2, %%mm0         \n\t"\
870
        "paddw %%mm3, %%mm1         \n\t"\
871
        "psllw $2, %%mm0            \n\t"\
872
        "psllw $2, %%mm1            \n\t"\
873
        "movq   -1(%0), %%mm2       \n\t"\
874
        "movq    2(%0), %%mm4       \n\t"\
875
        "movq %%mm2, %%mm3          \n\t"\
876
        "movq %%mm4, %%mm5          \n\t"\
877
        "punpcklbw %%mm7, %%mm2     \n\t"\
878
        "punpckhbw %%mm7, %%mm3     \n\t"\
879
        "punpcklbw %%mm7, %%mm4     \n\t"\
880
        "punpckhbw %%mm7, %%mm5     \n\t"\
881
        "paddw %%mm4, %%mm2         \n\t"\
882
        "paddw %%mm3, %%mm5         \n\t"\
883
        "psubw %%mm2, %%mm0         \n\t"\
884
        "psubw %%mm5, %%mm1         \n\t"\
885
        "pmullw %%mm6, %%mm0        \n\t"\
886
        "pmullw %%mm6, %%mm1        \n\t"\
887
        "movd   -2(%0), %%mm2       \n\t"\
888
        "movd    7(%0), %%mm5       \n\t"\
889
        "punpcklbw %%mm7, %%mm2     \n\t"\
890
        "punpcklbw %%mm7, %%mm5     \n\t"\
891
        "paddw %%mm3, %%mm2         \n\t"\
892
        "paddw %%mm5, %%mm4         \n\t"\
893
        "movq %6, %%mm5             \n\t"\
894
        "paddw %%mm5, %%mm2         \n\t"\
895
        "paddw %%mm5, %%mm4         \n\t"\
896
        "paddw %%mm2, %%mm0         \n\t"\
897
        "paddw %%mm4, %%mm1         \n\t"\
898
        "psraw $5, %%mm0            \n\t"\
899
        "psraw $5, %%mm1            \n\t"\
900
        "packuswb %%mm1, %%mm0      \n\t"\
901 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm5, q)\
902 bb270c08 Diego Biurrun
        "add %3, %0                 \n\t"\
903
        "add %4, %1                 \n\t"\
904
        "decl %2                    \n\t"\
905
        " jnz 1b                    \n\t"\
906 d2bb7db1 Loren Merritt
        : "+a"(src), "+c"(dst), "+m"(h)\
907
        : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
908
        : "memory"\
909
    );\
910
}\
911
\
912 6a8eb0f4 Loren Merritt
static void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
913
    int h=8;\
914
    asm volatile(\
915
        "pxor %%mm7, %%mm7          \n\t"\
916 d84f7c61 Loren Merritt
        "movq %0, %%mm6             \n\t"\
917
        :: "m"(ff_pw_5)\
918
    );\
919
    do{\
920
    asm volatile(\
921 6a8eb0f4 Loren Merritt
        "movq    (%0), %%mm0        \n\t"\
922
        "movq   1(%0), %%mm2        \n\t"\
923
        "movq %%mm0, %%mm1          \n\t"\
924
        "movq %%mm2, %%mm3          \n\t"\
925
        "punpcklbw %%mm7, %%mm0     \n\t"\
926
        "punpckhbw %%mm7, %%mm1     \n\t"\
927
        "punpcklbw %%mm7, %%mm2     \n\t"\
928
        "punpckhbw %%mm7, %%mm3     \n\t"\
929
        "paddw %%mm2, %%mm0         \n\t"\
930
        "paddw %%mm3, %%mm1         \n\t"\
931
        "psllw $2, %%mm0            \n\t"\
932
        "psllw $2, %%mm1            \n\t"\
933
        "movq   -1(%0), %%mm2       \n\t"\
934
        "movq    2(%0), %%mm4       \n\t"\
935
        "movq %%mm2, %%mm3          \n\t"\
936
        "movq %%mm4, %%mm5          \n\t"\
937
        "punpcklbw %%mm7, %%mm2     \n\t"\
938
        "punpckhbw %%mm7, %%mm3     \n\t"\
939
        "punpcklbw %%mm7, %%mm4     \n\t"\
940
        "punpckhbw %%mm7, %%mm5     \n\t"\
941
        "paddw %%mm4, %%mm2         \n\t"\
942
        "paddw %%mm3, %%mm5         \n\t"\
943
        "psubw %%mm2, %%mm0         \n\t"\
944
        "psubw %%mm5, %%mm1         \n\t"\
945
        "pmullw %%mm6, %%mm0        \n\t"\
946
        "pmullw %%mm6, %%mm1        \n\t"\
947
        "movd   -2(%0), %%mm2       \n\t"\
948
        "movd    7(%0), %%mm5       \n\t"\
949
        "punpcklbw %%mm7, %%mm2     \n\t"\
950
        "punpcklbw %%mm7, %%mm5     \n\t"\
951
        "paddw %%mm3, %%mm2         \n\t"\
952
        "paddw %%mm5, %%mm4         \n\t"\
953 d84f7c61 Loren Merritt
        "movq %5, %%mm5             \n\t"\
954 6a8eb0f4 Loren Merritt
        "paddw %%mm5, %%mm2         \n\t"\
955
        "paddw %%mm5, %%mm4         \n\t"\
956
        "paddw %%mm2, %%mm0         \n\t"\
957
        "paddw %%mm4, %%mm1         \n\t"\
958
        "psraw $5, %%mm0            \n\t"\
959
        "psraw $5, %%mm1            \n\t"\
960
        "movq (%2), %%mm4           \n\t"\
961
        "packuswb %%mm1, %%mm0      \n\t"\
962
        PAVGB" %%mm4, %%mm0         \n\t"\
963
        OP(%%mm0, (%1),%%mm5, q)\
964 d84f7c61 Loren Merritt
        "add %4, %0                 \n\t"\
965
        "add %4, %1                 \n\t"\
966
        "add %3, %2                 \n\t"\
967
        : "+a"(src), "+c"(dst), "+d"(src2)\
968 6a8eb0f4 Loren Merritt
        : "D"((long)src2Stride), "S"((long)dstStride),\
969 d84f7c61 Loren Merritt
          "m"(ff_pw_16)\
970 6a8eb0f4 Loren Merritt
        : "memory"\
971
    );\
972 d84f7c61 Loren Merritt
    }while(--h);\
973 6a8eb0f4 Loren Merritt
}\
974
\
975 c03ce51d Loren Merritt
static inline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
976
    int w= 2;\
977 d2bb7db1 Loren Merritt
    src -= 2*srcStride;\
978
    \
979 c03ce51d Loren Merritt
    while(w--){\
980 d2bb7db1 Loren Merritt
      asm volatile(\
981 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7          \n\t"\
982
        "movd (%0), %%mm0           \n\t"\
983
        "add %2, %0                 \n\t"\
984
        "movd (%0), %%mm1           \n\t"\
985
        "add %2, %0                 \n\t"\
986
        "movd (%0), %%mm2           \n\t"\
987
        "add %2, %0                 \n\t"\
988
        "movd (%0), %%mm3           \n\t"\
989
        "add %2, %0                 \n\t"\
990
        "movd (%0), %%mm4           \n\t"\
991
        "add %2, %0                 \n\t"\
992
        "punpcklbw %%mm7, %%mm0     \n\t"\
993
        "punpcklbw %%mm7, %%mm1     \n\t"\
994
        "punpcklbw %%mm7, %%mm2     \n\t"\
995
        "punpcklbw %%mm7, %%mm3     \n\t"\
996
        "punpcklbw %%mm7, %%mm4     \n\t"\
997 d2bb7db1 Loren Merritt
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
998
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
999
        QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1000
        QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1001
        QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
1002
        QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
1003
        QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1004
        QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1005
         \
1006
        : "+a"(src), "+c"(dst)\
1007
        : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1008
        : "memory"\
1009
     );\
1010 c03ce51d Loren Merritt
     if(h==16){\
1011
        asm volatile(\
1012
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1013
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1014
            QPEL_H264V(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\
1015
            QPEL_H264V(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\
1016
            QPEL_H264V(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\
1017
            QPEL_H264V(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\
1018
            QPEL_H264V(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\
1019
            QPEL_H264V(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\
1020
            \
1021
           : "+a"(src), "+c"(dst)\
1022
           : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\
1023
           : "memory"\
1024
        );\
1025
     }\
1026
     src += 4-(h+5)*srcStride;\
1027
     dst += 4-h*dstStride;\
1028 d2bb7db1 Loren Merritt
   }\
1029
}\
1030 0331f092 Loren Merritt
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){\
1031
    int h = size;\
1032
    int w = (size+8)>>2;\
1033 d2bb7db1 Loren Merritt
    src -= 2*srcStride+2;\
1034
    while(w--){\
1035
        asm volatile(\
1036 bb270c08 Diego Biurrun
            "pxor %%mm7, %%mm7      \n\t"\
1037
            "movd (%0), %%mm0       \n\t"\
1038
            "add %2, %0             \n\t"\
1039
            "movd (%0), %%mm1       \n\t"\
1040
            "add %2, %0             \n\t"\
1041
            "movd (%0), %%mm2       \n\t"\
1042
            "add %2, %0             \n\t"\
1043
            "movd (%0), %%mm3       \n\t"\
1044
            "add %2, %0             \n\t"\
1045
            "movd (%0), %%mm4       \n\t"\
1046
            "add %2, %0             \n\t"\
1047
            "punpcklbw %%mm7, %%mm0 \n\t"\
1048
            "punpcklbw %%mm7, %%mm1 \n\t"\
1049
            "punpcklbw %%mm7, %%mm2 \n\t"\
1050
            "punpcklbw %%mm7, %%mm3 \n\t"\
1051
            "punpcklbw %%mm7, %%mm4 \n\t"\
1052 0331f092 Loren Merritt
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 0*48)\
1053
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 1*48)\
1054
            QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 2*48)\
1055
            QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*48)\
1056
            QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 4*48)\
1057
            QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 5*48)\
1058
            QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\
1059
            QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\
1060 d2bb7db1 Loren Merritt
            : "+a"(src)\
1061
            : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
1062
            : "memory"\
1063
        );\
1064 0331f092 Loren Merritt
        if(size==16){\
1065
            asm volatile(\
1066
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1,  8*48)\
1067
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2,  9*48)\
1068
                QPEL_H264HV(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, 10*48)\
1069
                QPEL_H264HV(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, 11*48)\
1070
                QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 12*48)\
1071
                QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 13*48)\
1072
                QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\
1073
                QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
1074
                : "+a"(src)\
1075
                : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\
1076
                : "memory"\
1077
            );\
1078
        }\
1079 d2bb7db1 Loren Merritt
        tmp += 4;\
1080 0331f092 Loren Merritt
        src += 4 - (size+5)*srcStride;\
1081 d2bb7db1 Loren Merritt
    }\
1082 0331f092 Loren Merritt
    tmp -= size+8;\
1083
    w = size>>4;\
1084
    do{\
1085
    h = size;\
1086 d2bb7db1 Loren Merritt
    asm volatile(\
1087 bb270c08 Diego Biurrun
        "movq %4, %%mm6             \n\t"\
1088
        "1:                         \n\t"\
1089
        "movq     (%0), %%mm0       \n\t"\
1090
        "movq    8(%0), %%mm3       \n\t"\
1091
        "movq    2(%0), %%mm1       \n\t"\
1092
        "movq   10(%0), %%mm4       \n\t"\
1093
        "paddw   %%mm4, %%mm0       \n\t"\
1094
        "paddw   %%mm3, %%mm1       \n\t"\
1095
        "paddw  18(%0), %%mm3       \n\t"\
1096
        "paddw  16(%0), %%mm4       \n\t"\
1097
        "movq    4(%0), %%mm2       \n\t"\
1098
        "movq   12(%0), %%mm5       \n\t"\
1099
        "paddw   6(%0), %%mm2       \n\t"\
1100
        "paddw  14(%0), %%mm5       \n\t"\
1101
        "psubw %%mm1, %%mm0         \n\t"\
1102
        "psubw %%mm4, %%mm3         \n\t"\
1103
        "psraw $2, %%mm0            \n\t"\
1104
        "psraw $2, %%mm3            \n\t"\
1105
        "psubw %%mm1, %%mm0         \n\t"\
1106
        "psubw %%mm4, %%mm3         \n\t"\
1107
        "paddsw %%mm2, %%mm0        \n\t"\
1108
        "paddsw %%mm5, %%mm3        \n\t"\
1109
        "psraw $2, %%mm0            \n\t"\
1110
        "psraw $2, %%mm3            \n\t"\
1111
        "paddw %%mm6, %%mm2         \n\t"\
1112
        "paddw %%mm6, %%mm5         \n\t"\
1113
        "paddw %%mm2, %%mm0         \n\t"\
1114
        "paddw %%mm5, %%mm3         \n\t"\
1115
        "psraw $6, %%mm0            \n\t"\
1116
        "psraw $6, %%mm3            \n\t"\
1117
        "packuswb %%mm3, %%mm0      \n\t"\
1118 d2bb7db1 Loren Merritt
        OP(%%mm0, (%1),%%mm7, q)\
1119 0331f092 Loren Merritt
        "add $48, %0                \n\t"\
1120 bb270c08 Diego Biurrun
        "add %3, %1                 \n\t"\
1121
        "decl %2                    \n\t"\
1122
        " jnz 1b                    \n\t"\
1123 d2bb7db1 Loren Merritt
        : "+a"(tmp), "+c"(dst), "+m"(h)\
1124
        : "S"((long)dstStride), "m"(ff_pw_32)\
1125
        : "memory"\
1126
    );\
1127 0331f092 Loren Merritt
    tmp += 8 - size*24;\
1128
    dst += 8 - size*dstStride;\
1129
    }while(w--);\
1130 d2bb7db1 Loren Merritt
}\
1131 c03ce51d Loren Merritt
\
1132
static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1133
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 8);\
1134
}\
1135 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1136 c03ce51d Loren Merritt
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst  , src  , dstStride, srcStride, 16);\
1137
    OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
1138 d2bb7db1 Loren Merritt
}\
1139
\
1140
static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1141
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1142
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1143
    src += 8*srcStride;\
1144
    dst += 8*dstStride;\
1145
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst  , src  , dstStride, srcStride);\
1146
    OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
1147
}\
1148
\
1149 6a8eb0f4 Loren Merritt
static void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
1150
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1151
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1152
    src += 8*dstStride;\
1153
    dst += 8*dstStride;\
1154
    src2 += 8*src2Stride;\
1155
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst  , src  , src2  , dstStride, src2Stride);\
1156
    OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
1157
}\
1158
\
1159 0331f092 Loren Merritt
static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1160
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 8);\
1161
}\
1162
\
1163 d2bb7db1 Loren Merritt
static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1164 0331f092 Loren Merritt
    OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst  , tmp  , src  , dstStride, tmpStride, srcStride, 16);\
1165 d2bb7db1 Loren Merritt
}\
1166 e545f375 Loren Merritt
\
1167
static void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1168
{\
1169
    asm volatile(\
1170
        "movq       %5,  %%mm6          \n\t"\
1171
        "movq      (%1), %%mm0          \n\t"\
1172
        "movq    24(%1), %%mm1          \n\t"\
1173
        "paddw    %%mm6, %%mm0          \n\t"\
1174
        "paddw    %%mm6, %%mm1          \n\t"\
1175 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1176
        "psraw      $5,  %%mm1          \n\t"\
1177 7a5b2fa8 Loren Merritt
        "packuswb %%mm0, %%mm0          \n\t"\
1178
        "packuswb %%mm1, %%mm1          \n\t"\
1179 e545f375 Loren Merritt
        PAVGB"     (%0), %%mm0          \n\t"\
1180
        PAVGB"  (%0,%3), %%mm1          \n\t"\
1181
        OP(%%mm0, (%2),    %%mm4, d)\
1182
        OP(%%mm1, (%2,%4), %%mm5, d)\
1183
        "lea  (%0,%3,2), %0             \n\t"\
1184
        "lea  (%2,%4,2), %2             \n\t"\
1185
        "movq    48(%1), %%mm0          \n\t"\
1186
        "movq    72(%1), %%mm1          \n\t"\
1187
        "paddw    %%mm6, %%mm0          \n\t"\
1188
        "paddw    %%mm6, %%mm1          \n\t"\
1189 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1190
        "psraw      $5,  %%mm1          \n\t"\
1191 7a5b2fa8 Loren Merritt
        "packuswb %%mm0, %%mm0          \n\t"\
1192
        "packuswb %%mm1, %%mm1          \n\t"\
1193 e545f375 Loren Merritt
        PAVGB"     (%0), %%mm0          \n\t"\
1194
        PAVGB"  (%0,%3), %%mm1          \n\t"\
1195
        OP(%%mm0, (%2),    %%mm4, d)\
1196
        OP(%%mm1, (%2,%4), %%mm5, d)\
1197
        :"+a"(src8), "+c"(src16), "+d"(dst)\
1198 6ee66973 Loren Merritt
        :"S"((long)src8Stride), "D"((long)dstStride), "m"(ff_pw_16)\
1199 e545f375 Loren Merritt
        :"memory");\
1200
}\
1201
static void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1202
{\
1203
    asm volatile(\
1204
        "movq       %0,  %%mm6          \n\t"\
1205
        ::"m"(ff_pw_16)\
1206
        );\
1207
    while(h--){\
1208
    asm volatile(\
1209
        "movq      (%1), %%mm0          \n\t"\
1210
        "movq     8(%1), %%mm1          \n\t"\
1211
        "paddw    %%mm6, %%mm0          \n\t"\
1212
        "paddw    %%mm6, %%mm1          \n\t"\
1213 4e295993 Loren Merritt
        "psraw      $5,  %%mm0          \n\t"\
1214
        "psraw      $5,  %%mm1          \n\t"\
1215 e545f375 Loren Merritt
        "packuswb %%mm1, %%mm0          \n\t"\
1216
        PAVGB"     (%0), %%mm0          \n\t"\
1217
        OP(%%mm0, (%2), %%mm5, q)\
1218
        ::"a"(src8), "c"(src16), "d"(dst)\
1219
        :"memory");\
1220
        src8 += src8Stride;\
1221
        src16 += 24;\
1222
        dst += dstStride;\
1223
    }\
1224
}\
1225
static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
1226
{\
1227
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst  , src16  , src8  , dstStride, src8Stride, h);\
1228
    OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
1229
}\
1230
1231 d2bb7db1 Loren Merritt
1232
#define H264_MC(OPNAME, SIZE, MMX) \
1233
static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1234
    OPNAME ## pixels ## SIZE ## _mmx(dst, src, stride, SIZE);\
1235
}\
1236
\
1237
static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1238 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
1239 d2bb7db1 Loren Merritt
}\
1240
\
1241
static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1242
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
1243
}\
1244
\
1245
static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1246 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
1247 d2bb7db1 Loren Merritt
}\
1248
\
1249
static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1250
    uint64_t temp[SIZE*SIZE/8];\
1251
    uint8_t * const half= (uint8_t*)temp;\
1252
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
1253
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, half, stride, stride, SIZE);\
1254
}\
1255
\
1256
static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1257
    OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
1258
}\
1259
\
1260
static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1261
    uint64_t temp[SIZE*SIZE/8];\
1262
    uint8_t * const half= (uint8_t*)temp;\
1263
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\
1264
    OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, half, stride, stride, SIZE);\
1265
}\
1266
\
1267
static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1268 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*SIZE/8];\
1269
    uint8_t * const halfV= (uint8_t*)temp;\
1270 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
1271 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
1272 d2bb7db1 Loren Merritt
}\
1273
\
1274
static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1275 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*SIZE/8];\
1276
    uint8_t * const halfV= (uint8_t*)temp;\
1277 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
1278 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\
1279 d2bb7db1 Loren Merritt
}\
1280
\
1281
static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1282 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*SIZE/8];\
1283
    uint8_t * const halfV= (uint8_t*)temp;\
1284 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\
1285 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
1286 d2bb7db1 Loren Merritt
}\
1287
\
1288
static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1289 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*SIZE/8];\
1290
    uint8_t * const halfV= (uint8_t*)temp;\
1291 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\
1292 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\
1293 d2bb7db1 Loren Merritt
}\
1294
\
1295
static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1296 0331f092 Loren Merritt
    uint64_t temp[SIZE*(SIZE<8?12:24)/4];\
1297 d2bb7db1 Loren Merritt
    int16_t * const tmp= (int16_t*)temp;\
1298
    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, tmp, src, stride, SIZE, stride);\
1299
}\
1300
\
1301
static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1302 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1303
    uint8_t * const halfHV= (uint8_t*)temp;\
1304
    int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
1305 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
1306 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
1307 d2bb7db1 Loren Merritt
}\
1308
\
1309
static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1310 6a8eb0f4 Loren Merritt
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1311
    uint8_t * const halfHV= (uint8_t*)temp;\
1312
    int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\
1313 d2bb7db1 Loren Merritt
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\
1314 6a8eb0f4 Loren Merritt
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
1315 d2bb7db1 Loren Merritt
}\
1316
\
1317
static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1318 e545f375 Loren Merritt
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1319
    int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
1320
    uint8_t * const halfHV= ((uint8_t*)temp);\
1321
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
1322
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
1323 d2bb7db1 Loren Merritt
}\
1324
\
1325
static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1326 e545f375 Loren Merritt
    uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\
1327
    int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\
1328
    uint8_t * const halfHV= ((uint8_t*)temp);\
1329
    put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
1330
    OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
1331 d2bb7db1 Loren Merritt
}\
1332
1333
1334
#define AVG_3DNOW_OP(a,b,temp, size) \
1335 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
1336
"pavgusb " #temp ", " #a "        \n\t"\
1337
"mov" #size " " #a ", " #b "      \n\t"
1338 d2bb7db1 Loren Merritt
#define AVG_MMX2_OP(a,b,temp, size) \
1339 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
1340
"pavgb " #temp ", " #a "          \n\t"\
1341
"mov" #size " " #a ", " #b "      \n\t"
1342 d2bb7db1 Loren Merritt
1343 e545f375 Loren Merritt
#define PAVGB "pavgusb"
1344 d2bb7db1 Loren Merritt
QPEL_H264(put_,       PUT_OP, 3dnow)
1345
QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow)
1346 e545f375 Loren Merritt
#undef PAVGB
1347
#define PAVGB "pavgb"
1348 d2bb7db1 Loren Merritt
QPEL_H264(put_,       PUT_OP, mmx2)
1349
QPEL_H264(avg_,  AVG_MMX2_OP, mmx2)
1350 e545f375 Loren Merritt
#undef PAVGB
1351 d2bb7db1 Loren Merritt
1352
H264_MC(put_, 4, 3dnow)
1353
H264_MC(put_, 8, 3dnow)
1354
H264_MC(put_, 16,3dnow)
1355
H264_MC(avg_, 4, 3dnow)
1356
H264_MC(avg_, 8, 3dnow)
1357
H264_MC(avg_, 16,3dnow)
1358
H264_MC(put_, 4, mmx2)
1359
H264_MC(put_, 8, mmx2)
1360
H264_MC(put_, 16,mmx2)
1361
H264_MC(avg_, 4, mmx2)
1362
H264_MC(avg_, 8, mmx2)
1363
H264_MC(avg_, 16,mmx2)
1364
1365
1366
#define H264_CHROMA_OP(S,D)
1367 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T)
1368 d2bb7db1 Loren Merritt
#define H264_CHROMA_MC8_TMPL put_h264_chroma_mc8_mmx
1369 a6624e21 Loren Merritt
#define H264_CHROMA_MC4_TMPL put_h264_chroma_mc4_mmx
1370 fdd30579 Loren Merritt
#define H264_CHROMA_MC2_TMPL put_h264_chroma_mc2_mmx2
1371 a6624e21 Loren Merritt
#define H264_CHROMA_MC8_MV0 put_pixels8_mmx
1372 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
1373
#undef H264_CHROMA_OP
1374 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
1375 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
1376 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
1377 fdd30579 Loren Merritt
#undef H264_CHROMA_MC2_TMPL
1378 a6624e21 Loren Merritt
#undef H264_CHROMA_MC8_MV0
1379 d2bb7db1 Loren Merritt
1380
#define H264_CHROMA_OP(S,D) "pavgb " #S ", " #D " \n\t"
1381 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T) "movd  " #S ", " #T " \n\t"\
1382
                               "pavgb " #T ", " #D " \n\t"
1383 d2bb7db1 Loren Merritt
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_mmx2
1384 a6624e21 Loren Merritt
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_mmx2
1385 fdd30579 Loren Merritt
#define H264_CHROMA_MC2_TMPL avg_h264_chroma_mc2_mmx2
1386 a6624e21 Loren Merritt
#define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2
1387 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
1388
#undef H264_CHROMA_OP
1389 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
1390 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
1391 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
1392 fdd30579 Loren Merritt
#undef H264_CHROMA_MC2_TMPL
1393 a6624e21 Loren Merritt
#undef H264_CHROMA_MC8_MV0
1394 d2bb7db1 Loren Merritt
1395
#define H264_CHROMA_OP(S,D) "pavgusb " #S ", " #D " \n\t"
1396 a6624e21 Loren Merritt
#define H264_CHROMA_OP4(S,D,T) "movd " #S ", " #T " \n\t"\
1397
                               "pavgusb " #T ", " #D " \n\t"
1398 d2bb7db1 Loren Merritt
#define H264_CHROMA_MC8_TMPL avg_h264_chroma_mc8_3dnow
1399 a6624e21 Loren Merritt
#define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_3dnow
1400
#define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow
1401 d2bb7db1 Loren Merritt
#include "dsputil_h264_template_mmx.c"
1402
#undef H264_CHROMA_OP
1403 a6624e21 Loren Merritt
#undef H264_CHROMA_OP4
1404 d2bb7db1 Loren Merritt
#undef H264_CHROMA_MC8_TMPL
1405 a6624e21 Loren Merritt
#undef H264_CHROMA_MC4_TMPL
1406
#undef H264_CHROMA_MC8_MV0
1407 d2bb7db1 Loren Merritt
1408 b926572a Loren Merritt
/***********************************/
1409
/* weighted prediction */
1410
1411
static inline void ff_h264_weight_WxH_mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset, int w, int h)
1412
{
1413
    int x, y;
1414
    offset <<= log2_denom;
1415
    offset += (1 << log2_denom) >> 1;
1416
    asm volatile(
1417
        "movd    %0, %%mm4        \n\t"
1418
        "movd    %1, %%mm5        \n\t"
1419
        "movd    %2, %%mm6        \n\t"
1420
        "pshufw  $0, %%mm4, %%mm4 \n\t"
1421
        "pshufw  $0, %%mm5, %%mm5 \n\t"
1422
        "pxor    %%mm7, %%mm7     \n\t"
1423
        :: "g"(weight), "g"(offset), "g"(log2_denom)
1424
    );
1425
    for(y=0; y<h; y+=2){
1426
        for(x=0; x<w; x+=4){
1427
            asm volatile(
1428
                "movd      %0,    %%mm0 \n\t"
1429
                "movd      %1,    %%mm1 \n\t"
1430
                "punpcklbw %%mm7, %%mm0 \n\t"
1431
                "punpcklbw %%mm7, %%mm1 \n\t"
1432
                "pmullw    %%mm4, %%mm0 \n\t"
1433
                "pmullw    %%mm4, %%mm1 \n\t"
1434 cec93959 Loren Merritt
                "paddsw    %%mm5, %%mm0 \n\t"
1435
                "paddsw    %%mm5, %%mm1 \n\t"
1436 b926572a Loren Merritt
                "psraw     %%mm6, %%mm0 \n\t"
1437
                "psraw     %%mm6, %%mm1 \n\t"
1438
                "packuswb  %%mm7, %%mm0 \n\t"
1439
                "packuswb  %%mm7, %%mm1 \n\t"
1440
                "movd      %%mm0, %0    \n\t"
1441
                "movd      %%mm1, %1    \n\t"
1442
                : "+m"(*(uint32_t*)(dst+x)),
1443
                  "+m"(*(uint32_t*)(dst+x+stride))
1444
            );
1445
        }
1446
        dst += 2*stride;
1447
    }
1448
}
1449
1450 e8b56208 Loren Merritt
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)
1451 b926572a Loren Merritt
{
1452
    int x, y;
1453 e8b56208 Loren Merritt
    offset = ((offset + 1) | 1) << log2_denom;
1454 b926572a Loren Merritt
    asm volatile(
1455
        "movd    %0, %%mm3        \n\t"
1456
        "movd    %1, %%mm4        \n\t"
1457
        "movd    %2, %%mm5        \n\t"
1458
        "movd    %3, %%mm6        \n\t"
1459
        "pshufw  $0, %%mm3, %%mm3 \n\t"
1460
        "pshufw  $0, %%mm4, %%mm4 \n\t"
1461
        "pshufw  $0, %%mm5, %%mm5 \n\t"
1462
        "pxor    %%mm7, %%mm7     \n\t"
1463
        :: "g"(weightd), "g"(weights), "g"(offset), "g"(log2_denom+1)
1464
    );
1465
    for(y=0; y<h; y++){
1466
        for(x=0; x<w; x+=4){
1467
            asm volatile(
1468
                "movd      %0,    %%mm0 \n\t"
1469
                "movd      %1,    %%mm1 \n\t"
1470
                "punpcklbw %%mm7, %%mm0 \n\t"
1471
                "punpcklbw %%mm7, %%mm1 \n\t"
1472
                "pmullw    %%mm3, %%mm0 \n\t"
1473
                "pmullw    %%mm4, %%mm1 \n\t"
1474 cec93959 Loren Merritt
                "paddsw    %%mm1, %%mm0 \n\t"
1475
                "paddsw    %%mm5, %%mm0 \n\t"
1476 b926572a Loren Merritt
                "psraw     %%mm6, %%mm0 \n\t"
1477
                "packuswb  %%mm0, %%mm0 \n\t"
1478
                "movd      %%mm0, %0    \n\t"
1479
                : "+m"(*(uint32_t*)(dst+x))
1480
                :  "m"(*(uint32_t*)(src+x))
1481
            );
1482
        }
1483
        src += stride;
1484
        dst += stride;
1485
    }
1486
}
1487
1488
#define H264_WEIGHT(W,H) \
1489 e8b56208 Loren Merritt
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){ \
1490
    ff_h264_biweight_WxH_mmx2(dst, src, stride, log2_denom, weightd, weights, offset, W, H); \
1491 b926572a Loren Merritt
} \
1492
static void ff_h264_weight_ ## W ## x ## H ## _mmx2(uint8_t *dst, int stride, int log2_denom, int weight, int offset){ \
1493
    ff_h264_weight_WxH_mmx2(dst, stride, log2_denom, weight, offset, W, H); \
1494
}
1495
1496
H264_WEIGHT(16,16)
1497
H264_WEIGHT(16, 8)
1498
H264_WEIGHT( 8,16)
1499
H264_WEIGHT( 8, 8)
1500
H264_WEIGHT( 8, 4)
1501
H264_WEIGHT( 4, 8)
1502
H264_WEIGHT( 4, 4)
1503
H264_WEIGHT( 4, 2)