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
44 #include "cpudetect.h"
45 #include "img_format.h"
48 #include "vd_ffmpeg.h"
49 #include "libvo/fastmemcpy.h"
51 #include "libavutil/internal.h"
52 #include "libavutil/intreadwrite.h"
53 #include "libavutil/mem.h"
54 #include "libavcodec/avcodec.h"
55 #include "libavcodec/dsputil.h"
60 //===========================================================================//
63 static const short custom_threshold
[64]=
64 // values (296) can't be too high
65 // -it causes too big quant dependence
66 // or maybe overflow(check), which results in some flashing
67 { 71, 296, 295, 237, 71, 40, 38, 19,
68 245, 193, 185, 121, 102, 73, 53, 27,
69 158, 129, 141, 107, 97, 73, 50, 26,
70 102, 116, 109, 98, 82, 66, 45, 23,
71 71, 94, 95, 81, 70, 56, 38, 20,
72 56, 77, 74, 66, 56, 44, 30, 15,
73 38, 53, 50, 45, 38, 30, 21, 11,
74 20, 27, 26, 23, 20, 15, 11, 5
77 static const uint8_t __attribute__((aligned(32))) dither
[8][8]={
78 { 0, 48, 12, 60, 3, 51, 15, 63, },
79 { 32, 16, 44, 28, 35, 19, 47, 31, },
80 { 8, 56, 4, 52, 11, 59, 7, 55, },
81 { 40, 24, 36, 20, 43, 27, 39, 23, },
82 { 2, 50, 14, 62, 1, 49, 13, 61, },
83 { 34, 18, 46, 30, 33, 17, 45, 29, },
84 { 10, 58, 6, 54, 9, 57, 5, 53, },
85 { 42, 26, 38, 22, 41, 25, 37, 21, },
88 struct vf_priv_s
{ //align 16 !
89 uint64_t threshold_mtx_noq
[8*2];
90 uint64_t threshold_mtx
[8*2];//used in both C & MMX (& later SSE2) versions
106 //This func reads from 1 slice, 1 and clears 0 & 1
107 static void store_slice_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
110 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
111 src[x + pos]=src[x + pos - 8*src_stride]=0; \
112 if(temp & 0x100) temp= ~(temp>>31); \
115 for(y
=0; y
<height
; y
++){
116 const uint8_t *d
= dither
[y
];
117 for(x
=0; x
<width
; x
+=8){
133 //This func reads from 2 slices, 0 & 2 and clears 2-nd
134 static void store_slice2_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
136 #define STORE2(pos) \
137 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
138 src[x + pos + 16*src_stride]=0; \
139 if(temp & 0x100) temp= ~(temp>>31); \
142 for(y
=0; y
<height
; y
++){
143 const uint8_t *d
= dither
[y
];
144 for(x
=0; x
<width
; x
+=8){
160 static void mul_thrmat_c(struct vf_priv_s
*p
,int q
)
164 ((short*)p
->threshold_mtx
)[a
]=q
* ((short*)p
->threshold_mtx_noq
)[a
];//ints faster in C
167 static void column_fidct_c(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
168 static void row_idct_c(DCTELEM
* workspace
,
169 int16_t* output_adr
, int output_stride
, int cnt
);
170 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
172 //this is rather ugly, but there is no need for function pointers
173 #define store_slice_s store_slice_c
174 #define store_slice2_s store_slice2_c
175 #define mul_thrmat_s mul_thrmat_c
176 #define column_fidct_s column_fidct_c
177 #define row_idct_s row_idct_c
178 #define row_fdct_s row_fdct_c
182 //This func reads from 1 slice, 1 and clears 0 & 1
183 static void store_slice_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
185 const uint8_t *od
=&dither
[0][0];
186 const uint8_t *end
=&dither
[height
][0];
187 width
= (width
+7)&~7;
189 //src_stride=(src_stride-width)*2;
191 "mov %5, %%"REG_d
" \n\t"
192 "mov %6, %%"REG_S
" \n\t"
193 "mov %7, %%"REG_D
" \n\t"
194 "mov %1, %%"REG_a
" \n\t"
195 "movd %%"REG_d
", %%mm5 \n\t"
196 "xor $-1, %%"REG_d
" \n\t"
197 "mov %%"REG_a
", %%"REG_c
" \n\t"
198 "add $7, %%"REG_d
" \n\t"
200 "sub %0, %%"REG_c
" \n\t"
201 "add %%"REG_c
", %%"REG_c
" \n\t"
202 "movd %%"REG_d
", %%mm2 \n\t"
203 "mov %%"REG_c
", %1 \n\t"
204 "mov %2, %%"REG_d
" \n\t"
205 "shl $4, %%"REG_a
" \n\t"
208 "movq (%%"REG_d
"), %%mm3 \n\t"
209 "movq %%mm3, %%mm4 \n\t"
210 "pxor %%mm7, %%mm7 \n\t"
211 "punpcklbw %%mm7, %%mm3 \n\t"
212 "punpckhbw %%mm7, %%mm4 \n\t"
213 "mov %0, %%"REG_c
" \n\t"
214 "psraw %%mm5, %%mm3 \n\t"
215 "psraw %%mm5, %%mm4 \n\t"
217 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
218 "movq (%%"REG_S
"), %%mm0 \n\t"
219 "movq 8(%%"REG_S
"), %%mm1 \n\t"
221 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
222 "paddw %%mm3, %%mm0 \n\t"
223 "paddw %%mm4, %%mm1 \n\t"
225 "movq %%mm7, (%%"REG_S
") \n\t"
226 "psraw %%mm2, %%mm0 \n\t"
227 "psraw %%mm2, %%mm1 \n\t"
229 "movq %%mm7, 8(%%"REG_S
") \n\t"
230 "packuswb %%mm1, %%mm0 \n\t"
231 "add $16, %%"REG_S
" \n\t"
233 "movq %%mm0, (%%"REG_D
") \n\t"
234 "add $8, %%"REG_D
" \n\t"
235 "sub $8, %%"REG_c
" \n\t"
237 "add %1, %%"REG_S
" \n\t"
238 "add $8, %%"REG_d
" \n\t"
239 "add %3, %%"REG_D
" \n\t"
240 "cmp %4, %%"REG_d
" \n\t"
244 : "m" (width
), "m" (src_stride
), "erm" (od
), "m" (dst_stride
), "erm" (end
),
245 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
246 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_S
, "%"REG_D
250 //This func reads from 2 slices, 0 & 2 and clears 2-nd
251 static void store_slice2_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
253 const uint8_t *od
=&dither
[0][0];
254 const uint8_t *end
=&dither
[height
][0];
255 width
= (width
+7)&~7;
257 //src_stride=(src_stride-width)*2;
259 "mov %5, %%"REG_d
" \n\t"
260 "mov %6, %%"REG_S
" \n\t"
261 "mov %7, %%"REG_D
" \n\t"
262 "mov %1, %%"REG_a
" \n\t"
263 "movd %%"REG_d
", %%mm5 \n\t"
264 "xor $-1, %%"REG_d
" \n\t"
265 "mov %%"REG_a
", %%"REG_c
" \n\t"
266 "add $7, %%"REG_d
" \n\t"
267 "sub %0, %%"REG_c
" \n\t"
268 "add %%"REG_c
", %%"REG_c
" \n\t"
269 "movd %%"REG_d
", %%mm2 \n\t"
270 "mov %%"REG_c
", %1 \n\t"
271 "mov %2, %%"REG_d
" \n\t"
272 "shl $5, %%"REG_a
" \n\t"
275 "movq (%%"REG_d
"), %%mm3 \n\t"
276 "movq %%mm3, %%mm4 \n\t"
277 "pxor %%mm7, %%mm7 \n\t"
278 "punpcklbw %%mm7, %%mm3 \n\t"
279 "punpckhbw %%mm7, %%mm4 \n\t"
280 "mov %0, %%"REG_c
" \n\t"
281 "psraw %%mm5, %%mm3 \n\t"
282 "psraw %%mm5, %%mm4 \n\t"
284 "movq (%%"REG_S
"), %%mm0 \n\t"
285 "movq 8(%%"REG_S
"), %%mm1 \n\t"
286 "paddw %%mm3, %%mm0 \n\t"
288 "paddw (%%"REG_S
",%%"REG_a
",), %%mm0 \n\t"
289 "paddw %%mm4, %%mm1 \n\t"
290 "movq 8(%%"REG_S
",%%"REG_a
",), %%mm6 \n\t"
292 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
293 "psraw %%mm2, %%mm0 \n\t"
294 "paddw %%mm6, %%mm1 \n\t"
296 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
297 "psraw %%mm2, %%mm1 \n\t"
298 "packuswb %%mm1, %%mm0 \n\t"
300 "movq %%mm0, (%%"REG_D
") \n\t"
301 "add $16, %%"REG_S
" \n\t"
302 "add $8, %%"REG_D
" \n\t"
303 "sub $8, %%"REG_c
" \n\t"
305 "add %1, %%"REG_S
" \n\t"
306 "add $8, %%"REG_d
" \n\t"
307 "add %3, %%"REG_D
" \n\t"
308 "cmp %4, %%"REG_d
" \n\t"
312 : "m" (width
), "m" (src_stride
), "erm" (od
), "m" (dst_stride
), "erm" (end
),
313 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
314 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_D
, "%"REG_S
318 static void mul_thrmat_mmx(struct vf_priv_s
*p
, int q
)
320 uint64_t *adr
=&p
->threshold_mtx_noq
[0];
322 "movd %0, %%mm7 \n\t"
323 "add $8*8*2, %%"REG_D
" \n\t"
324 "movq 0*8(%%"REG_S
"), %%mm0 \n\t"
325 "punpcklwd %%mm7, %%mm7 \n\t"
326 "movq 1*8(%%"REG_S
"), %%mm1 \n\t"
327 "punpckldq %%mm7, %%mm7 \n\t"
328 "pmullw %%mm7, %%mm0 \n\t"
330 "movq 2*8(%%"REG_S
"), %%mm2 \n\t"
331 "pmullw %%mm7, %%mm1 \n\t"
333 "movq 3*8(%%"REG_S
"), %%mm3 \n\t"
334 "pmullw %%mm7, %%mm2 \n\t"
336 "movq %%mm0, 0*8(%%"REG_D
") \n\t"
337 "movq 4*8(%%"REG_S
"), %%mm4 \n\t"
338 "pmullw %%mm7, %%mm3 \n\t"
340 "movq %%mm1, 1*8(%%"REG_D
") \n\t"
341 "movq 5*8(%%"REG_S
"), %%mm5 \n\t"
342 "pmullw %%mm7, %%mm4 \n\t"
344 "movq %%mm2, 2*8(%%"REG_D
") \n\t"
345 "movq 6*8(%%"REG_S
"), %%mm6 \n\t"
346 "pmullw %%mm7, %%mm5 \n\t"
348 "movq %%mm3, 3*8(%%"REG_D
") \n\t"
349 "movq 7*8+0*8(%%"REG_S
"), %%mm0 \n\t"
350 "pmullw %%mm7, %%mm6 \n\t"
352 "movq %%mm4, 4*8(%%"REG_D
") \n\t"
353 "movq 7*8+1*8(%%"REG_S
"), %%mm1 \n\t"
354 "pmullw %%mm7, %%mm0 \n\t"
356 "movq %%mm5, 5*8(%%"REG_D
") \n\t"
357 "movq 7*8+2*8(%%"REG_S
"), %%mm2 \n\t"
358 "pmullw %%mm7, %%mm1 \n\t"
360 "movq %%mm6, 6*8(%%"REG_D
") \n\t"
361 "movq 7*8+3*8(%%"REG_S
"), %%mm3 \n\t"
362 "pmullw %%mm7, %%mm2 \n\t"
364 "movq %%mm0, 7*8+0*8(%%"REG_D
") \n\t"
365 "movq 7*8+4*8(%%"REG_S
"), %%mm4 \n\t"
366 "pmullw %%mm7, %%mm3 \n\t"
368 "movq %%mm1, 7*8+1*8(%%"REG_D
") \n\t"
369 "movq 7*8+5*8(%%"REG_S
"), %%mm5 \n\t"
370 "pmullw %%mm7, %%mm4 \n\t"
372 "movq %%mm2, 7*8+2*8(%%"REG_D
") \n\t"
373 "movq 7*8+6*8(%%"REG_S
"), %%mm6 \n\t"
374 "pmullw %%mm7, %%mm5 \n\t"
376 "movq %%mm3, 7*8+3*8(%%"REG_D
") \n\t"
377 "movq 14*8+0*8(%%"REG_S
"), %%mm0 \n\t"
378 "pmullw %%mm7, %%mm6 \n\t"
380 "movq %%mm4, 7*8+4*8(%%"REG_D
") \n\t"
381 "movq 14*8+1*8(%%"REG_S
"), %%mm1 \n\t"
382 "pmullw %%mm7, %%mm0 \n\t"
384 "movq %%mm5, 7*8+5*8(%%"REG_D
") \n\t"
385 "pmullw %%mm7, %%mm1 \n\t"
387 "movq %%mm6, 7*8+6*8(%%"REG_D
") \n\t"
388 "movq %%mm0, 14*8+0*8(%%"REG_D
") \n\t"
389 "movq %%mm1, 14*8+1*8(%%"REG_D
") \n\t"
391 : "+g" (q
), "+S" (adr
), "+D" (adr
)
396 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
397 static void row_idct_mmx(DCTELEM
* workspace
,
398 int16_t* output_adr
, int output_stride
, int cnt
);
399 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
401 #define store_slice_s store_slice_mmx
402 #define store_slice2_s store_slice2_mmx
403 #define mul_thrmat_s mul_thrmat_mmx
404 #define column_fidct_s column_fidct_mmx
405 #define row_idct_s row_idct_mmx
406 #define row_fdct_s row_fdct_mmx
409 static void filter(struct vf_priv_s
*p
, uint8_t *dst
, uint8_t *src
,
410 int dst_stride
, int src_stride
,
411 int width
, int height
,
412 uint8_t *qp_store
, int qp_stride
, int is_luma
)
414 int x
, x0
, y
, es
, qy
, t
;
415 const int stride
= is_luma
? p
->temp_stride
: (width
+16);//((width+16+15)&(~15))
416 const int step
=6-p
->log2_count
;
417 const int qps
= 3 + is_luma
;
418 int32_t __attribute__((aligned(32))) block_align
[4*8*BLOCKSZ
+ 4*8*BLOCKSZ
];
419 DCTELEM
*block
= (DCTELEM
*)block_align
;
420 DCTELEM
*block3
=(DCTELEM
*)(block_align
+4*8*BLOCKSZ
);
422 memset(block3
, 0, 4*8*BLOCKSZ
);
424 //p->src=src-src_stride*8-8;//!
425 if (!src
|| !dst
) return; // HACK avoid crash for Y8 colourspace
426 for(y
=0; y
<height
; y
++){
427 int index
= 8 + 8*stride
+ y
*stride
;
428 fast_memcpy(p
->src
+ index
, src
+ y
*src_stride
, width
);//this line can be avoided by using DR & user fr.buffers
430 p
->src
[index
- x
- 1]= p
->src
[index
+ x
];
431 p
->src
[index
+ width
+ x
]= p
->src
[index
+ width
- x
- 1];
435 fast_memcpy(p
->src
+ ( 7-y
)*stride
, p
->src
+ ( y
+8)*stride
, stride
);
436 fast_memcpy(p
->src
+ (height
+8+y
)*stride
, p
->src
+ (height
-y
+7)*stride
, stride
);
438 //FIXME (try edge emu)
441 memset(p
->temp
+ 8 +y
*stride
, 0,width
*sizeof(int16_t));
443 for(y
=step
; y
<height
+8; y
+=step
){ //step= 1,2
445 if (qy
>height
-1) qy
=height
-1;
447 qy
=(qy
>>qps
)*qp_stride
;
448 row_fdct_s(block
, p
->src
+ y
*stride
+2-(y
&1), stride
, 2);
449 for(x0
=0; x0
<width
+8-8*(BLOCKSZ
-1); x0
+=8*(BLOCKSZ
-1)){
450 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
452 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+0*8, block3
+0*8, 8*(BLOCKSZ
-1)); //yes, this is a HOTSPOT
454 for (x
=0; x
<8*(BLOCKSZ
-1); x
+=8) {
455 t
=x
+x0
-2; //correct t=x+x0-2-(y&1), but its the same
456 if (t
<0) t
=0;//t always < width-2
457 t
=qp_store
[qy
+(t
>>qps
)];
458 t
=norm_qscale(t
, p
->mpeg2
);
459 if (t
!=p
->prev_q
) p
->prev_q
=t
, mul_thrmat_s(p
, t
);
460 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+x
*8, block3
+x
*8, 8); //yes, this is a HOTSPOT
462 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
463 memmove(block
, block
+(BLOCKSZ
-1)*64, 8*8*sizeof(DCTELEM
)); //cycling
464 memmove(block3
, block3
+(BLOCKSZ
-1)*64, 6*8*sizeof(DCTELEM
));
467 es
=width
+8-x0
; // 8, ...
469 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, (es
-4)>>2);
470 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
, block3
, es
&(~1));
471 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, es
>>2);
472 {const int y1
=y
-8+step
;//l5-7 l4-6
474 if (y1
&8) store_slice_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +8*stride
,
475 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
476 else store_slice2_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +0*stride
,
477 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
481 if (y
&7) { // == height & 7
482 if (y
&8) store_slice_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +8*stride
,
483 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
484 else store_slice2_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +0*stride
,
485 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
489 static int config(struct vf_instance
*vf
,
490 int width
, int height
, int d_width
, int d_height
,
491 unsigned int flags
, unsigned int outfmt
)
493 int h
= (height
+16+15)&(~15);
495 vf
->priv
->temp_stride
= (width
+16+15)&(~15);
496 vf
->priv
->temp
= (int16_t*)av_mallocz(vf
->priv
->temp_stride
*3*8*sizeof(int16_t));
497 //this can also be avoided, see above
498 vf
->priv
->src
= (uint8_t*)av_malloc(vf
->priv
->temp_stride
*h
*sizeof(uint8_t));
500 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
503 static void get_image(struct vf_instance
*vf
, mp_image_t
*mpi
)
505 if(mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
506 // ok, we can do pp in-place (or pp disabled):
507 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
508 mpi
->type
, mpi
->flags
, mpi
->width
, mpi
->height
);
509 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
510 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
511 mpi
->width
=vf
->dmpi
->width
;
512 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
513 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
514 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
515 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
516 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
518 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
521 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
)
524 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
525 // no DR, so get a new image! hope we'll get DR buffer:
526 dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
528 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
529 mpi
->width
,mpi
->height
);
530 vf_clone_mpi_attributes(dmpi
, mpi
);
535 vf
->priv
->mpeg2
= mpi
->qscale_type
;
536 if(mpi
->pict_type
!= 3 && mpi
->qscale
&& !vf
->priv
->qp
){
537 int w
= mpi
->qstride
;
538 int h
= (mpi
->h
+ 15) >> 4;
540 w
= (mpi
->w
+ 15) >> 4;
543 if(!vf
->priv
->non_b_qp
)
544 vf
->priv
->non_b_qp
= malloc(w
*h
);
545 fast_memcpy(vf
->priv
->non_b_qp
, mpi
->qscale
, w
*h
);
547 if(vf
->priv
->log2_count
|| !(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
548 char *qp_tab
= vf
->priv
->non_b_qp
;
549 if(vf
->priv
->bframes
|| !qp_tab
)
552 if(qp_tab
|| vf
->priv
->qp
){
553 filter(vf
->priv
, dmpi
->planes
[0], mpi
->planes
[0], dmpi
->stride
[0], mpi
->stride
[0],
554 mpi
->w
, mpi
->h
, qp_tab
, mpi
->qstride
, 1);
555 filter(vf
->priv
, dmpi
->planes
[1], mpi
->planes
[1], dmpi
->stride
[1], mpi
->stride
[1],
556 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, qp_tab
, mpi
->qstride
, 0);
557 filter(vf
->priv
, dmpi
->planes
[2], mpi
->planes
[2], dmpi
->stride
[2], mpi
->stride
[2],
558 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, qp_tab
, mpi
->qstride
, 0);
560 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
, dmpi
->stride
[0], mpi
->stride
[0]);
561 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]);
562 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]);
567 if(gCpuCaps
.hasMMX
) __asm__
volatile ("emms\n\t");
570 if(gCpuCaps
.hasMMX2
) __asm__
volatile ("sfence\n\t");
572 return vf_next_put_image(vf
,dmpi
, pts
);
575 static void uninit(struct vf_instance
*vf
)
577 if(!vf
->priv
) return;
579 if(vf
->priv
->temp
) av_free(vf
->priv
->temp
);
580 vf
->priv
->temp
= NULL
;
581 if(vf
->priv
->src
) av_free(vf
->priv
->src
);
583 //if(vf->priv->avctx) free(vf->priv->avctx);
584 //vf->priv->avctx= NULL;
585 if(vf
->priv
->non_b_qp
) free(vf
->priv
->non_b_qp
);
586 vf
->priv
->non_b_qp
= NULL
;
592 //===========================================================================//
594 static int query_format(struct vf_instance
*vf
, unsigned int fmt
)
608 return vf_next_query_format(vf
,fmt
);
613 static int control(struct vf_instance
*vf
, int request
, void* data
)
616 case VFCTRL_QUERY_MAX_PP_LEVEL
:
618 case VFCTRL_SET_PP_LEVEL
:
619 vf
->priv
->log2_count
= *((unsigned int*)data
);
620 if (vf
->priv
->log2_count
< 4) vf
->priv
->log2_count
=4;
623 return vf_next_control(vf
,request
,data
);
626 static int vf_open(vf_instance_t
*vf
, char *args
)
629 int custom_threshold_m
[64];
633 vf
->put_image
=put_image
;
634 vf
->get_image
=get_image
;
635 vf
->query_format
=query_format
;
637 vf
->control
= control
;
638 vf
->priv
=av_mallocz(sizeof(struct vf_priv_s
));//assumes align 16 !
642 //vf->priv->avctx= avcodec_alloc_context();
643 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
645 vf
->priv
->log2_count
= 4;
646 vf
->priv
->bframes
= 0;
648 if (args
) sscanf(args
, "%d:%d:%d:%d", &log2c
, &vf
->priv
->qp
, &i
, &vf
->priv
->bframes
);
650 if( log2c
>=4 && log2c
<=5 )
651 vf
->priv
->log2_count
= log2c
;
652 else if( log2c
>= 6 )
653 vf
->priv
->log2_count
= 5;
658 if (i
< -15) i
= -15;
661 bias
= (1<<4)+i
; //regulable
664 for(i
=0;i
<64;i
++) //FIXME: tune custom_threshold[] and remove this !
665 custom_threshold_m
[i
]=(int)(custom_threshold
[i
]*(bias
/71.)+ 0.5);
667 vf
->priv
->threshold_mtx_noq
[2*i
]=(uint64_t)custom_threshold_m
[i
*8+2]
668 |(((uint64_t)custom_threshold_m
[i
*8+6])<<16)
669 |(((uint64_t)custom_threshold_m
[i
*8+0])<<32)
670 |(((uint64_t)custom_threshold_m
[i
*8+4])<<48);
671 vf
->priv
->threshold_mtx_noq
[2*i
+1]=(uint64_t)custom_threshold_m
[i
*8+5]
672 |(((uint64_t)custom_threshold_m
[i
*8+3])<<16)
673 |(((uint64_t)custom_threshold_m
[i
*8+1])<<32)
674 |(((uint64_t)custom_threshold_m
[i
*8+7])<<48);
677 if (vf
->priv
->qp
) vf
->priv
->prev_q
=vf
->priv
->qp
, mul_thrmat_s(vf
->priv
, vf
->priv
->qp
);
682 const vf_info_t vf_info_fspp
= {
683 "fast simple postprocess",
685 "Michael Niedermayer, Nikolaj Poroshin",
691 //====================================================================
692 //Specific spp's dct, idct and threshold functions
693 //I'd prefer to have them in the separate file.
695 //#define MANGLE(a) #a
697 //typedef int16_t DCTELEM; //! only int16_t
700 #define DCTSIZE_S "8"
702 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
703 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
704 #define FIX64(x,s) C64(FIX(x,s))
706 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
707 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
708 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
712 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433
)=FIX64(0.382683433, 14);
713 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100
)=FIX64(0.541196100, 14);
714 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781
)=FIX64(0.707106781, 14);
715 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965
)=FIX64(1.306562965, 14);
717 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A
)=FIX64(1.414213562, 14);
719 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065
)=FIX64(1.847759065, 13);
720 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930
)=FIX64(-2.613125930, 13); //-
721 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562
)=FIX64(1.414213562, 13);
722 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200
)=FIX64(1.082392200, 13);
723 //for t3,t5,t7 == 0 shortcut
724 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065
)=FIX64(0.847759065, 14);
725 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497
)=FIX64(0.566454497, 14);
726 DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367
)=FIX64(0.198912367, 14);
728 DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND
)=C64(4);
729 DECLARE_ASM_CONST(8, uint64_t, MM_2
)=C64(2);
731 #else /* !HAVE_MMX */
733 typedef int32_t int_simd16_t
;
734 static const int16_t FIX_0_382683433
=FIX(0.382683433, 14);
735 static const int16_t FIX_0_541196100
=FIX(0.541196100, 14);
736 static const int16_t FIX_0_707106781
=FIX(0.707106781, 14);
737 static const int16_t FIX_1_306562965
=FIX(1.306562965, 14);
738 static const int16_t FIX_1_414213562_A
=FIX(1.414213562, 14);
739 static const int16_t FIX_1_847759065
=FIX(1.847759065, 13);
740 static const int16_t FIX_2_613125930
=FIX(-2.613125930, 13); //-
741 static const int16_t FIX_1_414213562
=FIX(1.414213562, 13);
742 static const int16_t FIX_1_082392200
=FIX(1.082392200, 13);
748 static void column_fidct_c(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
)
750 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
751 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
752 int_simd16_t z1
,z2
,z3
,z4
,z5
, z10
, z11
, z12
, z13
;
753 int_simd16_t d0
, d1
, d2
, d3
, d4
, d5
, d6
, d7
;
763 for (; cnt
> 0; cnt
-=2) { //start positions
764 threshold
=(int16_t*)thr_adr
;//threshold_mtx
765 for (ctr
= DCTSIZE
; ctr
> 0; ctr
--) {
766 // Process columns from input, add to output.
767 tmp0
= dataptr
[DCTSIZE
*0] + dataptr
[DCTSIZE
*7];
768 tmp7
= dataptr
[DCTSIZE
*0] - dataptr
[DCTSIZE
*7];
770 tmp1
= dataptr
[DCTSIZE
*1] + dataptr
[DCTSIZE
*6];
771 tmp6
= dataptr
[DCTSIZE
*1] - dataptr
[DCTSIZE
*6];
773 tmp2
= dataptr
[DCTSIZE
*2] + dataptr
[DCTSIZE
*5];
774 tmp5
= dataptr
[DCTSIZE
*2] - dataptr
[DCTSIZE
*5];
776 tmp3
= dataptr
[DCTSIZE
*3] + dataptr
[DCTSIZE
*4];
777 tmp4
= dataptr
[DCTSIZE
*3] - dataptr
[DCTSIZE
*4];
789 z1
= MULTIPLY16H((tmp12
+ tmp13
) <<2, FIX_0_707106781
);
795 THRESHOLD(tmp0
, d0
, threshold
[0*8]);
796 THRESHOLD(tmp1
, d2
, threshold
[2*8]);
797 THRESHOLD(tmp2
, d4
, threshold
[4*8]);
798 THRESHOLD(tmp3
, d6
, threshold
[6*8]);
800 tmp10
= (tmp0
+ tmp2
)>>2;
801 tmp11
= (tmp0
- tmp2
)>>2;
803 tmp13
= (tmp1
+ tmp3
)>>2; //+2 ! (psnr decides)
804 tmp12
= MULTIPLY16H((tmp1
- tmp3
), FIX_1_414213562_A
) - tmp13
; //<<2
806 tmp0
= tmp10
+ tmp13
; //->temps
807 tmp3
= tmp10
- tmp13
; //->temps
808 tmp1
= tmp11
+ tmp12
; //->temps
809 tmp2
= tmp11
- tmp12
; //->temps
817 z5
= MULTIPLY16H((tmp10
- tmp12
)<<2, FIX_0_382683433
);
818 z2
= MULTIPLY16H(tmp10
<<2, FIX_0_541196100
) + z5
;
819 z4
= MULTIPLY16H(tmp12
<<2, FIX_1_306562965
) + z5
;
820 z3
= MULTIPLY16H(tmp11
<<2, FIX_0_707106781
);
832 THRESHOLD(tmp4
, d1
, threshold
[1*8]);
833 THRESHOLD(tmp5
, d3
, threshold
[3*8]);
834 THRESHOLD(tmp6
, d5
, threshold
[5*8]);
835 THRESHOLD(tmp7
, d7
, threshold
[7*8]);
837 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
839 z10
= (tmp6
- tmp5
)<<1;
841 z12
= (tmp4
- tmp7
)<<1;
843 tmp7
= (z11
+ z13
)>>2; //+2 !
844 tmp11
= MULTIPLY16H((z11
- z13
)<<1, FIX_1_414213562
);
845 z5
= MULTIPLY16H(z10
+ z12
, FIX_1_847759065
);
846 tmp10
= MULTIPLY16H(z12
, FIX_1_082392200
) - z5
;
847 tmp12
= MULTIPLY16H(z10
, FIX_2_613125930
) + z5
; // - !!
853 wsptr
[DCTSIZE
*0]+= (tmp0
+ tmp7
);
854 wsptr
[DCTSIZE
*1]+= (tmp1
+ tmp6
);
855 wsptr
[DCTSIZE
*2]+= (tmp2
+ tmp5
);
856 wsptr
[DCTSIZE
*3]+= (tmp3
- tmp4
);
857 wsptr
[DCTSIZE
*4]+= (tmp3
+ tmp4
);
858 wsptr
[DCTSIZE
*5]+= (tmp2
- tmp5
);
859 wsptr
[DCTSIZE
*6]= (tmp1
- tmp6
);
860 wsptr
[DCTSIZE
*7]= (tmp0
- tmp7
);
862 dataptr
++; //next column
866 dataptr
+=8; //skip each second start pos
873 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
)
875 uint64_t __attribute__((aligned(8))) temps
[4];
879 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm1 \n\t"
881 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm7 \n\t"
882 "movq %%mm1, %%mm0 \n\t"
884 "paddw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm1 \n\t" //t0
885 "movq %%mm7, %%mm3 \n\t"
887 "paddw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm7 \n\t" //t3
888 "movq %%mm1, %%mm5 \n\t"
890 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm6 \n\t"
891 "psubw %%mm7, %%mm1 \n\t" //t13
893 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
894 "movq %%mm6, %%mm4 \n\t"
896 "paddw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm6 \n\t" //t1
897 "paddw %%mm7, %%mm5 \n\t" //t10
899 "paddw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t2
900 "movq %%mm6, %%mm7 \n\t"
902 "paddw %%mm2, %%mm6 \n\t" //t11
903 "psubw %%mm2, %%mm7 \n\t" //t12
905 "movq %%mm5, %%mm2 \n\t"
906 "paddw %%mm6, %%mm5 \n\t" //d0
907 // i0 t13 t12 i3 i1 d0 - d4
908 "psubw %%mm6, %%mm2 \n\t" //d4
909 "paddw %%mm1, %%mm7 \n\t"
911 "movq 4*16(%%"REG_d
"), %%mm6 \n\t"
912 "psllw $2, %%mm7 \n\t"
914 "psubw 0*16(%%"REG_d
"), %%mm5 \n\t"
915 "psubw %%mm6, %%mm2 \n\t"
917 "paddusw 0*16(%%"REG_d
"), %%mm5 \n\t"
918 "paddusw %%mm6, %%mm2 \n\t"
920 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm7 \n\t"
922 "paddw 0*16(%%"REG_d
"), %%mm5 \n\t"
923 "paddw %%mm6, %%mm2 \n\t"
925 "psubusw 0*16(%%"REG_d
"), %%mm5 \n\t"
926 "psubusw %%mm6, %%mm2 \n\t"
928 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
929 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
930 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
931 "paddw "MANGLE(MM_2
)", %%mm5 \n\t"
932 "movq %%mm2, %%mm6 \n\t"
934 "paddw %%mm5, %%mm2 \n\t"
935 "psubw %%mm6, %%mm5 \n\t"
937 "movq %%mm1, %%mm6 \n\t"
938 "paddw %%mm7, %%mm1 \n\t" //d2
940 "psubw 2*16(%%"REG_d
"), %%mm1 \n\t"
941 "psubw %%mm7, %%mm6 \n\t" //d6
943 "movq 6*16(%%"REG_d
"), %%mm7 \n\t"
944 "psraw $2, %%mm5 \n\t"
946 "paddusw 2*16(%%"REG_d
"), %%mm1 \n\t"
947 "psubw %%mm7, %%mm6 \n\t"
948 // t7 d2 /t11 t4 t6 - d6 /t10
950 "paddw 2*16(%%"REG_d
"), %%mm1 \n\t"
951 "paddusw %%mm7, %%mm6 \n\t"
953 "psubusw 2*16(%%"REG_d
"), %%mm1 \n\t"
954 "paddw %%mm7, %%mm6 \n\t"
956 "psubw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm3 \n\t"
957 "psubusw %%mm7, %%mm6 \n\t"
959 //movq [edi+"DCTSIZE_S"*2*2], mm1
960 //movq [edi+"DCTSIZE_S"*6*2], mm6
961 "movq %%mm1, %%mm7 \n\t"
962 "psraw $2, %%mm2 \n\t"
964 "psubw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm4 \n\t"
965 "psubw %%mm6, %%mm1 \n\t"
967 "psubw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm0 \n\t"
968 "paddw %%mm7, %%mm6 \n\t" //'t13
970 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
971 "movq %%mm2, %%mm7 \n\t"
973 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm1 \n\t"
974 "paddw %%mm6, %%mm2 \n\t" //'t0
976 "movq %%mm2, 0*8+%3 \n\t" //!
977 "psubw %%mm6, %%mm7 \n\t" //'t3
979 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
980 "psubw %%mm6, %%mm1 \n\t" //'t12
982 "psubw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t5
983 "movq %%mm5, %%mm6 \n\t"
985 "movq %%mm7, 3*8+%3 \n\t"
986 "paddw %%mm2, %%mm3 \n\t" //t10
988 "paddw %%mm4, %%mm2 \n\t" //t11
989 "paddw %%mm0, %%mm4 \n\t" //t12
991 "movq %%mm3, %%mm7 \n\t"
992 "psubw %%mm4, %%mm3 \n\t"
994 "psllw $2, %%mm3 \n\t"
995 "psllw $2, %%mm7 \n\t" //opt for P6
997 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t"
998 "psllw $2, %%mm4 \n\t"
1000 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm7 \n\t"
1001 "psllw $2, %%mm2 \n\t"
1003 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm4 \n\t"
1004 "paddw %%mm1, %%mm5 \n\t" //'t1
1006 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm2 \n\t"
1007 "psubw %%mm1, %%mm6 \n\t" //'t2
1008 // t7 't12 't11 t4 t6 - 't13 't10 ---
1010 "paddw %%mm3, %%mm7 \n\t" //z2
1012 "movq %%mm5, 1*8+%3 \n\t"
1013 "paddw %%mm3, %%mm4 \n\t" //z4
1015 "movq 3*16(%%"REG_d
"), %%mm3 \n\t"
1016 "movq %%mm0, %%mm1 \n\t"
1018 "movq %%mm6, 2*8+%3 \n\t"
1019 "psubw %%mm2, %%mm1 \n\t" //z13
1022 "paddw %%mm2, %%mm0 \n\t" //z11
1023 "movq %%mm1, %%mm5 \n\t"
1025 "movq 5*16(%%"REG_d
"), %%mm2 \n\t"
1026 "psubw %%mm7, %%mm1 \n\t" //d3
1028 "paddw %%mm7, %%mm5 \n\t" //d5
1029 "psubw %%mm3, %%mm1 \n\t"
1031 "movq 1*16(%%"REG_d
"), %%mm7 \n\t"
1032 "psubw %%mm2, %%mm5 \n\t"
1034 "movq %%mm0, %%mm6 \n\t"
1035 "paddw %%mm4, %%mm0 \n\t" //d1
1037 "paddusw %%mm3, %%mm1 \n\t"
1038 "psubw %%mm4, %%mm6 \n\t" //d7
1040 // d1 d3 - - - d5 d7 -
1041 "movq 7*16(%%"REG_d
"), %%mm4 \n\t"
1042 "psubw %%mm7, %%mm0 \n\t"
1044 "psubw %%mm4, %%mm6 \n\t"
1045 "paddusw %%mm2, %%mm5 \n\t"
1047 "paddusw %%mm4, %%mm6 \n\t"
1048 "paddw %%mm3, %%mm1 \n\t"
1050 "paddw %%mm2, %%mm5 \n\t"
1051 "paddw %%mm4, %%mm6 \n\t"
1053 "psubusw %%mm3, %%mm1 \n\t"
1054 "psubusw %%mm2, %%mm5 \n\t"
1056 "psubusw %%mm4, %%mm6 \n\t"
1057 "movq %%mm1, %%mm4 \n\t"
1059 "por %%mm5, %%mm4 \n\t"
1060 "paddusw %%mm7, %%mm0 \n\t"
1062 "por %%mm6, %%mm4 \n\t"
1063 "paddw %%mm7, %%mm0 \n\t"
1065 "packssdw %%mm4, %%mm4 \n\t"
1066 "psubusw %%mm7, %%mm0 \n\t"
1068 "movd %%mm4, %%"REG_a
" \n\t"
1069 "or %%"REG_a
", %%"REG_a
" \n\t"
1071 //movq [edi+"DCTSIZE_S"*3*2], mm1
1072 //movq [edi+"DCTSIZE_S"*5*2], mm5
1073 //movq [edi+"DCTSIZE_S"*1*2], mm0
1074 //movq [edi+"DCTSIZE_S"*7*2], mm6
1075 // t4 t5 - - - t6 t7 -
1076 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1077 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1078 "movq 0*8+%3, %%mm4 \n\t"
1079 "movq %%mm0, %%mm1 \n\t"
1081 "pmulhw "MANGLE(MM_FIX_0_847759065
)", %%mm0 \n\t" //tmp6
1082 "movq %%mm1, %%mm2 \n\t"
1084 "movq "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm5 \n\t"
1085 "movq %%mm2, %%mm3 \n\t"
1087 "pmulhw "MANGLE(MM_FIX_0_566454497
)", %%mm1 \n\t" //tmp5
1088 "paddw %%mm4, %%mm5 \n\t"
1090 "movq 1*8+%3, %%mm6 \n\t"
1092 "psraw $2, %%mm3 \n\t" //tmp7
1094 "pmulhw "MANGLE(MM_FIX_0_198912367
)", %%mm2 \n\t" //-tmp4
1095 "psubw %%mm3, %%mm4 \n\t"
1097 "movq "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm7 \n\t"
1098 "paddw %%mm3, %%mm5 \n\t"
1100 "movq %%mm4, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1101 "paddw %%mm6, %%mm7 \n\t"
1103 "movq 2*8+%3, %%mm3 \n\t"
1104 "psubw %%mm0, %%mm6 \n\t"
1106 "movq "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm4 \n\t"
1107 "paddw %%mm0, %%mm7 \n\t"
1109 "movq %%mm5, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1110 "paddw %%mm3, %%mm4 \n\t"
1112 "movq %%mm6, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1113 "psubw %%mm1, %%mm3 \n\t"
1115 "movq "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm5 \n\t"
1116 "paddw %%mm1, %%mm4 \n\t"
1118 "movq "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm6 \n\t"
1119 "paddw %%mm3, %%mm5 \n\t"
1121 "movq 3*8+%3, %%mm0 \n\t"
1122 "add $8, %%"REG_S
" \n\t"
1124 "movq %%mm7, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1125 "paddw %%mm0, %%mm6 \n\t"
1127 "movq %%mm4, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1128 "psubw %%mm2, %%mm0 \n\t"
1130 "movq "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm7 \n\t"
1131 "paddw %%mm2, %%mm6 \n\t"
1133 "movq %%mm5, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1134 "paddw %%mm0, %%mm7 \n\t"
1136 "movq %%mm6, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1138 "movq %%mm7, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1139 "add $8, %%"REG_D
" \n\t"
1144 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1148 "movq %%mm5, %%mm3 \n\t"
1149 "psubw %%mm1, %%mm5 \n\t"
1151 "psllw $1, %%mm5 \n\t" //'z10
1152 "paddw %%mm1, %%mm3 \n\t" //'z13
1154 "movq %%mm0, %%mm2 \n\t"
1155 "psubw %%mm6, %%mm0 \n\t"
1157 "movq %%mm5, %%mm1 \n\t"
1158 "psllw $1, %%mm0 \n\t" //'z12
1160 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm1 \n\t" //-
1161 "paddw %%mm0, %%mm5 \n\t"
1163 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm5 \n\t" //'z5
1164 "paddw %%mm6, %%mm2 \n\t" //'z11
1166 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm0 \n\t"
1167 "movq %%mm2, %%mm7 \n\t"
1170 "movq 0*8+%3, %%mm4 \n\t"
1171 "psubw %%mm3, %%mm2 \n\t"
1173 "psllw $1, %%mm2 \n\t"
1174 "paddw %%mm3, %%mm7 \n\t" //'t7
1176 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //'t11
1177 "movq %%mm4, %%mm6 \n\t"
1179 "psraw $2, %%mm7 \n\t"
1181 "paddw "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm4 \n\t"
1182 "psubw %%mm7, %%mm6 \n\t"
1184 "movq 1*8+%3, %%mm3 \n\t"
1185 "paddw %%mm7, %%mm4 \n\t"
1187 "movq %%mm6, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1188 "paddw %%mm5, %%mm1 \n\t" //'t12
1190 "movq %%mm4, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1191 "psubw %%mm7, %%mm1 \n\t" //'t6
1193 "movq 2*8+%3, %%mm7 \n\t"
1194 "psubw %%mm5, %%mm0 \n\t" //'t10
1196 "movq 3*8+%3, %%mm6 \n\t"
1197 "movq %%mm3, %%mm5 \n\t"
1199 "paddw "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm3 \n\t"
1200 "psubw %%mm1, %%mm5 \n\t"
1202 "psubw %%mm1, %%mm2 \n\t" //'t5
1203 "paddw %%mm1, %%mm3 \n\t"
1205 "movq %%mm5, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1206 "movq %%mm7, %%mm4 \n\t"
1208 "paddw "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm7 \n\t"
1209 "psubw %%mm2, %%mm4 \n\t"
1211 "paddw "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm4 \n\t"
1212 "paddw %%mm2, %%mm7 \n\t"
1214 "movq %%mm3, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1215 "paddw %%mm2, %%mm0 \n\t" //'t4
1217 // 't4 't6 't5 - - - - 't7
1218 "movq %%mm7, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1219 "movq %%mm6, %%mm1 \n\t"
1221 "paddw "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm6 \n\t"
1222 "psubw %%mm0, %%mm1 \n\t"
1224 "paddw "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm1 \n\t"
1225 "paddw %%mm0, %%mm6 \n\t"
1227 "movq %%mm4, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1228 "add $8, %%"REG_S
" \n\t"
1230 "movq %%mm6, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1232 "movq %%mm1, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1233 "add $8, %%"REG_D
" \n\t"
1236 //=part 2 (the same)===========================================================
1237 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm1 \n\t"
1239 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm7 \n\t"
1240 "movq %%mm1, %%mm0 \n\t"
1242 "paddw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm1 \n\t" //t0
1243 "movq %%mm7, %%mm3 \n\t"
1245 "paddw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm7 \n\t" //t3
1246 "movq %%mm1, %%mm5 \n\t"
1248 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm6 \n\t"
1249 "psubw %%mm7, %%mm1 \n\t" //t13
1251 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1252 "movq %%mm6, %%mm4 \n\t"
1254 "paddw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm6 \n\t" //t1
1255 "paddw %%mm7, %%mm5 \n\t" //t10
1257 "paddw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t2
1258 "movq %%mm6, %%mm7 \n\t"
1260 "paddw %%mm2, %%mm6 \n\t" //t11
1261 "psubw %%mm2, %%mm7 \n\t" //t12
1263 "movq %%mm5, %%mm2 \n\t"
1264 "paddw %%mm6, %%mm5 \n\t" //d0
1265 // i0 t13 t12 i3 i1 d0 - d4
1266 "psubw %%mm6, %%mm2 \n\t" //d4
1267 "paddw %%mm1, %%mm7 \n\t"
1269 "movq 1*8+4*16(%%"REG_d
"), %%mm6 \n\t"
1270 "psllw $2, %%mm7 \n\t"
1272 "psubw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1273 "psubw %%mm6, %%mm2 \n\t"
1275 "paddusw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1276 "paddusw %%mm6, %%mm2 \n\t"
1278 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm7 \n\t"
1280 "paddw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1281 "paddw %%mm6, %%mm2 \n\t"
1283 "psubusw 1*8+0*16(%%"REG_d
"), %%mm5 \n\t"
1284 "psubusw %%mm6, %%mm2 \n\t"
1286 //This func is totally compute-bound, operates at huge speed. So, DC shortcut
1287 // at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
1288 //However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
1289 "paddw "MANGLE(MM_2
)", %%mm5 \n\t"
1290 "movq %%mm2, %%mm6 \n\t"
1292 "paddw %%mm5, %%mm2 \n\t"
1293 "psubw %%mm6, %%mm5 \n\t"
1295 "movq %%mm1, %%mm6 \n\t"
1296 "paddw %%mm7, %%mm1 \n\t" //d2
1298 "psubw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1299 "psubw %%mm7, %%mm6 \n\t" //d6
1301 "movq 1*8+6*16(%%"REG_d
"), %%mm7 \n\t"
1302 "psraw $2, %%mm5 \n\t"
1304 "paddusw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1305 "psubw %%mm7, %%mm6 \n\t"
1306 // t7 d2 /t11 t4 t6 - d6 /t10
1308 "paddw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1309 "paddusw %%mm7, %%mm6 \n\t"
1311 "psubusw 1*8+2*16(%%"REG_d
"), %%mm1 \n\t"
1312 "paddw %%mm7, %%mm6 \n\t"
1314 "psubw "DCTSIZE_S
"*4*2(%%"REG_S
"), %%mm3 \n\t"
1315 "psubusw %%mm7, %%mm6 \n\t"
1317 //movq [edi+"DCTSIZE_S"*2*2], mm1
1318 //movq [edi+"DCTSIZE_S"*6*2], mm6
1319 "movq %%mm1, %%mm7 \n\t"
1320 "psraw $2, %%mm2 \n\t"
1322 "psubw "DCTSIZE_S
"*6*2(%%"REG_S
"), %%mm4 \n\t"
1323 "psubw %%mm6, %%mm1 \n\t"
1325 "psubw "DCTSIZE_S
"*7*2(%%"REG_S
"), %%mm0 \n\t"
1326 "paddw %%mm7, %%mm6 \n\t" //'t13
1328 "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
1329 "movq %%mm2, %%mm7 \n\t"
1331 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm1 \n\t"
1332 "paddw %%mm6, %%mm2 \n\t" //'t0
1334 "movq %%mm2, 0*8+%3 \n\t" //!
1335 "psubw %%mm6, %%mm7 \n\t" //'t3
1337 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1338 "psubw %%mm6, %%mm1 \n\t" //'t12
1340 "psubw "DCTSIZE_S
"*5*2(%%"REG_S
"), %%mm2 \n\t" //t5
1341 "movq %%mm5, %%mm6 \n\t"
1343 "movq %%mm7, 3*8+%3 \n\t"
1344 "paddw %%mm2, %%mm3 \n\t" //t10
1346 "paddw %%mm4, %%mm2 \n\t" //t11
1347 "paddw %%mm0, %%mm4 \n\t" //t12
1349 "movq %%mm3, %%mm7 \n\t"
1350 "psubw %%mm4, %%mm3 \n\t"
1352 "psllw $2, %%mm3 \n\t"
1353 "psllw $2, %%mm7 \n\t" //opt for P6
1355 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t"
1356 "psllw $2, %%mm4 \n\t"
1358 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm7 \n\t"
1359 "psllw $2, %%mm2 \n\t"
1361 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm4 \n\t"
1362 "paddw %%mm1, %%mm5 \n\t" //'t1
1364 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm2 \n\t"
1365 "psubw %%mm1, %%mm6 \n\t" //'t2
1366 // t7 't12 't11 t4 t6 - 't13 't10 ---
1368 "paddw %%mm3, %%mm7 \n\t" //z2
1370 "movq %%mm5, 1*8+%3 \n\t"
1371 "paddw %%mm3, %%mm4 \n\t" //z4
1373 "movq 1*8+3*16(%%"REG_d
"), %%mm3 \n\t"
1374 "movq %%mm0, %%mm1 \n\t"
1376 "movq %%mm6, 2*8+%3 \n\t"
1377 "psubw %%mm2, %%mm1 \n\t" //z13
1380 "paddw %%mm2, %%mm0 \n\t" //z11
1381 "movq %%mm1, %%mm5 \n\t"
1383 "movq 1*8+5*16(%%"REG_d
"), %%mm2 \n\t"
1384 "psubw %%mm7, %%mm1 \n\t" //d3
1386 "paddw %%mm7, %%mm5 \n\t" //d5
1387 "psubw %%mm3, %%mm1 \n\t"
1389 "movq 1*8+1*16(%%"REG_d
"), %%mm7 \n\t"
1390 "psubw %%mm2, %%mm5 \n\t"
1392 "movq %%mm0, %%mm6 \n\t"
1393 "paddw %%mm4, %%mm0 \n\t" //d1
1395 "paddusw %%mm3, %%mm1 \n\t"
1396 "psubw %%mm4, %%mm6 \n\t" //d7
1398 // d1 d3 - - - d5 d7 -
1399 "movq 1*8+7*16(%%"REG_d
"), %%mm4 \n\t"
1400 "psubw %%mm7, %%mm0 \n\t"
1402 "psubw %%mm4, %%mm6 \n\t"
1403 "paddusw %%mm2, %%mm5 \n\t"
1405 "paddusw %%mm4, %%mm6 \n\t"
1406 "paddw %%mm3, %%mm1 \n\t"
1408 "paddw %%mm2, %%mm5 \n\t"
1409 "paddw %%mm4, %%mm6 \n\t"
1411 "psubusw %%mm3, %%mm1 \n\t"
1412 "psubusw %%mm2, %%mm5 \n\t"
1414 "psubusw %%mm4, %%mm6 \n\t"
1415 "movq %%mm1, %%mm4 \n\t"
1417 "por %%mm5, %%mm4 \n\t"
1418 "paddusw %%mm7, %%mm0 \n\t"
1420 "por %%mm6, %%mm4 \n\t"
1421 "paddw %%mm7, %%mm0 \n\t"
1423 "packssdw %%mm4, %%mm4 \n\t"
1424 "psubusw %%mm7, %%mm0 \n\t"
1426 "movd %%mm4, %%"REG_a
" \n\t"
1427 "or %%"REG_a
", %%"REG_a
" \n\t"
1429 //movq [edi+"DCTSIZE_S"*3*2], mm1
1430 //movq [edi+"DCTSIZE_S"*5*2], mm5
1431 //movq [edi+"DCTSIZE_S"*1*2], mm0
1432 //movq [edi+"DCTSIZE_S"*7*2], mm6
1433 // t4 t5 - - - t6 t7 -
1434 //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
1435 //Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
1436 "movq 0*8+%3, %%mm4 \n\t"
1437 "movq %%mm0, %%mm1 \n\t"
1439 "pmulhw "MANGLE(MM_FIX_0_847759065
)", %%mm0 \n\t" //tmp6
1440 "movq %%mm1, %%mm2 \n\t"
1442 "movq "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm5 \n\t"
1443 "movq %%mm2, %%mm3 \n\t"
1445 "pmulhw "MANGLE(MM_FIX_0_566454497
)", %%mm1 \n\t" //tmp5
1446 "paddw %%mm4, %%mm5 \n\t"
1448 "movq 1*8+%3, %%mm6 \n\t"
1450 "psraw $2, %%mm3 \n\t" //tmp7
1452 "pmulhw "MANGLE(MM_FIX_0_198912367
)", %%mm2 \n\t" //-tmp4
1453 "psubw %%mm3, %%mm4 \n\t"
1455 "movq "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm7 \n\t"
1456 "paddw %%mm3, %%mm5 \n\t"
1458 "movq %%mm4, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1459 "paddw %%mm6, %%mm7 \n\t"
1461 "movq 2*8+%3, %%mm3 \n\t"
1462 "psubw %%mm0, %%mm6 \n\t"
1464 "movq "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm4 \n\t"
1465 "paddw %%mm0, %%mm7 \n\t"
1467 "movq %%mm5, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1468 "paddw %%mm3, %%mm4 \n\t"
1470 "movq %%mm6, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1471 "psubw %%mm1, %%mm3 \n\t"
1473 "movq "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm5 \n\t"
1474 "paddw %%mm1, %%mm4 \n\t"
1476 "movq "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm6 \n\t"
1477 "paddw %%mm3, %%mm5 \n\t"
1479 "movq 3*8+%3, %%mm0 \n\t"
1480 "add $24, %%"REG_S
" \n\t"
1482 "movq %%mm7, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1483 "paddw %%mm0, %%mm6 \n\t"
1485 "movq %%mm4, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1486 "psubw %%mm2, %%mm0 \n\t"
1488 "movq "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm7 \n\t"
1489 "paddw %%mm2, %%mm6 \n\t"
1491 "movq %%mm5, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1492 "paddw %%mm0, %%mm7 \n\t"
1494 "movq %%mm6, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1496 "movq %%mm7, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1497 "add $24, %%"REG_D
" \n\t"
1498 "sub $2, %%"REG_c
" \n\t"
1504 //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
1508 "movq %%mm5, %%mm3 \n\t"
1509 "psubw %%mm1, %%mm5 \n\t"
1511 "psllw $1, %%mm5 \n\t" //'z10
1512 "paddw %%mm1, %%mm3 \n\t" //'z13
1514 "movq %%mm0, %%mm2 \n\t"
1515 "psubw %%mm6, %%mm0 \n\t"
1517 "movq %%mm5, %%mm1 \n\t"
1518 "psllw $1, %%mm0 \n\t" //'z12
1520 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm1 \n\t" //-
1521 "paddw %%mm0, %%mm5 \n\t"
1523 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm5 \n\t" //'z5
1524 "paddw %%mm6, %%mm2 \n\t" //'z11
1526 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm0 \n\t"
1527 "movq %%mm2, %%mm7 \n\t"
1530 "movq 0*8+%3, %%mm4 \n\t"
1531 "psubw %%mm3, %%mm2 \n\t"
1533 "psllw $1, %%mm2 \n\t"
1534 "paddw %%mm3, %%mm7 \n\t" //'t7
1536 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //'t11
1537 "movq %%mm4, %%mm6 \n\t"
1539 "psraw $2, %%mm7 \n\t"
1541 "paddw "DCTSIZE_S
"*0*2(%%"REG_D
"), %%mm4 \n\t"
1542 "psubw %%mm7, %%mm6 \n\t"
1544 "movq 1*8+%3, %%mm3 \n\t"
1545 "paddw %%mm7, %%mm4 \n\t"
1547 "movq %%mm6, "DCTSIZE_S
"*7*2(%%"REG_D
") \n\t"
1548 "paddw %%mm5, %%mm1 \n\t" //'t12
1550 "movq %%mm4, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
1551 "psubw %%mm7, %%mm1 \n\t" //'t6
1553 "movq 2*8+%3, %%mm7 \n\t"
1554 "psubw %%mm5, %%mm0 \n\t" //'t10
1556 "movq 3*8+%3, %%mm6 \n\t"
1557 "movq %%mm3, %%mm5 \n\t"
1559 "paddw "DCTSIZE_S
"*1*2(%%"REG_D
"), %%mm3 \n\t"
1560 "psubw %%mm1, %%mm5 \n\t"
1562 "psubw %%mm1, %%mm2 \n\t" //'t5
1563 "paddw %%mm1, %%mm3 \n\t"
1565 "movq %%mm5, "DCTSIZE_S
"*6*2(%%"REG_D
") \n\t"
1566 "movq %%mm7, %%mm4 \n\t"
1568 "paddw "DCTSIZE_S
"*2*2(%%"REG_D
"), %%mm7 \n\t"
1569 "psubw %%mm2, %%mm4 \n\t"
1571 "paddw "DCTSIZE_S
"*5*2(%%"REG_D
"), %%mm4 \n\t"
1572 "paddw %%mm2, %%mm7 \n\t"
1574 "movq %%mm3, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
1575 "paddw %%mm2, %%mm0 \n\t" //'t4
1577 // 't4 't6 't5 - - - - 't7
1578 "movq %%mm7, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
1579 "movq %%mm6, %%mm1 \n\t"
1581 "paddw "DCTSIZE_S
"*4*2(%%"REG_D
"), %%mm6 \n\t"
1582 "psubw %%mm0, %%mm1 \n\t"
1584 "paddw "DCTSIZE_S
"*3*2(%%"REG_D
"), %%mm1 \n\t"
1585 "paddw %%mm0, %%mm6 \n\t"
1587 "movq %%mm4, "DCTSIZE_S
"*5*2(%%"REG_D
") \n\t"
1588 "add $24, %%"REG_S
" \n\t"
1590 "movq %%mm6, "DCTSIZE_S
"*4*2(%%"REG_D
") \n\t"
1592 "movq %%mm1, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
1593 "add $24, %%"REG_D
" \n\t"
1594 "sub $2, %%"REG_c
" \n\t"
1598 : "+S"(data
), "+D"(output
), "+c"(cnt
), "=o"(temps
)
1608 static void row_idct_c(DCTELEM
* workspace
,
1609 int16_t* output_adr
, int output_stride
, int cnt
)
1611 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
1612 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
1613 int_simd16_t z5
, z10
, z11
, z12
, z13
;
1619 outptr
= output_adr
;
1620 for (; cnt
> 0; cnt
--) {
1622 //Simd version reads 4x4 block and transposes it
1623 tmp10
= ( wsptr
[2] + wsptr
[3]);
1624 tmp11
= ( wsptr
[2] - wsptr
[3]);
1626 tmp13
= ( wsptr
[0] + wsptr
[1]);
1627 tmp12
= (MULTIPLY16H( wsptr
[0] - wsptr
[1], FIX_1_414213562_A
)<<2) - tmp13
;//this shift order to avoid overflow
1629 tmp0
= tmp10
+ tmp13
; //->temps
1630 tmp3
= tmp10
- tmp13
; //->temps
1631 tmp1
= tmp11
+ tmp12
;
1632 tmp2
= tmp11
- tmp12
;
1635 //Also transpose, with previous:
1637 // ---- ---- idct ||||
1638 // ---- ---- ---> ||||
1640 z13
= wsptr
[4] + wsptr
[5];
1641 z10
= wsptr
[4] - wsptr
[5];
1642 z11
= wsptr
[6] + wsptr
[7];
1643 z12
= wsptr
[6] - wsptr
[7];
1646 tmp11
= MULTIPLY16H(z11
- z13
, FIX_1_414213562
);
1648 z5
= MULTIPLY16H(z10
+ z12
, FIX_1_847759065
);
1649 tmp10
= MULTIPLY16H(z12
, FIX_1_082392200
) - z5
;
1650 tmp12
= MULTIPLY16H(z10
, FIX_2_613125930
) + z5
; // - FIX_
1652 tmp6
= (tmp12
<<3) - tmp7
;
1653 tmp5
= (tmp11
<<3) - tmp6
;
1654 tmp4
= (tmp10
<<3) + tmp5
;
1656 // Final output stage: descale and write column
1657 outptr
[0*output_stride
]+= DESCALE(tmp0
+ tmp7
, 3);
1658 outptr
[1*output_stride
]+= DESCALE(tmp1
+ tmp6
, 3);
1659 outptr
[2*output_stride
]+= DESCALE(tmp2
+ tmp5
, 3);
1660 outptr
[3*output_stride
]+= DESCALE(tmp3
- tmp4
, 3);
1661 outptr
[4*output_stride
]+= DESCALE(tmp3
+ tmp4
, 3);
1662 outptr
[5*output_stride
]+= DESCALE(tmp2
- tmp5
, 3);
1663 outptr
[6*output_stride
]+= DESCALE(tmp1
- tmp6
, 3); //no += ?
1664 outptr
[7*output_stride
]+= DESCALE(tmp0
- tmp7
, 3); //no += ?
1667 wsptr
+= DCTSIZE
; // advance pointer to next row
1671 #else /* HAVE_MMX */
1673 static void row_idct_mmx (DCTELEM
* workspace
,
1674 int16_t* output_adr
, int output_stride
, int cnt
)
1676 uint64_t __attribute__((aligned(8))) temps
[4];
1678 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1680 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm0 \n\t"
1683 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm1 \n\t"
1684 "movq %%mm0, %%mm4 \n\t"
1686 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1687 "punpcklwd %%mm1, %%mm0 \n\t"
1689 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm3 \n\t"
1690 "punpckhwd %%mm1, %%mm4 \n\t"
1693 "movq %%mm2, %%mm7 \n\t"
1694 "punpcklwd %%mm3, %%mm2 \n\t"
1696 "movq %%mm0, %%mm6 \n\t"
1697 "punpckldq %%mm2, %%mm0 \n\t" //0
1699 "punpckhdq %%mm2, %%mm6 \n\t" //1
1700 "movq %%mm0, %%mm5 \n\t"
1702 "punpckhwd %%mm3, %%mm7 \n\t"
1703 "psubw %%mm6, %%mm0 \n\t"
1705 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm0 \n\t"
1706 "movq %%mm4, %%mm2 \n\t"
1708 "punpckldq %%mm7, %%mm4 \n\t" //2
1709 "paddw %%mm6, %%mm5 \n\t"
1711 "punpckhdq %%mm7, %%mm2 \n\t" //3
1712 "movq %%mm4, %%mm1 \n\t"
1714 "psllw $2, %%mm0 \n\t"
1715 "paddw %%mm2, %%mm4 \n\t" //t10
1717 "movq "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm3 \n\t"
1718 "psubw %%mm2, %%mm1 \n\t" //t11
1720 "movq "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm2 \n\t"
1721 "psubw %%mm5, %%mm0 \n\t"
1723 "movq %%mm4, %%mm6 \n\t"
1724 "paddw %%mm5, %%mm4 \n\t" //t0
1726 "psubw %%mm5, %%mm6 \n\t" //t3
1727 "movq %%mm1, %%mm7 \n\t"
1729 "movq "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm5 \n\t"
1730 "paddw %%mm0, %%mm1 \n\t" //t1
1732 "movq %%mm4, 0*8+%3 \n\t" //t0
1733 "movq %%mm3, %%mm4 \n\t"
1735 "movq %%mm6, 1*8+%3 \n\t" //t3
1736 "punpcklwd %%mm2, %%mm3 \n\t"
1739 "movq "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm6 \n\t"
1740 "punpckhwd %%mm2, %%mm4 \n\t"
1742 "movq %%mm5, %%mm2 \n\t"
1743 "punpcklwd %%mm6, %%mm5 \n\t"
1745 "psubw %%mm0, %%mm7 \n\t" //t2
1746 "punpckhwd %%mm6, %%mm2 \n\t"
1748 "movq %%mm3, %%mm0 \n\t"
1749 "punpckldq %%mm5, %%mm3 \n\t" //4
1751 "punpckhdq %%mm5, %%mm0 \n\t" //5
1752 "movq %%mm4, %%mm5 \n\t"
1755 "movq %%mm3, %%mm6 \n\t"
1756 "punpckldq %%mm2, %%mm4 \n\t" //6
1758 "psubw %%mm0, %%mm3 \n\t" //z10
1759 "punpckhdq %%mm2, %%mm5 \n\t" //7
1761 "paddw %%mm0, %%mm6 \n\t" //z13
1762 "movq %%mm4, %%mm2 \n\t"
1764 "movq %%mm3, %%mm0 \n\t"
1765 "psubw %%mm5, %%mm4 \n\t" //z12
1767 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm0 \n\t" //-
1768 "paddw %%mm4, %%mm3 \n\t"
1770 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm3 \n\t" //z5
1771 "paddw %%mm5, %%mm2 \n\t" //z11 >
1773 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm4 \n\t"
1774 "movq %%mm2, %%mm5 \n\t"
1776 "psubw %%mm6, %%mm2 \n\t"
1777 "paddw %%mm6, %%mm5 \n\t" //t7
1779 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //t11
1780 "paddw %%mm3, %%mm0 \n\t" //t12
1782 "psllw $3, %%mm0 \n\t"
1783 "psubw %%mm3, %%mm4 \n\t" //t10
1785 "movq 0*8+%3, %%mm6 \n\t"
1786 "movq %%mm1, %%mm3 \n\t"
1788 "psllw $3, %%mm4 \n\t"
1789 "psubw %%mm5, %%mm0 \n\t" //t6
1791 "psllw $3, %%mm2 \n\t"
1792 "paddw %%mm0, %%mm1 \n\t" //d1
1794 "psubw %%mm0, %%mm2 \n\t" //t5
1795 "psubw %%mm0, %%mm3 \n\t" //d6
1797 "paddw %%mm2, %%mm4 \n\t" //t4
1798 "movq %%mm7, %%mm0 \n\t"
1800 "paddw %%mm2, %%mm7 \n\t" //d2
1801 "psubw %%mm2, %%mm0 \n\t" //d5
1803 "movq "MANGLE(MM_DESCALE_RND
)", %%mm2 \n\t" //4
1804 "psubw %%mm5, %%mm6 \n\t" //d7
1806 "paddw 0*8+%3, %%mm5 \n\t" //d0
1807 "paddw %%mm2, %%mm1 \n\t"
1809 "paddw %%mm2, %%mm5 \n\t"
1810 "psraw $3, %%mm1 \n\t"
1812 "paddw %%mm2, %%mm7 \n\t"
1813 "psraw $3, %%mm5 \n\t"
1815 "paddw (%%"REG_D
"), %%mm5 \n\t"
1816 "psraw $3, %%mm7 \n\t"
1818 "paddw (%%"REG_D
",%%"REG_a
",), %%mm1 \n\t"
1819 "paddw %%mm2, %%mm0 \n\t"
1821 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm7 \n\t"
1822 "paddw %%mm2, %%mm3 \n\t"
1824 "movq %%mm5, (%%"REG_D
") \n\t"
1825 "paddw %%mm2, %%mm6 \n\t"
1827 "movq %%mm1, (%%"REG_D
",%%"REG_a
",) \n\t"
1828 "psraw $3, %%mm0 \n\t"
1830 "movq %%mm7, (%%"REG_D
",%%"REG_a
",2) \n\t"
1831 "add %%"REG_d
", %%"REG_D
" \n\t" //3*ls
1833 "movq 1*8+%3, %%mm5 \n\t" //t3
1834 "psraw $3, %%mm3 \n\t"
1836 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm0 \n\t"
1837 "psubw %%mm4, %%mm5 \n\t" //d3
1839 "paddw (%%"REG_D
",%%"REG_d
",), %%mm3 \n\t"
1840 "psraw $3, %%mm6 \n\t"
1842 "paddw 1*8+%3, %%mm4 \n\t" //d4
1843 "paddw %%mm2, %%mm5 \n\t"
1845 "paddw (%%"REG_D
",%%"REG_a
",4), %%mm6 \n\t"
1846 "paddw %%mm2, %%mm4 \n\t"
1848 "movq %%mm0, (%%"REG_D
",%%"REG_a
",2) \n\t"
1849 "psraw $3, %%mm5 \n\t"
1851 "paddw (%%"REG_D
"), %%mm5 \n\t"
1852 "psraw $3, %%mm4 \n\t"
1854 "paddw (%%"REG_D
",%%"REG_a
",), %%mm4 \n\t"
1855 "add $"DCTSIZE_S
"*2*4, %%"REG_S
" \n\t" //4 rows
1857 "movq %%mm3, (%%"REG_D
",%%"REG_d
",) \n\t"
1858 "movq %%mm6, (%%"REG_D
",%%"REG_a
",4) \n\t"
1859 "movq %%mm5, (%%"REG_D
") \n\t"
1860 "movq %%mm4, (%%"REG_D
",%%"REG_a
",) \n\t"
1862 "sub %%"REG_d
", %%"REG_D
" \n\t"
1863 "add $8, %%"REG_D
" \n\t"
1864 "dec %%"REG_c
" \n\t"
1867 : "+S"(workspace
), "+D"(output_adr
), "+c"(cnt
), "=o"(temps
)
1868 : "a"(output_stride
*sizeof(short))
1877 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1879 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
1880 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
1881 int_simd16_t z1
, z2
, z3
, z4
, z5
, z11
, z13
;
1885 // Pass 1: process rows.
1888 for (; cnt
> 0; cnt
--) {
1889 tmp0
= pixels
[line_size
*0] + pixels
[line_size
*7];
1890 tmp7
= pixels
[line_size
*0] - pixels
[line_size
*7];
1891 tmp1
= pixels
[line_size
*1] + pixels
[line_size
*6];
1892 tmp6
= pixels
[line_size
*1] - pixels
[line_size
*6];
1893 tmp2
= pixels
[line_size
*2] + pixels
[line_size
*5];
1894 tmp5
= pixels
[line_size
*2] - pixels
[line_size
*5];
1895 tmp3
= pixels
[line_size
*3] + pixels
[line_size
*4];
1896 tmp4
= pixels
[line_size
*3] - pixels
[line_size
*4];
1900 tmp10
= tmp0
+ tmp3
;
1901 tmp13
= tmp0
- tmp3
;
1902 tmp11
= tmp1
+ tmp2
;
1903 tmp12
= tmp1
- tmp2
;
1904 //Even columns are written first, this leads to different order of columns
1905 //in column_fidct(), but they are processed independently, so all ok.
1906 //Later in the row_idct() columns readed at the same order.
1907 dataptr
[2] = tmp10
+ tmp11
;
1908 dataptr
[3] = tmp10
- tmp11
;
1910 z1
= MULTIPLY16H((tmp12
+ tmp13
)<<2, FIX_0_707106781
);
1911 dataptr
[0] = tmp13
+ z1
;
1912 dataptr
[1] = tmp13
- z1
;
1916 tmp10
= (tmp4
+ tmp5
) <<2;
1917 tmp11
= (tmp5
+ tmp6
) <<2;
1918 tmp12
= (tmp6
+ tmp7
) <<2;
1920 z5
= MULTIPLY16H(tmp10
- tmp12
, FIX_0_382683433
);
1921 z2
= MULTIPLY16H(tmp10
, FIX_0_541196100
) + z5
;
1922 z4
= MULTIPLY16H(tmp12
, FIX_1_306562965
) + z5
;
1923 z3
= MULTIPLY16H(tmp11
, FIX_0_707106781
);
1928 dataptr
[4] = z13
+ z2
;
1929 dataptr
[5] = z13
- z2
;
1930 dataptr
[6] = z11
+ z4
;
1931 dataptr
[7] = z11
- z4
;
1933 pixels
++; // advance pointer to next column
1938 #else /* HAVE_MMX */
1940 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1942 uint64_t __attribute__((aligned(8))) temps
[4];
1944 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1946 "movd (%%"REG_S
"), %%mm0 \n\t"
1947 "pxor %%mm7, %%mm7 \n\t"
1949 "movd (%%"REG_S
",%%"REG_a
",), %%mm1 \n\t"
1950 "punpcklbw %%mm7, %%mm0 \n\t"
1952 "movd (%%"REG_S
",%%"REG_a
",2), %%mm2 \n\t"
1953 "punpcklbw %%mm7, %%mm1 \n\t"
1955 "punpcklbw %%mm7, %%mm2 \n\t"
1956 "add %%"REG_d
", %%"REG_S
" \n\t"
1958 "movq %%mm0, %%mm5 \n\t"
1961 "movd (%%"REG_S
",%%"REG_a
",4), %%mm3 \n\t" //7 ;prefetch!
1962 "movq %%mm1, %%mm6 \n\t"
1964 "movd (%%"REG_S
",%%"REG_d
",), %%mm4 \n\t" //6
1965 "punpcklbw %%mm7, %%mm3 \n\t"
1967 "psubw %%mm3, %%mm5 \n\t"
1968 "punpcklbw %%mm7, %%mm4 \n\t"
1970 "paddw %%mm3, %%mm0 \n\t"
1971 "psubw %%mm4, %%mm6 \n\t"
1973 "movd (%%"REG_S
",%%"REG_a
",2), %%mm3 \n\t" //5
1974 "paddw %%mm4, %%mm1 \n\t"
1976 "movq %%mm5, 0*8+%3 \n\t" //t7
1977 "punpcklbw %%mm7, %%mm3 \n\t"
1979 "movq %%mm6, 1*8+%3 \n\t" //t6
1980 "movq %%mm2, %%mm4 \n\t"
1982 "movd (%%"REG_S
"), %%mm5 \n\t" //3
1983 "paddw %%mm3, %%mm2 \n\t"
1985 "movd (%%"REG_S
",%%"REG_a
",), %%mm6 \n\t" //4
1986 "punpcklbw %%mm7, %%mm5 \n\t"
1988 "psubw %%mm3, %%mm4 \n\t"
1989 "punpcklbw %%mm7, %%mm6 \n\t"
1991 "movq %%mm5, %%mm3 \n\t"
1992 "paddw %%mm6, %%mm5 \n\t" //t3
1994 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1995 "movq %%mm0, %%mm6 \n\t"
1997 "movq %%mm1, %%mm7 \n\t"
1998 "psubw %%mm5, %%mm0 \n\t" //t13
2000 "psubw %%mm2, %%mm1 \n\t"
2001 "paddw %%mm2, %%mm7 \n\t" //t11
2003 "paddw %%mm0, %%mm1 \n\t"
2004 "movq %%mm7, %%mm2 \n\t"
2006 "psllw $2, %%mm1 \n\t"
2007 "paddw %%mm5, %%mm6 \n\t" //t10
2009 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm1 \n\t"
2010 "paddw %%mm6, %%mm7 \n\t" //d2
2012 "psubw %%mm2, %%mm6 \n\t" //d3
2013 "movq %%mm0, %%mm5 \n\t"
2016 "movq %%mm7, %%mm2 \n\t"
2017 "punpcklwd %%mm6, %%mm7 \n\t"
2019 "paddw %%mm1, %%mm0 \n\t" //d0
2020 "punpckhwd %%mm6, %%mm2 \n\t"
2022 "psubw %%mm1, %%mm5 \n\t" //d1
2023 "movq %%mm0, %%mm6 \n\t"
2025 "movq 1*8+%3, %%mm1 \n\t"
2026 "punpcklwd %%mm5, %%mm0 \n\t"
2028 "punpckhwd %%mm5, %%mm6 \n\t"
2029 "movq %%mm0, %%mm5 \n\t"
2031 "punpckldq %%mm7, %%mm0 \n\t" //0
2032 "paddw %%mm4, %%mm3 \n\t"
2034 "punpckhdq %%mm7, %%mm5 \n\t" //1
2035 "movq %%mm6, %%mm7 \n\t"
2037 "movq %%mm0, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
2038 "punpckldq %%mm2, %%mm6 \n\t" //2
2040 "movq %%mm5, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
2041 "punpckhdq %%mm2, %%mm7 \n\t" //3
2043 "movq %%mm6, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
2044 "paddw %%mm1, %%mm4 \n\t"
2046 "movq %%mm7, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
2047 "psllw $2, %%mm3 \n\t" //t10
2049 "movq 0*8+%3, %%mm2 \n\t"
2050 "psllw $2, %%mm4 \n\t" //t11
2052 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm4 \n\t" //z3
2053 "paddw %%mm2, %%mm1 \n\t"
2055 "psllw $2, %%mm1 \n\t" //t12
2056 "movq %%mm3, %%mm0 \n\t"
2058 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm0 \n\t"
2059 "psubw %%mm1, %%mm3 \n\t"
2061 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t" //z5
2062 "movq %%mm2, %%mm5 \n\t"
2064 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm1 \n\t"
2065 "psubw %%mm4, %%mm2 \n\t" //z13
2067 "paddw %%mm4, %%mm5 \n\t" //z11
2068 "movq %%mm2, %%mm6 \n\t"
2070 "paddw %%mm3, %%mm0 \n\t" //z2
2071 "movq %%mm5, %%mm7 \n\t"
2073 "paddw %%mm0, %%mm2 \n\t" //d4
2074 "psubw %%mm0, %%mm6 \n\t" //d5
2076 "movq %%mm2, %%mm4 \n\t"
2077 "paddw %%mm3, %%mm1 \n\t" //z4
2080 "punpcklwd %%mm6, %%mm2 \n\t"
2081 "paddw %%mm1, %%mm5 \n\t" //d6
2083 "punpckhwd %%mm6, %%mm4 \n\t"
2084 "psubw %%mm1, %%mm7 \n\t" //d7
2086 "movq %%mm5, %%mm6 \n\t"
2087 "punpcklwd %%mm7, %%mm5 \n\t"
2089 "punpckhwd %%mm7, %%mm6 \n\t"
2090 "movq %%mm2, %%mm7 \n\t"
2092 "punpckldq %%mm5, %%mm2 \n\t" //4
2093 "sub %%"REG_d
", %%"REG_S
" \n\t"
2095 "punpckhdq %%mm5, %%mm7 \n\t" //5
2096 "movq %%mm4, %%mm5 \n\t"
2098 "movq %%mm2, "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2099 "punpckldq %%mm6, %%mm4 \n\t" //6
2101 "movq %%mm7, "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2102 "punpckhdq %%mm6, %%mm5 \n\t" //7
2104 "movq %%mm4, "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2105 "add $4, %%"REG_S
" \n\t"
2107 "movq %%mm5, "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2108 "add $"DCTSIZE_S
"*2*4, %%"REG_D
" \n\t" //4 rows
2109 "dec %%"REG_c
" \n\t"
2112 : "+S"(pixels
), "+D"(data
), "+c"(cnt
), "=o"(temps
)