Add support for VDPAU video out, including hardware decoding.
[mplayer/glamo.git] / libmpcodecs / vf_fspp.c
blobcf3aac3768d89025c725445b0eadb814e8a0d04b
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 "config.h"
43 #include "mp_msg.h"
44 #include "cpudetect.h"
46 #include "libavutil/internal.h"
47 #include "libavutil/intreadwrite.h"
48 #include "libavutil/mem.h"
49 #include "libavcodec/avcodec.h"
50 #include "libavcodec/dsputil.h"
52 #ifdef HAVE_MALLOC_H
53 #include <malloc.h>
54 #endif
56 #include "img_format.h"
57 #include "mp_image.h"
58 #include "vf.h"
59 #include "libvo/fastmemcpy.h"
61 #undef free
62 #undef malloc
64 //===========================================================================//
65 #define BLOCKSZ 12
67 static const short custom_threshold[64]=
68 // values (296) can't be too high
69 // -it causes too big quant dependence
70 // or maybe overflow(check), which results in some flashing
71 { 71, 296, 295, 237, 71, 40, 38, 19,
72 245, 193, 185, 121, 102, 73, 53, 27,
73 158, 129, 141, 107, 97, 73, 50, 26,
74 102, 116, 109, 98, 82, 66, 45, 23,
75 71, 94, 95, 81, 70, 56, 38, 20,
76 56, 77, 74, 66, 56, 44, 30, 15,
77 38, 53, 50, 45, 38, 30, 21, 11,
78 20, 27, 26, 23, 20, 15, 11, 5
81 static const uint8_t __attribute__((aligned(32))) dither[8][8]={
82 { 0, 48, 12, 60, 3, 51, 15, 63, },
83 { 32, 16, 44, 28, 35, 19, 47, 31, },
84 { 8, 56, 4, 52, 11, 59, 7, 55, },
85 { 40, 24, 36, 20, 43, 27, 39, 23, },
86 { 2, 50, 14, 62, 1, 49, 13, 61, },
87 { 34, 18, 46, 30, 33, 17, 45, 29, },
88 { 10, 58, 6, 54, 9, 57, 5, 53, },
89 { 42, 26, 38, 22, 41, 25, 37, 21, },
92 struct vf_priv_s { //align 16 !
93 uint64_t threshold_mtx_noq[8*2];
94 uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions
96 int log2_count;
97 int temp_stride;
98 int qp;
99 int mpeg2;
100 int prev_q;
101 uint8_t *src;
102 int16_t *temp;
103 int bframes;
104 char *non_b_qp;
108 #if !HAVE_MMX
110 //This func reads from 1 slice, 1 and clears 0 & 1
111 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
112 {int y, x;
113 #define STORE(pos) \
114 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
115 src[x + pos]=src[x + pos - 8*src_stride]=0; \
116 if(temp & 0x100) temp= ~(temp>>31); \
117 dst[x + pos]= temp;
119 for(y=0; y<height; y++){
120 const uint8_t *d= dither[y];
121 for(x=0; x<width; x+=8){
122 int temp;
123 STORE(0);
124 STORE(1);
125 STORE(2);
126 STORE(3);
127 STORE(4);
128 STORE(5);
129 STORE(6);
130 STORE(7);
132 src+=src_stride;
133 dst+=dst_stride;
137 //This func reads from 2 slices, 0 & 2 and clears 2-nd
138 static void store_slice2_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
139 {int y, x;
140 #define STORE2(pos) \
141 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
142 src[x + pos + 16*src_stride]=0; \
143 if(temp & 0x100) temp= ~(temp>>31); \
144 dst[x + pos]= temp;
146 for(y=0; y<height; y++){
147 const uint8_t *d= dither[y];
148 for(x=0; x<width; x+=8){
149 int temp;
150 STORE2(0);
151 STORE2(1);
152 STORE2(2);
153 STORE2(3);
154 STORE2(4);
155 STORE2(5);
156 STORE2(6);
157 STORE2(7);
159 src+=src_stride;
160 dst+=dst_stride;
164 static void mul_thrmat_c(struct vf_priv_s *p,int q)
166 int a;
167 for(a=0;a<64;a++)
168 ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
171 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
172 static void row_idct_c(DCTELEM* workspace,
173 int16_t* output_adr, int output_stride, int cnt);
174 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
176 //this is rather ugly, but there is no need for function pointers
177 #define store_slice_s store_slice_c
178 #define store_slice2_s store_slice2_c
179 #define mul_thrmat_s mul_thrmat_c
180 #define column_fidct_s column_fidct_c
181 #define row_idct_s row_idct_c
182 #define row_fdct_s row_fdct_c
184 #else /* HAVE_MMX */
186 //This func reads from 1 slice, 1 and clears 0 & 1
187 static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
189 const uint8_t *od=&dither[0][0];
190 const uint8_t *end=&dither[height][0];
191 width = (width+7)&~7;
192 dst_stride-=width;
193 //src_stride=(src_stride-width)*2;
194 __asm__ volatile(
195 "mov %5, %%"REG_d" \n\t"
196 "mov %6, %%"REG_S" \n\t"
197 "mov %7, %%"REG_D" \n\t"
198 "mov %1, %%"REG_a" \n\t"
199 "movd %%"REG_d", %%mm5 \n\t"
200 "xor $-1, %%"REG_d" \n\t"
201 "mov %%"REG_a", %%"REG_c" \n\t"
202 "add $7, %%"REG_d" \n\t"
203 "neg %%"REG_a" \n\t"
204 "sub %0, %%"REG_c" \n\t"
205 "add %%"REG_c", %%"REG_c" \n\t"
206 "movd %%"REG_d", %%mm2 \n\t"
207 "mov %%"REG_c", %1 \n\t"
208 "mov %2, %%"REG_d" \n\t"
209 "shl $4, %%"REG_a" \n\t"
211 "2: \n\t"
212 "movq (%%"REG_d"), %%mm3 \n\t"
213 "movq %%mm3, %%mm4 \n\t"
214 "pxor %%mm7, %%mm7 \n\t"
215 "punpcklbw %%mm7, %%mm3 \n\t"
216 "punpckhbw %%mm7, %%mm4 \n\t"
217 "mov %0, %%"REG_c" \n\t"
218 "psraw %%mm5, %%mm3 \n\t"
219 "psraw %%mm5, %%mm4 \n\t"
220 "1: \n\t"
221 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
222 "movq (%%"REG_S"), %%mm0 \n\t"
223 "movq 8(%%"REG_S"), %%mm1 \n\t"
225 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
226 "paddw %%mm3, %%mm0 \n\t"
227 "paddw %%mm4, %%mm1 \n\t"
229 "movq %%mm7, (%%"REG_S") \n\t"
230 "psraw %%mm2, %%mm0 \n\t"
231 "psraw %%mm2, %%mm1 \n\t"
233 "movq %%mm7, 8(%%"REG_S") \n\t"
234 "packuswb %%mm1, %%mm0 \n\t"
235 "add $16, %%"REG_S" \n\t"
237 "movq %%mm0, (%%"REG_D") \n\t"
238 "add $8, %%"REG_D" \n\t"
239 "sub $8, %%"REG_c" \n\t"
240 "jg 1b \n\t"
241 "add %1, %%"REG_S" \n\t"
242 "add $8, %%"REG_d" \n\t"
243 "add %3, %%"REG_D" \n\t"
244 "cmp %4, %%"REG_d" \n\t"
245 "jl 2b \n\t"
248 : "m" (width), "m" (src_stride), "g" (od), "m" (dst_stride), "g" (end),
249 "m" (log2_scale), "m" (src), "m" (dst) //input
250 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
254 //This func reads from 2 slices, 0 & 2 and clears 2-nd
255 static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
257 const uint8_t *od=&dither[0][0];
258 const uint8_t *end=&dither[height][0];
259 width = (width+7)&~7;
260 dst_stride-=width;
261 //src_stride=(src_stride-width)*2;
262 __asm__ volatile(
263 "mov %5, %%"REG_d" \n\t"
264 "mov %6, %%"REG_S" \n\t"
265 "mov %7, %%"REG_D" \n\t"
266 "mov %1, %%"REG_a" \n\t"
267 "movd %%"REG_d", %%mm5 \n\t"
268 "xor $-1, %%"REG_d" \n\t"
269 "mov %%"REG_a", %%"REG_c" \n\t"
270 "add $7, %%"REG_d" \n\t"
271 "sub %0, %%"REG_c" \n\t"
272 "add %%"REG_c", %%"REG_c" \n\t"
273 "movd %%"REG_d", %%mm2 \n\t"
274 "mov %%"REG_c", %1 \n\t"
275 "mov %2, %%"REG_d" \n\t"
276 "shl $5, %%"REG_a" \n\t"
278 "2: \n\t"
279 "movq (%%"REG_d"), %%mm3 \n\t"
280 "movq %%mm3, %%mm4 \n\t"
281 "pxor %%mm7, %%mm7 \n\t"
282 "punpcklbw %%mm7, %%mm3 \n\t"
283 "punpckhbw %%mm7, %%mm4 \n\t"
284 "mov %0, %%"REG_c" \n\t"
285 "psraw %%mm5, %%mm3 \n\t"
286 "psraw %%mm5, %%mm4 \n\t"
287 "1: \n\t"
288 "movq (%%"REG_S"), %%mm0 \n\t"
289 "movq 8(%%"REG_S"), %%mm1 \n\t"
290 "paddw %%mm3, %%mm0 \n\t"
292 "paddw (%%"REG_S",%%"REG_a",), %%mm0 \n\t"
293 "paddw %%mm4, %%mm1 \n\t"
294 "movq 8(%%"REG_S",%%"REG_a",), %%mm6 \n\t"
296 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
297 "psraw %%mm2, %%mm0 \n\t"
298 "paddw %%mm6, %%mm1 \n\t"
300 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
301 "psraw %%mm2, %%mm1 \n\t"
302 "packuswb %%mm1, %%mm0 \n\t"
304 "movq %%mm0, (%%"REG_D") \n\t"
305 "add $16, %%"REG_S" \n\t"
306 "add $8, %%"REG_D" \n\t"
307 "sub $8, %%"REG_c" \n\t"
308 "jg 1b \n\t"
309 "add %1, %%"REG_S" \n\t"
310 "add $8, %%"REG_d" \n\t"
311 "add %3, %%"REG_D" \n\t"
312 "cmp %4, %%"REG_d" \n\t"
313 "jl 2b \n\t"
316 : "m" (width), "m" (src_stride), "g" (od), "m" (dst_stride), "g" (end),
317 "m" (log2_scale), "m" (src), "m" (dst) //input
318 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S
322 static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
324 uint64_t *adr=&p->threshold_mtx_noq[0];
325 __asm__ volatile(
326 "movd %0, %%mm7 \n\t"
327 "add $8*8*2, %%"REG_D" \n\t"
328 "movq 0*8(%%"REG_S"), %%mm0 \n\t"
329 "punpcklwd %%mm7, %%mm7 \n\t"
330 "movq 1*8(%%"REG_S"), %%mm1 \n\t"
331 "punpckldq %%mm7, %%mm7 \n\t"
332 "pmullw %%mm7, %%mm0 \n\t"
334 "movq 2*8(%%"REG_S"), %%mm2 \n\t"
335 "pmullw %%mm7, %%mm1 \n\t"
337 "movq 3*8(%%"REG_S"), %%mm3 \n\t"
338 "pmullw %%mm7, %%mm2 \n\t"
340 "movq %%mm0, 0*8(%%"REG_D") \n\t"
341 "movq 4*8(%%"REG_S"), %%mm4 \n\t"
342 "pmullw %%mm7, %%mm3 \n\t"
344 "movq %%mm1, 1*8(%%"REG_D") \n\t"
345 "movq 5*8(%%"REG_S"), %%mm5 \n\t"
346 "pmullw %%mm7, %%mm4 \n\t"
348 "movq %%mm2, 2*8(%%"REG_D") \n\t"
349 "movq 6*8(%%"REG_S"), %%mm6 \n\t"
350 "pmullw %%mm7, %%mm5 \n\t"
352 "movq %%mm3, 3*8(%%"REG_D") \n\t"
353 "movq 7*8+0*8(%%"REG_S"), %%mm0 \n\t"
354 "pmullw %%mm7, %%mm6 \n\t"
356 "movq %%mm4, 4*8(%%"REG_D") \n\t"
357 "movq 7*8+1*8(%%"REG_S"), %%mm1 \n\t"
358 "pmullw %%mm7, %%mm0 \n\t"
360 "movq %%mm5, 5*8(%%"REG_D") \n\t"
361 "movq 7*8+2*8(%%"REG_S"), %%mm2 \n\t"
362 "pmullw %%mm7, %%mm1 \n\t"
364 "movq %%mm6, 6*8(%%"REG_D") \n\t"
365 "movq 7*8+3*8(%%"REG_S"), %%mm3 \n\t"
366 "pmullw %%mm7, %%mm2 \n\t"
368 "movq %%mm0, 7*8+0*8(%%"REG_D") \n\t"
369 "movq 7*8+4*8(%%"REG_S"), %%mm4 \n\t"
370 "pmullw %%mm7, %%mm3 \n\t"
372 "movq %%mm1, 7*8+1*8(%%"REG_D") \n\t"
373 "movq 7*8+5*8(%%"REG_S"), %%mm5 \n\t"
374 "pmullw %%mm7, %%mm4 \n\t"
376 "movq %%mm2, 7*8+2*8(%%"REG_D") \n\t"
377 "movq 7*8+6*8(%%"REG_S"), %%mm6 \n\t"
378 "pmullw %%mm7, %%mm5 \n\t"
380 "movq %%mm3, 7*8+3*8(%%"REG_D") \n\t"
381 "movq 14*8+0*8(%%"REG_S"), %%mm0 \n\t"
382 "pmullw %%mm7, %%mm6 \n\t"
384 "movq %%mm4, 7*8+4*8(%%"REG_D") \n\t"
385 "movq 14*8+1*8(%%"REG_S"), %%mm1 \n\t"
386 "pmullw %%mm7, %%mm0 \n\t"
388 "movq %%mm5, 7*8+5*8(%%"REG_D") \n\t"
389 "pmullw %%mm7, %%mm1 \n\t"
391 "movq %%mm6, 7*8+6*8(%%"REG_D") \n\t"
392 "movq %%mm0, 14*8+0*8(%%"REG_D") \n\t"
393 "movq %%mm1, 14*8+1*8(%%"REG_D") \n\t"
395 : "+g" (q), "+S" (adr), "+D" (adr)
400 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
401 static void row_idct_mmx(DCTELEM* workspace,
402 int16_t* output_adr, int output_stride, int cnt);
403 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
405 #define store_slice_s store_slice_mmx
406 #define store_slice2_s store_slice2_mmx
407 #define mul_thrmat_s mul_thrmat_mmx
408 #define column_fidct_s column_fidct_mmx
409 #define row_idct_s row_idct_mmx
410 #define row_fdct_s row_fdct_mmx
411 #endif // HAVE_MMX
413 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
414 int dst_stride, int src_stride,
415 int width, int height,
416 uint8_t *qp_store, int qp_stride, int is_luma)
418 int x, x0, y, es, qy, t;
419 const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15))
420 const int step=6-p->log2_count;
421 const int qps= 3 + is_luma;
422 int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
423 DCTELEM *block= (DCTELEM *)block_align;
424 DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ);
426 memset(block3, 0, 4*8*BLOCKSZ);
428 //p->src=src-src_stride*8-8;//!
429 if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
430 for(y=0; y<height; y++){
431 int index= 8 + 8*stride + y*stride;
432 fast_memcpy(p->src + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers
433 for(x=0; x<8; x++){
434 p->src[index - x - 1]= p->src[index + x ];
435 p->src[index + width + x ]= p->src[index + width - x - 1];
438 for(y=0; y<8; y++){
439 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
440 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
442 //FIXME (try edge emu)
444 for(y=8; y<24; y++)
445 memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t));
447 for(y=step; y<height+8; y+=step){ //step= 1,2
448 qy=y-4;
449 if (qy>height-1) qy=height-1;
450 if (qy<0) qy=0;
451 qy=(qy>>qps)*qp_stride;
452 row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2);
453 for(x0=0; x0<width+8-8*(BLOCKSZ-1); x0+=8*(BLOCKSZ-1)){
454 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1));
455 if(p->qp)
456 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT
457 else
458 for (x=0; x<8*(BLOCKSZ-1); x+=8) {
459 t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same
460 if (t<0) t=0;//t always < width-2
461 t=qp_store[qy+(t>>qps)];
462 if(p->mpeg2) t>>=1; //copy p->mpeg2,prev_q to locals?
463 if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t);
464 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
466 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
467 memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
468 memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM));
471 es=width+8-x0; // 8, ...
472 if (es>8)
473 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2);
474 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1));
475 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2);
476 {const int y1=y-8+step;//l5-7 l4-6
477 if (!(y1&7) && y1) {
478 if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride,
479 dst_stride, stride, width, 8, 5-p->log2_count);
480 else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride,
481 dst_stride, stride, width, 8, 5-p->log2_count);
485 if (y&7) { // == height & 7
486 if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride,
487 dst_stride, stride, width, y&7, 5-p->log2_count);
488 else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride,
489 dst_stride, stride, width, y&7, 5-p->log2_count);
493 static int config(struct vf_instance_s* vf,
494 int width, int height, int d_width, int d_height,
495 unsigned int flags, unsigned int outfmt)
497 int h= (height+16+15)&(~15);
499 vf->priv->temp_stride= (width+16+15)&(~15);
500 vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t));
501 //this can also be avoided, see above
502 vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
504 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
507 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
509 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
510 // ok, we can do pp in-place (or pp disabled):
511 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
512 mpi->type, mpi->flags, mpi->width, mpi->height);
513 mpi->planes[0]=vf->dmpi->planes[0];
514 mpi->stride[0]=vf->dmpi->stride[0];
515 mpi->width=vf->dmpi->width;
516 if(mpi->flags&MP_IMGFLAG_PLANAR){
517 mpi->planes[1]=vf->dmpi->planes[1];
518 mpi->planes[2]=vf->dmpi->planes[2];
519 mpi->stride[1]=vf->dmpi->stride[1];
520 mpi->stride[2]=vf->dmpi->stride[2];
522 mpi->flags|=MP_IMGFLAG_DIRECT;
525 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
527 mp_image_t *dmpi;
528 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
529 // no DR, so get a new image! hope we'll get DR buffer:
530 dmpi=vf_get_image(vf->next,mpi->imgfmt,
531 MP_IMGTYPE_TEMP,
532 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
533 mpi->width,mpi->height);
534 vf_clone_mpi_attributes(dmpi, mpi);
535 }else{
536 dmpi=vf->dmpi;
539 vf->priv->mpeg2= mpi->qscale_type;
540 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
541 if(!vf->priv->non_b_qp)
542 vf->priv->non_b_qp= malloc(mpi->qstride * ((mpi->h + 15) >> 4));
543 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, mpi->qstride * ((mpi->h + 15) >> 4));
545 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
546 char *qp_tab= vf->priv->non_b_qp;
547 if(vf->priv->bframes || !qp_tab)
548 qp_tab= mpi->qscale;
550 if(qp_tab || vf->priv->qp){
551 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
552 mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
553 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
554 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
555 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
556 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
557 }else{
558 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
559 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]);
560 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]);
564 #if HAVE_MMX
565 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
566 #endif
567 #if HAVE_MMX2
568 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
569 #endif
570 return vf_next_put_image(vf,dmpi, pts);
573 static void uninit(struct vf_instance_s* vf)
575 if(!vf->priv) return;
577 if(vf->priv->temp) av_free(vf->priv->temp);
578 vf->priv->temp= NULL;
579 if(vf->priv->src) av_free(vf->priv->src);
580 vf->priv->src= NULL;
581 //if(vf->priv->avctx) free(vf->priv->avctx);
582 //vf->priv->avctx= NULL;
583 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp);
584 vf->priv->non_b_qp= NULL;
586 av_free(vf->priv);
587 vf->priv=NULL;
590 //===========================================================================//
592 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
594 switch(fmt){
595 case IMGFMT_YVU9:
596 case IMGFMT_IF09:
597 case IMGFMT_YV12:
598 case IMGFMT_I420:
599 case IMGFMT_IYUV:
600 case IMGFMT_CLPL:
601 case IMGFMT_Y800:
602 case IMGFMT_Y8:
603 case IMGFMT_444P:
604 case IMGFMT_422P:
605 case IMGFMT_411P:
606 return vf_next_query_format(vf,fmt);
608 return 0;
611 static int control(struct vf_instance_s* vf, int request, void* data)
613 switch(request){
614 case VFCTRL_QUERY_MAX_PP_LEVEL:
615 return 5;
616 case VFCTRL_SET_PP_LEVEL:
617 vf->priv->log2_count= *((unsigned int*)data);
618 if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
619 return CONTROL_TRUE;
621 return vf_next_control(vf,request,data);
624 static int open(vf_instance_t *vf, char* args)
626 int i=0, bias;
627 int custom_threshold_m[64];
628 int log2c=-1;
630 vf->config=config;
631 vf->put_image=put_image;
632 vf->get_image=get_image;
633 vf->query_format=query_format;
634 vf->uninit=uninit;
635 vf->control= control;
636 vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
638 avcodec_init();
640 //vf->priv->avctx= avcodec_alloc_context();
641 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
643 vf->priv->log2_count= 4;
644 vf->priv->bframes = 0;
646 if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
648 if( log2c >=4 && log2c <=5 )
649 vf->priv->log2_count = log2c;
650 else if( log2c >= 6 )
651 vf->priv->log2_count = 5;
653 if(vf->priv->qp < 0)
654 vf->priv->qp = 0;
656 if (i < -15) i = -15;
657 if (i > 32) i = 32;
659 bias= (1<<4)+i; //regulable
660 vf->priv->prev_q=0;
662 for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
663 custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
664 for(i=0;i<8;i++){
665 vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
666 |(((uint64_t)custom_threshold_m[i*8+6])<<16)
667 |(((uint64_t)custom_threshold_m[i*8+0])<<32)
668 |(((uint64_t)custom_threshold_m[i*8+4])<<48);
669 vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
670 |(((uint64_t)custom_threshold_m[i*8+3])<<16)
671 |(((uint64_t)custom_threshold_m[i*8+1])<<32)
672 |(((uint64_t)custom_threshold_m[i*8+7])<<48);
675 if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
677 return 1;
680 const vf_info_t vf_info_fspp = {
681 "fast simple postprocess",
682 "fspp",
683 "Michael Niedermayer, Nikolaj Poroshin",
685 open,
686 NULL
689 //====================================================================
690 //Specific spp's dct, idct and threshold functions
691 //I'd prefer to have them in the separate file.
693 #include "mangle.h"
694 //#define MANGLE(a) #a
696 //typedef int16_t DCTELEM; //! only int16_t
698 #define DCTSIZE 8
699 #define DCTSIZE_S "8"
701 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
702 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
703 #define FIX64(x,s) C64(FIX(x,s))
705 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
706 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
707 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
709 #if HAVE_MMX
711 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
712 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14);
713 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14);
714 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
716 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
718 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
719 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
720 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
721 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
722 //for t3,t5,t7 == 0 shortcut
723 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
724 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
725 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
727 DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
728 DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
730 #else /* !HAVE_MMX */
732 typedef int32_t int_simd16_t;
733 static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
734 static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
735 static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
736 static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
737 static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
738 static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
739 static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
740 static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
741 static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
743 #endif
745 #if !HAVE_MMX
747 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
749 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
750 int_simd16_t tmp10, tmp11, tmp12, tmp13;
751 int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
752 int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
754 DCTELEM* dataptr;
755 DCTELEM* wsptr;
756 int16_t *threshold;
757 int ctr;
759 dataptr = data;
760 wsptr = output;
762 for (; cnt > 0; cnt-=2) { //start positions
763 threshold=(int16_t*)thr_adr;//threshold_mtx
764 for (ctr = DCTSIZE; ctr > 0; ctr--) {
765 // Process columns from input, add to output.
766 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
767 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
769 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
770 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
772 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
773 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
775 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
776 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
778 // Even part of FDCT
780 tmp10 = tmp0 + tmp3;
781 tmp13 = tmp0 - tmp3;
782 tmp11 = tmp1 + tmp2;
783 tmp12 = tmp1 - tmp2;
785 d0 = tmp10 + tmp11;
786 d4 = tmp10 - tmp11;
788 z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
789 d2 = tmp13 + z1;
790 d6 = tmp13 - z1;
792 // Even part of IDCT
794 THRESHOLD(tmp0, d0, threshold[0*8]);
795 THRESHOLD(tmp1, d2, threshold[2*8]);
796 THRESHOLD(tmp2, d4, threshold[4*8]);
797 THRESHOLD(tmp3, d6, threshold[6*8]);
798 tmp0+=2;
799 tmp10 = (tmp0 + tmp2)>>2;
800 tmp11 = (tmp0 - tmp2)>>2;
802 tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
803 tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
805 tmp0 = tmp10 + tmp13; //->temps
806 tmp3 = tmp10 - tmp13; //->temps
807 tmp1 = tmp11 + tmp12; //->temps
808 tmp2 = tmp11 - tmp12; //->temps
810 // Odd part of FDCT
812 tmp10 = tmp4 + tmp5;
813 tmp11 = tmp5 + tmp6;
814 tmp12 = tmp6 + tmp7;
816 z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
817 z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
818 z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
819 z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
821 z11 = tmp7 + z3;
822 z13 = tmp7 - z3;
824 d5 = z13 + z2;
825 d3 = z13 - z2;
826 d1 = z11 + z4;
827 d7 = z11 - z4;
829 // Odd part of IDCT
831 THRESHOLD(tmp4, d1, threshold[1*8]);
832 THRESHOLD(tmp5, d3, threshold[3*8]);
833 THRESHOLD(tmp6, d5, threshold[5*8]);
834 THRESHOLD(tmp7, d7, threshold[7*8]);
836 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
837 z13 = tmp6 + tmp5;
838 z10 = (tmp6 - tmp5)<<1;
839 z11 = tmp4 + tmp7;
840 z12 = (tmp4 - tmp7)<<1;
842 tmp7 = (z11 + z13)>>2; //+2 !
843 tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
844 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
845 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
846 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
848 tmp6 = tmp12 - tmp7;
849 tmp5 = tmp11 - tmp6;
850 tmp4 = tmp10 + tmp5;
852 wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
853 wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
854 wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
855 wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
856 wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
857 wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
858 wsptr[DCTSIZE*6]= (tmp1 - tmp6);
859 wsptr[DCTSIZE*7]= (tmp0 - tmp7);
861 dataptr++; //next column
862 wsptr++;
863 threshold++;
865 dataptr+=8; //skip each second start pos
866 wsptr +=8;
870 #else /* HAVE_MMX */
872 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
874 uint64_t __attribute__((aligned(8))) temps[4];
875 __asm__ volatile(
876 ASMALIGN(4)
877 "1: \n\t"
878 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
880 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
881 "movq %%mm1, %%mm0 \n\t"
883 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
884 "movq %%mm7, %%mm3 \n\t"
886 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
887 "movq %%mm1, %%mm5 \n\t"
889 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
890 "psubw %%mm7, %%mm1 \n\t" //t13
892 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
893 "movq %%mm6, %%mm4 \n\t"
895 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
896 "paddw %%mm7, %%mm5 \n\t" //t10
898 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
899 "movq %%mm6, %%mm7 \n\t"
901 "paddw %%mm2, %%mm6 \n\t" //t11
902 "psubw %%mm2, %%mm7 \n\t" //t12
904 "movq %%mm5, %%mm2 \n\t"
905 "paddw %%mm6, %%mm5 \n\t" //d0
906 // i0 t13 t12 i3 i1 d0 - d4
907 "psubw %%mm6, %%mm2 \n\t" //d4
908 "paddw %%mm1, %%mm7 \n\t"
910 "movq 4*16(%%"REG_d"), %%mm6 \n\t"
911 "psllw $2, %%mm7 \n\t"
913 "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
914 "psubw %%mm6, %%mm2 \n\t"
916 "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
917 "paddusw %%mm6, %%mm2 \n\t"
919 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
921 "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
922 "paddw %%mm6, %%mm2 \n\t"
924 "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
925 "psubusw %%mm6, %%mm2 \n\t"
927 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
928 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
929 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
930 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
931 "movq %%mm2, %%mm6 \n\t"
933 "paddw %%mm5, %%mm2 \n\t"
934 "psubw %%mm6, %%mm5 \n\t"
936 "movq %%mm1, %%mm6 \n\t"
937 "paddw %%mm7, %%mm1 \n\t" //d2
939 "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
940 "psubw %%mm7, %%mm6 \n\t" //d6
942 "movq 6*16(%%"REG_d"), %%mm7 \n\t"
943 "psraw $2, %%mm5 \n\t"
945 "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
946 "psubw %%mm7, %%mm6 \n\t"
947 // t7 d2 /t11 t4 t6 - d6 /t10
949 "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
950 "paddusw %%mm7, %%mm6 \n\t"
952 "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
953 "paddw %%mm7, %%mm6 \n\t"
955 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
956 "psubusw %%mm7, %%mm6 \n\t"
958 //movq [edi+"DCTSIZE_S"*2*2], mm1
959 //movq [edi+"DCTSIZE_S"*6*2], mm6
960 "movq %%mm1, %%mm7 \n\t"
961 "psraw $2, %%mm2 \n\t"
963 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
964 "psubw %%mm6, %%mm1 \n\t"
966 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
967 "paddw %%mm7, %%mm6 \n\t" //'t13
969 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
970 "movq %%mm2, %%mm7 \n\t"
972 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
973 "paddw %%mm6, %%mm2 \n\t" //'t0
975 "movq %%mm2, 0*8+%3 \n\t" //!
976 "psubw %%mm6, %%mm7 \n\t" //'t3
978 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
979 "psubw %%mm6, %%mm1 \n\t" //'t12
981 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
982 "movq %%mm5, %%mm6 \n\t"
984 "movq %%mm7, 3*8+%3 \n\t"
985 "paddw %%mm2, %%mm3 \n\t" //t10
987 "paddw %%mm4, %%mm2 \n\t" //t11
988 "paddw %%mm0, %%mm4 \n\t" //t12
990 "movq %%mm3, %%mm7 \n\t"
991 "psubw %%mm4, %%mm3 \n\t"
993 "psllw $2, %%mm3 \n\t"
994 "psllw $2, %%mm7 \n\t" //opt for P6
996 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
997 "psllw $2, %%mm4 \n\t"
999 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1000 "psllw $2, %%mm2 \n\t"
1002 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1003 "paddw %%mm1, %%mm5 \n\t" //'t1
1005 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1006 "psubw %%mm1, %%mm6 \n\t" //'t2
1007 // t7 't12 't11 t4 t6 - 't13 't10 ---
1009 "paddw %%mm3, %%mm7 \n\t" //z2
1011 "movq %%mm5, 1*8+%3 \n\t"
1012 "paddw %%mm3, %%mm4 \n\t" //z4
1014 "movq 3*16(%%"REG_d"), %%mm3 \n\t"
1015 "movq %%mm0, %%mm1 \n\t"
1017 "movq %%mm6, 2*8+%3 \n\t"
1018 "psubw %%mm2, %%mm1 \n\t" //z13
1020 //===
1021 "paddw %%mm2, %%mm0 \n\t" //z11
1022 "movq %%mm1, %%mm5 \n\t"
1024 "movq 5*16(%%"REG_d"), %%mm2 \n\t"
1025 "psubw %%mm7, %%mm1 \n\t" //d3
1027 "paddw %%mm7, %%mm5 \n\t" //d5
1028 "psubw %%mm3, %%mm1 \n\t"
1030 "movq 1*16(%%"REG_d"), %%mm7 \n\t"
1031 "psubw %%mm2, %%mm5 \n\t"
1033 "movq %%mm0, %%mm6 \n\t"
1034 "paddw %%mm4, %%mm0 \n\t" //d1
1036 "paddusw %%mm3, %%mm1 \n\t"
1037 "psubw %%mm4, %%mm6 \n\t" //d7
1039 // d1 d3 - - - d5 d7 -
1040 "movq 7*16(%%"REG_d"), %%mm4 \n\t"
1041 "psubw %%mm7, %%mm0 \n\t"
1043 "psubw %%mm4, %%mm6 \n\t"
1044 "paddusw %%mm2, %%mm5 \n\t"
1046 "paddusw %%mm4, %%mm6 \n\t"
1047 "paddw %%mm3, %%mm1 \n\t"
1049 "paddw %%mm2, %%mm5 \n\t"
1050 "paddw %%mm4, %%mm6 \n\t"
1052 "psubusw %%mm3, %%mm1 \n\t"
1053 "psubusw %%mm2, %%mm5 \n\t"
1055 "psubusw %%mm4, %%mm6 \n\t"
1056 "movq %%mm1, %%mm4 \n\t"
1058 "por %%mm5, %%mm4 \n\t"
1059 "paddusw %%mm7, %%mm0 \n\t"
1061 "por %%mm6, %%mm4 \n\t"
1062 "paddw %%mm7, %%mm0 \n\t"
1064 "packssdw %%mm4, %%mm4 \n\t"
1065 "psubusw %%mm7, %%mm0 \n\t"
1067 "movd %%mm4, %%"REG_a" \n\t"
1068 "or %%"REG_a", %%"REG_a" \n\t"
1069 "jnz 2f \n\t"
1070 //movq [edi+"DCTSIZE_S"*3*2], mm1
1071 //movq [edi+"DCTSIZE_S"*5*2], mm5
1072 //movq [edi+"DCTSIZE_S"*1*2], mm0
1073 //movq [edi+"DCTSIZE_S"*7*2], mm6
1074 // t4 t5 - - - t6 t7 -
1075 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1076 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1077 "movq 0*8+%3, %%mm4 \n\t"
1078 "movq %%mm0, %%mm1 \n\t"
1080 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1081 "movq %%mm1, %%mm2 \n\t"
1083 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1084 "movq %%mm2, %%mm3 \n\t"
1086 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1087 "paddw %%mm4, %%mm5 \n\t"
1089 "movq 1*8+%3, %%mm6 \n\t"
1090 //paddw mm3, MM_2
1091 "psraw $2, %%mm3 \n\t" //tmp7
1093 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1094 "psubw %%mm3, %%mm4 \n\t"
1096 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1097 "paddw %%mm3, %%mm5 \n\t"
1099 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1100 "paddw %%mm6, %%mm7 \n\t"
1102 "movq 2*8+%3, %%mm3 \n\t"
1103 "psubw %%mm0, %%mm6 \n\t"
1105 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1106 "paddw %%mm0, %%mm7 \n\t"
1108 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1109 "paddw %%mm3, %%mm4 \n\t"
1111 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1112 "psubw %%mm1, %%mm3 \n\t"
1114 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1115 "paddw %%mm1, %%mm4 \n\t"
1117 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1118 "paddw %%mm3, %%mm5 \n\t"
1120 "movq 3*8+%3, %%mm0 \n\t"
1121 "add $8, %%"REG_S" \n\t"
1123 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1124 "paddw %%mm0, %%mm6 \n\t"
1126 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1127 "psubw %%mm2, %%mm0 \n\t"
1129 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1130 "paddw %%mm2, %%mm6 \n\t"
1132 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1133 "paddw %%mm0, %%mm7 \n\t"
1135 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1137 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1138 "add $8, %%"REG_D" \n\t"
1139 "jmp 4f \n\t"
1141 "2: \n\t"
1142 //--- non DC2
1143 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1144 //psraw mm5, 2
1145 //psraw mm0, 2
1146 //psraw mm6, 2
1147 "movq %%mm5, %%mm3 \n\t"
1148 "psubw %%mm1, %%mm5 \n\t"
1150 "psllw $1, %%mm5 \n\t" //'z10
1151 "paddw %%mm1, %%mm3 \n\t" //'z13
1153 "movq %%mm0, %%mm2 \n\t"
1154 "psubw %%mm6, %%mm0 \n\t"
1156 "movq %%mm5, %%mm1 \n\t"
1157 "psllw $1, %%mm0 \n\t" //'z12
1159 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1160 "paddw %%mm0, %%mm5 \n\t"
1162 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1163 "paddw %%mm6, %%mm2 \n\t" //'z11
1165 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1166 "movq %%mm2, %%mm7 \n\t"
1168 //---
1169 "movq 0*8+%3, %%mm4 \n\t"
1170 "psubw %%mm3, %%mm2 \n\t"
1172 "psllw $1, %%mm2 \n\t"
1173 "paddw %%mm3, %%mm7 \n\t" //'t7
1175 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1176 "movq %%mm4, %%mm6 \n\t"
1177 //paddw mm7, MM_2
1178 "psraw $2, %%mm7 \n\t"
1180 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1181 "psubw %%mm7, %%mm6 \n\t"
1183 "movq 1*8+%3, %%mm3 \n\t"
1184 "paddw %%mm7, %%mm4 \n\t"
1186 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1187 "paddw %%mm5, %%mm1 \n\t" //'t12
1189 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1190 "psubw %%mm7, %%mm1 \n\t" //'t6
1192 "movq 2*8+%3, %%mm7 \n\t"
1193 "psubw %%mm5, %%mm0 \n\t" //'t10
1195 "movq 3*8+%3, %%mm6 \n\t"
1196 "movq %%mm3, %%mm5 \n\t"
1198 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1199 "psubw %%mm1, %%mm5 \n\t"
1201 "psubw %%mm1, %%mm2 \n\t" //'t5
1202 "paddw %%mm1, %%mm3 \n\t"
1204 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1205 "movq %%mm7, %%mm4 \n\t"
1207 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1208 "psubw %%mm2, %%mm4 \n\t"
1210 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1211 "paddw %%mm2, %%mm7 \n\t"
1213 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1214 "paddw %%mm2, %%mm0 \n\t" //'t4
1216 // 't4 't6 't5 - - - - 't7
1217 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1218 "movq %%mm6, %%mm1 \n\t"
1220 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1221 "psubw %%mm0, %%mm1 \n\t"
1223 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1224 "paddw %%mm0, %%mm6 \n\t"
1226 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1227 "add $8, %%"REG_S" \n\t"
1229 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1231 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1232 "add $8, %%"REG_D" \n\t"
1234 "4: \n\t"
1235 //=part 2 (the same)===========================================================
1236 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
1238 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
1239 "movq %%mm1, %%mm0 \n\t"
1241 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
1242 "movq %%mm7, %%mm3 \n\t"
1244 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
1245 "movq %%mm1, %%mm5 \n\t"
1247 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
1248 "psubw %%mm7, %%mm1 \n\t" //t13
1250 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1251 "movq %%mm6, %%mm4 \n\t"
1253 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
1254 "paddw %%mm7, %%mm5 \n\t" //t10
1256 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
1257 "movq %%mm6, %%mm7 \n\t"
1259 "paddw %%mm2, %%mm6 \n\t" //t11
1260 "psubw %%mm2, %%mm7 \n\t" //t12
1262 "movq %%mm5, %%mm2 \n\t"
1263 "paddw %%mm6, %%mm5 \n\t" //d0
1264 // i0 t13 t12 i3 i1 d0 - d4
1265 "psubw %%mm6, %%mm2 \n\t" //d4
1266 "paddw %%mm1, %%mm7 \n\t"
1268 "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
1269 "psllw $2, %%mm7 \n\t"
1271 "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1272 "psubw %%mm6, %%mm2 \n\t"
1274 "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1275 "paddusw %%mm6, %%mm2 \n\t"
1277 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
1279 "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1280 "paddw %%mm6, %%mm2 \n\t"
1282 "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1283 "psubusw %%mm6, %%mm2 \n\t"
1285 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1286 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1287 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1288 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
1289 "movq %%mm2, %%mm6 \n\t"
1291 "paddw %%mm5, %%mm2 \n\t"
1292 "psubw %%mm6, %%mm5 \n\t"
1294 "movq %%mm1, %%mm6 \n\t"
1295 "paddw %%mm7, %%mm1 \n\t" //d2
1297 "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1298 "psubw %%mm7, %%mm6 \n\t" //d6
1300 "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
1301 "psraw $2, %%mm5 \n\t"
1303 "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1304 "psubw %%mm7, %%mm6 \n\t"
1305 // t7 d2 /t11 t4 t6 - d6 /t10
1307 "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1308 "paddusw %%mm7, %%mm6 \n\t"
1310 "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1311 "paddw %%mm7, %%mm6 \n\t"
1313 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
1314 "psubusw %%mm7, %%mm6 \n\t"
1316 //movq [edi+"DCTSIZE_S"*2*2], mm1
1317 //movq [edi+"DCTSIZE_S"*6*2], mm6
1318 "movq %%mm1, %%mm7 \n\t"
1319 "psraw $2, %%mm2 \n\t"
1321 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
1322 "psubw %%mm6, %%mm1 \n\t"
1324 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
1325 "paddw %%mm7, %%mm6 \n\t" //'t13
1327 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1328 "movq %%mm2, %%mm7 \n\t"
1330 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
1331 "paddw %%mm6, %%mm2 \n\t" //'t0
1333 "movq %%mm2, 0*8+%3 \n\t" //!
1334 "psubw %%mm6, %%mm7 \n\t" //'t3
1336 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1337 "psubw %%mm6, %%mm1 \n\t" //'t12
1339 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
1340 "movq %%mm5, %%mm6 \n\t"
1342 "movq %%mm7, 3*8+%3 \n\t"
1343 "paddw %%mm2, %%mm3 \n\t" //t10
1345 "paddw %%mm4, %%mm2 \n\t" //t11
1346 "paddw %%mm0, %%mm4 \n\t" //t12
1348 "movq %%mm3, %%mm7 \n\t"
1349 "psubw %%mm4, %%mm3 \n\t"
1351 "psllw $2, %%mm3 \n\t"
1352 "psllw $2, %%mm7 \n\t" //opt for P6
1354 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
1355 "psllw $2, %%mm4 \n\t"
1357 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1358 "psllw $2, %%mm2 \n\t"
1360 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1361 "paddw %%mm1, %%mm5 \n\t" //'t1
1363 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1364 "psubw %%mm1, %%mm6 \n\t" //'t2
1365 // t7 't12 't11 t4 t6 - 't13 't10 ---
1367 "paddw %%mm3, %%mm7 \n\t" //z2
1369 "movq %%mm5, 1*8+%3 \n\t"
1370 "paddw %%mm3, %%mm4 \n\t" //z4
1372 "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
1373 "movq %%mm0, %%mm1 \n\t"
1375 "movq %%mm6, 2*8+%3 \n\t"
1376 "psubw %%mm2, %%mm1 \n\t" //z13
1378 //===
1379 "paddw %%mm2, %%mm0 \n\t" //z11
1380 "movq %%mm1, %%mm5 \n\t"
1382 "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
1383 "psubw %%mm7, %%mm1 \n\t" //d3
1385 "paddw %%mm7, %%mm5 \n\t" //d5
1386 "psubw %%mm3, %%mm1 \n\t"
1388 "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
1389 "psubw %%mm2, %%mm5 \n\t"
1391 "movq %%mm0, %%mm6 \n\t"
1392 "paddw %%mm4, %%mm0 \n\t" //d1
1394 "paddusw %%mm3, %%mm1 \n\t"
1395 "psubw %%mm4, %%mm6 \n\t" //d7
1397 // d1 d3 - - - d5 d7 -
1398 "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
1399 "psubw %%mm7, %%mm0 \n\t"
1401 "psubw %%mm4, %%mm6 \n\t"
1402 "paddusw %%mm2, %%mm5 \n\t"
1404 "paddusw %%mm4, %%mm6 \n\t"
1405 "paddw %%mm3, %%mm1 \n\t"
1407 "paddw %%mm2, %%mm5 \n\t"
1408 "paddw %%mm4, %%mm6 \n\t"
1410 "psubusw %%mm3, %%mm1 \n\t"
1411 "psubusw %%mm2, %%mm5 \n\t"
1413 "psubusw %%mm4, %%mm6 \n\t"
1414 "movq %%mm1, %%mm4 \n\t"
1416 "por %%mm5, %%mm4 \n\t"
1417 "paddusw %%mm7, %%mm0 \n\t"
1419 "por %%mm6, %%mm4 \n\t"
1420 "paddw %%mm7, %%mm0 \n\t"
1422 "packssdw %%mm4, %%mm4 \n\t"
1423 "psubusw %%mm7, %%mm0 \n\t"
1425 "movd %%mm4, %%"REG_a" \n\t"
1426 "or %%"REG_a", %%"REG_a" \n\t"
1427 "jnz 3f \n\t"
1428 //movq [edi+"DCTSIZE_S"*3*2], mm1
1429 //movq [edi+"DCTSIZE_S"*5*2], mm5
1430 //movq [edi+"DCTSIZE_S"*1*2], mm0
1431 //movq [edi+"DCTSIZE_S"*7*2], mm6
1432 // t4 t5 - - - t6 t7 -
1433 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1434 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1435 "movq 0*8+%3, %%mm4 \n\t"
1436 "movq %%mm0, %%mm1 \n\t"
1438 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1439 "movq %%mm1, %%mm2 \n\t"
1441 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1442 "movq %%mm2, %%mm3 \n\t"
1444 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1445 "paddw %%mm4, %%mm5 \n\t"
1447 "movq 1*8+%3, %%mm6 \n\t"
1448 //paddw mm3, MM_2
1449 "psraw $2, %%mm3 \n\t" //tmp7
1451 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1452 "psubw %%mm3, %%mm4 \n\t"
1454 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1455 "paddw %%mm3, %%mm5 \n\t"
1457 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1458 "paddw %%mm6, %%mm7 \n\t"
1460 "movq 2*8+%3, %%mm3 \n\t"
1461 "psubw %%mm0, %%mm6 \n\t"
1463 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1464 "paddw %%mm0, %%mm7 \n\t"
1466 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1467 "paddw %%mm3, %%mm4 \n\t"
1469 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1470 "psubw %%mm1, %%mm3 \n\t"
1472 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1473 "paddw %%mm1, %%mm4 \n\t"
1475 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1476 "paddw %%mm3, %%mm5 \n\t"
1478 "movq 3*8+%3, %%mm0 \n\t"
1479 "add $24, %%"REG_S" \n\t"
1481 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1482 "paddw %%mm0, %%mm6 \n\t"
1484 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1485 "psubw %%mm2, %%mm0 \n\t"
1487 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1488 "paddw %%mm2, %%mm6 \n\t"
1490 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1491 "paddw %%mm0, %%mm7 \n\t"
1493 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1495 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1496 "add $24, %%"REG_D" \n\t"
1497 "sub $2, %%"REG_c" \n\t"
1498 "jnz 1b \n\t"
1499 "jmp 5f \n\t"
1501 "3: \n\t"
1502 //--- non DC2
1503 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1504 //psraw mm5, 2
1505 //psraw mm0, 2
1506 //psraw mm6, 2
1507 "movq %%mm5, %%mm3 \n\t"
1508 "psubw %%mm1, %%mm5 \n\t"
1510 "psllw $1, %%mm5 \n\t" //'z10
1511 "paddw %%mm1, %%mm3 \n\t" //'z13
1513 "movq %%mm0, %%mm2 \n\t"
1514 "psubw %%mm6, %%mm0 \n\t"
1516 "movq %%mm5, %%mm1 \n\t"
1517 "psllw $1, %%mm0 \n\t" //'z12
1519 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1520 "paddw %%mm0, %%mm5 \n\t"
1522 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1523 "paddw %%mm6, %%mm2 \n\t" //'z11
1525 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1526 "movq %%mm2, %%mm7 \n\t"
1528 //---
1529 "movq 0*8+%3, %%mm4 \n\t"
1530 "psubw %%mm3, %%mm2 \n\t"
1532 "psllw $1, %%mm2 \n\t"
1533 "paddw %%mm3, %%mm7 \n\t" //'t7
1535 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1536 "movq %%mm4, %%mm6 \n\t"
1537 //paddw mm7, MM_2
1538 "psraw $2, %%mm7 \n\t"
1540 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1541 "psubw %%mm7, %%mm6 \n\t"
1543 "movq 1*8+%3, %%mm3 \n\t"
1544 "paddw %%mm7, %%mm4 \n\t"
1546 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1547 "paddw %%mm5, %%mm1 \n\t" //'t12
1549 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1550 "psubw %%mm7, %%mm1 \n\t" //'t6
1552 "movq 2*8+%3, %%mm7 \n\t"
1553 "psubw %%mm5, %%mm0 \n\t" //'t10
1555 "movq 3*8+%3, %%mm6 \n\t"
1556 "movq %%mm3, %%mm5 \n\t"
1558 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1559 "psubw %%mm1, %%mm5 \n\t"
1561 "psubw %%mm1, %%mm2 \n\t" //'t5
1562 "paddw %%mm1, %%mm3 \n\t"
1564 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1565 "movq %%mm7, %%mm4 \n\t"
1567 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1568 "psubw %%mm2, %%mm4 \n\t"
1570 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1571 "paddw %%mm2, %%mm7 \n\t"
1573 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1574 "paddw %%mm2, %%mm0 \n\t" //'t4
1576 // 't4 't6 't5 - - - - 't7
1577 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1578 "movq %%mm6, %%mm1 \n\t"
1580 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1581 "psubw %%mm0, %%mm1 \n\t"
1583 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1584 "paddw %%mm0, %%mm6 \n\t"
1586 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1587 "add $24, %%"REG_S" \n\t"
1589 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1591 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1592 "add $24, %%"REG_D" \n\t"
1593 "sub $2, %%"REG_c" \n\t"
1594 "jnz 1b \n\t"
1595 "5: \n\t"
1597 : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
1598 : "d"(thr_adr)
1599 : "%"REG_a
1603 #endif // HAVE_MMX
1605 #if !HAVE_MMX
1607 static void row_idct_c(DCTELEM* workspace,
1608 int16_t* output_adr, int output_stride, int cnt)
1610 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1611 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1612 int_simd16_t z5, z10, z11, z12, z13;
1613 int16_t* outptr;
1614 DCTELEM* wsptr;
1616 cnt*=4;
1617 wsptr = workspace;
1618 outptr = output_adr;
1619 for (; cnt > 0; cnt--) {
1620 // Even part
1621 //Simd version reads 4x4 block and transposes it
1622 tmp10 = ( wsptr[2] + wsptr[3]);
1623 tmp11 = ( wsptr[2] - wsptr[3]);
1625 tmp13 = ( wsptr[0] + wsptr[1]);
1626 tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
1628 tmp0 = tmp10 + tmp13; //->temps
1629 tmp3 = tmp10 - tmp13; //->temps
1630 tmp1 = tmp11 + tmp12;
1631 tmp2 = tmp11 - tmp12;
1633 // Odd part
1634 //Also transpose, with previous:
1635 // ---- ---- ||||
1636 // ---- ---- idct ||||
1637 // ---- ---- ---> ||||
1638 // ---- ---- ||||
1639 z13 = wsptr[4] + wsptr[5];
1640 z10 = wsptr[4] - wsptr[5];
1641 z11 = wsptr[6] + wsptr[7];
1642 z12 = wsptr[6] - wsptr[7];
1644 tmp7 = z11 + z13;
1645 tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
1647 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
1648 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
1649 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
1651 tmp6 = (tmp12<<3) - tmp7;
1652 tmp5 = (tmp11<<3) - tmp6;
1653 tmp4 = (tmp10<<3) + tmp5;
1655 // Final output stage: descale and write column
1656 outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
1657 outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
1658 outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
1659 outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
1660 outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
1661 outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
1662 outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
1663 outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
1664 outptr++;
1666 wsptr += DCTSIZE; // advance pointer to next row
1670 #else /* HAVE_MMX */
1672 static void row_idct_mmx (DCTELEM* workspace,
1673 int16_t* output_adr, int output_stride, int cnt)
1675 uint64_t __attribute__((aligned(8))) temps[4];
1676 __asm__ volatile(
1677 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1678 "1: \n\t"
1679 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
1682 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
1683 "movq %%mm0, %%mm4 \n\t"
1685 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1686 "punpcklwd %%mm1, %%mm0 \n\t"
1688 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
1689 "punpckhwd %%mm1, %%mm4 \n\t"
1691 //transpose 4x4
1692 "movq %%mm2, %%mm7 \n\t"
1693 "punpcklwd %%mm3, %%mm2 \n\t"
1695 "movq %%mm0, %%mm6 \n\t"
1696 "punpckldq %%mm2, %%mm0 \n\t" //0
1698 "punpckhdq %%mm2, %%mm6 \n\t" //1
1699 "movq %%mm0, %%mm5 \n\t"
1701 "punpckhwd %%mm3, %%mm7 \n\t"
1702 "psubw %%mm6, %%mm0 \n\t"
1704 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
1705 "movq %%mm4, %%mm2 \n\t"
1707 "punpckldq %%mm7, %%mm4 \n\t" //2
1708 "paddw %%mm6, %%mm5 \n\t"
1710 "punpckhdq %%mm7, %%mm2 \n\t" //3
1711 "movq %%mm4, %%mm1 \n\t"
1713 "psllw $2, %%mm0 \n\t"
1714 "paddw %%mm2, %%mm4 \n\t" //t10
1716 "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
1717 "psubw %%mm2, %%mm1 \n\t" //t11
1719 "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
1720 "psubw %%mm5, %%mm0 \n\t"
1722 "movq %%mm4, %%mm6 \n\t"
1723 "paddw %%mm5, %%mm4 \n\t" //t0
1725 "psubw %%mm5, %%mm6 \n\t" //t3
1726 "movq %%mm1, %%mm7 \n\t"
1728 "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
1729 "paddw %%mm0, %%mm1 \n\t" //t1
1731 "movq %%mm4, 0*8+%3 \n\t" //t0
1732 "movq %%mm3, %%mm4 \n\t"
1734 "movq %%mm6, 1*8+%3 \n\t" //t3
1735 "punpcklwd %%mm2, %%mm3 \n\t"
1737 //transpose 4x4
1738 "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
1739 "punpckhwd %%mm2, %%mm4 \n\t"
1741 "movq %%mm5, %%mm2 \n\t"
1742 "punpcklwd %%mm6, %%mm5 \n\t"
1744 "psubw %%mm0, %%mm7 \n\t" //t2
1745 "punpckhwd %%mm6, %%mm2 \n\t"
1747 "movq %%mm3, %%mm0 \n\t"
1748 "punpckldq %%mm5, %%mm3 \n\t" //4
1750 "punpckhdq %%mm5, %%mm0 \n\t" //5
1751 "movq %%mm4, %%mm5 \n\t"
1754 "movq %%mm3, %%mm6 \n\t"
1755 "punpckldq %%mm2, %%mm4 \n\t" //6
1757 "psubw %%mm0, %%mm3 \n\t" //z10
1758 "punpckhdq %%mm2, %%mm5 \n\t" //7
1760 "paddw %%mm0, %%mm6 \n\t" //z13
1761 "movq %%mm4, %%mm2 \n\t"
1763 "movq %%mm3, %%mm0 \n\t"
1764 "psubw %%mm5, %%mm4 \n\t" //z12
1766 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
1767 "paddw %%mm4, %%mm3 \n\t"
1769 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
1770 "paddw %%mm5, %%mm2 \n\t" //z11 >
1772 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
1773 "movq %%mm2, %%mm5 \n\t"
1775 "psubw %%mm6, %%mm2 \n\t"
1776 "paddw %%mm6, %%mm5 \n\t" //t7
1778 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
1779 "paddw %%mm3, %%mm0 \n\t" //t12
1781 "psllw $3, %%mm0 \n\t"
1782 "psubw %%mm3, %%mm4 \n\t" //t10
1784 "movq 0*8+%3, %%mm6 \n\t"
1785 "movq %%mm1, %%mm3 \n\t"
1787 "psllw $3, %%mm4 \n\t"
1788 "psubw %%mm5, %%mm0 \n\t" //t6
1790 "psllw $3, %%mm2 \n\t"
1791 "paddw %%mm0, %%mm1 \n\t" //d1
1793 "psubw %%mm0, %%mm2 \n\t" //t5
1794 "psubw %%mm0, %%mm3 \n\t" //d6
1796 "paddw %%mm2, %%mm4 \n\t" //t4
1797 "movq %%mm7, %%mm0 \n\t"
1799 "paddw %%mm2, %%mm7 \n\t" //d2
1800 "psubw %%mm2, %%mm0 \n\t" //d5
1802 "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
1803 "psubw %%mm5, %%mm6 \n\t" //d7
1805 "paddw 0*8+%3, %%mm5 \n\t" //d0
1806 "paddw %%mm2, %%mm1 \n\t"
1808 "paddw %%mm2, %%mm5 \n\t"
1809 "psraw $3, %%mm1 \n\t"
1811 "paddw %%mm2, %%mm7 \n\t"
1812 "psraw $3, %%mm5 \n\t"
1814 "paddw (%%"REG_D"), %%mm5 \n\t"
1815 "psraw $3, %%mm7 \n\t"
1817 "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
1818 "paddw %%mm2, %%mm0 \n\t"
1820 "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
1821 "paddw %%mm2, %%mm3 \n\t"
1823 "movq %%mm5, (%%"REG_D") \n\t"
1824 "paddw %%mm2, %%mm6 \n\t"
1826 "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
1827 "psraw $3, %%mm0 \n\t"
1829 "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
1830 "add %%"REG_d", %%"REG_D" \n\t" //3*ls
1832 "movq 1*8+%3, %%mm5 \n\t" //t3
1833 "psraw $3, %%mm3 \n\t"
1835 "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
1836 "psubw %%mm4, %%mm5 \n\t" //d3
1838 "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
1839 "psraw $3, %%mm6 \n\t"
1841 "paddw 1*8+%3, %%mm4 \n\t" //d4
1842 "paddw %%mm2, %%mm5 \n\t"
1844 "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
1845 "paddw %%mm2, %%mm4 \n\t"
1847 "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
1848 "psraw $3, %%mm5 \n\t"
1850 "paddw (%%"REG_D"), %%mm5 \n\t"
1851 "psraw $3, %%mm4 \n\t"
1853 "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
1854 "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
1856 "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
1857 "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
1858 "movq %%mm5, (%%"REG_D") \n\t"
1859 "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
1861 "sub %%"REG_d", %%"REG_D" \n\t"
1862 "add $8, %%"REG_D" \n\t"
1863 "dec %%"REG_c" \n\t"
1864 "jnz 1b \n\t"
1866 : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
1867 : "a"(output_stride*sizeof(short))
1868 : "%"REG_d
1872 #endif // HAVE_MMX
1874 #if !HAVE_MMX
1876 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1878 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1879 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1880 int_simd16_t z1, z2, z3, z4, z5, z11, z13;
1881 DCTELEM *dataptr;
1883 cnt*=4;
1884 // Pass 1: process rows.
1886 dataptr = data;
1887 for (; cnt > 0; cnt--) {
1888 tmp0 = pixels[line_size*0] + pixels[line_size*7];
1889 tmp7 = pixels[line_size*0] - pixels[line_size*7];
1890 tmp1 = pixels[line_size*1] + pixels[line_size*6];
1891 tmp6 = pixels[line_size*1] - pixels[line_size*6];
1892 tmp2 = pixels[line_size*2] + pixels[line_size*5];
1893 tmp5 = pixels[line_size*2] - pixels[line_size*5];
1894 tmp3 = pixels[line_size*3] + pixels[line_size*4];
1895 tmp4 = pixels[line_size*3] - pixels[line_size*4];
1897 // Even part
1899 tmp10 = tmp0 + tmp3;
1900 tmp13 = tmp0 - tmp3;
1901 tmp11 = tmp1 + tmp2;
1902 tmp12 = tmp1 - tmp2;
1903 //Even columns are written first, this leads to different order of columns
1904 //in column_fidct(), but they are processed independently, so all ok.
1905 //Later in the row_idct() columns readed at the same order.
1906 dataptr[2] = tmp10 + tmp11;
1907 dataptr[3] = tmp10 - tmp11;
1909 z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
1910 dataptr[0] = tmp13 + z1;
1911 dataptr[1] = tmp13 - z1;
1913 // Odd part
1915 tmp10 = (tmp4 + tmp5) <<2;
1916 tmp11 = (tmp5 + tmp6) <<2;
1917 tmp12 = (tmp6 + tmp7) <<2;
1919 z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
1920 z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
1921 z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
1922 z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
1924 z11 = tmp7 + z3;
1925 z13 = tmp7 - z3;
1927 dataptr[4] = z13 + z2;
1928 dataptr[5] = z13 - z2;
1929 dataptr[6] = z11 + z4;
1930 dataptr[7] = z11 - z4;
1932 pixels++; // advance pointer to next column
1933 dataptr += DCTSIZE;
1937 #else /* HAVE_MMX */
1939 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1941 uint64_t __attribute__((aligned(8))) temps[4];
1942 __asm__ volatile(
1943 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1944 "6: \n\t"
1945 "movd (%%"REG_S"), %%mm0 \n\t"
1946 "pxor %%mm7, %%mm7 \n\t"
1948 "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
1949 "punpcklbw %%mm7, %%mm0 \n\t"
1951 "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
1952 "punpcklbw %%mm7, %%mm1 \n\t"
1954 "punpcklbw %%mm7, %%mm2 \n\t"
1955 "add %%"REG_d", %%"REG_S" \n\t"
1957 "movq %%mm0, %%mm5 \n\t"
1960 "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
1961 "movq %%mm1, %%mm6 \n\t"
1963 "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
1964 "punpcklbw %%mm7, %%mm3 \n\t"
1966 "psubw %%mm3, %%mm5 \n\t"
1967 "punpcklbw %%mm7, %%mm4 \n\t"
1969 "paddw %%mm3, %%mm0 \n\t"
1970 "psubw %%mm4, %%mm6 \n\t"
1972 "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
1973 "paddw %%mm4, %%mm1 \n\t"
1975 "movq %%mm5, 0*8+%3 \n\t" //t7
1976 "punpcklbw %%mm7, %%mm3 \n\t"
1978 "movq %%mm6, 1*8+%3 \n\t" //t6
1979 "movq %%mm2, %%mm4 \n\t"
1981 "movd (%%"REG_S"), %%mm5 \n\t" //3
1982 "paddw %%mm3, %%mm2 \n\t"
1984 "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
1985 "punpcklbw %%mm7, %%mm5 \n\t"
1987 "psubw %%mm3, %%mm4 \n\t"
1988 "punpcklbw %%mm7, %%mm6 \n\t"
1990 "movq %%mm5, %%mm3 \n\t"
1991 "paddw %%mm6, %%mm5 \n\t" //t3
1993 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1994 "movq %%mm0, %%mm6 \n\t"
1996 "movq %%mm1, %%mm7 \n\t"
1997 "psubw %%mm5, %%mm0 \n\t" //t13
1999 "psubw %%mm2, %%mm1 \n\t"
2000 "paddw %%mm2, %%mm7 \n\t" //t11
2002 "paddw %%mm0, %%mm1 \n\t"
2003 "movq %%mm7, %%mm2 \n\t"
2005 "psllw $2, %%mm1 \n\t"
2006 "paddw %%mm5, %%mm6 \n\t" //t10
2008 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
2009 "paddw %%mm6, %%mm7 \n\t" //d2
2011 "psubw %%mm2, %%mm6 \n\t" //d3
2012 "movq %%mm0, %%mm5 \n\t"
2014 //transpose 4x4
2015 "movq %%mm7, %%mm2 \n\t"
2016 "punpcklwd %%mm6, %%mm7 \n\t"
2018 "paddw %%mm1, %%mm0 \n\t" //d0
2019 "punpckhwd %%mm6, %%mm2 \n\t"
2021 "psubw %%mm1, %%mm5 \n\t" //d1
2022 "movq %%mm0, %%mm6 \n\t"
2024 "movq 1*8+%3, %%mm1 \n\t"
2025 "punpcklwd %%mm5, %%mm0 \n\t"
2027 "punpckhwd %%mm5, %%mm6 \n\t"
2028 "movq %%mm0, %%mm5 \n\t"
2030 "punpckldq %%mm7, %%mm0 \n\t" //0
2031 "paddw %%mm4, %%mm3 \n\t"
2033 "punpckhdq %%mm7, %%mm5 \n\t" //1
2034 "movq %%mm6, %%mm7 \n\t"
2036 "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
2037 "punpckldq %%mm2, %%mm6 \n\t" //2
2039 "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
2040 "punpckhdq %%mm2, %%mm7 \n\t" //3
2042 "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
2043 "paddw %%mm1, %%mm4 \n\t"
2045 "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
2046 "psllw $2, %%mm3 \n\t" //t10
2048 "movq 0*8+%3, %%mm2 \n\t"
2049 "psllw $2, %%mm4 \n\t" //t11
2051 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
2052 "paddw %%mm2, %%mm1 \n\t"
2054 "psllw $2, %%mm1 \n\t" //t12
2055 "movq %%mm3, %%mm0 \n\t"
2057 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
2058 "psubw %%mm1, %%mm3 \n\t"
2060 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
2061 "movq %%mm2, %%mm5 \n\t"
2063 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
2064 "psubw %%mm4, %%mm2 \n\t" //z13
2066 "paddw %%mm4, %%mm5 \n\t" //z11
2067 "movq %%mm2, %%mm6 \n\t"
2069 "paddw %%mm3, %%mm0 \n\t" //z2
2070 "movq %%mm5, %%mm7 \n\t"
2072 "paddw %%mm0, %%mm2 \n\t" //d4
2073 "psubw %%mm0, %%mm6 \n\t" //d5
2075 "movq %%mm2, %%mm4 \n\t"
2076 "paddw %%mm3, %%mm1 \n\t" //z4
2078 //transpose 4x4
2079 "punpcklwd %%mm6, %%mm2 \n\t"
2080 "paddw %%mm1, %%mm5 \n\t" //d6
2082 "punpckhwd %%mm6, %%mm4 \n\t"
2083 "psubw %%mm1, %%mm7 \n\t" //d7
2085 "movq %%mm5, %%mm6 \n\t"
2086 "punpcklwd %%mm7, %%mm5 \n\t"
2088 "punpckhwd %%mm7, %%mm6 \n\t"
2089 "movq %%mm2, %%mm7 \n\t"
2091 "punpckldq %%mm5, %%mm2 \n\t" //4
2092 "sub %%"REG_d", %%"REG_S" \n\t"
2094 "punpckhdq %%mm5, %%mm7 \n\t" //5
2095 "movq %%mm4, %%mm5 \n\t"
2097 "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2098 "punpckldq %%mm6, %%mm4 \n\t" //6
2100 "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2101 "punpckhdq %%mm6, %%mm5 \n\t" //7
2103 "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2104 "add $4, %%"REG_S" \n\t"
2106 "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2107 "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
2108 "dec %%"REG_c" \n\t"
2109 "jnz 6b \n\t"
2111 : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps)
2112 : "a"(line_size)
2113 : "%"REG_d);
2116 #endif // HAVE_MMX