2 Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
3 Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * This implementation is based on an algorithm described in
22 * "Aria Nosratinia Embedded Post-Processing for
23 * Enhancement of Compressed Images (1999)"
24 * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
25 * Futher, with splitting (i)dct into hor/ver passes, one of them can be
26 * performed once per block, not pixel. This allows for much better speed.
30 Heavily optimized version of SPP filter by Nikolaj
42 #include "cpudetect.h"
44 #include "libavcodec/avcodec.h"
45 #include "libavcodec/dsputil.h"
51 #include "img_format.h"
54 #include "libvo/fastmemcpy.h"
56 //===========================================================================//
59 static const short custom_threshold
[64]=
60 // values (296) can't be too high
61 // -it causes too big quant dependence
62 // or maybe overflow(check), which results in some flashing
63 { 71, 296, 295, 237, 71, 40, 38, 19,
64 245, 193, 185, 121, 102, 73, 53, 27,
65 158, 129, 141, 107, 97, 73, 50, 26,
66 102, 116, 109, 98, 82, 66, 45, 23,
67 71, 94, 95, 81, 70, 56, 38, 20,
68 56, 77, 74, 66, 56, 44, 30, 15,
69 38, 53, 50, 45, 38, 30, 21, 11,
70 20, 27, 26, 23, 20, 15, 11, 5
73 static const uint8_t __attribute__((aligned(32))) dither
[8][8]={
74 { 0, 48, 12, 60, 3, 51, 15, 63, },
75 { 32, 16, 44, 28, 35, 19, 47, 31, },
76 { 8, 56, 4, 52, 11, 59, 7, 55, },
77 { 40, 24, 36, 20, 43, 27, 39, 23, },
78 { 2, 50, 14, 62, 1, 49, 13, 61, },
79 { 34, 18, 46, 30, 33, 17, 45, 29, },
80 { 10, 58, 6, 54, 9, 57, 5, 53, },
81 { 42, 26, 38, 22, 41, 25, 37, 21, },
84 struct vf_priv_s
{ //align 16 !
85 uint64_t threshold_mtx_noq
[8*2];
86 uint64_t threshold_mtx
[8*2];//used in both C & MMX (& later SSE2) versions
102 //This func reads from 1 slice, 1 and clears 0 & 1
103 static void store_slice_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
106 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
107 src[x + pos]=src[x + pos - 8*src_stride]=0; \
108 if(temp & 0x100) temp= ~(temp>>31); \
111 for(y
=0; y
<height
; y
++){
112 const uint8_t *d
= dither
[y
];
113 for(x
=0; x
<width
; x
+=8){
129 //This func reads from 2 slices, 0 & 2 and clears 2-nd
130 static void store_slice2_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
132 #define STORE2(pos) \
133 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
134 src[x + pos + 16*src_stride]=0; \
135 if(temp & 0x100) temp= ~(temp>>31); \
138 for(y
=0; y
<height
; y
++){
139 const uint8_t *d
= dither
[y
];
140 for(x
=0; x
<width
; x
+=8){
156 static void mul_thrmat_c(struct vf_priv_s
*p
,int q
)
160 ((short*)p
->threshold_mtx
)[a
]=q
* ((short*)p
->threshold_mtx_noq
)[a
];//ints faster in C
163 static void column_fidct_c(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
164 static void row_idct_c(DCTELEM
* workspace
,
165 int16_t* output_adr
, int output_stride
, int cnt
);
166 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
168 //this is rather ugly, but there is no need for function pointers
169 #define store_slice_s store_slice_c
170 #define store_slice2_s store_slice2_c
171 #define mul_thrmat_s mul_thrmat_c
172 #define column_fidct_s column_fidct_c
173 #define row_idct_s row_idct_c
174 #define row_fdct_s row_fdct_c
178 //This func reads from 1 slice, 1 and clears 0 & 1
179 static void store_slice_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
181 const uint8_t *od
=&dither
[0][0];
182 const uint8_t *end
=&dither
[height
][0];
183 width
= (width
+7)&~7;
185 //src_stride=(src_stride-width)*2;
187 "mov %5, %%"REG_d
" \n\t"
188 "mov %6, %%"REG_S
" \n\t"
189 "mov %7, %%"REG_D
" \n\t"
190 "mov %1, %%"REG_a
" \n\t"
191 "movd %%"REG_d
", %%mm5 \n\t"
192 "xor $-1, %%"REG_d
" \n\t"
193 "mov %%"REG_a
", %%"REG_c
" \n\t"
194 "add $7, %%"REG_d
" \n\t"
196 "sub %0, %%"REG_c
" \n\t"
197 "add %%"REG_c
", %%"REG_c
" \n\t"
198 "movd %%"REG_d
", %%mm2 \n\t"
199 "mov %%"REG_c
", %1 \n\t"
200 "mov %2, %%"REG_d
" \n\t"
201 "shl $4, %%"REG_a
" \n\t"
204 "movq (%%"REG_d
"), %%mm3 \n\t"
205 "movq %%mm3, %%mm4 \n\t"
206 "pxor %%mm7, %%mm7 \n\t"
207 "punpcklbw %%mm7, %%mm3 \n\t"
208 "punpckhbw %%mm7, %%mm4 \n\t"
209 "mov %0, %%"REG_c
" \n\t"
210 "psraw %%mm5, %%mm3 \n\t"
211 "psraw %%mm5, %%mm4 \n\t"
213 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
214 "movq (%%"REG_S
"), %%mm0 \n\t"
215 "movq 8(%%"REG_S
"), %%mm1 \n\t"
217 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
218 "paddw %%mm3, %%mm0 \n\t"
219 "paddw %%mm4, %%mm1 \n\t"
221 "movq %%mm7, (%%"REG_S
") \n\t"
222 "psraw %%mm2, %%mm0 \n\t"
223 "psraw %%mm2, %%mm1 \n\t"
225 "movq %%mm7, 8(%%"REG_S
") \n\t"
226 "packuswb %%mm1, %%mm0 \n\t"
227 "add $16, %%"REG_S
" \n\t"
229 "movq %%mm0, (%%"REG_D
") \n\t"
230 "add $8, %%"REG_D
" \n\t"
231 "sub $8, %%"REG_c
" \n\t"
233 "add %1, %%"REG_S
" \n\t"
234 "add $8, %%"REG_d
" \n\t"
235 "add %3, %%"REG_D
" \n\t"
236 "cmp %4, %%"REG_d
" \n\t"
240 : "m" (width
), "m" (src_stride
), "g" (od
), "m" (dst_stride
), "g" (end
),
241 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
242 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_S
, "%"REG_D
246 //This func reads from 2 slices, 0 & 2 and clears 2-nd
247 static void store_slice2_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
249 const uint8_t *od
=&dither
[0][0];
250 const uint8_t *end
=&dither
[height
][0];
251 width
= (width
+7)&~7;
253 //src_stride=(src_stride-width)*2;
255 "mov %5, %%"REG_d
" \n\t"
256 "mov %6, %%"REG_S
" \n\t"
257 "mov %7, %%"REG_D
" \n\t"
258 "mov %1, %%"REG_a
" \n\t"
259 "movd %%"REG_d
", %%mm5 \n\t"
260 "xor $-1, %%"REG_d
" \n\t"
261 "mov %%"REG_a
", %%"REG_c
" \n\t"
262 "add $7, %%"REG_d
" \n\t"
263 "sub %0, %%"REG_c
" \n\t"
264 "add %%"REG_c
", %%"REG_c
" \n\t"
265 "movd %%"REG_d
", %%mm2 \n\t"
266 "mov %%"REG_c
", %1 \n\t"
267 "mov %2, %%"REG_d
" \n\t"
268 "shl $5, %%"REG_a
" \n\t"
271 "movq (%%"REG_d
"), %%mm3 \n\t"
272 "movq %%mm3, %%mm4 \n\t"
273 "pxor %%mm7, %%mm7 \n\t"
274 "punpcklbw %%mm7, %%mm3 \n\t"
275 "punpckhbw %%mm7, %%mm4 \n\t"
276 "mov %0, %%"REG_c
" \n\t"
277 "psraw %%mm5, %%mm3 \n\t"
278 "psraw %%mm5, %%mm4 \n\t"
280 "movq (%%"REG_S
"), %%mm0 \n\t"
281 "movq 8(%%"REG_S
"), %%mm1 \n\t"
282 "paddw %%mm3, %%mm0 \n\t"
284 "paddw (%%"REG_S
",%%"REG_a
",), %%mm0 \n\t"
285 "paddw %%mm4, %%mm1 \n\t"
286 "movq 8(%%"REG_S
",%%"REG_a
",), %%mm6 \n\t"
288 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
289 "psraw %%mm2, %%mm0 \n\t"
290 "paddw %%mm6, %%mm1 \n\t"
292 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
293 "psraw %%mm2, %%mm1 \n\t"
294 "packuswb %%mm1, %%mm0 \n\t"
296 "movq %%mm0, (%%"REG_D
") \n\t"
297 "add $16, %%"REG_S
" \n\t"
298 "add $8, %%"REG_D
" \n\t"
299 "sub $8, %%"REG_c
" \n\t"
301 "add %1, %%"REG_S
" \n\t"
302 "add $8, %%"REG_d
" \n\t"
303 "add %3, %%"REG_D
" \n\t"
304 "cmp %4, %%"REG_d
" \n\t"
308 : "m" (width
), "m" (src_stride
), "g" (od
), "m" (dst_stride
), "g" (end
),
309 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
310 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_D
, "%"REG_S
314 static void mul_thrmat_mmx(struct vf_priv_s
*p
, int q
)
316 uint64_t *adr
=&p
->threshold_mtx_noq
[0];
318 "movd %0, %%mm7 \n\t"
319 "add $8*8*2, %%"REG_D
" \n\t"
320 "movq 0*8(%%"REG_S
"), %%mm0 \n\t"
321 "punpcklwd %%mm7, %%mm7 \n\t"
322 "movq 1*8(%%"REG_S
"), %%mm1 \n\t"
323 "punpckldq %%mm7, %%mm7 \n\t"
324 "pmullw %%mm7, %%mm0 \n\t"
326 "movq 2*8(%%"REG_S
"), %%mm2 \n\t"
327 "pmullw %%mm7, %%mm1 \n\t"
329 "movq 3*8(%%"REG_S
"), %%mm3 \n\t"
330 "pmullw %%mm7, %%mm2 \n\t"
332 "movq %%mm0, 0*8(%%"REG_D
") \n\t"
333 "movq 4*8(%%"REG_S
"), %%mm4 \n\t"
334 "pmullw %%mm7, %%mm3 \n\t"
336 "movq %%mm1, 1*8(%%"REG_D
") \n\t"
337 "movq 5*8(%%"REG_S
"), %%mm5 \n\t"
338 "pmullw %%mm7, %%mm4 \n\t"
340 "movq %%mm2, 2*8(%%"REG_D
") \n\t"
341 "movq 6*8(%%"REG_S
"), %%mm6 \n\t"
342 "pmullw %%mm7, %%mm5 \n\t"
344 "movq %%mm3, 3*8(%%"REG_D
") \n\t"
345 "movq 7*8+0*8(%%"REG_S
"), %%mm0 \n\t"
346 "pmullw %%mm7, %%mm6 \n\t"
348 "movq %%mm4, 4*8(%%"REG_D
") \n\t"
349 "movq 7*8+1*8(%%"REG_S
"), %%mm1 \n\t"
350 "pmullw %%mm7, %%mm0 \n\t"
352 "movq %%mm5, 5*8(%%"REG_D
") \n\t"
353 "movq 7*8+2*8(%%"REG_S
"), %%mm2 \n\t"
354 "pmullw %%mm7, %%mm1 \n\t"
356 "movq %%mm6, 6*8(%%"REG_D
") \n\t"
357 "movq 7*8+3*8(%%"REG_S
"), %%mm3 \n\t"
358 "pmullw %%mm7, %%mm2 \n\t"
360 "movq %%mm0, 7*8+0*8(%%"REG_D
") \n\t"
361 "movq 7*8+4*8(%%"REG_S
"), %%mm4 \n\t"
362 "pmullw %%mm7, %%mm3 \n\t"
364 "movq %%mm1, 7*8+1*8(%%"REG_D
") \n\t"
365 "movq 7*8+5*8(%%"REG_S
"), %%mm5 \n\t"
366 "pmullw %%mm7, %%mm4 \n\t"
368 "movq %%mm2, 7*8+2*8(%%"REG_D
") \n\t"
369 "movq 7*8+6*8(%%"REG_S
"), %%mm6 \n\t"
370 "pmullw %%mm7, %%mm5 \n\t"
372 "movq %%mm3, 7*8+3*8(%%"REG_D
") \n\t"
373 "movq 14*8+0*8(%%"REG_S
"), %%mm0 \n\t"
374 "pmullw %%mm7, %%mm6 \n\t"
376 "movq %%mm4, 7*8+4*8(%%"REG_D
") \n\t"
377 "movq 14*8+1*8(%%"REG_S
"), %%mm1 \n\t"
378 "pmullw %%mm7, %%mm0 \n\t"
380 "movq %%mm5, 7*8+5*8(%%"REG_D
") \n\t"
381 "pmullw %%mm7, %%mm1 \n\t"
383 "movq %%mm6, 7*8+6*8(%%"REG_D
") \n\t"
384 "movq %%mm0, 14*8+0*8(%%"REG_D
") \n\t"
385 "movq %%mm1, 14*8+1*8(%%"REG_D
") \n\t"
387 : "+g" (q
), "+S" (adr
), "+D" (adr
)
392 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
393 static void row_idct_mmx(DCTELEM
* workspace
,
394 int16_t* output_adr
, int output_stride
, int cnt
);
395 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
397 #define store_slice_s store_slice_mmx
398 #define store_slice2_s store_slice2_mmx
399 #define mul_thrmat_s mul_thrmat_mmx
400 #define column_fidct_s column_fidct_mmx
401 #define row_idct_s row_idct_mmx
402 #define row_fdct_s row_fdct_mmx
405 static void filter(struct vf_priv_s
*p
, uint8_t *dst
, uint8_t *src
,
406 int dst_stride
, int src_stride
,
407 int width
, int height
,
408 uint8_t *qp_store
, int qp_stride
, int is_luma
)
410 int x
, x0
, y
, es
, qy
, t
;
411 const int stride
= is_luma
? p
->temp_stride
: (width
+16);//((width+16+15)&(~15))
412 const int step
=6-p
->log2_count
;
413 const int qps
= 3 + is_luma
;
414 int32_t __attribute__((aligned(32))) block_align
[4*8*BLOCKSZ
+ 4*8*BLOCKSZ
];
415 DCTELEM
*block
= (DCTELEM
*)block_align
;
416 DCTELEM
*block3
=(DCTELEM
*)(block_align
+4*8*BLOCKSZ
);
418 memset(block3
, 0, 4*8*BLOCKSZ
);
420 //p->src=src-src_stride*8-8;//!
421 if (!src
|| !dst
) return; // HACK avoid crash for Y8 colourspace
422 for(y
=0; y
<height
; y
++){
423 int index
= 8 + 8*stride
+ y
*stride
;
424 fast_memcpy(p
->src
+ index
, src
+ y
*src_stride
, width
);//this line can be avoided by using DR & user fr.buffers
426 p
->src
[index
- x
- 1]= p
->src
[index
+ x
];
427 p
->src
[index
+ width
+ x
]= p
->src
[index
+ width
- x
- 1];
431 fast_memcpy(p
->src
+ ( 7-y
)*stride
, p
->src
+ ( y
+8)*stride
, stride
);
432 fast_memcpy(p
->src
+ (height
+8+y
)*stride
, p
->src
+ (height
-y
+7)*stride
, stride
);
434 //FIXME (try edge emu)
437 memset(p
->temp
+ 8 +y
*stride
, 0,width
*sizeof(int16_t));
439 for(y
=step
; y
<height
+8; y
+=step
){ //step= 1,2
441 if (qy
>height
-1) qy
=height
-1;
443 qy
=(qy
>>qps
)*qp_stride
;
444 row_fdct_s(block
, p
->src
+ y
*stride
+2-(y
&1), stride
, 2);
445 for(x0
=0; x0
<width
+8-8*(BLOCKSZ
-1); x0
+=8*(BLOCKSZ
-1)){
446 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
448 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+0*8, block3
+0*8, 8*(BLOCKSZ
-1)); //yes, this is a HOTSPOT
450 for (x
=0; x
<8*(BLOCKSZ
-1); x
+=8) {
451 t
=x
+x0
-2; //correct t=x+x0-2-(y&1), but its the same
452 if (t
<0) t
=0;//t always < width-2
453 t
=qp_store
[qy
+(t
>>qps
)];
454 if(p
->mpeg2
) t
>>=1; //copy p->mpeg2,prev_q to locals?
455 if (t
!=p
->prev_q
) p
->prev_q
=t
, mul_thrmat_s(p
, t
);
456 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+x
*8, block3
+x
*8, 8); //yes, this is a HOTSPOT
458 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
459 memcpy(block
, block
+(BLOCKSZ
-1)*64, 8*8*sizeof(DCTELEM
)); //cycling
460 memcpy(block3
, block3
+(BLOCKSZ
-1)*64, 6*8*sizeof(DCTELEM
));
463 es
=width
+8-x0
; // 8, ...
465 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, (es
-4)>>2);
466 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
, block3
, es
&(~1));
467 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, es
>>2);
468 {const int y1
=y
-8+step
;//l5-7 l4-6
470 if (y1
&8) store_slice_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +8*stride
,
471 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
472 else store_slice2_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +0*stride
,
473 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
477 if (y
&7) { // == height & 7
478 if (y
&8) store_slice_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +8*stride
,
479 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
480 else store_slice2_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +0*stride
,
481 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
485 static int config(struct vf_instance_s
* vf
,
486 int width
, int height
, int d_width
, int d_height
,
487 unsigned int flags
, unsigned int outfmt
)
489 int h
= (height
+16+15)&(~15);
491 vf
->priv
->temp_stride
= (width
+16+15)&(~15);
492 vf
->priv
->temp
= (int16_t*)av_mallocz(vf
->priv
->temp_stride
*3*8*sizeof(int16_t));
493 //this can also be avoided, see above
494 vf
->priv
->src
= (uint8_t*)av_malloc(vf
->priv
->temp_stride
*h
*sizeof(uint8_t));
496 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
499 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
)
501 if(mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
502 // ok, we can do pp in-place (or pp disabled):
503 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
504 mpi
->type
, mpi
->flags
, mpi
->width
, mpi
->height
);
505 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
506 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
507 mpi
->width
=vf
->dmpi
->width
;
508 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
509 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
510 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
511 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
512 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
514 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
517 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
520 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
521 // no DR, so get a new image! hope we'll get DR buffer:
522 dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
524 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
525 mpi
->width
,mpi
->height
);
526 vf_clone_mpi_attributes(dmpi
, mpi
);
531 vf
->priv
->mpeg2
= mpi
->qscale_type
;
532 if(mpi
->pict_type
!= 3 && mpi
->qscale
&& !vf
->priv
->qp
){
533 if(!vf
->priv
->non_b_qp
)
534 vf
->priv
->non_b_qp
= malloc(mpi
->qstride
* ((mpi
->h
+ 15) >> 4));
535 fast_memcpy(vf
->priv
->non_b_qp
, mpi
->qscale
, mpi
->qstride
* ((mpi
->h
+ 15) >> 4));
537 if(vf
->priv
->log2_count
|| !(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
538 char *qp_tab
= vf
->priv
->non_b_qp
;
539 if(vf
->priv
->bframes
|| !qp_tab
)
542 if(qp_tab
|| vf
->priv
->qp
){
543 filter(vf
->priv
, dmpi
->planes
[0], mpi
->planes
[0], dmpi
->stride
[0], mpi
->stride
[0],
544 mpi
->w
, mpi
->h
, qp_tab
, mpi
->qstride
, 1);
545 filter(vf
->priv
, dmpi
->planes
[1], mpi
->planes
[1], dmpi
->stride
[1], mpi
->stride
[1],
546 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, qp_tab
, mpi
->qstride
, 0);
547 filter(vf
->priv
, dmpi
->planes
[2], mpi
->planes
[2], dmpi
->stride
[2], mpi
->stride
[2],
548 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, qp_tab
, mpi
->qstride
, 0);
550 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
, dmpi
->stride
[0], mpi
->stride
[0]);
551 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]);
552 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]);
557 if(gCpuCaps
.hasMMX
) asm volatile ("emms\n\t");
560 if(gCpuCaps
.hasMMX2
) asm volatile ("sfence\n\t");
562 return vf_next_put_image(vf
,dmpi
, pts
);
565 static void uninit(struct vf_instance_s
* vf
)
567 if(!vf
->priv
) return;
569 if(vf
->priv
->temp
) av_free(vf
->priv
->temp
);
570 vf
->priv
->temp
= NULL
;
571 if(vf
->priv
->src
) av_free(vf
->priv
->src
);
573 //if(vf->priv->avctx) free(vf->priv->avctx);
574 //vf->priv->avctx= NULL;
575 if(vf
->priv
->non_b_qp
) free(vf
->priv
->non_b_qp
);
576 vf
->priv
->non_b_qp
= NULL
;
582 //===========================================================================//
584 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
598 return vf_next_query_format(vf
,fmt
);
603 static int control(struct vf_instance_s
* vf
, int request
, void* data
)
606 case VFCTRL_QUERY_MAX_PP_LEVEL
:
608 case VFCTRL_SET_PP_LEVEL
:
609 vf
->priv
->log2_count
= *((unsigned int*)data
);
610 if (vf
->priv
->log2_count
< 4) vf
->priv
->log2_count
=4;
613 return vf_next_control(vf
,request
,data
);
616 static int open(vf_instance_t
*vf
, char* args
)
619 int custom_threshold_m
[64];
623 vf
->put_image
=put_image
;
624 vf
->get_image
=get_image
;
625 vf
->query_format
=query_format
;
627 vf
->control
= control
;
628 vf
->priv
=av_mallocz(sizeof(struct vf_priv_s
));//assumes align 16 !
632 //vf->priv->avctx= avcodec_alloc_context();
633 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
635 vf
->priv
->log2_count
= 4;
636 vf
->priv
->bframes
= 0;
638 if (args
) sscanf(args
, "%d:%d:%d:%d", &log2c
, &vf
->priv
->qp
, &i
, &vf
->priv
->bframes
);
640 if( log2c
>=4 && log2c
<=5 )
641 vf
->priv
->log2_count
= log2c
;
642 else if( log2c
>= 6 )
643 vf
->priv
->log2_count
= 5;
648 if (i
< -15) i
= -15;
651 bias
= (1<<4)+i
; //regulable
654 for(i
=0;i
<64;i
++) //FIXME: tune custom_threshold[] and remove this !
655 custom_threshold_m
[i
]=(int)(custom_threshold
[i
]*(bias
/71.)+ 0.5);
657 vf
->priv
->threshold_mtx_noq
[2*i
]=(uint64_t)custom_threshold_m
[i
*8+2]
658 |(((uint64_t)custom_threshold_m
[i
*8+6])<<16)
659 |(((uint64_t)custom_threshold_m
[i
*8+0])<<32)
660 |(((uint64_t)custom_threshold_m
[i
*8+4])<<48);
661 vf
->priv
->threshold_mtx_noq
[2*i
+1]=(uint64_t)custom_threshold_m
[i
*8+5]
662 |(((uint64_t)custom_threshold_m
[i
*8+3])<<16)
663 |(((uint64_t)custom_threshold_m
[i
*8+1])<<32)
664 |(((uint64_t)custom_threshold_m
[i
*8+7])<<48);
667 if (vf
->priv
->qp
) vf
->priv
->prev_q
=vf
->priv
->qp
, mul_thrmat_s(vf
->priv
, vf
->priv
->qp
);
672 vf_info_t vf_info_fspp
= {
673 "fast simple postprocess",
675 "Michael Niedermayer, Nikolaj Poroshin",
681 //====================================================================
682 //Specific spp's dct, idct and threshold functions
683 //I'd prefer to have them in the separate file.
686 //#define MANGLE(a) #a
688 //typedef int16_t DCTELEM; //! only int16_t
691 #define DCTSIZE_S "8"
693 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
694 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
695 #define FIX64(x,s) C64(FIX(x,s))
697 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
698 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
699 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
703 static uint64_t attribute_used
__attribute__((aligned(8))) temps
[4];//!!
705 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_382683433
=FIX64(0.382683433, 14);
706 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_541196100
=FIX64(0.541196100, 14);
707 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_707106781
=FIX64(0.707106781, 14);
708 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_306562965
=FIX64(1.306562965, 14);
710 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_414213562_A
=FIX64(1.414213562, 14);
712 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_847759065
=FIX64(1.847759065, 13);
713 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_2_613125930
=FIX64(-2.613125930, 13); //-
714 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_414213562
=FIX64(1.414213562, 13);
715 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_082392200
=FIX64(1.082392200, 13);
716 //for t3,t5,t7 == 0 shortcut
717 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_847759065
=FIX64(0.847759065, 14);
718 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_566454497
=FIX64(0.566454497, 14);
719 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_198912367
=FIX64(0.198912367, 14);
721 static uint64_t attribute_used
__attribute__((aligned(8))) MM_DESCALE_RND
=C64(4);
722 static uint64_t attribute_used
__attribute__((aligned(8))) MM_2
=C64(2);
724 #else /* !HAVE_MMX */
726 typedef int32_t int_simd16_t
;
727 static int16_t FIX_0_382683433
=FIX(0.382683433, 14);
728 static int16_t FIX_0_541196100
=FIX(0.541196100, 14);
729 static int16_t FIX_0_707106781
=FIX(0.707106781, 14);
730 static int16_t FIX_1_306562965
=FIX(1.306562965, 14);
731 static int16_t FIX_1_414213562_A
=FIX(1.414213562, 14);
732 static int16_t FIX_1_847759065
=FIX(1.847759065, 13);
733 static int16_t FIX_2_613125930
=FIX(-2.613125930, 13); //-
734 static int16_t FIX_1_414213562
=FIX(1.414213562, 13);
735 static int16_t FIX_1_082392200
=FIX(1.082392200, 13);
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
;
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];
782 z1
= MULTIPLY16H((tmp12
+ tmp13
) <<2, FIX_0_707106781
);
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]);
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
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
);
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
832 z10
= (tmp6
- tmp5
)<<1;
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
; // - !!
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
859 dataptr
+=8; //skip each second start pos
866 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
)
871 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm1 \n\t"
873 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm7 \n\t"
874 "movq %%mm1, %%mm0 \n\t"
876 "paddw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm1 \n\t" //t0
877 "movq %%mm7, %%mm3 \n\t"
879 "paddw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm7 \n\t" //t3
880 "movq %%mm1, %%mm5 \n\t"
882 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm6 \n\t"
883 "psubw %%mm7, %%mm1 \n\t" //t13
885 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
886 "movq %%mm6, %%mm4 \n\t"
888 "paddw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm6 \n\t" //t1
889 "paddw %%mm7, %%mm5 \n\t" //t10
891 "paddw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t2
892 "movq %%mm6, %%mm7 \n\t"
894 "paddw %%mm2, %%mm6 \n\t" //t11
895 "psubw %%mm2, %%mm7 \n\t" //t12
897 "movq %%mm5, %%mm2 \n\t"
898 "paddw %%mm6, %%mm5 \n\t" //d0
899 // i0 t13 t12 i3 i1 d0 - d4
900 "psubw %%mm6, %%mm2 \n\t" //d4
901 "paddw %%mm1, %%mm7 \n\t"
903 "movq 4*16(%%"REG_d
"), %%mm6 \n\t"
904 "psllw $2, %%mm7 \n\t"
906 "psubw 0*16(%%"REG_d
"), %%mm5 \n\t"
907 "psubw %%mm6, %%mm2 \n\t"
909 "paddusw 0*16(%%"REG_d
"), %%mm5 \n\t"
910 "paddusw %%mm6, %%mm2 \n\t"
912 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm7 \n\t"
914 "paddw 0*16(%%"REG_d
"), %%mm5 \n\t"
915 "paddw %%mm6, %%mm2 \n\t"
917 "psubusw 0*16(%%"REG_d
"), %%mm5 \n\t"
918 "psubusw %%mm6, %%mm2 \n\t"
920 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
921 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
922 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
923 "paddw "MANGLE(MM_2
)", %%mm5 \n\t"
924 "movq %%mm2, %%mm6 \n\t"
926 "paddw %%mm5, %%mm2 \n\t"
927 "psubw %%mm6, %%mm5 \n\t"
929 "movq %%mm1, %%mm6 \n\t"
930 "paddw %%mm7, %%mm1 \n\t" //d2
932 "psubw 2*16(%%"REG_d
"), %%mm1 \n\t"
933 "psubw %%mm7, %%mm6 \n\t" //d6
935 "movq 6*16(%%"REG_d
"), %%mm7 \n\t"
936 "psraw $2, %%mm5 \n\t"
938 "paddusw 2*16(%%"REG_d
"), %%mm1 \n\t"
939 "psubw %%mm7, %%mm6 \n\t"
940 // t7 d2 /t11 t4 t6 - d6 /t10
942 "paddw 2*16(%%"REG_d
"), %%mm1 \n\t"
943 "paddusw %%mm7, %%mm6 \n\t"
945 "psubusw 2*16(%%"REG_d
"), %%mm1 \n\t"
946 "paddw %%mm7, %%mm6 \n\t"
948 "psubw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm3 \n\t"
949 "psubusw %%mm7, %%mm6 \n\t"
951 //movq [edi+"DCTSIZE_S"*2*2], mm1
952 //movq [edi+"DCTSIZE_S"*6*2], mm6
953 "movq %%mm1, %%mm7 \n\t"
954 "psraw $2, %%mm2 \n\t"
956 "psubw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm4 \n\t"
957 "psubw %%mm6, %%mm1 \n\t"
959 "psubw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm0 \n\t"
960 "paddw %%mm7, %%mm6 \n\t" //'t13
962 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
963 "movq %%mm2, %%mm7 \n\t"
965 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm1 \n\t"
966 "paddw %%mm6, %%mm2 \n\t" //'t0
968 "movq %%mm2, "MANGLE(temps
)"+0*8 \n\t" //!
969 "psubw %%mm6, %%mm7 \n\t" //'t3
971 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
972 "psubw %%mm6, %%mm1 \n\t" //'t12
974 "psubw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t5
975 "movq %%mm5, %%mm6 \n\t"
977 "movq %%mm7, "MANGLE(temps
)"+3*8 \n\t"
978 "paddw %%mm2, %%mm3 \n\t" //t10
980 "paddw %%mm4, %%mm2 \n\t" //t11
981 "paddw %%mm0, %%mm4 \n\t" //t12
983 "movq %%mm3, %%mm7 \n\t"
984 "psubw %%mm4, %%mm3 \n\t"
986 "psllw $2, %%mm3 \n\t"
987 "psllw $2, %%mm7 \n\t" //opt for P6
989 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t"
990 "psllw $2, %%mm4 \n\t"
992 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm7 \n\t"
993 "psllw $2, %%mm2 \n\t"
995 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm4 \n\t"
996 "paddw %%mm1, %%mm5 \n\t" //'t1
998 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm2 \n\t"
999 "psubw %%mm1, %%mm6 \n\t" //'t2
1000 // t7 't12 't11 t4 t6 - 't13 't10 ---
1002 "paddw %%mm3, %%mm7 \n\t" //z2
1004 "movq %%mm5, "MANGLE(temps
)"+1*8 \n\t"
1005 "paddw %%mm3, %%mm4 \n\t" //z4
1007 "movq 3*16(%%"REG_d
"), %%mm3 \n\t"
1008 "movq %%mm0, %%mm1 \n\t"
1010 "movq %%mm6, "MANGLE(temps
)"+2*8 \n\t"
1011 "psubw %%mm2, %%mm1 \n\t" //z13
1014 "paddw %%mm2, %%mm0 \n\t" //z11
1015 "movq %%mm1, %%mm5 \n\t"
1017 "movq 5*16(%%"REG_d
"), %%mm2 \n\t"
1018 "psubw %%mm7, %%mm1 \n\t" //d3
1020 "paddw %%mm7, %%mm5 \n\t" //d5
1021 "psubw %%mm3, %%mm1 \n\t"
1023 "movq 1*16(%%"REG_d
"), %%mm7 \n\t"
1024 "psubw %%mm2, %%mm5 \n\t"
1026 "movq %%mm0, %%mm6 \n\t"
1027 "paddw %%mm4, %%mm0 \n\t" //d1
1029 "paddusw %%mm3, %%mm1 \n\t"
1030 "psubw %%mm4, %%mm6 \n\t" //d7
1032 // d1 d3 - - - d5 d7 -
1033 "movq 7*16(%%"REG_d
"), %%mm4 \n\t"
1034 "psubw %%mm7, %%mm0 \n\t"
1036 "psubw %%mm4, %%mm6 \n\t"
1037 "paddusw %%mm2, %%mm5 \n\t"
1039 "paddusw %%mm4, %%mm6 \n\t"
1040 "paddw %%mm3, %%mm1 \n\t"
1042 "paddw %%mm2, %%mm5 \n\t"
1043 "paddw %%mm4, %%mm6 \n\t"
1045 "psubusw %%mm3, %%mm1 \n\t"
1046 "psubusw %%mm2, %%mm5 \n\t"
1048 "psubusw %%mm4, %%mm6 \n\t"
1049 "movq %%mm1, %%mm4 \n\t"
1051 "por %%mm5, %%mm4 \n\t"
1052 "paddusw %%mm7, %%mm0 \n\t"
1054 "por %%mm6, %%mm4 \n\t"
1055 "paddw %%mm7, %%mm0 \n\t"
1057 "packssdw %%mm4, %%mm4 \n\t"
1058 "psubusw %%mm7, %%mm0 \n\t"
1060 "movd %%mm4, %%"REG_a
" \n\t"
1061 "or %%"REG_a
", %%"REG_a
" \n\t"
1063 //movq [edi+"DCTSIZE_S"*3*2], mm1
1064 //movq [edi+"DCTSIZE_S"*5*2], mm5
1065 //movq [edi+"DCTSIZE_S"*1*2], mm0
1066 //movq [edi+"DCTSIZE_S"*7*2], mm6
1067 // t4 t5 - - - t6 t7 -
1068 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1069 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1070 "movq "MANGLE(temps
)"+0*8, %%mm4 \n\t"
1071 "movq %%mm0, %%mm1 \n\t"
1073 "pmulhw "MANGLE(MM_FIX_0_847759065
)", %%mm0 \n\t" //tmp6
1074 "movq %%mm1, %%mm2 \n\t"
1076 "movq "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm5 \n\t"
1077 "movq %%mm2, %%mm3 \n\t"
1079 "pmulhw "MANGLE(MM_FIX_0_566454497
)", %%mm1 \n\t" //tmp5
1080 "paddw %%mm4, %%mm5 \n\t"
1082 "movq "MANGLE(temps
)"+1*8, %%mm6 \n\t"
1084 "psraw $2, %%mm3 \n\t" //tmp7
1086 "pmulhw "MANGLE(MM_FIX_0_198912367
)", %%mm2 \n\t" //-tmp4
1087 "psubw %%mm3, %%mm4 \n\t"
1089 "movq "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm7 \n\t"
1090 "paddw %%mm3, %%mm5 \n\t"
1092 "movq %%mm4, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1093 "paddw %%mm6, %%mm7 \n\t"
1095 "movq "MANGLE(temps
)"+2*8, %%mm3 \n\t"
1096 "psubw %%mm0, %%mm6 \n\t"
1098 "movq "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm4 \n\t"
1099 "paddw %%mm0, %%mm7 \n\t"
1101 "movq %%mm5, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1102 "paddw %%mm3, %%mm4 \n\t"
1104 "movq %%mm6, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1105 "psubw %%mm1, %%mm3 \n\t"
1107 "movq "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm5 \n\t"
1108 "paddw %%mm1, %%mm4 \n\t"
1110 "movq "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm6 \n\t"
1111 "paddw %%mm3, %%mm5 \n\t"
1113 "movq "MANGLE(temps
)"+3*8, %%mm0 \n\t"
1114 "add $8, %%"REG_S
" \n\t"
1116 "movq %%mm7, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1117 "paddw %%mm0, %%mm6 \n\t"
1119 "movq %%mm4, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1120 "psubw %%mm2, %%mm0 \n\t"
1122 "movq "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm7 \n\t"
1123 "paddw %%mm2, %%mm6 \n\t"
1125 "movq %%mm5, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1126 "paddw %%mm0, %%mm7 \n\t"
1128 "movq %%mm6, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1130 "movq %%mm7, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1131 "add $8, %%"REG_D
" \n\t"
1136 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1140 "movq %%mm5, %%mm3 \n\t"
1141 "psubw %%mm1, %%mm5 \n\t"
1143 "psllw $1, %%mm5 \n\t" //'z10
1144 "paddw %%mm1, %%mm3 \n\t" //'z13
1146 "movq %%mm0, %%mm2 \n\t"
1147 "psubw %%mm6, %%mm0 \n\t"
1149 "movq %%mm5, %%mm1 \n\t"
1150 "psllw $1, %%mm0 \n\t" //'z12
1152 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm1 \n\t" //-
1153 "paddw %%mm0, %%mm5 \n\t"
1155 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm5 \n\t" //'z5
1156 "paddw %%mm6, %%mm2 \n\t" //'z11
1158 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm0 \n\t"
1159 "movq %%mm2, %%mm7 \n\t"
1162 "movq "MANGLE(temps
)"+0*8, %%mm4 \n\t"
1163 "psubw %%mm3, %%mm2 \n\t"
1165 "psllw $1, %%mm2 \n\t"
1166 "paddw %%mm3, %%mm7 \n\t" //'t7
1168 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //'t11
1169 "movq %%mm4, %%mm6 \n\t"
1171 "psraw $2, %%mm7 \n\t"
1173 "paddw "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm4 \n\t"
1174 "psubw %%mm7, %%mm6 \n\t"
1176 "movq "MANGLE(temps
)"+1*8, %%mm3 \n\t"
1177 "paddw %%mm7, %%mm4 \n\t"
1179 "movq %%mm6, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1180 "paddw %%mm5, %%mm1 \n\t" //'t12
1182 "movq %%mm4, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1183 "psubw %%mm7, %%mm1 \n\t" //'t6
1185 "movq "MANGLE(temps
)"+2*8, %%mm7 \n\t"
1186 "psubw %%mm5, %%mm0 \n\t" //'t10
1188 "movq "MANGLE(temps
)"+3*8, %%mm6 \n\t"
1189 "movq %%mm3, %%mm5 \n\t"
1191 "paddw "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm3 \n\t"
1192 "psubw %%mm1, %%mm5 \n\t"
1194 "psubw %%mm1, %%mm2 \n\t" //'t5
1195 "paddw %%mm1, %%mm3 \n\t"
1197 "movq %%mm5, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1198 "movq %%mm7, %%mm4 \n\t"
1200 "paddw "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm7 \n\t"
1201 "psubw %%mm2, %%mm4 \n\t"
1203 "paddw "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm4 \n\t"
1204 "paddw %%mm2, %%mm7 \n\t"
1206 "movq %%mm3, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1207 "paddw %%mm2, %%mm0 \n\t" //'t4
1209 // 't4 't6 't5 - - - - 't7
1210 "movq %%mm7, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1211 "movq %%mm6, %%mm1 \n\t"
1213 "paddw "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm6 \n\t"
1214 "psubw %%mm0, %%mm1 \n\t"
1216 "paddw "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm1 \n\t"
1217 "paddw %%mm0, %%mm6 \n\t"
1219 "movq %%mm4, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1220 "add $8, %%"REG_S
" \n\t"
1222 "movq %%mm6, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1224 "movq %%mm1, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1225 "add $8, %%"REG_D
" \n\t"
1228 //=part 2 (the same)===========================================================
1229 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm1 \n\t"
1231 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm7 \n\t"
1232 "movq %%mm1, %%mm0 \n\t"
1234 "paddw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm1 \n\t" //t0
1235 "movq %%mm7, %%mm3 \n\t"
1237 "paddw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm7 \n\t" //t3
1238 "movq %%mm1, %%mm5 \n\t"
1240 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm6 \n\t"
1241 "psubw %%mm7, %%mm1 \n\t" //t13
1243 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1244 "movq %%mm6, %%mm4 \n\t"
1246 "paddw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm6 \n\t" //t1
1247 "paddw %%mm7, %%mm5 \n\t" //t10
1249 "paddw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t2
1250 "movq %%mm6, %%mm7 \n\t"
1252 "paddw %%mm2, %%mm6 \n\t" //t11
1253 "psubw %%mm2, %%mm7 \n\t" //t12
1255 "movq %%mm5, %%mm2 \n\t"
1256 "paddw %%mm6, %%mm5 \n\t" //d0
1257 // i0 t13 t12 i3 i1 d0 - d4
1258 "psubw %%mm6, %%mm2 \n\t" //d4
1259 "paddw %%mm1, %%mm7 \n\t"
1261 "movq 1*8+4*16(%%"REG_d
"), %%mm6 \n\t"
1262 "psllw $2, %%mm7 \n\t"
1264 "psubw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1265 "psubw %%mm6, %%mm2 \n\t"
1267 "paddusw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1268 "paddusw %%mm6, %%mm2 \n\t"
1270 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm7 \n\t"
1272 "paddw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1273 "paddw %%mm6, %%mm2 \n\t"
1275 "psubusw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1276 "psubusw %%mm6, %%mm2 \n\t"
1278 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1279 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1280 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1281 "paddw "MANGLE(MM_2
)", %%mm5 \n\t"
1282 "movq %%mm2, %%mm6 \n\t"
1284 "paddw %%mm5, %%mm2 \n\t"
1285 "psubw %%mm6, %%mm5 \n\t"
1287 "movq %%mm1, %%mm6 \n\t"
1288 "paddw %%mm7, %%mm1 \n\t" //d2
1290 "psubw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1291 "psubw %%mm7, %%mm6 \n\t" //d6
1293 "movq 1*8+6*16(%%"REG_d
"), %%mm7 \n\t"
1294 "psraw $2, %%mm5 \n\t"
1296 "paddusw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1297 "psubw %%mm7, %%mm6 \n\t"
1298 // t7 d2 /t11 t4 t6 - d6 /t10
1300 "paddw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1301 "paddusw %%mm7, %%mm6 \n\t"
1303 "psubusw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1304 "paddw %%mm7, %%mm6 \n\t"
1306 "psubw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm3 \n\t"
1307 "psubusw %%mm7, %%mm6 \n\t"
1309 //movq [edi+"DCTSIZE_S"*2*2], mm1
1310 //movq [edi+"DCTSIZE_S"*6*2], mm6
1311 "movq %%mm1, %%mm7 \n\t"
1312 "psraw $2, %%mm2 \n\t"
1314 "psubw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm4 \n\t"
1315 "psubw %%mm6, %%mm1 \n\t"
1317 "psubw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm0 \n\t"
1318 "paddw %%mm7, %%mm6 \n\t" //'t13
1320 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1321 "movq %%mm2, %%mm7 \n\t"
1323 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm1 \n\t"
1324 "paddw %%mm6, %%mm2 \n\t" //'t0
1326 "movq %%mm2, "MANGLE(temps
)"+0*8 \n\t" //!
1327 "psubw %%mm6, %%mm7 \n\t" //'t3
1329 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1330 "psubw %%mm6, %%mm1 \n\t" //'t12
1332 "psubw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t5
1333 "movq %%mm5, %%mm6 \n\t"
1335 "movq %%mm7, "MANGLE(temps
)"+3*8 \n\t"
1336 "paddw %%mm2, %%mm3 \n\t" //t10
1338 "paddw %%mm4, %%mm2 \n\t" //t11
1339 "paddw %%mm0, %%mm4 \n\t" //t12
1341 "movq %%mm3, %%mm7 \n\t"
1342 "psubw %%mm4, %%mm3 \n\t"
1344 "psllw $2, %%mm3 \n\t"
1345 "psllw $2, %%mm7 \n\t" //opt for P6
1347 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t"
1348 "psllw $2, %%mm4 \n\t"
1350 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm7 \n\t"
1351 "psllw $2, %%mm2 \n\t"
1353 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm4 \n\t"
1354 "paddw %%mm1, %%mm5 \n\t" //'t1
1356 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm2 \n\t"
1357 "psubw %%mm1, %%mm6 \n\t" //'t2
1358 // t7 't12 't11 t4 t6 - 't13 't10 ---
1360 "paddw %%mm3, %%mm7 \n\t" //z2
1362 "movq %%mm5, "MANGLE(temps
)"+1*8 \n\t"
1363 "paddw %%mm3, %%mm4 \n\t" //z4
1365 "movq 1*8+3*16(%%"REG_d
"), %%mm3 \n\t"
1366 "movq %%mm0, %%mm1 \n\t"
1368 "movq %%mm6, "MANGLE(temps
)"+2*8 \n\t"
1369 "psubw %%mm2, %%mm1 \n\t" //z13
1372 "paddw %%mm2, %%mm0 \n\t" //z11
1373 "movq %%mm1, %%mm5 \n\t"
1375 "movq 1*8+5*16(%%"REG_d
"), %%mm2 \n\t"
1376 "psubw %%mm7, %%mm1 \n\t" //d3
1378 "paddw %%mm7, %%mm5 \n\t" //d5
1379 "psubw %%mm3, %%mm1 \n\t"
1381 "movq 1*8+1*16(%%"REG_d
"), %%mm7 \n\t"
1382 "psubw %%mm2, %%mm5 \n\t"
1384 "movq %%mm0, %%mm6 \n\t"
1385 "paddw %%mm4, %%mm0 \n\t" //d1
1387 "paddusw %%mm3, %%mm1 \n\t"
1388 "psubw %%mm4, %%mm6 \n\t" //d7
1390 // d1 d3 - - - d5 d7 -
1391 "movq 1*8+7*16(%%"REG_d
"), %%mm4 \n\t"
1392 "psubw %%mm7, %%mm0 \n\t"
1394 "psubw %%mm4, %%mm6 \n\t"
1395 "paddusw %%mm2, %%mm5 \n\t"
1397 "paddusw %%mm4, %%mm6 \n\t"
1398 "paddw %%mm3, %%mm1 \n\t"
1400 "paddw %%mm2, %%mm5 \n\t"
1401 "paddw %%mm4, %%mm6 \n\t"
1403 "psubusw %%mm3, %%mm1 \n\t"
1404 "psubusw %%mm2, %%mm5 \n\t"
1406 "psubusw %%mm4, %%mm6 \n\t"
1407 "movq %%mm1, %%mm4 \n\t"
1409 "por %%mm5, %%mm4 \n\t"
1410 "paddusw %%mm7, %%mm0 \n\t"
1412 "por %%mm6, %%mm4 \n\t"
1413 "paddw %%mm7, %%mm0 \n\t"
1415 "packssdw %%mm4, %%mm4 \n\t"
1416 "psubusw %%mm7, %%mm0 \n\t"
1418 "movd %%mm4, %%"REG_a
" \n\t"
1419 "or %%"REG_a
", %%"REG_a
" \n\t"
1421 //movq [edi+"DCTSIZE_S"*3*2], mm1
1422 //movq [edi+"DCTSIZE_S"*5*2], mm5
1423 //movq [edi+"DCTSIZE_S"*1*2], mm0
1424 //movq [edi+"DCTSIZE_S"*7*2], mm6
1425 // t4 t5 - - - t6 t7 -
1426 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1427 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1428 "movq "MANGLE(temps
)"+0*8, %%mm4 \n\t"
1429 "movq %%mm0, %%mm1 \n\t"
1431 "pmulhw "MANGLE(MM_FIX_0_847759065
)", %%mm0 \n\t" //tmp6
1432 "movq %%mm1, %%mm2 \n\t"
1434 "movq "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm5 \n\t"
1435 "movq %%mm2, %%mm3 \n\t"
1437 "pmulhw "MANGLE(MM_FIX_0_566454497
)", %%mm1 \n\t" //tmp5
1438 "paddw %%mm4, %%mm5 \n\t"
1440 "movq "MANGLE(temps
)"+1*8, %%mm6 \n\t"
1442 "psraw $2, %%mm3 \n\t" //tmp7
1444 "pmulhw "MANGLE(MM_FIX_0_198912367
)", %%mm2 \n\t" //-tmp4
1445 "psubw %%mm3, %%mm4 \n\t"
1447 "movq "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm7 \n\t"
1448 "paddw %%mm3, %%mm5 \n\t"
1450 "movq %%mm4, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1451 "paddw %%mm6, %%mm7 \n\t"
1453 "movq "MANGLE(temps
)"+2*8, %%mm3 \n\t"
1454 "psubw %%mm0, %%mm6 \n\t"
1456 "movq "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm4 \n\t"
1457 "paddw %%mm0, %%mm7 \n\t"
1459 "movq %%mm5, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1460 "paddw %%mm3, %%mm4 \n\t"
1462 "movq %%mm6, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1463 "psubw %%mm1, %%mm3 \n\t"
1465 "movq "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm5 \n\t"
1466 "paddw %%mm1, %%mm4 \n\t"
1468 "movq "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm6 \n\t"
1469 "paddw %%mm3, %%mm5 \n\t"
1471 "movq "MANGLE(temps
)"+3*8, %%mm0 \n\t"
1472 "add $24, %%"REG_S
" \n\t"
1474 "movq %%mm7, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1475 "paddw %%mm0, %%mm6 \n\t"
1477 "movq %%mm4, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1478 "psubw %%mm2, %%mm0 \n\t"
1480 "movq "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm7 \n\t"
1481 "paddw %%mm2, %%mm6 \n\t"
1483 "movq %%mm5, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1484 "paddw %%mm0, %%mm7 \n\t"
1486 "movq %%mm6, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1488 "movq %%mm7, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1489 "add $24, %%"REG_D
" \n\t"
1490 "sub $2, %%"REG_c
" \n\t"
1496 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1500 "movq %%mm5, %%mm3 \n\t"
1501 "psubw %%mm1, %%mm5 \n\t"
1503 "psllw $1, %%mm5 \n\t" //'z10
1504 "paddw %%mm1, %%mm3 \n\t" //'z13
1506 "movq %%mm0, %%mm2 \n\t"
1507 "psubw %%mm6, %%mm0 \n\t"
1509 "movq %%mm5, %%mm1 \n\t"
1510 "psllw $1, %%mm0 \n\t" //'z12
1512 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm1 \n\t" //-
1513 "paddw %%mm0, %%mm5 \n\t"
1515 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm5 \n\t" //'z5
1516 "paddw %%mm6, %%mm2 \n\t" //'z11
1518 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm0 \n\t"
1519 "movq %%mm2, %%mm7 \n\t"
1522 "movq "MANGLE(temps
)"+0*8, %%mm4 \n\t"
1523 "psubw %%mm3, %%mm2 \n\t"
1525 "psllw $1, %%mm2 \n\t"
1526 "paddw %%mm3, %%mm7 \n\t" //'t7
1528 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //'t11
1529 "movq %%mm4, %%mm6 \n\t"
1531 "psraw $2, %%mm7 \n\t"
1533 "paddw "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm4 \n\t"
1534 "psubw %%mm7, %%mm6 \n\t"
1536 "movq "MANGLE(temps
)"+1*8, %%mm3 \n\t"
1537 "paddw %%mm7, %%mm4 \n\t"
1539 "movq %%mm6, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1540 "paddw %%mm5, %%mm1 \n\t" //'t12
1542 "movq %%mm4, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1543 "psubw %%mm7, %%mm1 \n\t" //'t6
1545 "movq "MANGLE(temps
)"+2*8, %%mm7 \n\t"
1546 "psubw %%mm5, %%mm0 \n\t" //'t10
1548 "movq "MANGLE(temps
)"+3*8, %%mm6 \n\t"
1549 "movq %%mm3, %%mm5 \n\t"
1551 "paddw "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm3 \n\t"
1552 "psubw %%mm1, %%mm5 \n\t"
1554 "psubw %%mm1, %%mm2 \n\t" //'t5
1555 "paddw %%mm1, %%mm3 \n\t"
1557 "movq %%mm5, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1558 "movq %%mm7, %%mm4 \n\t"
1560 "paddw "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm7 \n\t"
1561 "psubw %%mm2, %%mm4 \n\t"
1563 "paddw "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm4 \n\t"
1564 "paddw %%mm2, %%mm7 \n\t"
1566 "movq %%mm3, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1567 "paddw %%mm2, %%mm0 \n\t" //'t4
1569 // 't4 't6 't5 - - - - 't7
1570 "movq %%mm7, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1571 "movq %%mm6, %%mm1 \n\t"
1573 "paddw "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm6 \n\t"
1574 "psubw %%mm0, %%mm1 \n\t"
1576 "paddw "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm1 \n\t"
1577 "paddw %%mm0, %%mm6 \n\t"
1579 "movq %%mm4, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1580 "add $24, %%"REG_S
" \n\t"
1582 "movq %%mm6, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1584 "movq %%mm1, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1585 "add $24, %%"REG_D
" \n\t"
1586 "sub $2, %%"REG_c
" \n\t"
1590 : "+S"(data
), "+D"(output
), "+c"(cnt
)// input regs
1600 static void row_idct_c(DCTELEM
* workspace
,
1601 int16_t* output_adr
, int output_stride
, int cnt
)
1603 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
1604 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
1605 int_simd16_t z5
, z10
, z11
, z12
, z13
;
1611 outptr
= output_adr
;
1612 for (; cnt
> 0; cnt
--) {
1614 //Simd version reads 4x4 block and transposes it
1615 tmp10
= ( wsptr
[2] + wsptr
[3]);
1616 tmp11
= ( wsptr
[2] - wsptr
[3]);
1618 tmp13
= ( wsptr
[0] + wsptr
[1]);
1619 tmp12
= (MULTIPLY16H( wsptr
[0] - wsptr
[1], FIX_1_414213562_A
)<<2) - tmp13
;//this shift order to avoid overflow
1621 tmp0
= tmp10
+ tmp13
; //->temps
1622 tmp3
= tmp10
- tmp13
; //->temps
1623 tmp1
= tmp11
+ tmp12
;
1624 tmp2
= tmp11
- tmp12
;
1627 //Also transpose, with previous:
1629 // ---- ---- idct ||||
1630 // ---- ---- ---> ||||
1632 z13
= wsptr
[4] + wsptr
[5];
1633 z10
= wsptr
[4] - wsptr
[5];
1634 z11
= wsptr
[6] + wsptr
[7];
1635 z12
= wsptr
[6] - wsptr
[7];
1638 tmp11
= MULTIPLY16H(z11
- z13
, FIX_1_414213562
);
1640 z5
= MULTIPLY16H(z10
+ z12
, FIX_1_847759065
);
1641 tmp10
= MULTIPLY16H(z12
, FIX_1_082392200
) - z5
;
1642 tmp12
= MULTIPLY16H(z10
, FIX_2_613125930
) + z5
; // - FIX_
1644 tmp6
= (tmp12
<<3) - tmp7
;
1645 tmp5
= (tmp11
<<3) - tmp6
;
1646 tmp4
= (tmp10
<<3) + tmp5
;
1648 // Final output stage: descale and write column
1649 outptr
[0*output_stride
]+= DESCALE(tmp0
+ tmp7
, 3);
1650 outptr
[1*output_stride
]+= DESCALE(tmp1
+ tmp6
, 3);
1651 outptr
[2*output_stride
]+= DESCALE(tmp2
+ tmp5
, 3);
1652 outptr
[3*output_stride
]+= DESCALE(tmp3
- tmp4
, 3);
1653 outptr
[4*output_stride
]+= DESCALE(tmp3
+ tmp4
, 3);
1654 outptr
[5*output_stride
]+= DESCALE(tmp2
- tmp5
, 3);
1655 outptr
[6*output_stride
]+= DESCALE(tmp1
- tmp6
, 3); //no += ?
1656 outptr
[7*output_stride
]+= DESCALE(tmp0
- tmp7
, 3); //no += ?
1659 wsptr
+= DCTSIZE
; // advance pointer to next row
1663 #else /* HAVE_MMX */
1665 static void row_idct_mmx (DCTELEM
* workspace
,
1666 int16_t* output_adr
, int output_stride
, int cnt
)
1669 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1671 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm0 \n\t"
1674 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm1 \n\t"
1675 "movq %%mm0, %%mm4 \n\t"
1677 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1678 "punpcklwd %%mm1, %%mm0 \n\t"
1680 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm3 \n\t"
1681 "punpckhwd %%mm1, %%mm4 \n\t"
1684 "movq %%mm2, %%mm7 \n\t"
1685 "punpcklwd %%mm3, %%mm2 \n\t"
1687 "movq %%mm0, %%mm6 \n\t"
1688 "punpckldq %%mm2, %%mm0 \n\t" //0
1690 "punpckhdq %%mm2, %%mm6 \n\t" //1
1691 "movq %%mm0, %%mm5 \n\t"
1693 "punpckhwd %%mm3, %%mm7 \n\t"
1694 "psubw %%mm6, %%mm0 \n\t"
1696 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm0 \n\t"
1697 "movq %%mm4, %%mm2 \n\t"
1699 "punpckldq %%mm7, %%mm4 \n\t" //2
1700 "paddw %%mm6, %%mm5 \n\t"
1702 "punpckhdq %%mm7, %%mm2 \n\t" //3
1703 "movq %%mm4, %%mm1 \n\t"
1705 "psllw $2, %%mm0 \n\t"
1706 "paddw %%mm2, %%mm4 \n\t" //t10
1708 "movq "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm3 \n\t"
1709 "psubw %%mm2, %%mm1 \n\t" //t11
1711 "movq "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm2 \n\t"
1712 "psubw %%mm5, %%mm0 \n\t"
1714 "movq %%mm4, %%mm6 \n\t"
1715 "paddw %%mm5, %%mm4 \n\t" //t0
1717 "psubw %%mm5, %%mm6 \n\t" //t3
1718 "movq %%mm1, %%mm7 \n\t"
1720 "movq "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm5 \n\t"
1721 "paddw %%mm0, %%mm1 \n\t" //t1
1723 "movq %%mm4, "MANGLE(temps
)"+0*8 \n\t" //t0
1724 "movq %%mm3, %%mm4 \n\t"
1726 "movq %%mm6, "MANGLE(temps
)"+1*8 \n\t" //t3
1727 "punpcklwd %%mm2, %%mm3 \n\t"
1730 "movq "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm6 \n\t"
1731 "punpckhwd %%mm2, %%mm4 \n\t"
1733 "movq %%mm5, %%mm2 \n\t"
1734 "punpcklwd %%mm6, %%mm5 \n\t"
1736 "psubw %%mm0, %%mm7 \n\t" //t2
1737 "punpckhwd %%mm6, %%mm2 \n\t"
1739 "movq %%mm3, %%mm0 \n\t"
1740 "punpckldq %%mm5, %%mm3 \n\t" //4
1742 "punpckhdq %%mm5, %%mm0 \n\t" //5
1743 "movq %%mm4, %%mm5 \n\t"
1746 "movq %%mm3, %%mm6 \n\t"
1747 "punpckldq %%mm2, %%mm4 \n\t" //6
1749 "psubw %%mm0, %%mm3 \n\t" //z10
1750 "punpckhdq %%mm2, %%mm5 \n\t" //7
1752 "paddw %%mm0, %%mm6 \n\t" //z13
1753 "movq %%mm4, %%mm2 \n\t"
1755 "movq %%mm3, %%mm0 \n\t"
1756 "psubw %%mm5, %%mm4 \n\t" //z12
1758 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm0 \n\t" //-
1759 "paddw %%mm4, %%mm3 \n\t"
1761 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm3 \n\t" //z5
1762 "paddw %%mm5, %%mm2 \n\t" //z11 >
1764 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm4 \n\t"
1765 "movq %%mm2, %%mm5 \n\t"
1767 "psubw %%mm6, %%mm2 \n\t"
1768 "paddw %%mm6, %%mm5 \n\t" //t7
1770 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //t11
1771 "paddw %%mm3, %%mm0 \n\t" //t12
1773 "psllw $3, %%mm0 \n\t"
1774 "psubw %%mm3, %%mm4 \n\t" //t10
1776 "movq "MANGLE(temps
)"+0*8, %%mm6 \n\t"
1777 "movq %%mm1, %%mm3 \n\t"
1779 "psllw $3, %%mm4 \n\t"
1780 "psubw %%mm5, %%mm0 \n\t" //t6
1782 "psllw $3, %%mm2 \n\t"
1783 "paddw %%mm0, %%mm1 \n\t" //d1
1785 "psubw %%mm0, %%mm2 \n\t" //t5
1786 "psubw %%mm0, %%mm3 \n\t" //d6
1788 "paddw %%mm2, %%mm4 \n\t" //t4
1789 "movq %%mm7, %%mm0 \n\t"
1791 "paddw %%mm2, %%mm7 \n\t" //d2
1792 "psubw %%mm2, %%mm0 \n\t" //d5
1794 "movq "MANGLE(MM_DESCALE_RND
)", %%mm2 \n\t" //4
1795 "psubw %%mm5, %%mm6 \n\t" //d7
1797 "paddw "MANGLE(temps
)"+0*8, %%mm5 \n\t" //d0
1798 "paddw %%mm2, %%mm1 \n\t"
1800 "paddw %%mm2, %%mm5 \n\t"
1801 "psraw $3, %%mm1 \n\t"
1803 "paddw %%mm2, %%mm7 \n\t"
1804 "psraw $3, %%mm5 \n\t"
1806 "paddw (%%"REG_D
"), %%mm5 \n\t"
1807 "psraw $3, %%mm7 \n\t"
1809 "paddw (%%"REG_D
",%%"REG_a
",), %%mm1 \n\t"
1810 "paddw %%mm2, %%mm0 \n\t"
1812 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm7 \n\t"
1813 "paddw %%mm2, %%mm3 \n\t"
1815 "movq %%mm5, (%%"REG_D
") \n\t"
1816 "paddw %%mm2, %%mm6 \n\t"
1818 "movq %%mm1, (%%"REG_D
",%%"REG_a
",) \n\t"
1819 "psraw $3, %%mm0 \n\t"
1821 "movq %%mm7, (%%"REG_D
",%%"REG_a
",2) \n\t"
1822 "add %%"REG_d
", %%"REG_D
" \n\t" //3*ls
1824 "movq "MANGLE(temps
)"+1*8, %%mm5 \n\t" //t3
1825 "psraw $3, %%mm3 \n\t"
1827 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm0 \n\t"
1828 "psubw %%mm4, %%mm5 \n\t" //d3
1830 "paddw (%%"REG_D
",%%"REG_d
",), %%mm3 \n\t"
1831 "psraw $3, %%mm6 \n\t"
1833 "paddw "MANGLE(temps
)"+1*8, %%mm4 \n\t" //d4
1834 "paddw %%mm2, %%mm5 \n\t"
1836 "paddw (%%"REG_D
",%%"REG_a
",4), %%mm6 \n\t"
1837 "paddw %%mm2, %%mm4 \n\t"
1839 "movq %%mm0, (%%"REG_D
",%%"REG_a
",2) \n\t"
1840 "psraw $3, %%mm5 \n\t"
1842 "paddw (%%"REG_D
"), %%mm5 \n\t"
1843 "psraw $3, %%mm4 \n\t"
1845 "paddw (%%"REG_D
",%%"REG_a
",), %%mm4 \n\t"
1846 "add $"DCTSIZE_S
"*2*4, %%"REG_S
" \n\t" //4 rows
1848 "movq %%mm3, (%%"REG_D
",%%"REG_d
",) \n\t"
1849 "movq %%mm6, (%%"REG_D
",%%"REG_a
",4) \n\t"
1850 "movq %%mm5, (%%"REG_D
") \n\t"
1851 "movq %%mm4, (%%"REG_D
",%%"REG_a
",) \n\t"
1853 "sub %%"REG_d
", %%"REG_D
" \n\t"
1854 "add $8, %%"REG_D
" \n\t"
1855 "dec %%"REG_c
" \n\t"
1858 : "+S"(workspace
), "+D"(output_adr
), "+c"(cnt
) //input regs
1859 : "a"(output_stride
*sizeof(short))
1868 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1870 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
1871 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
1872 int_simd16_t z1
, z2
, z3
, z4
, z5
, z11
, z13
;
1876 // Pass 1: process rows.
1879 for (; cnt
> 0; cnt
--) {
1880 tmp0
= pixels
[line_size
*0] + pixels
[line_size
*7];
1881 tmp7
= pixels
[line_size
*0] - pixels
[line_size
*7];
1882 tmp1
= pixels
[line_size
*1] + pixels
[line_size
*6];
1883 tmp6
= pixels
[line_size
*1] - pixels
[line_size
*6];
1884 tmp2
= pixels
[line_size
*2] + pixels
[line_size
*5];
1885 tmp5
= pixels
[line_size
*2] - pixels
[line_size
*5];
1886 tmp3
= pixels
[line_size
*3] + pixels
[line_size
*4];
1887 tmp4
= pixels
[line_size
*3] - pixels
[line_size
*4];
1891 tmp10
= tmp0
+ tmp3
;
1892 tmp13
= tmp0
- tmp3
;
1893 tmp11
= tmp1
+ tmp2
;
1894 tmp12
= tmp1
- tmp2
;
1895 //Even columns are written first, this leads to different order of columns
1896 //in column_fidct(), but they are processed independently, so all ok.
1897 //Later in the row_idct() columns readed at the same order.
1898 dataptr
[2] = tmp10
+ tmp11
;
1899 dataptr
[3] = tmp10
- tmp11
;
1901 z1
= MULTIPLY16H((tmp12
+ tmp13
)<<2, FIX_0_707106781
);
1902 dataptr
[0] = tmp13
+ z1
;
1903 dataptr
[1] = tmp13
- z1
;
1907 tmp10
= (tmp4
+ tmp5
) <<2;
1908 tmp11
= (tmp5
+ tmp6
) <<2;
1909 tmp12
= (tmp6
+ tmp7
) <<2;
1911 z5
= MULTIPLY16H(tmp10
- tmp12
, FIX_0_382683433
);
1912 z2
= MULTIPLY16H(tmp10
, FIX_0_541196100
) + z5
;
1913 z4
= MULTIPLY16H(tmp12
, FIX_1_306562965
) + z5
;
1914 z3
= MULTIPLY16H(tmp11
, FIX_0_707106781
);
1919 dataptr
[4] = z13
+ z2
;
1920 dataptr
[5] = z13
- z2
;
1921 dataptr
[6] = z11
+ z4
;
1922 dataptr
[7] = z11
- z4
;
1924 pixels
++; // advance pointer to next column
1929 #else /* HAVE_MMX */
1931 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1934 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1936 "movd (%%"REG_S
"), %%mm0 \n\t"
1937 "pxor %%mm7, %%mm7 \n\t"
1939 "movd (%%"REG_S
",%%"REG_a
",), %%mm1 \n\t"
1940 "punpcklbw %%mm7, %%mm0 \n\t"
1942 "movd (%%"REG_S
",%%"REG_a
",2), %%mm2 \n\t"
1943 "punpcklbw %%mm7, %%mm1 \n\t"
1945 "punpcklbw %%mm7, %%mm2 \n\t"
1946 "add %%"REG_d
", %%"REG_S
" \n\t"
1948 "movq %%mm0, %%mm5 \n\t"
1951 "movd (%%"REG_S
",%%"REG_a
",4), %%mm3 \n\t" //7 ;prefetch!
1952 "movq %%mm1, %%mm6 \n\t"
1954 "movd (%%"REG_S
",%%"REG_d
",), %%mm4 \n\t" //6
1955 "punpcklbw %%mm7, %%mm3 \n\t"
1957 "psubw %%mm3, %%mm5 \n\t"
1958 "punpcklbw %%mm7, %%mm4 \n\t"
1960 "paddw %%mm3, %%mm0 \n\t"
1961 "psubw %%mm4, %%mm6 \n\t"
1963 "movd (%%"REG_S
",%%"REG_a
",2), %%mm3 \n\t" //5
1964 "paddw %%mm4, %%mm1 \n\t"
1966 "movq %%mm5, "MANGLE(temps
)"+0*8 \n\t" //t7
1967 "punpcklbw %%mm7, %%mm3 \n\t"
1969 "movq %%mm6, "MANGLE(temps
)"+1*8 \n\t" //t6
1970 "movq %%mm2, %%mm4 \n\t"
1972 "movd (%%"REG_S
"), %%mm5 \n\t" //3
1973 "paddw %%mm3, %%mm2 \n\t"
1975 "movd (%%"REG_S
",%%"REG_a
",), %%mm6 \n\t" //4
1976 "punpcklbw %%mm7, %%mm5 \n\t"
1978 "psubw %%mm3, %%mm4 \n\t"
1979 "punpcklbw %%mm7, %%mm6 \n\t"
1981 "movq %%mm5, %%mm3 \n\t"
1982 "paddw %%mm6, %%mm5 \n\t" //t3
1984 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1985 "movq %%mm0, %%mm6 \n\t"
1987 "movq %%mm1, %%mm7 \n\t"
1988 "psubw %%mm5, %%mm0 \n\t" //t13
1990 "psubw %%mm2, %%mm1 \n\t"
1991 "paddw %%mm2, %%mm7 \n\t" //t11
1993 "paddw %%mm0, %%mm1 \n\t"
1994 "movq %%mm7, %%mm2 \n\t"
1996 "psllw $2, %%mm1 \n\t"
1997 "paddw %%mm5, %%mm6 \n\t" //t10
1999 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm1 \n\t"
2000 "paddw %%mm6, %%mm7 \n\t" //d2
2002 "psubw %%mm2, %%mm6 \n\t" //d3
2003 "movq %%mm0, %%mm5 \n\t"
2006 "movq %%mm7, %%mm2 \n\t"
2007 "punpcklwd %%mm6, %%mm7 \n\t"
2009 "paddw %%mm1, %%mm0 \n\t" //d0
2010 "punpckhwd %%mm6, %%mm2 \n\t"
2012 "psubw %%mm1, %%mm5 \n\t" //d1
2013 "movq %%mm0, %%mm6 \n\t"
2015 "movq "MANGLE(temps
)"+1*8, %%mm1 \n\t"
2016 "punpcklwd %%mm5, %%mm0 \n\t"
2018 "punpckhwd %%mm5, %%mm6 \n\t"
2019 "movq %%mm0, %%mm5 \n\t"
2021 "punpckldq %%mm7, %%mm0 \n\t" //0
2022 "paddw %%mm4, %%mm3 \n\t"
2024 "punpckhdq %%mm7, %%mm5 \n\t" //1
2025 "movq %%mm6, %%mm7 \n\t"
2027 "movq %%mm0, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
2028 "punpckldq %%mm2, %%mm6 \n\t" //2
2030 "movq %%mm5, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
2031 "punpckhdq %%mm2, %%mm7 \n\t" //3
2033 "movq %%mm6, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
2034 "paddw %%mm1, %%mm4 \n\t"
2036 "movq %%mm7, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
2037 "psllw $2, %%mm3 \n\t" //t10
2039 "movq "MANGLE(temps
)"+0*8, %%mm2 \n\t"
2040 "psllw $2, %%mm4 \n\t" //t11
2042 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm4 \n\t" //z3
2043 "paddw %%mm2, %%mm1 \n\t"
2045 "psllw $2, %%mm1 \n\t" //t12
2046 "movq %%mm3, %%mm0 \n\t"
2048 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm0 \n\t"
2049 "psubw %%mm1, %%mm3 \n\t"
2051 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t" //z5
2052 "movq %%mm2, %%mm5 \n\t"
2054 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm1 \n\t"
2055 "psubw %%mm4, %%mm2 \n\t" //z13
2057 "paddw %%mm4, %%mm5 \n\t" //z11
2058 "movq %%mm2, %%mm6 \n\t"
2060 "paddw %%mm3, %%mm0 \n\t" //z2
2061 "movq %%mm5, %%mm7 \n\t"
2063 "paddw %%mm0, %%mm2 \n\t" //d4
2064 "psubw %%mm0, %%mm6 \n\t" //d5
2066 "movq %%mm2, %%mm4 \n\t"
2067 "paddw %%mm3, %%mm1 \n\t" //z4
2070 "punpcklwd %%mm6, %%mm2 \n\t"
2071 "paddw %%mm1, %%mm5 \n\t" //d6
2073 "punpckhwd %%mm6, %%mm4 \n\t"
2074 "psubw %%mm1, %%mm7 \n\t" //d7
2076 "movq %%mm5, %%mm6 \n\t"
2077 "punpcklwd %%mm7, %%mm5 \n\t"
2079 "punpckhwd %%mm7, %%mm6 \n\t"
2080 "movq %%mm2, %%mm7 \n\t"
2082 "punpckldq %%mm5, %%mm2 \n\t" //4
2083 "sub %%"REG_d
", %%"REG_S
" \n\t"
2085 "punpckhdq %%mm5, %%mm7 \n\t" //5
2086 "movq %%mm4, %%mm5 \n\t"
2088 "movq %%mm2, "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2089 "punpckldq %%mm6, %%mm4 \n\t" //6
2091 "movq %%mm7, "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2092 "punpckhdq %%mm6, %%mm5 \n\t" //7
2094 "movq %%mm4, "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2095 "add $4, %%"REG_S
" \n\t"
2097 "movq %%mm5, "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2098 "add $"DCTSIZE_S
"*2*4, %%"REG_D
" \n\t" //4 rows
2099 "dec %%"REG_c
" \n\t"
2102 : "+S"(pixels
), "+D"(data
), "+c"(cnt
) //input regs