Static pthread support
[mplayer/kovensky.git] / libmpcodecs / vf_fspp.c
blob7264199c216747bc1899013d0266e160dc236edc
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 if(!vf->priv->non_b_qp)
537 vf->priv->non_b_qp= malloc(mpi->qstride * ((mpi->h + 15) >> 4));
538 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, mpi->qstride * ((mpi->h + 15) >> 4));
540 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
541 char *qp_tab= vf->priv->non_b_qp;
542 if(vf->priv->bframes || !qp_tab)
543 qp_tab= mpi->qscale;
545 if(qp_tab || vf->priv->qp){
546 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
547 mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
548 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
549 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
550 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
551 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
552 }else{
553 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
554 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]);
555 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]);
559 #if HAVE_MMX
560 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
561 #endif
562 #if HAVE_MMX2
563 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
564 #endif
565 return vf_next_put_image(vf,dmpi, pts);
568 static void uninit(struct vf_instance* vf)
570 if(!vf->priv) return;
572 if(vf->priv->temp) av_free(vf->priv->temp);
573 vf->priv->temp= NULL;
574 if(vf->priv->src) av_free(vf->priv->src);
575 vf->priv->src= NULL;
576 //if(vf->priv->avctx) free(vf->priv->avctx);
577 //vf->priv->avctx= NULL;
578 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp);
579 vf->priv->non_b_qp= NULL;
581 av_free(vf->priv);
582 vf->priv=NULL;
585 //===========================================================================//
587 static int query_format(struct vf_instance* vf, unsigned int fmt)
589 switch(fmt){
590 case IMGFMT_YVU9:
591 case IMGFMT_IF09:
592 case IMGFMT_YV12:
593 case IMGFMT_I420:
594 case IMGFMT_IYUV:
595 case IMGFMT_CLPL:
596 case IMGFMT_Y800:
597 case IMGFMT_Y8:
598 case IMGFMT_444P:
599 case IMGFMT_422P:
600 case IMGFMT_411P:
601 return vf_next_query_format(vf,fmt);
603 return 0;
606 static int control(struct vf_instance* vf, int request, void* data)
608 switch(request){
609 case VFCTRL_QUERY_MAX_PP_LEVEL:
610 return 5;
611 case VFCTRL_SET_PP_LEVEL:
612 vf->priv->log2_count= *((unsigned int*)data);
613 if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
614 return CONTROL_TRUE;
616 return vf_next_control(vf,request,data);
619 static int open(vf_instance_t *vf, char* args)
621 int i=0, bias;
622 int custom_threshold_m[64];
623 int log2c=-1;
625 vf->config=config;
626 vf->put_image=put_image;
627 vf->get_image=get_image;
628 vf->query_format=query_format;
629 vf->uninit=uninit;
630 vf->control= control;
631 vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
633 avcodec_init();
635 //vf->priv->avctx= avcodec_alloc_context();
636 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
638 vf->priv->log2_count= 4;
639 vf->priv->bframes = 0;
641 if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
643 if( log2c >=4 && log2c <=5 )
644 vf->priv->log2_count = log2c;
645 else if( log2c >= 6 )
646 vf->priv->log2_count = 5;
648 if(vf->priv->qp < 0)
649 vf->priv->qp = 0;
651 if (i < -15) i = -15;
652 if (i > 32) i = 32;
654 bias= (1<<4)+i; //regulable
655 vf->priv->prev_q=0;
657 for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
658 custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
659 for(i=0;i<8;i++){
660 vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
661 |(((uint64_t)custom_threshold_m[i*8+6])<<16)
662 |(((uint64_t)custom_threshold_m[i*8+0])<<32)
663 |(((uint64_t)custom_threshold_m[i*8+4])<<48);
664 vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
665 |(((uint64_t)custom_threshold_m[i*8+3])<<16)
666 |(((uint64_t)custom_threshold_m[i*8+1])<<32)
667 |(((uint64_t)custom_threshold_m[i*8+7])<<48);
670 if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
672 return 1;
675 const vf_info_t vf_info_fspp = {
676 "fast simple postprocess",
677 "fspp",
678 "Michael Niedermayer, Nikolaj Poroshin",
680 open,
681 NULL
684 //====================================================================
685 //Specific spp's dct, idct and threshold functions
686 //I'd prefer to have them in the separate file.
688 //#define MANGLE(a) #a
690 //typedef int16_t DCTELEM; //! only int16_t
692 #define DCTSIZE 8
693 #define DCTSIZE_S "8"
695 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
696 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
697 #define FIX64(x,s) C64(FIX(x,s))
699 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
700 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
701 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
703 #if HAVE_MMX
705 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
706 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14);
707 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14);
708 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
710 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
712 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
713 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
714 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
715 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
716 //for t3,t5,t7 == 0 shortcut
717 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
718 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
719 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
721 DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
722 DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
724 #else /* !HAVE_MMX */
726 typedef int32_t int_simd16_t;
727 static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
728 static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
729 static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
730 static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
731 static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
732 static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
733 static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
734 static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
735 static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
737 #endif
739 #if !HAVE_MMX
741 static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
743 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
744 int_simd16_t tmp10, tmp11, tmp12, tmp13;
745 int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
746 int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
748 DCTELEM* dataptr;
749 DCTELEM* wsptr;
750 int16_t *threshold;
751 int ctr;
753 dataptr = data;
754 wsptr = output;
756 for (; cnt > 0; cnt-=2) { //start positions
757 threshold=(int16_t*)thr_adr;//threshold_mtx
758 for (ctr = DCTSIZE; ctr > 0; ctr--) {
759 // Process columns from input, add to output.
760 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
761 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
763 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
764 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
766 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
767 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
769 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
770 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
772 // Even part of FDCT
774 tmp10 = tmp0 + tmp3;
775 tmp13 = tmp0 - tmp3;
776 tmp11 = tmp1 + tmp2;
777 tmp12 = tmp1 - tmp2;
779 d0 = tmp10 + tmp11;
780 d4 = tmp10 - tmp11;
782 z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
783 d2 = tmp13 + z1;
784 d6 = tmp13 - z1;
786 // Even part of IDCT
788 THRESHOLD(tmp0, d0, threshold[0*8]);
789 THRESHOLD(tmp1, d2, threshold[2*8]);
790 THRESHOLD(tmp2, d4, threshold[4*8]);
791 THRESHOLD(tmp3, d6, threshold[6*8]);
792 tmp0+=2;
793 tmp10 = (tmp0 + tmp2)>>2;
794 tmp11 = (tmp0 - tmp2)>>2;
796 tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
797 tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
799 tmp0 = tmp10 + tmp13; //->temps
800 tmp3 = tmp10 - tmp13; //->temps
801 tmp1 = tmp11 + tmp12; //->temps
802 tmp2 = tmp11 - tmp12; //->temps
804 // Odd part of FDCT
806 tmp10 = tmp4 + tmp5;
807 tmp11 = tmp5 + tmp6;
808 tmp12 = tmp6 + tmp7;
810 z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
811 z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
812 z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
813 z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
815 z11 = tmp7 + z3;
816 z13 = tmp7 - z3;
818 d5 = z13 + z2;
819 d3 = z13 - z2;
820 d1 = z11 + z4;
821 d7 = z11 - z4;
823 // Odd part of IDCT
825 THRESHOLD(tmp4, d1, threshold[1*8]);
826 THRESHOLD(tmp5, d3, threshold[3*8]);
827 THRESHOLD(tmp6, d5, threshold[5*8]);
828 THRESHOLD(tmp7, d7, threshold[7*8]);
830 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
831 z13 = tmp6 + tmp5;
832 z10 = (tmp6 - tmp5)<<1;
833 z11 = tmp4 + tmp7;
834 z12 = (tmp4 - tmp7)<<1;
836 tmp7 = (z11 + z13)>>2; //+2 !
837 tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
838 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
839 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
840 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
842 tmp6 = tmp12 - tmp7;
843 tmp5 = tmp11 - tmp6;
844 tmp4 = tmp10 + tmp5;
846 wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
847 wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
848 wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
849 wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
850 wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
851 wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
852 wsptr[DCTSIZE*6]= (tmp1 - tmp6);
853 wsptr[DCTSIZE*7]= (tmp0 - tmp7);
855 dataptr++; //next column
856 wsptr++;
857 threshold++;
859 dataptr+=8; //skip each second start pos
860 wsptr +=8;
864 #else /* HAVE_MMX */
866 static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
868 uint64_t __attribute__((aligned(8))) temps[4];
869 __asm__ volatile(
870 ASMALIGN(4)
871 "1: \n\t"
872 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
874 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
875 "movq %%mm1, %%mm0 \n\t"
877 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
878 "movq %%mm7, %%mm3 \n\t"
880 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
881 "movq %%mm1, %%mm5 \n\t"
883 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
884 "psubw %%mm7, %%mm1 \n\t" //t13
886 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
887 "movq %%mm6, %%mm4 \n\t"
889 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
890 "paddw %%mm7, %%mm5 \n\t" //t10
892 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
893 "movq %%mm6, %%mm7 \n\t"
895 "paddw %%mm2, %%mm6 \n\t" //t11
896 "psubw %%mm2, %%mm7 \n\t" //t12
898 "movq %%mm5, %%mm2 \n\t"
899 "paddw %%mm6, %%mm5 \n\t" //d0
900 // i0 t13 t12 i3 i1 d0 - d4
901 "psubw %%mm6, %%mm2 \n\t" //d4
902 "paddw %%mm1, %%mm7 \n\t"
904 "movq 4*16(%%"REG_d"), %%mm6 \n\t"
905 "psllw $2, %%mm7 \n\t"
907 "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
908 "psubw %%mm6, %%mm2 \n\t"
910 "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
911 "paddusw %%mm6, %%mm2 \n\t"
913 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
915 "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
916 "paddw %%mm6, %%mm2 \n\t"
918 "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
919 "psubusw %%mm6, %%mm2 \n\t"
921 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
922 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
923 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
924 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
925 "movq %%mm2, %%mm6 \n\t"
927 "paddw %%mm5, %%mm2 \n\t"
928 "psubw %%mm6, %%mm5 \n\t"
930 "movq %%mm1, %%mm6 \n\t"
931 "paddw %%mm7, %%mm1 \n\t" //d2
933 "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
934 "psubw %%mm7, %%mm6 \n\t" //d6
936 "movq 6*16(%%"REG_d"), %%mm7 \n\t"
937 "psraw $2, %%mm5 \n\t"
939 "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
940 "psubw %%mm7, %%mm6 \n\t"
941 // t7 d2 /t11 t4 t6 - d6 /t10
943 "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
944 "paddusw %%mm7, %%mm6 \n\t"
946 "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
947 "paddw %%mm7, %%mm6 \n\t"
949 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
950 "psubusw %%mm7, %%mm6 \n\t"
952 //movq [edi+"DCTSIZE_S"*2*2], mm1
953 //movq [edi+"DCTSIZE_S"*6*2], mm6
954 "movq %%mm1, %%mm7 \n\t"
955 "psraw $2, %%mm2 \n\t"
957 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
958 "psubw %%mm6, %%mm1 \n\t"
960 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
961 "paddw %%mm7, %%mm6 \n\t" //'t13
963 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
964 "movq %%mm2, %%mm7 \n\t"
966 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
967 "paddw %%mm6, %%mm2 \n\t" //'t0
969 "movq %%mm2, 0*8+%3 \n\t" //!
970 "psubw %%mm6, %%mm7 \n\t" //'t3
972 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
973 "psubw %%mm6, %%mm1 \n\t" //'t12
975 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
976 "movq %%mm5, %%mm6 \n\t"
978 "movq %%mm7, 3*8+%3 \n\t"
979 "paddw %%mm2, %%mm3 \n\t" //t10
981 "paddw %%mm4, %%mm2 \n\t" //t11
982 "paddw %%mm0, %%mm4 \n\t" //t12
984 "movq %%mm3, %%mm7 \n\t"
985 "psubw %%mm4, %%mm3 \n\t"
987 "psllw $2, %%mm3 \n\t"
988 "psllw $2, %%mm7 \n\t" //opt for P6
990 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
991 "psllw $2, %%mm4 \n\t"
993 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
994 "psllw $2, %%mm2 \n\t"
996 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
997 "paddw %%mm1, %%mm5 \n\t" //'t1
999 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1000 "psubw %%mm1, %%mm6 \n\t" //'t2
1001 // t7 't12 't11 t4 t6 - 't13 't10 ---
1003 "paddw %%mm3, %%mm7 \n\t" //z2
1005 "movq %%mm5, 1*8+%3 \n\t"
1006 "paddw %%mm3, %%mm4 \n\t" //z4
1008 "movq 3*16(%%"REG_d"), %%mm3 \n\t"
1009 "movq %%mm0, %%mm1 \n\t"
1011 "movq %%mm6, 2*8+%3 \n\t"
1012 "psubw %%mm2, %%mm1 \n\t" //z13
1014 //===
1015 "paddw %%mm2, %%mm0 \n\t" //z11
1016 "movq %%mm1, %%mm5 \n\t"
1018 "movq 5*16(%%"REG_d"), %%mm2 \n\t"
1019 "psubw %%mm7, %%mm1 \n\t" //d3
1021 "paddw %%mm7, %%mm5 \n\t" //d5
1022 "psubw %%mm3, %%mm1 \n\t"
1024 "movq 1*16(%%"REG_d"), %%mm7 \n\t"
1025 "psubw %%mm2, %%mm5 \n\t"
1027 "movq %%mm0, %%mm6 \n\t"
1028 "paddw %%mm4, %%mm0 \n\t" //d1
1030 "paddusw %%mm3, %%mm1 \n\t"
1031 "psubw %%mm4, %%mm6 \n\t" //d7
1033 // d1 d3 - - - d5 d7 -
1034 "movq 7*16(%%"REG_d"), %%mm4 \n\t"
1035 "psubw %%mm7, %%mm0 \n\t"
1037 "psubw %%mm4, %%mm6 \n\t"
1038 "paddusw %%mm2, %%mm5 \n\t"
1040 "paddusw %%mm4, %%mm6 \n\t"
1041 "paddw %%mm3, %%mm1 \n\t"
1043 "paddw %%mm2, %%mm5 \n\t"
1044 "paddw %%mm4, %%mm6 \n\t"
1046 "psubusw %%mm3, %%mm1 \n\t"
1047 "psubusw %%mm2, %%mm5 \n\t"
1049 "psubusw %%mm4, %%mm6 \n\t"
1050 "movq %%mm1, %%mm4 \n\t"
1052 "por %%mm5, %%mm4 \n\t"
1053 "paddusw %%mm7, %%mm0 \n\t"
1055 "por %%mm6, %%mm4 \n\t"
1056 "paddw %%mm7, %%mm0 \n\t"
1058 "packssdw %%mm4, %%mm4 \n\t"
1059 "psubusw %%mm7, %%mm0 \n\t"
1061 "movd %%mm4, %%"REG_a" \n\t"
1062 "or %%"REG_a", %%"REG_a" \n\t"
1063 "jnz 2f \n\t"
1064 //movq [edi+"DCTSIZE_S"*3*2], mm1
1065 //movq [edi+"DCTSIZE_S"*5*2], mm5
1066 //movq [edi+"DCTSIZE_S"*1*2], mm0
1067 //movq [edi+"DCTSIZE_S"*7*2], mm6
1068 // t4 t5 - - - t6 t7 -
1069 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1070 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1071 "movq 0*8+%3, %%mm4 \n\t"
1072 "movq %%mm0, %%mm1 \n\t"
1074 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1075 "movq %%mm1, %%mm2 \n\t"
1077 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1078 "movq %%mm2, %%mm3 \n\t"
1080 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1081 "paddw %%mm4, %%mm5 \n\t"
1083 "movq 1*8+%3, %%mm6 \n\t"
1084 //paddw mm3, MM_2
1085 "psraw $2, %%mm3 \n\t" //tmp7
1087 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1088 "psubw %%mm3, %%mm4 \n\t"
1090 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1091 "paddw %%mm3, %%mm5 \n\t"
1093 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1094 "paddw %%mm6, %%mm7 \n\t"
1096 "movq 2*8+%3, %%mm3 \n\t"
1097 "psubw %%mm0, %%mm6 \n\t"
1099 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1100 "paddw %%mm0, %%mm7 \n\t"
1102 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1103 "paddw %%mm3, %%mm4 \n\t"
1105 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1106 "psubw %%mm1, %%mm3 \n\t"
1108 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1109 "paddw %%mm1, %%mm4 \n\t"
1111 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1112 "paddw %%mm3, %%mm5 \n\t"
1114 "movq 3*8+%3, %%mm0 \n\t"
1115 "add $8, %%"REG_S" \n\t"
1117 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1118 "paddw %%mm0, %%mm6 \n\t"
1120 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1121 "psubw %%mm2, %%mm0 \n\t"
1123 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1124 "paddw %%mm2, %%mm6 \n\t"
1126 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1127 "paddw %%mm0, %%mm7 \n\t"
1129 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1131 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1132 "add $8, %%"REG_D" \n\t"
1133 "jmp 4f \n\t"
1135 "2: \n\t"
1136 //--- non DC2
1137 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1138 //psraw mm5, 2
1139 //psraw mm0, 2
1140 //psraw mm6, 2
1141 "movq %%mm5, %%mm3 \n\t"
1142 "psubw %%mm1, %%mm5 \n\t"
1144 "psllw $1, %%mm5 \n\t" //'z10
1145 "paddw %%mm1, %%mm3 \n\t" //'z13
1147 "movq %%mm0, %%mm2 \n\t"
1148 "psubw %%mm6, %%mm0 \n\t"
1150 "movq %%mm5, %%mm1 \n\t"
1151 "psllw $1, %%mm0 \n\t" //'z12
1153 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1154 "paddw %%mm0, %%mm5 \n\t"
1156 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1157 "paddw %%mm6, %%mm2 \n\t" //'z11
1159 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1160 "movq %%mm2, %%mm7 \n\t"
1162 //---
1163 "movq 0*8+%3, %%mm4 \n\t"
1164 "psubw %%mm3, %%mm2 \n\t"
1166 "psllw $1, %%mm2 \n\t"
1167 "paddw %%mm3, %%mm7 \n\t" //'t7
1169 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1170 "movq %%mm4, %%mm6 \n\t"
1171 //paddw mm7, MM_2
1172 "psraw $2, %%mm7 \n\t"
1174 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1175 "psubw %%mm7, %%mm6 \n\t"
1177 "movq 1*8+%3, %%mm3 \n\t"
1178 "paddw %%mm7, %%mm4 \n\t"
1180 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1181 "paddw %%mm5, %%mm1 \n\t" //'t12
1183 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1184 "psubw %%mm7, %%mm1 \n\t" //'t6
1186 "movq 2*8+%3, %%mm7 \n\t"
1187 "psubw %%mm5, %%mm0 \n\t" //'t10
1189 "movq 3*8+%3, %%mm6 \n\t"
1190 "movq %%mm3, %%mm5 \n\t"
1192 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1193 "psubw %%mm1, %%mm5 \n\t"
1195 "psubw %%mm1, %%mm2 \n\t" //'t5
1196 "paddw %%mm1, %%mm3 \n\t"
1198 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1199 "movq %%mm7, %%mm4 \n\t"
1201 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1202 "psubw %%mm2, %%mm4 \n\t"
1204 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1205 "paddw %%mm2, %%mm7 \n\t"
1207 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1208 "paddw %%mm2, %%mm0 \n\t" //'t4
1210 // 't4 't6 't5 - - - - 't7
1211 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1212 "movq %%mm6, %%mm1 \n\t"
1214 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1215 "psubw %%mm0, %%mm1 \n\t"
1217 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1218 "paddw %%mm0, %%mm6 \n\t"
1220 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1221 "add $8, %%"REG_S" \n\t"
1223 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1225 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1226 "add $8, %%"REG_D" \n\t"
1228 "4: \n\t"
1229 //=part 2 (the same)===========================================================
1230 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
1232 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
1233 "movq %%mm1, %%mm0 \n\t"
1235 "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
1236 "movq %%mm7, %%mm3 \n\t"
1238 "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
1239 "movq %%mm1, %%mm5 \n\t"
1241 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
1242 "psubw %%mm7, %%mm1 \n\t" //t13
1244 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1245 "movq %%mm6, %%mm4 \n\t"
1247 "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
1248 "paddw %%mm7, %%mm5 \n\t" //t10
1250 "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
1251 "movq %%mm6, %%mm7 \n\t"
1253 "paddw %%mm2, %%mm6 \n\t" //t11
1254 "psubw %%mm2, %%mm7 \n\t" //t12
1256 "movq %%mm5, %%mm2 \n\t"
1257 "paddw %%mm6, %%mm5 \n\t" //d0
1258 // i0 t13 t12 i3 i1 d0 - d4
1259 "psubw %%mm6, %%mm2 \n\t" //d4
1260 "paddw %%mm1, %%mm7 \n\t"
1262 "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
1263 "psllw $2, %%mm7 \n\t"
1265 "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1266 "psubw %%mm6, %%mm2 \n\t"
1268 "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1269 "paddusw %%mm6, %%mm2 \n\t"
1271 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
1273 "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1274 "paddw %%mm6, %%mm2 \n\t"
1276 "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
1277 "psubusw %%mm6, %%mm2 \n\t"
1279 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1280 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1281 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1282 "paddw "MANGLE(MM_2)", %%mm5 \n\t"
1283 "movq %%mm2, %%mm6 \n\t"
1285 "paddw %%mm5, %%mm2 \n\t"
1286 "psubw %%mm6, %%mm5 \n\t"
1288 "movq %%mm1, %%mm6 \n\t"
1289 "paddw %%mm7, %%mm1 \n\t" //d2
1291 "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1292 "psubw %%mm7, %%mm6 \n\t" //d6
1294 "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
1295 "psraw $2, %%mm5 \n\t"
1297 "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1298 "psubw %%mm7, %%mm6 \n\t"
1299 // t7 d2 /t11 t4 t6 - d6 /t10
1301 "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1302 "paddusw %%mm7, %%mm6 \n\t"
1304 "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
1305 "paddw %%mm7, %%mm6 \n\t"
1307 "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
1308 "psubusw %%mm7, %%mm6 \n\t"
1310 //movq [edi+"DCTSIZE_S"*2*2], mm1
1311 //movq [edi+"DCTSIZE_S"*6*2], mm6
1312 "movq %%mm1, %%mm7 \n\t"
1313 "psraw $2, %%mm2 \n\t"
1315 "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
1316 "psubw %%mm6, %%mm1 \n\t"
1318 "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
1319 "paddw %%mm7, %%mm6 \n\t" //'t13
1321 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1322 "movq %%mm2, %%mm7 \n\t"
1324 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
1325 "paddw %%mm6, %%mm2 \n\t" //'t0
1327 "movq %%mm2, 0*8+%3 \n\t" //!
1328 "psubw %%mm6, %%mm7 \n\t" //'t3
1330 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1331 "psubw %%mm6, %%mm1 \n\t" //'t12
1333 "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
1334 "movq %%mm5, %%mm6 \n\t"
1336 "movq %%mm7, 3*8+%3 \n\t"
1337 "paddw %%mm2, %%mm3 \n\t" //t10
1339 "paddw %%mm4, %%mm2 \n\t" //t11
1340 "paddw %%mm0, %%mm4 \n\t" //t12
1342 "movq %%mm3, %%mm7 \n\t"
1343 "psubw %%mm4, %%mm3 \n\t"
1345 "psllw $2, %%mm3 \n\t"
1346 "psllw $2, %%mm7 \n\t" //opt for P6
1348 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
1349 "psllw $2, %%mm4 \n\t"
1351 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
1352 "psllw $2, %%mm2 \n\t"
1354 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
1355 "paddw %%mm1, %%mm5 \n\t" //'t1
1357 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
1358 "psubw %%mm1, %%mm6 \n\t" //'t2
1359 // t7 't12 't11 t4 t6 - 't13 't10 ---
1361 "paddw %%mm3, %%mm7 \n\t" //z2
1363 "movq %%mm5, 1*8+%3 \n\t"
1364 "paddw %%mm3, %%mm4 \n\t" //z4
1366 "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
1367 "movq %%mm0, %%mm1 \n\t"
1369 "movq %%mm6, 2*8+%3 \n\t"
1370 "psubw %%mm2, %%mm1 \n\t" //z13
1372 //===
1373 "paddw %%mm2, %%mm0 \n\t" //z11
1374 "movq %%mm1, %%mm5 \n\t"
1376 "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
1377 "psubw %%mm7, %%mm1 \n\t" //d3
1379 "paddw %%mm7, %%mm5 \n\t" //d5
1380 "psubw %%mm3, %%mm1 \n\t"
1382 "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
1383 "psubw %%mm2, %%mm5 \n\t"
1385 "movq %%mm0, %%mm6 \n\t"
1386 "paddw %%mm4, %%mm0 \n\t" //d1
1388 "paddusw %%mm3, %%mm1 \n\t"
1389 "psubw %%mm4, %%mm6 \n\t" //d7
1391 // d1 d3 - - - d5 d7 -
1392 "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
1393 "psubw %%mm7, %%mm0 \n\t"
1395 "psubw %%mm4, %%mm6 \n\t"
1396 "paddusw %%mm2, %%mm5 \n\t"
1398 "paddusw %%mm4, %%mm6 \n\t"
1399 "paddw %%mm3, %%mm1 \n\t"
1401 "paddw %%mm2, %%mm5 \n\t"
1402 "paddw %%mm4, %%mm6 \n\t"
1404 "psubusw %%mm3, %%mm1 \n\t"
1405 "psubusw %%mm2, %%mm5 \n\t"
1407 "psubusw %%mm4, %%mm6 \n\t"
1408 "movq %%mm1, %%mm4 \n\t"
1410 "por %%mm5, %%mm4 \n\t"
1411 "paddusw %%mm7, %%mm0 \n\t"
1413 "por %%mm6, %%mm4 \n\t"
1414 "paddw %%mm7, %%mm0 \n\t"
1416 "packssdw %%mm4, %%mm4 \n\t"
1417 "psubusw %%mm7, %%mm0 \n\t"
1419 "movd %%mm4, %%"REG_a" \n\t"
1420 "or %%"REG_a", %%"REG_a" \n\t"
1421 "jnz 3f \n\t"
1422 //movq [edi+"DCTSIZE_S"*3*2], mm1
1423 //movq [edi+"DCTSIZE_S"*5*2], mm5
1424 //movq [edi+"DCTSIZE_S"*1*2], mm0
1425 //movq [edi+"DCTSIZE_S"*7*2], mm6
1426 // t4 t5 - - - t6 t7 -
1427 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1428 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1429 "movq 0*8+%3, %%mm4 \n\t"
1430 "movq %%mm0, %%mm1 \n\t"
1432 "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
1433 "movq %%mm1, %%mm2 \n\t"
1435 "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
1436 "movq %%mm2, %%mm3 \n\t"
1438 "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
1439 "paddw %%mm4, %%mm5 \n\t"
1441 "movq 1*8+%3, %%mm6 \n\t"
1442 //paddw mm3, MM_2
1443 "psraw $2, %%mm3 \n\t" //tmp7
1445 "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
1446 "psubw %%mm3, %%mm4 \n\t"
1448 "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
1449 "paddw %%mm3, %%mm5 \n\t"
1451 "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1452 "paddw %%mm6, %%mm7 \n\t"
1454 "movq 2*8+%3, %%mm3 \n\t"
1455 "psubw %%mm0, %%mm6 \n\t"
1457 "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
1458 "paddw %%mm0, %%mm7 \n\t"
1460 "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1461 "paddw %%mm3, %%mm4 \n\t"
1463 "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1464 "psubw %%mm1, %%mm3 \n\t"
1466 "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
1467 "paddw %%mm1, %%mm4 \n\t"
1469 "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
1470 "paddw %%mm3, %%mm5 \n\t"
1472 "movq 3*8+%3, %%mm0 \n\t"
1473 "add $24, %%"REG_S" \n\t"
1475 "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1476 "paddw %%mm0, %%mm6 \n\t"
1478 "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1479 "psubw %%mm2, %%mm0 \n\t"
1481 "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
1482 "paddw %%mm2, %%mm6 \n\t"
1484 "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1485 "paddw %%mm0, %%mm7 \n\t"
1487 "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1489 "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1490 "add $24, %%"REG_D" \n\t"
1491 "sub $2, %%"REG_c" \n\t"
1492 "jnz 1b \n\t"
1493 "jmp 5f \n\t"
1495 "3: \n\t"
1496 //--- non DC2
1497 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1498 //psraw mm5, 2
1499 //psraw mm0, 2
1500 //psraw mm6, 2
1501 "movq %%mm5, %%mm3 \n\t"
1502 "psubw %%mm1, %%mm5 \n\t"
1504 "psllw $1, %%mm5 \n\t" //'z10
1505 "paddw %%mm1, %%mm3 \n\t" //'z13
1507 "movq %%mm0, %%mm2 \n\t"
1508 "psubw %%mm6, %%mm0 \n\t"
1510 "movq %%mm5, %%mm1 \n\t"
1511 "psllw $1, %%mm0 \n\t" //'z12
1513 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
1514 "paddw %%mm0, %%mm5 \n\t"
1516 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
1517 "paddw %%mm6, %%mm2 \n\t" //'z11
1519 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
1520 "movq %%mm2, %%mm7 \n\t"
1522 //---
1523 "movq 0*8+%3, %%mm4 \n\t"
1524 "psubw %%mm3, %%mm2 \n\t"
1526 "psllw $1, %%mm2 \n\t"
1527 "paddw %%mm3, %%mm7 \n\t" //'t7
1529 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
1530 "movq %%mm4, %%mm6 \n\t"
1531 //paddw mm7, MM_2
1532 "psraw $2, %%mm7 \n\t"
1534 "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
1535 "psubw %%mm7, %%mm6 \n\t"
1537 "movq 1*8+%3, %%mm3 \n\t"
1538 "paddw %%mm7, %%mm4 \n\t"
1540 "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
1541 "paddw %%mm5, %%mm1 \n\t" //'t12
1543 "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
1544 "psubw %%mm7, %%mm1 \n\t" //'t6
1546 "movq 2*8+%3, %%mm7 \n\t"
1547 "psubw %%mm5, %%mm0 \n\t" //'t10
1549 "movq 3*8+%3, %%mm6 \n\t"
1550 "movq %%mm3, %%mm5 \n\t"
1552 "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
1553 "psubw %%mm1, %%mm5 \n\t"
1555 "psubw %%mm1, %%mm2 \n\t" //'t5
1556 "paddw %%mm1, %%mm3 \n\t"
1558 "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
1559 "movq %%mm7, %%mm4 \n\t"
1561 "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
1562 "psubw %%mm2, %%mm4 \n\t"
1564 "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
1565 "paddw %%mm2, %%mm7 \n\t"
1567 "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
1568 "paddw %%mm2, %%mm0 \n\t" //'t4
1570 // 't4 't6 't5 - - - - 't7
1571 "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
1572 "movq %%mm6, %%mm1 \n\t"
1574 "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
1575 "psubw %%mm0, %%mm1 \n\t"
1577 "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
1578 "paddw %%mm0, %%mm6 \n\t"
1580 "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
1581 "add $24, %%"REG_S" \n\t"
1583 "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
1585 "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
1586 "add $24, %%"REG_D" \n\t"
1587 "sub $2, %%"REG_c" \n\t"
1588 "jnz 1b \n\t"
1589 "5: \n\t"
1591 : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
1592 : "d"(thr_adr)
1593 : "%"REG_a
1597 #endif // HAVE_MMX
1599 #if !HAVE_MMX
1601 static void row_idct_c(DCTELEM* workspace,
1602 int16_t* output_adr, int output_stride, int cnt)
1604 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1605 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1606 int_simd16_t z5, z10, z11, z12, z13;
1607 int16_t* outptr;
1608 DCTELEM* wsptr;
1610 cnt*=4;
1611 wsptr = workspace;
1612 outptr = output_adr;
1613 for (; cnt > 0; cnt--) {
1614 // Even part
1615 //Simd version reads 4x4 block and transposes it
1616 tmp10 = ( wsptr[2] + wsptr[3]);
1617 tmp11 = ( wsptr[2] - wsptr[3]);
1619 tmp13 = ( wsptr[0] + wsptr[1]);
1620 tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
1622 tmp0 = tmp10 + tmp13; //->temps
1623 tmp3 = tmp10 - tmp13; //->temps
1624 tmp1 = tmp11 + tmp12;
1625 tmp2 = tmp11 - tmp12;
1627 // Odd part
1628 //Also transpose, with previous:
1629 // ---- ---- ||||
1630 // ---- ---- idct ||||
1631 // ---- ---- ---> ||||
1632 // ---- ---- ||||
1633 z13 = wsptr[4] + wsptr[5];
1634 z10 = wsptr[4] - wsptr[5];
1635 z11 = wsptr[6] + wsptr[7];
1636 z12 = wsptr[6] - wsptr[7];
1638 tmp7 = z11 + z13;
1639 tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
1641 z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
1642 tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
1643 tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
1645 tmp6 = (tmp12<<3) - tmp7;
1646 tmp5 = (tmp11<<3) - tmp6;
1647 tmp4 = (tmp10<<3) + tmp5;
1649 // Final output stage: descale and write column
1650 outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
1651 outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
1652 outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
1653 outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
1654 outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
1655 outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
1656 outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
1657 outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
1658 outptr++;
1660 wsptr += DCTSIZE; // advance pointer to next row
1664 #else /* HAVE_MMX */
1666 static void row_idct_mmx (DCTELEM* workspace,
1667 int16_t* output_adr, int output_stride, int cnt)
1669 uint64_t __attribute__((aligned(8))) temps[4];
1670 __asm__ volatile(
1671 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1672 "1: \n\t"
1673 "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
1676 "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
1677 "movq %%mm0, %%mm4 \n\t"
1679 "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
1680 "punpcklwd %%mm1, %%mm0 \n\t"
1682 "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
1683 "punpckhwd %%mm1, %%mm4 \n\t"
1685 //transpose 4x4
1686 "movq %%mm2, %%mm7 \n\t"
1687 "punpcklwd %%mm3, %%mm2 \n\t"
1689 "movq %%mm0, %%mm6 \n\t"
1690 "punpckldq %%mm2, %%mm0 \n\t" //0
1692 "punpckhdq %%mm2, %%mm6 \n\t" //1
1693 "movq %%mm0, %%mm5 \n\t"
1695 "punpckhwd %%mm3, %%mm7 \n\t"
1696 "psubw %%mm6, %%mm0 \n\t"
1698 "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
1699 "movq %%mm4, %%mm2 \n\t"
1701 "punpckldq %%mm7, %%mm4 \n\t" //2
1702 "paddw %%mm6, %%mm5 \n\t"
1704 "punpckhdq %%mm7, %%mm2 \n\t" //3
1705 "movq %%mm4, %%mm1 \n\t"
1707 "psllw $2, %%mm0 \n\t"
1708 "paddw %%mm2, %%mm4 \n\t" //t10
1710 "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
1711 "psubw %%mm2, %%mm1 \n\t" //t11
1713 "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
1714 "psubw %%mm5, %%mm0 \n\t"
1716 "movq %%mm4, %%mm6 \n\t"
1717 "paddw %%mm5, %%mm4 \n\t" //t0
1719 "psubw %%mm5, %%mm6 \n\t" //t3
1720 "movq %%mm1, %%mm7 \n\t"
1722 "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
1723 "paddw %%mm0, %%mm1 \n\t" //t1
1725 "movq %%mm4, 0*8+%3 \n\t" //t0
1726 "movq %%mm3, %%mm4 \n\t"
1728 "movq %%mm6, 1*8+%3 \n\t" //t3
1729 "punpcklwd %%mm2, %%mm3 \n\t"
1731 //transpose 4x4
1732 "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
1733 "punpckhwd %%mm2, %%mm4 \n\t"
1735 "movq %%mm5, %%mm2 \n\t"
1736 "punpcklwd %%mm6, %%mm5 \n\t"
1738 "psubw %%mm0, %%mm7 \n\t" //t2
1739 "punpckhwd %%mm6, %%mm2 \n\t"
1741 "movq %%mm3, %%mm0 \n\t"
1742 "punpckldq %%mm5, %%mm3 \n\t" //4
1744 "punpckhdq %%mm5, %%mm0 \n\t" //5
1745 "movq %%mm4, %%mm5 \n\t"
1748 "movq %%mm3, %%mm6 \n\t"
1749 "punpckldq %%mm2, %%mm4 \n\t" //6
1751 "psubw %%mm0, %%mm3 \n\t" //z10
1752 "punpckhdq %%mm2, %%mm5 \n\t" //7
1754 "paddw %%mm0, %%mm6 \n\t" //z13
1755 "movq %%mm4, %%mm2 \n\t"
1757 "movq %%mm3, %%mm0 \n\t"
1758 "psubw %%mm5, %%mm4 \n\t" //z12
1760 "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
1761 "paddw %%mm4, %%mm3 \n\t"
1763 "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
1764 "paddw %%mm5, %%mm2 \n\t" //z11 >
1766 "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
1767 "movq %%mm2, %%mm5 \n\t"
1769 "psubw %%mm6, %%mm2 \n\t"
1770 "paddw %%mm6, %%mm5 \n\t" //t7
1772 "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
1773 "paddw %%mm3, %%mm0 \n\t" //t12
1775 "psllw $3, %%mm0 \n\t"
1776 "psubw %%mm3, %%mm4 \n\t" //t10
1778 "movq 0*8+%3, %%mm6 \n\t"
1779 "movq %%mm1, %%mm3 \n\t"
1781 "psllw $3, %%mm4 \n\t"
1782 "psubw %%mm5, %%mm0 \n\t" //t6
1784 "psllw $3, %%mm2 \n\t"
1785 "paddw %%mm0, %%mm1 \n\t" //d1
1787 "psubw %%mm0, %%mm2 \n\t" //t5
1788 "psubw %%mm0, %%mm3 \n\t" //d6
1790 "paddw %%mm2, %%mm4 \n\t" //t4
1791 "movq %%mm7, %%mm0 \n\t"
1793 "paddw %%mm2, %%mm7 \n\t" //d2
1794 "psubw %%mm2, %%mm0 \n\t" //d5
1796 "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
1797 "psubw %%mm5, %%mm6 \n\t" //d7
1799 "paddw 0*8+%3, %%mm5 \n\t" //d0
1800 "paddw %%mm2, %%mm1 \n\t"
1802 "paddw %%mm2, %%mm5 \n\t"
1803 "psraw $3, %%mm1 \n\t"
1805 "paddw %%mm2, %%mm7 \n\t"
1806 "psraw $3, %%mm5 \n\t"
1808 "paddw (%%"REG_D"), %%mm5 \n\t"
1809 "psraw $3, %%mm7 \n\t"
1811 "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
1812 "paddw %%mm2, %%mm0 \n\t"
1814 "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
1815 "paddw %%mm2, %%mm3 \n\t"
1817 "movq %%mm5, (%%"REG_D") \n\t"
1818 "paddw %%mm2, %%mm6 \n\t"
1820 "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
1821 "psraw $3, %%mm0 \n\t"
1823 "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
1824 "add %%"REG_d", %%"REG_D" \n\t" //3*ls
1826 "movq 1*8+%3, %%mm5 \n\t" //t3
1827 "psraw $3, %%mm3 \n\t"
1829 "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
1830 "psubw %%mm4, %%mm5 \n\t" //d3
1832 "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
1833 "psraw $3, %%mm6 \n\t"
1835 "paddw 1*8+%3, %%mm4 \n\t" //d4
1836 "paddw %%mm2, %%mm5 \n\t"
1838 "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
1839 "paddw %%mm2, %%mm4 \n\t"
1841 "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
1842 "psraw $3, %%mm5 \n\t"
1844 "paddw (%%"REG_D"), %%mm5 \n\t"
1845 "psraw $3, %%mm4 \n\t"
1847 "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
1848 "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
1850 "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
1851 "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
1852 "movq %%mm5, (%%"REG_D") \n\t"
1853 "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
1855 "sub %%"REG_d", %%"REG_D" \n\t"
1856 "add $8, %%"REG_D" \n\t"
1857 "dec %%"REG_c" \n\t"
1858 "jnz 1b \n\t"
1860 : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
1861 : "a"(output_stride*sizeof(short))
1862 : "%"REG_d
1866 #endif // HAVE_MMX
1868 #if !HAVE_MMX
1870 static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1872 int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1873 int_simd16_t tmp10, tmp11, tmp12, tmp13;
1874 int_simd16_t z1, z2, z3, z4, z5, z11, z13;
1875 DCTELEM *dataptr;
1877 cnt*=4;
1878 // Pass 1: process rows.
1880 dataptr = data;
1881 for (; cnt > 0; cnt--) {
1882 tmp0 = pixels[line_size*0] + pixels[line_size*7];
1883 tmp7 = pixels[line_size*0] - pixels[line_size*7];
1884 tmp1 = pixels[line_size*1] + pixels[line_size*6];
1885 tmp6 = pixels[line_size*1] - pixels[line_size*6];
1886 tmp2 = pixels[line_size*2] + pixels[line_size*5];
1887 tmp5 = pixels[line_size*2] - pixels[line_size*5];
1888 tmp3 = pixels[line_size*3] + pixels[line_size*4];
1889 tmp4 = pixels[line_size*3] - pixels[line_size*4];
1891 // Even part
1893 tmp10 = tmp0 + tmp3;
1894 tmp13 = tmp0 - tmp3;
1895 tmp11 = tmp1 + tmp2;
1896 tmp12 = tmp1 - tmp2;
1897 //Even columns are written first, this leads to different order of columns
1898 //in column_fidct(), but they are processed independently, so all ok.
1899 //Later in the row_idct() columns readed at the same order.
1900 dataptr[2] = tmp10 + tmp11;
1901 dataptr[3] = tmp10 - tmp11;
1903 z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
1904 dataptr[0] = tmp13 + z1;
1905 dataptr[1] = tmp13 - z1;
1907 // Odd part
1909 tmp10 = (tmp4 + tmp5) <<2;
1910 tmp11 = (tmp5 + tmp6) <<2;
1911 tmp12 = (tmp6 + tmp7) <<2;
1913 z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
1914 z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
1915 z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
1916 z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
1918 z11 = tmp7 + z3;
1919 z13 = tmp7 - z3;
1921 dataptr[4] = z13 + z2;
1922 dataptr[5] = z13 - z2;
1923 dataptr[6] = z11 + z4;
1924 dataptr[7] = z11 - z4;
1926 pixels++; // advance pointer to next column
1927 dataptr += DCTSIZE;
1931 #else /* HAVE_MMX */
1933 static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
1935 uint64_t __attribute__((aligned(8))) temps[4];
1936 __asm__ volatile(
1937 "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
1938 "6: \n\t"
1939 "movd (%%"REG_S"), %%mm0 \n\t"
1940 "pxor %%mm7, %%mm7 \n\t"
1942 "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
1943 "punpcklbw %%mm7, %%mm0 \n\t"
1945 "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
1946 "punpcklbw %%mm7, %%mm1 \n\t"
1948 "punpcklbw %%mm7, %%mm2 \n\t"
1949 "add %%"REG_d", %%"REG_S" \n\t"
1951 "movq %%mm0, %%mm5 \n\t"
1954 "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
1955 "movq %%mm1, %%mm6 \n\t"
1957 "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
1958 "punpcklbw %%mm7, %%mm3 \n\t"
1960 "psubw %%mm3, %%mm5 \n\t"
1961 "punpcklbw %%mm7, %%mm4 \n\t"
1963 "paddw %%mm3, %%mm0 \n\t"
1964 "psubw %%mm4, %%mm6 \n\t"
1966 "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
1967 "paddw %%mm4, %%mm1 \n\t"
1969 "movq %%mm5, 0*8+%3 \n\t" //t7
1970 "punpcklbw %%mm7, %%mm3 \n\t"
1972 "movq %%mm6, 1*8+%3 \n\t" //t6
1973 "movq %%mm2, %%mm4 \n\t"
1975 "movd (%%"REG_S"), %%mm5 \n\t" //3
1976 "paddw %%mm3, %%mm2 \n\t"
1978 "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
1979 "punpcklbw %%mm7, %%mm5 \n\t"
1981 "psubw %%mm3, %%mm4 \n\t"
1982 "punpcklbw %%mm7, %%mm6 \n\t"
1984 "movq %%mm5, %%mm3 \n\t"
1985 "paddw %%mm6, %%mm5 \n\t" //t3
1987 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1988 "movq %%mm0, %%mm6 \n\t"
1990 "movq %%mm1, %%mm7 \n\t"
1991 "psubw %%mm5, %%mm0 \n\t" //t13
1993 "psubw %%mm2, %%mm1 \n\t"
1994 "paddw %%mm2, %%mm7 \n\t" //t11
1996 "paddw %%mm0, %%mm1 \n\t"
1997 "movq %%mm7, %%mm2 \n\t"
1999 "psllw $2, %%mm1 \n\t"
2000 "paddw %%mm5, %%mm6 \n\t" //t10
2002 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
2003 "paddw %%mm6, %%mm7 \n\t" //d2
2005 "psubw %%mm2, %%mm6 \n\t" //d3
2006 "movq %%mm0, %%mm5 \n\t"
2008 //transpose 4x4
2009 "movq %%mm7, %%mm2 \n\t"
2010 "punpcklwd %%mm6, %%mm7 \n\t"
2012 "paddw %%mm1, %%mm0 \n\t" //d0
2013 "punpckhwd %%mm6, %%mm2 \n\t"
2015 "psubw %%mm1, %%mm5 \n\t" //d1
2016 "movq %%mm0, %%mm6 \n\t"
2018 "movq 1*8+%3, %%mm1 \n\t"
2019 "punpcklwd %%mm5, %%mm0 \n\t"
2021 "punpckhwd %%mm5, %%mm6 \n\t"
2022 "movq %%mm0, %%mm5 \n\t"
2024 "punpckldq %%mm7, %%mm0 \n\t" //0
2025 "paddw %%mm4, %%mm3 \n\t"
2027 "punpckhdq %%mm7, %%mm5 \n\t" //1
2028 "movq %%mm6, %%mm7 \n\t"
2030 "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
2031 "punpckldq %%mm2, %%mm6 \n\t" //2
2033 "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
2034 "punpckhdq %%mm2, %%mm7 \n\t" //3
2036 "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
2037 "paddw %%mm1, %%mm4 \n\t"
2039 "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
2040 "psllw $2, %%mm3 \n\t" //t10
2042 "movq 0*8+%3, %%mm2 \n\t"
2043 "psllw $2, %%mm4 \n\t" //t11
2045 "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
2046 "paddw %%mm2, %%mm1 \n\t"
2048 "psllw $2, %%mm1 \n\t" //t12
2049 "movq %%mm3, %%mm0 \n\t"
2051 "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
2052 "psubw %%mm1, %%mm3 \n\t"
2054 "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
2055 "movq %%mm2, %%mm5 \n\t"
2057 "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
2058 "psubw %%mm4, %%mm2 \n\t" //z13
2060 "paddw %%mm4, %%mm5 \n\t" //z11
2061 "movq %%mm2, %%mm6 \n\t"
2063 "paddw %%mm3, %%mm0 \n\t" //z2
2064 "movq %%mm5, %%mm7 \n\t"
2066 "paddw %%mm0, %%mm2 \n\t" //d4
2067 "psubw %%mm0, %%mm6 \n\t" //d5
2069 "movq %%mm2, %%mm4 \n\t"
2070 "paddw %%mm3, %%mm1 \n\t" //z4
2072 //transpose 4x4
2073 "punpcklwd %%mm6, %%mm2 \n\t"
2074 "paddw %%mm1, %%mm5 \n\t" //d6
2076 "punpckhwd %%mm6, %%mm4 \n\t"
2077 "psubw %%mm1, %%mm7 \n\t" //d7
2079 "movq %%mm5, %%mm6 \n\t"
2080 "punpcklwd %%mm7, %%mm5 \n\t"
2082 "punpckhwd %%mm7, %%mm6 \n\t"
2083 "movq %%mm2, %%mm7 \n\t"
2085 "punpckldq %%mm5, %%mm2 \n\t" //4
2086 "sub %%"REG_d", %%"REG_S" \n\t"
2088 "punpckhdq %%mm5, %%mm7 \n\t" //5
2089 "movq %%mm4, %%mm5 \n\t"
2091 "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2092 "punpckldq %%mm6, %%mm4 \n\t" //6
2094 "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2095 "punpckhdq %%mm6, %%mm5 \n\t" //7
2097 "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2098 "add $4, %%"REG_S" \n\t"
2100 "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
2101 "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
2102 "dec %%"REG_c" \n\t"
2103 "jnz 6b \n\t"
2105 : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps)
2106 : "a"(line_size)
2107 : "%"REG_d);
2110 #endif // HAVE_MMX