Remove internal NuppelVideo decoder, the code in libavcodec can decode
[mplayer/glamo.git] / libmpcodecs / vf_fspp.c
blob5acdfb36023ad576b75ffbbc177b4bfe8a665768
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 #if HAVE_MALLOC_H
47 #include <malloc.h>
48 #endif
50 #include "img_format.h"
51 #include "mp_image.h"
52 #include "vf.h"
53 #include "libvo/fastmemcpy.h"
55 #include "libavutil/internal.h"
56 #include "libavutil/intreadwrite.h"
57 #include "libavutil/mem.h"
58 #include "libavcodec/avcodec.h"
59 #include "libavcodec/dsputil.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 //#define MANGLE(a) #a
695 //typedef int16_t DCTELEM; //! only int16_t
697 #define DCTSIZE 8
698 #define DCTSIZE_S "8"
700 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
701 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
702 #define FIX64(x,s) C64(FIX(x,s))
704 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
705 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
706 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
708 #if HAVE_MMX
710 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
711 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14);
712 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14);
713 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
715 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
717 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
718 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
719 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
720 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
721 //for t3,t5,t7 == 0 shortcut
722 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
723 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
724 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
726 DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
727 DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
729 #else /* !HAVE_MMX */
731 typedef int32_t int_simd16_t;
732 static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
733 static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
734 static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
735 static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
736 static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
737 static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
738 static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
739 static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
740 static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
742 #endif
744 #if !HAVE_MMX
746 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
748 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
749 int_simd16_t tmp10, tmp11, tmp12, tmp13;
750 int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
751 int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
753 DCTELEM* dataptr;
754 DCTELEM* wsptr;
755 int16_t *threshold;
756 int ctr;
758 dataptr = data;
759 wsptr = output;
761 for (; cnt > 0; cnt-=2) { //start positions
762 threshold=(int16_t*)thr_adr;//threshold_mtx
763 for (ctr = DCTSIZE; ctr > 0; ctr--) {
764 // Process columns from input, add to output.
765 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
766 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
768 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
769 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
771 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
772 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
774 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
775 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
777 // Even part of FDCT
779 tmp10 = tmp0 + tmp3;
780 tmp13 = tmp0 - tmp3;
781 tmp11 = tmp1 + tmp2;
782 tmp12 = tmp1 - tmp2;
784 d0 = tmp10 + tmp11;
785 d4 = tmp10 - tmp11;
787 z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
788 d2 = tmp13 + z1;
789 d6 = tmp13 - z1;
791 // Even part of IDCT
793 THRESHOLD(tmp0, d0, threshold[0*8]);
794 THRESHOLD(tmp1, d2, threshold[2*8]);
795 THRESHOLD(tmp2, d4, threshold[4*8]);
796 THRESHOLD(tmp3, d6, threshold[6*8]);
797 tmp0+=2;
798 tmp10 = (tmp0 + tmp2)>>2;
799 tmp11 = (tmp0 - tmp2)>>2;
801 tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
802 tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
804 tmp0 = tmp10 + tmp13; //->temps
805 tmp3 = tmp10 - tmp13; //->temps
806 tmp1 = tmp11 + tmp12; //->temps
807 tmp2 = tmp11 - tmp12; //->temps
809 // Odd part of FDCT
811 tmp10 = tmp4 + tmp5;
812 tmp11 = tmp5 + tmp6;
813 tmp12 = tmp6 + tmp7;
815 z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
816 z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
817 z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
818 z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
820 z11 = tmp7 + z3;
821 z13 = tmp7 - z3;
823 d5 = z13 + z2;
824 d3 = z13 - z2;
825 d1 = z11 + z4;
826 d7 = z11 - z4;
828 // Odd part of IDCT
830 THRESHOLD(tmp4, d1, threshold[1*8]);
831 THRESHOLD(tmp5, d3, threshold[3*8]);
832 THRESHOLD(tmp6, d5, threshold[5*8]);
833 THRESHOLD(tmp7, d7, threshold[7*8]);
835 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
836 z13 = tmp6 + tmp5;
837 z10 = (tmp6 - tmp5)<<1;
838 z11 = tmp4 + tmp7;
839 z12 = (tmp4 - tmp7)<<1;
841 tmp7 = (z11 + z13)>>2; //+2 !
842 tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
843 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
844 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
845 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
847 tmp6 = tmp12 - tmp7;
848 tmp5 = tmp11 - tmp6;
849 tmp4 = tmp10 + tmp5;
851 wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
852 wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
853 wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
854 wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
855 wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
856 wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
857 wsptr[DCTSIZE*6]= (tmp1 - tmp6);
858 wsptr[DCTSIZE*7]= (tmp0 - tmp7);
860 dataptr++; //next column
861 wsptr++;
862 threshold++;
864 dataptr+=8; //skip each second start pos
865 wsptr +=8;
869 #else /* HAVE_MMX */
871 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
873 uint64_t __attribute__((aligned(8))) temps[4];
874 __asm__ volatile(
875 ASMALIGN(4)
876 "1: \n\t"
877 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
879 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
880 "movq %%mm1, %%mm0 \n\t"
882 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
883 "movq %%mm7, %%mm3 \n\t"
885 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
886 "movq %%mm1, %%mm5 \n\t"
888 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
889 "psubw %%mm7, %%mm1 \n\t" //t13
891 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
892 "movq %%mm6, %%mm4 \n\t"
894 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
895 "paddw %%mm7, %%mm5 \n\t" //t10
897 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
898 "movq %%mm6, %%mm7 \n\t"
900 "paddw %%mm2, %%mm6 \n\t" //t11
901 "psubw %%mm2, %%mm7 \n\t" //t12
903 "movq %%mm5, %%mm2 \n\t"
904 "paddw %%mm6, %%mm5 \n\t" //d0
905 // i0 t13 t12 i3 i1 d0 - d4
906 "psubw %%mm6, %%mm2 \n\t" //d4
907 "paddw %%mm1, %%mm7 \n\t"
909 "movq 4*16(%%"REG_d"), %%mm6 \n\t"
910 "psllw $2, %%mm7 \n\t"
912 "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
913 "psubw %%mm6, %%mm2 \n\t"
915 "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
916 "paddusw %%mm6, %%mm2 \n\t"
918 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
920 "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
921 "paddw %%mm6, %%mm2 \n\t"
923 "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
924 "psubusw %%mm6, %%mm2 \n\t"
926 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
927 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
928 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
929 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
930 "movq %%mm2, %%mm6 \n\t"
932 "paddw %%mm5, %%mm2 \n\t"
933 "psubw %%mm6, %%mm5 \n\t"
935 "movq %%mm1, %%mm6 \n\t"
936 "paddw %%mm7, %%mm1 \n\t" //d2
938 "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
939 "psubw %%mm7, %%mm6 \n\t" //d6
941 "movq 6*16(%%"REG_d"), %%mm7 \n\t"
942 "psraw $2, %%mm5 \n\t"
944 "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
945 "psubw %%mm7, %%mm6 \n\t"
946 // t7 d2 /t11 t4 t6 - d6 /t10
948 "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
949 "paddusw %%mm7, %%mm6 \n\t"
951 "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
952 "paddw %%mm7, %%mm6 \n\t"
954 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
955 "psubusw %%mm7, %%mm6 \n\t"
957 //movq [edi+"DCTSIZE_S"*2*2], mm1
958 //movq [edi+"DCTSIZE_S"*6*2], mm6
959 "movq %%mm1, %%mm7 \n\t"
960 "psraw $2, %%mm2 \n\t"
962 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
963 "psubw %%mm6, %%mm1 \n\t"
965 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
966 "paddw %%mm7, %%mm6 \n\t" //'t13
968 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
969 "movq %%mm2, %%mm7 \n\t"
971 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
972 "paddw %%mm6, %%mm2 \n\t" //'t0
974 "movq %%mm2, 0*8+%3 \n\t" //!
975 "psubw %%mm6, %%mm7 \n\t" //'t3
977 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
978 "psubw %%mm6, %%mm1 \n\t" //'t12
980 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
981 "movq %%mm5, %%mm6 \n\t"
983 "movq %%mm7, 3*8+%3 \n\t"
984 "paddw %%mm2, %%mm3 \n\t" //t10
986 "paddw %%mm4, %%mm2 \n\t" //t11
987 "paddw %%mm0, %%mm4 \n\t" //t12
989 "movq %%mm3, %%mm7 \n\t"
990 "psubw %%mm4, %%mm3 \n\t"
992 "psllw $2, %%mm3 \n\t"
993 "psllw $2, %%mm7 \n\t" //opt for P6
995 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
996 "psllw $2, %%mm4 \n\t"
998 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
999 "psllw $2, %%mm2 \n\t"
1001 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1002 "paddw %%mm1, %%mm5 \n\t" //'t1
1004 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1005 "psubw %%mm1, %%mm6 \n\t" //'t2
1006 // t7 't12 't11 t4 t6 - 't13 't10 ---
1008 "paddw %%mm3, %%mm7 \n\t" //z2
1010 "movq %%mm5, 1*8+%3 \n\t"
1011 "paddw %%mm3, %%mm4 \n\t" //z4
1013 "movq 3*16(%%"REG_d"), %%mm3 \n\t"
1014 "movq %%mm0, %%mm1 \n\t"
1016 "movq %%mm6, 2*8+%3 \n\t"
1017 "psubw %%mm2, %%mm1 \n\t" //z13
1019 //===
1020 "paddw %%mm2, %%mm0 \n\t" //z11
1021 "movq %%mm1, %%mm5 \n\t"
1023 "movq 5*16(%%"REG_d"), %%mm2 \n\t"
1024 "psubw %%mm7, %%mm1 \n\t" //d3
1026 "paddw %%mm7, %%mm5 \n\t" //d5
1027 "psubw %%mm3, %%mm1 \n\t"
1029 "movq 1*16(%%"REG_d"), %%mm7 \n\t"
1030 "psubw %%mm2, %%mm5 \n\t"
1032 "movq %%mm0, %%mm6 \n\t"
1033 "paddw %%mm4, %%mm0 \n\t" //d1
1035 "paddusw %%mm3, %%mm1 \n\t"
1036 "psubw %%mm4, %%mm6 \n\t" //d7
1038 // d1 d3 - - - d5 d7 -
1039 "movq 7*16(%%"REG_d"), %%mm4 \n\t"
1040 "psubw %%mm7, %%mm0 \n\t"
1042 "psubw %%mm4, %%mm6 \n\t"
1043 "paddusw %%mm2, %%mm5 \n\t"
1045 "paddusw %%mm4, %%mm6 \n\t"
1046 "paddw %%mm3, %%mm1 \n\t"
1048 "paddw %%mm2, %%mm5 \n\t"
1049 "paddw %%mm4, %%mm6 \n\t"
1051 "psubusw %%mm3, %%mm1 \n\t"
1052 "psubusw %%mm2, %%mm5 \n\t"
1054 "psubusw %%mm4, %%mm6 \n\t"
1055 "movq %%mm1, %%mm4 \n\t"
1057 "por %%mm5, %%mm4 \n\t"
1058 "paddusw %%mm7, %%mm0 \n\t"
1060 "por %%mm6, %%mm4 \n\t"
1061 "paddw %%mm7, %%mm0 \n\t"
1063 "packssdw %%mm4, %%mm4 \n\t"
1064 "psubusw %%mm7, %%mm0 \n\t"
1066 "movd %%mm4, %%"REG_a" \n\t"
1067 "or %%"REG_a", %%"REG_a" \n\t"
1068 "jnz 2f \n\t"
1069 //movq [edi+"DCTSIZE_S"*3*2], mm1
1070 //movq [edi+"DCTSIZE_S"*5*2], mm5
1071 //movq [edi+"DCTSIZE_S"*1*2], mm0
1072 //movq [edi+"DCTSIZE_S"*7*2], mm6
1073 // t4 t5 - - - t6 t7 -
1074 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1075 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1076 "movq 0*8+%3, %%mm4 \n\t"
1077 "movq %%mm0, %%mm1 \n\t"
1079 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1080 "movq %%mm1, %%mm2 \n\t"
1082 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1083 "movq %%mm2, %%mm3 \n\t"
1085 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1086 "paddw %%mm4, %%mm5 \n\t"
1088 "movq 1*8+%3, %%mm6 \n\t"
1089 //paddw mm3, MM_2
1090 "psraw $2, %%mm3 \n\t" //tmp7
1092 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1093 "psubw %%mm3, %%mm4 \n\t"
1095 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1096 "paddw %%mm3, %%mm5 \n\t"
1098 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1099 "paddw %%mm6, %%mm7 \n\t"
1101 "movq 2*8+%3, %%mm3 \n\t"
1102 "psubw %%mm0, %%mm6 \n\t"
1104 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1105 "paddw %%mm0, %%mm7 \n\t"
1107 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1108 "paddw %%mm3, %%mm4 \n\t"
1110 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1111 "psubw %%mm1, %%mm3 \n\t"
1113 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1114 "paddw %%mm1, %%mm4 \n\t"
1116 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1117 "paddw %%mm3, %%mm5 \n\t"
1119 "movq 3*8+%3, %%mm0 \n\t"
1120 "add $8, %%"REG_S" \n\t"
1122 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1123 "paddw %%mm0, %%mm6 \n\t"
1125 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1126 "psubw %%mm2, %%mm0 \n\t"
1128 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1129 "paddw %%mm2, %%mm6 \n\t"
1131 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1132 "paddw %%mm0, %%mm7 \n\t"
1134 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1136 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1137 "add $8, %%"REG_D" \n\t"
1138 "jmp 4f \n\t"
1140 "2: \n\t"
1141 //--- non DC2
1142 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1143 //psraw mm5, 2
1144 //psraw mm0, 2
1145 //psraw mm6, 2
1146 "movq %%mm5, %%mm3 \n\t"
1147 "psubw %%mm1, %%mm5 \n\t"
1149 "psllw $1, %%mm5 \n\t" //'z10
1150 "paddw %%mm1, %%mm3 \n\t" //'z13
1152 "movq %%mm0, %%mm2 \n\t"
1153 "psubw %%mm6, %%mm0 \n\t"
1155 "movq %%mm5, %%mm1 \n\t"
1156 "psllw $1, %%mm0 \n\t" //'z12
1158 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1159 "paddw %%mm0, %%mm5 \n\t"
1161 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1162 "paddw %%mm6, %%mm2 \n\t" //'z11
1164 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1165 "movq %%mm2, %%mm7 \n\t"
1167 //---
1168 "movq 0*8+%3, %%mm4 \n\t"
1169 "psubw %%mm3, %%mm2 \n\t"
1171 "psllw $1, %%mm2 \n\t"
1172 "paddw %%mm3, %%mm7 \n\t" //'t7
1174 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1175 "movq %%mm4, %%mm6 \n\t"
1176 //paddw mm7, MM_2
1177 "psraw $2, %%mm7 \n\t"
1179 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1180 "psubw %%mm7, %%mm6 \n\t"
1182 "movq 1*8+%3, %%mm3 \n\t"
1183 "paddw %%mm7, %%mm4 \n\t"
1185 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1186 "paddw %%mm5, %%mm1 \n\t" //'t12
1188 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1189 "psubw %%mm7, %%mm1 \n\t" //'t6
1191 "movq 2*8+%3, %%mm7 \n\t"
1192 "psubw %%mm5, %%mm0 \n\t" //'t10
1194 "movq 3*8+%3, %%mm6 \n\t"
1195 "movq %%mm3, %%mm5 \n\t"
1197 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1198 "psubw %%mm1, %%mm5 \n\t"
1200 "psubw %%mm1, %%mm2 \n\t" //'t5
1201 "paddw %%mm1, %%mm3 \n\t"
1203 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1204 "movq %%mm7, %%mm4 \n\t"
1206 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1207 "psubw %%mm2, %%mm4 \n\t"
1209 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1210 "paddw %%mm2, %%mm7 \n\t"
1212 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1213 "paddw %%mm2, %%mm0 \n\t" //'t4
1215 // 't4 't6 't5 - - - - 't7
1216 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1217 "movq %%mm6, %%mm1 \n\t"
1219 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1220 "psubw %%mm0, %%mm1 \n\t"
1222 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1223 "paddw %%mm0, %%mm6 \n\t"
1225 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1226 "add $8, %%"REG_S" \n\t"
1228 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1230 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1231 "add $8, %%"REG_D" \n\t"
1233 "4: \n\t"
1234 //=part 2 (the same)===========================================================
1235 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
1237 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
1238 "movq %%mm1, %%mm0 \n\t"
1240 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
1241 "movq %%mm7, %%mm3 \n\t"
1243 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
1244 "movq %%mm1, %%mm5 \n\t"
1246 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
1247 "psubw %%mm7, %%mm1 \n\t" //t13
1249 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1250 "movq %%mm6, %%mm4 \n\t"
1252 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
1253 "paddw %%mm7, %%mm5 \n\t" //t10
1255 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
1256 "movq %%mm6, %%mm7 \n\t"
1258 "paddw %%mm2, %%mm6 \n\t" //t11
1259 "psubw %%mm2, %%mm7 \n\t" //t12
1261 "movq %%mm5, %%mm2 \n\t"
1262 "paddw %%mm6, %%mm5 \n\t" //d0
1263 // i0 t13 t12 i3 i1 d0 - d4
1264 "psubw %%mm6, %%mm2 \n\t" //d4
1265 "paddw %%mm1, %%mm7 \n\t"
1267 "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
1268 "psllw $2, %%mm7 \n\t"
1270 "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1271 "psubw %%mm6, %%mm2 \n\t"
1273 "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1274 "paddusw %%mm6, %%mm2 \n\t"
1276 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
1278 "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1279 "paddw %%mm6, %%mm2 \n\t"
1281 "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1282 "psubusw %%mm6, %%mm2 \n\t"
1284 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1285 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1286 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1287 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
1288 "movq %%mm2, %%mm6 \n\t"
1290 "paddw %%mm5, %%mm2 \n\t"
1291 "psubw %%mm6, %%mm5 \n\t"
1293 "movq %%mm1, %%mm6 \n\t"
1294 "paddw %%mm7, %%mm1 \n\t" //d2
1296 "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1297 "psubw %%mm7, %%mm6 \n\t" //d6
1299 "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
1300 "psraw $2, %%mm5 \n\t"
1302 "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1303 "psubw %%mm7, %%mm6 \n\t"
1304 // t7 d2 /t11 t4 t6 - d6 /t10
1306 "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1307 "paddusw %%mm7, %%mm6 \n\t"
1309 "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1310 "paddw %%mm7, %%mm6 \n\t"
1312 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
1313 "psubusw %%mm7, %%mm6 \n\t"
1315 //movq [edi+"DCTSIZE_S"*2*2], mm1
1316 //movq [edi+"DCTSIZE_S"*6*2], mm6
1317 "movq %%mm1, %%mm7 \n\t"
1318 "psraw $2, %%mm2 \n\t"
1320 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
1321 "psubw %%mm6, %%mm1 \n\t"
1323 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
1324 "paddw %%mm7, %%mm6 \n\t" //'t13
1326 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1327 "movq %%mm2, %%mm7 \n\t"
1329 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
1330 "paddw %%mm6, %%mm2 \n\t" //'t0
1332 "movq %%mm2, 0*8+%3 \n\t" //!
1333 "psubw %%mm6, %%mm7 \n\t" //'t3
1335 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1336 "psubw %%mm6, %%mm1 \n\t" //'t12
1338 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
1339 "movq %%mm5, %%mm6 \n\t"
1341 "movq %%mm7, 3*8+%3 \n\t"
1342 "paddw %%mm2, %%mm3 \n\t" //t10
1344 "paddw %%mm4, %%mm2 \n\t" //t11
1345 "paddw %%mm0, %%mm4 \n\t" //t12
1347 "movq %%mm3, %%mm7 \n\t"
1348 "psubw %%mm4, %%mm3 \n\t"
1350 "psllw $2, %%mm3 \n\t"
1351 "psllw $2, %%mm7 \n\t" //opt for P6
1353 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
1354 "psllw $2, %%mm4 \n\t"
1356 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1357 "psllw $2, %%mm2 \n\t"
1359 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1360 "paddw %%mm1, %%mm5 \n\t" //'t1
1362 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1363 "psubw %%mm1, %%mm6 \n\t" //'t2
1364 // t7 't12 't11 t4 t6 - 't13 't10 ---
1366 "paddw %%mm3, %%mm7 \n\t" //z2
1368 "movq %%mm5, 1*8+%3 \n\t"
1369 "paddw %%mm3, %%mm4 \n\t" //z4
1371 "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
1372 "movq %%mm0, %%mm1 \n\t"
1374 "movq %%mm6, 2*8+%3 \n\t"
1375 "psubw %%mm2, %%mm1 \n\t" //z13
1377 //===
1378 "paddw %%mm2, %%mm0 \n\t" //z11
1379 "movq %%mm1, %%mm5 \n\t"
1381 "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
1382 "psubw %%mm7, %%mm1 \n\t" //d3
1384 "paddw %%mm7, %%mm5 \n\t" //d5
1385 "psubw %%mm3, %%mm1 \n\t"
1387 "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
1388 "psubw %%mm2, %%mm5 \n\t"
1390 "movq %%mm0, %%mm6 \n\t"
1391 "paddw %%mm4, %%mm0 \n\t" //d1
1393 "paddusw %%mm3, %%mm1 \n\t"
1394 "psubw %%mm4, %%mm6 \n\t" //d7
1396 // d1 d3 - - - d5 d7 -
1397 "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
1398 "psubw %%mm7, %%mm0 \n\t"
1400 "psubw %%mm4, %%mm6 \n\t"
1401 "paddusw %%mm2, %%mm5 \n\t"
1403 "paddusw %%mm4, %%mm6 \n\t"
1404 "paddw %%mm3, %%mm1 \n\t"
1406 "paddw %%mm2, %%mm5 \n\t"
1407 "paddw %%mm4, %%mm6 \n\t"
1409 "psubusw %%mm3, %%mm1 \n\t"
1410 "psubusw %%mm2, %%mm5 \n\t"
1412 "psubusw %%mm4, %%mm6 \n\t"
1413 "movq %%mm1, %%mm4 \n\t"
1415 "por %%mm5, %%mm4 \n\t"
1416 "paddusw %%mm7, %%mm0 \n\t"
1418 "por %%mm6, %%mm4 \n\t"
1419 "paddw %%mm7, %%mm0 \n\t"
1421 "packssdw %%mm4, %%mm4 \n\t"
1422 "psubusw %%mm7, %%mm0 \n\t"
1424 "movd %%mm4, %%"REG_a" \n\t"
1425 "or %%"REG_a", %%"REG_a" \n\t"
1426 "jnz 3f \n\t"
1427 //movq [edi+"DCTSIZE_S"*3*2], mm1
1428 //movq [edi+"DCTSIZE_S"*5*2], mm5
1429 //movq [edi+"DCTSIZE_S"*1*2], mm0
1430 //movq [edi+"DCTSIZE_S"*7*2], mm6
1431 // t4 t5 - - - t6 t7 -
1432 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1433 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1434 "movq 0*8+%3, %%mm4 \n\t"
1435 "movq %%mm0, %%mm1 \n\t"
1437 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1438 "movq %%mm1, %%mm2 \n\t"
1440 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1441 "movq %%mm2, %%mm3 \n\t"
1443 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1444 "paddw %%mm4, %%mm5 \n\t"
1446 "movq 1*8+%3, %%mm6 \n\t"
1447 //paddw mm3, MM_2
1448 "psraw $2, %%mm3 \n\t" //tmp7
1450 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1451 "psubw %%mm3, %%mm4 \n\t"
1453 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1454 "paddw %%mm3, %%mm5 \n\t"
1456 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1457 "paddw %%mm6, %%mm7 \n\t"
1459 "movq 2*8+%3, %%mm3 \n\t"
1460 "psubw %%mm0, %%mm6 \n\t"
1462 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1463 "paddw %%mm0, %%mm7 \n\t"
1465 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1466 "paddw %%mm3, %%mm4 \n\t"
1468 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1469 "psubw %%mm1, %%mm3 \n\t"
1471 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1472 "paddw %%mm1, %%mm4 \n\t"
1474 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1475 "paddw %%mm3, %%mm5 \n\t"
1477 "movq 3*8+%3, %%mm0 \n\t"
1478 "add $24, %%"REG_S" \n\t"
1480 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1481 "paddw %%mm0, %%mm6 \n\t"
1483 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1484 "psubw %%mm2, %%mm0 \n\t"
1486 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1487 "paddw %%mm2, %%mm6 \n\t"
1489 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1490 "paddw %%mm0, %%mm7 \n\t"
1492 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1494 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1495 "add $24, %%"REG_D" \n\t"
1496 "sub $2, %%"REG_c" \n\t"
1497 "jnz 1b \n\t"
1498 "jmp 5f \n\t"
1500 "3: \n\t"
1501 //--- non DC2
1502 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1503 //psraw mm5, 2
1504 //psraw mm0, 2
1505 //psraw mm6, 2
1506 "movq %%mm5, %%mm3 \n\t"
1507 "psubw %%mm1, %%mm5 \n\t"
1509 "psllw $1, %%mm5 \n\t" //'z10
1510 "paddw %%mm1, %%mm3 \n\t" //'z13
1512 "movq %%mm0, %%mm2 \n\t"
1513 "psubw %%mm6, %%mm0 \n\t"
1515 "movq %%mm5, %%mm1 \n\t"
1516 "psllw $1, %%mm0 \n\t" //'z12
1518 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1519 "paddw %%mm0, %%mm5 \n\t"
1521 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1522 "paddw %%mm6, %%mm2 \n\t" //'z11
1524 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1525 "movq %%mm2, %%mm7 \n\t"
1527 //---
1528 "movq 0*8+%3, %%mm4 \n\t"
1529 "psubw %%mm3, %%mm2 \n\t"
1531 "psllw $1, %%mm2 \n\t"
1532 "paddw %%mm3, %%mm7 \n\t" //'t7
1534 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1535 "movq %%mm4, %%mm6 \n\t"
1536 //paddw mm7, MM_2
1537 "psraw $2, %%mm7 \n\t"
1539 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1540 "psubw %%mm7, %%mm6 \n\t"
1542 "movq 1*8+%3, %%mm3 \n\t"
1543 "paddw %%mm7, %%mm4 \n\t"
1545 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1546 "paddw %%mm5, %%mm1 \n\t" //'t12
1548 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1549 "psubw %%mm7, %%mm1 \n\t" //'t6
1551 "movq 2*8+%3, %%mm7 \n\t"
1552 "psubw %%mm5, %%mm0 \n\t" //'t10
1554 "movq 3*8+%3, %%mm6 \n\t"
1555 "movq %%mm3, %%mm5 \n\t"
1557 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1558 "psubw %%mm1, %%mm5 \n\t"
1560 "psubw %%mm1, %%mm2 \n\t" //'t5
1561 "paddw %%mm1, %%mm3 \n\t"
1563 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1564 "movq %%mm7, %%mm4 \n\t"
1566 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1567 "psubw %%mm2, %%mm4 \n\t"
1569 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1570 "paddw %%mm2, %%mm7 \n\t"
1572 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1573 "paddw %%mm2, %%mm0 \n\t" //'t4
1575 // 't4 't6 't5 - - - - 't7
1576 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1577 "movq %%mm6, %%mm1 \n\t"
1579 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1580 "psubw %%mm0, %%mm1 \n\t"
1582 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1583 "paddw %%mm0, %%mm6 \n\t"
1585 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1586 "add $24, %%"REG_S" \n\t"
1588 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1590 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1591 "add $24, %%"REG_D" \n\t"
1592 "sub $2, %%"REG_c" \n\t"
1593 "jnz 1b \n\t"
1594 "5: \n\t"
1596 : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
1597 : "d"(thr_adr)
1598 : "%"REG_a
1602 #endif // HAVE_MMX
1604 #if !HAVE_MMX
1606 static void row_idct_c(DCTELEM* workspace,
1607 int16_t* output_adr, int output_stride, int cnt)
1609 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1610 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1611 int_simd16_t z5, z10, z11, z12, z13;
1612 int16_t* outptr;
1613 DCTELEM* wsptr;
1615 cnt*=4;
1616 wsptr = workspace;
1617 outptr = output_adr;
1618 for (; cnt > 0; cnt--) {
1619 // Even part
1620 //Simd version reads 4x4 block and transposes it
1621 tmp10 = ( wsptr[2] + wsptr[3]);
1622 tmp11 = ( wsptr[2] - wsptr[3]);
1624 tmp13 = ( wsptr[0] + wsptr[1]);
1625 tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
1627 tmp0 = tmp10 + tmp13; //->temps
1628 tmp3 = tmp10 - tmp13; //->temps
1629 tmp1 = tmp11 + tmp12;
1630 tmp2 = tmp11 - tmp12;
1632 // Odd part
1633 //Also transpose, with previous:
1634 // ---- ---- ||||
1635 // ---- ---- idct ||||
1636 // ---- ---- ---> ||||
1637 // ---- ---- ||||
1638 z13 = wsptr[4] + wsptr[5];
1639 z10 = wsptr[4] - wsptr[5];
1640 z11 = wsptr[6] + wsptr[7];
1641 z12 = wsptr[6] - wsptr[7];
1643 tmp7 = z11 + z13;
1644 tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
1646 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
1647 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
1648 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
1650 tmp6 = (tmp12<<3) - tmp7;
1651 tmp5 = (tmp11<<3) - tmp6;
1652 tmp4 = (tmp10<<3) + tmp5;
1654 // Final output stage: descale and write column
1655 outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
1656 outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
1657 outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
1658 outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
1659 outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
1660 outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
1661 outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
1662 outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
1663 outptr++;
1665 wsptr += DCTSIZE; // advance pointer to next row
1669 #else /* HAVE_MMX */
1671 static void row_idct_mmx (DCTELEM* workspace,
1672 int16_t* output_adr, int output_stride, int cnt)
1674 uint64_t __attribute__((aligned(8))) temps[4];
1675 __asm__ volatile(
1676 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1677 "1: \n\t"
1678 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
1681 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
1682 "movq %%mm0, %%mm4 \n\t"
1684 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1685 "punpcklwd %%mm1, %%mm0 \n\t"
1687 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
1688 "punpckhwd %%mm1, %%mm4 \n\t"
1690 //transpose 4x4
1691 "movq %%mm2, %%mm7 \n\t"
1692 "punpcklwd %%mm3, %%mm2 \n\t"
1694 "movq %%mm0, %%mm6 \n\t"
1695 "punpckldq %%mm2, %%mm0 \n\t" //0
1697 "punpckhdq %%mm2, %%mm6 \n\t" //1
1698 "movq %%mm0, %%mm5 \n\t"
1700 "punpckhwd %%mm3, %%mm7 \n\t"
1701 "psubw %%mm6, %%mm0 \n\t"
1703 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
1704 "movq %%mm4, %%mm2 \n\t"
1706 "punpckldq %%mm7, %%mm4 \n\t" //2
1707 "paddw %%mm6, %%mm5 \n\t"
1709 "punpckhdq %%mm7, %%mm2 \n\t" //3
1710 "movq %%mm4, %%mm1 \n\t"
1712 "psllw $2, %%mm0 \n\t"
1713 "paddw %%mm2, %%mm4 \n\t" //t10
1715 "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
1716 "psubw %%mm2, %%mm1 \n\t" //t11
1718 "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
1719 "psubw %%mm5, %%mm0 \n\t"
1721 "movq %%mm4, %%mm6 \n\t"
1722 "paddw %%mm5, %%mm4 \n\t" //t0
1724 "psubw %%mm5, %%mm6 \n\t" //t3
1725 "movq %%mm1, %%mm7 \n\t"
1727 "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
1728 "paddw %%mm0, %%mm1 \n\t" //t1
1730 "movq %%mm4, 0*8+%3 \n\t" //t0
1731 "movq %%mm3, %%mm4 \n\t"
1733 "movq %%mm6, 1*8+%3 \n\t" //t3
1734 "punpcklwd %%mm2, %%mm3 \n\t"
1736 //transpose 4x4
1737 "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
1738 "punpckhwd %%mm2, %%mm4 \n\t"
1740 "movq %%mm5, %%mm2 \n\t"
1741 "punpcklwd %%mm6, %%mm5 \n\t"
1743 "psubw %%mm0, %%mm7 \n\t" //t2
1744 "punpckhwd %%mm6, %%mm2 \n\t"
1746 "movq %%mm3, %%mm0 \n\t"
1747 "punpckldq %%mm5, %%mm3 \n\t" //4
1749 "punpckhdq %%mm5, %%mm0 \n\t" //5
1750 "movq %%mm4, %%mm5 \n\t"
1753 "movq %%mm3, %%mm6 \n\t"
1754 "punpckldq %%mm2, %%mm4 \n\t" //6
1756 "psubw %%mm0, %%mm3 \n\t" //z10
1757 "punpckhdq %%mm2, %%mm5 \n\t" //7
1759 "paddw %%mm0, %%mm6 \n\t" //z13
1760 "movq %%mm4, %%mm2 \n\t"
1762 "movq %%mm3, %%mm0 \n\t"
1763 "psubw %%mm5, %%mm4 \n\t" //z12
1765 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
1766 "paddw %%mm4, %%mm3 \n\t"
1768 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
1769 "paddw %%mm5, %%mm2 \n\t" //z11 >
1771 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
1772 "movq %%mm2, %%mm5 \n\t"
1774 "psubw %%mm6, %%mm2 \n\t"
1775 "paddw %%mm6, %%mm5 \n\t" //t7
1777 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
1778 "paddw %%mm3, %%mm0 \n\t" //t12
1780 "psllw $3, %%mm0 \n\t"
1781 "psubw %%mm3, %%mm4 \n\t" //t10
1783 "movq 0*8+%3, %%mm6 \n\t"
1784 "movq %%mm1, %%mm3 \n\t"
1786 "psllw $3, %%mm4 \n\t"
1787 "psubw %%mm5, %%mm0 \n\t" //t6
1789 "psllw $3, %%mm2 \n\t"
1790 "paddw %%mm0, %%mm1 \n\t" //d1
1792 "psubw %%mm0, %%mm2 \n\t" //t5
1793 "psubw %%mm0, %%mm3 \n\t" //d6
1795 "paddw %%mm2, %%mm4 \n\t" //t4
1796 "movq %%mm7, %%mm0 \n\t"
1798 "paddw %%mm2, %%mm7 \n\t" //d2
1799 "psubw %%mm2, %%mm0 \n\t" //d5
1801 "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
1802 "psubw %%mm5, %%mm6 \n\t" //d7
1804 "paddw 0*8+%3, %%mm5 \n\t" //d0
1805 "paddw %%mm2, %%mm1 \n\t"
1807 "paddw %%mm2, %%mm5 \n\t"
1808 "psraw $3, %%mm1 \n\t"
1810 "paddw %%mm2, %%mm7 \n\t"
1811 "psraw $3, %%mm5 \n\t"
1813 "paddw (%%"REG_D"), %%mm5 \n\t"
1814 "psraw $3, %%mm7 \n\t"
1816 "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
1817 "paddw %%mm2, %%mm0 \n\t"
1819 "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
1820 "paddw %%mm2, %%mm3 \n\t"
1822 "movq %%mm5, (%%"REG_D") \n\t"
1823 "paddw %%mm2, %%mm6 \n\t"
1825 "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
1826 "psraw $3, %%mm0 \n\t"
1828 "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
1829 "add %%"REG_d", %%"REG_D" \n\t" //3*ls
1831 "movq 1*8+%3, %%mm5 \n\t" //t3
1832 "psraw $3, %%mm3 \n\t"
1834 "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
1835 "psubw %%mm4, %%mm5 \n\t" //d3
1837 "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
1838 "psraw $3, %%mm6 \n\t"
1840 "paddw 1*8+%3, %%mm4 \n\t" //d4
1841 "paddw %%mm2, %%mm5 \n\t"
1843 "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
1844 "paddw %%mm2, %%mm4 \n\t"
1846 "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
1847 "psraw $3, %%mm5 \n\t"
1849 "paddw (%%"REG_D"), %%mm5 \n\t"
1850 "psraw $3, %%mm4 \n\t"
1852 "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
1853 "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
1855 "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
1856 "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
1857 "movq %%mm5, (%%"REG_D") \n\t"
1858 "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
1860 "sub %%"REG_d", %%"REG_D" \n\t"
1861 "add $8, %%"REG_D" \n\t"
1862 "dec %%"REG_c" \n\t"
1863 "jnz 1b \n\t"
1865 : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
1866 : "a"(output_stride*sizeof(short))
1867 : "%"REG_d
1871 #endif // HAVE_MMX
1873 #if !HAVE_MMX
1875 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1877 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1878 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1879 int_simd16_t z1, z2, z3, z4, z5, z11, z13;
1880 DCTELEM *dataptr;
1882 cnt*=4;
1883 // Pass 1: process rows.
1885 dataptr = data;
1886 for (; cnt > 0; cnt--) {
1887 tmp0 = pixels[line_size*0] + pixels[line_size*7];
1888 tmp7 = pixels[line_size*0] - pixels[line_size*7];
1889 tmp1 = pixels[line_size*1] + pixels[line_size*6];
1890 tmp6 = pixels[line_size*1] - pixels[line_size*6];
1891 tmp2 = pixels[line_size*2] + pixels[line_size*5];
1892 tmp5 = pixels[line_size*2] - pixels[line_size*5];
1893 tmp3 = pixels[line_size*3] + pixels[line_size*4];
1894 tmp4 = pixels[line_size*3] - pixels[line_size*4];
1896 // Even part
1898 tmp10 = tmp0 + tmp3;
1899 tmp13 = tmp0 - tmp3;
1900 tmp11 = tmp1 + tmp2;
1901 tmp12 = tmp1 - tmp2;
1902 //Even columns are written first, this leads to different order of columns
1903 //in column_fidct(), but they are processed independently, so all ok.
1904 //Later in the row_idct() columns readed at the same order.
1905 dataptr[2] = tmp10 + tmp11;
1906 dataptr[3] = tmp10 - tmp11;
1908 z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
1909 dataptr[0] = tmp13 + z1;
1910 dataptr[1] = tmp13 - z1;
1912 // Odd part
1914 tmp10 = (tmp4 + tmp5) <<2;
1915 tmp11 = (tmp5 + tmp6) <<2;
1916 tmp12 = (tmp6 + tmp7) <<2;
1918 z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
1919 z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
1920 z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
1921 z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
1923 z11 = tmp7 + z3;
1924 z13 = tmp7 - z3;
1926 dataptr[4] = z13 + z2;
1927 dataptr[5] = z13 - z2;
1928 dataptr[6] = z11 + z4;
1929 dataptr[7] = z11 - z4;
1931 pixels++; // advance pointer to next column
1932 dataptr += DCTSIZE;
1936 #else /* HAVE_MMX */
1938 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1940 uint64_t __attribute__((aligned(8))) temps[4];
1941 __asm__ volatile(
1942 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1943 "6: \n\t"
1944 "movd (%%"REG_S"), %%mm0 \n\t"
1945 "pxor %%mm7, %%mm7 \n\t"
1947 "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
1948 "punpcklbw %%mm7, %%mm0 \n\t"
1950 "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
1951 "punpcklbw %%mm7, %%mm1 \n\t"
1953 "punpcklbw %%mm7, %%mm2 \n\t"
1954 "add %%"REG_d", %%"REG_S" \n\t"
1956 "movq %%mm0, %%mm5 \n\t"
1959 "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
1960 "movq %%mm1, %%mm6 \n\t"
1962 "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
1963 "punpcklbw %%mm7, %%mm3 \n\t"
1965 "psubw %%mm3, %%mm5 \n\t"
1966 "punpcklbw %%mm7, %%mm4 \n\t"
1968 "paddw %%mm3, %%mm0 \n\t"
1969 "psubw %%mm4, %%mm6 \n\t"
1971 "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
1972 "paddw %%mm4, %%mm1 \n\t"
1974 "movq %%mm5, 0*8+%3 \n\t" //t7
1975 "punpcklbw %%mm7, %%mm3 \n\t"
1977 "movq %%mm6, 1*8+%3 \n\t" //t6
1978 "movq %%mm2, %%mm4 \n\t"
1980 "movd (%%"REG_S"), %%mm5 \n\t" //3
1981 "paddw %%mm3, %%mm2 \n\t"
1983 "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
1984 "punpcklbw %%mm7, %%mm5 \n\t"
1986 "psubw %%mm3, %%mm4 \n\t"
1987 "punpcklbw %%mm7, %%mm6 \n\t"
1989 "movq %%mm5, %%mm3 \n\t"
1990 "paddw %%mm6, %%mm5 \n\t" //t3
1992 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1993 "movq %%mm0, %%mm6 \n\t"
1995 "movq %%mm1, %%mm7 \n\t"
1996 "psubw %%mm5, %%mm0 \n\t" //t13
1998 "psubw %%mm2, %%mm1 \n\t"
1999 "paddw %%mm2, %%mm7 \n\t" //t11
2001 "paddw %%mm0, %%mm1 \n\t"
2002 "movq %%mm7, %%mm2 \n\t"
2004 "psllw $2, %%mm1 \n\t"
2005 "paddw %%mm5, %%mm6 \n\t" //t10
2007 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
2008 "paddw %%mm6, %%mm7 \n\t" //d2
2010 "psubw %%mm2, %%mm6 \n\t" //d3
2011 "movq %%mm0, %%mm5 \n\t"
2013 //transpose 4x4
2014 "movq %%mm7, %%mm2 \n\t"
2015 "punpcklwd %%mm6, %%mm7 \n\t"
2017 "paddw %%mm1, %%mm0 \n\t" //d0
2018 "punpckhwd %%mm6, %%mm2 \n\t"
2020 "psubw %%mm1, %%mm5 \n\t" //d1
2021 "movq %%mm0, %%mm6 \n\t"
2023 "movq 1*8+%3, %%mm1 \n\t"
2024 "punpcklwd %%mm5, %%mm0 \n\t"
2026 "punpckhwd %%mm5, %%mm6 \n\t"
2027 "movq %%mm0, %%mm5 \n\t"
2029 "punpckldq %%mm7, %%mm0 \n\t" //0
2030 "paddw %%mm4, %%mm3 \n\t"
2032 "punpckhdq %%mm7, %%mm5 \n\t" //1
2033 "movq %%mm6, %%mm7 \n\t"
2035 "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
2036 "punpckldq %%mm2, %%mm6 \n\t" //2
2038 "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
2039 "punpckhdq %%mm2, %%mm7 \n\t" //3
2041 "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
2042 "paddw %%mm1, %%mm4 \n\t"
2044 "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
2045 "psllw $2, %%mm3 \n\t" //t10
2047 "movq 0*8+%3, %%mm2 \n\t"
2048 "psllw $2, %%mm4 \n\t" //t11
2050 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
2051 "paddw %%mm2, %%mm1 \n\t"
2053 "psllw $2, %%mm1 \n\t" //t12
2054 "movq %%mm3, %%mm0 \n\t"
2056 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
2057 "psubw %%mm1, %%mm3 \n\t"
2059 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
2060 "movq %%mm2, %%mm5 \n\t"
2062 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
2063 "psubw %%mm4, %%mm2 \n\t" //z13
2065 "paddw %%mm4, %%mm5 \n\t" //z11
2066 "movq %%mm2, %%mm6 \n\t"
2068 "paddw %%mm3, %%mm0 \n\t" //z2
2069 "movq %%mm5, %%mm7 \n\t"
2071 "paddw %%mm0, %%mm2 \n\t" //d4
2072 "psubw %%mm0, %%mm6 \n\t" //d5
2074 "movq %%mm2, %%mm4 \n\t"
2075 "paddw %%mm3, %%mm1 \n\t" //z4
2077 //transpose 4x4
2078 "punpcklwd %%mm6, %%mm2 \n\t"
2079 "paddw %%mm1, %%mm5 \n\t" //d6
2081 "punpckhwd %%mm6, %%mm4 \n\t"
2082 "psubw %%mm1, %%mm7 \n\t" //d7
2084 "movq %%mm5, %%mm6 \n\t"
2085 "punpcklwd %%mm7, %%mm5 \n\t"
2087 "punpckhwd %%mm7, %%mm6 \n\t"
2088 "movq %%mm2, %%mm7 \n\t"
2090 "punpckldq %%mm5, %%mm2 \n\t" //4
2091 "sub %%"REG_d", %%"REG_S" \n\t"
2093 "punpckhdq %%mm5, %%mm7 \n\t" //5
2094 "movq %%mm4, %%mm5 \n\t"
2096 "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2097 "punpckldq %%mm6, %%mm4 \n\t" //6
2099 "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2100 "punpckhdq %%mm6, %%mm5 \n\t" //7
2102 "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2103 "add $4, %%"REG_S" \n\t"
2105 "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2106 "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
2107 "dec %%"REG_c" \n\t"
2108 "jnz 6b \n\t"
2110 : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps)
2111 : "a"(line_size)
2112 : "%"REG_d);
2115 #endif // HAVE_MMX