docs: convert manpage contents into reStructuredText markup
[mplayer.git] / libmpcodecs / vf_fspp.c
blobda54892fb1320aa49c17b033817afce31245d9bd
1 /*
2 * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This implementation is based on an algorithm described in
24 * "Aria Nosratinia Embedded Post-Processing for
25 * Enhancement of Compressed Images (1999)"
26 * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
27 * Futher, with splitting (i)dct into hor/ver passes, one of them can be
28 * performed once per block, not pixel. This allows for much better speed.
32 Heavily optimized version of SPP filter by Nikolaj
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <inttypes.h>
39 #include <math.h>
41 #include <libavutil/intreadwrite.h>
42 #include <libavutil/mem.h>
43 #include <libavcodec/avcodec.h>
45 #include "config.h"
47 #include "mp_msg.h"
48 #include "cpudetect.h"
49 #include "img_format.h"
50 #include "mp_image.h"
51 #include "vf.h"
52 #include "libvo/fastmemcpy.h"
53 #include "mangle.h"
55 typedef short DCTELEM;
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 #if !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), "erm" (od), "m" (dst_stride), "erm" (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), "erm" (od), "m" (dst_stride), "erm" (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 t=norm_qscale(t, p->mpeg2);
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 memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
461 memmove(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 *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 *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 *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 int w = mpi->qstride;
535 int h = (mpi->h + 15) >> 4;
536 if (!w) {
537 w = (mpi->w + 15) >> 4;
538 h = 1;
540 if(!vf->priv->non_b_qp)
541 vf->priv->non_b_qp= malloc(w*h);
542 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
544 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
545 char *qp_tab= vf->priv->non_b_qp;
546 if(vf->priv->bframes || !qp_tab)
547 qp_tab= mpi->qscale;
549 if(qp_tab || vf->priv->qp){
550 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
551 mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
552 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
553 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
554 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
555 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
556 }else{
557 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
558 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]);
559 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]);
563 #if HAVE_MMX
564 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
565 #endif
566 #if HAVE_MMX2
567 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
568 #endif
569 return vf_next_put_image(vf,dmpi, pts);
572 static void uninit(struct vf_instance *vf)
574 if(!vf->priv) return;
576 av_free(vf->priv->temp);
577 vf->priv->temp= NULL;
578 av_free(vf->priv->src);
579 vf->priv->src= NULL;
580 //free(vf->priv->avctx);
581 //vf->priv->avctx= NULL;
582 free(vf->priv->non_b_qp);
583 vf->priv->non_b_qp= NULL;
585 av_free(vf->priv);
586 vf->priv=NULL;
589 //===========================================================================//
591 static int query_format(struct vf_instance *vf, unsigned int fmt)
593 switch(fmt){
594 case IMGFMT_YVU9:
595 case IMGFMT_IF09:
596 case IMGFMT_YV12:
597 case IMGFMT_I420:
598 case IMGFMT_IYUV:
599 case IMGFMT_CLPL:
600 case IMGFMT_Y800:
601 case IMGFMT_Y8:
602 case IMGFMT_444P:
603 case IMGFMT_422P:
604 case IMGFMT_411P:
605 return vf_next_query_format(vf,fmt);
607 return 0;
610 static int control(struct vf_instance *vf, int request, void* data)
612 switch(request){
613 case VFCTRL_QUERY_MAX_PP_LEVEL:
614 return 5;
615 case VFCTRL_SET_PP_LEVEL:
616 vf->priv->log2_count= *((unsigned int*)data);
617 if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
618 return CONTROL_TRUE;
620 return vf_next_control(vf,request,data);
623 static int vf_open(vf_instance_t *vf, char *args)
625 int i=0, bias;
626 int custom_threshold_m[64];
627 int log2c=-1;
629 vf->config=config;
630 vf->put_image=put_image;
631 vf->get_image=get_image;
632 vf->query_format=query_format;
633 vf->uninit=uninit;
634 vf->control= control;
635 vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
637 //vf->priv->avctx= avcodec_alloc_context();
638 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
640 vf->priv->log2_count= 4;
641 vf->priv->bframes = 0;
643 if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
645 if( log2c >=4 && log2c <=5 )
646 vf->priv->log2_count = log2c;
647 else if( log2c >= 6 )
648 vf->priv->log2_count = 5;
650 if(vf->priv->qp < 0)
651 vf->priv->qp = 0;
653 if (i < -15) i = -15;
654 if (i > 32) i = 32;
656 bias= (1<<4)+i; //regulable
657 vf->priv->prev_q=0;
659 for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
660 custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
661 for(i=0;i<8;i++){
662 vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
663 |(((uint64_t)custom_threshold_m[i*8+6])<<16)
664 |(((uint64_t)custom_threshold_m[i*8+0])<<32)
665 |(((uint64_t)custom_threshold_m[i*8+4])<<48);
666 vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
667 |(((uint64_t)custom_threshold_m[i*8+3])<<16)
668 |(((uint64_t)custom_threshold_m[i*8+1])<<32)
669 |(((uint64_t)custom_threshold_m[i*8+7])<<48);
672 if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
674 return 1;
677 const vf_info_t vf_info_fspp = {
678 "fast simple postprocess",
679 "fspp",
680 "Michael Niedermayer, Nikolaj Poroshin",
682 vf_open,
683 NULL
686 //====================================================================
687 //Specific spp's dct, idct and threshold functions
688 //I'd prefer to have them in the separate file.
690 //#define MANGLE(a) #a
692 //typedef int16_t DCTELEM; //! only int16_t
694 #define DCTSIZE 8
695 #define DCTSIZE_S "8"
697 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
698 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
699 #define FIX64(x,s) C64(FIX(x,s))
701 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
702 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
703 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
705 #if HAVE_MMX
707 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
708 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14);
709 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14);
710 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
712 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
714 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
715 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
716 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
717 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
718 //for t3,t5,t7 == 0 shortcut
719 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
720 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
721 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
723 DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
724 DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
726 #else /* !HAVE_MMX */
728 typedef int32_t int_simd16_t;
729 static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
730 static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
731 static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
732 static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
733 static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
734 static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
735 static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
736 static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
737 static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
739 #endif
741 #if !HAVE_MMX
743 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
745 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
746 int_simd16_t tmp10, tmp11, tmp12, tmp13;
747 int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
748 int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
750 DCTELEM* dataptr;
751 DCTELEM* wsptr;
752 int16_t *threshold;
753 int ctr;
755 dataptr = data;
756 wsptr = output;
758 for (; cnt > 0; cnt-=2) { //start positions
759 threshold=(int16_t*)thr_adr;//threshold_mtx
760 for (ctr = DCTSIZE; ctr > 0; ctr--) {
761 // Process columns from input, add to output.
762 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
763 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
765 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
766 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
768 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
769 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
771 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
772 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
774 // Even part of FDCT
776 tmp10 = tmp0 + tmp3;
777 tmp13 = tmp0 - tmp3;
778 tmp11 = tmp1 + tmp2;
779 tmp12 = tmp1 - tmp2;
781 d0 = tmp10 + tmp11;
782 d4 = tmp10 - tmp11;
784 z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
785 d2 = tmp13 + z1;
786 d6 = tmp13 - z1;
788 // Even part of IDCT
790 THRESHOLD(tmp0, d0, threshold[0*8]);
791 THRESHOLD(tmp1, d2, threshold[2*8]);
792 THRESHOLD(tmp2, d4, threshold[4*8]);
793 THRESHOLD(tmp3, d6, threshold[6*8]);
794 tmp0+=2;
795 tmp10 = (tmp0 + tmp2)>>2;
796 tmp11 = (tmp0 - tmp2)>>2;
798 tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
799 tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
801 tmp0 = tmp10 + tmp13; //->temps
802 tmp3 = tmp10 - tmp13; //->temps
803 tmp1 = tmp11 + tmp12; //->temps
804 tmp2 = tmp11 - tmp12; //->temps
806 // Odd part of FDCT
808 tmp10 = tmp4 + tmp5;
809 tmp11 = tmp5 + tmp6;
810 tmp12 = tmp6 + tmp7;
812 z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
813 z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
814 z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
815 z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
817 z11 = tmp7 + z3;
818 z13 = tmp7 - z3;
820 d5 = z13 + z2;
821 d3 = z13 - z2;
822 d1 = z11 + z4;
823 d7 = z11 - z4;
825 // Odd part of IDCT
827 THRESHOLD(tmp4, d1, threshold[1*8]);
828 THRESHOLD(tmp5, d3, threshold[3*8]);
829 THRESHOLD(tmp6, d5, threshold[5*8]);
830 THRESHOLD(tmp7, d7, threshold[7*8]);
832 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
833 z13 = tmp6 + tmp5;
834 z10 = (tmp6 - tmp5)<<1;
835 z11 = tmp4 + tmp7;
836 z12 = (tmp4 - tmp7)<<1;
838 tmp7 = (z11 + z13)>>2; //+2 !
839 tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
840 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
841 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
842 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
844 tmp6 = tmp12 - tmp7;
845 tmp5 = tmp11 - tmp6;
846 tmp4 = tmp10 + tmp5;
848 wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
849 wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
850 wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
851 wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
852 wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
853 wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
854 wsptr[DCTSIZE*6]= (tmp1 - tmp6);
855 wsptr[DCTSIZE*7]= (tmp0 - tmp7);
857 dataptr++; //next column
858 wsptr++;
859 threshold++;
861 dataptr+=8; //skip each second start pos
862 wsptr +=8;
866 #else /* HAVE_MMX */
868 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
870 uint64_t __attribute__((aligned(8))) temps[4];
871 __asm__ volatile(
872 ASMALIGN(4)
873 "1: \n\t"
874 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
876 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
877 "movq %%mm1, %%mm0 \n\t"
879 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
880 "movq %%mm7, %%mm3 \n\t"
882 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
883 "movq %%mm1, %%mm5 \n\t"
885 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
886 "psubw %%mm7, %%mm1 \n\t" //t13
888 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
889 "movq %%mm6, %%mm4 \n\t"
891 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
892 "paddw %%mm7, %%mm5 \n\t" //t10
894 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
895 "movq %%mm6, %%mm7 \n\t"
897 "paddw %%mm2, %%mm6 \n\t" //t11
898 "psubw %%mm2, %%mm7 \n\t" //t12
900 "movq %%mm5, %%mm2 \n\t"
901 "paddw %%mm6, %%mm5 \n\t" //d0
902 // i0 t13 t12 i3 i1 d0 - d4
903 "psubw %%mm6, %%mm2 \n\t" //d4
904 "paddw %%mm1, %%mm7 \n\t"
906 "movq 4*16(%%"REG_d"), %%mm6 \n\t"
907 "psllw $2, %%mm7 \n\t"
909 "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
910 "psubw %%mm6, %%mm2 \n\t"
912 "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
913 "paddusw %%mm6, %%mm2 \n\t"
915 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
917 "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
918 "paddw %%mm6, %%mm2 \n\t"
920 "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
921 "psubusw %%mm6, %%mm2 \n\t"
923 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
924 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
925 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
926 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
927 "movq %%mm2, %%mm6 \n\t"
929 "paddw %%mm5, %%mm2 \n\t"
930 "psubw %%mm6, %%mm5 \n\t"
932 "movq %%mm1, %%mm6 \n\t"
933 "paddw %%mm7, %%mm1 \n\t" //d2
935 "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
936 "psubw %%mm7, %%mm6 \n\t" //d6
938 "movq 6*16(%%"REG_d"), %%mm7 \n\t"
939 "psraw $2, %%mm5 \n\t"
941 "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
942 "psubw %%mm7, %%mm6 \n\t"
943 // t7 d2 /t11 t4 t6 - d6 /t10
945 "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
946 "paddusw %%mm7, %%mm6 \n\t"
948 "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
949 "paddw %%mm7, %%mm6 \n\t"
951 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
952 "psubusw %%mm7, %%mm6 \n\t"
954 //movq [edi+"DCTSIZE_S"*2*2], mm1
955 //movq [edi+"DCTSIZE_S"*6*2], mm6
956 "movq %%mm1, %%mm7 \n\t"
957 "psraw $2, %%mm2 \n\t"
959 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
960 "psubw %%mm6, %%mm1 \n\t"
962 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
963 "paddw %%mm7, %%mm6 \n\t" //'t13
965 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
966 "movq %%mm2, %%mm7 \n\t"
968 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
969 "paddw %%mm6, %%mm2 \n\t" //'t0
971 "movq %%mm2, 0*8+%3 \n\t" //!
972 "psubw %%mm6, %%mm7 \n\t" //'t3
974 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
975 "psubw %%mm6, %%mm1 \n\t" //'t12
977 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
978 "movq %%mm5, %%mm6 \n\t"
980 "movq %%mm7, 3*8+%3 \n\t"
981 "paddw %%mm2, %%mm3 \n\t" //t10
983 "paddw %%mm4, %%mm2 \n\t" //t11
984 "paddw %%mm0, %%mm4 \n\t" //t12
986 "movq %%mm3, %%mm7 \n\t"
987 "psubw %%mm4, %%mm3 \n\t"
989 "psllw $2, %%mm3 \n\t"
990 "psllw $2, %%mm7 \n\t" //opt for P6
992 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
993 "psllw $2, %%mm4 \n\t"
995 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
996 "psllw $2, %%mm2 \n\t"
998 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
999 "paddw %%mm1, %%mm5 \n\t" //'t1
1001 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1002 "psubw %%mm1, %%mm6 \n\t" //'t2
1003 // t7 't12 't11 t4 t6 - 't13 't10 ---
1005 "paddw %%mm3, %%mm7 \n\t" //z2
1007 "movq %%mm5, 1*8+%3 \n\t"
1008 "paddw %%mm3, %%mm4 \n\t" //z4
1010 "movq 3*16(%%"REG_d"), %%mm3 \n\t"
1011 "movq %%mm0, %%mm1 \n\t"
1013 "movq %%mm6, 2*8+%3 \n\t"
1014 "psubw %%mm2, %%mm1 \n\t" //z13
1016 //===
1017 "paddw %%mm2, %%mm0 \n\t" //z11
1018 "movq %%mm1, %%mm5 \n\t"
1020 "movq 5*16(%%"REG_d"), %%mm2 \n\t"
1021 "psubw %%mm7, %%mm1 \n\t" //d3
1023 "paddw %%mm7, %%mm5 \n\t" //d5
1024 "psubw %%mm3, %%mm1 \n\t"
1026 "movq 1*16(%%"REG_d"), %%mm7 \n\t"
1027 "psubw %%mm2, %%mm5 \n\t"
1029 "movq %%mm0, %%mm6 \n\t"
1030 "paddw %%mm4, %%mm0 \n\t" //d1
1032 "paddusw %%mm3, %%mm1 \n\t"
1033 "psubw %%mm4, %%mm6 \n\t" //d7
1035 // d1 d3 - - - d5 d7 -
1036 "movq 7*16(%%"REG_d"), %%mm4 \n\t"
1037 "psubw %%mm7, %%mm0 \n\t"
1039 "psubw %%mm4, %%mm6 \n\t"
1040 "paddusw %%mm2, %%mm5 \n\t"
1042 "paddusw %%mm4, %%mm6 \n\t"
1043 "paddw %%mm3, %%mm1 \n\t"
1045 "paddw %%mm2, %%mm5 \n\t"
1046 "paddw %%mm4, %%mm6 \n\t"
1048 "psubusw %%mm3, %%mm1 \n\t"
1049 "psubusw %%mm2, %%mm5 \n\t"
1051 "psubusw %%mm4, %%mm6 \n\t"
1052 "movq %%mm1, %%mm4 \n\t"
1054 "por %%mm5, %%mm4 \n\t"
1055 "paddusw %%mm7, %%mm0 \n\t"
1057 "por %%mm6, %%mm4 \n\t"
1058 "paddw %%mm7, %%mm0 \n\t"
1060 "packssdw %%mm4, %%mm4 \n\t"
1061 "psubusw %%mm7, %%mm0 \n\t"
1063 "movd %%mm4, %%"REG_a" \n\t"
1064 "or %%"REG_a", %%"REG_a" \n\t"
1065 "jnz 2f \n\t"
1066 //movq [edi+"DCTSIZE_S"*3*2], mm1
1067 //movq [edi+"DCTSIZE_S"*5*2], mm5
1068 //movq [edi+"DCTSIZE_S"*1*2], mm0
1069 //movq [edi+"DCTSIZE_S"*7*2], mm6
1070 // t4 t5 - - - t6 t7 -
1071 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1072 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1073 "movq 0*8+%3, %%mm4 \n\t"
1074 "movq %%mm0, %%mm1 \n\t"
1076 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1077 "movq %%mm1, %%mm2 \n\t"
1079 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1080 "movq %%mm2, %%mm3 \n\t"
1082 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1083 "paddw %%mm4, %%mm5 \n\t"
1085 "movq 1*8+%3, %%mm6 \n\t"
1086 //paddw mm3, MM_2
1087 "psraw $2, %%mm3 \n\t" //tmp7
1089 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1090 "psubw %%mm3, %%mm4 \n\t"
1092 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1093 "paddw %%mm3, %%mm5 \n\t"
1095 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1096 "paddw %%mm6, %%mm7 \n\t"
1098 "movq 2*8+%3, %%mm3 \n\t"
1099 "psubw %%mm0, %%mm6 \n\t"
1101 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1102 "paddw %%mm0, %%mm7 \n\t"
1104 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1105 "paddw %%mm3, %%mm4 \n\t"
1107 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1108 "psubw %%mm1, %%mm3 \n\t"
1110 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1111 "paddw %%mm1, %%mm4 \n\t"
1113 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1114 "paddw %%mm3, %%mm5 \n\t"
1116 "movq 3*8+%3, %%mm0 \n\t"
1117 "add $8, %%"REG_S" \n\t"
1119 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1120 "paddw %%mm0, %%mm6 \n\t"
1122 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1123 "psubw %%mm2, %%mm0 \n\t"
1125 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1126 "paddw %%mm2, %%mm6 \n\t"
1128 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1129 "paddw %%mm0, %%mm7 \n\t"
1131 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1133 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1134 "add $8, %%"REG_D" \n\t"
1135 "jmp 4f \n\t"
1137 "2: \n\t"
1138 //--- non DC2
1139 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1140 //psraw mm5, 2
1141 //psraw mm0, 2
1142 //psraw mm6, 2
1143 "movq %%mm5, %%mm3 \n\t"
1144 "psubw %%mm1, %%mm5 \n\t"
1146 "psllw $1, %%mm5 \n\t" //'z10
1147 "paddw %%mm1, %%mm3 \n\t" //'z13
1149 "movq %%mm0, %%mm2 \n\t"
1150 "psubw %%mm6, %%mm0 \n\t"
1152 "movq %%mm5, %%mm1 \n\t"
1153 "psllw $1, %%mm0 \n\t" //'z12
1155 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1156 "paddw %%mm0, %%mm5 \n\t"
1158 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1159 "paddw %%mm6, %%mm2 \n\t" //'z11
1161 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1162 "movq %%mm2, %%mm7 \n\t"
1164 //---
1165 "movq 0*8+%3, %%mm4 \n\t"
1166 "psubw %%mm3, %%mm2 \n\t"
1168 "psllw $1, %%mm2 \n\t"
1169 "paddw %%mm3, %%mm7 \n\t" //'t7
1171 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1172 "movq %%mm4, %%mm6 \n\t"
1173 //paddw mm7, MM_2
1174 "psraw $2, %%mm7 \n\t"
1176 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1177 "psubw %%mm7, %%mm6 \n\t"
1179 "movq 1*8+%3, %%mm3 \n\t"
1180 "paddw %%mm7, %%mm4 \n\t"
1182 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1183 "paddw %%mm5, %%mm1 \n\t" //'t12
1185 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1186 "psubw %%mm7, %%mm1 \n\t" //'t6
1188 "movq 2*8+%3, %%mm7 \n\t"
1189 "psubw %%mm5, %%mm0 \n\t" //'t10
1191 "movq 3*8+%3, %%mm6 \n\t"
1192 "movq %%mm3, %%mm5 \n\t"
1194 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1195 "psubw %%mm1, %%mm5 \n\t"
1197 "psubw %%mm1, %%mm2 \n\t" //'t5
1198 "paddw %%mm1, %%mm3 \n\t"
1200 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1201 "movq %%mm7, %%mm4 \n\t"
1203 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1204 "psubw %%mm2, %%mm4 \n\t"
1206 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1207 "paddw %%mm2, %%mm7 \n\t"
1209 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1210 "paddw %%mm2, %%mm0 \n\t" //'t4
1212 // 't4 't6 't5 - - - - 't7
1213 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1214 "movq %%mm6, %%mm1 \n\t"
1216 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1217 "psubw %%mm0, %%mm1 \n\t"
1219 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1220 "paddw %%mm0, %%mm6 \n\t"
1222 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1223 "add $8, %%"REG_S" \n\t"
1225 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1227 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1228 "add $8, %%"REG_D" \n\t"
1230 "4: \n\t"
1231 //=part 2 (the same)===========================================================
1232 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
1234 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
1235 "movq %%mm1, %%mm0 \n\t"
1237 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
1238 "movq %%mm7, %%mm3 \n\t"
1240 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
1241 "movq %%mm1, %%mm5 \n\t"
1243 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
1244 "psubw %%mm7, %%mm1 \n\t" //t13
1246 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1247 "movq %%mm6, %%mm4 \n\t"
1249 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
1250 "paddw %%mm7, %%mm5 \n\t" //t10
1252 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
1253 "movq %%mm6, %%mm7 \n\t"
1255 "paddw %%mm2, %%mm6 \n\t" //t11
1256 "psubw %%mm2, %%mm7 \n\t" //t12
1258 "movq %%mm5, %%mm2 \n\t"
1259 "paddw %%mm6, %%mm5 \n\t" //d0
1260 // i0 t13 t12 i3 i1 d0 - d4
1261 "psubw %%mm6, %%mm2 \n\t" //d4
1262 "paddw %%mm1, %%mm7 \n\t"
1264 "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
1265 "psllw $2, %%mm7 \n\t"
1267 "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1268 "psubw %%mm6, %%mm2 \n\t"
1270 "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1271 "paddusw %%mm6, %%mm2 \n\t"
1273 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
1275 "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1276 "paddw %%mm6, %%mm2 \n\t"
1278 "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1279 "psubusw %%mm6, %%mm2 \n\t"
1281 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1282 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1283 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1284 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
1285 "movq %%mm2, %%mm6 \n\t"
1287 "paddw %%mm5, %%mm2 \n\t"
1288 "psubw %%mm6, %%mm5 \n\t"
1290 "movq %%mm1, %%mm6 \n\t"
1291 "paddw %%mm7, %%mm1 \n\t" //d2
1293 "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1294 "psubw %%mm7, %%mm6 \n\t" //d6
1296 "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
1297 "psraw $2, %%mm5 \n\t"
1299 "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1300 "psubw %%mm7, %%mm6 \n\t"
1301 // t7 d2 /t11 t4 t6 - d6 /t10
1303 "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1304 "paddusw %%mm7, %%mm6 \n\t"
1306 "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1307 "paddw %%mm7, %%mm6 \n\t"
1309 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
1310 "psubusw %%mm7, %%mm6 \n\t"
1312 //movq [edi+"DCTSIZE_S"*2*2], mm1
1313 //movq [edi+"DCTSIZE_S"*6*2], mm6
1314 "movq %%mm1, %%mm7 \n\t"
1315 "psraw $2, %%mm2 \n\t"
1317 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
1318 "psubw %%mm6, %%mm1 \n\t"
1320 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
1321 "paddw %%mm7, %%mm6 \n\t" //'t13
1323 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1324 "movq %%mm2, %%mm7 \n\t"
1326 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
1327 "paddw %%mm6, %%mm2 \n\t" //'t0
1329 "movq %%mm2, 0*8+%3 \n\t" //!
1330 "psubw %%mm6, %%mm7 \n\t" //'t3
1332 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1333 "psubw %%mm6, %%mm1 \n\t" //'t12
1335 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
1336 "movq %%mm5, %%mm6 \n\t"
1338 "movq %%mm7, 3*8+%3 \n\t"
1339 "paddw %%mm2, %%mm3 \n\t" //t10
1341 "paddw %%mm4, %%mm2 \n\t" //t11
1342 "paddw %%mm0, %%mm4 \n\t" //t12
1344 "movq %%mm3, %%mm7 \n\t"
1345 "psubw %%mm4, %%mm3 \n\t"
1347 "psllw $2, %%mm3 \n\t"
1348 "psllw $2, %%mm7 \n\t" //opt for P6
1350 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
1351 "psllw $2, %%mm4 \n\t"
1353 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1354 "psllw $2, %%mm2 \n\t"
1356 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1357 "paddw %%mm1, %%mm5 \n\t" //'t1
1359 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1360 "psubw %%mm1, %%mm6 \n\t" //'t2
1361 // t7 't12 't11 t4 t6 - 't13 't10 ---
1363 "paddw %%mm3, %%mm7 \n\t" //z2
1365 "movq %%mm5, 1*8+%3 \n\t"
1366 "paddw %%mm3, %%mm4 \n\t" //z4
1368 "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
1369 "movq %%mm0, %%mm1 \n\t"
1371 "movq %%mm6, 2*8+%3 \n\t"
1372 "psubw %%mm2, %%mm1 \n\t" //z13
1374 //===
1375 "paddw %%mm2, %%mm0 \n\t" //z11
1376 "movq %%mm1, %%mm5 \n\t"
1378 "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
1379 "psubw %%mm7, %%mm1 \n\t" //d3
1381 "paddw %%mm7, %%mm5 \n\t" //d5
1382 "psubw %%mm3, %%mm1 \n\t"
1384 "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
1385 "psubw %%mm2, %%mm5 \n\t"
1387 "movq %%mm0, %%mm6 \n\t"
1388 "paddw %%mm4, %%mm0 \n\t" //d1
1390 "paddusw %%mm3, %%mm1 \n\t"
1391 "psubw %%mm4, %%mm6 \n\t" //d7
1393 // d1 d3 - - - d5 d7 -
1394 "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
1395 "psubw %%mm7, %%mm0 \n\t"
1397 "psubw %%mm4, %%mm6 \n\t"
1398 "paddusw %%mm2, %%mm5 \n\t"
1400 "paddusw %%mm4, %%mm6 \n\t"
1401 "paddw %%mm3, %%mm1 \n\t"
1403 "paddw %%mm2, %%mm5 \n\t"
1404 "paddw %%mm4, %%mm6 \n\t"
1406 "psubusw %%mm3, %%mm1 \n\t"
1407 "psubusw %%mm2, %%mm5 \n\t"
1409 "psubusw %%mm4, %%mm6 \n\t"
1410 "movq %%mm1, %%mm4 \n\t"
1412 "por %%mm5, %%mm4 \n\t"
1413 "paddusw %%mm7, %%mm0 \n\t"
1415 "por %%mm6, %%mm4 \n\t"
1416 "paddw %%mm7, %%mm0 \n\t"
1418 "packssdw %%mm4, %%mm4 \n\t"
1419 "psubusw %%mm7, %%mm0 \n\t"
1421 "movd %%mm4, %%"REG_a" \n\t"
1422 "or %%"REG_a", %%"REG_a" \n\t"
1423 "jnz 3f \n\t"
1424 //movq [edi+"DCTSIZE_S"*3*2], mm1
1425 //movq [edi+"DCTSIZE_S"*5*2], mm5
1426 //movq [edi+"DCTSIZE_S"*1*2], mm0
1427 //movq [edi+"DCTSIZE_S"*7*2], mm6
1428 // t4 t5 - - - t6 t7 -
1429 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1430 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1431 "movq 0*8+%3, %%mm4 \n\t"
1432 "movq %%mm0, %%mm1 \n\t"
1434 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1435 "movq %%mm1, %%mm2 \n\t"
1437 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1438 "movq %%mm2, %%mm3 \n\t"
1440 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1441 "paddw %%mm4, %%mm5 \n\t"
1443 "movq 1*8+%3, %%mm6 \n\t"
1444 //paddw mm3, MM_2
1445 "psraw $2, %%mm3 \n\t" //tmp7
1447 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1448 "psubw %%mm3, %%mm4 \n\t"
1450 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1451 "paddw %%mm3, %%mm5 \n\t"
1453 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1454 "paddw %%mm6, %%mm7 \n\t"
1456 "movq 2*8+%3, %%mm3 \n\t"
1457 "psubw %%mm0, %%mm6 \n\t"
1459 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1460 "paddw %%mm0, %%mm7 \n\t"
1462 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1463 "paddw %%mm3, %%mm4 \n\t"
1465 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1466 "psubw %%mm1, %%mm3 \n\t"
1468 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1469 "paddw %%mm1, %%mm4 \n\t"
1471 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1472 "paddw %%mm3, %%mm5 \n\t"
1474 "movq 3*8+%3, %%mm0 \n\t"
1475 "add $24, %%"REG_S" \n\t"
1477 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1478 "paddw %%mm0, %%mm6 \n\t"
1480 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1481 "psubw %%mm2, %%mm0 \n\t"
1483 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1484 "paddw %%mm2, %%mm6 \n\t"
1486 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1487 "paddw %%mm0, %%mm7 \n\t"
1489 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1491 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1492 "add $24, %%"REG_D" \n\t"
1493 "sub $2, %%"REG_c" \n\t"
1494 "jnz 1b \n\t"
1495 "jmp 5f \n\t"
1497 "3: \n\t"
1498 //--- non DC2
1499 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1500 //psraw mm5, 2
1501 //psraw mm0, 2
1502 //psraw mm6, 2
1503 "movq %%mm5, %%mm3 \n\t"
1504 "psubw %%mm1, %%mm5 \n\t"
1506 "psllw $1, %%mm5 \n\t" //'z10
1507 "paddw %%mm1, %%mm3 \n\t" //'z13
1509 "movq %%mm0, %%mm2 \n\t"
1510 "psubw %%mm6, %%mm0 \n\t"
1512 "movq %%mm5, %%mm1 \n\t"
1513 "psllw $1, %%mm0 \n\t" //'z12
1515 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1516 "paddw %%mm0, %%mm5 \n\t"
1518 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1519 "paddw %%mm6, %%mm2 \n\t" //'z11
1521 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1522 "movq %%mm2, %%mm7 \n\t"
1524 //---
1525 "movq 0*8+%3, %%mm4 \n\t"
1526 "psubw %%mm3, %%mm2 \n\t"
1528 "psllw $1, %%mm2 \n\t"
1529 "paddw %%mm3, %%mm7 \n\t" //'t7
1531 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1532 "movq %%mm4, %%mm6 \n\t"
1533 //paddw mm7, MM_2
1534 "psraw $2, %%mm7 \n\t"
1536 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1537 "psubw %%mm7, %%mm6 \n\t"
1539 "movq 1*8+%3, %%mm3 \n\t"
1540 "paddw %%mm7, %%mm4 \n\t"
1542 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1543 "paddw %%mm5, %%mm1 \n\t" //'t12
1545 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1546 "psubw %%mm7, %%mm1 \n\t" //'t6
1548 "movq 2*8+%3, %%mm7 \n\t"
1549 "psubw %%mm5, %%mm0 \n\t" //'t10
1551 "movq 3*8+%3, %%mm6 \n\t"
1552 "movq %%mm3, %%mm5 \n\t"
1554 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1555 "psubw %%mm1, %%mm5 \n\t"
1557 "psubw %%mm1, %%mm2 \n\t" //'t5
1558 "paddw %%mm1, %%mm3 \n\t"
1560 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1561 "movq %%mm7, %%mm4 \n\t"
1563 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1564 "psubw %%mm2, %%mm4 \n\t"
1566 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1567 "paddw %%mm2, %%mm7 \n\t"
1569 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1570 "paddw %%mm2, %%mm0 \n\t" //'t4
1572 // 't4 't6 't5 - - - - 't7
1573 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1574 "movq %%mm6, %%mm1 \n\t"
1576 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1577 "psubw %%mm0, %%mm1 \n\t"
1579 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1580 "paddw %%mm0, %%mm6 \n\t"
1582 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1583 "add $24, %%"REG_S" \n\t"
1585 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1587 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1588 "add $24, %%"REG_D" \n\t"
1589 "sub $2, %%"REG_c" \n\t"
1590 "jnz 1b \n\t"
1591 "5: \n\t"
1593 : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
1594 : "d"(thr_adr)
1595 : "%"REG_a
1599 #endif // HAVE_MMX
1601 #if !HAVE_MMX
1603 static void row_idct_c(DCTELEM* workspace,
1604 int16_t* output_adr, int output_stride, int cnt)
1606 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1607 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1608 int_simd16_t z5, z10, z11, z12, z13;
1609 int16_t* outptr;
1610 DCTELEM* wsptr;
1612 cnt*=4;
1613 wsptr = workspace;
1614 outptr = output_adr;
1615 for (; cnt > 0; cnt--) {
1616 // Even part
1617 //Simd version reads 4x4 block and transposes it
1618 tmp10 = ( wsptr[2] + wsptr[3]);
1619 tmp11 = ( wsptr[2] - wsptr[3]);
1621 tmp13 = ( wsptr[0] + wsptr[1]);
1622 tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
1624 tmp0 = tmp10 + tmp13; //->temps
1625 tmp3 = tmp10 - tmp13; //->temps
1626 tmp1 = tmp11 + tmp12;
1627 tmp2 = tmp11 - tmp12;
1629 // Odd part
1630 //Also transpose, with previous:
1631 // ---- ---- ||||
1632 // ---- ---- idct ||||
1633 // ---- ---- ---> ||||
1634 // ---- ---- ||||
1635 z13 = wsptr[4] + wsptr[5];
1636 z10 = wsptr[4] - wsptr[5];
1637 z11 = wsptr[6] + wsptr[7];
1638 z12 = wsptr[6] - wsptr[7];
1640 tmp7 = z11 + z13;
1641 tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
1643 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
1644 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
1645 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
1647 tmp6 = (tmp12<<3) - tmp7;
1648 tmp5 = (tmp11<<3) - tmp6;
1649 tmp4 = (tmp10<<3) + tmp5;
1651 // Final output stage: descale and write column
1652 outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
1653 outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
1654 outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
1655 outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
1656 outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
1657 outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
1658 outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
1659 outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
1660 outptr++;
1662 wsptr += DCTSIZE; // advance pointer to next row
1666 #else /* HAVE_MMX */
1668 static void row_idct_mmx (DCTELEM* workspace,
1669 int16_t* output_adr, int output_stride, int cnt)
1671 uint64_t __attribute__((aligned(8))) temps[4];
1672 __asm__ volatile(
1673 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1674 "1: \n\t"
1675 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
1678 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
1679 "movq %%mm0, %%mm4 \n\t"
1681 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1682 "punpcklwd %%mm1, %%mm0 \n\t"
1684 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
1685 "punpckhwd %%mm1, %%mm4 \n\t"
1687 //transpose 4x4
1688 "movq %%mm2, %%mm7 \n\t"
1689 "punpcklwd %%mm3, %%mm2 \n\t"
1691 "movq %%mm0, %%mm6 \n\t"
1692 "punpckldq %%mm2, %%mm0 \n\t" //0
1694 "punpckhdq %%mm2, %%mm6 \n\t" //1
1695 "movq %%mm0, %%mm5 \n\t"
1697 "punpckhwd %%mm3, %%mm7 \n\t"
1698 "psubw %%mm6, %%mm0 \n\t"
1700 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
1701 "movq %%mm4, %%mm2 \n\t"
1703 "punpckldq %%mm7, %%mm4 \n\t" //2
1704 "paddw %%mm6, %%mm5 \n\t"
1706 "punpckhdq %%mm7, %%mm2 \n\t" //3
1707 "movq %%mm4, %%mm1 \n\t"
1709 "psllw $2, %%mm0 \n\t"
1710 "paddw %%mm2, %%mm4 \n\t" //t10
1712 "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
1713 "psubw %%mm2, %%mm1 \n\t" //t11
1715 "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
1716 "psubw %%mm5, %%mm0 \n\t"
1718 "movq %%mm4, %%mm6 \n\t"
1719 "paddw %%mm5, %%mm4 \n\t" //t0
1721 "psubw %%mm5, %%mm6 \n\t" //t3
1722 "movq %%mm1, %%mm7 \n\t"
1724 "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
1725 "paddw %%mm0, %%mm1 \n\t" //t1
1727 "movq %%mm4, 0*8+%3 \n\t" //t0
1728 "movq %%mm3, %%mm4 \n\t"
1730 "movq %%mm6, 1*8+%3 \n\t" //t3
1731 "punpcklwd %%mm2, %%mm3 \n\t"
1733 //transpose 4x4
1734 "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
1735 "punpckhwd %%mm2, %%mm4 \n\t"
1737 "movq %%mm5, %%mm2 \n\t"
1738 "punpcklwd %%mm6, %%mm5 \n\t"
1740 "psubw %%mm0, %%mm7 \n\t" //t2
1741 "punpckhwd %%mm6, %%mm2 \n\t"
1743 "movq %%mm3, %%mm0 \n\t"
1744 "punpckldq %%mm5, %%mm3 \n\t" //4
1746 "punpckhdq %%mm5, %%mm0 \n\t" //5
1747 "movq %%mm4, %%mm5 \n\t"
1750 "movq %%mm3, %%mm6 \n\t"
1751 "punpckldq %%mm2, %%mm4 \n\t" //6
1753 "psubw %%mm0, %%mm3 \n\t" //z10
1754 "punpckhdq %%mm2, %%mm5 \n\t" //7
1756 "paddw %%mm0, %%mm6 \n\t" //z13
1757 "movq %%mm4, %%mm2 \n\t"
1759 "movq %%mm3, %%mm0 \n\t"
1760 "psubw %%mm5, %%mm4 \n\t" //z12
1762 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
1763 "paddw %%mm4, %%mm3 \n\t"
1765 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
1766 "paddw %%mm5, %%mm2 \n\t" //z11 >
1768 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
1769 "movq %%mm2, %%mm5 \n\t"
1771 "psubw %%mm6, %%mm2 \n\t"
1772 "paddw %%mm6, %%mm5 \n\t" //t7
1774 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
1775 "paddw %%mm3, %%mm0 \n\t" //t12
1777 "psllw $3, %%mm0 \n\t"
1778 "psubw %%mm3, %%mm4 \n\t" //t10
1780 "movq 0*8+%3, %%mm6 \n\t"
1781 "movq %%mm1, %%mm3 \n\t"
1783 "psllw $3, %%mm4 \n\t"
1784 "psubw %%mm5, %%mm0 \n\t" //t6
1786 "psllw $3, %%mm2 \n\t"
1787 "paddw %%mm0, %%mm1 \n\t" //d1
1789 "psubw %%mm0, %%mm2 \n\t" //t5
1790 "psubw %%mm0, %%mm3 \n\t" //d6
1792 "paddw %%mm2, %%mm4 \n\t" //t4
1793 "movq %%mm7, %%mm0 \n\t"
1795 "paddw %%mm2, %%mm7 \n\t" //d2
1796 "psubw %%mm2, %%mm0 \n\t" //d5
1798 "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
1799 "psubw %%mm5, %%mm6 \n\t" //d7
1801 "paddw 0*8+%3, %%mm5 \n\t" //d0
1802 "paddw %%mm2, %%mm1 \n\t"
1804 "paddw %%mm2, %%mm5 \n\t"
1805 "psraw $3, %%mm1 \n\t"
1807 "paddw %%mm2, %%mm7 \n\t"
1808 "psraw $3, %%mm5 \n\t"
1810 "paddw (%%"REG_D"), %%mm5 \n\t"
1811 "psraw $3, %%mm7 \n\t"
1813 "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
1814 "paddw %%mm2, %%mm0 \n\t"
1816 "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
1817 "paddw %%mm2, %%mm3 \n\t"
1819 "movq %%mm5, (%%"REG_D") \n\t"
1820 "paddw %%mm2, %%mm6 \n\t"
1822 "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
1823 "psraw $3, %%mm0 \n\t"
1825 "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
1826 "add %%"REG_d", %%"REG_D" \n\t" //3*ls
1828 "movq 1*8+%3, %%mm5 \n\t" //t3
1829 "psraw $3, %%mm3 \n\t"
1831 "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
1832 "psubw %%mm4, %%mm5 \n\t" //d3
1834 "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
1835 "psraw $3, %%mm6 \n\t"
1837 "paddw 1*8+%3, %%mm4 \n\t" //d4
1838 "paddw %%mm2, %%mm5 \n\t"
1840 "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
1841 "paddw %%mm2, %%mm4 \n\t"
1843 "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
1844 "psraw $3, %%mm5 \n\t"
1846 "paddw (%%"REG_D"), %%mm5 \n\t"
1847 "psraw $3, %%mm4 \n\t"
1849 "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
1850 "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
1852 "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
1853 "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
1854 "movq %%mm5, (%%"REG_D") \n\t"
1855 "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
1857 "sub %%"REG_d", %%"REG_D" \n\t"
1858 "add $8, %%"REG_D" \n\t"
1859 "dec %%"REG_c" \n\t"
1860 "jnz 1b \n\t"
1862 : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
1863 : "a"(output_stride*sizeof(short))
1864 : "%"REG_d
1868 #endif // HAVE_MMX
1870 #if !HAVE_MMX
1872 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1874 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1875 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1876 int_simd16_t z1, z2, z3, z4, z5, z11, z13;
1877 DCTELEM *dataptr;
1879 cnt*=4;
1880 // Pass 1: process rows.
1882 dataptr = data;
1883 for (; cnt > 0; cnt--) {
1884 tmp0 = pixels[line_size*0] + pixels[line_size*7];
1885 tmp7 = pixels[line_size*0] - pixels[line_size*7];
1886 tmp1 = pixels[line_size*1] + pixels[line_size*6];
1887 tmp6 = pixels[line_size*1] - pixels[line_size*6];
1888 tmp2 = pixels[line_size*2] + pixels[line_size*5];
1889 tmp5 = pixels[line_size*2] - pixels[line_size*5];
1890 tmp3 = pixels[line_size*3] + pixels[line_size*4];
1891 tmp4 = pixels[line_size*3] - pixels[line_size*4];
1893 // Even part
1895 tmp10 = tmp0 + tmp3;
1896 tmp13 = tmp0 - tmp3;
1897 tmp11 = tmp1 + tmp2;
1898 tmp12 = tmp1 - tmp2;
1899 //Even columns are written first, this leads to different order of columns
1900 //in column_fidct(), but they are processed independently, so all ok.
1901 //Later in the row_idct() columns readed at the same order.
1902 dataptr[2] = tmp10 + tmp11;
1903 dataptr[3] = tmp10 - tmp11;
1905 z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
1906 dataptr[0] = tmp13 + z1;
1907 dataptr[1] = tmp13 - z1;
1909 // Odd part
1911 tmp10 = (tmp4 + tmp5) <<2;
1912 tmp11 = (tmp5 + tmp6) <<2;
1913 tmp12 = (tmp6 + tmp7) <<2;
1915 z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
1916 z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
1917 z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
1918 z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
1920 z11 = tmp7 + z3;
1921 z13 = tmp7 - z3;
1923 dataptr[4] = z13 + z2;
1924 dataptr[5] = z13 - z2;
1925 dataptr[6] = z11 + z4;
1926 dataptr[7] = z11 - z4;
1928 pixels++; // advance pointer to next column
1929 dataptr += DCTSIZE;
1933 #else /* HAVE_MMX */
1935 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1937 uint64_t __attribute__((aligned(8))) temps[4];
1938 __asm__ volatile(
1939 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1940 "6: \n\t"
1941 "movd (%%"REG_S"), %%mm0 \n\t"
1942 "pxor %%mm7, %%mm7 \n\t"
1944 "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
1945 "punpcklbw %%mm7, %%mm0 \n\t"
1947 "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
1948 "punpcklbw %%mm7, %%mm1 \n\t"
1950 "punpcklbw %%mm7, %%mm2 \n\t"
1951 "add %%"REG_d", %%"REG_S" \n\t"
1953 "movq %%mm0, %%mm5 \n\t"
1956 "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
1957 "movq %%mm1, %%mm6 \n\t"
1959 "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
1960 "punpcklbw %%mm7, %%mm3 \n\t"
1962 "psubw %%mm3, %%mm5 \n\t"
1963 "punpcklbw %%mm7, %%mm4 \n\t"
1965 "paddw %%mm3, %%mm0 \n\t"
1966 "psubw %%mm4, %%mm6 \n\t"
1968 "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
1969 "paddw %%mm4, %%mm1 \n\t"
1971 "movq %%mm5, 0*8+%3 \n\t" //t7
1972 "punpcklbw %%mm7, %%mm3 \n\t"
1974 "movq %%mm6, 1*8+%3 \n\t" //t6
1975 "movq %%mm2, %%mm4 \n\t"
1977 "movd (%%"REG_S"), %%mm5 \n\t" //3
1978 "paddw %%mm3, %%mm2 \n\t"
1980 "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
1981 "punpcklbw %%mm7, %%mm5 \n\t"
1983 "psubw %%mm3, %%mm4 \n\t"
1984 "punpcklbw %%mm7, %%mm6 \n\t"
1986 "movq %%mm5, %%mm3 \n\t"
1987 "paddw %%mm6, %%mm5 \n\t" //t3
1989 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1990 "movq %%mm0, %%mm6 \n\t"
1992 "movq %%mm1, %%mm7 \n\t"
1993 "psubw %%mm5, %%mm0 \n\t" //t13
1995 "psubw %%mm2, %%mm1 \n\t"
1996 "paddw %%mm2, %%mm7 \n\t" //t11
1998 "paddw %%mm0, %%mm1 \n\t"
1999 "movq %%mm7, %%mm2 \n\t"
2001 "psllw $2, %%mm1 \n\t"
2002 "paddw %%mm5, %%mm6 \n\t" //t10
2004 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
2005 "paddw %%mm6, %%mm7 \n\t" //d2
2007 "psubw %%mm2, %%mm6 \n\t" //d3
2008 "movq %%mm0, %%mm5 \n\t"
2010 //transpose 4x4
2011 "movq %%mm7, %%mm2 \n\t"
2012 "punpcklwd %%mm6, %%mm7 \n\t"
2014 "paddw %%mm1, %%mm0 \n\t" //d0
2015 "punpckhwd %%mm6, %%mm2 \n\t"
2017 "psubw %%mm1, %%mm5 \n\t" //d1
2018 "movq %%mm0, %%mm6 \n\t"
2020 "movq 1*8+%3, %%mm1 \n\t"
2021 "punpcklwd %%mm5, %%mm0 \n\t"
2023 "punpckhwd %%mm5, %%mm6 \n\t"
2024 "movq %%mm0, %%mm5 \n\t"
2026 "punpckldq %%mm7, %%mm0 \n\t" //0
2027 "paddw %%mm4, %%mm3 \n\t"
2029 "punpckhdq %%mm7, %%mm5 \n\t" //1
2030 "movq %%mm6, %%mm7 \n\t"
2032 "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
2033 "punpckldq %%mm2, %%mm6 \n\t" //2
2035 "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
2036 "punpckhdq %%mm2, %%mm7 \n\t" //3
2038 "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
2039 "paddw %%mm1, %%mm4 \n\t"
2041 "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
2042 "psllw $2, %%mm3 \n\t" //t10
2044 "movq 0*8+%3, %%mm2 \n\t"
2045 "psllw $2, %%mm4 \n\t" //t11
2047 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
2048 "paddw %%mm2, %%mm1 \n\t"
2050 "psllw $2, %%mm1 \n\t" //t12
2051 "movq %%mm3, %%mm0 \n\t"
2053 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
2054 "psubw %%mm1, %%mm3 \n\t"
2056 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
2057 "movq %%mm2, %%mm5 \n\t"
2059 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
2060 "psubw %%mm4, %%mm2 \n\t" //z13
2062 "paddw %%mm4, %%mm5 \n\t" //z11
2063 "movq %%mm2, %%mm6 \n\t"
2065 "paddw %%mm3, %%mm0 \n\t" //z2
2066 "movq %%mm5, %%mm7 \n\t"
2068 "paddw %%mm0, %%mm2 \n\t" //d4
2069 "psubw %%mm0, %%mm6 \n\t" //d5
2071 "movq %%mm2, %%mm4 \n\t"
2072 "paddw %%mm3, %%mm1 \n\t" //z4
2074 //transpose 4x4
2075 "punpcklwd %%mm6, %%mm2 \n\t"
2076 "paddw %%mm1, %%mm5 \n\t" //d6
2078 "punpckhwd %%mm6, %%mm4 \n\t"
2079 "psubw %%mm1, %%mm7 \n\t" //d7
2081 "movq %%mm5, %%mm6 \n\t"
2082 "punpcklwd %%mm7, %%mm5 \n\t"
2084 "punpckhwd %%mm7, %%mm6 \n\t"
2085 "movq %%mm2, %%mm7 \n\t"
2087 "punpckldq %%mm5, %%mm2 \n\t" //4
2088 "sub %%"REG_d", %%"REG_S" \n\t"
2090 "punpckhdq %%mm5, %%mm7 \n\t" //5
2091 "movq %%mm4, %%mm5 \n\t"
2093 "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2094 "punpckldq %%mm6, %%mm4 \n\t" //6
2096 "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2097 "punpckhdq %%mm6, %%mm5 \n\t" //7
2099 "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2100 "add $4, %%"REG_S" \n\t"
2102 "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2103 "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
2104 "dec %%"REG_c" \n\t"
2105 "jnz 6b \n\t"
2107 : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps)
2108 : "a"(line_size)
2109 : "%"REG_d);
2112 #endif // HAVE_MMX