Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / snowdsp_mmx.c @ b550bfaa

History | View | Annotate | Download (41 KB)

1
/*
2
 * MMX and SSE2 optimized snow DSP utils
3
 * Copyright (c) 2005-2006 Robert Edele <yartrebo@earthlink.net>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
#include "avcodec.h"
23
#include "snow.h"
24
#include "x86_cpu.h"
25

    
26
void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){
27
    const int w2= (width+1)>>1;
28
    // SSE2 code runs faster with pointers aligned on a 32-byte boundary.
29
    DWTELEM temp_buf[(width>>1) + 4];
30
    DWTELEM * const temp = temp_buf + 4 - (((int)temp_buf & 0xF) >> 2);
31
    const int w_l= (width>>1);
32
    const int w_r= w2 - 1;
33
    int i;
34

    
35
    { // Lift 0
36
        DWTELEM * const ref = b + w2 - 1;
37
        DWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice
38
        // (the first time erroneously), we allow the SSE2 code to run an extra pass.
39
        // The savings in code and time are well worth having to store this value and
40
        // calculate b[0] correctly afterwards.
41

    
42
        i = 0;
43
        asm volatile(
44
            "pcmpeqd   %%xmm7, %%xmm7         \n\t"
45
            "pslld        $31, %%xmm7         \n\t"
46
            "psrld        $29, %%xmm7         \n\t"
47
        ::);
48
        for(; i<w_l-7; i+=8){
49
            asm volatile(
50
                "movdqu   (%1), %%xmm1        \n\t"
51
                "movdqu 16(%1), %%xmm5        \n\t"
52
                "movdqu  4(%1), %%xmm2        \n\t"
53
                "movdqu 20(%1), %%xmm6        \n\t"
54
                "paddd  %%xmm1, %%xmm2        \n\t"
55
                "paddd  %%xmm5, %%xmm6        \n\t"
56
                "movdqa %%xmm2, %%xmm0        \n\t"
57
                "movdqa %%xmm6, %%xmm4        \n\t"
58
                "paddd  %%xmm2, %%xmm2        \n\t"
59
                "paddd  %%xmm6, %%xmm6        \n\t"
60
                "paddd  %%xmm0, %%xmm2        \n\t"
61
                "paddd  %%xmm4, %%xmm6        \n\t"
62
                "paddd  %%xmm7, %%xmm2        \n\t"
63
                "paddd  %%xmm7, %%xmm6        \n\t"
64
                "psrad      $3, %%xmm2        \n\t"
65
                "psrad      $3, %%xmm6        \n\t"
66
                "movdqa   (%0), %%xmm0        \n\t"
67
                "movdqa 16(%0), %%xmm4        \n\t"
68
                "psubd  %%xmm2, %%xmm0        \n\t"
69
                "psubd  %%xmm6, %%xmm4        \n\t"
70
                "movdqa %%xmm0, (%0)          \n\t"
71
                "movdqa %%xmm4, 16(%0)        \n\t"
72
                :: "r"(&b[i]), "r"(&ref[i])
73
                : "memory"
74
            );
75
        }
76
        snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
77
        b[0] = b_0 - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
78
    }
79

    
80
    { // Lift 1
81
        DWTELEM * const dst = b+w2;
82

    
83
        i = 0;
84
        for(; (((long)&dst[i]) & 0xF) && i<w_r; i++){
85
            dst[i] = dst[i] - (b[i] + b[i + 1]);
86
        }
87
        for(; i<w_r-7; i+=8){
88
            asm volatile(
89
                "movdqu   (%1), %%xmm1        \n\t"
90
                "movdqu 16(%1), %%xmm5        \n\t"
91
                "movdqu  4(%1), %%xmm2        \n\t"
92
                "movdqu 20(%1), %%xmm6        \n\t"
93
                "paddd  %%xmm1, %%xmm2        \n\t"
94
                "paddd  %%xmm5, %%xmm6        \n\t"
95
                "movdqa   (%0), %%xmm0        \n\t"
96
                "movdqa 16(%0), %%xmm4        \n\t"
97
                "psubd  %%xmm2, %%xmm0        \n\t"
98
                "psubd  %%xmm6, %%xmm4        \n\t"
99
                "movdqa %%xmm0, (%0)          \n\t"
100
                "movdqa %%xmm4, 16(%0)        \n\t"
101
                :: "r"(&dst[i]), "r"(&b[i])
102
                : "memory"
103
            );
104
        }
105
        snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
106
    }
107

    
108
    { // Lift 2
109
        DWTELEM * const ref = b+w2 - 1;
110
        DWTELEM b_0 = b[0];
111

    
112
        i = 0;
113
        asm volatile(
114
            "pslld          $1, %%xmm7       \n\t" /* xmm7 already holds a '4' from 2 lifts ago. */
115
        ::);
116
        for(; i<w_l-7; i+=8){
117
            asm volatile(
118
                "movdqu   (%1), %%xmm1        \n\t"
119
                "movdqu 16(%1), %%xmm5        \n\t"
120
                "movdqu  4(%1), %%xmm0        \n\t"
121
                "movdqu 20(%1), %%xmm4        \n\t"
122
                "paddd  %%xmm1, %%xmm0        \n\t"
123
                "paddd  %%xmm5, %%xmm4        \n\t"
124
                "movdqa %%xmm7, %%xmm1        \n\t"
125
                "movdqa %%xmm7, %%xmm5        \n\t"
126
                "psubd  %%xmm0, %%xmm1        \n\t"
127
                "psubd  %%xmm4, %%xmm5        \n\t"
128
                "movdqa   (%0), %%xmm0        \n\t"
129
                "movdqa 16(%0), %%xmm4        \n\t"
130
                "pslld      $2, %%xmm0        \n\t"
131
                "pslld      $2, %%xmm4        \n\t"
132
                "psubd  %%xmm0, %%xmm1        \n\t"
133
                "psubd  %%xmm4, %%xmm5        \n\t"
134
                "psrad      $4, %%xmm1        \n\t"
135
                "psrad      $4, %%xmm5        \n\t"
136
                "movdqa   (%0), %%xmm0        \n\t"
137
                "movdqa 16(%0), %%xmm4        \n\t"
138
                "psubd  %%xmm1, %%xmm0        \n\t"
139
                "psubd  %%xmm5, %%xmm4        \n\t"
140
                "movdqa %%xmm0, (%0)          \n\t"
141
                "movdqa %%xmm4, 16(%0)        \n\t"
142
                :: "r"(&b[i]), "r"(&ref[i])
143
                : "memory"
144
            );
145
        }
146
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
147
        b[0] = b_0 - (((-2 * ref[1] + W_BO) - 4 * b_0) >> W_BS);
148
    }
149

    
150
    { // Lift 3
151
        DWTELEM * const src = b+w2;
152

    
153
        i = 0;
154
        for(; (((long)&temp[i]) & 0xF) && i<w_r; i++){
155
            temp[i] = src[i] - ((-W_AM*(b[i] + b[i+1]))>>W_AS);
156
        }
157
        for(; i<w_r-7; i+=8){
158
            asm volatile(
159
                "movdqu  4(%1), %%xmm2        \n\t"
160
                "movdqu 20(%1), %%xmm6        \n\t"
161
                "paddd    (%1), %%xmm2        \n\t"
162
                "paddd  16(%1), %%xmm6        \n\t"
163
                "movdqa %%xmm2, %%xmm0        \n\t"
164
                "movdqa %%xmm6, %%xmm4        \n\t"
165
                "pslld      $2, %%xmm2        \n\t"
166
                "pslld      $2, %%xmm6        \n\t"
167
                "psubd  %%xmm2, %%xmm0        \n\t"
168
                "psubd  %%xmm6, %%xmm4        \n\t"
169
                "psrad      $1, %%xmm0        \n\t"
170
                "psrad      $1, %%xmm4        \n\t"
171
                "movdqu   (%0), %%xmm2        \n\t"
172
                "movdqu 16(%0), %%xmm6        \n\t"
173
                "psubd  %%xmm0, %%xmm2        \n\t"
174
                "psubd  %%xmm4, %%xmm6        \n\t"
175
                "movdqa %%xmm2, (%2)          \n\t"
176
                "movdqa %%xmm6, 16(%2)        \n\t"
177
                :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
178
                 : "memory"
179
               );
180
        }
181
        snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO, W_AS);
182
    }
183

    
184
    {
185
        snow_interleave_line_header(&i, width, b, temp);
186

    
187
        for (; (i & 0x1E) != 0x1E; i-=2){
188
            b[i+1] = temp[i>>1];
189
            b[i] = b[i>>1];
190
        }
191
        for (i-=30; i>=0; i-=32){
192
            asm volatile(
193
                "movdqa      (%1), %%xmm0       \n\t"
194
                "movdqa    16(%1), %%xmm2       \n\t"
195
                "movdqa    32(%1), %%xmm4       \n\t"
196
                "movdqa    48(%1), %%xmm6       \n\t"
197
                "movdqa      (%1), %%xmm1       \n\t"
198
                "movdqa    16(%1), %%xmm3       \n\t"
199
                "movdqa    32(%1), %%xmm5       \n\t"
200
                "movdqa    48(%1), %%xmm7       \n\t"
201
                "punpckldq   (%2), %%xmm0       \n\t"
202
                "punpckldq 16(%2), %%xmm2       \n\t"
203
                "punpckldq 32(%2), %%xmm4       \n\t"
204
                "punpckldq 48(%2), %%xmm6       \n\t"
205
                "movdqa    %%xmm0, (%0)         \n\t"
206
                "movdqa    %%xmm2, 32(%0)       \n\t"
207
                "movdqa    %%xmm4, 64(%0)       \n\t"
208
                "movdqa    %%xmm6, 96(%0)       \n\t"
209
                "punpckhdq   (%2), %%xmm1       \n\t"
210
                "punpckhdq 16(%2), %%xmm3       \n\t"
211
                "punpckhdq 32(%2), %%xmm5       \n\t"
212
                "punpckhdq 48(%2), %%xmm7       \n\t"
213
                "movdqa    %%xmm1, 16(%0)       \n\t"
214
                "movdqa    %%xmm3, 48(%0)       \n\t"
215
                "movdqa    %%xmm5, 80(%0)       \n\t"
216
                "movdqa    %%xmm7, 112(%0)      \n\t"
217
                :: "r"(&(b)[i]), "r"(&(b)[i>>1]), "r"(&(temp)[i>>1])
218
                 : "memory"
219
               );
220
        }
221
    }
222
}
223

    
224
void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){
225
    const int w2= (width+1)>>1;
226
    DWTELEM temp[width >> 1];
227
    const int w_l= (width>>1);
228
    const int w_r= w2 - 1;
229
    int i;
230

    
231
    { // Lift 0
232
        DWTELEM * const ref = b + w2 - 1;
233

    
234
        i = 1;
235
        b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
236
        asm volatile(
237
            "pcmpeqd    %%mm7, %%mm7         \n\t"
238
            "pslld        $31, %%mm7         \n\t"
239
            "psrld        $29, %%mm7         \n\t"
240
           ::);
241
        for(; i<w_l-3; i+=4){
242
            asm volatile(
243
                "movq     (%1), %%mm2        \n\t"
244
                "movq    8(%1), %%mm6        \n\t"
245
                "paddd   4(%1), %%mm2        \n\t"
246
                "paddd  12(%1), %%mm6        \n\t"
247
                "movq    %%mm2, %%mm0        \n\t"
248
                "movq    %%mm6, %%mm4        \n\t"
249
                "paddd   %%mm2, %%mm2        \n\t"
250
                "paddd   %%mm6, %%mm6        \n\t"
251
                "paddd   %%mm0, %%mm2        \n\t"
252
                "paddd   %%mm4, %%mm6        \n\t"
253
                "paddd   %%mm7, %%mm2        \n\t"
254
                "paddd   %%mm7, %%mm6        \n\t"
255
                "psrad      $3, %%mm2        \n\t"
256
                "psrad      $3, %%mm6        \n\t"
257
                "movq     (%0), %%mm0        \n\t"
258
                "movq    8(%0), %%mm4        \n\t"
259
                "psubd   %%mm2, %%mm0        \n\t"
260
                "psubd   %%mm6, %%mm4        \n\t"
261
                "movq    %%mm0, (%0)         \n\t"
262
                "movq    %%mm4, 8(%0)        \n\t"
263
                :: "r"(&b[i]), "r"(&ref[i])
264
                 : "memory"
265
               );
266
        }
267
        snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
268
    }
269

    
270
    { // Lift 1
271
        DWTELEM * const dst = b+w2;
272

    
273
        i = 0;
274
        for(; i<w_r-3; i+=4){
275
            asm volatile(
276
                "movq     (%1), %%mm2        \n\t"
277
                "movq    8(%1), %%mm6        \n\t"
278
                "paddd   4(%1), %%mm2        \n\t"
279
                "paddd  12(%1), %%mm6        \n\t"
280
                "movq     (%0), %%mm0        \n\t"
281
                "movq    8(%0), %%mm4        \n\t"
282
                "psubd   %%mm2, %%mm0        \n\t"
283
                "psubd   %%mm6, %%mm4        \n\t"
284
                "movq    %%mm0, (%0)         \n\t"
285
                "movq    %%mm4, 8(%0)        \n\t"
286
                :: "r"(&dst[i]), "r"(&b[i])
287
                 : "memory"
288
               );
289
        }
290
        snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
291
    }
292

    
293
    { // Lift 2
294
        DWTELEM * const ref = b+w2 - 1;
295

    
296
        i = 1;
297
        b[0] = b[0] - (((-2 * ref[1] + W_BO) - 4 * b[0]) >> W_BS);
298
        asm volatile(
299
            "pslld          $1, %%mm7       \n\t" /* xmm7 already holds a '4' from 2 lifts ago. */
300
           ::);
301
        for(; i<w_l-3; i+=4){
302
            asm volatile(
303
                "movq     (%1), %%mm0        \n\t"
304
                "movq    8(%1), %%mm4        \n\t"
305
                "paddd   4(%1), %%mm0        \n\t"
306
                "paddd  12(%1), %%mm4        \n\t"
307
                "movq    %%mm7, %%mm1        \n\t"
308
                "movq    %%mm7, %%mm5        \n\t"
309
                "psubd   %%mm0, %%mm1        \n\t"
310
                "psubd   %%mm4, %%mm5        \n\t"
311
                "movq     (%0), %%mm0        \n\t"
312
                "movq    8(%0), %%mm4        \n\t"
313
                "pslld      $2, %%mm0        \n\t"
314
                "pslld      $2, %%mm4        \n\t"
315
                "psubd   %%mm0, %%mm1        \n\t"
316
                "psubd   %%mm4, %%mm5        \n\t"
317
                "psrad      $4, %%mm1        \n\t"
318
                "psrad      $4, %%mm5        \n\t"
319
                "movq     (%0), %%mm0        \n\t"
320
                "movq    8(%0), %%mm4        \n\t"
321
                "psubd   %%mm1, %%mm0        \n\t"
322
                "psubd   %%mm5, %%mm4        \n\t"
323
                "movq    %%mm0, (%0)         \n\t"
324
                "movq    %%mm4, 8(%0)        \n\t"
325
                :: "r"(&b[i]), "r"(&ref[i])
326
                 : "memory"
327
               );
328
        }
329
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
330
    }
331

    
332
    { // Lift 3
333
        DWTELEM * const src = b+w2;
334
        i = 0;
335

    
336
        for(; i<w_r-3; i+=4){
337
            asm volatile(
338
                "movq    4(%1), %%mm2        \n\t"
339
                "movq   12(%1), %%mm6        \n\t"
340
                "paddd    (%1), %%mm2        \n\t"
341
                "paddd   8(%1), %%mm6        \n\t"
342
                "movq    %%mm2, %%mm0        \n\t"
343
                "movq    %%mm6, %%mm4        \n\t"
344
                "pslld      $2, %%mm2        \n\t"
345
                "pslld      $2, %%mm6        \n\t"
346
                "psubd   %%mm2, %%mm0        \n\t"
347
                "psubd   %%mm6, %%mm4        \n\t"
348
                "psrad      $1, %%mm0        \n\t"
349
                "psrad      $1, %%mm4        \n\t"
350
                "movq     (%0), %%mm2        \n\t"
351
                "movq    8(%0), %%mm6        \n\t"
352
                "psubd   %%mm0, %%mm2        \n\t"
353
                "psubd   %%mm4, %%mm6        \n\t"
354
                "movq    %%mm2, (%2)         \n\t"
355
                "movq    %%mm6, 8(%2)        \n\t"
356
                :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
357
                 : "memory"
358
               );
359
        }
360
        snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO, W_AS);
361
    }
362

    
363
    {
364
        snow_interleave_line_header(&i, width, b, temp);
365

    
366
        for (; (i & 0xE) != 0xE; i-=2){
367
            b[i+1] = temp[i>>1];
368
            b[i] = b[i>>1];
369
        }
370
        for (i-=14; i>=0; i-=16){
371
            asm volatile(
372
                "movq        (%1), %%mm0       \n\t"
373
                "movq       8(%1), %%mm2       \n\t"
374
                "movq      16(%1), %%mm4       \n\t"
375
                "movq      24(%1), %%mm6       \n\t"
376
                "movq        (%1), %%mm1       \n\t"
377
                "movq       8(%1), %%mm3       \n\t"
378
                "movq      16(%1), %%mm5       \n\t"
379
                "movq      24(%1), %%mm7       \n\t"
380
                "punpckldq   (%2), %%mm0       \n\t"
381
                "punpckldq  8(%2), %%mm2       \n\t"
382
                "punpckldq 16(%2), %%mm4       \n\t"
383
                "punpckldq 24(%2), %%mm6       \n\t"
384
                "movq       %%mm0, (%0)        \n\t"
385
                "movq       %%mm2, 16(%0)      \n\t"
386
                "movq       %%mm4, 32(%0)      \n\t"
387
                "movq       %%mm6, 48(%0)      \n\t"
388
                "punpckhdq   (%2), %%mm1       \n\t"
389
                "punpckhdq  8(%2), %%mm3       \n\t"
390
                "punpckhdq 16(%2), %%mm5       \n\t"
391
                "punpckhdq 24(%2), %%mm7       \n\t"
392
                "movq       %%mm1, 8(%0)       \n\t"
393
                "movq       %%mm3, 24(%0)      \n\t"
394
                "movq       %%mm5, 40(%0)      \n\t"
395
                "movq       %%mm7, 56(%0)      \n\t"
396
                :: "r"(&b[i]), "r"(&b[i>>1]), "r"(&temp[i>>1])
397
                 : "memory"
398
               );
399
        }
400
    }
401
}
402

    
403
#define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\
404
        ""op" (%%"r",%%"REG_d",4), %%"t0"      \n\t"\
405
        ""op" 16(%%"r",%%"REG_d",4), %%"t1"    \n\t"\
406
        ""op" 32(%%"r",%%"REG_d",4), %%"t2"    \n\t"\
407
        ""op" 48(%%"r",%%"REG_d",4), %%"t3"    \n\t"
408

    
409
#define snow_vertical_compose_sse2_load(r,t0,t1,t2,t3)\
410
        snow_vertical_compose_sse2_load_add("movdqa",r,t0,t1,t2,t3)
411

    
412
#define snow_vertical_compose_sse2_add(r,t0,t1,t2,t3)\
413
        snow_vertical_compose_sse2_load_add("paddd",r,t0,t1,t2,t3)
414

    
415
#define snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
416
        "psubd %%"s0", %%"t0" \n\t"\
417
        "psubd %%"s1", %%"t1" \n\t"\
418
        "psubd %%"s2", %%"t2" \n\t"\
419
        "psubd %%"s3", %%"t3" \n\t"
420

    
421
#define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\
422
        "movdqa %%"s0", (%%"w",%%"REG_d",4)      \n\t"\
423
        "movdqa %%"s1", 16(%%"w",%%"REG_d",4)    \n\t"\
424
        "movdqa %%"s2", 32(%%"w",%%"REG_d",4)    \n\t"\
425
        "movdqa %%"s3", 48(%%"w",%%"REG_d",4)    \n\t"
426

    
427
#define snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)\
428
        "psrad $"n", %%"t0" \n\t"\
429
        "psrad $"n", %%"t1" \n\t"\
430
        "psrad $"n", %%"t2" \n\t"\
431
        "psrad $"n", %%"t3" \n\t"
432

    
433
#define snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
434
        "paddd %%"s0", %%"t0" \n\t"\
435
        "paddd %%"s1", %%"t1" \n\t"\
436
        "paddd %%"s2", %%"t2" \n\t"\
437
        "paddd %%"s3", %%"t3" \n\t"
438

    
439
#define snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3)\
440
        "pslld $"n", %%"t0" \n\t"\
441
        "pslld $"n", %%"t1" \n\t"\
442
        "pslld $"n", %%"t2" \n\t"\
443
        "pslld $"n", %%"t3" \n\t"
444

    
445
#define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\
446
        "movdqa %%"s0", %%"t0" \n\t"\
447
        "movdqa %%"s1", %%"t1" \n\t"\
448
        "movdqa %%"s2", %%"t2" \n\t"\
449
        "movdqa %%"s3", %%"t3" \n\t"
450

    
451
void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
452
    long i = width;
453

    
454
    while(i & 0xF)
455
    {
456
        i--;
457
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
458
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
459
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
460
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
461
    }
462

    
463
         asm volatile (
464
        "jmp 2f                                      \n\t"
465
        "1:                                          \n\t"
466

    
467
        "mov %6, %%"REG_a"                           \n\t"
468
        "mov %4, %%"REG_S"                           \n\t"
469

    
470
        snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
471
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
472
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
473
        snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\
474
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
475

    
476
        "pcmpeqd %%xmm1, %%xmm1                      \n\t"
477
        "pslld $31, %%xmm1                           \n\t"
478
        "psrld $29, %%xmm1                           \n\t"
479
        "mov %5, %%"REG_a"                           \n\t"
480

    
481
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
482
        snow_vertical_compose_sse2_sra("3","xmm0","xmm2","xmm4","xmm6")
483
        snow_vertical_compose_sse2_load(REG_a,"xmm1","xmm3","xmm5","xmm7")
484
        snow_vertical_compose_sse2_sub("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
485
        snow_vertical_compose_sse2_store(REG_a,"xmm1","xmm3","xmm5","xmm7")
486
        "mov %3, %%"REG_c"                           \n\t"
487
        snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
488
        snow_vertical_compose_sse2_add(REG_c,"xmm1","xmm3","xmm5","xmm7")
489
        snow_vertical_compose_sse2_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
490
        snow_vertical_compose_sse2_store(REG_S,"xmm0","xmm2","xmm4","xmm6")
491
        "mov %2, %%"REG_a"                           \n\t"
492
        snow_vertical_compose_sse2_load(REG_c,"xmm1","xmm3","xmm5","xmm7")
493
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
494
        snow_vertical_compose_sse2_sll("2","xmm1","xmm3","xmm5","xmm7")\
495
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
496

    
497
        "pcmpeqd %%xmm1, %%xmm1                      \n\t"
498
        "pslld $31, %%xmm1                           \n\t"
499
        "psrld $28, %%xmm1                           \n\t"
500
        "mov %1, %%"REG_S"                           \n\t"
501

    
502
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
503
        snow_vertical_compose_sse2_sra("4","xmm0","xmm2","xmm4","xmm6")
504
        snow_vertical_compose_sse2_add(REG_c,"xmm0","xmm2","xmm4","xmm6")
505
        snow_vertical_compose_sse2_store(REG_c,"xmm0","xmm2","xmm4","xmm6")
506
        snow_vertical_compose_sse2_add(REG_S,"xmm0","xmm2","xmm4","xmm6")
507
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
508
        snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\
509
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
510
        snow_vertical_compose_sse2_sra("1","xmm0","xmm2","xmm4","xmm6")
511
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
512
        snow_vertical_compose_sse2_store(REG_a,"xmm0","xmm2","xmm4","xmm6")
513

    
514
        "2:                                          \n\t"
515
        "sub $16, %%"REG_d"                          \n\t"
516
        "jge 1b                                      \n\t"
517
        :"+d"(i)
518
        :
519
        "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
520
        "%"REG_a"","%"REG_S"","%"REG_c"");
521
}
522

    
523
#define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\
524
        ""op" (%%"r",%%"REG_d",4), %%"t0"   \n\t"\
525
        ""op" 8(%%"r",%%"REG_d",4), %%"t1"  \n\t"\
526
        ""op" 16(%%"r",%%"REG_d",4), %%"t2" \n\t"\
527
        ""op" 24(%%"r",%%"REG_d",4), %%"t3" \n\t"
528

    
529
#define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\
530
        snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3)
531

    
532
#define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\
533
        snow_vertical_compose_mmx_load_add("paddd",r,t0,t1,t2,t3)
534

    
535
#define snow_vertical_compose_mmx_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
536
        snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)
537

    
538
#define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\
539
        "movq %%"s0", (%%"w",%%"REG_d",4)   \n\t"\
540
        "movq %%"s1", 8(%%"w",%%"REG_d",4)  \n\t"\
541
        "movq %%"s2", 16(%%"w",%%"REG_d",4) \n\t"\
542
        "movq %%"s3", 24(%%"w",%%"REG_d",4) \n\t"
543

    
544
#define snow_vertical_compose_mmx_sra(n,t0,t1,t2,t3)\
545
        snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)
546

    
547
#define snow_vertical_compose_mmx_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
548
        snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)
549

    
550
#define snow_vertical_compose_mmx_sll(n,t0,t1,t2,t3)\
551
        snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3)
552

    
553
#define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\
554
        "movq %%"s0", %%"t0" \n\t"\
555
        "movq %%"s1", %%"t1" \n\t"\
556
        "movq %%"s2", %%"t2" \n\t"\
557
        "movq %%"s3", %%"t3" \n\t"
558

    
559
void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
560
    long i = width;
561
    while(i & 0x7)
562
    {
563
        i--;
564
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
565
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
566
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
567
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
568
    }
569

    
570
    asm volatile(
571
        "jmp 2f                                      \n\t"
572
        "1:                                          \n\t"
573

    
574
        "mov %6, %%"REG_a"                           \n\t"
575
        "mov %4, %%"REG_S"                           \n\t"
576

    
577
        snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
578
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
579
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
580
        snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6")
581
        snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
582

    
583
        "pcmpeqd %%mm1, %%mm1                        \n\t"
584
        "pslld $31, %%mm1                            \n\t"
585
        "psrld $29, %%mm1                            \n\t"
586
        "mov %5, %%"REG_a"                           \n\t"
587

    
588
        snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
589
        snow_vertical_compose_mmx_sra("3","mm0","mm2","mm4","mm6")
590
        snow_vertical_compose_mmx_load(REG_a,"mm1","mm3","mm5","mm7")
591
        snow_vertical_compose_mmx_sub("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
592
        snow_vertical_compose_mmx_store(REG_a,"mm1","mm3","mm5","mm7")
593
        "mov %3, %%"REG_c"                           \n\t"
594
        snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
595
        snow_vertical_compose_mmx_add(REG_c,"mm1","mm3","mm5","mm7")
596
        snow_vertical_compose_mmx_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
597
        snow_vertical_compose_mmx_store(REG_S,"mm0","mm2","mm4","mm6")
598
        "mov %2, %%"REG_a"                           \n\t"
599
        snow_vertical_compose_mmx_load(REG_c,"mm1","mm3","mm5","mm7")
600
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
601
        snow_vertical_compose_mmx_sll("2","mm1","mm3","mm5","mm7")
602
        snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
603

    
604
        "pcmpeqd %%mm1, %%mm1                        \n\t"
605
        "pslld $31, %%mm1                            \n\t"
606
        "psrld $28, %%mm1                            \n\t"
607
        "mov %1, %%"REG_S"                           \n\t"
608

    
609
        snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
610
        snow_vertical_compose_mmx_sra("4","mm0","mm2","mm4","mm6")
611
        snow_vertical_compose_mmx_add(REG_c,"mm0","mm2","mm4","mm6")
612
        snow_vertical_compose_mmx_store(REG_c,"mm0","mm2","mm4","mm6")
613
        snow_vertical_compose_mmx_add(REG_S,"mm0","mm2","mm4","mm6")
614
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
615
        snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6")
616
        snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
617
        snow_vertical_compose_mmx_sra("1","mm0","mm2","mm4","mm6")
618
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
619
        snow_vertical_compose_mmx_store(REG_a,"mm0","mm2","mm4","mm6")
620

    
621
        "2:                                          \n\t"
622
        "sub $8, %%"REG_d"                           \n\t"
623
        "jge 1b                                      \n\t"
624
        :"+d"(i)
625
        :
626
        "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
627
        "%"REG_a"","%"REG_S"","%"REG_c"");
628
}
629

    
630
#define snow_inner_add_yblock_sse2_header \
631
    DWTELEM * * dst_array = sb->line + src_y;\
632
    long tmp;\
633
    asm volatile(\
634
             "mov  %7, %%"REG_c"             \n\t"\
635
             "mov  %6, %2                    \n\t"\
636
             "mov  %4, %%"REG_S"             \n\t"\
637
             "pxor %%xmm7, %%xmm7            \n\t" /* 0 */\
638
             "pcmpeqd %%xmm3, %%xmm3         \n\t"\
639
             "pslld $31, %%xmm3              \n\t"\
640
             "psrld $24, %%xmm3              \n\t" /* FRAC_BITS >> 1 */\
641
             "1:                             \n\t"\
642
             "mov %1, %%"REG_D"              \n\t"\
643
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
644
             "add %3, %%"REG_D"              \n\t"
645

    
646
#define snow_inner_add_yblock_sse2_start_8(out_reg1, out_reg2, ptr_offset, s_offset)\
647
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
648
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
649
             "movq (%%"REG_d", %%"REG_c"), %%"out_reg2" \n\t"\
650
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
651
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
652
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
653
             "movq "s_offset"+16(%%"REG_S"), %%xmm4 \n\t"\
654
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
655
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
656
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
657
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
658

    
659
#define snow_inner_add_yblock_sse2_start_16(out_reg1, out_reg2, ptr_offset, s_offset)\
660
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
661
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
662
             "movq 8(%%"REG_d"), %%"out_reg2" \n\t"\
663
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
664
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
665
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
666
             "movq "s_offset"+8(%%"REG_S"), %%xmm4 \n\t"\
667
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
668
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
669
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
670
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
671

    
672
#define snow_inner_add_yblock_sse2_accum_8(ptr_offset, s_offset) \
673
             snow_inner_add_yblock_sse2_start_8("xmm2", "xmm6", ptr_offset, s_offset)\
674
             "paddusw %%xmm2, %%xmm1         \n\t"\
675
             "paddusw %%xmm6, %%xmm5         \n\t"
676

    
677
#define snow_inner_add_yblock_sse2_accum_16(ptr_offset, s_offset) \
678
             snow_inner_add_yblock_sse2_start_16("xmm2", "xmm6", ptr_offset, s_offset)\
679
             "paddusw %%xmm2, %%xmm1         \n\t"\
680
             "paddusw %%xmm6, %%xmm5         \n\t"
681

    
682
#define snow_inner_add_yblock_sse2_end_common1\
683
             "add $32, %%"REG_S"             \n\t"\
684
             "add %%"REG_c", %0              \n\t"\
685
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
686
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
687
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
688
             "add %%"REG_c", (%%"REG_a")     \n\t"
689

    
690
#define snow_inner_add_yblock_sse2_end_common2\
691
             "jnz 1b                         \n\t"\
692
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
693
             :\
694
             "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
695
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
696

    
697
#define snow_inner_add_yblock_sse2_end_8\
698
             "sal $1, %%"REG_c"              \n\t"\
699
             "add $"PTR_SIZE"*2, %1          \n\t"\
700
             snow_inner_add_yblock_sse2_end_common1\
701
             "sar $1, %%"REG_c"              \n\t"\
702
             "sub $2, %2                     \n\t"\
703
             snow_inner_add_yblock_sse2_end_common2
704

    
705
#define snow_inner_add_yblock_sse2_end_16\
706
             "add $"PTR_SIZE"*1, %1          \n\t"\
707
             snow_inner_add_yblock_sse2_end_common1\
708
             "dec %2                         \n\t"\
709
             snow_inner_add_yblock_sse2_end_common2
710

    
711
static void inner_add_yblock_bw_8_obmc_16_bh_even_sse2(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
712
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
713
snow_inner_add_yblock_sse2_header
714
snow_inner_add_yblock_sse2_start_8("xmm1", "xmm5", "3", "0")
715
snow_inner_add_yblock_sse2_accum_8("2", "8")
716
snow_inner_add_yblock_sse2_accum_8("1", "128")
717
snow_inner_add_yblock_sse2_accum_8("0", "136")
718

    
719
             "mov %0, %%"REG_d"              \n\t"
720
             "movdqa (%%"REG_D"), %%xmm0     \n\t"
721
             "movdqa %%xmm1, %%xmm2          \n\t"
722

    
723
             "punpckhwd %%xmm7, %%xmm1       \n\t"
724
             "punpcklwd %%xmm7, %%xmm2       \n\t"
725
             "paddd %%xmm2, %%xmm0           \n\t"
726
             "movdqa 16(%%"REG_D"), %%xmm2   \n\t"
727
             "paddd %%xmm1, %%xmm2           \n\t"
728
             "paddd %%xmm3, %%xmm0           \n\t"
729
             "paddd %%xmm3, %%xmm2           \n\t"
730

    
731
             "mov %1, %%"REG_D"              \n\t"
732
             "mov "PTR_SIZE"(%%"REG_D"), %%"REG_D";\n\t"
733
             "add %3, %%"REG_D"              \n\t"
734

    
735
             "movdqa (%%"REG_D"), %%xmm4     \n\t"
736
             "movdqa %%xmm5, %%xmm6          \n\t"
737
             "punpckhwd %%xmm7, %%xmm5       \n\t"
738
             "punpcklwd %%xmm7, %%xmm6       \n\t"
739
             "paddd %%xmm6, %%xmm4           \n\t"
740
             "movdqa 16(%%"REG_D"), %%xmm6   \n\t"
741
             "paddd %%xmm5, %%xmm6           \n\t"
742
             "paddd %%xmm3, %%xmm4           \n\t"
743
             "paddd %%xmm3, %%xmm6           \n\t"
744

    
745
             "psrad $8, %%xmm0               \n\t" /* FRAC_BITS. */
746
             "psrad $8, %%xmm2               \n\t" /* FRAC_BITS. */
747
             "packssdw %%xmm2, %%xmm0        \n\t"
748
             "packuswb %%xmm7, %%xmm0        \n\t"
749
             "movq %%xmm0, (%%"REG_d")       \n\t"
750

    
751
             "psrad $8, %%xmm4               \n\t" /* FRAC_BITS. */
752
             "psrad $8, %%xmm6               \n\t" /* FRAC_BITS. */
753
             "packssdw %%xmm6, %%xmm4        \n\t"
754
             "packuswb %%xmm7, %%xmm4        \n\t"
755
             "movq %%xmm4, (%%"REG_d",%%"REG_c");\n\t"
756
snow_inner_add_yblock_sse2_end_8
757
}
758

    
759
static void inner_add_yblock_bw_16_obmc_32_sse2(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
760
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
761
snow_inner_add_yblock_sse2_header
762
snow_inner_add_yblock_sse2_start_16("xmm1", "xmm5", "3", "0")
763
snow_inner_add_yblock_sse2_accum_16("2", "16")
764
snow_inner_add_yblock_sse2_accum_16("1", "512")
765
snow_inner_add_yblock_sse2_accum_16("0", "528")
766

    
767
             "mov %0, %%"REG_d"              \n\t"
768
             "movdqa %%xmm1, %%xmm0          \n\t"
769
             "movdqa %%xmm5, %%xmm4          \n\t"
770
             "punpcklwd %%xmm7, %%xmm0       \n\t"
771
             "paddd (%%"REG_D"), %%xmm0      \n\t"
772
             "punpckhwd %%xmm7, %%xmm1       \n\t"
773
             "paddd 16(%%"REG_D"), %%xmm1    \n\t"
774
             "punpcklwd %%xmm7, %%xmm4       \n\t"
775
             "paddd 32(%%"REG_D"), %%xmm4    \n\t"
776
             "punpckhwd %%xmm7, %%xmm5       \n\t"
777
             "paddd 48(%%"REG_D"), %%xmm5    \n\t"
778
             "paddd %%xmm3, %%xmm0           \n\t"
779
             "paddd %%xmm3, %%xmm1           \n\t"
780
             "paddd %%xmm3, %%xmm4           \n\t"
781
             "paddd %%xmm3, %%xmm5           \n\t"
782
             "psrad $8, %%xmm0               \n\t" /* FRAC_BITS. */
783
             "psrad $8, %%xmm1               \n\t" /* FRAC_BITS. */
784
             "psrad $8, %%xmm4               \n\t" /* FRAC_BITS. */
785
             "psrad $8, %%xmm5               \n\t" /* FRAC_BITS. */
786

    
787
             "packssdw %%xmm1, %%xmm0        \n\t"
788
             "packssdw %%xmm5, %%xmm4        \n\t"
789
             "packuswb %%xmm4, %%xmm0        \n\t"
790

    
791
             "movdqu %%xmm0, (%%"REG_d")       \n\t"
792

    
793
snow_inner_add_yblock_sse2_end_16
794
}
795

    
796
#define snow_inner_add_yblock_mmx_header \
797
    DWTELEM * * dst_array = sb->line + src_y;\
798
    long tmp;\
799
    asm volatile(\
800
             "mov  %7, %%"REG_c"             \n\t"\
801
             "mov  %6, %2                    \n\t"\
802
             "mov  %4, %%"REG_S"             \n\t"\
803
             "pxor %%mm7, %%mm7              \n\t" /* 0 */\
804
             "pcmpeqd %%mm3, %%mm3           \n\t"\
805
             "pslld $31, %%mm3               \n\t"\
806
             "psrld $24, %%mm3               \n\t" /* FRAC_BITS >> 1 */\
807
             "1:                             \n\t"\
808
             "mov %1, %%"REG_D"              \n\t"\
809
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
810
             "add %3, %%"REG_D"              \n\t"
811

    
812
#define snow_inner_add_yblock_mmx_start(out_reg1, out_reg2, ptr_offset, s_offset, d_offset)\
813
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
814
             "movd "d_offset"(%%"REG_d"), %%"out_reg1" \n\t"\
815
             "movd "d_offset"+4(%%"REG_d"), %%"out_reg2" \n\t"\
816
             "punpcklbw %%mm7, %%"out_reg1" \n\t"\
817
             "punpcklbw %%mm7, %%"out_reg2" \n\t"\
818
             "movd "s_offset"(%%"REG_S"), %%mm0 \n\t"\
819
             "movd "s_offset"+4(%%"REG_S"), %%mm4 \n\t"\
820
             "punpcklbw %%mm7, %%mm0       \n\t"\
821
             "punpcklbw %%mm7, %%mm4       \n\t"\
822
             "pmullw %%mm0, %%"out_reg1"    \n\t"\
823
             "pmullw %%mm4, %%"out_reg2"    \n\t"
824

    
825
#define snow_inner_add_yblock_mmx_accum(ptr_offset, s_offset, d_offset) \
826
             snow_inner_add_yblock_mmx_start("mm2", "mm6", ptr_offset, s_offset, d_offset)\
827
             "paddusw %%mm2, %%mm1         \n\t"\
828
             "paddusw %%mm6, %%mm5         \n\t"
829

    
830
#define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\
831
             "mov %0, %%"REG_d"              \n\t"\
832
             "movq %%mm1, %%mm0              \n\t"\
833
             "movq %%mm5, %%mm4              \n\t"\
834
             "punpcklwd %%mm7, %%mm0         \n\t"\
835
             "paddd "read_offset"(%%"REG_D"), %%mm0 \n\t"\
836
             "punpckhwd %%mm7, %%mm1         \n\t"\
837
             "paddd "read_offset"+8(%%"REG_D"), %%mm1 \n\t"\
838
             "punpcklwd %%mm7, %%mm4         \n\t"\
839
             "paddd "read_offset"+16(%%"REG_D"), %%mm4 \n\t"\
840
             "punpckhwd %%mm7, %%mm5         \n\t"\
841
             "paddd "read_offset"+24(%%"REG_D"), %%mm5 \n\t"\
842
             "paddd %%mm3, %%mm0             \n\t"\
843
             "paddd %%mm3, %%mm1             \n\t"\
844
             "paddd %%mm3, %%mm4             \n\t"\
845
             "paddd %%mm3, %%mm5             \n\t"\
846
             "psrad $8, %%mm0                \n\t"\
847
             "psrad $8, %%mm1                \n\t"\
848
             "psrad $8, %%mm4                \n\t"\
849
             "psrad $8, %%mm5                \n\t"\
850
\
851
             "packssdw %%mm1, %%mm0          \n\t"\
852
             "packssdw %%mm5, %%mm4          \n\t"\
853
             "packuswb %%mm4, %%mm0          \n\t"\
854
             "movq %%mm0, "write_offset"(%%"REG_d") \n\t"
855

    
856
#define snow_inner_add_yblock_mmx_end(s_step)\
857
             "add $"s_step", %%"REG_S"             \n\t"\
858
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
859
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
860
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
861
             "add %%"REG_c", (%%"REG_a")     \n\t"\
862
             "add $"PTR_SIZE"*1, %1          \n\t"\
863
             "add %%"REG_c", %0              \n\t"\
864
             "dec %2                         \n\t"\
865
             "jnz 1b                         \n\t"\
866
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
867
             :\
868
             "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
869
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
870

    
871
static void inner_add_yblock_bw_8_obmc_16_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
872
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
873
snow_inner_add_yblock_mmx_header
874
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
875
snow_inner_add_yblock_mmx_accum("2", "8", "0")
876
snow_inner_add_yblock_mmx_accum("1", "128", "0")
877
snow_inner_add_yblock_mmx_accum("0", "136", "0")
878
snow_inner_add_yblock_mmx_mix("0", "0")
879
snow_inner_add_yblock_mmx_end("16")
880
}
881

    
882
static void inner_add_yblock_bw_16_obmc_32_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,
883
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
884
snow_inner_add_yblock_mmx_header
885
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
886
snow_inner_add_yblock_mmx_accum("2", "16", "0")
887
snow_inner_add_yblock_mmx_accum("1", "512", "0")
888
snow_inner_add_yblock_mmx_accum("0", "528", "0")
889
snow_inner_add_yblock_mmx_mix("0", "0")
890

    
891
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8")
892
snow_inner_add_yblock_mmx_accum("2", "24", "8")
893
snow_inner_add_yblock_mmx_accum("1", "520", "8")
894
snow_inner_add_yblock_mmx_accum("0", "536", "8")
895
snow_inner_add_yblock_mmx_mix("32", "8")
896
snow_inner_add_yblock_mmx_end("32")
897
}
898

    
899
void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
900
                           int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
901

    
902
    if (b_w == 16)
903
        inner_add_yblock_bw_16_obmc_32_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
904
    else if (b_w == 8 && obmc_stride == 16) {
905
        if (!(b_h & 1))
906
            inner_add_yblock_bw_8_obmc_16_bh_even_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
907
        else
908
            inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
909
    } else
910
         ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
911
}
912

    
913
void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
914
                          int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
915
    if (b_w == 16)
916
        inner_add_yblock_bw_16_obmc_32_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
917
    else if (b_w == 8 && obmc_stride == 16)
918
        inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
919
    else
920
        ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
921
}