Merge svn changes up to r30419
[mplayer/glamo.git] / libmpcodecs / vf_fspp.c
blob8ef33381b146f194d68e3d309a563e2fdc32ed4f
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"
45 #include "img_format.h"
46 #include "mp_image.h"
47 #include "vf.h"
48 #include "libvo/fastmemcpy.h"
50 #include "libavutil/internal.h"
51 #include "libavutil/intreadwrite.h"
52 #include "libavutil/mem.h"
53 #include "libavcodec/avcodec.h"
54 #include "libavcodec/dsputil.h"
56 #undef free
57 #undef malloc
59 //===========================================================================//
60 #define BLOCKSZ 12
62 static const short custom_threshold[64]=
63 // values (296) can't be too high
64 // -it causes too big quant dependence
65 // or maybe overflow(check), which results in some flashing
66 { 71, 296, 295, 237, 71, 40, 38, 19,
67 245, 193, 185, 121, 102, 73, 53, 27,
68 158, 129, 141, 107, 97, 73, 50, 26,
69 102, 116, 109, 98, 82, 66, 45, 23,
70 71, 94, 95, 81, 70, 56, 38, 20,
71 56, 77, 74, 66, 56, 44, 30, 15,
72 38, 53, 50, 45, 38, 30, 21, 11,
73 20, 27, 26, 23, 20, 15, 11, 5
76 static const uint8_t __attribute__((aligned(32))) dither[8][8]={
77 { 0, 48, 12, 60, 3, 51, 15, 63, },
78 { 32, 16, 44, 28, 35, 19, 47, 31, },
79 { 8, 56, 4, 52, 11, 59, 7, 55, },
80 { 40, 24, 36, 20, 43, 27, 39, 23, },
81 { 2, 50, 14, 62, 1, 49, 13, 61, },
82 { 34, 18, 46, 30, 33, 17, 45, 29, },
83 { 10, 58, 6, 54, 9, 57, 5, 53, },
84 { 42, 26, 38, 22, 41, 25, 37, 21, },
87 struct vf_priv_s { //align 16 !
88 uint64_t threshold_mtx_noq[8*2];
89 uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions
91 int log2_count;
92 int temp_stride;
93 int qp;
94 int mpeg2;
95 int prev_q;
96 uint8_t *src;
97 int16_t *temp;
98 int bframes;
99 char *non_b_qp;
103 #if !HAVE_MMX
105 //This func reads from 1 slice, 1 and clears 0 & 1
106 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
107 {int y, x;
108 #define STORE(pos) \
109 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
110 src[x + pos]=src[x + pos - 8*src_stride]=0; \
111 if(temp & 0x100) temp= ~(temp>>31); \
112 dst[x + pos]= temp;
114 for(y=0; y<height; y++){
115 const uint8_t *d= dither[y];
116 for(x=0; x<width; x+=8){
117 int temp;
118 STORE(0);
119 STORE(1);
120 STORE(2);
121 STORE(3);
122 STORE(4);
123 STORE(5);
124 STORE(6);
125 STORE(7);
127 src+=src_stride;
128 dst+=dst_stride;
132 //This func reads from 2 slices, 0 & 2 and clears 2-nd
133 static void store_slice2_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
134 {int y, x;
135 #define STORE2(pos) \
136 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
137 src[x + pos + 16*src_stride]=0; \
138 if(temp & 0x100) temp= ~(temp>>31); \
139 dst[x + pos]= temp;
141 for(y=0; y<height; y++){
142 const uint8_t *d= dither[y];
143 for(x=0; x<width; x+=8){
144 int temp;
145 STORE2(0);
146 STORE2(1);
147 STORE2(2);
148 STORE2(3);
149 STORE2(4);
150 STORE2(5);
151 STORE2(6);
152 STORE2(7);
154 src+=src_stride;
155 dst+=dst_stride;
159 static void mul_thrmat_c(struct vf_priv_s *p,int q)
161 int a;
162 for(a=0;a<64;a++)
163 ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
166 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
167 static void row_idct_c(DCTELEM* workspace,
168 int16_t* output_adr, int output_stride, int cnt);
169 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
171 //this is rather ugly, but there is no need for function pointers
172 #define store_slice_s store_slice_c
173 #define store_slice2_s store_slice2_c
174 #define mul_thrmat_s mul_thrmat_c
175 #define column_fidct_s column_fidct_c
176 #define row_idct_s row_idct_c
177 #define row_fdct_s row_fdct_c
179 #else /* HAVE_MMX */
181 //This func reads from 1 slice, 1 and clears 0 & 1
182 static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
184 const uint8_t *od=&dither[0][0];
185 const uint8_t *end=&dither[height][0];
186 width = (width+7)&~7;
187 dst_stride-=width;
188 //src_stride=(src_stride-width)*2;
189 __asm__ volatile(
190 "mov %5, %%"REG_d" \n\t"
191 "mov %6, %%"REG_S" \n\t"
192 "mov %7, %%"REG_D" \n\t"
193 "mov %1, %%"REG_a" \n\t"
194 "movd %%"REG_d", %%mm5 \n\t"
195 "xor $-1, %%"REG_d" \n\t"
196 "mov %%"REG_a", %%"REG_c" \n\t"
197 "add $7, %%"REG_d" \n\t"
198 "neg %%"REG_a" \n\t"
199 "sub %0, %%"REG_c" \n\t"
200 "add %%"REG_c", %%"REG_c" \n\t"
201 "movd %%"REG_d", %%mm2 \n\t"
202 "mov %%"REG_c", %1 \n\t"
203 "mov %2, %%"REG_d" \n\t"
204 "shl $4, %%"REG_a" \n\t"
206 "2: \n\t"
207 "movq (%%"REG_d"), %%mm3 \n\t"
208 "movq %%mm3, %%mm4 \n\t"
209 "pxor %%mm7, %%mm7 \n\t"
210 "punpcklbw %%mm7, %%mm3 \n\t"
211 "punpckhbw %%mm7, %%mm4 \n\t"
212 "mov %0, %%"REG_c" \n\t"
213 "psraw %%mm5, %%mm3 \n\t"
214 "psraw %%mm5, %%mm4 \n\t"
215 "1: \n\t"
216 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
217 "movq (%%"REG_S"), %%mm0 \n\t"
218 "movq 8(%%"REG_S"), %%mm1 \n\t"
220 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
221 "paddw %%mm3, %%mm0 \n\t"
222 "paddw %%mm4, %%mm1 \n\t"
224 "movq %%mm7, (%%"REG_S") \n\t"
225 "psraw %%mm2, %%mm0 \n\t"
226 "psraw %%mm2, %%mm1 \n\t"
228 "movq %%mm7, 8(%%"REG_S") \n\t"
229 "packuswb %%mm1, %%mm0 \n\t"
230 "add $16, %%"REG_S" \n\t"
232 "movq %%mm0, (%%"REG_D") \n\t"
233 "add $8, %%"REG_D" \n\t"
234 "sub $8, %%"REG_c" \n\t"
235 "jg 1b \n\t"
236 "add %1, %%"REG_S" \n\t"
237 "add $8, %%"REG_d" \n\t"
238 "add %3, %%"REG_D" \n\t"
239 "cmp %4, %%"REG_d" \n\t"
240 "jl 2b \n\t"
243 : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
244 "m" (log2_scale), "m" (src), "m" (dst) //input
245 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
249 //This func reads from 2 slices, 0 & 2 and clears 2-nd
250 static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
252 const uint8_t *od=&dither[0][0];
253 const uint8_t *end=&dither[height][0];
254 width = (width+7)&~7;
255 dst_stride-=width;
256 //src_stride=(src_stride-width)*2;
257 __asm__ volatile(
258 "mov %5, %%"REG_d" \n\t"
259 "mov %6, %%"REG_S" \n\t"
260 "mov %7, %%"REG_D" \n\t"
261 "mov %1, %%"REG_a" \n\t"
262 "movd %%"REG_d", %%mm5 \n\t"
263 "xor $-1, %%"REG_d" \n\t"
264 "mov %%"REG_a", %%"REG_c" \n\t"
265 "add $7, %%"REG_d" \n\t"
266 "sub %0, %%"REG_c" \n\t"
267 "add %%"REG_c", %%"REG_c" \n\t"
268 "movd %%"REG_d", %%mm2 \n\t"
269 "mov %%"REG_c", %1 \n\t"
270 "mov %2, %%"REG_d" \n\t"
271 "shl $5, %%"REG_a" \n\t"
273 "2: \n\t"
274 "movq (%%"REG_d"), %%mm3 \n\t"
275 "movq %%mm3, %%mm4 \n\t"
276 "pxor %%mm7, %%mm7 \n\t"
277 "punpcklbw %%mm7, %%mm3 \n\t"
278 "punpckhbw %%mm7, %%mm4 \n\t"
279 "mov %0, %%"REG_c" \n\t"
280 "psraw %%mm5, %%mm3 \n\t"
281 "psraw %%mm5, %%mm4 \n\t"
282 "1: \n\t"
283 "movq (%%"REG_S"), %%mm0 \n\t"
284 "movq 8(%%"REG_S"), %%mm1 \n\t"
285 "paddw %%mm3, %%mm0 \n\t"
287 "paddw (%%"REG_S",%%"REG_a",), %%mm0 \n\t"
288 "paddw %%mm4, %%mm1 \n\t"
289 "movq 8(%%"REG_S",%%"REG_a",), %%mm6 \n\t"
291 "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
292 "psraw %%mm2, %%mm0 \n\t"
293 "paddw %%mm6, %%mm1 \n\t"
295 "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
296 "psraw %%mm2, %%mm1 \n\t"
297 "packuswb %%mm1, %%mm0 \n\t"
299 "movq %%mm0, (%%"REG_D") \n\t"
300 "add $16, %%"REG_S" \n\t"
301 "add $8, %%"REG_D" \n\t"
302 "sub $8, %%"REG_c" \n\t"
303 "jg 1b \n\t"
304 "add %1, %%"REG_S" \n\t"
305 "add $8, %%"REG_d" \n\t"
306 "add %3, %%"REG_D" \n\t"
307 "cmp %4, %%"REG_d" \n\t"
308 "jl 2b \n\t"
311 : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
312 "m" (log2_scale), "m" (src), "m" (dst) //input
313 : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S
317 static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
319 uint64_t *adr=&p->threshold_mtx_noq[0];
320 __asm__ volatile(
321 "movd %0, %%mm7 \n\t"
322 "add $8*8*2, %%"REG_D" \n\t"
323 "movq 0*8(%%"REG_S"), %%mm0 \n\t"
324 "punpcklwd %%mm7, %%mm7 \n\t"
325 "movq 1*8(%%"REG_S"), %%mm1 \n\t"
326 "punpckldq %%mm7, %%mm7 \n\t"
327 "pmullw %%mm7, %%mm0 \n\t"
329 "movq 2*8(%%"REG_S"), %%mm2 \n\t"
330 "pmullw %%mm7, %%mm1 \n\t"
332 "movq 3*8(%%"REG_S"), %%mm3 \n\t"
333 "pmullw %%mm7, %%mm2 \n\t"
335 "movq %%mm0, 0*8(%%"REG_D") \n\t"
336 "movq 4*8(%%"REG_S"), %%mm4 \n\t"
337 "pmullw %%mm7, %%mm3 \n\t"
339 "movq %%mm1, 1*8(%%"REG_D") \n\t"
340 "movq 5*8(%%"REG_S"), %%mm5 \n\t"
341 "pmullw %%mm7, %%mm4 \n\t"
343 "movq %%mm2, 2*8(%%"REG_D") \n\t"
344 "movq 6*8(%%"REG_S"), %%mm6 \n\t"
345 "pmullw %%mm7, %%mm5 \n\t"
347 "movq %%mm3, 3*8(%%"REG_D") \n\t"
348 "movq 7*8+0*8(%%"REG_S"), %%mm0 \n\t"
349 "pmullw %%mm7, %%mm6 \n\t"
351 "movq %%mm4, 4*8(%%"REG_D") \n\t"
352 "movq 7*8+1*8(%%"REG_S"), %%mm1 \n\t"
353 "pmullw %%mm7, %%mm0 \n\t"
355 "movq %%mm5, 5*8(%%"REG_D") \n\t"
356 "movq 7*8+2*8(%%"REG_S"), %%mm2 \n\t"
357 "pmullw %%mm7, %%mm1 \n\t"
359 "movq %%mm6, 6*8(%%"REG_D") \n\t"
360 "movq 7*8+3*8(%%"REG_S"), %%mm3 \n\t"
361 "pmullw %%mm7, %%mm2 \n\t"
363 "movq %%mm0, 7*8+0*8(%%"REG_D") \n\t"
364 "movq 7*8+4*8(%%"REG_S"), %%mm4 \n\t"
365 "pmullw %%mm7, %%mm3 \n\t"
367 "movq %%mm1, 7*8+1*8(%%"REG_D") \n\t"
368 "movq 7*8+5*8(%%"REG_S"), %%mm5 \n\t"
369 "pmullw %%mm7, %%mm4 \n\t"
371 "movq %%mm2, 7*8+2*8(%%"REG_D") \n\t"
372 "movq 7*8+6*8(%%"REG_S"), %%mm6 \n\t"
373 "pmullw %%mm7, %%mm5 \n\t"
375 "movq %%mm3, 7*8+3*8(%%"REG_D") \n\t"
376 "movq 14*8+0*8(%%"REG_S"), %%mm0 \n\t"
377 "pmullw %%mm7, %%mm6 \n\t"
379 "movq %%mm4, 7*8+4*8(%%"REG_D") \n\t"
380 "movq 14*8+1*8(%%"REG_S"), %%mm1 \n\t"
381 "pmullw %%mm7, %%mm0 \n\t"
383 "movq %%mm5, 7*8+5*8(%%"REG_D") \n\t"
384 "pmullw %%mm7, %%mm1 \n\t"
386 "movq %%mm6, 7*8+6*8(%%"REG_D") \n\t"
387 "movq %%mm0, 14*8+0*8(%%"REG_D") \n\t"
388 "movq %%mm1, 14*8+1*8(%%"REG_D") \n\t"
390 : "+g" (q), "+S" (adr), "+D" (adr)
395 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
396 static void row_idct_mmx(DCTELEM* workspace,
397 int16_t* output_adr, int output_stride, int cnt);
398 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
400 #define store_slice_s store_slice_mmx
401 #define store_slice2_s store_slice2_mmx
402 #define mul_thrmat_s mul_thrmat_mmx
403 #define column_fidct_s column_fidct_mmx
404 #define row_idct_s row_idct_mmx
405 #define row_fdct_s row_fdct_mmx
406 #endif // HAVE_MMX
408 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
409 int dst_stride, int src_stride,
410 int width, int height,
411 uint8_t *qp_store, int qp_stride, int is_luma)
413 int x, x0, y, es, qy, t;
414 const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15))
415 const int step=6-p->log2_count;
416 const int qps= 3 + is_luma;
417 int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
418 DCTELEM *block= (DCTELEM *)block_align;
419 DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ);
421 memset(block3, 0, 4*8*BLOCKSZ);
423 //p->src=src-src_stride*8-8;//!
424 if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
425 for(y=0; y<height; y++){
426 int index= 8 + 8*stride + y*stride;
427 fast_memcpy(p->src + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers
428 for(x=0; x<8; x++){
429 p->src[index - x - 1]= p->src[index + x ];
430 p->src[index + width + x ]= p->src[index + width - x - 1];
433 for(y=0; y<8; y++){
434 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
435 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
437 //FIXME (try edge emu)
439 for(y=8; y<24; y++)
440 memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t));
442 for(y=step; y<height+8; y+=step){ //step= 1,2
443 qy=y-4;
444 if (qy>height-1) qy=height-1;
445 if (qy<0) qy=0;
446 qy=(qy>>qps)*qp_stride;
447 row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2);
448 for(x0=0; x0<width+8-8*(BLOCKSZ-1); x0+=8*(BLOCKSZ-1)){
449 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1));
450 if(p->qp)
451 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT
452 else
453 for (x=0; x<8*(BLOCKSZ-1); x+=8) {
454 t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same
455 if (t<0) t=0;//t always < width-2
456 t=qp_store[qy+(t>>qps)];
457 if(p->mpeg2) t>>=1; //copy p->mpeg2,prev_q to locals?
458 if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t);
459 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
461 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
462 memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
463 memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM));
466 es=width+8-x0; // 8, ...
467 if (es>8)
468 row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2);
469 column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1));
470 row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2);
471 {const int y1=y-8+step;//l5-7 l4-6
472 if (!(y1&7) && y1) {
473 if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride,
474 dst_stride, stride, width, 8, 5-p->log2_count);
475 else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride,
476 dst_stride, stride, width, 8, 5-p->log2_count);
480 if (y&7) { // == height & 7
481 if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride,
482 dst_stride, stride, width, y&7, 5-p->log2_count);
483 else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride,
484 dst_stride, stride, width, y&7, 5-p->log2_count);
488 static int config(struct vf_instance* vf,
489 int width, int height, int d_width, int d_height,
490 unsigned int flags, unsigned int outfmt)
492 int h= (height+16+15)&(~15);
494 vf->priv->temp_stride= (width+16+15)&(~15);
495 vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t));
496 //this can also be avoided, see above
497 vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
499 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
502 static void get_image(struct vf_instance* vf, mp_image_t *mpi)
504 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
505 // ok, we can do pp in-place (or pp disabled):
506 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
507 mpi->type, mpi->flags, mpi->width, mpi->height);
508 mpi->planes[0]=vf->dmpi->planes[0];
509 mpi->stride[0]=vf->dmpi->stride[0];
510 mpi->width=vf->dmpi->width;
511 if(mpi->flags&MP_IMGFLAG_PLANAR){
512 mpi->planes[1]=vf->dmpi->planes[1];
513 mpi->planes[2]=vf->dmpi->planes[2];
514 mpi->stride[1]=vf->dmpi->stride[1];
515 mpi->stride[2]=vf->dmpi->stride[2];
517 mpi->flags|=MP_IMGFLAG_DIRECT;
520 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts)
522 mp_image_t *dmpi;
523 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
524 // no DR, so get a new image! hope we'll get DR buffer:
525 dmpi=vf_get_image(vf->next,mpi->imgfmt,
526 MP_IMGTYPE_TEMP,
527 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
528 mpi->width,mpi->height);
529 vf_clone_mpi_attributes(dmpi, mpi);
530 }else{
531 dmpi=vf->dmpi;
534 vf->priv->mpeg2= mpi->qscale_type;
535 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
536 int w = mpi->qstride;
537 int h = (mpi->h + 15) >> 4;
538 if (!w) {
539 w = (mpi->w + 15) >> 4;
540 h = 1;
542 if(!vf->priv->non_b_qp)
543 vf->priv->non_b_qp= malloc(w*h);
544 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
546 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
547 char *qp_tab= vf->priv->non_b_qp;
548 if(vf->priv->bframes || !qp_tab)
549 qp_tab= mpi->qscale;
551 if(qp_tab || vf->priv->qp){
552 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
553 mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
554 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
555 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
556 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
557 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
558 }else{
559 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
560 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]);
561 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]);
565 #if HAVE_MMX
566 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
567 #endif
568 #if HAVE_MMX2
569 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
570 #endif
571 return vf_next_put_image(vf,dmpi, pts);
574 static void uninit(struct vf_instance* vf)
576 if(!vf->priv) return;
578 if(vf->priv->temp) av_free(vf->priv->temp);
579 vf->priv->temp= NULL;
580 if(vf->priv->src) av_free(vf->priv->src);
581 vf->priv->src= NULL;
582 //if(vf->priv->avctx) free(vf->priv->avctx);
583 //vf->priv->avctx= NULL;
584 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp);
585 vf->priv->non_b_qp= NULL;
587 av_free(vf->priv);
588 vf->priv=NULL;
591 //===========================================================================//
593 static int query_format(struct vf_instance* vf, unsigned int fmt)
595 switch(fmt){
596 case IMGFMT_YVU9:
597 case IMGFMT_IF09:
598 case IMGFMT_YV12:
599 case IMGFMT_I420:
600 case IMGFMT_IYUV:
601 case IMGFMT_CLPL:
602 case IMGFMT_Y800:
603 case IMGFMT_Y8:
604 case IMGFMT_444P:
605 case IMGFMT_422P:
606 case IMGFMT_411P:
607 return vf_next_query_format(vf,fmt);
609 return 0;
612 static int control(struct vf_instance* vf, int request, void* data)
614 switch(request){
615 case VFCTRL_QUERY_MAX_PP_LEVEL:
616 return 5;
617 case VFCTRL_SET_PP_LEVEL:
618 vf->priv->log2_count= *((unsigned int*)data);
619 if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
620 return CONTROL_TRUE;
622 return vf_next_control(vf,request,data);
625 static int open(vf_instance_t *vf, char* args)
627 int i=0, bias;
628 int custom_threshold_m[64];
629 int log2c=-1;
631 vf->config=config;
632 vf->put_image=put_image;
633 vf->get_image=get_image;
634 vf->query_format=query_format;
635 vf->uninit=uninit;
636 vf->control= control;
637 vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
639 avcodec_init();
641 //vf->priv->avctx= avcodec_alloc_context();
642 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
644 vf->priv->log2_count= 4;
645 vf->priv->bframes = 0;
647 if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
649 if( log2c >=4 && log2c <=5 )
650 vf->priv->log2_count = log2c;
651 else if( log2c >= 6 )
652 vf->priv->log2_count = 5;
654 if(vf->priv->qp < 0)
655 vf->priv->qp = 0;
657 if (i < -15) i = -15;
658 if (i > 32) i = 32;
660 bias= (1<<4)+i; //regulable
661 vf->priv->prev_q=0;
663 for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
664 custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
665 for(i=0;i<8;i++){
666 vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
667 |(((uint64_t)custom_threshold_m[i*8+6])<<16)
668 |(((uint64_t)custom_threshold_m[i*8+0])<<32)
669 |(((uint64_t)custom_threshold_m[i*8+4])<<48);
670 vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
671 |(((uint64_t)custom_threshold_m[i*8+3])<<16)
672 |(((uint64_t)custom_threshold_m[i*8+1])<<32)
673 |(((uint64_t)custom_threshold_m[i*8+7])<<48);
676 if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
678 return 1;
681 const vf_info_t vf_info_fspp = {
682 "fast simple postprocess",
683 "fspp",
684 "Michael Niedermayer, Nikolaj Poroshin",
686 open,
687 NULL
690 //====================================================================
691 //Specific spp's dct, idct and threshold functions
692 //I'd prefer to have them in the separate file.
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