Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / snowdsp_mmx.c @ 1104bf2b

History | View | Annotate | Download (39.3 KB)

1 4567b4bd Robert Edele
/*
2
 * MMX and SSE2 optimized snow DSP utils
3
 * Copyright (c) 2005-2006 Robert Edele <yartrebo@earthlink.net>
4
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 4567b4bd Robert Edele
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 4567b4bd Robert Edele
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 4567b4bd Robert Edele
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 4567b4bd Robert Edele
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22 b550bfaa Ronald S. Bultje
#include "avcodec.h"
23
#include "snow.h"
24 9c39071d Luca Abeni
#include "x86_cpu.h"
25 4567b4bd Robert Edele
26 3e0f7126 Michael Niedermayer
void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width){
27 2c9a0285 Robert Edele
    const int w2= (width+1)>>1;
28
    // SSE2 code runs faster with pointers aligned on a 32-byte boundary.
29 3e0f7126 Michael Niedermayer
    IDWTELEM temp_buf[(width>>1) + 4];
30
    IDWTELEM * const temp = temp_buf + 4 - (((int)temp_buf & 0xF) >> 2);
31 2c9a0285 Robert Edele
    const int w_l= (width>>1);
32
    const int w_r= w2 - 1;
33
    int i;
34
35
    { // Lift 0
36 3e0f7126 Michael Niedermayer
        IDWTELEM * const ref = b + w2 - 1;
37
        IDWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice
38 2c9a0285 Robert Edele
        // (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 3e0f7126 Michael Niedermayer
            "psllw        $15, %%xmm7         \n\t"
46 b696a4c9 Michael Niedermayer
            "psrlw        $14, %%xmm7         \n\t"
47 2c9a0285 Robert Edele
        ::);
48 3e0f7126 Michael Niedermayer
        for(; i<w_l-15; i+=16){
49 2c9a0285 Robert Edele
            asm volatile(
50
                "movdqu   (%1), %%xmm1        \n\t"
51
                "movdqu 16(%1), %%xmm5        \n\t"
52 3e0f7126 Michael Niedermayer
                "movdqu  2(%1), %%xmm2        \n\t"
53
                "movdqu 18(%1), %%xmm6        \n\t"
54
                "paddw  %%xmm1, %%xmm2        \n\t"
55
                "paddw  %%xmm5, %%xmm6        \n\t"
56 2c9a0285 Robert Edele
                "movdqa %%xmm2, %%xmm0        \n\t"
57
                "movdqa %%xmm6, %%xmm4        \n\t"
58 b696a4c9 Michael Niedermayer
                "psraw      $1, %%xmm0        \n\t"
59
                "psraw      $1, %%xmm4        \n\t"
60 3e0f7126 Michael Niedermayer
                "paddw  %%xmm0, %%xmm2        \n\t"
61
                "paddw  %%xmm4, %%xmm6        \n\t"
62
                "paddw  %%xmm7, %%xmm2        \n\t"
63
                "paddw  %%xmm7, %%xmm6        \n\t"
64 b696a4c9 Michael Niedermayer
                "psraw      $2, %%xmm2        \n\t"
65
                "psraw      $2, %%xmm6        \n\t"
66 2c9a0285 Robert Edele
                "movdqa   (%0), %%xmm0        \n\t"
67
                "movdqa 16(%0), %%xmm4        \n\t"
68 3e0f7126 Michael Niedermayer
                "psubw  %%xmm2, %%xmm0        \n\t"
69
                "psubw  %%xmm6, %%xmm4        \n\t"
70 2c9a0285 Robert Edele
                "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 3e0f7126 Michael Niedermayer
        IDWTELEM * const dst = b+w2;
82 2c9a0285 Robert Edele
83
        i = 0;
84 3e0f7126 Michael Niedermayer
        for(; (((long)&dst[i]) & 0x1F) && i<w_r; i++){
85 2c9a0285 Robert Edele
            dst[i] = dst[i] - (b[i] + b[i + 1]);
86
        }
87 3e0f7126 Michael Niedermayer
        for(; i<w_r-15; i+=16){
88 2c9a0285 Robert Edele
            asm volatile(
89
                "movdqu   (%1), %%xmm1        \n\t"
90
                "movdqu 16(%1), %%xmm5        \n\t"
91 3e0f7126 Michael Niedermayer
                "movdqu  2(%1), %%xmm2        \n\t"
92
                "movdqu 18(%1), %%xmm6        \n\t"
93
                "paddw  %%xmm1, %%xmm2        \n\t"
94
                "paddw  %%xmm5, %%xmm6        \n\t"
95 2c9a0285 Robert Edele
                "movdqa   (%0), %%xmm0        \n\t"
96
                "movdqa 16(%0), %%xmm4        \n\t"
97 3e0f7126 Michael Niedermayer
                "psubw  %%xmm2, %%xmm0        \n\t"
98
                "psubw  %%xmm6, %%xmm4        \n\t"
99 2c9a0285 Robert Edele
                "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 3e0f7126 Michael Niedermayer
        IDWTELEM * const ref = b+w2 - 1;
110
        IDWTELEM b_0 = b[0];
111 2c9a0285 Robert Edele
112
        i = 0;
113
        asm volatile(
114 62975029 Michael Niedermayer
            "psllw         $13, %%xmm7        \n\t"
115
            "pcmpeqw    %%xmm6, %%xmm6        \n\t"
116
            "psrlw         $13, %%xmm6        \n\t"
117
            "paddw      %%xmm7, %%xmm6        \n\t"
118 2c9a0285 Robert Edele
        ::);
119 3e0f7126 Michael Niedermayer
        for(; i<w_l-15; i+=16){
120 2c9a0285 Robert Edele
            asm volatile(
121 62975029 Michael Niedermayer
                "movdqu   (%1), %%xmm0        \n\t"
122
                "movdqu 16(%1), %%xmm4        \n\t"
123
                "movdqu  2(%1), %%xmm1        \n\t"
124
                "movdqu 18(%1), %%xmm5        \n\t" //FIXME try aligned reads and shifts
125
                "paddw  %%xmm6, %%xmm0        \n\t"
126
                "paddw  %%xmm6, %%xmm4        \n\t"
127
                "paddw  %%xmm7, %%xmm1        \n\t"
128
                "paddw  %%xmm7, %%xmm5        \n\t"
129
                "pavgw  %%xmm1, %%xmm0        \n\t"
130
                "pavgw  %%xmm5, %%xmm4        \n\t"
131
                "psubw  %%xmm7, %%xmm0        \n\t"
132
                "psubw  %%xmm7, %%xmm4        \n\t"
133
                "psraw      $1, %%xmm0        \n\t"
134
                "psraw      $1, %%xmm4        \n\t"
135 be3b22f9 Michael Niedermayer
                "movdqa   (%0), %%xmm1        \n\t"
136
                "movdqa 16(%0), %%xmm5        \n\t"
137 3e0f7126 Michael Niedermayer
                "paddw  %%xmm1, %%xmm0        \n\t"
138
                "paddw  %%xmm5, %%xmm4        \n\t"
139
                "psraw      $2, %%xmm0        \n\t"
140
                "psraw      $2, %%xmm4        \n\t"
141
                "paddw  %%xmm1, %%xmm0        \n\t"
142
                "paddw  %%xmm5, %%xmm4        \n\t"
143 2c9a0285 Robert Edele
                "movdqa %%xmm0, (%0)          \n\t"
144
                "movdqa %%xmm4, 16(%0)        \n\t"
145
                :: "r"(&b[i]), "r"(&ref[i])
146
                : "memory"
147
            );
148
        }
149
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
150 be3b22f9 Michael Niedermayer
        b[0] = b_0 + ((2 * ref[1] + W_BO-1 + 4 * b_0) >> W_BS);
151 2c9a0285 Robert Edele
    }
152
153
    { // Lift 3
154 3e0f7126 Michael Niedermayer
        IDWTELEM * const src = b+w2;
155 2c9a0285 Robert Edele
156
        i = 0;
157 3e0f7126 Michael Niedermayer
        for(; (((long)&temp[i]) & 0x1F) && i<w_r; i++){
158 2c9a0285 Robert Edele
            temp[i] = src[i] - ((-W_AM*(b[i] + b[i+1]))>>W_AS);
159
        }
160
        for(; i<w_r-7; i+=8){
161
            asm volatile(
162 3e0f7126 Michael Niedermayer
                "movdqu  2(%1), %%xmm2        \n\t"
163
                "movdqu 18(%1), %%xmm6        \n\t"
164
                "paddw    (%1), %%xmm2        \n\t"
165
                "paddw  16(%1), %%xmm6        \n\t"
166 ce611a27 Michael Niedermayer
                "movdqu   (%0), %%xmm0        \n\t"
167
                "movdqu 16(%0), %%xmm4        \n\t"
168 3e0f7126 Michael Niedermayer
                "paddw  %%xmm2, %%xmm0        \n\t"
169
                "paddw  %%xmm6, %%xmm4        \n\t"
170
                "psraw      $1, %%xmm2        \n\t"
171
                "psraw      $1, %%xmm6        \n\t"
172
                "paddw  %%xmm0, %%xmm2        \n\t"
173
                "paddw  %%xmm4, %%xmm6        \n\t"
174 2c9a0285 Robert Edele
                "movdqa %%xmm2, (%2)          \n\t"
175
                "movdqa %%xmm6, 16(%2)        \n\t"
176
                :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i])
177
                 : "memory"
178
               );
179
        }
180 ce611a27 Michael Niedermayer
        snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS);
181 2c9a0285 Robert Edele
    }
182
183
    {
184
        snow_interleave_line_header(&i, width, b, temp);
185
186 3e0f7126 Michael Niedermayer
        for (; (i & 0x3E) != 0x3E; i-=2){
187 2c9a0285 Robert Edele
            b[i+1] = temp[i>>1];
188
            b[i] = b[i>>1];
189
        }
190 3e0f7126 Michael Niedermayer
        for (i-=62; i>=0; i-=64){
191 2c9a0285 Robert Edele
            asm volatile(
192
                "movdqa      (%1), %%xmm0       \n\t"
193
                "movdqa    16(%1), %%xmm2       \n\t"
194
                "movdqa    32(%1), %%xmm4       \n\t"
195
                "movdqa    48(%1), %%xmm6       \n\t"
196
                "movdqa      (%1), %%xmm1       \n\t"
197
                "movdqa    16(%1), %%xmm3       \n\t"
198
                "movdqa    32(%1), %%xmm5       \n\t"
199
                "movdqa    48(%1), %%xmm7       \n\t"
200 3e0f7126 Michael Niedermayer
                "punpcklwd   (%2), %%xmm0       \n\t"
201
                "punpcklwd 16(%2), %%xmm2       \n\t"
202
                "punpcklwd 32(%2), %%xmm4       \n\t"
203
                "punpcklwd 48(%2), %%xmm6       \n\t"
204 2c9a0285 Robert Edele
                "movdqa    %%xmm0, (%0)         \n\t"
205
                "movdqa    %%xmm2, 32(%0)       \n\t"
206
                "movdqa    %%xmm4, 64(%0)       \n\t"
207
                "movdqa    %%xmm6, 96(%0)       \n\t"
208 3e0f7126 Michael Niedermayer
                "punpckhwd   (%2), %%xmm1       \n\t"
209
                "punpckhwd 16(%2), %%xmm3       \n\t"
210
                "punpckhwd 32(%2), %%xmm5       \n\t"
211
                "punpckhwd 48(%2), %%xmm7       \n\t"
212 2c9a0285 Robert Edele
                "movdqa    %%xmm1, 16(%0)       \n\t"
213
                "movdqa    %%xmm3, 48(%0)       \n\t"
214
                "movdqa    %%xmm5, 80(%0)       \n\t"
215
                "movdqa    %%xmm7, 112(%0)      \n\t"
216
                :: "r"(&(b)[i]), "r"(&(b)[i>>1]), "r"(&(temp)[i>>1])
217
                 : "memory"
218
               );
219
        }
220
    }
221
}
222
223 3e0f7126 Michael Niedermayer
void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){
224 2c9a0285 Robert Edele
    const int w2= (width+1)>>1;
225 3e0f7126 Michael Niedermayer
    IDWTELEM temp[width >> 1];
226 2c9a0285 Robert Edele
    const int w_l= (width>>1);
227
    const int w_r= w2 - 1;
228
    int i;
229
230
    { // Lift 0
231 3e0f7126 Michael Niedermayer
        IDWTELEM * const ref = b + w2 - 1;
232 2c9a0285 Robert Edele
233
        i = 1;
234
        b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
235
        asm volatile(
236 3e0f7126 Michael Niedermayer
            "pcmpeqw    %%mm7, %%mm7         \n\t"
237
            "psllw        $15, %%mm7         \n\t"
238 b696a4c9 Michael Niedermayer
            "psrlw        $14, %%mm7         \n\t"
239 2c9a0285 Robert Edele
           ::);
240 3e0f7126 Michael Niedermayer
        for(; i<w_l-7; i+=8){
241 2c9a0285 Robert Edele
            asm volatile(
242
                "movq     (%1), %%mm2        \n\t"
243
                "movq    8(%1), %%mm6        \n\t"
244 3e0f7126 Michael Niedermayer
                "paddw   2(%1), %%mm2        \n\t"
245
                "paddw  10(%1), %%mm6        \n\t"
246 2c9a0285 Robert Edele
                "movq    %%mm2, %%mm0        \n\t"
247
                "movq    %%mm6, %%mm4        \n\t"
248 b696a4c9 Michael Niedermayer
                "psraw      $1, %%mm2        \n\t"
249
                "psraw      $1, %%mm6        \n\t"
250 3e0f7126 Michael Niedermayer
                "paddw   %%mm0, %%mm2        \n\t"
251
                "paddw   %%mm4, %%mm6        \n\t"
252
                "paddw   %%mm7, %%mm2        \n\t"
253
                "paddw   %%mm7, %%mm6        \n\t"
254 b696a4c9 Michael Niedermayer
                "psraw      $2, %%mm2        \n\t"
255
                "psraw      $2, %%mm6        \n\t"
256 2c9a0285 Robert Edele
                "movq     (%0), %%mm0        \n\t"
257
                "movq    8(%0), %%mm4        \n\t"
258 3e0f7126 Michael Niedermayer
                "psubw   %%mm2, %%mm0        \n\t"
259
                "psubw   %%mm6, %%mm4        \n\t"
260 2c9a0285 Robert Edele
                "movq    %%mm0, (%0)         \n\t"
261
                "movq    %%mm4, 8(%0)        \n\t"
262
                :: "r"(&b[i]), "r"(&ref[i])
263
                 : "memory"
264
               );
265
        }
266
        snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
267
    }
268
269
    { // Lift 1
270 3e0f7126 Michael Niedermayer
        IDWTELEM * const dst = b+w2;
271 2c9a0285 Robert Edele
272
        i = 0;
273 3e0f7126 Michael Niedermayer
        for(; i<w_r-7; i+=8){
274 2c9a0285 Robert Edele
            asm volatile(
275
                "movq     (%1), %%mm2        \n\t"
276
                "movq    8(%1), %%mm6        \n\t"
277 3e0f7126 Michael Niedermayer
                "paddw   2(%1), %%mm2        \n\t"
278
                "paddw  10(%1), %%mm6        \n\t"
279 2c9a0285 Robert Edele
                "movq     (%0), %%mm0        \n\t"
280
                "movq    8(%0), %%mm4        \n\t"
281 3e0f7126 Michael Niedermayer
                "psubw   %%mm2, %%mm0        \n\t"
282
                "psubw   %%mm6, %%mm4        \n\t"
283 2c9a0285 Robert Edele
                "movq    %%mm0, (%0)         \n\t"
284
                "movq    %%mm4, 8(%0)        \n\t"
285
                :: "r"(&dst[i]), "r"(&b[i])
286
                 : "memory"
287
               );
288
        }
289
        snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
290
    }
291
292
    { // Lift 2
293 3e0f7126 Michael Niedermayer
        IDWTELEM * const ref = b+w2 - 1;
294 2c9a0285 Robert Edele
295
        i = 1;
296 ce611a27 Michael Niedermayer
        b[0] = b[0] + (((2 * ref[1] + W_BO) + 4 * b[0]) >> W_BS);
297 2c9a0285 Robert Edele
        asm volatile(
298 1104bf2b Michael Niedermayer
            "psllw         $14, %%mm7        \n\t"
299 62975029 Michael Niedermayer
            "pcmpeqw     %%mm6, %%mm6        \n\t"
300
            "psrlw         $13, %%mm6        \n\t"
301
            "paddw       %%mm7, %%mm6        \n\t"
302 2c9a0285 Robert Edele
           ::);
303 3e0f7126 Michael Niedermayer
        for(; i<w_l-7; i+=8){
304 2c9a0285 Robert Edele
            asm volatile(
305
                "movq     (%1), %%mm0        \n\t"
306
                "movq    8(%1), %%mm4        \n\t"
307 62975029 Michael Niedermayer
                "movq    2(%1), %%mm1        \n\t"
308
                "movq   10(%1), %%mm5        \n\t"
309
                "paddw   %%mm6, %%mm0        \n\t"
310
                "paddw   %%mm6, %%mm4        \n\t"
311
                "paddw   %%mm7, %%mm1        \n\t"
312
                "paddw   %%mm7, %%mm5        \n\t"
313
                "pavgw   %%mm1, %%mm0        \n\t"
314
                "pavgw   %%mm5, %%mm4        \n\t"
315
                "psubw   %%mm7, %%mm0        \n\t"
316
                "psubw   %%mm7, %%mm4        \n\t"
317
                "psraw      $1, %%mm0        \n\t"
318
                "psraw      $1, %%mm4        \n\t"
319 3a9f44d5 Michael Niedermayer
                "movq     (%0), %%mm1        \n\t"
320
                "movq    8(%0), %%mm5        \n\t"
321 3e0f7126 Michael Niedermayer
                "paddw   %%mm1, %%mm0        \n\t"
322
                "paddw   %%mm5, %%mm4        \n\t"
323
                "psraw      $2, %%mm0        \n\t"
324
                "psraw      $2, %%mm4        \n\t"
325
                "paddw   %%mm1, %%mm0        \n\t"
326
                "paddw   %%mm5, %%mm4        \n\t"
327 2c9a0285 Robert Edele
                "movq    %%mm0, (%0)         \n\t"
328
                "movq    %%mm4, 8(%0)        \n\t"
329
                :: "r"(&b[i]), "r"(&ref[i])
330
                 : "memory"
331
               );
332
        }
333
        snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
334
    }
335
336
    { // Lift 3
337 3e0f7126 Michael Niedermayer
        IDWTELEM * const src = b+w2;
338 2c9a0285 Robert Edele
        i = 0;
339
340 3e0f7126 Michael Niedermayer
        for(; i<w_r-7; i+=8){
341 2c9a0285 Robert Edele
            asm volatile(
342 3e0f7126 Michael Niedermayer
                "movq    2(%1), %%mm2        \n\t"
343
                "movq   10(%1), %%mm6        \n\t"
344
                "paddw    (%1), %%mm2        \n\t"
345
                "paddw   8(%1), %%mm6        \n\t"
346 eee649d3 Michael Niedermayer
                "movq     (%0), %%mm0        \n\t"
347
                "movq    8(%0), %%mm4        \n\t"
348 3e0f7126 Michael Niedermayer
                "paddw   %%mm2, %%mm0        \n\t"
349
                "paddw   %%mm6, %%mm4        \n\t"
350
                "psraw      $1, %%mm2        \n\t"
351
                "psraw      $1, %%mm6        \n\t"
352
                "paddw   %%mm0, %%mm2        \n\t"
353
                "paddw   %%mm4, %%mm6        \n\t"
354 2c9a0285 Robert Edele
                "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 ce611a27 Michael Niedermayer
        snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS);
361 2c9a0285 Robert Edele
    }
362
363
    {
364
        snow_interleave_line_header(&i, width, b, temp);
365
366 3e0f7126 Michael Niedermayer
        for (; (i & 0x1E) != 0x1E; i-=2){
367 2c9a0285 Robert Edele
            b[i+1] = temp[i>>1];
368
            b[i] = b[i>>1];
369
        }
370 3e0f7126 Michael Niedermayer
        for (i-=30; i>=0; i-=32){
371 2c9a0285 Robert Edele
            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 3e0f7126 Michael Niedermayer
                "punpcklwd   (%2), %%mm0       \n\t"
381
                "punpcklwd  8(%2), %%mm2       \n\t"
382
                "punpcklwd 16(%2), %%mm4       \n\t"
383
                "punpcklwd 24(%2), %%mm6       \n\t"
384 2c9a0285 Robert Edele
                "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 3e0f7126 Michael Niedermayer
                "punpckhwd   (%2), %%mm1       \n\t"
389
                "punpckhwd  8(%2), %%mm3       \n\t"
390
                "punpckhwd 16(%2), %%mm5       \n\t"
391
                "punpckhwd 24(%2), %%mm7       \n\t"
392 2c9a0285 Robert Edele
                "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 4567b4bd Robert Edele
#define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\
404 8b502929 Michael Niedermayer
        ""op" ("r",%%"REG_d"), %%"t0"      \n\t"\
405
        ""op" 16("r",%%"REG_d"), %%"t1"    \n\t"\
406
        ""op" 32("r",%%"REG_d"), %%"t2"    \n\t"\
407
        ""op" 48("r",%%"REG_d"), %%"t3"    \n\t"
408 4567b4bd Robert Edele
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 3e0f7126 Michael Niedermayer
        snow_vertical_compose_sse2_load_add("paddw",r,t0,t1,t2,t3)
414 4567b4bd Robert Edele
415 25bb359f Michael Niedermayer
#define snow_vertical_compose_r2r_sub(s0,s1,s2,s3,t0,t1,t2,t3)\
416 3e0f7126 Michael Niedermayer
        "psubw %%"s0", %%"t0" \n\t"\
417
        "psubw %%"s1", %%"t1" \n\t"\
418
        "psubw %%"s2", %%"t2" \n\t"\
419
        "psubw %%"s3", %%"t3" \n\t"
420 4567b4bd Robert Edele
421
#define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\
422 8b502929 Michael Niedermayer
        "movdqa %%"s0", ("w",%%"REG_d")      \n\t"\
423
        "movdqa %%"s1", 16("w",%%"REG_d")    \n\t"\
424
        "movdqa %%"s2", 32("w",%%"REG_d")    \n\t"\
425
        "movdqa %%"s3", 48("w",%%"REG_d")    \n\t"
426 4567b4bd Robert Edele
427 25bb359f Michael Niedermayer
#define snow_vertical_compose_sra(n,t0,t1,t2,t3)\
428 3e0f7126 Michael Niedermayer
        "psraw $"n", %%"t0" \n\t"\
429
        "psraw $"n", %%"t1" \n\t"\
430
        "psraw $"n", %%"t2" \n\t"\
431
        "psraw $"n", %%"t3" \n\t"
432 4567b4bd Robert Edele
433 25bb359f Michael Niedermayer
#define snow_vertical_compose_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\
434 3e0f7126 Michael Niedermayer
        "paddw %%"s0", %%"t0" \n\t"\
435
        "paddw %%"s1", %%"t1" \n\t"\
436
        "paddw %%"s2", %%"t2" \n\t"\
437
        "paddw %%"s3", %%"t3" \n\t"
438 4567b4bd Robert Edele
439
#define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\
440
        "movdqa %%"s0", %%"t0" \n\t"\
441
        "movdqa %%"s1", %%"t1" \n\t"\
442
        "movdqa %%"s2", %%"t2" \n\t"\
443
        "movdqa %%"s3", %%"t3" \n\t"
444
445 3e0f7126 Michael Niedermayer
void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){
446 4567b4bd Robert Edele
    long i = width;
447
448 3e0f7126 Michael Niedermayer
    while(i & 0x1F)
449 4567b4bd Robert Edele
    {
450
        i--;
451
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
452
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
453
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
454
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
455
    }
456 bc1e78d8 Michael Niedermayer
    i+=i;
457 4567b4bd Robert Edele
458
         asm volatile (
459
        "jmp 2f                                      \n\t"
460
        "1:                                          \n\t"
461
462 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6")
463
        snow_vertical_compose_sse2_add("%6","xmm0","xmm2","xmm4","xmm6")
464 4567b4bd Robert Edele
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
465 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6")
466
        snow_vertical_compose_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
467 4567b4bd Robert Edele
468
        "pcmpeqd %%xmm1, %%xmm1                      \n\t"
469 3e0f7126 Michael Niedermayer
        "psllw $15, %%xmm1                           \n\t"
470 9caa1ccc Michael Niedermayer
        "psrlw $14, %%xmm1                           \n\t"
471 4567b4bd Robert Edele
472 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6")
473
        snow_vertical_compose_sra("2","xmm0","xmm2","xmm4","xmm6")
474 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_load("%5","xmm1","xmm3","xmm5","xmm7")
475 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
476 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_store("%5","xmm1","xmm3","xmm5","xmm7")
477
        snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6")
478
        snow_vertical_compose_sse2_add("%3","xmm1","xmm3","xmm5","xmm7")
479 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
480 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_store("%4","xmm0","xmm2","xmm4","xmm6")
481 62975029 Michael Niedermayer
482
        "pcmpeqw %%xmm7, %%xmm7                      \n\t"
483
        "pcmpeqw %%xmm5, %%xmm5                      \n\t"
484
        "psllw $15, %%xmm7                           \n\t"
485
        "psrlw $13, %%xmm5                           \n\t"
486
        "paddw %%xmm7, %%xmm5                        \n\t"
487 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_add("xmm5","xmm5","xmm5","xmm5","xmm0","xmm2","xmm4","xmm6")
488 8b502929 Michael Niedermayer
        "movq   (%2,%%"REG_d"), %%xmm1        \n\t"
489
        "movq  8(%2,%%"REG_d"), %%xmm3        \n\t"
490 62975029 Michael Niedermayer
        "paddw %%xmm7, %%xmm1                        \n\t"
491
        "paddw %%xmm7, %%xmm3                        \n\t"
492
        "pavgw %%xmm1, %%xmm0                        \n\t"
493
        "pavgw %%xmm3, %%xmm2                        \n\t"
494 8b502929 Michael Niedermayer
        "movq 16(%2,%%"REG_d"), %%xmm1        \n\t"
495
        "movq 24(%2,%%"REG_d"), %%xmm3        \n\t"
496 62975029 Michael Niedermayer
        "paddw %%xmm7, %%xmm1                        \n\t"
497
        "paddw %%xmm7, %%xmm3                        \n\t"
498
        "pavgw %%xmm1, %%xmm4                        \n\t"
499
        "pavgw %%xmm3, %%xmm6                        \n\t"
500 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("xmm7","xmm7","xmm7","xmm7","xmm0","xmm2","xmm4","xmm6")
501
        snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6")
502 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6")
503 4567b4bd Robert Edele
504 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("2","xmm0","xmm2","xmm4","xmm6")
505 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6")
506
        snow_vertical_compose_sse2_store("%3","xmm0","xmm2","xmm4","xmm6")
507
        snow_vertical_compose_sse2_add("%1","xmm0","xmm2","xmm4","xmm6")
508 4567b4bd Robert Edele
        snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7")
509 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6")
510
        snow_vertical_compose_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6")
511 8b502929 Michael Niedermayer
        snow_vertical_compose_sse2_add("%2","xmm0","xmm2","xmm4","xmm6")
512
        snow_vertical_compose_sse2_store("%2","xmm0","xmm2","xmm4","xmm6")
513 4567b4bd Robert Edele
514
        "2:                                          \n\t"
515 bc1e78d8 Michael Niedermayer
        "sub $64, %%"REG_d"                          \n\t"
516 4567b4bd Robert Edele
        "jge 1b                                      \n\t"
517
        :"+d"(i)
518 8b502929 Michael Niedermayer
        :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5));
519 4567b4bd Robert Edele
}
520
521
#define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\
522 8b502929 Michael Niedermayer
        ""op" ("r",%%"REG_d"), %%"t0"   \n\t"\
523
        ""op" 8("r",%%"REG_d"), %%"t1"  \n\t"\
524
        ""op" 16("r",%%"REG_d"), %%"t2" \n\t"\
525
        ""op" 24("r",%%"REG_d"), %%"t3" \n\t"
526 4567b4bd Robert Edele
527
#define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\
528
        snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3)
529
530
#define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\
531 3e0f7126 Michael Niedermayer
        snow_vertical_compose_mmx_load_add("paddw",r,t0,t1,t2,t3)
532 4567b4bd Robert Edele
533
#define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\
534 8b502929 Michael Niedermayer
        "movq %%"s0", ("w",%%"REG_d")   \n\t"\
535
        "movq %%"s1", 8("w",%%"REG_d")  \n\t"\
536
        "movq %%"s2", 16("w",%%"REG_d") \n\t"\
537
        "movq %%"s3", 24("w",%%"REG_d") \n\t"
538 4567b4bd Robert Edele
539
#define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\
540
        "movq %%"s0", %%"t0" \n\t"\
541
        "movq %%"s1", %%"t1" \n\t"\
542
        "movq %%"s2", %%"t2" \n\t"\
543
        "movq %%"s3", %%"t3" \n\t"
544
545 3e0f7126 Michael Niedermayer
void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){
546 4567b4bd Robert Edele
    long i = width;
547 3e0f7126 Michael Niedermayer
    while(i & 15)
548 4567b4bd Robert Edele
    {
549
        i--;
550
        b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
551
        b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
552
        b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
553
        b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
554
    }
555 bc1e78d8 Michael Niedermayer
    i+=i;
556 4567b4bd Robert Edele
    asm volatile(
557
        "jmp 2f                                      \n\t"
558
        "1:                                          \n\t"
559
560 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_load("%4","mm0","mm2","mm4","mm6")
561
        snow_vertical_compose_mmx_add("%6","mm0","mm2","mm4","mm6")
562 4567b4bd Robert Edele
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
563 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6")
564
        snow_vertical_compose_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
565 4567b4bd Robert Edele
566 3e0f7126 Michael Niedermayer
        "pcmpeqw %%mm1, %%mm1                        \n\t"
567
        "psllw $15, %%mm1                            \n\t"
568 9caa1ccc Michael Niedermayer
        "psrlw $14, %%mm1                            \n\t"
569 4567b4bd Robert Edele
570 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6")
571
        snow_vertical_compose_sra("2","mm0","mm2","mm4","mm6")
572 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_load("%5","mm1","mm3","mm5","mm7")
573 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
574 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_store("%5","mm1","mm3","mm5","mm7")
575
        snow_vertical_compose_mmx_load("%4","mm0","mm2","mm4","mm6")
576
        snow_vertical_compose_mmx_add("%3","mm1","mm3","mm5","mm7")
577 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
578 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_store("%4","mm0","mm2","mm4","mm6")
579 62975029 Michael Niedermayer
        "pcmpeqw %%mm7, %%mm7                        \n\t"
580
        "pcmpeqw %%mm5, %%mm5                        \n\t"
581
        "psllw $15, %%mm7                            \n\t"
582
        "psrlw $13, %%mm5                            \n\t"
583
        "paddw %%mm7, %%mm5                          \n\t"
584 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_add("mm5","mm5","mm5","mm5","mm0","mm2","mm4","mm6")
585 8b502929 Michael Niedermayer
        "movq   (%2,%%"REG_d"), %%mm1         \n\t"
586
        "movq  8(%2,%%"REG_d"), %%mm3         \n\t"
587 62975029 Michael Niedermayer
        "paddw %%mm7, %%mm1                          \n\t"
588
        "paddw %%mm7, %%mm3                          \n\t"
589
        "pavgw %%mm1, %%mm0                          \n\t"
590
        "pavgw %%mm3, %%mm2                          \n\t"
591 8b502929 Michael Niedermayer
        "movq 16(%2,%%"REG_d"), %%mm1         \n\t"
592
        "movq 24(%2,%%"REG_d"), %%mm3         \n\t"
593 62975029 Michael Niedermayer
        "paddw %%mm7, %%mm1                          \n\t"
594
        "paddw %%mm7, %%mm3                          \n\t"
595
        "pavgw %%mm1, %%mm4                          \n\t"
596
        "pavgw %%mm3, %%mm6                          \n\t"
597 25bb359f Michael Niedermayer
        snow_vertical_compose_r2r_sub("mm7","mm7","mm7","mm7","mm0","mm2","mm4","mm6")
598
        snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6")
599 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6")
600 4567b4bd Robert Edele
601 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("2","mm0","mm2","mm4","mm6")
602 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6")
603
        snow_vertical_compose_mmx_store("%3","mm0","mm2","mm4","mm6")
604
        snow_vertical_compose_mmx_add("%1","mm0","mm2","mm4","mm6")
605 4567b4bd Robert Edele
        snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7")
606 25bb359f Michael Niedermayer
        snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6")
607
        snow_vertical_compose_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6")
608 8b502929 Michael Niedermayer
        snow_vertical_compose_mmx_add("%2","mm0","mm2","mm4","mm6")
609
        snow_vertical_compose_mmx_store("%2","mm0","mm2","mm4","mm6")
610 4567b4bd Robert Edele
611
        "2:                                          \n\t"
612 bc1e78d8 Michael Niedermayer
        "sub $32, %%"REG_d"                          \n\t"
613 4567b4bd Robert Edele
        "jge 1b                                      \n\t"
614
        :"+d"(i)
615 8b502929 Michael Niedermayer
        :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5));
616 4567b4bd Robert Edele
}
617 e8600e5e Robert Edele
618
#define snow_inner_add_yblock_sse2_header \
619 3e0f7126 Michael Niedermayer
    IDWTELEM * * dst_array = sb->line + src_y;\
620 ffad4ed1 Luca Barbato
    long tmp;\
621 e8600e5e Robert Edele
    asm volatile(\
622 ffad4ed1 Luca Barbato
             "mov  %7, %%"REG_c"             \n\t"\
623
             "mov  %6, %2                    \n\t"\
624
             "mov  %4, %%"REG_S"             \n\t"\
625 e8600e5e Robert Edele
             "pxor %%xmm7, %%xmm7            \n\t" /* 0 */\
626
             "pcmpeqd %%xmm3, %%xmm3         \n\t"\
627 3e0f7126 Michael Niedermayer
             "psllw $15, %%xmm3              \n\t"\
628
             "psrlw $12, %%xmm3              \n\t" /* FRAC_BITS >> 1 */\
629 e8600e5e Robert Edele
             "1:                             \n\t"\
630
             "mov %1, %%"REG_D"              \n\t"\
631
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
632 ffad4ed1 Luca Barbato
             "add %3, %%"REG_D"              \n\t"
633 e8600e5e Robert Edele
634
#define snow_inner_add_yblock_sse2_start_8(out_reg1, out_reg2, ptr_offset, s_offset)\
635
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
636
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
637
             "movq (%%"REG_d", %%"REG_c"), %%"out_reg2" \n\t"\
638
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
639
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
640
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
641
             "movq "s_offset"+16(%%"REG_S"), %%xmm4 \n\t"\
642
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
643
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
644
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
645
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
646
647
#define snow_inner_add_yblock_sse2_start_16(out_reg1, out_reg2, ptr_offset, s_offset)\
648
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
649
             "movq (%%"REG_d"), %%"out_reg1" \n\t"\
650
             "movq 8(%%"REG_d"), %%"out_reg2" \n\t"\
651
             "punpcklbw %%xmm7, %%"out_reg1" \n\t"\
652
             "punpcklbw %%xmm7, %%"out_reg2" \n\t"\
653
             "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\
654
             "movq "s_offset"+8(%%"REG_S"), %%xmm4 \n\t"\
655
             "punpcklbw %%xmm7, %%xmm0       \n\t"\
656
             "punpcklbw %%xmm7, %%xmm4       \n\t"\
657
             "pmullw %%xmm0, %%"out_reg1"    \n\t"\
658
             "pmullw %%xmm4, %%"out_reg2"    \n\t"
659
660
#define snow_inner_add_yblock_sse2_accum_8(ptr_offset, s_offset) \
661
             snow_inner_add_yblock_sse2_start_8("xmm2", "xmm6", ptr_offset, s_offset)\
662
             "paddusw %%xmm2, %%xmm1         \n\t"\
663
             "paddusw %%xmm6, %%xmm5         \n\t"
664
665
#define snow_inner_add_yblock_sse2_accum_16(ptr_offset, s_offset) \
666
             snow_inner_add_yblock_sse2_start_16("xmm2", "xmm6", ptr_offset, s_offset)\
667
             "paddusw %%xmm2, %%xmm1         \n\t"\
668
             "paddusw %%xmm6, %%xmm5         \n\t"
669
670
#define snow_inner_add_yblock_sse2_end_common1\
671
             "add $32, %%"REG_S"             \n\t"\
672
             "add %%"REG_c", %0              \n\t"\
673
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
674
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
675
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
676
             "add %%"REG_c", (%%"REG_a")     \n\t"
677
678
#define snow_inner_add_yblock_sse2_end_common2\
679
             "jnz 1b                         \n\t"\
680 ffad4ed1 Luca Barbato
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
681 e8600e5e Robert Edele
             :\
682 3e0f7126 Michael Niedermayer
             "rm"((long)(src_x<<1)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
683 ffad4ed1 Luca Barbato
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
684 e8600e5e Robert Edele
685
#define snow_inner_add_yblock_sse2_end_8\
686
             "sal $1, %%"REG_c"              \n\t"\
687
             "add $"PTR_SIZE"*2, %1          \n\t"\
688
             snow_inner_add_yblock_sse2_end_common1\
689
             "sar $1, %%"REG_c"              \n\t"\
690 ffad4ed1 Luca Barbato
             "sub $2, %2                     \n\t"\
691 e8600e5e Robert Edele
             snow_inner_add_yblock_sse2_end_common2
692
693
#define snow_inner_add_yblock_sse2_end_16\
694
             "add $"PTR_SIZE"*1, %1          \n\t"\
695
             snow_inner_add_yblock_sse2_end_common1\
696 ffad4ed1 Luca Barbato
             "dec %2                         \n\t"\
697 e8600e5e Robert Edele
             snow_inner_add_yblock_sse2_end_common2
698
699 9dd6c804 Panagiotis Issaris
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,
700 e8600e5e Robert Edele
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
701
snow_inner_add_yblock_sse2_header
702
snow_inner_add_yblock_sse2_start_8("xmm1", "xmm5", "3", "0")
703
snow_inner_add_yblock_sse2_accum_8("2", "8")
704
snow_inner_add_yblock_sse2_accum_8("1", "128")
705
snow_inner_add_yblock_sse2_accum_8("0", "136")
706
707
             "mov %0, %%"REG_d"              \n\t"
708
             "movdqa (%%"REG_D"), %%xmm0     \n\t"
709
             "movdqa %%xmm1, %%xmm2          \n\t"
710
711
             "punpckhwd %%xmm7, %%xmm1       \n\t"
712
             "punpcklwd %%xmm7, %%xmm2       \n\t"
713
             "paddd %%xmm2, %%xmm0           \n\t"
714
             "movdqa 16(%%"REG_D"), %%xmm2   \n\t"
715
             "paddd %%xmm1, %%xmm2           \n\t"
716
             "paddd %%xmm3, %%xmm0           \n\t"
717
             "paddd %%xmm3, %%xmm2           \n\t"
718
719
             "mov %1, %%"REG_D"              \n\t"
720
             "mov "PTR_SIZE"(%%"REG_D"), %%"REG_D";\n\t"
721 ffad4ed1 Luca Barbato
             "add %3, %%"REG_D"              \n\t"
722 e8600e5e Robert Edele
723
             "movdqa (%%"REG_D"), %%xmm4     \n\t"
724
             "movdqa %%xmm5, %%xmm6          \n\t"
725
             "punpckhwd %%xmm7, %%xmm5       \n\t"
726
             "punpcklwd %%xmm7, %%xmm6       \n\t"
727
             "paddd %%xmm6, %%xmm4           \n\t"
728
             "movdqa 16(%%"REG_D"), %%xmm6   \n\t"
729
             "paddd %%xmm5, %%xmm6           \n\t"
730
             "paddd %%xmm3, %%xmm4           \n\t"
731
             "paddd %%xmm3, %%xmm6           \n\t"
732
733
             "psrad $8, %%xmm0               \n\t" /* FRAC_BITS. */
734
             "psrad $8, %%xmm2               \n\t" /* FRAC_BITS. */
735
             "packssdw %%xmm2, %%xmm0        \n\t"
736
             "packuswb %%xmm7, %%xmm0        \n\t"
737
             "movq %%xmm0, (%%"REG_d")       \n\t"
738
739
             "psrad $8, %%xmm4               \n\t" /* FRAC_BITS. */
740
             "psrad $8, %%xmm6               \n\t" /* FRAC_BITS. */
741
             "packssdw %%xmm6, %%xmm4        \n\t"
742
             "packuswb %%xmm7, %%xmm4        \n\t"
743
             "movq %%xmm4, (%%"REG_d",%%"REG_c");\n\t"
744
snow_inner_add_yblock_sse2_end_8
745
}
746
747 9dd6c804 Panagiotis Issaris
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,
748 e8600e5e Robert Edele
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
749
snow_inner_add_yblock_sse2_header
750
snow_inner_add_yblock_sse2_start_16("xmm1", "xmm5", "3", "0")
751
snow_inner_add_yblock_sse2_accum_16("2", "16")
752
snow_inner_add_yblock_sse2_accum_16("1", "512")
753
snow_inner_add_yblock_sse2_accum_16("0", "528")
754
755
             "mov %0, %%"REG_d"              \n\t"
756 3e0f7126 Michael Niedermayer
             "psrlw $4, %%xmm1               \n\t"
757
             "psrlw $4, %%xmm5               \n\t"
758
             "paddw   (%%"REG_D"), %%xmm1    \n\t"
759
             "paddw 16(%%"REG_D"), %%xmm5    \n\t"
760
             "paddw %%xmm3, %%xmm1           \n\t"
761
             "paddw %%xmm3, %%xmm5           \n\t"
762
             "psraw $4, %%xmm1               \n\t" /* FRAC_BITS. */
763
             "psraw $4, %%xmm5               \n\t" /* FRAC_BITS. */
764
             "packuswb %%xmm5, %%xmm1        \n\t"
765
766
             "movdqu %%xmm1, (%%"REG_d")       \n\t"
767 e8600e5e Robert Edele
768
snow_inner_add_yblock_sse2_end_16
769
}
770
771
#define snow_inner_add_yblock_mmx_header \
772 3e0f7126 Michael Niedermayer
    IDWTELEM * * dst_array = sb->line + src_y;\
773 ffad4ed1 Luca Barbato
    long tmp;\
774 e8600e5e Robert Edele
    asm volatile(\
775 ffad4ed1 Luca Barbato
             "mov  %7, %%"REG_c"             \n\t"\
776
             "mov  %6, %2                    \n\t"\
777
             "mov  %4, %%"REG_S"             \n\t"\
778 e8600e5e Robert Edele
             "pxor %%mm7, %%mm7              \n\t" /* 0 */\
779
             "pcmpeqd %%mm3, %%mm3           \n\t"\
780 3e0f7126 Michael Niedermayer
             "psllw $15, %%mm3               \n\t"\
781
             "psrlw $12, %%mm3               \n\t" /* FRAC_BITS >> 1 */\
782 e8600e5e Robert Edele
             "1:                             \n\t"\
783
             "mov %1, %%"REG_D"              \n\t"\
784
             "mov (%%"REG_D"), %%"REG_D"     \n\t"\
785 ffad4ed1 Luca Barbato
             "add %3, %%"REG_D"              \n\t"
786 e8600e5e Robert Edele
787
#define snow_inner_add_yblock_mmx_start(out_reg1, out_reg2, ptr_offset, s_offset, d_offset)\
788
             "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\
789
             "movd "d_offset"(%%"REG_d"), %%"out_reg1" \n\t"\
790
             "movd "d_offset"+4(%%"REG_d"), %%"out_reg2" \n\t"\
791
             "punpcklbw %%mm7, %%"out_reg1" \n\t"\
792
             "punpcklbw %%mm7, %%"out_reg2" \n\t"\
793
             "movd "s_offset"(%%"REG_S"), %%mm0 \n\t"\
794
             "movd "s_offset"+4(%%"REG_S"), %%mm4 \n\t"\
795
             "punpcklbw %%mm7, %%mm0       \n\t"\
796
             "punpcklbw %%mm7, %%mm4       \n\t"\
797
             "pmullw %%mm0, %%"out_reg1"    \n\t"\
798
             "pmullw %%mm4, %%"out_reg2"    \n\t"
799
800
#define snow_inner_add_yblock_mmx_accum(ptr_offset, s_offset, d_offset) \
801
             snow_inner_add_yblock_mmx_start("mm2", "mm6", ptr_offset, s_offset, d_offset)\
802
             "paddusw %%mm2, %%mm1         \n\t"\
803
             "paddusw %%mm6, %%mm5         \n\t"
804
805
#define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\
806
             "mov %0, %%"REG_d"              \n\t"\
807 3e0f7126 Michael Niedermayer
             "psrlw $4, %%mm1                \n\t"\
808
             "psrlw $4, %%mm5                \n\t"\
809
             "paddw "read_offset"(%%"REG_D"), %%mm1 \n\t"\
810
             "paddw "read_offset"+8(%%"REG_D"), %%mm5 \n\t"\
811
             "paddw %%mm3, %%mm1             \n\t"\
812
             "paddw %%mm3, %%mm5             \n\t"\
813
             "psraw $4, %%mm1                \n\t"\
814
             "psraw $4, %%mm5                \n\t"\
815
             "packuswb %%mm5, %%mm1          \n\t"\
816
             "movq %%mm1, "write_offset"(%%"REG_d") \n\t"
817 e8600e5e Robert Edele
818
#define snow_inner_add_yblock_mmx_end(s_step)\
819
             "add $"s_step", %%"REG_S"             \n\t"\
820
             "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\
821
             "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\
822
             "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\
823
             "add %%"REG_c", (%%"REG_a")     \n\t"\
824
             "add $"PTR_SIZE"*1, %1          \n\t"\
825
             "add %%"REG_c", %0              \n\t"\
826 ffad4ed1 Luca Barbato
             "dec %2                         \n\t"\
827 e8600e5e Robert Edele
             "jnz 1b                         \n\t"\
828 ffad4ed1 Luca Barbato
             :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\
829 e8600e5e Robert Edele
             :\
830 3e0f7126 Michael Niedermayer
             "rm"((long)(src_x<<1)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\
831 ffad4ed1 Luca Barbato
             "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d"");
832 e8600e5e Robert Edele
833 9dd6c804 Panagiotis Issaris
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,
834 e8600e5e Robert Edele
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
835
snow_inner_add_yblock_mmx_header
836
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
837
snow_inner_add_yblock_mmx_accum("2", "8", "0")
838
snow_inner_add_yblock_mmx_accum("1", "128", "0")
839
snow_inner_add_yblock_mmx_accum("0", "136", "0")
840
snow_inner_add_yblock_mmx_mix("0", "0")
841
snow_inner_add_yblock_mmx_end("16")
842
}
843
844 9dd6c804 Panagiotis Issaris
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,
845 e8600e5e Robert Edele
                      int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){
846
snow_inner_add_yblock_mmx_header
847
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0")
848
snow_inner_add_yblock_mmx_accum("2", "16", "0")
849
snow_inner_add_yblock_mmx_accum("1", "512", "0")
850
snow_inner_add_yblock_mmx_accum("0", "528", "0")
851
snow_inner_add_yblock_mmx_mix("0", "0")
852
853
snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8")
854
snow_inner_add_yblock_mmx_accum("2", "24", "8")
855
snow_inner_add_yblock_mmx_accum("1", "520", "8")
856
snow_inner_add_yblock_mmx_accum("0", "536", "8")
857 3e0f7126 Michael Niedermayer
snow_inner_add_yblock_mmx_mix("16", "8")
858 e8600e5e Robert Edele
snow_inner_add_yblock_mmx_end("32")
859
}
860
861 9dd6c804 Panagiotis Issaris
void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
862 e8600e5e Robert Edele
                           int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
863
864
    if (b_w == 16)
865
        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);
866
    else if (b_w == 8 && obmc_stride == 16) {
867
        if (!(b_h & 1))
868
            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);
869
        else
870
            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);
871
    } else
872
         ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
873
}
874
875 9dd6c804 Panagiotis Issaris
void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
876 e8600e5e Robert Edele
                          int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){
877
    if (b_w == 16)
878
        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);
879
    else if (b_w == 8 && obmc_stride == 16)
880
        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);
881
    else
882
        ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
883
}