Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / snowdsp_mmx.c @ ce611a27

History | View | Annotate | Download (39.5 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"
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" //FIXME try aligned reads and shifts
122
                "paddd  %%xmm1, %%xmm0        \n\t"
123
                "paddd  %%xmm5, %%xmm4        \n\t"
124
                "paddd  %%xmm7, %%xmm0        \n\t"
125
                "paddd  %%xmm7, %%xmm4        \n\t"
126
                "movdqa   (%0), %%xmm1        \n\t"
127
                "movdqa 16(%0), %%xmm5        \n\t"
128
                "psrad      $2, %%xmm0        \n\t"
129
                "psrad      $2, %%xmm4        \n\t"
130
                "paddd  %%xmm1, %%xmm0        \n\t"
131
                "paddd  %%xmm5, %%xmm4        \n\t"
132
                "psrad      $2, %%xmm0        \n\t"
133
                "psrad      $2, %%xmm4        \n\t"
134
                "paddd  %%xmm1, %%xmm0        \n\t"
135
                "paddd  %%xmm5, %%xmm4        \n\t"
136
                "movdqa %%xmm0, (%0)          \n\t"
137
                "movdqa %%xmm4, 16(%0)        \n\t"
138
                :: "r"(&b[i]), "r"(&ref[i])
139
                : "memory"
140
            );
141
        }
142
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
143
        b[0] = b_0 + ((2 * ref[1] + W_BO-1 + 4 * b_0) >> W_BS);
144
    }
145

    
146
    { // Lift 3
147
        DWTELEM * const src = b+w2;
148

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

    
176
    {
177
        snow_interleave_line_header(&i, width, b, temp);
178

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

    
216
void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){
217
    const int w2= (width+1)>>1;
218
    DWTELEM temp[width >> 1];
219
    const int w_l= (width>>1);
220
    const int w_r= w2 - 1;
221
    int i;
222

    
223
    { // Lift 0
224
        DWTELEM * const ref = b + w2 - 1;
225

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

    
262
    { // Lift 1
263
        DWTELEM * const dst = b+w2;
264

    
265
        i = 0;
266
        for(; i<w_r-3; i+=4){
267
            asm volatile(
268
                "movq     (%1), %%mm2        \n\t"
269
                "movq    8(%1), %%mm6        \n\t"
270
                "paddd   4(%1), %%mm2        \n\t"
271
                "paddd  12(%1), %%mm6        \n\t"
272
                "movq     (%0), %%mm0        \n\t"
273
                "movq    8(%0), %%mm4        \n\t"
274
                "psubd   %%mm2, %%mm0        \n\t"
275
                "psubd   %%mm6, %%mm4        \n\t"
276
                "movq    %%mm0, (%0)         \n\t"
277
                "movq    %%mm4, 8(%0)        \n\t"
278
                :: "r"(&dst[i]), "r"(&b[i])
279
                 : "memory"
280
               );
281
        }
282
        snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
283
    }
284

    
285
    { // Lift 2
286
        DWTELEM * const ref = b+w2 - 1;
287

    
288
        i = 1;
289
        b[0] = b[0] + (((2 * ref[1] + W_BO) + 4 * b[0]) >> W_BS);
290
        asm volatile(
291
            "pslld          $1, %%mm7        \n\t"
292
           ::);
293
        for(; i<w_l-3; i+=4){
294
            asm volatile(
295
                "movq     (%1), %%mm0        \n\t"
296
                "movq    8(%1), %%mm4        \n\t"
297
                "paddd   4(%1), %%mm0        \n\t"
298
                "paddd  12(%1), %%mm4        \n\t"
299
                "paddd   %%mm7, %%mm0        \n\t"
300
                "paddd   %%mm7, %%mm4        \n\t"
301
                "psrad      $2, %%mm0        \n\t"
302
                "psrad      $2, %%mm4        \n\t"
303
                "movq     (%0), %%mm1        \n\t"
304
                "movq    8(%0), %%mm5        \n\t"
305
                "paddd   %%mm1, %%mm0        \n\t"
306
                "paddd   %%mm5, %%mm4        \n\t"
307
                "psrad      $2, %%mm0        \n\t"
308
                "psrad      $2, %%mm4        \n\t"
309
                "paddd   %%mm1, %%mm0        \n\t"
310
                "paddd   %%mm5, %%mm4        \n\t"
311
                "movq    %%mm0, (%0)         \n\t"
312
                "movq    %%mm4, 8(%0)        \n\t"
313
                :: "r"(&b[i]), "r"(&ref[i])
314
                 : "memory"
315
               );
316
        }
317
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
318
    }
319

    
320
    { // Lift 3
321
        DWTELEM * const src = b+w2;
322
        i = 0;
323

    
324
        for(; i<w_r-3; i+=4){
325
            asm volatile(
326
                "movq    4(%1), %%mm2        \n\t"
327
                "movq   12(%1), %%mm6        \n\t"
328
                "paddd    (%1), %%mm2        \n\t"
329
                "paddd   8(%1), %%mm6        \n\t"
330
                "movq     (%0), %%mm0        \n\t"
331
                "movq    8(%0), %%mm4        \n\t"
332
                "paddd   %%mm2, %%mm0        \n\t"
333
                "paddd   %%mm6, %%mm4        \n\t"
334
                "psrad      $1, %%mm2        \n\t"
335
                "psrad      $1, %%mm6        \n\t"
336
                "paddd   %%mm0, %%mm2        \n\t"
337
                "paddd   %%mm4, %%mm6        \n\t"
338
                "movq    %%mm2, (%2)         \n\t"
339
                "movq    %%mm6, 8(%2)        \n\t"
340
                :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
341
                 : "memory"
342
               );
343
        }
344
        snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS);
345
    }
346

    
347
    {
348
        snow_interleave_line_header(&i, width, b, temp);
349

    
350
        for (; (i & 0xE) != 0xE; i-=2){
351
            b[i+1] = temp[i>>1];
352
            b[i] = b[i>>1];
353
        }
354
        for (i-=14; i>=0; i-=16){
355
            asm volatile(
356
                "movq        (%1), %%mm0       \n\t"
357
                "movq       8(%1), %%mm2       \n\t"
358
                "movq      16(%1), %%mm4       \n\t"
359
                "movq      24(%1), %%mm6       \n\t"
360
                "movq        (%1), %%mm1       \n\t"
361
                "movq       8(%1), %%mm3       \n\t"
362
                "movq      16(%1), %%mm5       \n\t"
363
                "movq      24(%1), %%mm7       \n\t"
364
                "punpckldq   (%2), %%mm0       \n\t"
365
                "punpckldq  8(%2), %%mm2       \n\t"
366
                "punpckldq 16(%2), %%mm4       \n\t"
367
                "punpckldq 24(%2), %%mm6       \n\t"
368
                "movq       %%mm0, (%0)        \n\t"
369
                "movq       %%mm2, 16(%0)      \n\t"
370
                "movq       %%mm4, 32(%0)      \n\t"
371
                "movq       %%mm6, 48(%0)      \n\t"
372
                "punpckhdq   (%2), %%mm1       \n\t"
373
                "punpckhdq  8(%2), %%mm3       \n\t"
374
                "punpckhdq 16(%2), %%mm5       \n\t"
375
                "punpckhdq 24(%2), %%mm7       \n\t"
376
                "movq       %%mm1, 8(%0)       \n\t"
377
                "movq       %%mm3, 24(%0)      \n\t"
378
                "movq       %%mm5, 40(%0)      \n\t"
379
                "movq       %%mm7, 56(%0)      \n\t"
380
                :: "r"(&b[i]), "r"(&b[i>>1]), "r"(&temp[i>>1])
381
                 : "memory"
382
               );
383
        }
384
    }
385
}
386

    
387
#define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\
388
        ""op" (%%"r",%%"REG_d",4), %%"t0"      \n\t"\
389
        ""op" 16(%%"r",%%"REG_d",4), %%"t1"    \n\t"\
390
        ""op" 32(%%"r",%%"REG_d",4), %%"t2"    \n\t"\
391
        ""op" 48(%%"r",%%"REG_d",4), %%"t3"    \n\t"
392

    
393
#define snow_vertical_compose_sse2_load(r,t0,t1,t2,t3)\
394
        snow_vertical_compose_sse2_load_add("movdqa",r,t0,t1,t2,t3)
395

    
396
#define snow_vertical_compose_sse2_add(r,t0,t1,t2,t3)\
397
        snow_vertical_compose_sse2_load_add("paddd",r,t0,t1,t2,t3)
398

    
399
#define snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
400
        "psubd %%"s0", %%"t0" \n\t"\
401
        "psubd %%"s1", %%"t1" \n\t"\
402
        "psubd %%"s2", %%"t2" \n\t"\
403
        "psubd %%"s3", %%"t3" \n\t"
404

    
405
#define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\
406
        "movdqa %%"s0", (%%"w",%%"REG_d",4)      \n\t"\
407
        "movdqa %%"s1", 16(%%"w",%%"REG_d",4)    \n\t"\
408
        "movdqa %%"s2", 32(%%"w",%%"REG_d",4)    \n\t"\
409
        "movdqa %%"s3", 48(%%"w",%%"REG_d",4)    \n\t"
410

    
411
#define snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)\
412
        "psrad $"n", %%"t0" \n\t"\
413
        "psrad $"n", %%"t1" \n\t"\
414
        "psrad $"n", %%"t2" \n\t"\
415
        "psrad $"n", %%"t3" \n\t"
416

    
417
#define snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
418
        "paddd %%"s0", %%"t0" \n\t"\
419
        "paddd %%"s1", %%"t1" \n\t"\
420
        "paddd %%"s2", %%"t2" \n\t"\
421
        "paddd %%"s3", %%"t3" \n\t"
422

    
423
#define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\
424
        "movdqa %%"s0", %%"t0" \n\t"\
425
        "movdqa %%"s1", %%"t1" \n\t"\
426
        "movdqa %%"s2", %%"t2" \n\t"\
427
        "movdqa %%"s3", %%"t3" \n\t"
428

    
429
void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
430
    long i = width;
431

    
432
    while(i & 0xF)
433
    {
434
        i--;
435
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
436
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
437
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
438
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
439
    }
440

    
441
         asm volatile (
442
        "jmp 2f                                      \n\t"
443
        "1:                                          \n\t"
444

    
445
        "mov %6, %%"REG_a"                           \n\t"
446
        "mov %4, %%"REG_S"                           \n\t"
447

    
448
        snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
449
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
450
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
451
        snow_vertical_compose_sse2_r2r_add("xmm0","xmm2","xmm4","xmm6","xmm0","xmm2","xmm4","xmm6")
452
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
453

    
454
        "pcmpeqd %%xmm1, %%xmm1                      \n\t"
455
        "pslld $31, %%xmm1                           \n\t"
456
        "psrld $29, %%xmm1                           \n\t"
457
        "mov %5, %%"REG_a"                           \n\t"
458

    
459
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
460
        snow_vertical_compose_sse2_sra("3","xmm0","xmm2","xmm4","xmm6")
461
        snow_vertical_compose_sse2_load(REG_a,"xmm1","xmm3","xmm5","xmm7")
462
        snow_vertical_compose_sse2_sub("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
463
        snow_vertical_compose_sse2_store(REG_a,"xmm1","xmm3","xmm5","xmm7")
464
        "mov %3, %%"REG_c"                           \n\t"
465
        snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6")
466
        snow_vertical_compose_sse2_add(REG_c,"xmm1","xmm3","xmm5","xmm7")
467
        snow_vertical_compose_sse2_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
468
        snow_vertical_compose_sse2_store(REG_S,"xmm0","xmm2","xmm4","xmm6")
469
        "mov %2, %%"REG_a"                           \n\t"
470
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
471
        snow_vertical_compose_sse2_sra("2","xmm0","xmm2","xmm4","xmm6")
472
        snow_vertical_compose_sse2_add(REG_c,"xmm0","xmm2","xmm4","xmm6")
473

    
474
        "pcmpeqd %%xmm1, %%xmm1                      \n\t"
475
        "pslld $31, %%xmm1                           \n\t"
476
        "psrld $30, %%xmm1                           \n\t"
477
        "mov %1, %%"REG_S"                           \n\t"
478

    
479
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
480
        snow_vertical_compose_sse2_sra("2","xmm0","xmm2","xmm4","xmm6")
481
        snow_vertical_compose_sse2_add(REG_c,"xmm0","xmm2","xmm4","xmm6")
482
        snow_vertical_compose_sse2_store(REG_c,"xmm0","xmm2","xmm4","xmm6")
483
        snow_vertical_compose_sse2_add(REG_S,"xmm0","xmm2","xmm4","xmm6")
484
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
485
        snow_vertical_compose_sse2_sra("1","xmm0","xmm2","xmm4","xmm6")
486
        snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
487
        snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6")
488
        snow_vertical_compose_sse2_store(REG_a,"xmm0","xmm2","xmm4","xmm6")
489

    
490
        "2:                                          \n\t"
491
        "sub $16, %%"REG_d"                          \n\t"
492
        "jge 1b                                      \n\t"
493
        :"+d"(i)
494
        :
495
        "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
496
        "%"REG_a"","%"REG_S"","%"REG_c"");
497
}
498

    
499
#define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\
500
        ""op" (%%"r",%%"REG_d",4), %%"t0"   \n\t"\
501
        ""op" 8(%%"r",%%"REG_d",4), %%"t1"  \n\t"\
502
        ""op" 16(%%"r",%%"REG_d",4), %%"t2" \n\t"\
503
        ""op" 24(%%"r",%%"REG_d",4), %%"t3" \n\t"
504

    
505
#define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\
506
        snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3)
507

    
508
#define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\
509
        snow_vertical_compose_mmx_load_add("paddd",r,t0,t1,t2,t3)
510

    
511
#define snow_vertical_compose_mmx_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
512
        snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)
513

    
514
#define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\
515
        "movq %%"s0", (%%"w",%%"REG_d",4)   \n\t"\
516
        "movq %%"s1", 8(%%"w",%%"REG_d",4)  \n\t"\
517
        "movq %%"s2", 16(%%"w",%%"REG_d",4) \n\t"\
518
        "movq %%"s3", 24(%%"w",%%"REG_d",4) \n\t"
519

    
520
#define snow_vertical_compose_mmx_sra(n,t0,t1,t2,t3)\
521
        snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)
522

    
523
#define snow_vertical_compose_mmx_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
524
        snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)
525

    
526
#define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\
527
        "movq %%"s0", %%"t0" \n\t"\
528
        "movq %%"s1", %%"t1" \n\t"\
529
        "movq %%"s2", %%"t2" \n\t"\
530
        "movq %%"s3", %%"t3" \n\t"
531

    
532
void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
533
    long i = width;
534
    while(i & 0x7)
535
    {
536
        i--;
537
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
538
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
539
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
540
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
541
    }
542

    
543
    asm volatile(
544
        "jmp 2f                                      \n\t"
545
        "1:                                          \n\t"
546

    
547
        "mov %6, %%"REG_a"                           \n\t"
548
        "mov %4, %%"REG_S"                           \n\t"
549

    
550
        snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
551
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
552
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
553
        snow_vertical_compose_mmx_r2r_add("mm0","mm2","mm4","mm6","mm0","mm2","mm4","mm6")
554
        snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
555

    
556
        "pcmpeqd %%mm1, %%mm1                        \n\t"
557
        "pslld $31, %%mm1                            \n\t"
558
        "psrld $29, %%mm1                            \n\t"
559
        "mov %5, %%"REG_a"                           \n\t"
560

    
561
        snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
562
        snow_vertical_compose_mmx_sra("3","mm0","mm2","mm4","mm6")
563
        snow_vertical_compose_mmx_load(REG_a,"mm1","mm3","mm5","mm7")
564
        snow_vertical_compose_mmx_sub("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
565
        snow_vertical_compose_mmx_store(REG_a,"mm1","mm3","mm5","mm7")
566
        "mov %3, %%"REG_c"                           \n\t"
567
        snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6")
568
        snow_vertical_compose_mmx_add(REG_c,"mm1","mm3","mm5","mm7")
569
        snow_vertical_compose_mmx_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
570
        snow_vertical_compose_mmx_store(REG_S,"mm0","mm2","mm4","mm6")
571
        "mov %2, %%"REG_a"                           \n\t"
572
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
573
        snow_vertical_compose_mmx_sra("2","mm0","mm2","mm4","mm6")
574
        snow_vertical_compose_mmx_add(REG_c,"mm0","mm2","mm4","mm6")
575

    
576
        "pcmpeqd %%mm1, %%mm1                        \n\t"
577
        "pslld $31, %%mm1                            \n\t"
578
        "psrld $30, %%mm1                            \n\t"
579
        "mov %1, %%"REG_S"                           \n\t"
580

    
581
        snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
582
        snow_vertical_compose_mmx_sra("2","mm0","mm2","mm4","mm6")
583
        snow_vertical_compose_mmx_add(REG_c,"mm0","mm2","mm4","mm6")
584
        snow_vertical_compose_mmx_store(REG_c,"mm0","mm2","mm4","mm6")
585
        snow_vertical_compose_mmx_add(REG_S,"mm0","mm2","mm4","mm6")
586
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
587
        snow_vertical_compose_mmx_sra("1","mm0","mm2","mm4","mm6")
588
        snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
589
        snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6")
590
        snow_vertical_compose_mmx_store(REG_a,"mm0","mm2","mm4","mm6")
591

    
592
        "2:                                          \n\t"
593
        "sub $8, %%"REG_d"                           \n\t"
594
        "jge 1b                                      \n\t"
595
        :"+d"(i)
596
        :
597
        "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5):
598
        "%"REG_a"","%"REG_S"","%"REG_c"");
599
}
600

    
601
#define snow_inner_add_yblock_sse2_header \
602
    DWTELEM * * dst_array = sb->line + src_y;\
603
    long tmp;\
604
    asm volatile(\
605
             "mov  %7, %%"REG_c"             \n\t"\
606
             "mov  %6, %2                    \n\t"\
607
             "mov  %4, %%"REG_S"             \n\t"\
608
             "pxor %%xmm7, %%xmm7            \n\t" /* 0 */\
609
             "pcmpeqd %%xmm3, %%xmm3         \n\t"\
610
             "pslld $31, %%xmm3              \n\t"\
611
             "psrld $24, %%xmm3              \n\t" /* FRAC_BITS >> 1 */\
612
             "1:                             \n\t"\
613
             "mov %1, %%"REG_D"              \n\t"\
614
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
615
             "add %3, %%"REG_D"              \n\t"
616

    
617
#define snow_inner_add_yblock_sse2_start_8(out_reg1, out_reg2, ptr_offset, s_offset)\
618
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
619
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
620
             "movq (%%"REG_d", %%"REG_c"), %%"out_reg2" \n\t"\
621
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
622
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
623
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
624
             "movq "s_offset"+16(%%"REG_S"), %%xmm4 \n\t"\
625
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
626
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
627
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
628
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
629

    
630
#define snow_inner_add_yblock_sse2_start_16(out_reg1, out_reg2, ptr_offset, s_offset)\
631
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
632
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
633
             "movq 8(%%"REG_d"), %%"out_reg2" \n\t"\
634
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
635
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
636
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
637
             "movq "s_offset"+8(%%"REG_S"), %%xmm4 \n\t"\
638
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
639
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
640
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
641
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
642

    
643
#define snow_inner_add_yblock_sse2_accum_8(ptr_offset, s_offset) \
644
             snow_inner_add_yblock_sse2_start_8("xmm2", "xmm6", ptr_offset, s_offset)\
645
             "paddusw %%xmm2, %%xmm1         \n\t"\
646
             "paddusw %%xmm6, %%xmm5         \n\t"
647

    
648
#define snow_inner_add_yblock_sse2_accum_16(ptr_offset, s_offset) \
649
             snow_inner_add_yblock_sse2_start_16("xmm2", "xmm6", ptr_offset, s_offset)\
650
             "paddusw %%xmm2, %%xmm1         \n\t"\
651
             "paddusw %%xmm6, %%xmm5         \n\t"
652

    
653
#define snow_inner_add_yblock_sse2_end_common1\
654
             "add $32, %%"REG_S"             \n\t"\
655
             "add %%"REG_c", %0              \n\t"\
656
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
657
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
658
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
659
             "add %%"REG_c", (%%"REG_a")     \n\t"
660

    
661
#define snow_inner_add_yblock_sse2_end_common2\
662
             "jnz 1b                         \n\t"\
663
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
664
             :\
665
             "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
666
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
667

    
668
#define snow_inner_add_yblock_sse2_end_8\
669
             "sal $1, %%"REG_c"              \n\t"\
670
             "add $"PTR_SIZE"*2, %1          \n\t"\
671
             snow_inner_add_yblock_sse2_end_common1\
672
             "sar $1, %%"REG_c"              \n\t"\
673
             "sub $2, %2                     \n\t"\
674
             snow_inner_add_yblock_sse2_end_common2
675

    
676
#define snow_inner_add_yblock_sse2_end_16\
677
             "add $"PTR_SIZE"*1, %1          \n\t"\
678
             snow_inner_add_yblock_sse2_end_common1\
679
             "dec %2                         \n\t"\
680
             snow_inner_add_yblock_sse2_end_common2
681

    
682
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,
683
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
684
snow_inner_add_yblock_sse2_header
685
snow_inner_add_yblock_sse2_start_8("xmm1", "xmm5", "3", "0")
686
snow_inner_add_yblock_sse2_accum_8("2", "8")
687
snow_inner_add_yblock_sse2_accum_8("1", "128")
688
snow_inner_add_yblock_sse2_accum_8("0", "136")
689

    
690
             "mov %0, %%"REG_d"              \n\t"
691
             "movdqa (%%"REG_D"), %%xmm0     \n\t"
692
             "movdqa %%xmm1, %%xmm2          \n\t"
693

    
694
             "punpckhwd %%xmm7, %%xmm1       \n\t"
695
             "punpcklwd %%xmm7, %%xmm2       \n\t"
696
             "paddd %%xmm2, %%xmm0           \n\t"
697
             "movdqa 16(%%"REG_D"), %%xmm2   \n\t"
698
             "paddd %%xmm1, %%xmm2           \n\t"
699
             "paddd %%xmm3, %%xmm0           \n\t"
700
             "paddd %%xmm3, %%xmm2           \n\t"
701

    
702
             "mov %1, %%"REG_D"              \n\t"
703
             "mov "PTR_SIZE"(%%"REG_D"), %%"REG_D";\n\t"
704
             "add %3, %%"REG_D"              \n\t"
705

    
706
             "movdqa (%%"REG_D"), %%xmm4     \n\t"
707
             "movdqa %%xmm5, %%xmm6          \n\t"
708
             "punpckhwd %%xmm7, %%xmm5       \n\t"
709
             "punpcklwd %%xmm7, %%xmm6       \n\t"
710
             "paddd %%xmm6, %%xmm4           \n\t"
711
             "movdqa 16(%%"REG_D"), %%xmm6   \n\t"
712
             "paddd %%xmm5, %%xmm6           \n\t"
713
             "paddd %%xmm3, %%xmm4           \n\t"
714
             "paddd %%xmm3, %%xmm6           \n\t"
715

    
716
             "psrad $8, %%xmm0               \n\t" /* FRAC_BITS. */
717
             "psrad $8, %%xmm2               \n\t" /* FRAC_BITS. */
718
             "packssdw %%xmm2, %%xmm0        \n\t"
719
             "packuswb %%xmm7, %%xmm0        \n\t"
720
             "movq %%xmm0, (%%"REG_d")       \n\t"
721

    
722
             "psrad $8, %%xmm4               \n\t" /* FRAC_BITS. */
723
             "psrad $8, %%xmm6               \n\t" /* FRAC_BITS. */
724
             "packssdw %%xmm6, %%xmm4        \n\t"
725
             "packuswb %%xmm7, %%xmm4        \n\t"
726
             "movq %%xmm4, (%%"REG_d",%%"REG_c");\n\t"
727
snow_inner_add_yblock_sse2_end_8
728
}
729

    
730
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,
731
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
732
snow_inner_add_yblock_sse2_header
733
snow_inner_add_yblock_sse2_start_16("xmm1", "xmm5", "3", "0")
734
snow_inner_add_yblock_sse2_accum_16("2", "16")
735
snow_inner_add_yblock_sse2_accum_16("1", "512")
736
snow_inner_add_yblock_sse2_accum_16("0", "528")
737

    
738
             "mov %0, %%"REG_d"              \n\t"
739
             "movdqa %%xmm1, %%xmm0          \n\t"
740
             "movdqa %%xmm5, %%xmm4          \n\t"
741
             "punpcklwd %%xmm7, %%xmm0       \n\t"
742
             "paddd (%%"REG_D"), %%xmm0      \n\t"
743
             "punpckhwd %%xmm7, %%xmm1       \n\t"
744
             "paddd 16(%%"REG_D"), %%xmm1    \n\t"
745
             "punpcklwd %%xmm7, %%xmm4       \n\t"
746
             "paddd 32(%%"REG_D"), %%xmm4    \n\t"
747
             "punpckhwd %%xmm7, %%xmm5       \n\t"
748
             "paddd 48(%%"REG_D"), %%xmm5    \n\t"
749
             "paddd %%xmm3, %%xmm0           \n\t"
750
             "paddd %%xmm3, %%xmm1           \n\t"
751
             "paddd %%xmm3, %%xmm4           \n\t"
752
             "paddd %%xmm3, %%xmm5           \n\t"
753
             "psrad $8, %%xmm0               \n\t" /* FRAC_BITS. */
754
             "psrad $8, %%xmm1               \n\t" /* FRAC_BITS. */
755
             "psrad $8, %%xmm4               \n\t" /* FRAC_BITS. */
756
             "psrad $8, %%xmm5               \n\t" /* FRAC_BITS. */
757

    
758
             "packssdw %%xmm1, %%xmm0        \n\t"
759
             "packssdw %%xmm5, %%xmm4        \n\t"
760
             "packuswb %%xmm4, %%xmm0        \n\t"
761

    
762
             "movdqu %%xmm0, (%%"REG_d")       \n\t"
763

    
764
snow_inner_add_yblock_sse2_end_16
765
}
766

    
767
#define snow_inner_add_yblock_mmx_header \
768
    DWTELEM * * dst_array = sb->line + src_y;\
769
    long tmp;\
770
    asm volatile(\
771
             "mov  %7, %%"REG_c"             \n\t"\
772
             "mov  %6, %2                    \n\t"\
773
             "mov  %4, %%"REG_S"             \n\t"\
774
             "pxor %%mm7, %%mm7              \n\t" /* 0 */\
775
             "pcmpeqd %%mm3, %%mm3           \n\t"\
776
             "pslld $31, %%mm3               \n\t"\
777
             "psrld $24, %%mm3               \n\t" /* FRAC_BITS >> 1 */\
778
             "1:                             \n\t"\
779
             "mov %1, %%"REG_D"              \n\t"\
780
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
781
             "add %3, %%"REG_D"              \n\t"
782

    
783
#define snow_inner_add_yblock_mmx_start(out_reg1, out_reg2, ptr_offset, s_offset, d_offset)\
784
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
785
             "movd "d_offset"(%%"REG_d"), %%"out_reg1" \n\t"\
786
             "movd "d_offset"+4(%%"REG_d"), %%"out_reg2" \n\t"\
787
             "punpcklbw %%mm7, %%"out_reg1" \n\t"\
788
             "punpcklbw %%mm7, %%"out_reg2" \n\t"\
789
             "movd "s_offset"(%%"REG_S"), %%mm0 \n\t"\
790
             "movd "s_offset"+4(%%"REG_S"), %%mm4 \n\t"\
791
             "punpcklbw %%mm7, %%mm0       \n\t"\
792
             "punpcklbw %%mm7, %%mm4       \n\t"\
793
             "pmullw %%mm0, %%"out_reg1"    \n\t"\
794
             "pmullw %%mm4, %%"out_reg2"    \n\t"
795

    
796
#define snow_inner_add_yblock_mmx_accum(ptr_offset, s_offset, d_offset) \
797
             snow_inner_add_yblock_mmx_start("mm2", "mm6", ptr_offset, s_offset, d_offset)\
798
             "paddusw %%mm2, %%mm1         \n\t"\
799
             "paddusw %%mm6, %%mm5         \n\t"
800

    
801
#define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\
802
             "mov %0, %%"REG_d"              \n\t"\
803
             "movq %%mm1, %%mm0              \n\t"\
804
             "movq %%mm5, %%mm4              \n\t"\
805
             "punpcklwd %%mm7, %%mm0         \n\t"\
806
             "paddd "read_offset"(%%"REG_D"), %%mm0 \n\t"\
807
             "punpckhwd %%mm7, %%mm1         \n\t"\
808
             "paddd "read_offset"+8(%%"REG_D"), %%mm1 \n\t"\
809
             "punpcklwd %%mm7, %%mm4         \n\t"\
810
             "paddd "read_offset"+16(%%"REG_D"), %%mm4 \n\t"\
811
             "punpckhwd %%mm7, %%mm5         \n\t"\
812
             "paddd "read_offset"+24(%%"REG_D"), %%mm5 \n\t"\
813
             "paddd %%mm3, %%mm0             \n\t"\
814
             "paddd %%mm3, %%mm1             \n\t"\
815
             "paddd %%mm3, %%mm4             \n\t"\
816
             "paddd %%mm3, %%mm5             \n\t"\
817
             "psrad $8, %%mm0                \n\t"\
818
             "psrad $8, %%mm1                \n\t"\
819
             "psrad $8, %%mm4                \n\t"\
820
             "psrad $8, %%mm5                \n\t"\
821
\
822
             "packssdw %%mm1, %%mm0          \n\t"\
823
             "packssdw %%mm5, %%mm4          \n\t"\
824
             "packuswb %%mm4, %%mm0          \n\t"\
825
             "movq %%mm0, "write_offset"(%%"REG_d") \n\t"
826

    
827
#define snow_inner_add_yblock_mmx_end(s_step)\
828
             "add $"s_step", %%"REG_S"             \n\t"\
829
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
830
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
831
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
832
             "add %%"REG_c", (%%"REG_a")     \n\t"\
833
             "add $"PTR_SIZE"*1, %1          \n\t"\
834
             "add %%"REG_c", %0              \n\t"\
835
             "dec %2                         \n\t"\
836
             "jnz 1b                         \n\t"\
837
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
838
             :\
839
             "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
840
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
841

    
842
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,
843
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
844
snow_inner_add_yblock_mmx_header
845
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
846
snow_inner_add_yblock_mmx_accum("2", "8", "0")
847
snow_inner_add_yblock_mmx_accum("1", "128", "0")
848
snow_inner_add_yblock_mmx_accum("0", "136", "0")
849
snow_inner_add_yblock_mmx_mix("0", "0")
850
snow_inner_add_yblock_mmx_end("16")
851
}
852

    
853
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,
854
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
855
snow_inner_add_yblock_mmx_header
856
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
857
snow_inner_add_yblock_mmx_accum("2", "16", "0")
858
snow_inner_add_yblock_mmx_accum("1", "512", "0")
859
snow_inner_add_yblock_mmx_accum("0", "528", "0")
860
snow_inner_add_yblock_mmx_mix("0", "0")
861

    
862
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8")
863
snow_inner_add_yblock_mmx_accum("2", "24", "8")
864
snow_inner_add_yblock_mmx_accum("1", "520", "8")
865
snow_inner_add_yblock_mmx_accum("0", "536", "8")
866
snow_inner_add_yblock_mmx_mix("32", "8")
867
snow_inner_add_yblock_mmx_end("32")
868
}
869

    
870
void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
871
                           int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
872

    
873
    if (b_w == 16)
874
        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);
875
    else if (b_w == 8 && obmc_stride == 16) {
876
        if (!(b_h & 1))
877
            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);
878
        else
879
            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);
880
    } else
881
         ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
882
}
883

    
884
void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
885
                          int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
886
    if (b_w == 16)
887
        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);
888
    else if (b_w == 8 && obmc_stride == 16)
889
        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);
890
    else
891
        ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
892
}