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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
44 #include "cpudetect.h"
46 #ifdef USE_LIBAVCODEC_SO
47 #include <ffmpeg/avcodec.h>
48 #include <ffmpeg/dsputil.h>
50 #include "libavcodec/avcodec.h"
51 #include "libavcodec/dsputil.h"
58 #include "img_format.h"
61 #include "libvo/fastmemcpy.h"
63 //===========================================================================//
66 static const short custom_threshold
[64]=
67 // values (296) can't be too high
68 // -it causes too big quant dependence
69 // or maybe overflow(check), which results in some flashing
70 { 71, 296, 295, 237, 71, 40, 38, 19,
71 245, 193, 185, 121, 102, 73, 53, 27,
72 158, 129, 141, 107, 97, 73, 50, 26,
73 102, 116, 109, 98, 82, 66, 45, 23,
74 71, 94, 95, 81, 70, 56, 38, 20,
75 56, 77, 74, 66, 56, 44, 30, 15,
76 38, 53, 50, 45, 38, 30, 21, 11,
77 20, 27, 26, 23, 20, 15, 11, 5
80 static const uint8_t __attribute__((aligned(32))) dither
[8][8]={
81 { 0, 48, 12, 60, 3, 51, 15, 63, },
82 { 32, 16, 44, 28, 35, 19, 47, 31, },
83 { 8, 56, 4, 52, 11, 59, 7, 55, },
84 { 40, 24, 36, 20, 43, 27, 39, 23, },
85 { 2, 50, 14, 62, 1, 49, 13, 61, },
86 { 34, 18, 46, 30, 33, 17, 45, 29, },
87 { 10, 58, 6, 54, 9, 57, 5, 53, },
88 { 42, 26, 38, 22, 41, 25, 37, 21, },
91 struct vf_priv_s
{ //align 16 !
92 uint64_t threshold_mtx_noq
[8*2];
93 uint64_t threshold_mtx
[8*2];//used in both C & MMX (& later SSE2) versions
108 //This func reads from 1 slice, 1 and clears 0 & 1
109 static void store_slice_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
112 temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
113 src[x + pos]=src[x + pos - 8*src_stride]=0; \
114 if(temp & 0x100) temp= ~(temp>>31); \
117 for(y
=0; y
<height
; y
++){
118 const uint8_t *d
= dither
[y
];
119 for(x
=0; x
<width
; x
+=8){
135 //This func reads from 2 slices, 0 & 2 and clears 2-nd
136 static void store_slice2_c(uint8_t *dst
, int16_t *src
, int dst_stride
, int src_stride
, int width
, int height
, int log2_scale
)
138 #define STORE2(pos) \
139 temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
140 src[x + pos + 16*src_stride]=0; \
141 if(temp & 0x100) temp= ~(temp>>31); \
144 for(y
=0; y
<height
; y
++){
145 const uint8_t *d
= dither
[y
];
146 for(x
=0; x
<width
; x
+=8){
162 static void mul_thrmat_c(struct vf_priv_s
*p
,int q
)
166 ((short*)p
->threshold_mtx
)[a
]=q
* ((short*)p
->threshold_mtx_noq
)[a
];//ints faster in C
169 static void column_fidct_c(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
170 static void row_idct_c(DCTELEM
* workspace
,
171 int16_t* output_adr
, int output_stride
, int cnt
);
172 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
174 //this is rather ugly, but there is no need for function pointers
175 #define store_slice_s store_slice_c
176 #define store_slice2_s store_slice2_c
177 #define mul_thrmat_s mul_thrmat_c
178 #define column_fidct_s column_fidct_c
179 #define row_idct_s row_idct_c
180 #define row_fdct_s row_fdct_c
184 //This func reads from 1 slice, 1 and clears 0 & 1
185 static void store_slice_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
187 const uint8_t *od
=&dither
[0][0];
188 const uint8_t *end
=&dither
[height
][0];
189 width
= (width
+7)&~7;
191 //src_stride=(src_stride-width)*2;
193 "mov %5, %%"REG_d
" \n\t"
194 "mov %6, %%"REG_S
" \n\t"
195 "mov %7, %%"REG_D
" \n\t"
196 "mov %1, %%"REG_a
" \n\t"
197 "movd %%"REG_d
", %%mm5 \n\t"
198 "xor $-1, %%"REG_d
" \n\t"
199 "mov %%"REG_a
", %%"REG_c
" \n\t"
200 "add $7, %%"REG_d
" \n\t"
202 "sub %0, %%"REG_c
" \n\t"
203 "add %%"REG_c
", %%"REG_c
" \n\t"
204 "movd %%"REG_d
", %%mm2 \n\t"
205 "mov %%"REG_c
", %1 \n\t"
206 "mov %2, %%"REG_d
" \n\t"
207 "shl $4, %%"REG_a
" \n\t"
210 "movq (%%"REG_d
"), %%mm3 \n\t"
211 "movq %%mm3, %%mm4 \n\t"
212 "pxor %%mm7, %%mm7 \n\t"
213 "punpcklbw %%mm7, %%mm3 \n\t"
214 "punpckhbw %%mm7, %%mm4 \n\t"
215 "mov %0, %%"REG_c
" \n\t"
216 "psraw %%mm5, %%mm3 \n\t"
217 "psraw %%mm5, %%mm4 \n\t"
219 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
220 "movq (%%"REG_S
"), %%mm0 \n\t"
221 "movq 8(%%"REG_S
"), %%mm1 \n\t"
223 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
224 "paddw %%mm3, %%mm0 \n\t"
225 "paddw %%mm4, %%mm1 \n\t"
227 "movq %%mm7, (%%"REG_S
") \n\t"
228 "psraw %%mm2, %%mm0 \n\t"
229 "psraw %%mm2, %%mm1 \n\t"
231 "movq %%mm7, 8(%%"REG_S
") \n\t"
232 "packuswb %%mm1, %%mm0 \n\t"
233 "add $16, %%"REG_S
" \n\t"
235 "movq %%mm0, (%%"REG_D
") \n\t"
236 "add $8, %%"REG_D
" \n\t"
237 "sub $8, %%"REG_c
" \n\t"
239 "add %1, %%"REG_S
" \n\t"
240 "add $8, %%"REG_d
" \n\t"
241 "add %3, %%"REG_D
" \n\t"
242 "cmp %4, %%"REG_d
" \n\t"
246 : "m" (width
), "m" (src_stride
), "g" (od
), "m" (dst_stride
), "g" (end
),
247 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
248 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_S
, "%"REG_D
252 //This func reads from 2 slices, 0 & 2 and clears 2-nd
253 static void store_slice2_mmx(uint8_t *dst
, int16_t *src
, long dst_stride
, long src_stride
, long width
, long height
, long log2_scale
)
255 const uint8_t *od
=&dither
[0][0];
256 const uint8_t *end
=&dither
[height
][0];
257 width
= (width
+7)&~7;
259 //src_stride=(src_stride-width)*2;
261 "mov %5, %%"REG_d
" \n\t"
262 "mov %6, %%"REG_S
" \n\t"
263 "mov %7, %%"REG_D
" \n\t"
264 "mov %1, %%"REG_a
" \n\t"
265 "movd %%"REG_d
", %%mm5 \n\t"
266 "xor $-1, %%"REG_d
" \n\t"
267 "mov %%"REG_a
", %%"REG_c
" \n\t"
268 "add $7, %%"REG_d
" \n\t"
269 "sub %0, %%"REG_c
" \n\t"
270 "add %%"REG_c
", %%"REG_c
" \n\t"
271 "movd %%"REG_d
", %%mm2 \n\t"
272 "mov %%"REG_c
", %1 \n\t"
273 "mov %2, %%"REG_d
" \n\t"
274 "shl $5, %%"REG_a
" \n\t"
277 "movq (%%"REG_d
"), %%mm3 \n\t"
278 "movq %%mm3, %%mm4 \n\t"
279 "pxor %%mm7, %%mm7 \n\t"
280 "punpcklbw %%mm7, %%mm3 \n\t"
281 "punpckhbw %%mm7, %%mm4 \n\t"
282 "mov %0, %%"REG_c
" \n\t"
283 "psraw %%mm5, %%mm3 \n\t"
284 "psraw %%mm5, %%mm4 \n\t"
286 "movq (%%"REG_S
"), %%mm0 \n\t"
287 "movq 8(%%"REG_S
"), %%mm1 \n\t"
288 "paddw %%mm3, %%mm0 \n\t"
290 "paddw (%%"REG_S
",%%"REG_a
",), %%mm0 \n\t"
291 "paddw %%mm4, %%mm1 \n\t"
292 "movq 8(%%"REG_S
",%%"REG_a
",), %%mm6 \n\t"
294 "movq %%mm7, (%%"REG_S
",%%"REG_a
",) \n\t"
295 "psraw %%mm2, %%mm0 \n\t"
296 "paddw %%mm6, %%mm1 \n\t"
298 "movq %%mm7, 8(%%"REG_S
",%%"REG_a
",) \n\t"
299 "psraw %%mm2, %%mm1 \n\t"
300 "packuswb %%mm1, %%mm0 \n\t"
302 "movq %%mm0, (%%"REG_D
") \n\t"
303 "add $16, %%"REG_S
" \n\t"
304 "add $8, %%"REG_D
" \n\t"
305 "sub $8, %%"REG_c
" \n\t"
307 "add %1, %%"REG_S
" \n\t"
308 "add $8, %%"REG_d
" \n\t"
309 "add %3, %%"REG_D
" \n\t"
310 "cmp %4, %%"REG_d
" \n\t"
314 : "m" (width
), "m" (src_stride
), "g" (od
), "m" (dst_stride
), "g" (end
),
315 "m" (log2_scale
), "m" (src
), "m" (dst
) //input
316 : "%"REG_a
, "%"REG_c
, "%"REG_d
, "%"REG_D
, "%"REG_S
320 static void mul_thrmat_mmx(struct vf_priv_s
*p
, int q
)
322 uint64_t *adr
=&p
->threshold_mtx_noq
[0];
324 "movd %0, %%mm7 \n\t"
325 "add $8*8*2, %%"REG_D
" \n\t"
326 "movq 0*8(%%"REG_S
"), %%mm0 \n\t"
327 "punpcklwd %%mm7, %%mm7 \n\t"
328 "movq 1*8(%%"REG_S
"), %%mm1 \n\t"
329 "punpckldq %%mm7, %%mm7 \n\t"
330 "pmullw %%mm7, %%mm0 \n\t"
332 "movq 2*8(%%"REG_S
"), %%mm2 \n\t"
333 "pmullw %%mm7, %%mm1 \n\t"
335 "movq 3*8(%%"REG_S
"), %%mm3 \n\t"
336 "pmullw %%mm7, %%mm2 \n\t"
338 "movq %%mm0, 0*8(%%"REG_D
") \n\t"
339 "movq 4*8(%%"REG_S
"), %%mm4 \n\t"
340 "pmullw %%mm7, %%mm3 \n\t"
342 "movq %%mm1, 1*8(%%"REG_D
") \n\t"
343 "movq 5*8(%%"REG_S
"), %%mm5 \n\t"
344 "pmullw %%mm7, %%mm4 \n\t"
346 "movq %%mm2, 2*8(%%"REG_D
") \n\t"
347 "movq 6*8(%%"REG_S
"), %%mm6 \n\t"
348 "pmullw %%mm7, %%mm5 \n\t"
350 "movq %%mm3, 3*8(%%"REG_D
") \n\t"
351 "movq 7*8+0*8(%%"REG_S
"), %%mm0 \n\t"
352 "pmullw %%mm7, %%mm6 \n\t"
354 "movq %%mm4, 4*8(%%"REG_D
") \n\t"
355 "movq 7*8+1*8(%%"REG_S
"), %%mm1 \n\t"
356 "pmullw %%mm7, %%mm0 \n\t"
358 "movq %%mm5, 5*8(%%"REG_D
") \n\t"
359 "movq 7*8+2*8(%%"REG_S
"), %%mm2 \n\t"
360 "pmullw %%mm7, %%mm1 \n\t"
362 "movq %%mm6, 6*8(%%"REG_D
") \n\t"
363 "movq 7*8+3*8(%%"REG_S
"), %%mm3 \n\t"
364 "pmullw %%mm7, %%mm2 \n\t"
366 "movq %%mm0, 7*8+0*8(%%"REG_D
") \n\t"
367 "movq 7*8+4*8(%%"REG_S
"), %%mm4 \n\t"
368 "pmullw %%mm7, %%mm3 \n\t"
370 "movq %%mm1, 7*8+1*8(%%"REG_D
") \n\t"
371 "movq 7*8+5*8(%%"REG_S
"), %%mm5 \n\t"
372 "pmullw %%mm7, %%mm4 \n\t"
374 "movq %%mm2, 7*8+2*8(%%"REG_D
") \n\t"
375 "movq 7*8+6*8(%%"REG_S
"), %%mm6 \n\t"
376 "pmullw %%mm7, %%mm5 \n\t"
378 "movq %%mm3, 7*8+3*8(%%"REG_D
") \n\t"
379 "movq 14*8+0*8(%%"REG_S
"), %%mm0 \n\t"
380 "pmullw %%mm7, %%mm6 \n\t"
382 "movq %%mm4, 7*8+4*8(%%"REG_D
") \n\t"
383 "movq 14*8+1*8(%%"REG_S
"), %%mm1 \n\t"
384 "pmullw %%mm7, %%mm0 \n\t"
386 "movq %%mm5, 7*8+5*8(%%"REG_D
") \n\t"
387 "pmullw %%mm7, %%mm1 \n\t"
389 "movq %%mm6, 7*8+6*8(%%"REG_D
") \n\t"
390 "movq %%mm0, 14*8+0*8(%%"REG_D
") \n\t"
391 "movq %%mm1, 14*8+1*8(%%"REG_D
") \n\t"
393 : "+g" (q
), "+S" (adr
), "+D" (adr
)
398 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
);
399 static void row_idct_mmx(DCTELEM
* workspace
,
400 int16_t* output_adr
, int output_stride
, int cnt
);
401 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
);
403 #define store_slice_s store_slice_mmx
404 #define store_slice2_s store_slice2_mmx
405 #define mul_thrmat_s mul_thrmat_mmx
406 #define column_fidct_s column_fidct_mmx
407 #define row_idct_s row_idct_mmx
408 #define row_fdct_s row_fdct_mmx
411 static void filter(struct vf_priv_s
*p
, uint8_t *dst
, uint8_t *src
,
412 int dst_stride
, int src_stride
,
413 int width
, int height
,
414 uint8_t *qp_store
, int qp_stride
, int is_luma
)
416 int x
, x0
, y
, es
, qy
, t
;
417 const int stride
= is_luma
? p
->temp_stride
: (width
+16);//((width+16+15)&(~15))
418 const int step
=6-p
->log2_count
;
419 const int qps
= 3 + is_luma
;
420 int32_t __attribute__((aligned(32))) block_align
[4*8*BLOCKSZ
+ 4*8*BLOCKSZ
];
421 DCTELEM
*block
= (DCTELEM
*)block_align
;
422 DCTELEM
*block3
=(DCTELEM
*)(block_align
+4*8*BLOCKSZ
);
424 memset(block3
, 0, 4*8*BLOCKSZ
);
426 //p->src=src-src_stride*8-8;//!
427 if (!src
|| !dst
) return; // HACK avoid crash for Y8 colourspace
428 for(y
=0; y
<height
; y
++){
429 int index
= 8 + 8*stride
+ y
*stride
;
430 memcpy(p
->src
+ index
, src
+ y
*src_stride
, width
);//this line can be avoided by using DR & user fr.buffers
432 p
->src
[index
- x
- 1]= p
->src
[index
+ x
];
433 p
->src
[index
+ width
+ x
]= p
->src
[index
+ width
- x
- 1];
437 memcpy(p
->src
+ ( 7-y
)*stride
, p
->src
+ ( y
+8)*stride
, stride
);
438 memcpy(p
->src
+ (height
+8+y
)*stride
, p
->src
+ (height
-y
+7)*stride
, stride
);
440 //FIXME (try edge emu)
443 memset(p
->temp
+ 8 +y
*stride
, 0,width
*sizeof(int16_t));
445 for(y
=step
; y
<height
+8; y
+=step
){ //step= 1,2
447 if (qy
>height
-1) qy
=height
-1;
449 qy
=(qy
>>qps
)*qp_stride
;
450 row_fdct_s(block
, p
->src
+ y
*stride
+2-(y
&1), stride
, 2);
451 for(x0
=0; x0
<width
+8-8*(BLOCKSZ
-1); x0
+=8*(BLOCKSZ
-1)){
452 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
454 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+0*8, block3
+0*8, 8*(BLOCKSZ
-1)); //yes, this is a HOTSPOT
456 for (x
=0; x
<8*(BLOCKSZ
-1); x
+=8) {
457 t
=x
+x0
-2; //correct t=x+x0-2-(y&1), but its the same
458 if (t
<0) t
=0;//t always < width-2
459 t
=qp_store
[qy
+(t
>>qps
)];
460 if(p
->mpeg2
) t
>>=1; //copy p->mpeg2,prev_q to locals?
461 if (t
!=p
->prev_q
) p
->prev_q
=t
, mul_thrmat_s(p
, t
);
462 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
+x
*8, block3
+x
*8, 8); //yes, this is a HOTSPOT
464 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, 2*(BLOCKSZ
-1));
465 memcpy(block
, block
+(BLOCKSZ
-1)*64, 8*8*sizeof(DCTELEM
)); //cycling
466 memcpy(block3
, block3
+(BLOCKSZ
-1)*64, 6*8*sizeof(DCTELEM
));
469 es
=width
+8-x0
; // 8, ...
471 row_fdct_s(block
+8*8, p
->src
+ y
*stride
+8+x0
+2-(y
&1), stride
, (es
-4)>>2);
472 column_fidct_s((int16_t*)(&p
->threshold_mtx
[0]), block
, block3
, es
-0);
473 row_idct_s(block3
+0*8, p
->temp
+ (y
&15)*stride
+x0
+2-(y
&1), stride
, es
>>2);
474 {const int y1
=y
-8+step
;//l5-7 l4-6
476 if (y1
&8) store_slice_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +8*stride
,
477 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
478 else store_slice2_s(dst
+ (y1
-8)*dst_stride
, p
->temp
+ 8 +0*stride
,
479 dst_stride
, stride
, width
, 8, 5-p
->log2_count
);
483 if (y
&7) { // == height & 7
484 if (y
&8) store_slice_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +8*stride
,
485 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
486 else store_slice2_s(dst
+ ((y
-8)&~7)*dst_stride
, p
->temp
+ 8 +0*stride
,
487 dst_stride
, stride
, width
, y
&7, 5-p
->log2_count
);
491 static int config(struct vf_instance_s
* vf
,
492 int width
, int height
, int d_width
, int d_height
,
493 unsigned int flags
, unsigned int outfmt
)
495 int h
= (height
+16+15)&(~15);
497 vf
->priv
->temp_stride
= (width
+16+15)&(~15);
498 vf
->priv
->temp
= (int16_t*)av_mallocz(vf
->priv
->temp_stride
*3*8*sizeof(int16_t));
499 //this can also be avoided, see above
500 vf
->priv
->src
= (uint8_t*)av_malloc(vf
->priv
->temp_stride
*h
*sizeof(uint8_t));
502 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
505 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
)
507 if(mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
508 // ok, we can do pp in-place (or pp disabled):
509 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
510 mpi
->type
, mpi
->flags
, mpi
->width
, mpi
->height
);
511 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
512 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
513 mpi
->width
=vf
->dmpi
->width
;
514 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
515 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
516 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
517 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
518 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
520 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
523 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
)
526 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
527 // no DR, so get a new image! hope we'll get DR buffer:
528 dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
530 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
531 mpi
->width
,mpi
->height
);
532 vf_clone_mpi_attributes(dmpi
, mpi
);
537 vf
->priv
->mpeg2
= mpi
->qscale_type
;
538 if(vf
->priv
->log2_count
|| !(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
539 if(mpi
->qscale
|| vf
->priv
->qp
){
540 filter(vf
->priv
, dmpi
->planes
[0], mpi
->planes
[0], dmpi
->stride
[0], mpi
->stride
[0], mpi
->w
, mpi
->h
, mpi
->qscale
, mpi
->qstride
, 1);
541 filter(vf
->priv
, dmpi
->planes
[1], mpi
->planes
[1], dmpi
->stride
[1], mpi
->stride
[1], mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, mpi
->qscale
, mpi
->qstride
, 0);
542 filter(vf
->priv
, dmpi
->planes
[2], mpi
->planes
[2], dmpi
->stride
[2], mpi
->stride
[2], mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
, mpi
->qscale
, mpi
->qstride
, 0);
544 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
, dmpi
->stride
[0], mpi
->stride
[0]);
545 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]);
546 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]);
551 if(gCpuCaps
.hasMMX
) asm volatile ("emms\n\t");
554 if(gCpuCaps
.hasMMX2
) asm volatile ("sfence\n\t");
556 return vf_next_put_image(vf
,dmpi
);
559 static void uninit(struct vf_instance_s
* vf
)
561 if(!vf
->priv
) return;
563 if(vf
->priv
->temp
) av_free(vf
->priv
->temp
);
564 vf
->priv
->temp
= NULL
;
565 if(vf
->priv
->src
) av_free(vf
->priv
->src
);
567 //if(vf->priv->avctx) free(vf->priv->avctx);
568 //vf->priv->avctx= NULL;
574 //===========================================================================//
576 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
590 return vf_next_query_format(vf
,fmt
);
596 static unsigned int fmt_list[]={
612 static int control(struct vf_instance_s
* vf
, int request
, void* data
)
615 case VFCTRL_QUERY_MAX_PP_LEVEL
:
617 case VFCTRL_SET_PP_LEVEL
:
618 vf
->priv
->log2_count
= *((unsigned int*)data
);
619 if (vf
->priv
->log2_count
< 4) vf
->priv
->log2_count
=4;
622 return vf_next_control(vf
,request
,data
);
625 static int open(vf_instance_t
*vf
, char* args
)
628 int custom_threshold_m
[64];
632 vf
->put_image
=put_image
;
633 vf
->get_image
=get_image
;
634 vf
->query_format
=query_format
;
636 vf
->control
= control
;
637 vf
->priv
=av_mallocz(sizeof(struct vf_priv_s
));//assumes align 16 !
641 //vf->priv->avctx= avcodec_alloc_context();
642 //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
644 vf
->priv
->log2_count
= 4;
646 if (args
) sscanf(args
, "%d:%d:%d", &log2c
, &vf
->priv
->qp
, &i
);
648 if( log2c
>=4 && log2c
<=5 )
649 vf
->priv
->log2_count
= log2c
;
650 else if( log2c
>= 6 )
651 vf
->priv
->log2_count
= 5;
656 if (i
< -15) i
= -15;
659 bias
= (1<<4)+i
; //regulable
662 for(i
=0;i
<64;i
++) //FIXME: tune custom_threshold[] and remove this !
663 custom_threshold_m
[i
]=(int)(custom_threshold
[i
]*(bias
/71.)+ 0.5);
665 vf
->priv
->threshold_mtx_noq
[2*i
]=(uint64_t)custom_threshold_m
[i
*8+2]
666 |(((uint64_t)custom_threshold_m
[i
*8+6])<<16)
667 |(((uint64_t)custom_threshold_m
[i
*8+0])<<32)
668 |(((uint64_t)custom_threshold_m
[i
*8+4])<<48);
669 vf
->priv
->threshold_mtx_noq
[2*i
+1]=(uint64_t)custom_threshold_m
[i
*8+5]
670 |(((uint64_t)custom_threshold_m
[i
*8+3])<<16)
671 |(((uint64_t)custom_threshold_m
[i
*8+1])<<32)
672 |(((uint64_t)custom_threshold_m
[i
*8+7])<<48);
675 if (vf
->priv
->qp
) vf
->priv
->prev_q
=vf
->priv
->qp
, mul_thrmat_s(vf
->priv
, vf
->priv
->qp
);
680 vf_info_t vf_info_fspp
= {
681 "fast simple postprocess",
683 "Michael Niedermayer, Nikolaj Poroshin",
689 //====================================================================
690 //Specific spp's dct, idct and threshold functions
691 //I'd prefer to have them in the separate file.
694 //#define MANGLE(a) #a
696 //typedef int16_t DCTELEM; //! only int16_t
699 #define DCTSIZE_S "8"
701 #define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
702 #define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
703 #define FIX64(x,s) C64(FIX(x,s))
705 #define MULTIPLY16H(x,k) (((x)*(k))>>16)
706 #define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
707 #define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
711 static uint64_t attribute_used
__attribute__((aligned(8))) temps
[4];//!!
713 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_382683433
=FIX64(0.382683433, 14);
714 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_541196100
=FIX64(0.541196100, 14);
715 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_707106781
=FIX64(0.707106781, 14);
716 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_306562965
=FIX64(1.306562965, 14);
718 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_414213562_A
=FIX64(1.414213562, 14);
720 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_847759065
=FIX64(1.847759065, 13);
721 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_2_613125930
=FIX64(-2.613125930, 13); //-
722 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_414213562
=FIX64(1.414213562, 13);
723 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_1_082392200
=FIX64(1.082392200, 13);
724 //for t3,t5,t7 == 0 shortcut
725 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_847759065
=FIX64(0.847759065, 14);
726 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_566454497
=FIX64(0.566454497, 14);
727 static uint64_t attribute_used
__attribute__((aligned(8))) MM_FIX_0_198912367
=FIX64(0.198912367, 14);
729 static uint64_t attribute_used
__attribute__((aligned(8))) MM_DESCALE_RND
=C64(4);
730 static uint64_t attribute_used
__attribute__((aligned(8))) MM_2
=C64(2);
732 #else /* !HAVE_MMX */
734 typedef int32_t int_simd16_t
;
735 static int16_t FIX_0_382683433
=FIX(0.382683433, 14);
736 static int16_t FIX_0_541196100
=FIX(0.541196100, 14);
737 static int16_t FIX_0_707106781
=FIX(0.707106781, 14);
738 static int16_t FIX_1_306562965
=FIX(1.306562965, 14);
739 static int16_t FIX_1_414213562_A
=FIX(1.414213562, 14);
740 static int16_t FIX_1_847759065
=FIX(1.847759065, 13);
741 static int16_t FIX_2_613125930
=FIX(-2.613125930, 13); //-
742 static int16_t FIX_1_414213562
=FIX(1.414213562, 13);
743 static int16_t FIX_1_082392200
=FIX(1.082392200, 13);
749 static void column_fidct_c(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
)
751 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
752 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
753 int_simd16_t z1
,z2
,z3
,z4
,z5
, z10
, z11
, z12
, z13
;
754 int_simd16_t d0
, d1
, d2
, d3
, d4
, d5
, d6
, d7
;
764 for (; cnt
> 0; cnt
-=2) { //start positions
765 threshold
=(int16_t*)thr_adr
;//threshold_mtx
766 for (ctr
= DCTSIZE
; ctr
> 0; ctr
--) {
767 // Process columns from input, add to output.
768 tmp0
= dataptr
[DCTSIZE
*0] + dataptr
[DCTSIZE
*7];
769 tmp7
= dataptr
[DCTSIZE
*0] - dataptr
[DCTSIZE
*7];
771 tmp1
= dataptr
[DCTSIZE
*1] + dataptr
[DCTSIZE
*6];
772 tmp6
= dataptr
[DCTSIZE
*1] - dataptr
[DCTSIZE
*6];
774 tmp2
= dataptr
[DCTSIZE
*2] + dataptr
[DCTSIZE
*5];
775 tmp5
= dataptr
[DCTSIZE
*2] - dataptr
[DCTSIZE
*5];
777 tmp3
= dataptr
[DCTSIZE
*3] + dataptr
[DCTSIZE
*4];
778 tmp4
= dataptr
[DCTSIZE
*3] - dataptr
[DCTSIZE
*4];
790 z1
= MULTIPLY16H((tmp12
+ tmp13
) <<2, FIX_0_707106781
);
796 THRESHOLD(tmp0
, d0
, threshold
[0*8]);
797 THRESHOLD(tmp1
, d2
, threshold
[2*8]);
798 THRESHOLD(tmp2
, d4
, threshold
[4*8]);
799 THRESHOLD(tmp3
, d6
, threshold
[6*8]);
801 tmp10
= (tmp0
+ tmp2
)>>2;
802 tmp11
= (tmp0
- tmp2
)>>2;
804 tmp13
= (tmp1
+ tmp3
)>>2; //+2 ! (psnr decides)
805 tmp12
= MULTIPLY16H((tmp1
- tmp3
), FIX_1_414213562_A
) - tmp13
; //<<2
807 tmp0
= tmp10
+ tmp13
; //->temps
808 tmp3
= tmp10
- tmp13
; //->temps
809 tmp1
= tmp11
+ tmp12
; //->temps
810 tmp2
= tmp11
- tmp12
; //->temps
818 z5
= MULTIPLY16H((tmp10
- tmp12
)<<2, FIX_0_382683433
);
819 z2
= MULTIPLY16H(tmp10
<<2, FIX_0_541196100
) + z5
;
820 z4
= MULTIPLY16H(tmp12
<<2, FIX_1_306562965
) + z5
;
821 z3
= MULTIPLY16H(tmp11
<<2, FIX_0_707106781
);
833 THRESHOLD(tmp4
, d1
, threshold
[1*8]);
834 THRESHOLD(tmp5
, d3
, threshold
[3*8]);
835 THRESHOLD(tmp6
, d5
, threshold
[5*8]);
836 THRESHOLD(tmp7
, d7
, threshold
[7*8]);
838 //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
840 z10
= (tmp6
- tmp5
)<<1;
842 z12
= (tmp4
- tmp7
)<<1;
844 tmp7
= (z11
+ z13
)>>2; //+2 !
845 tmp11
= MULTIPLY16H((z11
- z13
)<<1, FIX_1_414213562
);
846 z5
= MULTIPLY16H(z10
+ z12
, FIX_1_847759065
);
847 tmp10
= MULTIPLY16H(z12
, FIX_1_082392200
) - z5
;
848 tmp12
= MULTIPLY16H(z10
, FIX_2_613125930
) + z5
; // - !!
854 wsptr
[DCTSIZE
*0]+= (tmp0
+ tmp7
);
855 wsptr
[DCTSIZE
*1]+= (tmp1
+ tmp6
);
856 wsptr
[DCTSIZE
*2]+= (tmp2
+ tmp5
);
857 wsptr
[DCTSIZE
*3]+= (tmp3
- tmp4
);
858 wsptr
[DCTSIZE
*4]+= (tmp3
+ tmp4
);
859 wsptr
[DCTSIZE
*5]+= (tmp2
- tmp5
);
860 wsptr
[DCTSIZE
*6]= (tmp1
- tmp6
);
861 wsptr
[DCTSIZE
*7]= (tmp0
- tmp7
);
863 dataptr
++; //next column
867 dataptr
+=8; //skip each second start pos
874 static void column_fidct_mmx(int16_t* thr_adr
, DCTELEM
*data
, DCTELEM
*output
, int cnt
)
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, "MANGLE(temps
)"+0*8 \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, "MANGLE(temps
)"+3*8 \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, "MANGLE(temps
)"+1*8 \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, "MANGLE(temps
)"+2*8 \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 "MANGLE(temps
)"+0*8, %%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 "MANGLE(temps
)"+1*8, %%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 "MANGLE(temps
)"+2*8, %%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 "MANGLE(temps
)"+3*8, %%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 "MANGLE(temps
)"+0*8, %%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 "MANGLE(temps
)"+1*8, %%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 "MANGLE(temps
)"+2*8, %%mm7 \n\t"
1194 "psubw %%mm5, %%mm0 \n\t" //'t10
1196 "movq "MANGLE(temps
)"+3*8, %%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, "MANGLE(temps
)"+0*8 \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, "MANGLE(temps
)"+3*8 \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, "MANGLE(temps
)"+1*8 \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, "MANGLE(temps
)"+2*8 \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 "MANGLE(temps
)"+0*8, %%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 "MANGLE(temps
)"+1*8, %%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 "MANGLE(temps
)"+2*8, %%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 "MANGLE(temps
)"+3*8, %%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 "MANGLE(temps
)"+0*8, %%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 "MANGLE(temps
)"+1*8, %%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 "MANGLE(temps
)"+2*8, %%mm7 \n\t"
1554 "psubw %%mm5, %%mm0 \n\t" //'t10
1556 "movq "MANGLE(temps
)"+3*8, %%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
)// input regs
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
)
1677 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1679 "movq "DCTSIZE_S
"*0*2(%%"REG_S
"), %%mm0 \n\t"
1682 "movq "DCTSIZE_S
"*1*2(%%"REG_S
"), %%mm1 \n\t"
1683 "movq %%mm0, %%mm4 \n\t"
1685 "movq "DCTSIZE_S
"*2*2(%%"REG_S
"), %%mm2 \n\t"
1686 "punpcklwd %%mm1, %%mm0 \n\t"
1688 "movq "DCTSIZE_S
"*3*2(%%"REG_S
"), %%mm3 \n\t"
1689 "punpckhwd %%mm1, %%mm4 \n\t"
1692 "movq %%mm2, %%mm7 \n\t"
1693 "punpcklwd %%mm3, %%mm2 \n\t"
1695 "movq %%mm0, %%mm6 \n\t"
1696 "punpckldq %%mm2, %%mm0 \n\t" //0
1698 "punpckhdq %%mm2, %%mm6 \n\t" //1
1699 "movq %%mm0, %%mm5 \n\t"
1701 "punpckhwd %%mm3, %%mm7 \n\t"
1702 "psubw %%mm6, %%mm0 \n\t"
1704 "pmulhw "MANGLE(MM_FIX_1_414213562_A
)", %%mm0 \n\t"
1705 "movq %%mm4, %%mm2 \n\t"
1707 "punpckldq %%mm7, %%mm4 \n\t" //2
1708 "paddw %%mm6, %%mm5 \n\t"
1710 "punpckhdq %%mm7, %%mm2 \n\t" //3
1711 "movq %%mm4, %%mm1 \n\t"
1713 "psllw $2, %%mm0 \n\t"
1714 "paddw %%mm2, %%mm4 \n\t" //t10
1716 "movq "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm3 \n\t"
1717 "psubw %%mm2, %%mm1 \n\t" //t11
1719 "movq "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm2 \n\t"
1720 "psubw %%mm5, %%mm0 \n\t"
1722 "movq %%mm4, %%mm6 \n\t"
1723 "paddw %%mm5, %%mm4 \n\t" //t0
1725 "psubw %%mm5, %%mm6 \n\t" //t3
1726 "movq %%mm1, %%mm7 \n\t"
1728 "movq "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm5 \n\t"
1729 "paddw %%mm0, %%mm1 \n\t" //t1
1731 "movq %%mm4, "MANGLE(temps
)"+0*8 \n\t" //t0
1732 "movq %%mm3, %%mm4 \n\t"
1734 "movq %%mm6, "MANGLE(temps
)"+1*8 \n\t" //t3
1735 "punpcklwd %%mm2, %%mm3 \n\t"
1738 "movq "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_S
"), %%mm6 \n\t"
1739 "punpckhwd %%mm2, %%mm4 \n\t"
1741 "movq %%mm5, %%mm2 \n\t"
1742 "punpcklwd %%mm6, %%mm5 \n\t"
1744 "psubw %%mm0, %%mm7 \n\t" //t2
1745 "punpckhwd %%mm6, %%mm2 \n\t"
1747 "movq %%mm3, %%mm0 \n\t"
1748 "punpckldq %%mm5, %%mm3 \n\t" //4
1750 "punpckhdq %%mm5, %%mm0 \n\t" //5
1751 "movq %%mm4, %%mm5 \n\t"
1754 "movq %%mm3, %%mm6 \n\t"
1755 "punpckldq %%mm2, %%mm4 \n\t" //6
1757 "psubw %%mm0, %%mm3 \n\t" //z10
1758 "punpckhdq %%mm2, %%mm5 \n\t" //7
1760 "paddw %%mm0, %%mm6 \n\t" //z13
1761 "movq %%mm4, %%mm2 \n\t"
1763 "movq %%mm3, %%mm0 \n\t"
1764 "psubw %%mm5, %%mm4 \n\t" //z12
1766 "pmulhw "MANGLE(MM_FIX_2_613125930
)", %%mm0 \n\t" //-
1767 "paddw %%mm4, %%mm3 \n\t"
1769 "pmulhw "MANGLE(MM_FIX_1_847759065
)", %%mm3 \n\t" //z5
1770 "paddw %%mm5, %%mm2 \n\t" //z11 >
1772 "pmulhw "MANGLE(MM_FIX_1_082392200
)", %%mm4 \n\t"
1773 "movq %%mm2, %%mm5 \n\t"
1775 "psubw %%mm6, %%mm2 \n\t"
1776 "paddw %%mm6, %%mm5 \n\t" //t7
1778 "pmulhw "MANGLE(MM_FIX_1_414213562
)", %%mm2 \n\t" //t11
1779 "paddw %%mm3, %%mm0 \n\t" //t12
1781 "psllw $3, %%mm0 \n\t"
1782 "psubw %%mm3, %%mm4 \n\t" //t10
1784 "movq "MANGLE(temps
)"+0*8, %%mm6 \n\t"
1785 "movq %%mm1, %%mm3 \n\t"
1787 "psllw $3, %%mm4 \n\t"
1788 "psubw %%mm5, %%mm0 \n\t" //t6
1790 "psllw $3, %%mm2 \n\t"
1791 "paddw %%mm0, %%mm1 \n\t" //d1
1793 "psubw %%mm0, %%mm2 \n\t" //t5
1794 "psubw %%mm0, %%mm3 \n\t" //d6
1796 "paddw %%mm2, %%mm4 \n\t" //t4
1797 "movq %%mm7, %%mm0 \n\t"
1799 "paddw %%mm2, %%mm7 \n\t" //d2
1800 "psubw %%mm2, %%mm0 \n\t" //d5
1802 "movq "MANGLE(MM_DESCALE_RND
)", %%mm2 \n\t" //4
1803 "psubw %%mm5, %%mm6 \n\t" //d7
1805 "paddw "MANGLE(temps
)"+0*8, %%mm5 \n\t" //d0
1806 "paddw %%mm2, %%mm1 \n\t"
1808 "paddw %%mm2, %%mm5 \n\t"
1809 "psraw $3, %%mm1 \n\t"
1811 "paddw %%mm2, %%mm7 \n\t"
1812 "psraw $3, %%mm5 \n\t"
1814 "paddw (%%"REG_D
"), %%mm5 \n\t"
1815 "psraw $3, %%mm7 \n\t"
1817 "paddw (%%"REG_D
",%%"REG_a
",), %%mm1 \n\t"
1818 "paddw %%mm2, %%mm0 \n\t"
1820 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm7 \n\t"
1821 "paddw %%mm2, %%mm3 \n\t"
1823 "movq %%mm5, (%%"REG_D
") \n\t"
1824 "paddw %%mm2, %%mm6 \n\t"
1826 "movq %%mm1, (%%"REG_D
",%%"REG_a
",) \n\t"
1827 "psraw $3, %%mm0 \n\t"
1829 "movq %%mm7, (%%"REG_D
",%%"REG_a
",2) \n\t"
1830 "add %%"REG_d
", %%"REG_D
" \n\t" //3*ls
1832 "movq "MANGLE(temps
)"+1*8, %%mm5 \n\t" //t3
1833 "psraw $3, %%mm3 \n\t"
1835 "paddw (%%"REG_D
",%%"REG_a
",2), %%mm0 \n\t"
1836 "psubw %%mm4, %%mm5 \n\t" //d3
1838 "paddw (%%"REG_D
",%%"REG_d
",), %%mm3 \n\t"
1839 "psraw $3, %%mm6 \n\t"
1841 "paddw "MANGLE(temps
)"+1*8, %%mm4 \n\t" //d4
1842 "paddw %%mm2, %%mm5 \n\t"
1844 "paddw (%%"REG_D
",%%"REG_a
",4), %%mm6 \n\t"
1845 "paddw %%mm2, %%mm4 \n\t"
1847 "movq %%mm0, (%%"REG_D
",%%"REG_a
",2) \n\t"
1848 "psraw $3, %%mm5 \n\t"
1850 "paddw (%%"REG_D
"), %%mm5 \n\t"
1851 "psraw $3, %%mm4 \n\t"
1853 "paddw (%%"REG_D
",%%"REG_a
",), %%mm4 \n\t"
1854 "add $"DCTSIZE_S
"*2*4, %%"REG_S
" \n\t" //4 rows
1856 "movq %%mm3, (%%"REG_D
",%%"REG_d
",) \n\t"
1857 "movq %%mm6, (%%"REG_D
",%%"REG_a
",4) \n\t"
1858 "movq %%mm5, (%%"REG_D
") \n\t"
1859 "movq %%mm4, (%%"REG_D
",%%"REG_a
",) \n\t"
1861 "sub %%"REG_d
", %%"REG_D
" \n\t"
1862 "add $8, %%"REG_D
" \n\t"
1863 "dec %%"REG_c
" \n\t"
1866 : "+S"(workspace
), "+D"(output_adr
), "+c"(cnt
) //input regs
1867 : "a"(output_stride
*sizeof(short))
1876 static void row_fdct_c(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1878 int_simd16_t tmp0
, tmp1
, tmp2
, tmp3
, tmp4
, tmp5
, tmp6
, tmp7
;
1879 int_simd16_t tmp10
, tmp11
, tmp12
, tmp13
;
1880 int_simd16_t z1
, z2
, z3
, z4
, z5
, z11
, z13
;
1884 // Pass 1: process rows.
1887 for (; cnt
> 0; cnt
--) {
1888 tmp0
= pixels
[line_size
*0] + pixels
[line_size
*7];
1889 tmp7
= pixels
[line_size
*0] - pixels
[line_size
*7];
1890 tmp1
= pixels
[line_size
*1] + pixels
[line_size
*6];
1891 tmp6
= pixels
[line_size
*1] - pixels
[line_size
*6];
1892 tmp2
= pixels
[line_size
*2] + pixels
[line_size
*5];
1893 tmp5
= pixels
[line_size
*2] - pixels
[line_size
*5];
1894 tmp3
= pixels
[line_size
*3] + pixels
[line_size
*4];
1895 tmp4
= pixels
[line_size
*3] - pixels
[line_size
*4];
1899 tmp10
= tmp0
+ tmp3
;
1900 tmp13
= tmp0
- tmp3
;
1901 tmp11
= tmp1
+ tmp2
;
1902 tmp12
= tmp1
- tmp2
;
1903 //Even columns are written first, this leads to different order of columns
1904 //in column_fidct(), but they are processed independently, so all ok.
1905 //Later in the row_idct() columns readed at the same order.
1906 dataptr
[2] = tmp10
+ tmp11
;
1907 dataptr
[3] = tmp10
- tmp11
;
1909 z1
= MULTIPLY16H((tmp12
+ tmp13
)<<2, FIX_0_707106781
);
1910 dataptr
[0] = tmp13
+ z1
;
1911 dataptr
[1] = tmp13
- z1
;
1915 tmp10
= (tmp4
+ tmp5
) <<2;
1916 tmp11
= (tmp5
+ tmp6
) <<2;
1917 tmp12
= (tmp6
+ tmp7
) <<2;
1919 z5
= MULTIPLY16H(tmp10
- tmp12
, FIX_0_382683433
);
1920 z2
= MULTIPLY16H(tmp10
, FIX_0_541196100
) + z5
;
1921 z4
= MULTIPLY16H(tmp12
, FIX_1_306562965
) + z5
;
1922 z3
= MULTIPLY16H(tmp11
, FIX_0_707106781
);
1927 dataptr
[4] = z13
+ z2
;
1928 dataptr
[5] = z13
- z2
;
1929 dataptr
[6] = z11
+ z4
;
1930 dataptr
[7] = z11
- z4
;
1932 pixels
++; // advance pointer to next column
1937 #else /* HAVE_MMX */
1939 static void row_fdct_mmx(DCTELEM
*data
, const uint8_t *pixels
, int line_size
, int cnt
)
1942 "lea (%%"REG_a
",%%"REG_a
",2), %%"REG_d
" \n\t"
1944 "movd (%%"REG_S
"), %%mm0 \n\t"
1945 "pxor %%mm7, %%mm7 \n\t"
1947 "movd (%%"REG_S
",%%"REG_a
",), %%mm1 \n\t"
1948 "punpcklbw %%mm7, %%mm0 \n\t"
1950 "movd (%%"REG_S
",%%"REG_a
",2), %%mm2 \n\t"
1951 "punpcklbw %%mm7, %%mm1 \n\t"
1953 "punpcklbw %%mm7, %%mm2 \n\t"
1954 "add %%"REG_d
", %%"REG_S
" \n\t"
1956 "movq %%mm0, %%mm5 \n\t"
1959 "movd (%%"REG_S
",%%"REG_a
",4), %%mm3 \n\t" //7 ;prefetch!
1960 "movq %%mm1, %%mm6 \n\t"
1962 "movd (%%"REG_S
",%%"REG_d
",), %%mm4 \n\t" //6
1963 "punpcklbw %%mm7, %%mm3 \n\t"
1965 "psubw %%mm3, %%mm5 \n\t"
1966 "punpcklbw %%mm7, %%mm4 \n\t"
1968 "paddw %%mm3, %%mm0 \n\t"
1969 "psubw %%mm4, %%mm6 \n\t"
1971 "movd (%%"REG_S
",%%"REG_a
",2), %%mm3 \n\t" //5
1972 "paddw %%mm4, %%mm1 \n\t"
1974 "movq %%mm5, "MANGLE(temps
)"+0*8 \n\t" //t7
1975 "punpcklbw %%mm7, %%mm3 \n\t"
1977 "movq %%mm6, "MANGLE(temps
)"+1*8 \n\t" //t6
1978 "movq %%mm2, %%mm4 \n\t"
1980 "movd (%%"REG_S
"), %%mm5 \n\t" //3
1981 "paddw %%mm3, %%mm2 \n\t"
1983 "movd (%%"REG_S
",%%"REG_a
",), %%mm6 \n\t" //4
1984 "punpcklbw %%mm7, %%mm5 \n\t"
1986 "psubw %%mm3, %%mm4 \n\t"
1987 "punpcklbw %%mm7, %%mm6 \n\t"
1989 "movq %%mm5, %%mm3 \n\t"
1990 "paddw %%mm6, %%mm5 \n\t" //t3
1992 "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
1993 "movq %%mm0, %%mm6 \n\t"
1995 "movq %%mm1, %%mm7 \n\t"
1996 "psubw %%mm5, %%mm0 \n\t" //t13
1998 "psubw %%mm2, %%mm1 \n\t"
1999 "paddw %%mm2, %%mm7 \n\t" //t11
2001 "paddw %%mm0, %%mm1 \n\t"
2002 "movq %%mm7, %%mm2 \n\t"
2004 "psllw $2, %%mm1 \n\t"
2005 "paddw %%mm5, %%mm6 \n\t" //t10
2007 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm1 \n\t"
2008 "paddw %%mm6, %%mm7 \n\t" //d2
2010 "psubw %%mm2, %%mm6 \n\t" //d3
2011 "movq %%mm0, %%mm5 \n\t"
2014 "movq %%mm7, %%mm2 \n\t"
2015 "punpcklwd %%mm6, %%mm7 \n\t"
2017 "paddw %%mm1, %%mm0 \n\t" //d0
2018 "punpckhwd %%mm6, %%mm2 \n\t"
2020 "psubw %%mm1, %%mm5 \n\t" //d1
2021 "movq %%mm0, %%mm6 \n\t"
2023 "movq "MANGLE(temps
)"+1*8, %%mm1 \n\t"
2024 "punpcklwd %%mm5, %%mm0 \n\t"
2026 "punpckhwd %%mm5, %%mm6 \n\t"
2027 "movq %%mm0, %%mm5 \n\t"
2029 "punpckldq %%mm7, %%mm0 \n\t" //0
2030 "paddw %%mm4, %%mm3 \n\t"
2032 "punpckhdq %%mm7, %%mm5 \n\t" //1
2033 "movq %%mm6, %%mm7 \n\t"
2035 "movq %%mm0, "DCTSIZE_S
"*0*2(%%"REG_D
") \n\t"
2036 "punpckldq %%mm2, %%mm6 \n\t" //2
2038 "movq %%mm5, "DCTSIZE_S
"*1*2(%%"REG_D
") \n\t"
2039 "punpckhdq %%mm2, %%mm7 \n\t" //3
2041 "movq %%mm6, "DCTSIZE_S
"*2*2(%%"REG_D
") \n\t"
2042 "paddw %%mm1, %%mm4 \n\t"
2044 "movq %%mm7, "DCTSIZE_S
"*3*2(%%"REG_D
") \n\t"
2045 "psllw $2, %%mm3 \n\t" //t10
2047 "movq "MANGLE(temps
)"+0*8, %%mm2 \n\t"
2048 "psllw $2, %%mm4 \n\t" //t11
2050 "pmulhw "MANGLE(MM_FIX_0_707106781
)", %%mm4 \n\t" //z3
2051 "paddw %%mm2, %%mm1 \n\t"
2053 "psllw $2, %%mm1 \n\t" //t12
2054 "movq %%mm3, %%mm0 \n\t"
2056 "pmulhw "MANGLE(MM_FIX_0_541196100
)", %%mm0 \n\t"
2057 "psubw %%mm1, %%mm3 \n\t"
2059 "pmulhw "MANGLE(MM_FIX_0_382683433
)", %%mm3 \n\t" //z5
2060 "movq %%mm2, %%mm5 \n\t"
2062 "pmulhw "MANGLE(MM_FIX_1_306562965
)", %%mm1 \n\t"
2063 "psubw %%mm4, %%mm2 \n\t" //z13
2065 "paddw %%mm4, %%mm5 \n\t" //z11
2066 "movq %%mm2, %%mm6 \n\t"
2068 "paddw %%mm3, %%mm0 \n\t" //z2
2069 "movq %%mm5, %%mm7 \n\t"
2071 "paddw %%mm0, %%mm2 \n\t" //d4
2072 "psubw %%mm0, %%mm6 \n\t" //d5
2074 "movq %%mm2, %%mm4 \n\t"
2075 "paddw %%mm3, %%mm1 \n\t" //z4
2078 "punpcklwd %%mm6, %%mm2 \n\t"
2079 "paddw %%mm1, %%mm5 \n\t" //d6
2081 "punpckhwd %%mm6, %%mm4 \n\t"
2082 "psubw %%mm1, %%mm7 \n\t" //d7
2084 "movq %%mm5, %%mm6 \n\t"
2085 "punpcklwd %%mm7, %%mm5 \n\t"
2087 "punpckhwd %%mm7, %%mm6 \n\t"
2088 "movq %%mm2, %%mm7 \n\t"
2090 "punpckldq %%mm5, %%mm2 \n\t" //4
2091 "sub %%"REG_d
", %%"REG_S
" \n\t"
2093 "punpckhdq %%mm5, %%mm7 \n\t" //5
2094 "movq %%mm4, %%mm5 \n\t"
2096 "movq %%mm2, "DCTSIZE_S
"*0*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2097 "punpckldq %%mm6, %%mm4 \n\t" //6
2099 "movq %%mm7, "DCTSIZE_S
"*1*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2100 "punpckhdq %%mm6, %%mm5 \n\t" //7
2102 "movq %%mm4, "DCTSIZE_S
"*2*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2103 "add $4, %%"REG_S
" \n\t"
2105 "movq %%mm5, "DCTSIZE_S
"*3*2+"DCTSIZE_S
"(%%"REG_D
") \n\t"
2106 "add $"DCTSIZE_S
"*2*4, %%"REG_D
" \n\t" //4 rows
2107 "dec %%"REG_c
" \n\t"
2110 : "+S"(pixels
), "+D"(data
), "+c"(cnt
) //input regs
2117 #endif //USE_LIBAVCODEC