Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libmpcodecs / vf_fspp.c
blob6df261fb709650d905ba09196dd894a3fefd0435
1 /*
2 Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
3 Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * This implementation is based on an algorithm described in
22 * "Aria Nosratinia Embedded Post-Processing for
23 * Enhancement of Compressed Images (1999)"
24 * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
25 * Futher, with splitting (i)dct into hor/ver passes, one of them can be
26 * performed once per block, not pixel. This allows for much better speed.
30 Heavily optimized version of SPP filter by Nikolaj
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <inttypes.h>
37 #include <math.h>
39 #include "config.h"
41 #include "mp_msg.h"
42 #include "cpudetect.h"
44 #include "libavutil/intreadwrite.h"
45 #include "libavcodec/avcodec.h"
46 #include "libavcodec/dsputil.h"
48 #ifdef HAVE_MALLOC_H
49 #include <malloc.h>
50 #endif
52 #include "img_format.h"
53 #include "mp_image.h"
54 #include "vf.h"
55 #include "libvo/fastmemcpy.h"
57 //===========================================================================//
58 #define BLOCKSZ 12
60 static const short custom_threshold[64]=
61 // values (296) can't be too high
62 // -it causes too big quant dependence
63 // or maybe overflow(check), which results in some flashing
64 { 71, 296, 295, 237, 71, 40, 38, 19,
65 245, 193, 185, 121, 102, 73, 53, 27,
66 158, 129, 141, 107, 97, 73, 50, 26,
67 102, 116, 109, 98, 82, 66, 45, 23,
68 71, 94, 95, 81, 70, 56, 38, 20,
69 56, 77, 74, 66, 56, 44, 30, 15,
70 38, 53, 50, 45, 38, 30, 21, 11,
71 20, 27, 26, 23, 20, 15, 11, 5
74 static const uint8_t __attribute__((aligned(32))) dither[8][8]={
75 { 0, 48, 12, 60, 3, 51, 15, 63, },
76 { 32, 16, 44, 28, 35, 19, 47, 31, },
77 { 8, 56, 4, 52, 11, 59, 7, 55, },
78 { 40, 24, 36, 20, 43, 27, 39, 23, },
79 { 2, 50, 14, 62, 1, 49, 13, 61, },
80 { 34, 18, 46, 30, 33, 17, 45, 29, },
81 { 10, 58, 6, 54, 9, 57, 5, 53, },
82 { 42, 26, 38, 22, 41, 25, 37, 21, },
85 struct vf_priv_s { //align 16 !
86 uint64_t threshold_mtx_noq[8*2];
87 uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions
89 int log2_count;
90 int temp_stride;
91 int qp;
92 int mpeg2;
93 int prev_q;
94 uint8_t *src;
95 int16_t *temp;
96 int bframes;
97 char *non_b_qp;
101 #ifndef HAVE_MMX
103 //This func reads from 1 slice, 1 and clears 0 & 1
104 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
105 {int y, x;
106 #define STORE(pos) \
107 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
108 src[x + pos]=src[x + pos - 8*src_stride]=0; \
109 if(temp & 0x100) temp= ~(temp>>31); \
110 dst[x + pos]= temp;
112 for(y=0; y<height; y++){
113 const uint8_t *d= dither[y];
114 for(x=0; x<width; x+=8){
115 int temp;
116 STORE(0);
117 STORE(1);
118 STORE(2);
119 STORE(3);
120 STORE(4);
121 STORE(5);
122 STORE(6);
123 STORE(7);
125 src+=src_stride;
126 dst+=dst_stride;
130 //This func reads from 2 slices, 0 & 2 and clears 2-nd
131 static void store_slice2_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
132 {int y, x;
133 #define STORE2(pos) \
134 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
135 src[x + pos + 16*src_stride]=0; \
136 if(temp & 0x100) temp= ~(temp>>31); \
137 dst[x + pos]= temp;
139 for(y=0; y<height; y++){
140 const uint8_t *d= dither[y];
141 for(x=0; x<width; x+=8){
142 int temp;
143 STORE2(0);
144 STORE2(1);
145 STORE2(2);
146 STORE2(3);
147 STORE2(4);
148 STORE2(5);
149 STORE2(6);
150 STORE2(7);
152 src+=src_stride;
153 dst+=dst_stride;
157 static void mul_thrmat_c(struct vf_priv_s *p,int q)
159 int a;
160 for(a=0;a<64;a++)
161 ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
164 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
165 static void row_idct_c(DCTELEM* workspace,
166 int16_t* output_adr, int output_stride, int cnt);
167 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
169 //this is rather ugly, but there is no need for function pointers
170 #define store_slice_s store_slice_c
171 #define store_slice2_s store_slice2_c
172 #define mul_thrmat_s mul_thrmat_c
173 #define column_fidct_s column_fidct_c
174 #define row_idct_s row_idct_c
175 #define row_fdct_s row_fdct_c
177 #else /* HAVE_MMX */
179 //This func reads from 1 slice, 1 and clears 0 & 1
180 static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
182 const uint8_t *od=&dither[0][0];
183 const uint8_t *end=&dither[height][0];
184 width = (width+7)&~7;
185 dst_stride-=width;
186 //src_stride=(src_stride-width)*2;
187 asm volatile(
188 "mov %5, %%"REG_d" \n\t"
189 "mov %6, %%"REG_S" \n\t"
190 "mov %7, %%"REG_D" \n\t"
191 "mov %1, %%"REG_a" \n\t"
192 "movd %%"REG_d", %%mm5 \n\t"
193 "xor $-1, %%"REG_d" \n\t"
194 "mov %%"REG_a", %%"REG_c" \n\t"
195 "add $7, %%"REG_d" \n\t"
196 "neg %%"REG_a" \n\t"
197 "sub %0, %%"REG_c" \n\t"
198 "add %%"REG_c", %%"REG_c" \n\t"
199 "movd %%"REG_d", %%mm2 \n\t"
200 "mov %%"REG_c", %1 \n\t"
201 "mov %2, %%"REG_d" \n\t"
202 "shl $4, %%"REG_a" \n\t"
204 "2: \n\t"
205 "movq (%%"REG_d"), %%mm3 \n\t"
206 "movq %%mm3, %%mm4 \n\t"
207 "pxor %%mm7, %%mm7 \n\t"
208 "punpcklbw %%mm7, %%mm3 \n\t"
209 "punpckhbw %%mm7, %%mm4 \n\t"
210 "mov %0, %%"REG_c" \n\t"
211 "psraw %%mm5, %%mm3 \n\t"
212 "psraw %%mm5, %%mm4 \n\t"
213 "1: \n\t"
214 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
215 "movq (%%"REG_S"), %%mm0 \n\t"
216 "movq 8(%%"REG_S"), %%mm1 \n\t"
218 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
219 "paddw %%mm3, %%mm0 \n\t"
220 "paddw %%mm4, %%mm1 \n\t"
222 "movq %%mm7, (%%"REG_S") \n\t"
223 "psraw %%mm2, %%mm0 \n\t"
224 "psraw %%mm2, %%mm1 \n\t"
226 "movq %%mm7, 8(%%"REG_S") \n\t"
227 "packuswb %%mm1, %%mm0 \n\t"
228 "add $16, %%"REG_S" \n\t"
230 "movq %%mm0, (%%"REG_D") \n\t"
231 "add $8, %%"REG_D" \n\t"
232 "sub $8, %%"REG_c" \n\t"
233 "jg 1b \n\t"
234 "add %1, %%"REG_S" \n\t"
235 "add $8, %%"REG_d" \n\t"
236 "add %3, %%"REG_D" \n\t"
237 "cmp %4, %%"REG_d" \n\t"
238 "jl 2b \n\t"
241 : "m" (width), "m" (src_stride), "g" (od), "m" (dst_stride), "g" (end),
242 "m" (log2_scale), "m" (src), "m" (dst) //input
243 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
247 //This func reads from 2 slices, 0 & 2 and clears 2-nd
248 static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
250 const uint8_t *od=&dither[0][0];
251 const uint8_t *end=&dither[height][0];
252 width = (width+7)&~7;
253 dst_stride-=width;
254 //src_stride=(src_stride-width)*2;
255 asm volatile(
256 "mov %5, %%"REG_d" \n\t"
257 "mov %6, %%"REG_S" \n\t"
258 "mov %7, %%"REG_D" \n\t"
259 "mov %1, %%"REG_a" \n\t"
260 "movd %%"REG_d", %%mm5 \n\t"
261 "xor $-1, %%"REG_d" \n\t"
262 "mov %%"REG_a", %%"REG_c" \n\t"
263 "add $7, %%"REG_d" \n\t"
264 "sub %0, %%"REG_c" \n\t"
265 "add %%"REG_c", %%"REG_c" \n\t"
266 "movd %%"REG_d", %%mm2 \n\t"
267 "mov %%"REG_c", %1 \n\t"
268 "mov %2, %%"REG_d" \n\t"
269 "shl $5, %%"REG_a" \n\t"
271 "2: \n\t"
272 "movq (%%"REG_d"), %%mm3 \n\t"
273 "movq %%mm3, %%mm4 \n\t"
274 "pxor %%mm7, %%mm7 \n\t"
275 "punpcklbw %%mm7, %%mm3 \n\t"
276 "punpckhbw %%mm7, %%mm4 \n\t"
277 "mov %0, %%"REG_c" \n\t"
278 "psraw %%mm5, %%mm3 \n\t"
279 "psraw %%mm5, %%mm4 \n\t"
280 "1: \n\t"
281 "movq (%%"REG_S"), %%mm0 \n\t"
282 "movq 8(%%"REG_S"), %%mm1 \n\t"
283 "paddw %%mm3, %%mm0 \n\t"
285 "paddw (%%"REG_S",%%"REG_a",), %%mm0 \n\t"
286 "paddw %%mm4, %%mm1 \n\t"
287 "movq 8(%%"REG_S",%%"REG_a",), %%mm6 \n\t"
289 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
290 "psraw %%mm2, %%mm0 \n\t"
291 "paddw %%mm6, %%mm1 \n\t"
293 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
294 "psraw %%mm2, %%mm1 \n\t"
295 "packuswb %%mm1, %%mm0 \n\t"
297 "movq %%mm0, (%%"REG_D") \n\t"
298 "add $16, %%"REG_S" \n\t"
299 "add $8, %%"REG_D" \n\t"
300 "sub $8, %%"REG_c" \n\t"
301 "jg 1b \n\t"
302 "add %1, %%"REG_S" \n\t"
303 "add $8, %%"REG_d" \n\t"
304 "add %3, %%"REG_D" \n\t"
305 "cmp %4, %%"REG_d" \n\t"
306 "jl 2b \n\t"
309 : "m" (width), "m" (src_stride), "g" (od), "m" (dst_stride), "g" (end),
310 "m" (log2_scale), "m" (src), "m" (dst) //input
311 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S
315 static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
317 uint64_t *adr=&p->threshold_mtx_noq[0];
318 asm volatile(
319 "movd %0, %%mm7 \n\t"
320 "add $8*8*2, %%"REG_D" \n\t"
321 "movq 0*8(%%"REG_S"), %%mm0 \n\t"
322 "punpcklwd %%mm7, %%mm7 \n\t"
323 "movq 1*8(%%"REG_S"), %%mm1 \n\t"
324 "punpckldq %%mm7, %%mm7 \n\t"
325 "pmullw %%mm7, %%mm0 \n\t"
327 "movq 2*8(%%"REG_S"), %%mm2 \n\t"
328 "pmullw %%mm7, %%mm1 \n\t"
330 "movq 3*8(%%"REG_S"), %%mm3 \n\t"
331 "pmullw %%mm7, %%mm2 \n\t"
333 "movq %%mm0, 0*8(%%"REG_D") \n\t"
334 "movq 4*8(%%"REG_S"), %%mm4 \n\t"
335 "pmullw %%mm7, %%mm3 \n\t"
337 "movq %%mm1, 1*8(%%"REG_D") \n\t"
338 "movq 5*8(%%"REG_S"), %%mm5 \n\t"
339 "pmullw %%mm7, %%mm4 \n\t"
341 "movq %%mm2, 2*8(%%"REG_D") \n\t"
342 "movq 6*8(%%"REG_S"), %%mm6 \n\t"
343 "pmullw %%mm7, %%mm5 \n\t"
345 "movq %%mm3, 3*8(%%"REG_D") \n\t"
346 "movq 7*8+0*8(%%"REG_S"), %%mm0 \n\t"
347 "pmullw %%mm7, %%mm6 \n\t"
349 "movq %%mm4, 4*8(%%"REG_D") \n\t"
350 "movq 7*8+1*8(%%"REG_S"), %%mm1 \n\t"
351 "pmullw %%mm7, %%mm0 \n\t"
353 "movq %%mm5, 5*8(%%"REG_D") \n\t"
354 "movq 7*8+2*8(%%"REG_S"), %%mm2 \n\t"
355 "pmullw %%mm7, %%mm1 \n\t"
357 "movq %%mm6, 6*8(%%"REG_D") \n\t"
358 "movq 7*8+3*8(%%"REG_S"), %%mm3 \n\t"
359 "pmullw %%mm7, %%mm2 \n\t"
361 "movq %%mm0, 7*8+0*8(%%"REG_D") \n\t"
362 "movq 7*8+4*8(%%"REG_S"), %%mm4 \n\t"
363 "pmullw %%mm7, %%mm3 \n\t"
365 "movq %%mm1, 7*8+1*8(%%"REG_D") \n\t"
366 "movq 7*8+5*8(%%"REG_S"), %%mm5 \n\t"
367 "pmullw %%mm7, %%mm4 \n\t"
369 "movq %%mm2, 7*8+2*8(%%"REG_D") \n\t"
370 "movq 7*8+6*8(%%"REG_S"), %%mm6 \n\t"
371 "pmullw %%mm7, %%mm5 \n\t"
373 "movq %%mm3, 7*8+3*8(%%"REG_D") \n\t"
374 "movq 14*8+0*8(%%"REG_S"), %%mm0 \n\t"
375 "pmullw %%mm7, %%mm6 \n\t"
377 "movq %%mm4, 7*8+4*8(%%"REG_D") \n\t"
378 "movq 14*8+1*8(%%"REG_S"), %%mm1 \n\t"
379 "pmullw %%mm7, %%mm0 \n\t"
381 "movq %%mm5, 7*8+5*8(%%"REG_D") \n\t"
382 "pmullw %%mm7, %%mm1 \n\t"
384 "movq %%mm6, 7*8+6*8(%%"REG_D") \n\t"
385 "movq %%mm0, 14*8+0*8(%%"REG_D") \n\t"
386 "movq %%mm1, 14*8+1*8(%%"REG_D") \n\t"
388 : "+g" (q), "+S" (adr), "+D" (adr)
393 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
394 static void row_idct_mmx(DCTELEM* workspace,
395 int16_t* output_adr, int output_stride, int cnt);
396 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
398 #define store_slice_s store_slice_mmx
399 #define store_slice2_s store_slice2_mmx
400 #define mul_thrmat_s mul_thrmat_mmx
401 #define column_fidct_s column_fidct_mmx
402 #define row_idct_s row_idct_mmx
403 #define row_fdct_s row_fdct_mmx
404 #endif // HAVE_MMX
406 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
407 int dst_stride, int src_stride,
408 int width, int height,
409 uint8_t *qp_store, int qp_stride, int is_luma)
411 int x, x0, y, es, qy, t;
412 const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15))
413 const int step=6-p->log2_count;
414 const int qps= 3 + is_luma;
415 int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
416 DCTELEM *block= (DCTELEM *)block_align;
417 DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ);
419 memset(block3, 0, 4*8*BLOCKSZ);
421 //p->src=src-src_stride*8-8;//!
422 if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
423 for(y=0; y<height; y++){
424 int index= 8 + 8*stride + y*stride;
425 fast_memcpy(p->src + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers
426 for(x=0; x<8; x++){
427 p->src[index - x - 1]= p->src[index + x ];
428 p->src[index + width + x ]= p->src[index + width - x - 1];
431 for(y=0; y<8; y++){
432 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
433 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
435 //FIXME (try edge emu)
437 for(y=8; y<24; y++)
438 memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t));
440 for(y=step; y<height+8; y+=step){ //step= 1,2
441 qy=y-4;
442 if (qy>height-1) qy=height-1;
443 if (qy<0) qy=0;
444 qy=(qy>>qps)*qp_stride;
445 row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2);
446 for(x0=0; x0<width+8-8*(BLOCKSZ-1); x0+=8*(BLOCKSZ-1)){
447 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1));
448 if(p->qp)
449 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT
450 else
451 for (x=0; x<8*(BLOCKSZ-1); x+=8) {
452 t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same
453 if (t<0) t=0;//t always < width-2
454 t=qp_store[qy+(t>>qps)];
455 if(p->mpeg2) t>>=1; //copy p->mpeg2,prev_q to locals?
456 if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t);
457 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
459 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
460 memcpy(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
461 memcpy(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM));
464 es=width+8-x0; // 8, ...
465 if (es>8)
466 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2);
467 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1));
468 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2);
469 {const int y1=y-8+step;//l5-7 l4-6
470 if (!(y1&7) && y1) {
471 if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride,
472 dst_stride, stride, width, 8, 5-p->log2_count);
473 else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride,
474 dst_stride, stride, width, 8, 5-p->log2_count);
478 if (y&7) { // == height & 7
479 if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride,
480 dst_stride, stride, width, y&7, 5-p->log2_count);
481 else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride,
482 dst_stride, stride, width, y&7, 5-p->log2_count);
486 static int config(struct vf_instance_s* vf,
487 int width, int height, int d_width, int d_height,
488 unsigned int flags, unsigned int outfmt)
490 int h= (height+16+15)&(~15);
492 vf->priv->temp_stride= (width+16+15)&(~15);
493 vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t));
494 //this can also be avoided, see above
495 vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
497 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
500 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
502 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
503 // ok, we can do pp in-place (or pp disabled):
504 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
505 mpi->type, mpi->flags, mpi->width, mpi->height);
506 mpi->planes[0]=vf->dmpi->planes[0];
507 mpi->stride[0]=vf->dmpi->stride[0];
508 mpi->width=vf->dmpi->width;
509 if(mpi->flags&MP_IMGFLAG_PLANAR){
510 mpi->planes[1]=vf->dmpi->planes[1];
511 mpi->planes[2]=vf->dmpi->planes[2];
512 mpi->stride[1]=vf->dmpi->stride[1];
513 mpi->stride[2]=vf->dmpi->stride[2];
515 mpi->flags|=MP_IMGFLAG_DIRECT;
518 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
520 mp_image_t *dmpi;
521 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
522 // no DR, so get a new image! hope we'll get DR buffer:
523 dmpi=vf_get_image(vf->next,mpi->imgfmt,
524 MP_IMGTYPE_TEMP,
525 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
526 mpi->width,mpi->height);
527 vf_clone_mpi_attributes(dmpi, mpi);
528 }else{
529 dmpi=vf->dmpi;
532 vf->priv->mpeg2= mpi->qscale_type;
533 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
534 if(!vf->priv->non_b_qp)
535 vf->priv->non_b_qp= malloc(mpi->qstride * ((mpi->h + 15) >> 4));
536 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, mpi->qstride * ((mpi->h + 15) >> 4));
538 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
539 char *qp_tab= vf->priv->non_b_qp;
540 if(vf->priv->bframes || !qp_tab)
541 qp_tab= mpi->qscale;
543 if(qp_tab || vf->priv->qp){
544 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
545 mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
546 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
547 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
548 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
549 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
550 }else{
551 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
552 memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
553 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
557 #ifdef HAVE_MMX
558 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
559 #endif
560 #ifdef HAVE_MMX2
561 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
562 #endif
563 return vf_next_put_image(vf,dmpi, pts);
566 static void uninit(struct vf_instance_s* vf)
568 if(!vf->priv) return;
570 if(vf->priv->temp) av_free(vf->priv->temp);
571 vf->priv->temp= NULL;
572 if(vf->priv->src) av_free(vf->priv->src);
573 vf->priv->src= NULL;
574 //if(vf->priv->avctx) free(vf->priv->avctx);
575 //vf->priv->avctx= NULL;
576 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp);
577 vf->priv->non_b_qp= NULL;
579 av_free(vf->priv);
580 vf->priv=NULL;
583 //===========================================================================//
585 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
587 switch(fmt){
588 case IMGFMT_YVU9:
589 case IMGFMT_IF09:
590 case IMGFMT_YV12:
591 case IMGFMT_I420:
592 case IMGFMT_IYUV:
593 case IMGFMT_CLPL:
594 case IMGFMT_Y800:
595 case IMGFMT_Y8:
596 case IMGFMT_444P:
597 case IMGFMT_422P:
598 case IMGFMT_411P:
599 return vf_next_query_format(vf,fmt);
601 return 0;
604 static int control(struct vf_instance_s* vf, int request, void* data)
606 switch(request){
607 case VFCTRL_QUERY_MAX_PP_LEVEL:
608 return 5;
609 case VFCTRL_SET_PP_LEVEL:
610 vf->priv->log2_count= *((unsigned int*)data);
611 if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
612 return CONTROL_TRUE;
614 return vf_next_control(vf,request,data);
617 static int open(vf_instance_t *vf, char* args)
619 int i=0, bias;
620 int custom_threshold_m[64];
621 int log2c=-1;
623 vf->config=config;
624 vf->put_image=put_image;
625 vf->get_image=get_image;
626 vf->query_format=query_format;
627 vf->uninit=uninit;
628 vf->control= control;
629 vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
631 avcodec_init();
633 //vf->priv->avctx= avcodec_alloc_context();
634 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
636 vf->priv->log2_count= 4;
637 vf->priv->bframes = 0;
639 if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
641 if( log2c >=4 && log2c <=5 )
642 vf->priv->log2_count = log2c;
643 else if( log2c >= 6 )
644 vf->priv->log2_count = 5;
646 if(vf->priv->qp < 0)
647 vf->priv->qp = 0;
649 if (i < -15) i = -15;
650 if (i > 32) i = 32;
652 bias= (1<<4)+i; //regulable
653 vf->priv->prev_q=0;
655 for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
656 custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
657 for(i=0;i<8;i++){
658 vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
659 |(((uint64_t)custom_threshold_m[i*8+6])<<16)
660 |(((uint64_t)custom_threshold_m[i*8+0])<<32)
661 |(((uint64_t)custom_threshold_m[i*8+4])<<48);
662 vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
663 |(((uint64_t)custom_threshold_m[i*8+3])<<16)
664 |(((uint64_t)custom_threshold_m[i*8+1])<<32)
665 |(((uint64_t)custom_threshold_m[i*8+7])<<48);
668 if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
670 return 1;
673 const vf_info_t vf_info_fspp = {
674 "fast simple postprocess",
675 "fspp",
676 "Michael Niedermayer, Nikolaj Poroshin",
678 open,
679 NULL
682 //====================================================================
683 //Specific spp's dct, idct and threshold functions
684 //I'd prefer to have them in the separate file.
686 #include "mangle.h"
687 //#define MANGLE(a) #a
689 //typedef int16_t DCTELEM; //! only int16_t
691 #define DCTSIZE 8
692 #define DCTSIZE_S "8"
694 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
695 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
696 #define FIX64(x,s) C64(FIX(x,s))
698 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
699 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
700 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
702 #ifdef HAVE_MMX
704 static uint64_t attribute_used __attribute__((aligned(8))) temps[4];//!!
706 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_382683433=FIX64(0.382683433, 14);
707 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_541196100=FIX64(0.541196100, 14);
708 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_707106781=FIX64(0.707106781, 14);
709 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_1_306562965=FIX64(1.306562965, 14);
711 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_1_414213562_A=FIX64(1.414213562, 14);
713 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_1_847759065=FIX64(1.847759065, 13);
714 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_2_613125930=FIX64(-2.613125930, 13); //-
715 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_1_414213562=FIX64(1.414213562, 13);
716 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_1_082392200=FIX64(1.082392200, 13);
717 //for t3,t5,t7 == 0 shortcut
718 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_847759065=FIX64(0.847759065, 14);
719 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_566454497=FIX64(0.566454497, 14);
720 static uint64_t attribute_used __attribute__((aligned(8))) MM_FIX_0_198912367=FIX64(0.198912367, 14);
722 static uint64_t attribute_used __attribute__((aligned(8))) MM_DESCALE_RND=C64(4);
723 static uint64_t attribute_used __attribute__((aligned(8))) MM_2=C64(2);
725 #else /* !HAVE_MMX */
727 typedef int32_t int_simd16_t;
728 static int16_t FIX_0_382683433=FIX(0.382683433, 14);
729 static int16_t FIX_0_541196100=FIX(0.541196100, 14);
730 static int16_t FIX_0_707106781=FIX(0.707106781, 14);
731 static int16_t FIX_1_306562965=FIX(1.306562965, 14);
732 static int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
733 static int16_t FIX_1_847759065=FIX(1.847759065, 13);
734 static int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
735 static int16_t FIX_1_414213562=FIX(1.414213562, 13);
736 static int16_t FIX_1_082392200=FIX(1.082392200, 13);
738 #endif
740 #ifndef HAVE_MMX
742 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
744 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
745 int_simd16_t tmp10, tmp11, tmp12, tmp13;
746 int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
747 int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
749 DCTELEM* dataptr;
750 DCTELEM* wsptr;
751 int16_t *threshold;
752 int ctr;
754 dataptr = data;
755 wsptr = output;
757 for (; cnt > 0; cnt-=2) { //start positions
758 threshold=(int16_t*)thr_adr;//threshold_mtx
759 for (ctr = DCTSIZE; ctr > 0; ctr--) {
760 // Process columns from input, add to output.
761 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
762 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
764 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
765 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
767 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
768 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
770 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
771 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
773 // Even part of FDCT
775 tmp10 = tmp0 + tmp3;
776 tmp13 = tmp0 - tmp3;
777 tmp11 = tmp1 + tmp2;
778 tmp12 = tmp1 - tmp2;
780 d0 = tmp10 + tmp11;
781 d4 = tmp10 - tmp11;
783 z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
784 d2 = tmp13 + z1;
785 d6 = tmp13 - z1;
787 // Even part of IDCT
789 THRESHOLD(tmp0, d0, threshold[0*8]);
790 THRESHOLD(tmp1, d2, threshold[2*8]);
791 THRESHOLD(tmp2, d4, threshold[4*8]);
792 THRESHOLD(tmp3, d6, threshold[6*8]);
793 tmp0+=2;
794 tmp10 = (tmp0 + tmp2)>>2;
795 tmp11 = (tmp0 - tmp2)>>2;
797 tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
798 tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
800 tmp0 = tmp10 + tmp13; //->temps
801 tmp3 = tmp10 - tmp13; //->temps
802 tmp1 = tmp11 + tmp12; //->temps
803 tmp2 = tmp11 - tmp12; //->temps
805 // Odd part of FDCT
807 tmp10 = tmp4 + tmp5;
808 tmp11 = tmp5 + tmp6;
809 tmp12 = tmp6 + tmp7;
811 z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
812 z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
813 z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
814 z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
816 z11 = tmp7 + z3;
817 z13 = tmp7 - z3;
819 d5 = z13 + z2;
820 d3 = z13 - z2;
821 d1 = z11 + z4;
822 d7 = z11 - z4;
824 // Odd part of IDCT
826 THRESHOLD(tmp4, d1, threshold[1*8]);
827 THRESHOLD(tmp5, d3, threshold[3*8]);
828 THRESHOLD(tmp6, d5, threshold[5*8]);
829 THRESHOLD(tmp7, d7, threshold[7*8]);
831 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
832 z13 = tmp6 + tmp5;
833 z10 = (tmp6 - tmp5)<<1;
834 z11 = tmp4 + tmp7;
835 z12 = (tmp4 - tmp7)<<1;
837 tmp7 = (z11 + z13)>>2; //+2 !
838 tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
839 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
840 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
841 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
843 tmp6 = tmp12 - tmp7;
844 tmp5 = tmp11 - tmp6;
845 tmp4 = tmp10 + tmp5;
847 wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
848 wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
849 wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
850 wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
851 wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
852 wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
853 wsptr[DCTSIZE*6]= (tmp1 - tmp6);
854 wsptr[DCTSIZE*7]= (tmp0 - tmp7);
856 dataptr++; //next column
857 wsptr++;
858 threshold++;
860 dataptr+=8; //skip each second start pos
861 wsptr +=8;
865 #else /* HAVE_MMX */
867 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
869 asm volatile(
870 ASMALIGN(4)
871 "1: \n\t"
872 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
874 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
875 "movq %%mm1, %%mm0 \n\t"
877 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
878 "movq %%mm7, %%mm3 \n\t"
880 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
881 "movq %%mm1, %%mm5 \n\t"
883 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
884 "psubw %%mm7, %%mm1 \n\t" //t13
886 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
887 "movq %%mm6, %%mm4 \n\t"
889 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
890 "paddw %%mm7, %%mm5 \n\t" //t10
892 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
893 "movq %%mm6, %%mm7 \n\t"
895 "paddw %%mm2, %%mm6 \n\t" //t11
896 "psubw %%mm2, %%mm7 \n\t" //t12
898 "movq %%mm5, %%mm2 \n\t"
899 "paddw %%mm6, %%mm5 \n\t" //d0
900 // i0 t13 t12 i3 i1 d0 - d4
901 "psubw %%mm6, %%mm2 \n\t" //d4
902 "paddw %%mm1, %%mm7 \n\t"
904 "movq 4*16(%%"REG_d"), %%mm6 \n\t"
905 "psllw $2, %%mm7 \n\t"
907 "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
908 "psubw %%mm6, %%mm2 \n\t"
910 "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
911 "paddusw %%mm6, %%mm2 \n\t"
913 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
915 "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
916 "paddw %%mm6, %%mm2 \n\t"
918 "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
919 "psubusw %%mm6, %%mm2 \n\t"
921 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
922 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
923 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
924 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
925 "movq %%mm2, %%mm6 \n\t"
927 "paddw %%mm5, %%mm2 \n\t"
928 "psubw %%mm6, %%mm5 \n\t"
930 "movq %%mm1, %%mm6 \n\t"
931 "paddw %%mm7, %%mm1 \n\t" //d2
933 "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
934 "psubw %%mm7, %%mm6 \n\t" //d6
936 "movq 6*16(%%"REG_d"), %%mm7 \n\t"
937 "psraw $2, %%mm5 \n\t"
939 "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
940 "psubw %%mm7, %%mm6 \n\t"
941 // t7 d2 /t11 t4 t6 - d6 /t10
943 "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
944 "paddusw %%mm7, %%mm6 \n\t"
946 "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
947 "paddw %%mm7, %%mm6 \n\t"
949 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
950 "psubusw %%mm7, %%mm6 \n\t"
952 //movq [edi+"DCTSIZE_S"*2*2], mm1
953 //movq [edi+"DCTSIZE_S"*6*2], mm6
954 "movq %%mm1, %%mm7 \n\t"
955 "psraw $2, %%mm2 \n\t"
957 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
958 "psubw %%mm6, %%mm1 \n\t"
960 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
961 "paddw %%mm7, %%mm6 \n\t" //'t13
963 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
964 "movq %%mm2, %%mm7 \n\t"
966 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
967 "paddw %%mm6, %%mm2 \n\t" //'t0
969 "movq %%mm2, "MANGLE(temps)"+0*8 \n\t" //!
970 "psubw %%mm6, %%mm7 \n\t" //'t3
972 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
973 "psubw %%mm6, %%mm1 \n\t" //'t12
975 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
976 "movq %%mm5, %%mm6 \n\t"
978 "movq %%mm7, "MANGLE(temps)"+3*8 \n\t"
979 "paddw %%mm2, %%mm3 \n\t" //t10
981 "paddw %%mm4, %%mm2 \n\t" //t11
982 "paddw %%mm0, %%mm4 \n\t" //t12
984 "movq %%mm3, %%mm7 \n\t"
985 "psubw %%mm4, %%mm3 \n\t"
987 "psllw $2, %%mm3 \n\t"
988 "psllw $2, %%mm7 \n\t" //opt for P6
990 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
991 "psllw $2, %%mm4 \n\t"
993 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
994 "psllw $2, %%mm2 \n\t"
996 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
997 "paddw %%mm1, %%mm5 \n\t" //'t1
999 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1000 "psubw %%mm1, %%mm6 \n\t" //'t2
1001 // t7 't12 't11 t4 t6 - 't13 't10 ---
1003 "paddw %%mm3, %%mm7 \n\t" //z2
1005 "movq %%mm5, "MANGLE(temps)"+1*8 \n\t"
1006 "paddw %%mm3, %%mm4 \n\t" //z4
1008 "movq 3*16(%%"REG_d"), %%mm3 \n\t"
1009 "movq %%mm0, %%mm1 \n\t"
1011 "movq %%mm6, "MANGLE(temps)"+2*8 \n\t"
1012 "psubw %%mm2, %%mm1 \n\t" //z13
1014 //===
1015 "paddw %%mm2, %%mm0 \n\t" //z11
1016 "movq %%mm1, %%mm5 \n\t"
1018 "movq 5*16(%%"REG_d"), %%mm2 \n\t"
1019 "psubw %%mm7, %%mm1 \n\t" //d3
1021 "paddw %%mm7, %%mm5 \n\t" //d5
1022 "psubw %%mm3, %%mm1 \n\t"
1024 "movq 1*16(%%"REG_d"), %%mm7 \n\t"
1025 "psubw %%mm2, %%mm5 \n\t"
1027 "movq %%mm0, %%mm6 \n\t"
1028 "paddw %%mm4, %%mm0 \n\t" //d1
1030 "paddusw %%mm3, %%mm1 \n\t"
1031 "psubw %%mm4, %%mm6 \n\t" //d7
1033 // d1 d3 - - - d5 d7 -
1034 "movq 7*16(%%"REG_d"), %%mm4 \n\t"
1035 "psubw %%mm7, %%mm0 \n\t"
1037 "psubw %%mm4, %%mm6 \n\t"
1038 "paddusw %%mm2, %%mm5 \n\t"
1040 "paddusw %%mm4, %%mm6 \n\t"
1041 "paddw %%mm3, %%mm1 \n\t"
1043 "paddw %%mm2, %%mm5 \n\t"
1044 "paddw %%mm4, %%mm6 \n\t"
1046 "psubusw %%mm3, %%mm1 \n\t"
1047 "psubusw %%mm2, %%mm5 \n\t"
1049 "psubusw %%mm4, %%mm6 \n\t"
1050 "movq %%mm1, %%mm4 \n\t"
1052 "por %%mm5, %%mm4 \n\t"
1053 "paddusw %%mm7, %%mm0 \n\t"
1055 "por %%mm6, %%mm4 \n\t"
1056 "paddw %%mm7, %%mm0 \n\t"
1058 "packssdw %%mm4, %%mm4 \n\t"
1059 "psubusw %%mm7, %%mm0 \n\t"
1061 "movd %%mm4, %%"REG_a" \n\t"
1062 "or %%"REG_a", %%"REG_a" \n\t"
1063 "jnz 2f \n\t"
1064 //movq [edi+"DCTSIZE_S"*3*2], mm1
1065 //movq [edi+"DCTSIZE_S"*5*2], mm5
1066 //movq [edi+"DCTSIZE_S"*1*2], mm0
1067 //movq [edi+"DCTSIZE_S"*7*2], mm6
1068 // t4 t5 - - - t6 t7 -
1069 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1070 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1071 "movq "MANGLE(temps)"+0*8, %%mm4 \n\t"
1072 "movq %%mm0, %%mm1 \n\t"
1074 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1075 "movq %%mm1, %%mm2 \n\t"
1077 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1078 "movq %%mm2, %%mm3 \n\t"
1080 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1081 "paddw %%mm4, %%mm5 \n\t"
1083 "movq "MANGLE(temps)"+1*8, %%mm6 \n\t"
1084 //paddw mm3, MM_2
1085 "psraw $2, %%mm3 \n\t" //tmp7
1087 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1088 "psubw %%mm3, %%mm4 \n\t"
1090 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1091 "paddw %%mm3, %%mm5 \n\t"
1093 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1094 "paddw %%mm6, %%mm7 \n\t"
1096 "movq "MANGLE(temps)"+2*8, %%mm3 \n\t"
1097 "psubw %%mm0, %%mm6 \n\t"
1099 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1100 "paddw %%mm0, %%mm7 \n\t"
1102 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1103 "paddw %%mm3, %%mm4 \n\t"
1105 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1106 "psubw %%mm1, %%mm3 \n\t"
1108 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1109 "paddw %%mm1, %%mm4 \n\t"
1111 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1112 "paddw %%mm3, %%mm5 \n\t"
1114 "movq "MANGLE(temps)"+3*8, %%mm0 \n\t"
1115 "add $8, %%"REG_S" \n\t"
1117 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1118 "paddw %%mm0, %%mm6 \n\t"
1120 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1121 "psubw %%mm2, %%mm0 \n\t"
1123 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1124 "paddw %%mm2, %%mm6 \n\t"
1126 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1127 "paddw %%mm0, %%mm7 \n\t"
1129 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1131 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1132 "add $8, %%"REG_D" \n\t"
1133 "jmp 4f \n\t"
1135 "2: \n\t"
1136 //--- non DC2
1137 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1138 //psraw mm5, 2
1139 //psraw mm0, 2
1140 //psraw mm6, 2
1141 "movq %%mm5, %%mm3 \n\t"
1142 "psubw %%mm1, %%mm5 \n\t"
1144 "psllw $1, %%mm5 \n\t" //'z10
1145 "paddw %%mm1, %%mm3 \n\t" //'z13
1147 "movq %%mm0, %%mm2 \n\t"
1148 "psubw %%mm6, %%mm0 \n\t"
1150 "movq %%mm5, %%mm1 \n\t"
1151 "psllw $1, %%mm0 \n\t" //'z12
1153 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1154 "paddw %%mm0, %%mm5 \n\t"
1156 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1157 "paddw %%mm6, %%mm2 \n\t" //'z11
1159 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1160 "movq %%mm2, %%mm7 \n\t"
1162 //---
1163 "movq "MANGLE(temps)"+0*8, %%mm4 \n\t"
1164 "psubw %%mm3, %%mm2 \n\t"
1166 "psllw $1, %%mm2 \n\t"
1167 "paddw %%mm3, %%mm7 \n\t" //'t7
1169 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1170 "movq %%mm4, %%mm6 \n\t"
1171 //paddw mm7, MM_2
1172 "psraw $2, %%mm7 \n\t"
1174 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1175 "psubw %%mm7, %%mm6 \n\t"
1177 "movq "MANGLE(temps)"+1*8, %%mm3 \n\t"
1178 "paddw %%mm7, %%mm4 \n\t"
1180 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1181 "paddw %%mm5, %%mm1 \n\t" //'t12
1183 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1184 "psubw %%mm7, %%mm1 \n\t" //'t6
1186 "movq "MANGLE(temps)"+2*8, %%mm7 \n\t"
1187 "psubw %%mm5, %%mm0 \n\t" //'t10
1189 "movq "MANGLE(temps)"+3*8, %%mm6 \n\t"
1190 "movq %%mm3, %%mm5 \n\t"
1192 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1193 "psubw %%mm1, %%mm5 \n\t"
1195 "psubw %%mm1, %%mm2 \n\t" //'t5
1196 "paddw %%mm1, %%mm3 \n\t"
1198 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1199 "movq %%mm7, %%mm4 \n\t"
1201 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1202 "psubw %%mm2, %%mm4 \n\t"
1204 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1205 "paddw %%mm2, %%mm7 \n\t"
1207 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1208 "paddw %%mm2, %%mm0 \n\t" //'t4
1210 // 't4 't6 't5 - - - - 't7
1211 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1212 "movq %%mm6, %%mm1 \n\t"
1214 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1215 "psubw %%mm0, %%mm1 \n\t"
1217 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1218 "paddw %%mm0, %%mm6 \n\t"
1220 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1221 "add $8, %%"REG_S" \n\t"
1223 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1225 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1226 "add $8, %%"REG_D" \n\t"
1228 "4: \n\t"
1229 //=part 2 (the same)===========================================================
1230 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
1232 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
1233 "movq %%mm1, %%mm0 \n\t"
1235 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
1236 "movq %%mm7, %%mm3 \n\t"
1238 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
1239 "movq %%mm1, %%mm5 \n\t"
1241 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
1242 "psubw %%mm7, %%mm1 \n\t" //t13
1244 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1245 "movq %%mm6, %%mm4 \n\t"
1247 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
1248 "paddw %%mm7, %%mm5 \n\t" //t10
1250 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
1251 "movq %%mm6, %%mm7 \n\t"
1253 "paddw %%mm2, %%mm6 \n\t" //t11
1254 "psubw %%mm2, %%mm7 \n\t" //t12
1256 "movq %%mm5, %%mm2 \n\t"
1257 "paddw %%mm6, %%mm5 \n\t" //d0
1258 // i0 t13 t12 i3 i1 d0 - d4
1259 "psubw %%mm6, %%mm2 \n\t" //d4
1260 "paddw %%mm1, %%mm7 \n\t"
1262 "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
1263 "psllw $2, %%mm7 \n\t"
1265 "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1266 "psubw %%mm6, %%mm2 \n\t"
1268 "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1269 "paddusw %%mm6, %%mm2 \n\t"
1271 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
1273 "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1274 "paddw %%mm6, %%mm2 \n\t"
1276 "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1277 "psubusw %%mm6, %%mm2 \n\t"
1279 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1280 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1281 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1282 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
1283 "movq %%mm2, %%mm6 \n\t"
1285 "paddw %%mm5, %%mm2 \n\t"
1286 "psubw %%mm6, %%mm5 \n\t"
1288 "movq %%mm1, %%mm6 \n\t"
1289 "paddw %%mm7, %%mm1 \n\t" //d2
1291 "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1292 "psubw %%mm7, %%mm6 \n\t" //d6
1294 "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
1295 "psraw $2, %%mm5 \n\t"
1297 "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1298 "psubw %%mm7, %%mm6 \n\t"
1299 // t7 d2 /t11 t4 t6 - d6 /t10
1301 "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1302 "paddusw %%mm7, %%mm6 \n\t"
1304 "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1305 "paddw %%mm7, %%mm6 \n\t"
1307 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
1308 "psubusw %%mm7, %%mm6 \n\t"
1310 //movq [edi+"DCTSIZE_S"*2*2], mm1
1311 //movq [edi+"DCTSIZE_S"*6*2], mm6
1312 "movq %%mm1, %%mm7 \n\t"
1313 "psraw $2, %%mm2 \n\t"
1315 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
1316 "psubw %%mm6, %%mm1 \n\t"
1318 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
1319 "paddw %%mm7, %%mm6 \n\t" //'t13
1321 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1322 "movq %%mm2, %%mm7 \n\t"
1324 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
1325 "paddw %%mm6, %%mm2 \n\t" //'t0
1327 "movq %%mm2, "MANGLE(temps)"+0*8 \n\t" //!
1328 "psubw %%mm6, %%mm7 \n\t" //'t3
1330 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1331 "psubw %%mm6, %%mm1 \n\t" //'t12
1333 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
1334 "movq %%mm5, %%mm6 \n\t"
1336 "movq %%mm7, "MANGLE(temps)"+3*8 \n\t"
1337 "paddw %%mm2, %%mm3 \n\t" //t10
1339 "paddw %%mm4, %%mm2 \n\t" //t11
1340 "paddw %%mm0, %%mm4 \n\t" //t12
1342 "movq %%mm3, %%mm7 \n\t"
1343 "psubw %%mm4, %%mm3 \n\t"
1345 "psllw $2, %%mm3 \n\t"
1346 "psllw $2, %%mm7 \n\t" //opt for P6
1348 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
1349 "psllw $2, %%mm4 \n\t"
1351 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1352 "psllw $2, %%mm2 \n\t"
1354 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1355 "paddw %%mm1, %%mm5 \n\t" //'t1
1357 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1358 "psubw %%mm1, %%mm6 \n\t" //'t2
1359 // t7 't12 't11 t4 t6 - 't13 't10 ---
1361 "paddw %%mm3, %%mm7 \n\t" //z2
1363 "movq %%mm5, "MANGLE(temps)"+1*8 \n\t"
1364 "paddw %%mm3, %%mm4 \n\t" //z4
1366 "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
1367 "movq %%mm0, %%mm1 \n\t"
1369 "movq %%mm6, "MANGLE(temps)"+2*8 \n\t"
1370 "psubw %%mm2, %%mm1 \n\t" //z13
1372 //===
1373 "paddw %%mm2, %%mm0 \n\t" //z11
1374 "movq %%mm1, %%mm5 \n\t"
1376 "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
1377 "psubw %%mm7, %%mm1 \n\t" //d3
1379 "paddw %%mm7, %%mm5 \n\t" //d5
1380 "psubw %%mm3, %%mm1 \n\t"
1382 "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
1383 "psubw %%mm2, %%mm5 \n\t"
1385 "movq %%mm0, %%mm6 \n\t"
1386 "paddw %%mm4, %%mm0 \n\t" //d1
1388 "paddusw %%mm3, %%mm1 \n\t"
1389 "psubw %%mm4, %%mm6 \n\t" //d7
1391 // d1 d3 - - - d5 d7 -
1392 "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
1393 "psubw %%mm7, %%mm0 \n\t"
1395 "psubw %%mm4, %%mm6 \n\t"
1396 "paddusw %%mm2, %%mm5 \n\t"
1398 "paddusw %%mm4, %%mm6 \n\t"
1399 "paddw %%mm3, %%mm1 \n\t"
1401 "paddw %%mm2, %%mm5 \n\t"
1402 "paddw %%mm4, %%mm6 \n\t"
1404 "psubusw %%mm3, %%mm1 \n\t"
1405 "psubusw %%mm2, %%mm5 \n\t"
1407 "psubusw %%mm4, %%mm6 \n\t"
1408 "movq %%mm1, %%mm4 \n\t"
1410 "por %%mm5, %%mm4 \n\t"
1411 "paddusw %%mm7, %%mm0 \n\t"
1413 "por %%mm6, %%mm4 \n\t"
1414 "paddw %%mm7, %%mm0 \n\t"
1416 "packssdw %%mm4, %%mm4 \n\t"
1417 "psubusw %%mm7, %%mm0 \n\t"
1419 "movd %%mm4, %%"REG_a" \n\t"
1420 "or %%"REG_a", %%"REG_a" \n\t"
1421 "jnz 3f \n\t"
1422 //movq [edi+"DCTSIZE_S"*3*2], mm1
1423 //movq [edi+"DCTSIZE_S"*5*2], mm5
1424 //movq [edi+"DCTSIZE_S"*1*2], mm0
1425 //movq [edi+"DCTSIZE_S"*7*2], mm6
1426 // t4 t5 - - - t6 t7 -
1427 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1428 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1429 "movq "MANGLE(temps)"+0*8, %%mm4 \n\t"
1430 "movq %%mm0, %%mm1 \n\t"
1432 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1433 "movq %%mm1, %%mm2 \n\t"
1435 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1436 "movq %%mm2, %%mm3 \n\t"
1438 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1439 "paddw %%mm4, %%mm5 \n\t"
1441 "movq "MANGLE(temps)"+1*8, %%mm6 \n\t"
1442 //paddw mm3, MM_2
1443 "psraw $2, %%mm3 \n\t" //tmp7
1445 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1446 "psubw %%mm3, %%mm4 \n\t"
1448 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1449 "paddw %%mm3, %%mm5 \n\t"
1451 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1452 "paddw %%mm6, %%mm7 \n\t"
1454 "movq "MANGLE(temps)"+2*8, %%mm3 \n\t"
1455 "psubw %%mm0, %%mm6 \n\t"
1457 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1458 "paddw %%mm0, %%mm7 \n\t"
1460 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1461 "paddw %%mm3, %%mm4 \n\t"
1463 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1464 "psubw %%mm1, %%mm3 \n\t"
1466 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1467 "paddw %%mm1, %%mm4 \n\t"
1469 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1470 "paddw %%mm3, %%mm5 \n\t"
1472 "movq "MANGLE(temps)"+3*8, %%mm0 \n\t"
1473 "add $24, %%"REG_S" \n\t"
1475 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1476 "paddw %%mm0, %%mm6 \n\t"
1478 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1479 "psubw %%mm2, %%mm0 \n\t"
1481 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1482 "paddw %%mm2, %%mm6 \n\t"
1484 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1485 "paddw %%mm0, %%mm7 \n\t"
1487 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1489 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1490 "add $24, %%"REG_D" \n\t"
1491 "sub $2, %%"REG_c" \n\t"
1492 "jnz 1b \n\t"
1493 "jmp 5f \n\t"
1495 "3: \n\t"
1496 //--- non DC2
1497 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1498 //psraw mm5, 2
1499 //psraw mm0, 2
1500 //psraw mm6, 2
1501 "movq %%mm5, %%mm3 \n\t"
1502 "psubw %%mm1, %%mm5 \n\t"
1504 "psllw $1, %%mm5 \n\t" //'z10
1505 "paddw %%mm1, %%mm3 \n\t" //'z13
1507 "movq %%mm0, %%mm2 \n\t"
1508 "psubw %%mm6, %%mm0 \n\t"
1510 "movq %%mm5, %%mm1 \n\t"
1511 "psllw $1, %%mm0 \n\t" //'z12
1513 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1514 "paddw %%mm0, %%mm5 \n\t"
1516 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1517 "paddw %%mm6, %%mm2 \n\t" //'z11
1519 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1520 "movq %%mm2, %%mm7 \n\t"
1522 //---
1523 "movq "MANGLE(temps)"+0*8, %%mm4 \n\t"
1524 "psubw %%mm3, %%mm2 \n\t"
1526 "psllw $1, %%mm2 \n\t"
1527 "paddw %%mm3, %%mm7 \n\t" //'t7
1529 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1530 "movq %%mm4, %%mm6 \n\t"
1531 //paddw mm7, MM_2
1532 "psraw $2, %%mm7 \n\t"
1534 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1535 "psubw %%mm7, %%mm6 \n\t"
1537 "movq "MANGLE(temps)"+1*8, %%mm3 \n\t"
1538 "paddw %%mm7, %%mm4 \n\t"
1540 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1541 "paddw %%mm5, %%mm1 \n\t" //'t12
1543 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1544 "psubw %%mm7, %%mm1 \n\t" //'t6
1546 "movq "MANGLE(temps)"+2*8, %%mm7 \n\t"
1547 "psubw %%mm5, %%mm0 \n\t" //'t10
1549 "movq "MANGLE(temps)"+3*8, %%mm6 \n\t"
1550 "movq %%mm3, %%mm5 \n\t"
1552 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1553 "psubw %%mm1, %%mm5 \n\t"
1555 "psubw %%mm1, %%mm2 \n\t" //'t5
1556 "paddw %%mm1, %%mm3 \n\t"
1558 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1559 "movq %%mm7, %%mm4 \n\t"
1561 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1562 "psubw %%mm2, %%mm4 \n\t"
1564 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1565 "paddw %%mm2, %%mm7 \n\t"
1567 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1568 "paddw %%mm2, %%mm0 \n\t" //'t4
1570 // 't4 't6 't5 - - - - 't7
1571 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1572 "movq %%mm6, %%mm1 \n\t"
1574 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1575 "psubw %%mm0, %%mm1 \n\t"
1577 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1578 "paddw %%mm0, %%mm6 \n\t"
1580 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1581 "add $24, %%"REG_S" \n\t"
1583 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1585 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1586 "add $24, %%"REG_D" \n\t"
1587 "sub $2, %%"REG_c" \n\t"
1588 "jnz 1b \n\t"
1589 "5: \n\t"
1591 : "+S"(data), "+D"(output), "+c"(cnt)// input regs
1592 : "d"(thr_adr)
1593 : "%"REG_a
1597 #endif // HAVE_MMX
1599 #ifndef HAVE_MMX
1601 static void row_idct_c(DCTELEM* workspace,
1602 int16_t* output_adr, int output_stride, int cnt)
1604 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1605 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1606 int_simd16_t z5, z10, z11, z12, z13;
1607 int16_t* outptr;
1608 DCTELEM* wsptr;
1610 cnt*=4;
1611 wsptr = workspace;
1612 outptr = output_adr;
1613 for (; cnt > 0; cnt--) {
1614 // Even part
1615 //Simd version reads 4x4 block and transposes it
1616 tmp10 = ( wsptr[2] + wsptr[3]);
1617 tmp11 = ( wsptr[2] - wsptr[3]);
1619 tmp13 = ( wsptr[0] + wsptr[1]);
1620 tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
1622 tmp0 = tmp10 + tmp13; //->temps
1623 tmp3 = tmp10 - tmp13; //->temps
1624 tmp1 = tmp11 + tmp12;
1625 tmp2 = tmp11 - tmp12;
1627 // Odd part
1628 //Also transpose, with previous:
1629 // ---- ---- ||||
1630 // ---- ---- idct ||||
1631 // ---- ---- ---> ||||
1632 // ---- ---- ||||
1633 z13 = wsptr[4] + wsptr[5];
1634 z10 = wsptr[4] - wsptr[5];
1635 z11 = wsptr[6] + wsptr[7];
1636 z12 = wsptr[6] - wsptr[7];
1638 tmp7 = z11 + z13;
1639 tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
1641 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
1642 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
1643 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
1645 tmp6 = (tmp12<<3) - tmp7;
1646 tmp5 = (tmp11<<3) - tmp6;
1647 tmp4 = (tmp10<<3) + tmp5;
1649 // Final output stage: descale and write column
1650 outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
1651 outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
1652 outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
1653 outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
1654 outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
1655 outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
1656 outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
1657 outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
1658 outptr++;
1660 wsptr += DCTSIZE; // advance pointer to next row
1664 #else /* HAVE_MMX */
1666 static void row_idct_mmx (DCTELEM* workspace,
1667 int16_t* output_adr, int output_stride, int cnt)
1669 asm volatile(
1670 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1671 "1: \n\t"
1672 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
1675 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
1676 "movq %%mm0, %%mm4 \n\t"
1678 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1679 "punpcklwd %%mm1, %%mm0 \n\t"
1681 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
1682 "punpckhwd %%mm1, %%mm4 \n\t"
1684 //transpose 4x4
1685 "movq %%mm2, %%mm7 \n\t"
1686 "punpcklwd %%mm3, %%mm2 \n\t"
1688 "movq %%mm0, %%mm6 \n\t"
1689 "punpckldq %%mm2, %%mm0 \n\t" //0
1691 "punpckhdq %%mm2, %%mm6 \n\t" //1
1692 "movq %%mm0, %%mm5 \n\t"
1694 "punpckhwd %%mm3, %%mm7 \n\t"
1695 "psubw %%mm6, %%mm0 \n\t"
1697 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
1698 "movq %%mm4, %%mm2 \n\t"
1700 "punpckldq %%mm7, %%mm4 \n\t" //2
1701 "paddw %%mm6, %%mm5 \n\t"
1703 "punpckhdq %%mm7, %%mm2 \n\t" //3
1704 "movq %%mm4, %%mm1 \n\t"
1706 "psllw $2, %%mm0 \n\t"
1707 "paddw %%mm2, %%mm4 \n\t" //t10
1709 "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
1710 "psubw %%mm2, %%mm1 \n\t" //t11
1712 "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
1713 "psubw %%mm5, %%mm0 \n\t"
1715 "movq %%mm4, %%mm6 \n\t"
1716 "paddw %%mm5, %%mm4 \n\t" //t0
1718 "psubw %%mm5, %%mm6 \n\t" //t3
1719 "movq %%mm1, %%mm7 \n\t"
1721 "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
1722 "paddw %%mm0, %%mm1 \n\t" //t1
1724 "movq %%mm4, "MANGLE(temps)"+0*8 \n\t" //t0
1725 "movq %%mm3, %%mm4 \n\t"
1727 "movq %%mm6, "MANGLE(temps)"+1*8 \n\t" //t3
1728 "punpcklwd %%mm2, %%mm3 \n\t"
1730 //transpose 4x4
1731 "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
1732 "punpckhwd %%mm2, %%mm4 \n\t"
1734 "movq %%mm5, %%mm2 \n\t"
1735 "punpcklwd %%mm6, %%mm5 \n\t"
1737 "psubw %%mm0, %%mm7 \n\t" //t2
1738 "punpckhwd %%mm6, %%mm2 \n\t"
1740 "movq %%mm3, %%mm0 \n\t"
1741 "punpckldq %%mm5, %%mm3 \n\t" //4
1743 "punpckhdq %%mm5, %%mm0 \n\t" //5
1744 "movq %%mm4, %%mm5 \n\t"
1747 "movq %%mm3, %%mm6 \n\t"
1748 "punpckldq %%mm2, %%mm4 \n\t" //6
1750 "psubw %%mm0, %%mm3 \n\t" //z10
1751 "punpckhdq %%mm2, %%mm5 \n\t" //7
1753 "paddw %%mm0, %%mm6 \n\t" //z13
1754 "movq %%mm4, %%mm2 \n\t"
1756 "movq %%mm3, %%mm0 \n\t"
1757 "psubw %%mm5, %%mm4 \n\t" //z12
1759 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
1760 "paddw %%mm4, %%mm3 \n\t"
1762 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
1763 "paddw %%mm5, %%mm2 \n\t" //z11 >
1765 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
1766 "movq %%mm2, %%mm5 \n\t"
1768 "psubw %%mm6, %%mm2 \n\t"
1769 "paddw %%mm6, %%mm5 \n\t" //t7
1771 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
1772 "paddw %%mm3, %%mm0 \n\t" //t12
1774 "psllw $3, %%mm0 \n\t"
1775 "psubw %%mm3, %%mm4 \n\t" //t10
1777 "movq "MANGLE(temps)"+0*8, %%mm6 \n\t"
1778 "movq %%mm1, %%mm3 \n\t"
1780 "psllw $3, %%mm4 \n\t"
1781 "psubw %%mm5, %%mm0 \n\t" //t6
1783 "psllw $3, %%mm2 \n\t"
1784 "paddw %%mm0, %%mm1 \n\t" //d1
1786 "psubw %%mm0, %%mm2 \n\t" //t5
1787 "psubw %%mm0, %%mm3 \n\t" //d6
1789 "paddw %%mm2, %%mm4 \n\t" //t4
1790 "movq %%mm7, %%mm0 \n\t"
1792 "paddw %%mm2, %%mm7 \n\t" //d2
1793 "psubw %%mm2, %%mm0 \n\t" //d5
1795 "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
1796 "psubw %%mm5, %%mm6 \n\t" //d7
1798 "paddw "MANGLE(temps)"+0*8, %%mm5 \n\t" //d0
1799 "paddw %%mm2, %%mm1 \n\t"
1801 "paddw %%mm2, %%mm5 \n\t"
1802 "psraw $3, %%mm1 \n\t"
1804 "paddw %%mm2, %%mm7 \n\t"
1805 "psraw $3, %%mm5 \n\t"
1807 "paddw (%%"REG_D"), %%mm5 \n\t"
1808 "psraw $3, %%mm7 \n\t"
1810 "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
1811 "paddw %%mm2, %%mm0 \n\t"
1813 "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
1814 "paddw %%mm2, %%mm3 \n\t"
1816 "movq %%mm5, (%%"REG_D") \n\t"
1817 "paddw %%mm2, %%mm6 \n\t"
1819 "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
1820 "psraw $3, %%mm0 \n\t"
1822 "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
1823 "add %%"REG_d", %%"REG_D" \n\t" //3*ls
1825 "movq "MANGLE(temps)"+1*8, %%mm5 \n\t" //t3
1826 "psraw $3, %%mm3 \n\t"
1828 "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
1829 "psubw %%mm4, %%mm5 \n\t" //d3
1831 "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
1832 "psraw $3, %%mm6 \n\t"
1834 "paddw "MANGLE(temps)"+1*8, %%mm4 \n\t" //d4
1835 "paddw %%mm2, %%mm5 \n\t"
1837 "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
1838 "paddw %%mm2, %%mm4 \n\t"
1840 "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
1841 "psraw $3, %%mm5 \n\t"
1843 "paddw (%%"REG_D"), %%mm5 \n\t"
1844 "psraw $3, %%mm4 \n\t"
1846 "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
1847 "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
1849 "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
1850 "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
1851 "movq %%mm5, (%%"REG_D") \n\t"
1852 "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
1854 "sub %%"REG_d", %%"REG_D" \n\t"
1855 "add $8, %%"REG_D" \n\t"
1856 "dec %%"REG_c" \n\t"
1857 "jnz 1b \n\t"
1859 : "+S"(workspace), "+D"(output_adr), "+c"(cnt) //input regs
1860 : "a"(output_stride*sizeof(short))
1861 : "%"REG_d
1865 #endif // HAVE_MMX
1867 #ifndef HAVE_MMX
1869 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1871 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1872 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1873 int_simd16_t z1, z2, z3, z4, z5, z11, z13;
1874 DCTELEM *dataptr;
1876 cnt*=4;
1877 // Pass 1: process rows.
1879 dataptr = data;
1880 for (; cnt > 0; cnt--) {
1881 tmp0 = pixels[line_size*0] + pixels[line_size*7];
1882 tmp7 = pixels[line_size*0] - pixels[line_size*7];
1883 tmp1 = pixels[line_size*1] + pixels[line_size*6];
1884 tmp6 = pixels[line_size*1] - pixels[line_size*6];
1885 tmp2 = pixels[line_size*2] + pixels[line_size*5];
1886 tmp5 = pixels[line_size*2] - pixels[line_size*5];
1887 tmp3 = pixels[line_size*3] + pixels[line_size*4];
1888 tmp4 = pixels[line_size*3] - pixels[line_size*4];
1890 // Even part
1892 tmp10 = tmp0 + tmp3;
1893 tmp13 = tmp0 - tmp3;
1894 tmp11 = tmp1 + tmp2;
1895 tmp12 = tmp1 - tmp2;
1896 //Even columns are written first, this leads to different order of columns
1897 //in column_fidct(), but they are processed independently, so all ok.
1898 //Later in the row_idct() columns readed at the same order.
1899 dataptr[2] = tmp10 + tmp11;
1900 dataptr[3] = tmp10 - tmp11;
1902 z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
1903 dataptr[0] = tmp13 + z1;
1904 dataptr[1] = tmp13 - z1;
1906 // Odd part
1908 tmp10 = (tmp4 + tmp5) <<2;
1909 tmp11 = (tmp5 + tmp6) <<2;
1910 tmp12 = (tmp6 + tmp7) <<2;
1912 z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
1913 z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
1914 z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
1915 z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
1917 z11 = tmp7 + z3;
1918 z13 = tmp7 - z3;
1920 dataptr[4] = z13 + z2;
1921 dataptr[5] = z13 - z2;
1922 dataptr[6] = z11 + z4;
1923 dataptr[7] = z11 - z4;
1925 pixels++; // advance pointer to next column
1926 dataptr += DCTSIZE;
1930 #else /* HAVE_MMX */
1932 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1934 asm volatile(
1935 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1936 "6: \n\t"
1937 "movd (%%"REG_S"), %%mm0 \n\t"
1938 "pxor %%mm7, %%mm7 \n\t"
1940 "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
1941 "punpcklbw %%mm7, %%mm0 \n\t"
1943 "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
1944 "punpcklbw %%mm7, %%mm1 \n\t"
1946 "punpcklbw %%mm7, %%mm2 \n\t"
1947 "add %%"REG_d", %%"REG_S" \n\t"
1949 "movq %%mm0, %%mm5 \n\t"
1952 "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
1953 "movq %%mm1, %%mm6 \n\t"
1955 "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
1956 "punpcklbw %%mm7, %%mm3 \n\t"
1958 "psubw %%mm3, %%mm5 \n\t"
1959 "punpcklbw %%mm7, %%mm4 \n\t"
1961 "paddw %%mm3, %%mm0 \n\t"
1962 "psubw %%mm4, %%mm6 \n\t"
1964 "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
1965 "paddw %%mm4, %%mm1 \n\t"
1967 "movq %%mm5, "MANGLE(temps)"+0*8 \n\t" //t7
1968 "punpcklbw %%mm7, %%mm3 \n\t"
1970 "movq %%mm6, "MANGLE(temps)"+1*8 \n\t" //t6
1971 "movq %%mm2, %%mm4 \n\t"
1973 "movd (%%"REG_S"), %%mm5 \n\t" //3
1974 "paddw %%mm3, %%mm2 \n\t"
1976 "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
1977 "punpcklbw %%mm7, %%mm5 \n\t"
1979 "psubw %%mm3, %%mm4 \n\t"
1980 "punpcklbw %%mm7, %%mm6 \n\t"
1982 "movq %%mm5, %%mm3 \n\t"
1983 "paddw %%mm6, %%mm5 \n\t" //t3
1985 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1986 "movq %%mm0, %%mm6 \n\t"
1988 "movq %%mm1, %%mm7 \n\t"
1989 "psubw %%mm5, %%mm0 \n\t" //t13
1991 "psubw %%mm2, %%mm1 \n\t"
1992 "paddw %%mm2, %%mm7 \n\t" //t11
1994 "paddw %%mm0, %%mm1 \n\t"
1995 "movq %%mm7, %%mm2 \n\t"
1997 "psllw $2, %%mm1 \n\t"
1998 "paddw %%mm5, %%mm6 \n\t" //t10
2000 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
2001 "paddw %%mm6, %%mm7 \n\t" //d2
2003 "psubw %%mm2, %%mm6 \n\t" //d3
2004 "movq %%mm0, %%mm5 \n\t"
2006 //transpose 4x4
2007 "movq %%mm7, %%mm2 \n\t"
2008 "punpcklwd %%mm6, %%mm7 \n\t"
2010 "paddw %%mm1, %%mm0 \n\t" //d0
2011 "punpckhwd %%mm6, %%mm2 \n\t"
2013 "psubw %%mm1, %%mm5 \n\t" //d1
2014 "movq %%mm0, %%mm6 \n\t"
2016 "movq "MANGLE(temps)"+1*8, %%mm1 \n\t"
2017 "punpcklwd %%mm5, %%mm0 \n\t"
2019 "punpckhwd %%mm5, %%mm6 \n\t"
2020 "movq %%mm0, %%mm5 \n\t"
2022 "punpckldq %%mm7, %%mm0 \n\t" //0
2023 "paddw %%mm4, %%mm3 \n\t"
2025 "punpckhdq %%mm7, %%mm5 \n\t" //1
2026 "movq %%mm6, %%mm7 \n\t"
2028 "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
2029 "punpckldq %%mm2, %%mm6 \n\t" //2
2031 "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
2032 "punpckhdq %%mm2, %%mm7 \n\t" //3
2034 "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
2035 "paddw %%mm1, %%mm4 \n\t"
2037 "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
2038 "psllw $2, %%mm3 \n\t" //t10
2040 "movq "MANGLE(temps)"+0*8, %%mm2 \n\t"
2041 "psllw $2, %%mm4 \n\t" //t11
2043 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
2044 "paddw %%mm2, %%mm1 \n\t"
2046 "psllw $2, %%mm1 \n\t" //t12
2047 "movq %%mm3, %%mm0 \n\t"
2049 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
2050 "psubw %%mm1, %%mm3 \n\t"
2052 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
2053 "movq %%mm2, %%mm5 \n\t"
2055 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
2056 "psubw %%mm4, %%mm2 \n\t" //z13
2058 "paddw %%mm4, %%mm5 \n\t" //z11
2059 "movq %%mm2, %%mm6 \n\t"
2061 "paddw %%mm3, %%mm0 \n\t" //z2
2062 "movq %%mm5, %%mm7 \n\t"
2064 "paddw %%mm0, %%mm2 \n\t" //d4
2065 "psubw %%mm0, %%mm6 \n\t" //d5
2067 "movq %%mm2, %%mm4 \n\t"
2068 "paddw %%mm3, %%mm1 \n\t" //z4
2070 //transpose 4x4
2071 "punpcklwd %%mm6, %%mm2 \n\t"
2072 "paddw %%mm1, %%mm5 \n\t" //d6
2074 "punpckhwd %%mm6, %%mm4 \n\t"
2075 "psubw %%mm1, %%mm7 \n\t" //d7
2077 "movq %%mm5, %%mm6 \n\t"
2078 "punpcklwd %%mm7, %%mm5 \n\t"
2080 "punpckhwd %%mm7, %%mm6 \n\t"
2081 "movq %%mm2, %%mm7 \n\t"
2083 "punpckldq %%mm5, %%mm2 \n\t" //4
2084 "sub %%"REG_d", %%"REG_S" \n\t"
2086 "punpckhdq %%mm5, %%mm7 \n\t" //5
2087 "movq %%mm4, %%mm5 \n\t"
2089 "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2090 "punpckldq %%mm6, %%mm4 \n\t" //6
2092 "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2093 "punpckhdq %%mm6, %%mm5 \n\t" //7
2095 "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2096 "add $4, %%"REG_S" \n\t"
2098 "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2099 "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
2100 "dec %%"REG_c" \n\t"
2101 "jnz 6b \n\t"
2103 : "+S"(pixels), "+D"(data), "+c"(cnt) //input regs
2104 : "a"(line_size)
2105 : "%"REG_d);
2108 #endif // HAVE_MMX