2 * Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @file libpostproc/postprocess_template.c
23 * mmx/mmx2/3dnow postprocess code.
26 #include "libavutil/x86_cpu.h"
28 #define ALIGN_MASK "$-8"
35 #define REAL_PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
37 #define REAL_PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
39 #define PAVGB(a,b) REAL_PAVGB(a,b)
42 #define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
44 #define PMINUB(b,a,t) \
45 "movq " #a ", " #t " \n\t"\
46 "psubusb " #b ", " #t " \n\t"\
47 "psubb " #t ", " #a " \n\t"
51 #define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
54 "psubusb " #a ", " #b " \n\t"\
55 "paddb " #a ", " #b " \n\t"
58 //FIXME? |255-0| = 1 (should not be a problem ...)
61 * Check if the middle 8x8 Block in the given 8x16 block is flat
63 static inline int RENAME(vertClassify
)(uint8_t src
[], int stride
, PPContext
*c
){
65 src
+= stride
*4; // src points to begin of the 8x8 Block
69 : : "m" (c
->mmxDcOffset
[c
->nonBQP
]), "m" (c
->mmxDcThreshold
[c
->nonBQP
])
73 "lea (%2, %3), %%"REG_a
" \n\t"
74 // 0 1 2 3 4 5 6 7 8 9
75 // %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
77 "movq (%2), %%mm0 \n\t"
78 "movq (%%"REG_a
"), %%mm1 \n\t"
79 "movq %%mm0, %%mm3 \n\t"
80 "movq %%mm0, %%mm4 \n\t"
82 PMINUB(%%mm1
, %%mm3
, %%mm5
)
83 "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
84 "paddb %%mm7, %%mm0 \n\t"
85 "pcmpgtb %%mm6, %%mm0 \n\t"
87 "movq (%%"REG_a
",%3), %%mm2 \n\t"
89 PMINUB(%%mm2
, %%mm3
, %%mm5
)
90 "psubb %%mm2, %%mm1 \n\t"
91 "paddb %%mm7, %%mm1 \n\t"
92 "pcmpgtb %%mm6, %%mm1 \n\t"
93 "paddb %%mm1, %%mm0 \n\t"
95 "movq (%%"REG_a
", %3, 2), %%mm1 \n\t"
97 PMINUB(%%mm1
, %%mm3
, %%mm5
)
98 "psubb %%mm1, %%mm2 \n\t"
99 "paddb %%mm7, %%mm2 \n\t"
100 "pcmpgtb %%mm6, %%mm2 \n\t"
101 "paddb %%mm2, %%mm0 \n\t"
103 "lea (%%"REG_a
", %3, 4), %%"REG_a
" \n\t"
105 "movq (%2, %3, 4), %%mm2 \n\t"
107 PMINUB(%%mm2
, %%mm3
, %%mm5
)
108 "psubb %%mm2, %%mm1 \n\t"
109 "paddb %%mm7, %%mm1 \n\t"
110 "pcmpgtb %%mm6, %%mm1 \n\t"
111 "paddb %%mm1, %%mm0 \n\t"
113 "movq (%%"REG_a
"), %%mm1 \n\t"
115 PMINUB(%%mm1
, %%mm3
, %%mm5
)
116 "psubb %%mm1, %%mm2 \n\t"
117 "paddb %%mm7, %%mm2 \n\t"
118 "pcmpgtb %%mm6, %%mm2 \n\t"
119 "paddb %%mm2, %%mm0 \n\t"
121 "movq (%%"REG_a
", %3), %%mm2 \n\t"
123 PMINUB(%%mm2
, %%mm3
, %%mm5
)
124 "psubb %%mm2, %%mm1 \n\t"
125 "paddb %%mm7, %%mm1 \n\t"
126 "pcmpgtb %%mm6, %%mm1 \n\t"
127 "paddb %%mm1, %%mm0 \n\t"
129 "movq (%%"REG_a
", %3, 2), %%mm1 \n\t"
131 PMINUB(%%mm1
, %%mm3
, %%mm5
)
132 "psubb %%mm1, %%mm2 \n\t"
133 "paddb %%mm7, %%mm2 \n\t"
134 "pcmpgtb %%mm6, %%mm2 \n\t"
135 "paddb %%mm2, %%mm0 \n\t"
136 "psubusb %%mm3, %%mm4 \n\t"
140 "pxor %%mm7, %%mm7 \n\t"
141 "psadbw %%mm7, %%mm0 \n\t"
143 "movq %%mm0, %%mm1 \n\t"
144 "psrlw $8, %%mm0 \n\t"
145 "paddb %%mm1, %%mm0 \n\t"
146 "movq %%mm0, %%mm1 \n\t"
147 "psrlq $16, %%mm0 \n\t"
148 "paddb %%mm1, %%mm0 \n\t"
149 "movq %%mm0, %%mm1 \n\t"
150 "psrlq $32, %%mm0 \n\t"
151 "paddb %%mm1, %%mm0 \n\t"
153 "movq %4, %%mm7 \n\t" // QP,..., QP
154 "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
155 "psubusb %%mm7, %%mm4 \n\t" // Diff <= 2QP -> 0
156 "packssdw %%mm4, %%mm4 \n\t"
157 "movd %%mm0, %0 \n\t"
158 "movd %%mm4, %1 \n\t"
160 : "=r" (numEq
), "=r" (dcOk
)
161 : "r" (src
), "r" ((x86_reg
)stride
), "m" (c
->pQPb
)
165 numEq
= (-numEq
) &0xFF;
166 if(numEq
> c
->ppMode
.flatnessThreshold
){
176 * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
177 * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
180 static inline void RENAME(doVertLowPass
)(uint8_t *src
, int stride
, PPContext
*c
)
182 #if HAVE_MMX2 || HAVE_AMD3DNOW
184 __asm__
volatile( //"movv %0 %1 %2\n\t"
185 "movq %2, %%mm0 \n\t" // QP,..., QP
186 "pxor %%mm4, %%mm4 \n\t"
188 "movq (%0), %%mm6 \n\t"
189 "movq (%0, %1), %%mm5 \n\t"
190 "movq %%mm5, %%mm1 \n\t"
191 "movq %%mm6, %%mm2 \n\t"
192 "psubusb %%mm6, %%mm5 \n\t"
193 "psubusb %%mm1, %%mm2 \n\t"
194 "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
195 "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
196 "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
198 "pand %%mm2, %%mm6 \n\t"
199 "pandn %%mm1, %%mm2 \n\t"
200 "por %%mm2, %%mm6 \n\t"// First Line to Filter
202 "movq (%0, %1, 8), %%mm5 \n\t"
203 "lea (%0, %1, 4), %%"REG_a
" \n\t"
204 "lea (%0, %1, 8), %%"REG_c
" \n\t"
205 "sub %1, %%"REG_c
" \n\t"
206 "add %1, %0 \n\t" // %0 points to line 1 not 0
207 "movq (%0, %1, 8), %%mm7 \n\t"
208 "movq %%mm5, %%mm1 \n\t"
209 "movq %%mm7, %%mm2 \n\t"
210 "psubusb %%mm7, %%mm5 \n\t"
211 "psubusb %%mm1, %%mm2 \n\t"
212 "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
213 "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
214 "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
216 "pand %%mm2, %%mm7 \n\t"
217 "pandn %%mm1, %%mm2 \n\t"
218 "por %%mm2, %%mm7 \n\t" // First Line to Filter
222 // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ecx eax+4%1
227 "movq (%0, %1), %%mm0 \n\t" // 1
228 "movq %%mm0, %%mm1 \n\t" // 1
229 PAVGB(%%mm6
, %%mm0
) //1 1 /2
230 PAVGB(%%mm6
, %%mm0
) //3 1 /4
232 "movq (%0, %1, 4), %%mm2 \n\t" // 1
233 "movq %%mm2, %%mm5 \n\t" // 1
234 PAVGB((%%REGa
), %%mm2
) // 11 /2
235 PAVGB((%0, %1, 2), %%mm2
) // 211 /4
236 "movq %%mm2, %%mm3 \n\t" // 211 /4
237 "movq (%0), %%mm4 \n\t" // 1
238 PAVGB(%%mm4
, %%mm3
) // 4 211 /8
239 PAVGB(%%mm0
, %%mm3
) //642211 /16
240 "movq %%mm3, (%0) \n\t" // X
241 // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9
242 "movq %%mm1, %%mm0 \n\t" // 1
243 PAVGB(%%mm6
, %%mm0
) //1 1 /2
244 "movq %%mm4, %%mm3 \n\t" // 1
245 PAVGB((%0,%1,2), %%mm3
) // 1 1 /2
246 PAVGB((%%REGa
,%1,2), %%mm5
) // 11 /2
247 PAVGB((%%REGa
), %%mm5
) // 211 /4
248 PAVGB(%%mm5
, %%mm3
) // 2 2211 /8
249 PAVGB(%%mm0
, %%mm3
) //4242211 /16
250 "movq %%mm3, (%0,%1) \n\t" // X
251 // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9
252 PAVGB(%%mm4
, %%mm6
) //11 /2
253 "movq (%%"REG_c
"), %%mm0 \n\t" // 1
254 PAVGB((%%REGa
, %1, 2), %%mm0
) // 11/2
255 "movq %%mm0, %%mm3 \n\t" // 11/2
256 PAVGB(%%mm1
, %%mm0
) // 2 11/4
257 PAVGB(%%mm6
, %%mm0
) //222 11/8
258 PAVGB(%%mm2
, %%mm0
) //22242211/16
259 "movq (%0, %1, 2), %%mm2 \n\t" // 1
260 "movq %%mm0, (%0, %1, 2) \n\t" // X
261 // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9
262 "movq (%%"REG_a
", %1, 4), %%mm0 \n\t" // 1
263 PAVGB((%%REGc
), %%mm0
) // 11 /2
264 PAVGB(%%mm0
, %%mm6
) //11 11 /4
265 PAVGB(%%mm1
, %%mm4
) // 11 /2
266 PAVGB(%%mm2
, %%mm1
) // 11 /2
267 PAVGB(%%mm1
, %%mm6
) //1122 11 /8
268 PAVGB(%%mm5
, %%mm6
) //112242211 /16
269 "movq (%%"REG_a
"), %%mm5 \n\t" // 1
270 "movq %%mm6, (%%"REG_a
") \n\t" // X
271 // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9
272 "movq (%%"REG_a
", %1, 4), %%mm6 \n\t" // 1
273 PAVGB(%%mm7
, %%mm6
) // 11 /2
274 PAVGB(%%mm4
, %%mm6
) // 11 11 /4
275 PAVGB(%%mm3
, %%mm6
) // 11 2211 /8
276 PAVGB(%%mm5
, %%mm2
) // 11 /2
277 "movq (%0, %1, 4), %%mm4 \n\t" // 1
278 PAVGB(%%mm4
, %%mm2
) // 112 /4
279 PAVGB(%%mm2
, %%mm6
) // 112242211 /16
280 "movq %%mm6, (%0, %1, 4) \n\t" // X
281 // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9
282 PAVGB(%%mm7
, %%mm1
) // 11 2 /4
283 PAVGB(%%mm4
, %%mm5
) // 11 /2
284 PAVGB(%%mm5
, %%mm0
) // 11 11 /4
285 "movq (%%"REG_a
", %1, 2), %%mm6 \n\t" // 1
286 PAVGB(%%mm6
, %%mm1
) // 11 4 2 /8
287 PAVGB(%%mm0
, %%mm1
) // 11224222 /16
288 "movq %%mm1, (%%"REG_a
", %1, 2) \n\t" // X
289 // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9
290 PAVGB((%%REGc
), %%mm2
) // 112 4 /8
291 "movq (%%"REG_a
", %1, 4), %%mm0 \n\t" // 1
292 PAVGB(%%mm0
, %%mm6
) // 1 1 /2
293 PAVGB(%%mm7
, %%mm6
) // 1 12 /4
294 PAVGB(%%mm2
, %%mm6
) // 1122424 /4
295 "movq %%mm6, (%%"REG_c
") \n\t" // X
296 // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9
297 PAVGB(%%mm7
, %%mm5
) // 11 2 /4
298 PAVGB(%%mm7
, %%mm5
) // 11 6 /8
300 PAVGB(%%mm3
, %%mm0
) // 112 /4
301 PAVGB(%%mm0
, %%mm5
) // 112246 /16
302 "movq %%mm5, (%%"REG_a
", %1, 4) \n\t" // X
306 : "r" (src
), "r" ((x86_reg
)stride
), "m" (c
->pQPb
)
309 #else //HAVE_MMX2 || HAVE_AMD3DNOW
310 const int l1
= stride
;
311 const int l2
= stride
+ l1
;
312 const int l3
= stride
+ l2
;
313 const int l4
= stride
+ l3
;
314 const int l5
= stride
+ l4
;
315 const int l6
= stride
+ l5
;
316 const int l7
= stride
+ l6
;
317 const int l8
= stride
+ l7
;
318 const int l9
= stride
+ l8
;
321 for(x
=0; x
<BLOCK_SIZE
; x
++){
322 const int first
= FFABS(src
[0] - src
[l1
]) < c
->QP
? src
[0] : src
[l1
];
323 const int last
= FFABS(src
[l8
] - src
[l9
]) < c
->QP
? src
[l9
] : src
[l8
];
326 sums
[0] = 4*first
+ src
[l1
] + src
[l2
] + src
[l3
] + 4;
327 sums
[1] = sums
[0] - first
+ src
[l4
];
328 sums
[2] = sums
[1] - first
+ src
[l5
];
329 sums
[3] = sums
[2] - first
+ src
[l6
];
330 sums
[4] = sums
[3] - first
+ src
[l7
];
331 sums
[5] = sums
[4] - src
[l1
] + src
[l8
];
332 sums
[6] = sums
[5] - src
[l2
] + last
;
333 sums
[7] = sums
[6] - src
[l3
] + last
;
334 sums
[8] = sums
[7] - src
[l4
] + last
;
335 sums
[9] = sums
[8] - src
[l5
] + last
;
337 src
[l1
]= (sums
[0] + sums
[2] + 2*src
[l1
])>>4;
338 src
[l2
]= (sums
[1] + sums
[3] + 2*src
[l2
])>>4;
339 src
[l3
]= (sums
[2] + sums
[4] + 2*src
[l3
])>>4;
340 src
[l4
]= (sums
[3] + sums
[5] + 2*src
[l4
])>>4;
341 src
[l5
]= (sums
[4] + sums
[6] + 2*src
[l5
])>>4;
342 src
[l6
]= (sums
[5] + sums
[7] + 2*src
[l6
])>>4;
343 src
[l7
]= (sums
[6] + sums
[8] + 2*src
[l7
])>>4;
344 src
[l8
]= (sums
[7] + sums
[9] + 2*src
[l8
])>>4;
348 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
350 #endif //HAVE_ALTIVEC
353 * Experimental Filter 1
354 * will not damage linear gradients
355 * Flat blocks should look like they were passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
356 * can only smooth blocks at the expected locations (it cannot smooth them if they did move)
357 * MMX2 version does correct clipping C version does not
359 static inline void RENAME(vertX1Filter
)(uint8_t *src
, int stride
, PPContext
*co
)
361 #if HAVE_MMX2 || HAVE_AMD3DNOW
365 "pxor %%mm7, %%mm7 \n\t" // 0
366 "lea (%0, %1), %%"REG_a
" \n\t"
367 "lea (%%"REG_a
", %1, 4), %%"REG_c
" \n\t"
368 // 0 1 2 3 4 5 6 7 8 9
369 // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
370 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t" // line 3
371 "movq (%0, %1, 4), %%mm1 \n\t" // line 4
372 "movq %%mm1, %%mm2 \n\t" // line 4
373 "psubusb %%mm0, %%mm1 \n\t"
374 "psubusb %%mm2, %%mm0 \n\t"
375 "por %%mm1, %%mm0 \n\t" // |l2 - l3|
376 "movq (%%"REG_c
"), %%mm3 \n\t" // line 5
377 "movq (%%"REG_c
", %1), %%mm4 \n\t" // line 6
378 "movq %%mm3, %%mm5 \n\t" // line 5
379 "psubusb %%mm4, %%mm3 \n\t"
380 "psubusb %%mm5, %%mm4 \n\t"
381 "por %%mm4, %%mm3 \n\t" // |l5 - l6|
382 PAVGB(%%mm3
, %%mm0
) // (|l2 - l3| + |l5 - l6|)/2
383 "movq %%mm2, %%mm1 \n\t" // line 4
384 "psubusb %%mm5, %%mm2 \n\t"
385 "movq %%mm2, %%mm4 \n\t"
386 "pcmpeqb %%mm7, %%mm2 \n\t" // (l4 - l5) <= 0 ? -1 : 0
387 "psubusb %%mm1, %%mm5 \n\t"
388 "por %%mm5, %%mm4 \n\t" // |l4 - l5|
389 "psubusb %%mm0, %%mm4 \n\t" //d = MAX(0, |l4-l5| - (|l2-l3| + |l5-l6|)/2)
390 "movq %%mm4, %%mm3 \n\t" // d
391 "movq %2, %%mm0 \n\t"
392 "paddusb %%mm0, %%mm0 \n\t"
393 "psubusb %%mm0, %%mm4 \n\t"
394 "pcmpeqb %%mm7, %%mm4 \n\t" // d <= QP ? -1 : 0
395 "psubusb "MANGLE(b01
)", %%mm3 \n\t"
396 "pand %%mm4, %%mm3 \n\t" // d <= QP ? d : 0
398 PAVGB(%%mm7
, %%mm3
) // d/2
399 "movq %%mm3, %%mm1 \n\t" // d/2
400 PAVGB(%%mm7
, %%mm3
) // d/4
401 PAVGB(%%mm1
, %%mm3
) // 3*d/8
403 "movq (%0, %1, 4), %%mm0 \n\t" // line 4
404 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
405 "psubusb %%mm3, %%mm0 \n\t"
406 "pxor %%mm2, %%mm0 \n\t"
407 "movq %%mm0, (%0, %1, 4) \n\t" // line 4
409 "movq (%%"REG_c
"), %%mm0 \n\t" // line 5
410 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
411 "paddusb %%mm3, %%mm0 \n\t"
412 "pxor %%mm2, %%mm0 \n\t"
413 "movq %%mm0, (%%"REG_c
") \n\t" // line 5
415 PAVGB(%%mm7
, %%mm1
) // d/4
417 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t" // line 3
418 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
419 "psubusb %%mm1, %%mm0 \n\t"
420 "pxor %%mm2, %%mm0 \n\t"
421 "movq %%mm0, (%%"REG_a
", %1, 2) \n\t" // line 3
423 "movq (%%"REG_c
", %1), %%mm0 \n\t" // line 6
424 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
425 "paddusb %%mm1, %%mm0 \n\t"
426 "pxor %%mm2, %%mm0 \n\t"
427 "movq %%mm0, (%%"REG_c
", %1) \n\t" // line 6
429 PAVGB(%%mm7
, %%mm1
) // d/8
431 "movq (%%"REG_a
", %1), %%mm0 \n\t" // line 2
432 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l2-1 : l2
433 "psubusb %%mm1, %%mm0 \n\t"
434 "pxor %%mm2, %%mm0 \n\t"
435 "movq %%mm0, (%%"REG_a
", %1) \n\t" // line 2
437 "movq (%%"REG_c
", %1, 2), %%mm0 \n\t" // line 7
438 "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l7-1 : l7
439 "paddusb %%mm1, %%mm0 \n\t"
440 "pxor %%mm2, %%mm0 \n\t"
441 "movq %%mm0, (%%"REG_c
", %1, 2) \n\t" // line 7
444 : "r" (src
), "r" ((x86_reg
)stride
), "m" (co
->pQPb
)
447 #else //HAVE_MMX2 || HAVE_AMD3DNOW
449 const int l1
= stride
;
450 const int l2
= stride
+ l1
;
451 const int l3
= stride
+ l2
;
452 const int l4
= stride
+ l3
;
453 const int l5
= stride
+ l4
;
454 const int l6
= stride
+ l5
;
455 const int l7
= stride
+ l6
;
456 // const int l8= stride + l7;
457 // const int l9= stride + l8;
461 for(x
=0; x
<BLOCK_SIZE
; x
++){
462 int a
= src
[l3
] - src
[l4
];
463 int b
= src
[l4
] - src
[l5
];
464 int c
= src
[l5
] - src
[l6
];
466 int d
= FFABS(b
) - ((FFABS(a
) + FFABS(c
))>>1);
470 int v
= d
* FFSIGN(-b
);
481 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
485 static inline void RENAME(doVertDefFilter
)(uint8_t src
[], int stride
, PPContext
*c
)
487 #if HAVE_MMX2 || HAVE_AMD3DNOW
490 const int l1= stride;
491 const int l2= stride + l1;
492 const int l3= stride + l2;
493 const int l4= (int)tmp - (int)src - stride*3;
494 const int l5= (int)tmp - (int)src - stride*3 + 8;
495 const int l6= stride*3 + l3;
496 const int l7= stride + l6;
497 const int l8= stride + l7;
499 memcpy(tmp, src+stride*7, 8);
500 memcpy(tmp+8, src+stride*8, 8);
505 #if 0 //slightly more accurate and slightly slower
506 "pxor %%mm7, %%mm7 \n\t" // 0
507 "lea (%0, %1), %%"REG_a
" \n\t"
508 "lea (%%"REG_a
", %1, 4), %%"REG_c
" \n\t"
510 // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
511 // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
514 "movq (%0, %1, 2), %%mm0 \n\t" // l2
515 "movq (%0), %%mm1 \n\t" // l0
516 "movq %%mm0, %%mm2 \n\t" // l2
517 PAVGB(%%mm7
, %%mm0
) // ~l2/2
518 PAVGB(%%mm1
, %%mm0
) // ~(l2 + 2l0)/4
519 PAVGB(%%mm2
, %%mm0
) // ~(5l2 + 2l0)/8
521 "movq (%%"REG_a
"), %%mm1 \n\t" // l1
522 "movq (%%"REG_a
", %1, 2), %%mm3 \n\t" // l3
523 "movq %%mm1, %%mm4 \n\t" // l1
524 PAVGB(%%mm7
, %%mm1
) // ~l1/2
525 PAVGB(%%mm3
, %%mm1
) // ~(l1 + 2l3)/4
526 PAVGB(%%mm4
, %%mm1
) // ~(5l1 + 2l3)/8
528 "movq %%mm0, %%mm4 \n\t" // ~(5l2 + 2l0)/8
529 "psubusb %%mm1, %%mm0 \n\t"
530 "psubusb %%mm4, %%mm1 \n\t"
531 "por %%mm0, %%mm1 \n\t" // ~|2l0 - 5l1 + 5l2 - 2l3|/8
532 // mm1= |lenergy|, mm2= l2, mm3= l3, mm7=0
534 "movq (%0, %1, 4), %%mm0 \n\t" // l4
535 "movq %%mm0, %%mm4 \n\t" // l4
536 PAVGB(%%mm7
, %%mm0
) // ~l4/2
537 PAVGB(%%mm2
, %%mm0
) // ~(l4 + 2l2)/4
538 PAVGB(%%mm4
, %%mm0
) // ~(5l4 + 2l2)/8
540 "movq (%%"REG_c
"), %%mm2 \n\t" // l5
541 "movq %%mm3, %%mm5 \n\t" // l3
542 PAVGB(%%mm7
, %%mm3
) // ~l3/2
543 PAVGB(%%mm2
, %%mm3
) // ~(l3 + 2l5)/4
544 PAVGB(%%mm5
, %%mm3
) // ~(5l3 + 2l5)/8
546 "movq %%mm0, %%mm6 \n\t" // ~(5l4 + 2l2)/8
547 "psubusb %%mm3, %%mm0 \n\t"
548 "psubusb %%mm6, %%mm3 \n\t"
549 "por %%mm0, %%mm3 \n\t" // ~|2l2 - 5l3 + 5l4 - 2l5|/8
550 "pcmpeqb %%mm7, %%mm0 \n\t" // SIGN(2l2 - 5l3 + 5l4 - 2l5)
551 // mm0= SIGN(menergy), mm1= |lenergy|, mm2= l5, mm3= |menergy|, mm4=l4, mm5= l3, mm7=0
553 "movq (%%"REG_c
", %1), %%mm6 \n\t" // l6
554 "movq %%mm6, %%mm5 \n\t" // l6
555 PAVGB(%%mm7
, %%mm6
) // ~l6/2
556 PAVGB(%%mm4
, %%mm6
) // ~(l6 + 2l4)/4
557 PAVGB(%%mm5
, %%mm6
) // ~(5l6 + 2l4)/8
559 "movq (%%"REG_c
", %1, 2), %%mm5 \n\t" // l7
560 "movq %%mm2, %%mm4 \n\t" // l5
561 PAVGB(%%mm7
, %%mm2
) // ~l5/2
562 PAVGB(%%mm5
, %%mm2
) // ~(l5 + 2l7)/4
563 PAVGB(%%mm4
, %%mm2
) // ~(5l5 + 2l7)/8
565 "movq %%mm6, %%mm4 \n\t" // ~(5l6 + 2l4)/8
566 "psubusb %%mm2, %%mm6 \n\t"
567 "psubusb %%mm4, %%mm2 \n\t"
568 "por %%mm6, %%mm2 \n\t" // ~|2l4 - 5l5 + 5l6 - 2l7|/8
569 // mm0= SIGN(menergy), mm1= |lenergy|/8, mm2= |renergy|/8, mm3= |menergy|/8, mm7=0
572 PMINUB(%%mm2
, %%mm1
, %%mm4
) // MIN(|lenergy|,|renergy|)/8
573 "movq %2, %%mm4 \n\t" // QP //FIXME QP+1 ?
574 "paddusb "MANGLE(b01
)", %%mm4 \n\t"
575 "pcmpgtb %%mm3, %%mm4 \n\t" // |menergy|/8 < QP
576 "psubusb %%mm1, %%mm3 \n\t" // d=|menergy|/8-MIN(|lenergy|,|renergy|)/8
577 "pand %%mm4, %%mm3 \n\t"
579 "movq %%mm3, %%mm1 \n\t"
580 // "psubusb "MANGLE(b01)", %%mm3 \n\t"
583 "paddusb %%mm1, %%mm3 \n\t"
584 // "paddusb "MANGLE(b01)", %%mm3 \n\t"
586 "movq (%%"REG_a
", %1, 2), %%mm6 \n\t" //l3
587 "movq (%0, %1, 4), %%mm5 \n\t" //l4
588 "movq (%0, %1, 4), %%mm4 \n\t" //l4
589 "psubusb %%mm6, %%mm5 \n\t"
590 "psubusb %%mm4, %%mm6 \n\t"
591 "por %%mm6, %%mm5 \n\t" // |l3-l4|
592 "pcmpeqb %%mm7, %%mm6 \n\t" // SIGN(l3-l4)
593 "pxor %%mm6, %%mm0 \n\t"
594 "pand %%mm0, %%mm3 \n\t"
595 PMINUB(%%mm5
, %%mm3
, %%mm0
)
597 "psubusb "MANGLE(b01
)", %%mm3 \n\t"
600 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t"
601 "movq (%0, %1, 4), %%mm2 \n\t"
602 "pxor %%mm6, %%mm0 \n\t"
603 "pxor %%mm6, %%mm2 \n\t"
604 "psubb %%mm3, %%mm0 \n\t"
605 "paddb %%mm3, %%mm2 \n\t"
606 "pxor %%mm6, %%mm0 \n\t"
607 "pxor %%mm6, %%mm2 \n\t"
608 "movq %%mm0, (%%"REG_a
", %1, 2) \n\t"
609 "movq %%mm2, (%0, %1, 4) \n\t"
612 "lea (%0, %1), %%"REG_a
" \n\t"
613 "pcmpeqb %%mm6, %%mm6 \n\t" // -1
615 // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
616 // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
619 "movq (%%"REG_a
", %1, 2), %%mm1 \n\t" // l3
620 "movq (%0, %1, 4), %%mm0 \n\t" // l4
621 "pxor %%mm6, %%mm1 \n\t" // -l3-1
622 PAVGB(%%mm1
, %%mm0
) // -q+128 = (l4-l3+256)/2
623 // mm1=-l3-1, mm0=128-q
625 "movq (%%"REG_a
", %1, 4), %%mm2 \n\t" // l5
626 "movq (%%"REG_a
", %1), %%mm3 \n\t" // l2
627 "pxor %%mm6, %%mm2 \n\t" // -l5-1
628 "movq %%mm2, %%mm5 \n\t" // -l5-1
629 "movq "MANGLE(b80
)", %%mm4 \n\t" // 128
630 "lea (%%"REG_a
", %1, 4), %%"REG_c
" \n\t"
631 PAVGB(%%mm3
, %%mm2
) // (l2-l5+256)/2
632 PAVGB(%%mm0
, %%mm4
) // ~(l4-l3)/4 + 128
633 PAVGB(%%mm2
, %%mm4
) // ~(l2-l5)/4 +(l4-l3)/8 + 128
634 PAVGB(%%mm0
, %%mm4
) // ~(l2-l5)/8 +5(l4-l3)/16 + 128
635 // mm1=-l3-1, mm0=128-q, mm3=l2, mm4=menergy/16 + 128, mm5= -l5-1
637 "movq (%%"REG_a
"), %%mm2 \n\t" // l1
638 "pxor %%mm6, %%mm2 \n\t" // -l1-1
639 PAVGB(%%mm3
, %%mm2
) // (l2-l1+256)/2
640 PAVGB((%0), %%mm1
) // (l0-l3+256)/2
641 "movq "MANGLE(b80
)", %%mm3 \n\t" // 128
642 PAVGB(%%mm2
, %%mm3
) // ~(l2-l1)/4 + 128
643 PAVGB(%%mm1
, %%mm3
) // ~(l0-l3)/4 +(l2-l1)/8 + 128
644 PAVGB(%%mm2
, %%mm3
) // ~(l0-l3)/8 +5(l2-l1)/16 + 128
645 // mm0=128-q, mm3=lenergy/16 + 128, mm4= menergy/16 + 128, mm5= -l5-1
647 PAVGB((%%REGc
, %1), %%mm5
) // (l6-l5+256)/2
648 "movq (%%"REG_c
", %1, 2), %%mm1 \n\t" // l7
649 "pxor %%mm6, %%mm1 \n\t" // -l7-1
650 PAVGB((%0, %1, 4), %%mm1
) // (l4-l7+256)/2
651 "movq "MANGLE(b80
)", %%mm2 \n\t" // 128
652 PAVGB(%%mm5
, %%mm2
) // ~(l6-l5)/4 + 128
653 PAVGB(%%mm1
, %%mm2
) // ~(l4-l7)/4 +(l6-l5)/8 + 128
654 PAVGB(%%mm5
, %%mm2
) // ~(l4-l7)/8 +5(l6-l5)/16 + 128
655 // mm0=128-q, mm2=renergy/16 + 128, mm3=lenergy/16 + 128, mm4= menergy/16 + 128
657 "movq "MANGLE(b00
)", %%mm1 \n\t" // 0
658 "movq "MANGLE(b00
)", %%mm5 \n\t" // 0
659 "psubb %%mm2, %%mm1 \n\t" // 128 - renergy/16
660 "psubb %%mm3, %%mm5 \n\t" // 128 - lenergy/16
661 PMAXUB(%%mm1
, %%mm2
) // 128 + |renergy/16|
662 PMAXUB(%%mm5
, %%mm3
) // 128 + |lenergy/16|
663 PMINUB(%%mm2
, %%mm3
, %%mm1
) // 128 + MIN(|lenergy|,|renergy|)/16
665 // mm0=128-q, mm3=128 + MIN(|lenergy|,|renergy|)/16, mm4= menergy/16 + 128
667 "movq "MANGLE(b00
)", %%mm7 \n\t" // 0
668 "movq %2, %%mm2 \n\t" // QP
669 PAVGB(%%mm6
, %%mm2
) // 128 + QP/2
670 "psubb %%mm6, %%mm2 \n\t"
672 "movq %%mm4, %%mm1 \n\t"
673 "pcmpgtb %%mm7, %%mm1 \n\t" // SIGN(menergy)
674 "pxor %%mm1, %%mm4 \n\t"
675 "psubb %%mm1, %%mm4 \n\t" // 128 + |menergy|/16
676 "pcmpgtb %%mm4, %%mm2 \n\t" // |menergy|/16 < QP/2
677 "psubusb %%mm3, %%mm4 \n\t" //d=|menergy|/16 - MIN(|lenergy|,|renergy|)/16
678 // mm0=128-q, mm1= SIGN(menergy), mm2= |menergy|/16 < QP/2, mm4= d/16
680 "movq %%mm4, %%mm3 \n\t" // d
681 "psubusb "MANGLE(b01
)", %%mm4 \n\t"
682 PAVGB(%%mm7
, %%mm4
) // d/32
683 PAVGB(%%mm7
, %%mm4
) // (d + 32)/64
684 "paddb %%mm3, %%mm4 \n\t" // 5d/64
685 "pand %%mm2, %%mm4 \n\t"
687 "movq "MANGLE(b80
)", %%mm5 \n\t" // 128
688 "psubb %%mm0, %%mm5 \n\t" // q
689 "paddsb %%mm6, %%mm5 \n\t" // fix bad rounding
690 "pcmpgtb %%mm5, %%mm7 \n\t" // SIGN(q)
691 "pxor %%mm7, %%mm5 \n\t"
693 PMINUB(%%mm5
, %%mm4
, %%mm3
) // MIN(|q|, 5d/64)
694 "pxor %%mm1, %%mm7 \n\t" // SIGN(d*q)
696 "pand %%mm7, %%mm4 \n\t"
697 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t"
698 "movq (%0, %1, 4), %%mm2 \n\t"
699 "pxor %%mm1, %%mm0 \n\t"
700 "pxor %%mm1, %%mm2 \n\t"
701 "paddb %%mm4, %%mm0 \n\t"
702 "psubb %%mm4, %%mm2 \n\t"
703 "pxor %%mm1, %%mm0 \n\t"
704 "pxor %%mm1, %%mm2 \n\t"
705 "movq %%mm0, (%%"REG_a
", %1, 2) \n\t"
706 "movq %%mm2, (%0, %1, 4) \n\t"
709 : "r" (src
), "r" ((x86_reg
)stride
), "m" (c
->pQPb
)
717 for(x=0; x<BLOCK_SIZE; x++){
718 const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
719 if(FFABS(middleEnergy)< 8*QP){
720 const int q=(src[l4] - src[l5])/2;
721 const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
722 const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
724 int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
728 d*= FFSIGN(-middleEnergy);
747 int d= src[x+y*stride] - tmp[x+(y-4)*8];
757 src[0] = src[7] = src[stride*7] = src[(stride+1)*7]=255;
761 if(num%1000000 == 0){
762 av_log(c, AV_LOG_INFO, " %d %d %d %d\n", num, sum, max, bias);
771 "pxor %%mm7, %%mm7 \n\t"
772 "lea -40(%%"REG_SP
"), %%"REG_c
" \n\t" // make space for 4 8-byte vars
773 "and "ALIGN_MASK
", %%"REG_c
" \n\t" // align
775 // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
776 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
778 "movq (%0), %%mm0 \n\t"
779 "movq %%mm0, %%mm1 \n\t"
780 "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
781 "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
783 "movq (%0, %1), %%mm2 \n\t"
784 "lea (%0, %1, 2), %%"REG_a
" \n\t"
785 "movq %%mm2, %%mm3 \n\t"
786 "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
787 "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
789 "movq (%%"REG_a
"), %%mm4 \n\t"
790 "movq %%mm4, %%mm5 \n\t"
791 "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
792 "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
794 "paddw %%mm0, %%mm0 \n\t" // 2L0
795 "paddw %%mm1, %%mm1 \n\t" // 2H0
796 "psubw %%mm4, %%mm2 \n\t" // L1 - L2
797 "psubw %%mm5, %%mm3 \n\t" // H1 - H2
798 "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
799 "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
801 "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
802 "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
803 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
804 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
806 "movq (%%"REG_a
", %1), %%mm2 \n\t"
807 "movq %%mm2, %%mm3 \n\t"
808 "punpcklbw %%mm7, %%mm2 \n\t" // L3
809 "punpckhbw %%mm7, %%mm3 \n\t" // H3
811 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
812 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
813 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
814 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
815 "movq %%mm0, (%%"REG_c
") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
816 "movq %%mm1, 8(%%"REG_c
") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
818 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t"
819 "movq %%mm0, %%mm1 \n\t"
820 "punpcklbw %%mm7, %%mm0 \n\t" // L4
821 "punpckhbw %%mm7, %%mm1 \n\t" // H4
823 "psubw %%mm0, %%mm2 \n\t" // L3 - L4
824 "psubw %%mm1, %%mm3 \n\t" // H3 - H4
825 "movq %%mm2, 16(%%"REG_c
") \n\t" // L3 - L4
826 "movq %%mm3, 24(%%"REG_c
") \n\t" // H3 - H4
827 "paddw %%mm4, %%mm4 \n\t" // 2L2
828 "paddw %%mm5, %%mm5 \n\t" // 2H2
829 "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
830 "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
832 "lea (%%"REG_a
", %1), %0 \n\t"
833 "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
834 "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
835 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
836 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
838 "movq (%0, %1, 2), %%mm2 \n\t"
839 "movq %%mm2, %%mm3 \n\t"
840 "punpcklbw %%mm7, %%mm2 \n\t" // L5
841 "punpckhbw %%mm7, %%mm3 \n\t" // H5
842 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
843 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
844 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
845 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
847 "movq (%%"REG_a
", %1, 4), %%mm6 \n\t"
848 "punpcklbw %%mm7, %%mm6 \n\t" // L6
849 "psubw %%mm6, %%mm2 \n\t" // L5 - L6
850 "movq (%%"REG_a
", %1, 4), %%mm6 \n\t"
851 "punpckhbw %%mm7, %%mm6 \n\t" // H6
852 "psubw %%mm6, %%mm3 \n\t" // H5 - H6
854 "paddw %%mm0, %%mm0 \n\t" // 2L4
855 "paddw %%mm1, %%mm1 \n\t" // 2H4
856 "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
857 "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
859 "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
860 "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
861 "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
862 "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
864 "movq (%0, %1, 4), %%mm2 \n\t"
865 "movq %%mm2, %%mm3 \n\t"
866 "punpcklbw %%mm7, %%mm2 \n\t" // L7
867 "punpckhbw %%mm7, %%mm3 \n\t" // H7
869 "paddw %%mm2, %%mm2 \n\t" // 2L7
870 "paddw %%mm3, %%mm3 \n\t" // 2H7
871 "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
872 "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
874 "movq (%%"REG_c
"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
875 "movq 8(%%"REG_c
"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
878 "movq %%mm7, %%mm6 \n\t" // 0
879 "psubw %%mm0, %%mm6 \n\t"
880 "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
881 "movq %%mm7, %%mm6 \n\t" // 0
882 "psubw %%mm1, %%mm6 \n\t"
883 "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
884 "movq %%mm7, %%mm6 \n\t" // 0
885 "psubw %%mm2, %%mm6 \n\t"
886 "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
887 "movq %%mm7, %%mm6 \n\t" // 0
888 "psubw %%mm3, %%mm6 \n\t"
889 "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
891 "movq %%mm7, %%mm6 \n\t" // 0
892 "pcmpgtw %%mm0, %%mm6 \n\t"
893 "pxor %%mm6, %%mm0 \n\t"
894 "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
895 "movq %%mm7, %%mm6 \n\t" // 0
896 "pcmpgtw %%mm1, %%mm6 \n\t"
897 "pxor %%mm6, %%mm1 \n\t"
898 "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
899 "movq %%mm7, %%mm6 \n\t" // 0
900 "pcmpgtw %%mm2, %%mm6 \n\t"
901 "pxor %%mm6, %%mm2 \n\t"
902 "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
903 "movq %%mm7, %%mm6 \n\t" // 0
904 "pcmpgtw %%mm3, %%mm6 \n\t"
905 "pxor %%mm6, %%mm3 \n\t"
906 "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
910 "pminsw %%mm2, %%mm0 \n\t"
911 "pminsw %%mm3, %%mm1 \n\t"
913 "movq %%mm0, %%mm6 \n\t"
914 "psubusw %%mm2, %%mm6 \n\t"
915 "psubw %%mm6, %%mm0 \n\t"
916 "movq %%mm1, %%mm6 \n\t"
917 "psubusw %%mm3, %%mm6 \n\t"
918 "psubw %%mm6, %%mm1 \n\t"
921 "movd %2, %%mm2 \n\t" // QP
922 "punpcklbw %%mm7, %%mm2 \n\t"
924 "movq %%mm7, %%mm6 \n\t" // 0
925 "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
926 "pxor %%mm6, %%mm4 \n\t"
927 "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
928 "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
929 "pxor %%mm7, %%mm5 \n\t"
930 "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
932 "psllw $3, %%mm2 \n\t" // 8QP
933 "movq %%mm2, %%mm3 \n\t" // 8QP
934 "pcmpgtw %%mm4, %%mm2 \n\t"
935 "pcmpgtw %%mm5, %%mm3 \n\t"
936 "pand %%mm2, %%mm4 \n\t"
937 "pand %%mm3, %%mm5 \n\t"
940 "psubusw %%mm0, %%mm4 \n\t" // hd
941 "psubusw %%mm1, %%mm5 \n\t" // ld
944 "movq "MANGLE(w05
)", %%mm2 \n\t" // 5
945 "pmullw %%mm2, %%mm4 \n\t"
946 "pmullw %%mm2, %%mm5 \n\t"
947 "movq "MANGLE(w20
)", %%mm2 \n\t" // 32
948 "paddw %%mm2, %%mm4 \n\t"
949 "paddw %%mm2, %%mm5 \n\t"
950 "psrlw $6, %%mm4 \n\t"
951 "psrlw $6, %%mm5 \n\t"
953 "movq 16(%%"REG_c
"), %%mm0 \n\t" // L3 - L4
954 "movq 24(%%"REG_c
"), %%mm1 \n\t" // H3 - H4
956 "pxor %%mm2, %%mm2 \n\t"
957 "pxor %%mm3, %%mm3 \n\t"
959 "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
960 "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
961 "pxor %%mm2, %%mm0 \n\t"
962 "pxor %%mm3, %%mm1 \n\t"
963 "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
964 "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
965 "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
966 "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
968 "pxor %%mm6, %%mm2 \n\t"
969 "pxor %%mm7, %%mm3 \n\t"
970 "pand %%mm2, %%mm4 \n\t"
971 "pand %%mm3, %%mm5 \n\t"
974 "pminsw %%mm0, %%mm4 \n\t"
975 "pminsw %%mm1, %%mm5 \n\t"
977 "movq %%mm4, %%mm2 \n\t"
978 "psubusw %%mm0, %%mm2 \n\t"
979 "psubw %%mm2, %%mm4 \n\t"
980 "movq %%mm5, %%mm2 \n\t"
981 "psubusw %%mm1, %%mm2 \n\t"
982 "psubw %%mm2, %%mm5 \n\t"
984 "pxor %%mm6, %%mm4 \n\t"
985 "pxor %%mm7, %%mm5 \n\t"
986 "psubw %%mm6, %%mm4 \n\t"
987 "psubw %%mm7, %%mm5 \n\t"
988 "packsswb %%mm5, %%mm4 \n\t"
989 "movq (%0), %%mm0 \n\t"
990 "paddb %%mm4, %%mm0 \n\t"
991 "movq %%mm0, (%0) \n\t"
992 "movq (%0, %1), %%mm0 \n\t"
993 "psubb %%mm4, %%mm0 \n\t"
994 "movq %%mm0, (%0, %1) \n\t"
997 : "r" ((x86_reg
)stride
), "m" (c
->pQPb
)
1000 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1001 const int l1
= stride
;
1002 const int l2
= stride
+ l1
;
1003 const int l3
= stride
+ l2
;
1004 const int l4
= stride
+ l3
;
1005 const int l5
= stride
+ l4
;
1006 const int l6
= stride
+ l5
;
1007 const int l7
= stride
+ l6
;
1008 const int l8
= stride
+ l7
;
1009 // const int l9= stride + l8;
1012 for(x
=0; x
<BLOCK_SIZE
; x
++){
1013 const int middleEnergy
= 5*(src
[l5
] - src
[l4
]) + 2*(src
[l3
] - src
[l6
]);
1014 if(FFABS(middleEnergy
) < 8*c
->QP
){
1015 const int q
=(src
[l4
] - src
[l5
])/2;
1016 const int leftEnergy
= 5*(src
[l3
] - src
[l2
]) + 2*(src
[l1
] - src
[l4
]);
1017 const int rightEnergy
= 5*(src
[l7
] - src
[l6
]) + 2*(src
[l5
] - src
[l8
]);
1019 int d
= FFABS(middleEnergy
) - FFMIN( FFABS(leftEnergy
), FFABS(rightEnergy
) );
1023 d
*= FFSIGN(-middleEnergy
);
1038 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1040 #endif //HAVE_ALTIVEC
1043 static inline void RENAME(dering
)(uint8_t src
[], int stride
, PPContext
*c
)
1045 #if HAVE_MMX2 || HAVE_AMD3DNOW
1047 "pxor %%mm6, %%mm6 \n\t"
1048 "pcmpeqb %%mm7, %%mm7 \n\t"
1049 "movq %2, %%mm0 \n\t"
1050 "punpcklbw %%mm6, %%mm0 \n\t"
1051 "psrlw $1, %%mm0 \n\t"
1052 "psubw %%mm7, %%mm0 \n\t"
1053 "packuswb %%mm0, %%mm0 \n\t"
1054 "movq %%mm0, %3 \n\t"
1056 "lea (%0, %1), %%"REG_a
" \n\t"
1057 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1059 // 0 1 2 3 4 5 6 7 8 9
1060 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
1064 #define REAL_FIND_MIN_MAX(addr)\
1065 "movq " #addr ", %%mm0 \n\t"\
1066 "pminub %%mm0, %%mm7 \n\t"\
1067 "pmaxub %%mm0, %%mm6 \n\t"
1069 #define REAL_FIND_MIN_MAX(addr)\
1070 "movq " #addr ", %%mm0 \n\t"\
1071 "movq %%mm7, %%mm1 \n\t"\
1072 "psubusb %%mm0, %%mm6 \n\t"\
1073 "paddb %%mm0, %%mm6 \n\t"\
1074 "psubusb %%mm0, %%mm1 \n\t"\
1075 "psubb %%mm1, %%mm7 \n\t"
1077 #define FIND_MIN_MAX(addr) REAL_FIND_MIN_MAX(addr)
1079 FIND_MIN_MAX((%%REGa
))
1080 FIND_MIN_MAX((%%REGa
, %1))
1081 FIND_MIN_MAX((%%REGa
, %1, 2))
1082 FIND_MIN_MAX((%0, %1, 4))
1083 FIND_MIN_MAX((%%REGd
))
1084 FIND_MIN_MAX((%%REGd
, %1))
1085 FIND_MIN_MAX((%%REGd
, %1, 2))
1086 FIND_MIN_MAX((%0, %1, 8))
1088 "movq %%mm7, %%mm4 \n\t"
1089 "psrlq $8, %%mm7 \n\t"
1091 "pminub %%mm4, %%mm7 \n\t" // min of pixels
1092 "pshufw $0xF9, %%mm7, %%mm4 \n\t"
1093 "pminub %%mm4, %%mm7 \n\t" // min of pixels
1094 "pshufw $0xFE, %%mm7, %%mm4 \n\t"
1095 "pminub %%mm4, %%mm7 \n\t"
1097 "movq %%mm7, %%mm1 \n\t"
1098 "psubusb %%mm4, %%mm1 \n\t"
1099 "psubb %%mm1, %%mm7 \n\t"
1100 "movq %%mm7, %%mm4 \n\t"
1101 "psrlq $16, %%mm7 \n\t"
1102 "movq %%mm7, %%mm1 \n\t"
1103 "psubusb %%mm4, %%mm1 \n\t"
1104 "psubb %%mm1, %%mm7 \n\t"
1105 "movq %%mm7, %%mm4 \n\t"
1106 "psrlq $32, %%mm7 \n\t"
1107 "movq %%mm7, %%mm1 \n\t"
1108 "psubusb %%mm4, %%mm1 \n\t"
1109 "psubb %%mm1, %%mm7 \n\t"
1113 "movq %%mm6, %%mm4 \n\t"
1114 "psrlq $8, %%mm6 \n\t"
1116 "pmaxub %%mm4, %%mm6 \n\t" // max of pixels
1117 "pshufw $0xF9, %%mm6, %%mm4 \n\t"
1118 "pmaxub %%mm4, %%mm6 \n\t"
1119 "pshufw $0xFE, %%mm6, %%mm4 \n\t"
1120 "pmaxub %%mm4, %%mm6 \n\t"
1122 "psubusb %%mm4, %%mm6 \n\t"
1123 "paddb %%mm4, %%mm6 \n\t"
1124 "movq %%mm6, %%mm4 \n\t"
1125 "psrlq $16, %%mm6 \n\t"
1126 "psubusb %%mm4, %%mm6 \n\t"
1127 "paddb %%mm4, %%mm6 \n\t"
1128 "movq %%mm6, %%mm4 \n\t"
1129 "psrlq $32, %%mm6 \n\t"
1130 "psubusb %%mm4, %%mm6 \n\t"
1131 "paddb %%mm4, %%mm6 \n\t"
1133 "movq %%mm6, %%mm0 \n\t" // max
1134 "psubb %%mm7, %%mm6 \n\t" // max - min
1135 "movd %%mm6, %%ecx \n\t"
1136 "cmpb "MANGLE(deringThreshold
)", %%cl \n\t"
1138 "lea -24(%%"REG_SP
"), %%"REG_c
" \n\t"
1139 "and "ALIGN_MASK
", %%"REG_c
" \n\t"
1140 PAVGB(%%mm0
, %%mm7
) // a=(max + min)/2
1141 "punpcklbw %%mm7, %%mm7 \n\t"
1142 "punpcklbw %%mm7, %%mm7 \n\t"
1143 "punpcklbw %%mm7, %%mm7 \n\t"
1144 "movq %%mm7, (%%"REG_c
") \n\t"
1146 "movq (%0), %%mm0 \n\t" // L10
1147 "movq %%mm0, %%mm1 \n\t" // L10
1148 "movq %%mm0, %%mm2 \n\t" // L10
1149 "psllq $8, %%mm1 \n\t"
1150 "psrlq $8, %%mm2 \n\t"
1151 "movd -4(%0), %%mm3 \n\t"
1152 "movd 8(%0), %%mm4 \n\t"
1153 "psrlq $24, %%mm3 \n\t"
1154 "psllq $56, %%mm4 \n\t"
1155 "por %%mm3, %%mm1 \n\t" // L00
1156 "por %%mm4, %%mm2 \n\t" // L20
1157 "movq %%mm1, %%mm3 \n\t" // L00
1158 PAVGB(%%mm2
, %%mm1
) // (L20 + L00)/2
1159 PAVGB(%%mm0
, %%mm1
) // (L20 + L00 + 2L10)/4
1160 "psubusb %%mm7, %%mm0 \n\t"
1161 "psubusb %%mm7, %%mm2 \n\t"
1162 "psubusb %%mm7, %%mm3 \n\t"
1163 "pcmpeqb "MANGLE(b00
)", %%mm0 \n\t" // L10 > a ? 0 : -1
1164 "pcmpeqb "MANGLE(b00
)", %%mm2 \n\t" // L20 > a ? 0 : -1
1165 "pcmpeqb "MANGLE(b00
)", %%mm3 \n\t" // L00 > a ? 0 : -1
1166 "paddb %%mm2, %%mm0 \n\t"
1167 "paddb %%mm3, %%mm0 \n\t"
1169 "movq (%%"REG_a
"), %%mm2 \n\t" // L11
1170 "movq %%mm2, %%mm3 \n\t" // L11
1171 "movq %%mm2, %%mm4 \n\t" // L11
1172 "psllq $8, %%mm3 \n\t"
1173 "psrlq $8, %%mm4 \n\t"
1174 "movd -4(%%"REG_a
"), %%mm5 \n\t"
1175 "movd 8(%%"REG_a
"), %%mm6 \n\t"
1176 "psrlq $24, %%mm5 \n\t"
1177 "psllq $56, %%mm6 \n\t"
1178 "por %%mm5, %%mm3 \n\t" // L01
1179 "por %%mm6, %%mm4 \n\t" // L21
1180 "movq %%mm3, %%mm5 \n\t" // L01
1181 PAVGB(%%mm4
, %%mm3
) // (L21 + L01)/2
1182 PAVGB(%%mm2
, %%mm3
) // (L21 + L01 + 2L11)/4
1183 "psubusb %%mm7, %%mm2 \n\t"
1184 "psubusb %%mm7, %%mm4 \n\t"
1185 "psubusb %%mm7, %%mm5 \n\t"
1186 "pcmpeqb "MANGLE(b00
)", %%mm2 \n\t" // L11 > a ? 0 : -1
1187 "pcmpeqb "MANGLE(b00
)", %%mm4 \n\t" // L21 > a ? 0 : -1
1188 "pcmpeqb "MANGLE(b00
)", %%mm5 \n\t" // L01 > a ? 0 : -1
1189 "paddb %%mm4, %%mm2 \n\t"
1190 "paddb %%mm5, %%mm2 \n\t"
1192 #define REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
1193 "movq " #src ", " #sx " \n\t" /* src[0] */\
1194 "movq " #sx ", " #lx " \n\t" /* src[0] */\
1195 "movq " #sx ", " #t0 " \n\t" /* src[0] */\
1196 "psllq $8, " #lx " \n\t"\
1197 "psrlq $8, " #t0 " \n\t"\
1198 "movd -4" #src ", " #t1 " \n\t"\
1199 "psrlq $24, " #t1 " \n\t"\
1200 "por " #t1 ", " #lx " \n\t" /* src[-1] */\
1201 "movd 8" #src ", " #t1 " \n\t"\
1202 "psllq $56, " #t1 " \n\t"\
1203 "por " #t1 ", " #t0 " \n\t" /* src[+1] */\
1204 "movq " #lx ", " #t1 " \n\t" /* src[-1] */\
1205 PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
1206 PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
1208 "movq " #lx ", 8(%%"REG_c") \n\t"\
1209 "movq (%%"REG_c"), " #lx " \n\t"\
1210 "psubusb " #lx ", " #t1 " \n\t"\
1211 "psubusb " #lx ", " #t0 " \n\t"\
1212 "psubusb " #lx ", " #sx " \n\t"\
1213 "movq "MANGLE(b00)", " #lx " \n\t"\
1214 "pcmpeqb " #lx ", " #t1 " \n\t" /* src[-1] > a ? 0 : -1*/\
1215 "pcmpeqb " #lx ", " #t0 " \n\t" /* src[+1] > a ? 0 : -1*/\
1216 "pcmpeqb " #lx ", " #sx " \n\t" /* src[0] > a ? 0 : -1*/\
1217 "paddb " #t1 ", " #t0 " \n\t"\
1218 "paddb " #t0 ", " #sx " \n\t"\
1220 PAVGB(plx, pplx) /* filtered */\
1221 "movq " #dst ", " #t0 " \n\t" /* dst */\
1222 "movq " #t0 ", " #t1 " \n\t" /* dst */\
1223 "psubusb %3, " #t0 " \n\t"\
1224 "paddusb %3, " #t1 " \n\t"\
1226 PMINUB(t1, pplx, t0)\
1227 "paddb " #sx ", " #ppsx " \n\t"\
1228 "paddb " #psx ", " #ppsx " \n\t"\
1229 "#paddb "MANGLE(b02)", " #ppsx " \n\t"\
1230 "pand "MANGLE(b08)", " #ppsx " \n\t"\
1231 "pcmpeqb " #lx ", " #ppsx " \n\t"\
1232 "pand " #ppsx ", " #pplx " \n\t"\
1233 "pandn " #dst ", " #ppsx " \n\t"\
1234 "por " #pplx ", " #ppsx " \n\t"\
1235 "movq " #ppsx ", " #dst " \n\t"\
1236 "movq 8(%%"REG_c"), " #lx " \n\t"
1238 #define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
1239 REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1)
1255 //DERING_CORE(dst ,src ,ppsx ,psx ,sx ,pplx ,plx ,lx ,t0 ,t1)
1256 DERING_CORE((%%REGa
) ,(%%REGa
, %1) ,%%mm0
,%%mm2
,%%mm4
,%%mm1
,%%mm3
,%%mm5
,%%mm6
,%%mm7
)
1257 DERING_CORE((%%REGa
, %1) ,(%%REGa
, %1, 2),%%mm2
,%%mm4
,%%mm0
,%%mm3
,%%mm5
,%%mm1
,%%mm6
,%%mm7
)
1258 DERING_CORE((%%REGa
, %1, 2),(%0, %1, 4) ,%%mm4
,%%mm0
,%%mm2
,%%mm5
,%%mm1
,%%mm3
,%%mm6
,%%mm7
)
1259 DERING_CORE((%0, %1, 4) ,(%%REGd
) ,%%mm0
,%%mm2
,%%mm4
,%%mm1
,%%mm3
,%%mm5
,%%mm6
,%%mm7
)
1260 DERING_CORE((%%REGd
) ,(%%REGd
, %1) ,%%mm2
,%%mm4
,%%mm0
,%%mm3
,%%mm5
,%%mm1
,%%mm6
,%%mm7
)
1261 DERING_CORE((%%REGd
, %1) ,(%%REGd
, %1, 2),%%mm4
,%%mm0
,%%mm2
,%%mm5
,%%mm1
,%%mm3
,%%mm6
,%%mm7
)
1262 DERING_CORE((%%REGd
, %1, 2),(%0, %1, 8) ,%%mm0
,%%mm2
,%%mm4
,%%mm1
,%%mm3
,%%mm5
,%%mm6
,%%mm7
)
1263 DERING_CORE((%0, %1, 8) ,(%%REGd
, %1, 4),%%mm2
,%%mm4
,%%mm0
,%%mm3
,%%mm5
,%%mm1
,%%mm6
,%%mm7
)
1266 : : "r" (src
), "r" ((x86_reg
)stride
), "m" (c
->pQPb
), "m"(c
->pQPb2
)
1267 : "%"REG_a
, "%"REG_d
, "%"REG_c
1269 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1276 const int QP2
= c
->QP
/2 + 1;
1283 if(*p
> max
) max
= *p
;
1284 if(*p
< min
) min
= *p
;
1287 avg
= (min
+ max
+ 1)>>1;
1289 if(max
- min
<deringThreshold
) return;
1291 for(y
=0; y
<10; y
++){
1294 if(src
[stride
*y
+ 0] > avg
) t
+= 1;
1295 if(src
[stride
*y
+ 1] > avg
) t
+= 2;
1296 if(src
[stride
*y
+ 2] > avg
) t
+= 4;
1297 if(src
[stride
*y
+ 3] > avg
) t
+= 8;
1298 if(src
[stride
*y
+ 4] > avg
) t
+= 16;
1299 if(src
[stride
*y
+ 5] > avg
) t
+= 32;
1300 if(src
[stride
*y
+ 6] > avg
) t
+= 64;
1301 if(src
[stride
*y
+ 7] > avg
) t
+= 128;
1302 if(src
[stride
*y
+ 8] > avg
) t
+= 256;
1303 if(src
[stride
*y
+ 9] > avg
) t
+= 512;
1306 t
&= (t
<<1) & (t
>>1);
1311 int t
= s
[y
-1] & s
[y
] & s
[y
+1];
1324 int f
= (*(p
-stride
-1)) + 2*(*(p
-stride
)) + (*(p
-stride
+1))
1325 +2*(*(p
-1)) + 4*(*p
) + 2*(*(p
+1))
1326 +(*(p
+stride
-1)) + 2*(*(p
+stride
)) + (*(p
+stride
+1));
1329 #ifdef DEBUG_DERING_THRESHOLD
1330 __asm__
volatile("emms\n\t":);
1332 static long long numPixels
=0;
1333 if(x
!=1 && x
!=8 && y
!=1 && y
!=8) numPixels
++;
1334 // if((max-min)<20 || (max-min)*QP<200)
1335 // if((max-min)*QP < 500)
1338 static int numSkipped
=0;
1339 static int errorSum
=0;
1340 static int worstQP
=0;
1341 static int worstRange
=0;
1342 static int worstDiff
=0;
1344 int absDiff
= FFABS(diff
);
1345 int error
= diff
*diff
;
1347 if(x
==1 || x
==8 || y
==1 || y
==8) continue;
1350 if(absDiff
> worstDiff
){
1353 worstRange
= max
-min
;
1357 if(1024LL*1024LL*1024LL % numSkipped
== 0){
1358 av_log(c
, AV_LOG_INFO
, "sum:%1.3f, skip:%d, wQP:%d, "
1359 "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
1360 (float)errorSum
/numSkipped
, numSkipped
, worstQP
, worstRange
,
1361 worstDiff
, (float)numSkipped
/numPixels
);
1366 if (*p
+ QP2
< f
) *p
= *p
+ QP2
;
1367 else if(*p
- QP2
> f
) *p
= *p
- QP2
;
1372 #ifdef DEBUG_DERING_THRESHOLD
1380 *p
= FFMIN(*p
+ 20, 255);
1383 // src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
1386 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1388 #endif //HAVE_ALTIVEC
1391 * Deinterlaces the given block by linearly interpolating every second line.
1392 * will be called for every 8x8 block and can read & write from line 4-15
1393 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1394 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1396 static inline void RENAME(deInterlaceInterpolateLinear
)(uint8_t src
[], int stride
)
1398 #if HAVE_MMX2 || HAVE_AMD3DNOW
1401 "lea (%0, %1), %%"REG_a
" \n\t"
1402 "lea (%%"REG_a
", %1, 4), %%"REG_c
" \n\t"
1403 // 0 1 2 3 4 5 6 7 8 9
1404 // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
1406 "movq (%0), %%mm0 \n\t"
1407 "movq (%%"REG_a
", %1), %%mm1 \n\t"
1409 "movq %%mm0, (%%"REG_a
") \n\t"
1410 "movq (%0, %1, 4), %%mm0 \n\t"
1412 "movq %%mm1, (%%"REG_a
", %1, 2) \n\t"
1413 "movq (%%"REG_c
", %1), %%mm1 \n\t"
1415 "movq %%mm0, (%%"REG_c
") \n\t"
1416 "movq (%0, %1, 8), %%mm0 \n\t"
1418 "movq %%mm1, (%%"REG_c
", %1, 2) \n\t"
1420 : : "r" (src
), "r" ((x86_reg
)stride
)
1421 : "%"REG_a
, "%"REG_c
1428 a
= *(uint32_t*)&src
[stride
*0];
1429 b
= *(uint32_t*)&src
[stride
*2];
1430 *(uint32_t*)&src
[stride
*1]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1431 a
= *(uint32_t*)&src
[stride
*4];
1432 *(uint32_t*)&src
[stride
*3]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1433 b
= *(uint32_t*)&src
[stride
*6];
1434 *(uint32_t*)&src
[stride
*5]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1435 a
= *(uint32_t*)&src
[stride
*8];
1436 *(uint32_t*)&src
[stride
*7]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1443 * Deinterlaces the given block by cubic interpolating every second line.
1444 * will be called for every 8x8 block and can read & write from line 4-15
1445 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1446 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1447 * this filter will read lines 3-15 and write 7-13
1449 static inline void RENAME(deInterlaceInterpolateCubic
)(uint8_t src
[], int stride
)
1451 #if HAVE_MMX2 || HAVE_AMD3DNOW
1454 "lea (%0, %1), %%"REG_a
" \n\t"
1455 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1456 "lea (%%"REG_d
", %1, 4), %%"REG_c
" \n\t"
1457 "add %1, %%"REG_c
" \n\t"
1458 "pxor %%mm7, %%mm7 \n\t"
1459 // 0 1 2 3 4 5 6 7 8 9 10
1460 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
1462 #define REAL_DEINT_CUBIC(a,b,c,d,e)\
1463 "movq " #a ", %%mm0 \n\t"\
1464 "movq " #b ", %%mm1 \n\t"\
1465 "movq " #d ", %%mm2 \n\t"\
1466 "movq " #e ", %%mm3 \n\t"\
1467 PAVGB(%%mm2, %%mm1) /* (b+d) /2 */\
1468 PAVGB(%%mm3, %%mm0) /* a(a+e) /2 */\
1469 "movq %%mm0, %%mm2 \n\t"\
1470 "punpcklbw %%mm7, %%mm0 \n\t"\
1471 "punpckhbw %%mm7, %%mm2 \n\t"\
1472 "movq %%mm1, %%mm3 \n\t"\
1473 "punpcklbw %%mm7, %%mm1 \n\t"\
1474 "punpckhbw %%mm7, %%mm3 \n\t"\
1475 "psubw %%mm1, %%mm0 \n\t" /* L(a+e - (b+d))/2 */\
1476 "psubw %%mm3, %%mm2 \n\t" /* H(a+e - (b+d))/2 */\
1477 "psraw $3, %%mm0 \n\t" /* L(a+e - (b+d))/16 */\
1478 "psraw $3, %%mm2 \n\t" /* H(a+e - (b+d))/16 */\
1479 "psubw %%mm0, %%mm1 \n\t" /* L(9b + 9d - a - e)/16 */\
1480 "psubw %%mm2, %%mm3 \n\t" /* H(9b + 9d - a - e)/16 */\
1481 "packuswb %%mm3, %%mm1 \n\t"\
1482 "movq %%mm1, " #c " \n\t"
1483 #define DEINT_CUBIC(a,b,c,d,e) REAL_DEINT_CUBIC(a,b,c,d,e)
1485 DEINT_CUBIC((%0) , (%%REGa
, %1), (%%REGa
, %1, 2), (%0, %1, 4) , (%%REGd
, %1))
1486 DEINT_CUBIC((%%REGa
, %1), (%0, %1, 4) , (%%REGd
) , (%%REGd
, %1), (%0, %1, 8))
1487 DEINT_CUBIC((%0, %1, 4) , (%%REGd
, %1), (%%REGd
, %1, 2), (%0, %1, 8) , (%%REGc
))
1488 DEINT_CUBIC((%%REGd
, %1), (%0, %1, 8) , (%%REGd
, %1, 4), (%%REGc
) , (%%REGc
, %1, 2))
1490 : : "r" (src
), "r" ((x86_reg
)stride
)
1491 : "%"REG_a
, "%"REG_d
, "%"REG_c
1493 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1497 src
[stride
*3] = CLIP((-src
[0] + 9*src
[stride
*2] + 9*src
[stride
*4] - src
[stride
*6])>>4);
1498 src
[stride
*5] = CLIP((-src
[stride
*2] + 9*src
[stride
*4] + 9*src
[stride
*6] - src
[stride
*8])>>4);
1499 src
[stride
*7] = CLIP((-src
[stride
*4] + 9*src
[stride
*6] + 9*src
[stride
*8] - src
[stride
*10])>>4);
1500 src
[stride
*9] = CLIP((-src
[stride
*6] + 9*src
[stride
*8] + 9*src
[stride
*10] - src
[stride
*12])>>4);
1503 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1507 * Deinterlaces the given block by filtering every second line with a (-1 4 2 4 -1) filter.
1508 * will be called for every 8x8 block and can read & write from line 4-15
1509 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1510 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1511 * this filter will read lines 4-13 and write 5-11
1513 static inline void RENAME(deInterlaceFF
)(uint8_t src
[], int stride
, uint8_t *tmp
)
1515 #if HAVE_MMX2 || HAVE_AMD3DNOW
1518 "lea (%0, %1), %%"REG_a
" \n\t"
1519 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1520 "pxor %%mm7, %%mm7 \n\t"
1521 "movq (%2), %%mm0 \n\t"
1522 // 0 1 2 3 4 5 6 7 8 9 10
1523 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
1525 #define REAL_DEINT_FF(a,b,c,d)\
1526 "movq " #a ", %%mm1 \n\t"\
1527 "movq " #b ", %%mm2 \n\t"\
1528 "movq " #c ", %%mm3 \n\t"\
1529 "movq " #d ", %%mm4 \n\t"\
1530 PAVGB(%%mm3, %%mm1) \
1531 PAVGB(%%mm4, %%mm0) \
1532 "movq %%mm0, %%mm3 \n\t"\
1533 "punpcklbw %%mm7, %%mm0 \n\t"\
1534 "punpckhbw %%mm7, %%mm3 \n\t"\
1535 "movq %%mm1, %%mm4 \n\t"\
1536 "punpcklbw %%mm7, %%mm1 \n\t"\
1537 "punpckhbw %%mm7, %%mm4 \n\t"\
1538 "psllw $2, %%mm1 \n\t"\
1539 "psllw $2, %%mm4 \n\t"\
1540 "psubw %%mm0, %%mm1 \n\t"\
1541 "psubw %%mm3, %%mm4 \n\t"\
1542 "movq %%mm2, %%mm5 \n\t"\
1543 "movq %%mm2, %%mm0 \n\t"\
1544 "punpcklbw %%mm7, %%mm2 \n\t"\
1545 "punpckhbw %%mm7, %%mm5 \n\t"\
1546 "paddw %%mm2, %%mm1 \n\t"\
1547 "paddw %%mm5, %%mm4 \n\t"\
1548 "psraw $2, %%mm1 \n\t"\
1549 "psraw $2, %%mm4 \n\t"\
1550 "packuswb %%mm4, %%mm1 \n\t"\
1551 "movq %%mm1, " #b " \n\t"\
1553 #define DEINT_FF(a,b,c,d) REAL_DEINT_FF(a,b,c,d)
1555 DEINT_FF((%0) , (%%REGa
) , (%%REGa
, %1), (%%REGa
, %1, 2))
1556 DEINT_FF((%%REGa
, %1), (%%REGa
, %1, 2), (%0, %1, 4) , (%%REGd
) )
1557 DEINT_FF((%0, %1, 4) , (%%REGd
) , (%%REGd
, %1), (%%REGd
, %1, 2))
1558 DEINT_FF((%%REGd
, %1), (%%REGd
, %1, 2), (%0, %1, 8) , (%%REGd
, %1, 4))
1560 "movq %%mm0, (%2) \n\t"
1561 : : "r" (src
), "r" ((x86_reg
)stride
), "r"(tmp
)
1562 : "%"REG_a
, "%"REG_d
1564 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1569 int t2
= src
[stride
*1];
1571 src
[stride
*1]= CLIP((-t1
+ 4*src
[stride
*0] + 2*t2
+ 4*src
[stride
*2] - src
[stride
*3] + 4)>>3);
1573 src
[stride
*3]= CLIP((-t2
+ 4*src
[stride
*2] + 2*t1
+ 4*src
[stride
*4] - src
[stride
*5] + 4)>>3);
1575 src
[stride
*5]= CLIP((-t1
+ 4*src
[stride
*4] + 2*t2
+ 4*src
[stride
*6] - src
[stride
*7] + 4)>>3);
1577 src
[stride
*7]= CLIP((-t2
+ 4*src
[stride
*6] + 2*t1
+ 4*src
[stride
*8] - src
[stride
*9] + 4)>>3);
1582 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1586 * Deinterlaces the given block by filtering every line with a (-1 2 6 2 -1) filter.
1587 * will be called for every 8x8 block and can read & write from line 4-15
1588 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1589 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1590 * this filter will read lines 4-13 and write 4-11
1592 static inline void RENAME(deInterlaceL5
)(uint8_t src
[], int stride
, uint8_t *tmp
, uint8_t *tmp2
)
1594 #if HAVE_MMX2 || HAVE_AMD3DNOW
1597 "lea (%0, %1), %%"REG_a
" \n\t"
1598 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1599 "pxor %%mm7, %%mm7 \n\t"
1600 "movq (%2), %%mm0 \n\t"
1601 "movq (%3), %%mm1 \n\t"
1602 // 0 1 2 3 4 5 6 7 8 9 10
1603 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
1605 #define REAL_DEINT_L5(t1,t2,a,b,c)\
1606 "movq " #a ", %%mm2 \n\t"\
1607 "movq " #b ", %%mm3 \n\t"\
1608 "movq " #c ", %%mm4 \n\t"\
1611 "movq %%mm2, %%mm5 \n\t"\
1612 "movq %%mm2, " #t1 " \n\t"\
1613 "punpcklbw %%mm7, %%mm2 \n\t"\
1614 "punpckhbw %%mm7, %%mm5 \n\t"\
1615 "movq %%mm2, %%mm6 \n\t"\
1616 "paddw %%mm2, %%mm2 \n\t"\
1617 "paddw %%mm6, %%mm2 \n\t"\
1618 "movq %%mm5, %%mm6 \n\t"\
1619 "paddw %%mm5, %%mm5 \n\t"\
1620 "paddw %%mm6, %%mm5 \n\t"\
1621 "movq %%mm3, %%mm6 \n\t"\
1622 "punpcklbw %%mm7, %%mm3 \n\t"\
1623 "punpckhbw %%mm7, %%mm6 \n\t"\
1624 "paddw %%mm3, %%mm3 \n\t"\
1625 "paddw %%mm6, %%mm6 \n\t"\
1626 "paddw %%mm3, %%mm2 \n\t"\
1627 "paddw %%mm6, %%mm5 \n\t"\
1628 "movq %%mm4, %%mm6 \n\t"\
1629 "punpcklbw %%mm7, %%mm4 \n\t"\
1630 "punpckhbw %%mm7, %%mm6 \n\t"\
1631 "psubw %%mm4, %%mm2 \n\t"\
1632 "psubw %%mm6, %%mm5 \n\t"\
1633 "psraw $2, %%mm2 \n\t"\
1634 "psraw $2, %%mm5 \n\t"\
1635 "packuswb %%mm5, %%mm2 \n\t"\
1636 "movq %%mm2, " #a " \n\t"\
1638 #define DEINT_L5(t1,t2,a,b,c) REAL_DEINT_L5(t1,t2,a,b,c)
1640 DEINT_L5(%%mm0
, %%mm1
, (%0) , (%%REGa
) , (%%REGa
, %1) )
1641 DEINT_L5(%%mm1
, %%mm0
, (%%REGa
) , (%%REGa
, %1) , (%%REGa
, %1, 2))
1642 DEINT_L5(%%mm0
, %%mm1
, (%%REGa
, %1) , (%%REGa
, %1, 2), (%0, %1, 4) )
1643 DEINT_L5(%%mm1
, %%mm0
, (%%REGa
, %1, 2), (%0, %1, 4) , (%%REGd
) )
1644 DEINT_L5(%%mm0
, %%mm1
, (%0, %1, 4) , (%%REGd
) , (%%REGd
, %1) )
1645 DEINT_L5(%%mm1
, %%mm0
, (%%REGd
) , (%%REGd
, %1) , (%%REGd
, %1, 2))
1646 DEINT_L5(%%mm0
, %%mm1
, (%%REGd
, %1) , (%%REGd
, %1, 2), (%0, %1, 8) )
1647 DEINT_L5(%%mm1
, %%mm0
, (%%REGd
, %1, 2), (%0, %1, 8) , (%%REGd
, %1, 4))
1649 "movq %%mm0, (%2) \n\t"
1650 "movq %%mm1, (%3) \n\t"
1651 : : "r" (src
), "r" ((x86_reg
)stride
), "r"(tmp
), "r"(tmp2
)
1652 : "%"REG_a
, "%"REG_d
1654 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1662 src
[stride
*0]= CLIP((-(t1
+ src
[stride
*2]) + 2*(t2
+ src
[stride
*1]) + 6*t3
+ 4)>>3);
1664 src
[stride
*1]= CLIP((-(t2
+ src
[stride
*3]) + 2*(t3
+ src
[stride
*2]) + 6*t1
+ 4)>>3);
1666 src
[stride
*2]= CLIP((-(t3
+ src
[stride
*4]) + 2*(t1
+ src
[stride
*3]) + 6*t2
+ 4)>>3);
1668 src
[stride
*3]= CLIP((-(t1
+ src
[stride
*5]) + 2*(t2
+ src
[stride
*4]) + 6*t3
+ 4)>>3);
1670 src
[stride
*4]= CLIP((-(t2
+ src
[stride
*6]) + 2*(t3
+ src
[stride
*5]) + 6*t1
+ 4)>>3);
1672 src
[stride
*5]= CLIP((-(t3
+ src
[stride
*7]) + 2*(t1
+ src
[stride
*6]) + 6*t2
+ 4)>>3);
1674 src
[stride
*6]= CLIP((-(t1
+ src
[stride
*8]) + 2*(t2
+ src
[stride
*7]) + 6*t3
+ 4)>>3);
1676 src
[stride
*7]= CLIP((-(t2
+ src
[stride
*9]) + 2*(t3
+ src
[stride
*8]) + 6*t1
+ 4)>>3);
1683 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1687 * Deinterlaces the given block by filtering all lines with a (1 2 1) filter.
1688 * will be called for every 8x8 block and can read & write from line 4-15
1689 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1690 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1691 * this filter will read lines 4-13 and write 4-11
1693 static inline void RENAME(deInterlaceBlendLinear
)(uint8_t src
[], int stride
, uint8_t *tmp
)
1695 #if HAVE_MMX2 || HAVE_AMD3DNOW
1698 "lea (%0, %1), %%"REG_a
" \n\t"
1699 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1700 // 0 1 2 3 4 5 6 7 8 9
1701 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
1703 "movq (%2), %%mm0 \n\t" // L0
1704 "movq (%%"REG_a
"), %%mm1 \n\t" // L2
1705 PAVGB(%%mm1
, %%mm0
) // L0+L2
1706 "movq (%0), %%mm2 \n\t" // L1
1708 "movq %%mm0, (%0) \n\t"
1709 "movq (%%"REG_a
", %1), %%mm0 \n\t" // L3
1710 PAVGB(%%mm0
, %%mm2
) // L1+L3
1711 PAVGB(%%mm1
, %%mm2
) // 2L2 + L1 + L3
1712 "movq %%mm2, (%%"REG_a
") \n\t"
1713 "movq (%%"REG_a
", %1, 2), %%mm2 \n\t" // L4
1714 PAVGB(%%mm2
, %%mm1
) // L2+L4
1715 PAVGB(%%mm0
, %%mm1
) // 2L3 + L2 + L4
1716 "movq %%mm1, (%%"REG_a
", %1) \n\t"
1717 "movq (%0, %1, 4), %%mm1 \n\t" // L5
1718 PAVGB(%%mm1
, %%mm0
) // L3+L5
1719 PAVGB(%%mm2
, %%mm0
) // 2L4 + L3 + L5
1720 "movq %%mm0, (%%"REG_a
", %1, 2) \n\t"
1721 "movq (%%"REG_d
"), %%mm0 \n\t" // L6
1722 PAVGB(%%mm0
, %%mm2
) // L4+L6
1723 PAVGB(%%mm1
, %%mm2
) // 2L5 + L4 + L6
1724 "movq %%mm2, (%0, %1, 4) \n\t"
1725 "movq (%%"REG_d
", %1), %%mm2 \n\t" // L7
1726 PAVGB(%%mm2
, %%mm1
) // L5+L7
1727 PAVGB(%%mm0
, %%mm1
) // 2L6 + L5 + L7
1728 "movq %%mm1, (%%"REG_d
") \n\t"
1729 "movq (%%"REG_d
", %1, 2), %%mm1 \n\t" // L8
1730 PAVGB(%%mm1
, %%mm0
) // L6+L8
1731 PAVGB(%%mm2
, %%mm0
) // 2L7 + L6 + L8
1732 "movq %%mm0, (%%"REG_d
", %1) \n\t"
1733 "movq (%0, %1, 8), %%mm0 \n\t" // L9
1734 PAVGB(%%mm0
, %%mm2
) // L7+L9
1735 PAVGB(%%mm1
, %%mm2
) // 2L8 + L7 + L9
1736 "movq %%mm2, (%%"REG_d
", %1, 2) \n\t"
1737 "movq %%mm1, (%2) \n\t"
1739 : : "r" (src
), "r" ((x86_reg
)stride
), "r" (tmp
)
1740 : "%"REG_a
, "%"REG_d
1742 #else //HAVE_MMX2 || HAVE_AMD3DNOW
1747 a
= *(uint32_t*)&tmp
[stride
*0];
1748 b
= *(uint32_t*)&src
[stride
*0];
1749 c
= *(uint32_t*)&src
[stride
*1];
1750 a
= (a
&c
) + (((a
^c
)&0xFEFEFEFEUL
)>>1);
1751 *(uint32_t*)&src
[stride
*0]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1753 a
= *(uint32_t*)&src
[stride
*2];
1754 b
= (a
&b
) + (((a
^b
)&0xFEFEFEFEUL
)>>1);
1755 *(uint32_t*)&src
[stride
*1]= (c
|b
) - (((c
^b
)&0xFEFEFEFEUL
)>>1);
1757 b
= *(uint32_t*)&src
[stride
*3];
1758 c
= (b
&c
) + (((b
^c
)&0xFEFEFEFEUL
)>>1);
1759 *(uint32_t*)&src
[stride
*2]= (c
|a
) - (((c
^a
)&0xFEFEFEFEUL
)>>1);
1761 c
= *(uint32_t*)&src
[stride
*4];
1762 a
= (a
&c
) + (((a
^c
)&0xFEFEFEFEUL
)>>1);
1763 *(uint32_t*)&src
[stride
*3]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1765 a
= *(uint32_t*)&src
[stride
*5];
1766 b
= (a
&b
) + (((a
^b
)&0xFEFEFEFEUL
)>>1);
1767 *(uint32_t*)&src
[stride
*4]= (c
|b
) - (((c
^b
)&0xFEFEFEFEUL
)>>1);
1769 b
= *(uint32_t*)&src
[stride
*6];
1770 c
= (b
&c
) + (((b
^c
)&0xFEFEFEFEUL
)>>1);
1771 *(uint32_t*)&src
[stride
*5]= (c
|a
) - (((c
^a
)&0xFEFEFEFEUL
)>>1);
1773 c
= *(uint32_t*)&src
[stride
*7];
1774 a
= (a
&c
) + (((a
^c
)&0xFEFEFEFEUL
)>>1);
1775 *(uint32_t*)&src
[stride
*6]= (a
|b
) - (((a
^b
)&0xFEFEFEFEUL
)>>1);
1777 a
= *(uint32_t*)&src
[stride
*8];
1778 b
= (a
&b
) + (((a
^b
)&0xFEFEFEFEUL
)>>1);
1779 *(uint32_t*)&src
[stride
*7]= (c
|b
) - (((c
^b
)&0xFEFEFEFEUL
)>>1);
1781 *(uint32_t*)&tmp
[stride
*0]= c
;
1785 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
1789 * Deinterlaces the given block by applying a median filter to every second line.
1790 * will be called for every 8x8 block and can read & write from line 4-15,
1791 * lines 0-3 have been passed through the deblock / dering filters already, but can be read, too.
1792 * lines 4-12 will be read into the deblocking filter and should be deinterlaced
1794 static inline void RENAME(deInterlaceMedian
)(uint8_t src
[], int stride
)
1800 "lea (%0, %1), %%"REG_a
" \n\t"
1801 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1802 // 0 1 2 3 4 5 6 7 8 9
1803 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
1805 "movq (%0), %%mm0 \n\t" //
1806 "movq (%%"REG_a
", %1), %%mm2 \n\t" //
1807 "movq (%%"REG_a
"), %%mm1 \n\t" //
1808 "movq %%mm0, %%mm3 \n\t"
1809 "pmaxub %%mm1, %%mm0 \n\t" //
1810 "pminub %%mm3, %%mm1 \n\t" //
1811 "pmaxub %%mm2, %%mm1 \n\t" //
1812 "pminub %%mm1, %%mm0 \n\t"
1813 "movq %%mm0, (%%"REG_a
") \n\t"
1815 "movq (%0, %1, 4), %%mm0 \n\t" //
1816 "movq (%%"REG_a
", %1, 2), %%mm1 \n\t" //
1817 "movq %%mm2, %%mm3 \n\t"
1818 "pmaxub %%mm1, %%mm2 \n\t" //
1819 "pminub %%mm3, %%mm1 \n\t" //
1820 "pmaxub %%mm0, %%mm1 \n\t" //
1821 "pminub %%mm1, %%mm2 \n\t"
1822 "movq %%mm2, (%%"REG_a
", %1, 2) \n\t"
1824 "movq (%%"REG_d
"), %%mm2 \n\t" //
1825 "movq (%%"REG_d
", %1), %%mm1 \n\t" //
1826 "movq %%mm2, %%mm3 \n\t"
1827 "pmaxub %%mm0, %%mm2 \n\t" //
1828 "pminub %%mm3, %%mm0 \n\t" //
1829 "pmaxub %%mm1, %%mm0 \n\t" //
1830 "pminub %%mm0, %%mm2 \n\t"
1831 "movq %%mm2, (%%"REG_d
") \n\t"
1833 "movq (%%"REG_d
", %1, 2), %%mm2 \n\t" //
1834 "movq (%0, %1, 8), %%mm0 \n\t" //
1835 "movq %%mm2, %%mm3 \n\t"
1836 "pmaxub %%mm0, %%mm2 \n\t" //
1837 "pminub %%mm3, %%mm0 \n\t" //
1838 "pmaxub %%mm1, %%mm0 \n\t" //
1839 "pminub %%mm0, %%mm2 \n\t"
1840 "movq %%mm2, (%%"REG_d
", %1, 2) \n\t"
1843 : : "r" (src
), "r" ((x86_reg
)stride
)
1844 : "%"REG_a
, "%"REG_d
1847 #else // MMX without MMX2
1849 "lea (%0, %1), %%"REG_a
" \n\t"
1850 "lea (%%"REG_a
", %1, 4), %%"REG_d
" \n\t"
1851 // 0 1 2 3 4 5 6 7 8 9
1852 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
1853 "pxor %%mm7, %%mm7 \n\t"
1855 #define REAL_MEDIAN(a,b,c)\
1856 "movq " #a ", %%mm0 \n\t"\
1857 "movq " #b ", %%mm2 \n\t"\
1858 "movq " #c ", %%mm1 \n\t"\
1859 "movq %%mm0, %%mm3 \n\t"\
1860 "movq %%mm1, %%mm4 \n\t"\
1861 "movq %%mm2, %%mm5 \n\t"\
1862 "psubusb %%mm1, %%mm3 \n\t"\
1863 "psubusb %%mm2, %%mm4 \n\t"\
1864 "psubusb %%mm0, %%mm5 \n\t"\
1865 "pcmpeqb %%mm7, %%mm3 \n\t"\
1866 "pcmpeqb %%mm7, %%mm4 \n\t"\
1867 "pcmpeqb %%mm7, %%mm5 \n\t"\
1868 "movq %%mm3, %%mm6 \n\t"\
1869 "pxor %%mm4, %%mm3 \n\t"\
1870 "pxor %%mm5, %%mm4 \n\t"\
1871 "pxor %%mm6, %%mm5 \n\t"\
1872 "por %%mm3, %%mm1 \n\t"\
1873 "por %%mm4, %%mm2 \n\t"\
1874 "por %%mm5, %%mm0 \n\t"\
1875 "pand %%mm2, %%mm0 \n\t"\
1876 "pand %%mm1, %%mm0 \n\t"\
1877 "movq %%mm0, " #b " \n\t"
1878 #define MEDIAN(a,b,c) REAL_MEDIAN(a,b,c)
1880 MEDIAN((%0) , (%%REGa
) , (%%REGa
, %1))
1881 MEDIAN((%%REGa
, %1), (%%REGa
, %1, 2), (%0, %1, 4))
1882 MEDIAN((%0, %1, 4) , (%%REGd
) , (%%REGd
, %1))
1883 MEDIAN((%%REGd
, %1), (%%REGd
, %1, 2), (%0, %1, 8))
1885 : : "r" (src
), "r" ((x86_reg
)stride
)
1886 : "%"REG_a
, "%"REG_d
1892 // FIXME - there should be a way to do a few columns in parallel like w/mmx
1894 uint8_t *colsrc
= src
;
1895 for (y
=0; y
<4; y
++){
1896 int a
, b
, c
, d
, e
, f
;
1898 b
= colsrc
[stride
];
1899 c
= colsrc
[stride
*2];
1903 colsrc
[stride
] = (a
|(d
^f
)) & (b
|(d
^e
)) & (c
|(e
^f
));
1913 * transposes and shift the given 8x8 Block into dst1 and dst2
1915 static inline void RENAME(transpose1
)(uint8_t *dst1
, uint8_t *dst2
, uint8_t *src
, int srcStride
)
1918 "lea (%0, %1), %%"REG_a
" \n\t"
1919 // 0 1 2 3 4 5 6 7 8 9
1920 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
1921 "movq (%0), %%mm0 \n\t" // 12345678
1922 "movq (%%"REG_a
"), %%mm1 \n\t" // abcdefgh
1923 "movq %%mm0, %%mm2 \n\t" // 12345678
1924 "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
1925 "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
1927 "movq (%%"REG_a
", %1), %%mm1 \n\t"
1928 "movq (%%"REG_a
", %1, 2), %%mm3 \n\t"
1929 "movq %%mm1, %%mm4 \n\t"
1930 "punpcklbw %%mm3, %%mm1 \n\t"
1931 "punpckhbw %%mm3, %%mm4 \n\t"
1933 "movq %%mm0, %%mm3 \n\t"
1934 "punpcklwd %%mm1, %%mm0 \n\t"
1935 "punpckhwd %%mm1, %%mm3 \n\t"
1936 "movq %%mm2, %%mm1 \n\t"
1937 "punpcklwd %%mm4, %%mm2 \n\t"
1938 "punpckhwd %%mm4, %%mm1 \n\t"
1940 "movd %%mm0, 128(%2) \n\t"
1941 "psrlq $32, %%mm0 \n\t"
1942 "movd %%mm0, 144(%2) \n\t"
1943 "movd %%mm3, 160(%2) \n\t"
1944 "psrlq $32, %%mm3 \n\t"
1945 "movd %%mm3, 176(%2) \n\t"
1946 "movd %%mm3, 48(%3) \n\t"
1947 "movd %%mm2, 192(%2) \n\t"
1948 "movd %%mm2, 64(%3) \n\t"
1949 "psrlq $32, %%mm2 \n\t"
1950 "movd %%mm2, 80(%3) \n\t"
1951 "movd %%mm1, 96(%3) \n\t"
1952 "psrlq $32, %%mm1 \n\t"
1953 "movd %%mm1, 112(%3) \n\t"
1955 "lea (%%"REG_a
", %1, 4), %%"REG_a
" \n\t"
1957 "movq (%0, %1, 4), %%mm0 \n\t" // 12345678
1958 "movq (%%"REG_a
"), %%mm1 \n\t" // abcdefgh
1959 "movq %%mm0, %%mm2 \n\t" // 12345678
1960 "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
1961 "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
1963 "movq (%%"REG_a
", %1), %%mm1 \n\t"
1964 "movq (%%"REG_a
", %1, 2), %%mm3 \n\t"
1965 "movq %%mm1, %%mm4 \n\t"
1966 "punpcklbw %%mm3, %%mm1 \n\t"
1967 "punpckhbw %%mm3, %%mm4 \n\t"
1969 "movq %%mm0, %%mm3 \n\t"
1970 "punpcklwd %%mm1, %%mm0 \n\t"
1971 "punpckhwd %%mm1, %%mm3 \n\t"
1972 "movq %%mm2, %%mm1 \n\t"
1973 "punpcklwd %%mm4, %%mm2 \n\t"
1974 "punpckhwd %%mm4, %%mm1 \n\t"
1976 "movd %%mm0, 132(%2) \n\t"
1977 "psrlq $32, %%mm0 \n\t"
1978 "movd %%mm0, 148(%2) \n\t"
1979 "movd %%mm3, 164(%2) \n\t"
1980 "psrlq $32, %%mm3 \n\t"
1981 "movd %%mm3, 180(%2) \n\t"
1982 "movd %%mm3, 52(%3) \n\t"
1983 "movd %%mm2, 196(%2) \n\t"
1984 "movd %%mm2, 68(%3) \n\t"
1985 "psrlq $32, %%mm2 \n\t"
1986 "movd %%mm2, 84(%3) \n\t"
1987 "movd %%mm1, 100(%3) \n\t"
1988 "psrlq $32, %%mm1 \n\t"
1989 "movd %%mm1, 116(%3) \n\t"
1992 :: "r" (src
), "r" ((x86_reg
)srcStride
), "r" (dst1
), "r" (dst2
)
1998 * transposes the given 8x8 block
2000 static inline void RENAME(transpose2
)(uint8_t *dst
, int dstStride
, uint8_t *src
)
2003 "lea (%0, %1), %%"REG_a
" \n\t"
2004 "lea (%%"REG_a
",%1,4), %%"REG_d
" \n\t"
2005 // 0 1 2 3 4 5 6 7 8 9
2006 // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
2007 "movq (%2), %%mm0 \n\t" // 12345678
2008 "movq 16(%2), %%mm1 \n\t" // abcdefgh
2009 "movq %%mm0, %%mm2 \n\t" // 12345678
2010 "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
2011 "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
2013 "movq 32(%2), %%mm1 \n\t"
2014 "movq 48(%2), %%mm3 \n\t"
2015 "movq %%mm1, %%mm4 \n\t"
2016 "punpcklbw %%mm3, %%mm1 \n\t"
2017 "punpckhbw %%mm3, %%mm4 \n\t"
2019 "movq %%mm0, %%mm3 \n\t"
2020 "punpcklwd %%mm1, %%mm0 \n\t"
2021 "punpckhwd %%mm1, %%mm3 \n\t"
2022 "movq %%mm2, %%mm1 \n\t"
2023 "punpcklwd %%mm4, %%mm2 \n\t"
2024 "punpckhwd %%mm4, %%mm1 \n\t"
2026 "movd %%mm0, (%0) \n\t"
2027 "psrlq $32, %%mm0 \n\t"
2028 "movd %%mm0, (%%"REG_a
") \n\t"
2029 "movd %%mm3, (%%"REG_a
", %1) \n\t"
2030 "psrlq $32, %%mm3 \n\t"
2031 "movd %%mm3, (%%"REG_a
", %1, 2) \n\t"
2032 "movd %%mm2, (%0, %1, 4) \n\t"
2033 "psrlq $32, %%mm2 \n\t"
2034 "movd %%mm2, (%%"REG_d
") \n\t"
2035 "movd %%mm1, (%%"REG_d
", %1) \n\t"
2036 "psrlq $32, %%mm1 \n\t"
2037 "movd %%mm1, (%%"REG_d
", %1, 2) \n\t"
2040 "movq 64(%2), %%mm0 \n\t" // 12345678
2041 "movq 80(%2), %%mm1 \n\t" // abcdefgh
2042 "movq %%mm0, %%mm2 \n\t" // 12345678
2043 "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
2044 "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
2046 "movq 96(%2), %%mm1 \n\t"
2047 "movq 112(%2), %%mm3 \n\t"
2048 "movq %%mm1, %%mm4 \n\t"
2049 "punpcklbw %%mm3, %%mm1 \n\t"
2050 "punpckhbw %%mm3, %%mm4 \n\t"
2052 "movq %%mm0, %%mm3 \n\t"
2053 "punpcklwd %%mm1, %%mm0 \n\t"
2054 "punpckhwd %%mm1, %%mm3 \n\t"
2055 "movq %%mm2, %%mm1 \n\t"
2056 "punpcklwd %%mm4, %%mm2 \n\t"
2057 "punpckhwd %%mm4, %%mm1 \n\t"
2059 "movd %%mm0, 4(%0) \n\t"
2060 "psrlq $32, %%mm0 \n\t"
2061 "movd %%mm0, 4(%%"REG_a
") \n\t"
2062 "movd %%mm3, 4(%%"REG_a
", %1) \n\t"
2063 "psrlq $32, %%mm3 \n\t"
2064 "movd %%mm3, 4(%%"REG_a
", %1, 2) \n\t"
2065 "movd %%mm2, 4(%0, %1, 4) \n\t"
2066 "psrlq $32, %%mm2 \n\t"
2067 "movd %%mm2, 4(%%"REG_d
") \n\t"
2068 "movd %%mm1, 4(%%"REG_d
", %1) \n\t"
2069 "psrlq $32, %%mm1 \n\t"
2070 "movd %%mm1, 4(%%"REG_d
", %1, 2) \n\t"
2072 :: "r" (dst
), "r" ((x86_reg
)dstStride
), "r" (src
)
2073 : "%"REG_a
, "%"REG_d
2077 //static long test=0;
2080 static inline void RENAME(tempNoiseReducer
)(uint8_t *src
, int stride
,
2081 uint8_t *tempBlurred
, uint32_t *tempBlurredPast
, int *maxNoise
)
2083 // to save a register (FIXME do this outside of the loops)
2084 tempBlurredPast
[127]= maxNoise
[0];
2085 tempBlurredPast
[128]= maxNoise
[1];
2086 tempBlurredPast
[129]= maxNoise
[2];
2088 #define FAST_L2_DIFF
2089 //#define L1_DIFF //u should change the thresholds too if u try that one
2090 #if HAVE_MMX2 || HAVE_AMD3DNOW
2092 "lea (%2, %2, 2), %%"REG_a
" \n\t" // 3*stride
2093 "lea (%2, %2, 4), %%"REG_d
" \n\t" // 5*stride
2094 "lea (%%"REG_d
", %2, 2), %%"REG_c
" \n\t" // 7*stride
2095 // 0 1 2 3 4 5 6 7 8 9
2096 // %x %x+%2 %x+2%2 %x+eax %x+4%2 %x+edx %x+2eax %x+ecx %x+8%2
2098 #ifdef L1_DIFF //needs mmx2
2099 "movq (%0), %%mm0 \n\t" // L0
2100 "psadbw (%1), %%mm0 \n\t" // |L0-R0|
2101 "movq (%0, %2), %%mm1 \n\t" // L1
2102 "psadbw (%1, %2), %%mm1 \n\t" // |L1-R1|
2103 "movq (%0, %2, 2), %%mm2 \n\t" // L2
2104 "psadbw (%1, %2, 2), %%mm2 \n\t" // |L2-R2|
2105 "movq (%0, %%"REG_a
"), %%mm3 \n\t" // L3
2106 "psadbw (%1, %%"REG_a
"), %%mm3 \n\t" // |L3-R3|
2108 "movq (%0, %2, 4), %%mm4 \n\t" // L4
2109 "paddw %%mm1, %%mm0 \n\t"
2110 "psadbw (%1, %2, 4), %%mm4 \n\t" // |L4-R4|
2111 "movq (%0, %%"REG_d
"), %%mm5 \n\t" // L5
2112 "paddw %%mm2, %%mm0 \n\t"
2113 "psadbw (%1, %%"REG_d
"), %%mm5 \n\t" // |L5-R5|
2114 "movq (%0, %%"REG_a
", 2), %%mm6 \n\t" // L6
2115 "paddw %%mm3, %%mm0 \n\t"
2116 "psadbw (%1, %%"REG_a
", 2), %%mm6 \n\t" // |L6-R6|
2117 "movq (%0, %%"REG_c
"), %%mm7 \n\t" // L7
2118 "paddw %%mm4, %%mm0 \n\t"
2119 "psadbw (%1, %%"REG_c
"), %%mm7 \n\t" // |L7-R7|
2120 "paddw %%mm5, %%mm6 \n\t"
2121 "paddw %%mm7, %%mm6 \n\t"
2122 "paddw %%mm6, %%mm0 \n\t"
2124 #if defined (FAST_L2_DIFF)
2125 "pcmpeqb %%mm7, %%mm7 \n\t"
2126 "movq "MANGLE(b80
)", %%mm6 \n\t"
2127 "pxor %%mm0, %%mm0 \n\t"
2128 #define REAL_L2_DIFF_CORE(a, b)\
2129 "movq " #a ", %%mm5 \n\t"\
2130 "movq " #b ", %%mm2 \n\t"\
2131 "pxor %%mm7, %%mm2 \n\t"\
2132 PAVGB(%%mm2, %%mm5)\
2133 "paddb %%mm6, %%mm5 \n\t"\
2134 "movq %%mm5, %%mm2 \n\t"\
2135 "psllw $8, %%mm5 \n\t"\
2136 "pmaddwd %%mm5, %%mm5 \n\t"\
2137 "pmaddwd %%mm2, %%mm2 \n\t"\
2138 "paddd %%mm2, %%mm5 \n\t"\
2139 "psrld $14, %%mm5 \n\t"\
2140 "paddd %%mm5, %%mm0 \n\t"
2142 #else //defined (FAST_L2_DIFF)
2143 "pxor %%mm7, %%mm7 \n\t"
2144 "pxor %%mm0, %%mm0 \n\t"
2145 #define REAL_L2_DIFF_CORE(a, b)\
2146 "movq " #a ", %%mm5 \n\t"\
2147 "movq " #b ", %%mm2 \n\t"\
2148 "movq %%mm5, %%mm1 \n\t"\
2149 "movq %%mm2, %%mm3 \n\t"\
2150 "punpcklbw %%mm7, %%mm5 \n\t"\
2151 "punpckhbw %%mm7, %%mm1 \n\t"\
2152 "punpcklbw %%mm7, %%mm2 \n\t"\
2153 "punpckhbw %%mm7, %%mm3 \n\t"\
2154 "psubw %%mm2, %%mm5 \n\t"\
2155 "psubw %%mm3, %%mm1 \n\t"\
2156 "pmaddwd %%mm5, %%mm5 \n\t"\
2157 "pmaddwd %%mm1, %%mm1 \n\t"\
2158 "paddd %%mm1, %%mm5 \n\t"\
2159 "paddd %%mm5, %%mm0 \n\t"
2161 #endif //defined (FAST_L2_DIFF)
2163 #define L2_DIFF_CORE(a, b) REAL_L2_DIFF_CORE(a, b)
2165 L2_DIFF_CORE((%0) , (%1))
2166 L2_DIFF_CORE((%0, %2) , (%1, %2))
2167 L2_DIFF_CORE((%0, %2, 2) , (%1, %2, 2))
2168 L2_DIFF_CORE((%0, %%REGa
) , (%1, %%REGa
))
2169 L2_DIFF_CORE((%0, %2, 4) , (%1, %2, 4))
2170 L2_DIFF_CORE((%0, %%REGd
) , (%1, %%REGd
))
2171 L2_DIFF_CORE((%0, %%REGa
,2), (%1, %%REGa
,2))
2172 L2_DIFF_CORE((%0, %%REGc
) , (%1, %%REGc
))
2176 "movq %%mm0, %%mm4 \n\t"
2177 "psrlq $32, %%mm0 \n\t"
2178 "paddd %%mm0, %%mm4 \n\t"
2179 "movd %%mm4, %%ecx \n\t"
2180 "shll $2, %%ecx \n\t"
2181 "mov %3, %%"REG_d
" \n\t"
2182 "addl -4(%%"REG_d
"), %%ecx \n\t"
2183 "addl 4(%%"REG_d
"), %%ecx \n\t"
2184 "addl -1024(%%"REG_d
"), %%ecx \n\t"
2185 "addl $4, %%ecx \n\t"
2186 "addl 1024(%%"REG_d
"), %%ecx \n\t"
2187 "shrl $3, %%ecx \n\t"
2188 "movl %%ecx, (%%"REG_d
") \n\t"
2190 // "mov %3, %%"REG_c" \n\t"
2191 // "mov %%"REG_c", test \n\t"
2193 "cmpl 512(%%"REG_d
"), %%ecx \n\t"
2195 "cmpl 516(%%"REG_d
"), %%ecx \n\t"
2198 "lea (%%"REG_a
", %2, 2), %%"REG_d
" \n\t" // 5*stride
2199 "lea (%%"REG_d
", %2, 2), %%"REG_c
" \n\t" // 7*stride
2200 "movq (%0), %%mm0 \n\t" // L0
2201 "movq (%0, %2), %%mm1 \n\t" // L1
2202 "movq (%0, %2, 2), %%mm2 \n\t" // L2
2203 "movq (%0, %%"REG_a
"), %%mm3 \n\t" // L3
2204 "movq (%0, %2, 4), %%mm4 \n\t" // L4
2205 "movq (%0, %%"REG_d
"), %%mm5 \n\t" // L5
2206 "movq (%0, %%"REG_a
", 2), %%mm6 \n\t" // L6
2207 "movq (%0, %%"REG_c
"), %%mm7 \n\t" // L7
2208 "movq %%mm0, (%1) \n\t" // L0
2209 "movq %%mm1, (%1, %2) \n\t" // L1
2210 "movq %%mm2, (%1, %2, 2) \n\t" // L2
2211 "movq %%mm3, (%1, %%"REG_a
") \n\t" // L3
2212 "movq %%mm4, (%1, %2, 4) \n\t" // L4
2213 "movq %%mm5, (%1, %%"REG_d
") \n\t" // L5
2214 "movq %%mm6, (%1, %%"REG_a
", 2) \n\t" // L6
2215 "movq %%mm7, (%1, %%"REG_c
") \n\t" // L7
2219 "lea (%%"REG_a
", %2, 2), %%"REG_d
" \n\t" // 5*stride
2220 "lea (%%"REG_d
", %2, 2), %%"REG_c
" \n\t" // 7*stride
2221 "movq (%0), %%mm0 \n\t" // L0
2222 PAVGB((%1), %%mm0
) // L0
2223 "movq (%0, %2), %%mm1 \n\t" // L1
2224 PAVGB((%1, %2), %%mm1
) // L1
2225 "movq (%0, %2, 2), %%mm2 \n\t" // L2
2226 PAVGB((%1, %2, 2), %%mm2
) // L2
2227 "movq (%0, %%"REG_a
"), %%mm3 \n\t" // L3
2228 PAVGB((%1, %%REGa
), %%mm3
) // L3
2229 "movq (%0, %2, 4), %%mm4 \n\t" // L4
2230 PAVGB((%1, %2, 4), %%mm4
) // L4
2231 "movq (%0, %%"REG_d
"), %%mm5 \n\t" // L5
2232 PAVGB((%1, %%REGd
), %%mm5
) // L5
2233 "movq (%0, %%"REG_a
", 2), %%mm6 \n\t" // L6
2234 PAVGB((%1, %%REGa
, 2), %%mm6
) // L6
2235 "movq (%0, %%"REG_c
"), %%mm7 \n\t" // L7
2236 PAVGB((%1, %%REGc
), %%mm7
) // L7
2237 "movq %%mm0, (%1) \n\t" // R0
2238 "movq %%mm1, (%1, %2) \n\t" // R1
2239 "movq %%mm2, (%1, %2, 2) \n\t" // R2
2240 "movq %%mm3, (%1, %%"REG_a
") \n\t" // R3
2241 "movq %%mm4, (%1, %2, 4) \n\t" // R4
2242 "movq %%mm5, (%1, %%"REG_d
") \n\t" // R5
2243 "movq %%mm6, (%1, %%"REG_a
", 2) \n\t" // R6
2244 "movq %%mm7, (%1, %%"REG_c
") \n\t" // R7
2245 "movq %%mm0, (%0) \n\t" // L0
2246 "movq %%mm1, (%0, %2) \n\t" // L1
2247 "movq %%mm2, (%0, %2, 2) \n\t" // L2
2248 "movq %%mm3, (%0, %%"REG_a
") \n\t" // L3
2249 "movq %%mm4, (%0, %2, 4) \n\t" // L4
2250 "movq %%mm5, (%0, %%"REG_d
") \n\t" // L5
2251 "movq %%mm6, (%0, %%"REG_a
", 2) \n\t" // L6
2252 "movq %%mm7, (%0, %%"REG_c
") \n\t" // L7
2256 "cmpl 508(%%"REG_d
"), %%ecx \n\t"
2259 "lea (%%"REG_a
", %2, 2), %%"REG_d
" \n\t" // 5*stride
2260 "lea (%%"REG_d
", %2, 2), %%"REG_c
" \n\t" // 7*stride
2261 "movq (%0), %%mm0 \n\t" // L0
2262 "movq (%0, %2), %%mm1 \n\t" // L1
2263 "movq (%0, %2, 2), %%mm2 \n\t" // L2
2264 "movq (%0, %%"REG_a
"), %%mm3 \n\t" // L3
2265 "movq (%1), %%mm4 \n\t" // R0
2266 "movq (%1, %2), %%mm5 \n\t" // R1
2267 "movq (%1, %2, 2), %%mm6 \n\t" // R2
2268 "movq (%1, %%"REG_a
"), %%mm7 \n\t" // R3
2277 "movq %%mm0, (%1) \n\t" // R0
2278 "movq %%mm1, (%1, %2) \n\t" // R1
2279 "movq %%mm2, (%1, %2, 2) \n\t" // R2
2280 "movq %%mm3, (%1, %%"REG_a
") \n\t" // R3
2281 "movq %%mm0, (%0) \n\t" // L0
2282 "movq %%mm1, (%0, %2) \n\t" // L1
2283 "movq %%mm2, (%0, %2, 2) \n\t" // L2
2284 "movq %%mm3, (%0, %%"REG_a
") \n\t" // L3
2286 "movq (%0, %2, 4), %%mm0 \n\t" // L4
2287 "movq (%0, %%"REG_d
"), %%mm1 \n\t" // L5
2288 "movq (%0, %%"REG_a
", 2), %%mm2 \n\t" // L6
2289 "movq (%0, %%"REG_c
"), %%mm3 \n\t" // L7
2290 "movq (%1, %2, 4), %%mm4 \n\t" // R4
2291 "movq (%1, %%"REG_d
"), %%mm5 \n\t" // R5
2292 "movq (%1, %%"REG_a
", 2), %%mm6 \n\t" // R6
2293 "movq (%1, %%"REG_c
"), %%mm7 \n\t" // R7
2302 "movq %%mm0, (%1, %2, 4) \n\t" // R4
2303 "movq %%mm1, (%1, %%"REG_d
") \n\t" // R5
2304 "movq %%mm2, (%1, %%"REG_a
", 2) \n\t" // R6
2305 "movq %%mm3, (%1, %%"REG_c
") \n\t" // R7
2306 "movq %%mm0, (%0, %2, 4) \n\t" // L4
2307 "movq %%mm1, (%0, %%"REG_d
") \n\t" // L5
2308 "movq %%mm2, (%0, %%"REG_a
", 2) \n\t" // L6
2309 "movq %%mm3, (%0, %%"REG_c
") \n\t" // L7
2313 "lea (%%"REG_a
", %2, 2), %%"REG_d
" \n\t" // 5*stride
2314 "lea (%%"REG_d
", %2, 2), %%"REG_c
" \n\t" // 7*stride
2315 "movq (%0), %%mm0 \n\t" // L0
2316 "movq (%0, %2), %%mm1 \n\t" // L1
2317 "movq (%0, %2, 2), %%mm2 \n\t" // L2
2318 "movq (%0, %%"REG_a
"), %%mm3 \n\t" // L3
2319 "movq (%1), %%mm4 \n\t" // R0
2320 "movq (%1, %2), %%mm5 \n\t" // R1
2321 "movq (%1, %2, 2), %%mm6 \n\t" // R2
2322 "movq (%1, %%"REG_a
"), %%mm7 \n\t" // R3
2335 "movq %%mm0, (%1) \n\t" // R0
2336 "movq %%mm1, (%1, %2) \n\t" // R1
2337 "movq %%mm2, (%1, %2, 2) \n\t" // R2
2338 "movq %%mm3, (%1, %%"REG_a
") \n\t" // R3
2339 "movq %%mm0, (%0) \n\t" // L0
2340 "movq %%mm1, (%0, %2) \n\t" // L1
2341 "movq %%mm2, (%0, %2, 2) \n\t" // L2
2342 "movq %%mm3, (%0, %%"REG_a
") \n\t" // L3
2344 "movq (%0, %2, 4), %%mm0 \n\t" // L4
2345 "movq (%0, %%"REG_d
"), %%mm1 \n\t" // L5
2346 "movq (%0, %%"REG_a
", 2), %%mm2 \n\t" // L6
2347 "movq (%0, %%"REG_c
"), %%mm3 \n\t" // L7
2348 "movq (%1, %2, 4), %%mm4 \n\t" // R4
2349 "movq (%1, %%"REG_d
"), %%mm5 \n\t" // R5
2350 "movq (%1, %%"REG_a
", 2), %%mm6 \n\t" // R6
2351 "movq (%1, %%"REG_c
"), %%mm7 \n\t" // R7
2364 "movq %%mm0, (%1, %2, 4) \n\t" // R4
2365 "movq %%mm1, (%1, %%"REG_d
") \n\t" // R5
2366 "movq %%mm2, (%1, %%"REG_a
", 2) \n\t" // R6
2367 "movq %%mm3, (%1, %%"REG_c
") \n\t" // R7
2368 "movq %%mm0, (%0, %2, 4) \n\t" // L4
2369 "movq %%mm1, (%0, %%"REG_d
") \n\t" // L5
2370 "movq %%mm2, (%0, %%"REG_a
", 2) \n\t" // L6
2371 "movq %%mm3, (%0, %%"REG_c
") \n\t" // L7
2375 :: "r" (src
), "r" (tempBlurred
), "r"((x86_reg
)stride
), "m" (tempBlurredPast
)
2376 : "%"REG_a
, "%"REG_d
, "%"REG_c
, "memory"
2378 #else //HAVE_MMX2 || HAVE_AMD3DNOW
2388 int ref
= tempBlurred
[ x
+ y
*stride
];
2389 int cur
= src
[ x
+ y
*stride
];
2391 // if(x==0 || x==7) d1+= d1>>1;
2392 // if(y==0 || y==7) d1+= d1>>1;
2401 +(*(tempBlurredPast
-256))
2402 +(*(tempBlurredPast
-1))+ (*(tempBlurredPast
+1))
2403 +(*(tempBlurredPast
+256))
2406 // ((*tempBlurredPast)*3 + d + 2)>>2;
2411 64 32 16 8 4 2 1 (1)
2412 64 48 36 27 20 15 11 (33) (approx)
2413 64 56 49 43 37 33 29 (200) (approx)
2415 if(d
> maxNoise
[1]){
2416 if(d
< maxNoise
[2]){
2420 int ref
= tempBlurred
[ x
+ y
*stride
];
2421 int cur
= src
[ x
+ y
*stride
];
2422 tempBlurred
[ x
+ y
*stride
]=
2423 src
[ x
+ y
*stride
]=
2431 tempBlurred
[ x
+ y
*stride
]= src
[ x
+ y
*stride
];
2436 if(d
< maxNoise
[0]){
2440 int ref
= tempBlurred
[ x
+ y
*stride
];
2441 int cur
= src
[ x
+ y
*stride
];
2442 tempBlurred
[ x
+ y
*stride
]=
2443 src
[ x
+ y
*stride
]=
2444 (ref
*7 + cur
+ 4)>>3;
2451 int ref
= tempBlurred
[ x
+ y
*stride
];
2452 int cur
= src
[ x
+ y
*stride
];
2453 tempBlurred
[ x
+ y
*stride
]=
2454 src
[ x
+ y
*stride
]=
2455 (ref
*3 + cur
+ 2)>>2;
2461 #endif //HAVE_MMX2 || HAVE_AMD3DNOW
2463 #endif //HAVE_ALTIVEC
2467 * accurate deblock filter
2469 static av_always_inline
void RENAME(do_a_deblock
)(uint8_t *src
, int step
, int stride
, PPContext
*c
){
2470 int64_t dc_mask
, eq_mask
, both_masks
;
2471 int64_t sums
[10*8*2];
2472 src
+= step
*3; // src points to begin of the 8x8 Block
2475 "movq %0, %%mm7 \n\t"
2476 "movq %1, %%mm6 \n\t"
2477 : : "m" (c
->mmxDcOffset
[c
->nonBQP
]), "m" (c
->mmxDcThreshold
[c
->nonBQP
])
2481 "lea (%2, %3), %%"REG_a
" \n\t"
2482 // 0 1 2 3 4 5 6 7 8 9
2483 // %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
2485 "movq (%2), %%mm0 \n\t"
2486 "movq (%%"REG_a
"), %%mm1 \n\t"
2487 "movq %%mm1, %%mm3 \n\t"
2488 "movq %%mm1, %%mm4 \n\t"
2489 "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
2490 "paddb %%mm7, %%mm0 \n\t"
2491 "pcmpgtb %%mm6, %%mm0 \n\t"
2493 "movq (%%"REG_a
",%3), %%mm2 \n\t"
2494 PMAXUB(%%mm2
, %%mm4
)
2495 PMINUB(%%mm2
, %%mm3
, %%mm5
)
2496 "psubb %%mm2, %%mm1 \n\t"
2497 "paddb %%mm7, %%mm1 \n\t"
2498 "pcmpgtb %%mm6, %%mm1 \n\t"
2499 "paddb %%mm1, %%mm0 \n\t"
2501 "movq (%%"REG_a
", %3, 2), %%mm1 \n\t"
2502 PMAXUB(%%mm1
, %%mm4
)
2503 PMINUB(%%mm1
, %%mm3
, %%mm5
)
2504 "psubb %%mm1, %%mm2 \n\t"
2505 "paddb %%mm7, %%mm2 \n\t"
2506 "pcmpgtb %%mm6, %%mm2 \n\t"
2507 "paddb %%mm2, %%mm0 \n\t"
2509 "lea (%%"REG_a
", %3, 4), %%"REG_a
" \n\t"
2511 "movq (%2, %3, 4), %%mm2 \n\t"
2512 PMAXUB(%%mm2
, %%mm4
)
2513 PMINUB(%%mm2
, %%mm3
, %%mm5
)
2514 "psubb %%mm2, %%mm1 \n\t"
2515 "paddb %%mm7, %%mm1 \n\t"
2516 "pcmpgtb %%mm6, %%mm1 \n\t"
2517 "paddb %%mm1, %%mm0 \n\t"
2519 "movq (%%"REG_a
"), %%mm1 \n\t"
2520 PMAXUB(%%mm1
, %%mm4
)
2521 PMINUB(%%mm1
, %%mm3
, %%mm5
)
2522 "psubb %%mm1, %%mm2 \n\t"
2523 "paddb %%mm7, %%mm2 \n\t"
2524 "pcmpgtb %%mm6, %%mm2 \n\t"
2525 "paddb %%mm2, %%mm0 \n\t"
2527 "movq (%%"REG_a
", %3), %%mm2 \n\t"
2528 PMAXUB(%%mm2
, %%mm4
)
2529 PMINUB(%%mm2
, %%mm3
, %%mm5
)
2530 "psubb %%mm2, %%mm1 \n\t"
2531 "paddb %%mm7, %%mm1 \n\t"
2532 "pcmpgtb %%mm6, %%mm1 \n\t"
2533 "paddb %%mm1, %%mm0 \n\t"
2535 "movq (%%"REG_a
", %3, 2), %%mm1 \n\t"
2536 PMAXUB(%%mm1
, %%mm4
)
2537 PMINUB(%%mm1
, %%mm3
, %%mm5
)
2538 "psubb %%mm1, %%mm2 \n\t"
2539 "paddb %%mm7, %%mm2 \n\t"
2540 "pcmpgtb %%mm6, %%mm2 \n\t"
2541 "paddb %%mm2, %%mm0 \n\t"
2543 "movq (%2, %3, 8), %%mm2 \n\t"
2544 PMAXUB(%%mm2
, %%mm4
)
2545 PMINUB(%%mm2
, %%mm3
, %%mm5
)
2546 "psubb %%mm2, %%mm1 \n\t"
2547 "paddb %%mm7, %%mm1 \n\t"
2548 "pcmpgtb %%mm6, %%mm1 \n\t"
2549 "paddb %%mm1, %%mm0 \n\t"
2551 "movq (%%"REG_a
", %3, 4), %%mm1 \n\t"
2552 "psubb %%mm1, %%mm2 \n\t"
2553 "paddb %%mm7, %%mm2 \n\t"
2554 "pcmpgtb %%mm6, %%mm2 \n\t"
2555 "paddb %%mm2, %%mm0 \n\t"
2556 "psubusb %%mm3, %%mm4 \n\t"
2558 "pxor %%mm6, %%mm6 \n\t"
2559 "movq %4, %%mm7 \n\t" // QP,..., QP
2560 "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
2561 "psubusb %%mm4, %%mm7 \n\t" // Diff >=2QP -> 0
2562 "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
2563 "pcmpeqb %%mm6, %%mm7 \n\t" // Diff < 2QP -> 0
2564 "movq %%mm7, %1 \n\t"
2566 "movq %5, %%mm7 \n\t"
2567 "punpcklbw %%mm7, %%mm7 \n\t"
2568 "punpcklbw %%mm7, %%mm7 \n\t"
2569 "punpcklbw %%mm7, %%mm7 \n\t"
2570 "psubb %%mm0, %%mm6 \n\t"
2571 "pcmpgtb %%mm7, %%mm6 \n\t"
2572 "movq %%mm6, %0 \n\t"
2574 : "=m" (eq_mask
), "=m" (dc_mask
)
2575 : "r" (src
), "r" ((x86_reg
)step
), "m" (c
->pQPb
), "m"(c
->ppMode
.flatnessThreshold
)
2579 both_masks
= dc_mask
& eq_mask
;
2582 x86_reg offset
= -8*step
;
2583 int64_t *temp_sums
= sums
;
2586 "movq %2, %%mm0 \n\t" // QP,..., QP
2587 "pxor %%mm4, %%mm4 \n\t"
2589 "movq (%0), %%mm6 \n\t"
2590 "movq (%0, %1), %%mm5 \n\t"
2591 "movq %%mm5, %%mm1 \n\t"
2592 "movq %%mm6, %%mm2 \n\t"
2593 "psubusb %%mm6, %%mm5 \n\t"
2594 "psubusb %%mm1, %%mm2 \n\t"
2595 "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
2596 "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
2597 "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
2599 "pxor %%mm6, %%mm1 \n\t"
2600 "pand %%mm0, %%mm1 \n\t"
2601 "pxor %%mm1, %%mm6 \n\t"
2604 "movq (%0, %1, 8), %%mm5 \n\t"
2605 "add %1, %0 \n\t" // %0 points to line 1 not 0
2606 "movq (%0, %1, 8), %%mm7 \n\t"
2607 "movq %%mm5, %%mm1 \n\t"
2608 "movq %%mm7, %%mm2 \n\t"
2609 "psubusb %%mm7, %%mm5 \n\t"
2610 "psubusb %%mm1, %%mm2 \n\t"
2611 "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
2612 "movq %2, %%mm0 \n\t" // QP,..., QP
2613 "psubusb %%mm2, %%mm0 \n\t" // diff >= QP -> 0
2614 "pcmpeqb %%mm4, %%mm0 \n\t" // diff >= QP -> FF
2616 "pxor %%mm7, %%mm1 \n\t"
2617 "pand %%mm0, %%mm1 \n\t"
2618 "pxor %%mm1, %%mm7 \n\t"
2620 "movq %%mm6, %%mm5 \n\t"
2621 "punpckhbw %%mm4, %%mm6 \n\t"
2622 "punpcklbw %%mm4, %%mm5 \n\t"
2623 // 4:0 5/6:First 7:Last
2625 "movq %%mm5, %%mm0 \n\t"
2626 "movq %%mm6, %%mm1 \n\t"
2627 "psllw $2, %%mm0 \n\t"
2628 "psllw $2, %%mm1 \n\t"
2629 "paddw "MANGLE(w04
)", %%mm0 \n\t"
2630 "paddw "MANGLE(w04
)", %%mm1 \n\t"
2633 "movq (%0), %%mm2 \n\t"\
2634 "movq (%0), %%mm3 \n\t"\
2636 "punpcklbw %%mm4, %%mm2 \n\t"\
2637 "punpckhbw %%mm4, %%mm3 \n\t"\
2638 "paddw %%mm2, %%mm0 \n\t"\
2639 "paddw %%mm3, %%mm1 \n\t"
2642 "movq (%0), %%mm2 \n\t"\
2643 "movq (%0), %%mm3 \n\t"\
2645 "punpcklbw %%mm4, %%mm2 \n\t"\
2646 "punpckhbw %%mm4, %%mm3 \n\t"\
2647 "psubw %%mm2, %%mm0 \n\t"\
2648 "psubw %%mm3, %%mm1 \n\t"
2654 "movq %%mm0, (%3) \n\t"
2655 "movq %%mm1, 8(%3) \n\t"
2658 "psubw %%mm5, %%mm0 \n\t"
2659 "psubw %%mm6, %%mm1 \n\t"
2660 "movq %%mm0, 16(%3) \n\t"
2661 "movq %%mm1, 24(%3) \n\t"
2664 "psubw %%mm5, %%mm0 \n\t"
2665 "psubw %%mm6, %%mm1 \n\t"
2666 "movq %%mm0, 32(%3) \n\t"
2667 "movq %%mm1, 40(%3) \n\t"
2670 "psubw %%mm5, %%mm0 \n\t"
2671 "psubw %%mm6, %%mm1 \n\t"
2672 "movq %%mm0, 48(%3) \n\t"
2673 "movq %%mm1, 56(%3) \n\t"
2676 "psubw %%mm5, %%mm0 \n\t"
2677 "psubw %%mm6, %%mm1 \n\t"
2678 "movq %%mm0, 64(%3) \n\t"
2679 "movq %%mm1, 72(%3) \n\t"
2681 "movq %%mm7, %%mm6 \n\t"
2682 "punpckhbw %%mm4, %%mm7 \n\t"
2683 "punpcklbw %%mm4, %%mm6 \n\t"
2689 "movq %%mm0, 80(%3) \n\t"
2690 "movq %%mm1, 88(%3) \n\t"
2693 "paddw %%mm6, %%mm0 \n\t"
2694 "paddw %%mm7, %%mm1 \n\t"
2695 "movq %%mm0, 96(%3) \n\t"
2696 "movq %%mm1, 104(%3) \n\t"
2699 "paddw %%mm6, %%mm0 \n\t"
2700 "paddw %%mm7, %%mm1 \n\t"
2701 "movq %%mm0, 112(%3) \n\t"
2702 "movq %%mm1, 120(%3) \n\t"
2705 "paddw %%mm6, %%mm0 \n\t"
2706 "paddw %%mm7, %%mm1 \n\t"
2707 "movq %%mm0, 128(%3) \n\t"
2708 "movq %%mm1, 136(%3) \n\t"
2711 "paddw %%mm6, %%mm0 \n\t"
2712 "paddw %%mm7, %%mm1 \n\t"
2713 "movq %%mm0, 144(%3) \n\t"
2714 "movq %%mm1, 152(%3) \n\t"
2716 "mov %4, %0 \n\t" //FIXME
2719 : "r" ((x86_reg
)step
), "m" (c
->pQPb
), "r"(sums
), "g"(src
)
2722 src
+= step
; // src points to begin of the 8x8 Block
2725 "movq %4, %%mm6 \n\t"
2726 "pcmpeqb %%mm5, %%mm5 \n\t"
2727 "pxor %%mm6, %%mm5 \n\t"
2728 "pxor %%mm7, %%mm7 \n\t"
2731 "movq (%1), %%mm0 \n\t"
2732 "movq 8(%1), %%mm1 \n\t"
2733 "paddw 32(%1), %%mm0 \n\t"
2734 "paddw 40(%1), %%mm1 \n\t"
2735 "movq (%0, %3), %%mm2 \n\t"
2736 "movq %%mm2, %%mm3 \n\t"
2737 "movq %%mm2, %%mm4 \n\t"
2738 "punpcklbw %%mm7, %%mm2 \n\t"
2739 "punpckhbw %%mm7, %%mm3 \n\t"
2740 "paddw %%mm2, %%mm0 \n\t"
2741 "paddw %%mm3, %%mm1 \n\t"
2742 "paddw %%mm2, %%mm0 \n\t"
2743 "paddw %%mm3, %%mm1 \n\t"
2744 "psrlw $4, %%mm0 \n\t"
2745 "psrlw $4, %%mm1 \n\t"
2746 "packuswb %%mm1, %%mm0 \n\t"
2747 "pand %%mm6, %%mm0 \n\t"
2748 "pand %%mm5, %%mm4 \n\t"
2749 "por %%mm4, %%mm0 \n\t"
2750 "movq %%mm0, (%0, %3) \n\t"
2755 : "+r"(offset
), "+r"(temp_sums
)
2756 : "r" ((x86_reg
)step
), "r"(src
- offset
), "m"(both_masks
)
2759 src
+= step
; // src points to begin of the 8x8 Block
2761 if(eq_mask
!= -1LL){
2762 uint8_t *temp_src
= src
;
2764 "pxor %%mm7, %%mm7 \n\t"
2765 "lea -40(%%"REG_SP
"), %%"REG_c
" \n\t" // make space for 4 8-byte vars
2766 "and "ALIGN_MASK
", %%"REG_c
" \n\t" // align
2767 // 0 1 2 3 4 5 6 7 8 9
2768 // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
2770 "movq (%0), %%mm0 \n\t"
2771 "movq %%mm0, %%mm1 \n\t"
2772 "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
2773 "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
2775 "movq (%0, %1), %%mm2 \n\t"
2776 "lea (%0, %1, 2), %%"REG_a
" \n\t"
2777 "movq %%mm2, %%mm3 \n\t"
2778 "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
2779 "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
2781 "movq (%%"REG_a
"), %%mm4 \n\t"
2782 "movq %%mm4, %%mm5 \n\t"
2783 "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
2784 "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
2786 "paddw %%mm0, %%mm0 \n\t" // 2L0
2787 "paddw %%mm1, %%mm1 \n\t" // 2H0
2788 "psubw %%mm4, %%mm2 \n\t" // L1 - L2
2789 "psubw %%mm5, %%mm3 \n\t" // H1 - H2
2790 "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
2791 "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
2793 "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
2794 "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
2795 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
2796 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
2798 "movq (%%"REG_a
", %1), %%mm2 \n\t"
2799 "movq %%mm2, %%mm3 \n\t"
2800 "punpcklbw %%mm7, %%mm2 \n\t" // L3
2801 "punpckhbw %%mm7, %%mm3 \n\t" // H3
2803 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
2804 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
2805 "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
2806 "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
2807 "movq %%mm0, (%%"REG_c
") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
2808 "movq %%mm1, 8(%%"REG_c
") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
2810 "movq (%%"REG_a
", %1, 2), %%mm0 \n\t"
2811 "movq %%mm0, %%mm1 \n\t"
2812 "punpcklbw %%mm7, %%mm0 \n\t" // L4
2813 "punpckhbw %%mm7, %%mm1 \n\t" // H4
2815 "psubw %%mm0, %%mm2 \n\t" // L3 - L4
2816 "psubw %%mm1, %%mm3 \n\t" // H3 - H4
2817 "movq %%mm2, 16(%%"REG_c
") \n\t" // L3 - L4
2818 "movq %%mm3, 24(%%"REG_c
") \n\t" // H3 - H4
2819 "paddw %%mm4, %%mm4 \n\t" // 2L2
2820 "paddw %%mm5, %%mm5 \n\t" // 2H2
2821 "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
2822 "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
2824 "lea (%%"REG_a
", %1), %0 \n\t"
2825 "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
2826 "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
2827 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
2828 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
2830 "movq (%0, %1, 2), %%mm2 \n\t"
2831 "movq %%mm2, %%mm3 \n\t"
2832 "punpcklbw %%mm7, %%mm2 \n\t" // L5
2833 "punpckhbw %%mm7, %%mm3 \n\t" // H5
2834 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
2835 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
2836 "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
2837 "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
2839 "movq (%%"REG_a
", %1, 4), %%mm6 \n\t"
2840 "punpcklbw %%mm7, %%mm6 \n\t" // L6
2841 "psubw %%mm6, %%mm2 \n\t" // L5 - L6
2842 "movq (%%"REG_a
", %1, 4), %%mm6 \n\t"
2843 "punpckhbw %%mm7, %%mm6 \n\t" // H6
2844 "psubw %%mm6, %%mm3 \n\t" // H5 - H6
2846 "paddw %%mm0, %%mm0 \n\t" // 2L4
2847 "paddw %%mm1, %%mm1 \n\t" // 2H4
2848 "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
2849 "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
2851 "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
2852 "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
2853 "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
2854 "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
2856 "movq (%0, %1, 4), %%mm2 \n\t"
2857 "movq %%mm2, %%mm3 \n\t"
2858 "punpcklbw %%mm7, %%mm2 \n\t" // L7
2859 "punpckhbw %%mm7, %%mm3 \n\t" // H7
2861 "paddw %%mm2, %%mm2 \n\t" // 2L7
2862 "paddw %%mm3, %%mm3 \n\t" // 2H7
2863 "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
2864 "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
2866 "movq (%%"REG_c
"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
2867 "movq 8(%%"REG_c
"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
2870 "movq %%mm7, %%mm6 \n\t" // 0
2871 "psubw %%mm0, %%mm6 \n\t"
2872 "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
2873 "movq %%mm7, %%mm6 \n\t" // 0
2874 "psubw %%mm1, %%mm6 \n\t"
2875 "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
2876 "movq %%mm7, %%mm6 \n\t" // 0
2877 "psubw %%mm2, %%mm6 \n\t"
2878 "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
2879 "movq %%mm7, %%mm6 \n\t" // 0
2880 "psubw %%mm3, %%mm6 \n\t"
2881 "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
2883 "movq %%mm7, %%mm6 \n\t" // 0
2884 "pcmpgtw %%mm0, %%mm6 \n\t"
2885 "pxor %%mm6, %%mm0 \n\t"
2886 "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
2887 "movq %%mm7, %%mm6 \n\t" // 0
2888 "pcmpgtw %%mm1, %%mm6 \n\t"
2889 "pxor %%mm6, %%mm1 \n\t"
2890 "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
2891 "movq %%mm7, %%mm6 \n\t" // 0
2892 "pcmpgtw %%mm2, %%mm6 \n\t"
2893 "pxor %%mm6, %%mm2 \n\t"
2894 "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
2895 "movq %%mm7, %%mm6 \n\t" // 0
2896 "pcmpgtw %%mm3, %%mm6 \n\t"
2897 "pxor %%mm6, %%mm3 \n\t"
2898 "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
2902 "pminsw %%mm2, %%mm0 \n\t"
2903 "pminsw %%mm3, %%mm1 \n\t"
2905 "movq %%mm0, %%mm6 \n\t"
2906 "psubusw %%mm2, %%mm6 \n\t"
2907 "psubw %%mm6, %%mm0 \n\t"
2908 "movq %%mm1, %%mm6 \n\t"
2909 "psubusw %%mm3, %%mm6 \n\t"
2910 "psubw %%mm6, %%mm1 \n\t"
2913 "movd %2, %%mm2 \n\t" // QP
2914 "punpcklbw %%mm7, %%mm2 \n\t"
2916 "movq %%mm7, %%mm6 \n\t" // 0
2917 "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
2918 "pxor %%mm6, %%mm4 \n\t"
2919 "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
2920 "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
2921 "pxor %%mm7, %%mm5 \n\t"
2922 "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
2924 "psllw $3, %%mm2 \n\t" // 8QP
2925 "movq %%mm2, %%mm3 \n\t" // 8QP
2926 "pcmpgtw %%mm4, %%mm2 \n\t"
2927 "pcmpgtw %%mm5, %%mm3 \n\t"
2928 "pand %%mm2, %%mm4 \n\t"
2929 "pand %%mm3, %%mm5 \n\t"
2932 "psubusw %%mm0, %%mm4 \n\t" // hd
2933 "psubusw %%mm1, %%mm5 \n\t" // ld
2936 "movq "MANGLE(w05
)", %%mm2 \n\t" // 5
2937 "pmullw %%mm2, %%mm4 \n\t"
2938 "pmullw %%mm2, %%mm5 \n\t"
2939 "movq "MANGLE(w20
)", %%mm2 \n\t" // 32
2940 "paddw %%mm2, %%mm4 \n\t"
2941 "paddw %%mm2, %%mm5 \n\t"
2942 "psrlw $6, %%mm4 \n\t"
2943 "psrlw $6, %%mm5 \n\t"
2945 "movq 16(%%"REG_c
"), %%mm0 \n\t" // L3 - L4
2946 "movq 24(%%"REG_c
"), %%mm1 \n\t" // H3 - H4
2948 "pxor %%mm2, %%mm2 \n\t"
2949 "pxor %%mm3, %%mm3 \n\t"
2951 "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
2952 "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
2953 "pxor %%mm2, %%mm0 \n\t"
2954 "pxor %%mm3, %%mm1 \n\t"
2955 "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
2956 "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
2957 "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
2958 "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
2960 "pxor %%mm6, %%mm2 \n\t"
2961 "pxor %%mm7, %%mm3 \n\t"
2962 "pand %%mm2, %%mm4 \n\t"
2963 "pand %%mm3, %%mm5 \n\t"
2966 "pminsw %%mm0, %%mm4 \n\t"
2967 "pminsw %%mm1, %%mm5 \n\t"
2969 "movq %%mm4, %%mm2 \n\t"
2970 "psubusw %%mm0, %%mm2 \n\t"
2971 "psubw %%mm2, %%mm4 \n\t"
2972 "movq %%mm5, %%mm2 \n\t"
2973 "psubusw %%mm1, %%mm2 \n\t"
2974 "psubw %%mm2, %%mm5 \n\t"
2976 "pxor %%mm6, %%mm4 \n\t"
2977 "pxor %%mm7, %%mm5 \n\t"
2978 "psubw %%mm6, %%mm4 \n\t"
2979 "psubw %%mm7, %%mm5 \n\t"
2980 "packsswb %%mm5, %%mm4 \n\t"
2981 "movq %3, %%mm1 \n\t"
2982 "pandn %%mm4, %%mm1 \n\t"
2983 "movq (%0), %%mm0 \n\t"
2984 "paddb %%mm1, %%mm0 \n\t"
2985 "movq %%mm0, (%0) \n\t"
2986 "movq (%0, %1), %%mm0 \n\t"
2987 "psubb %%mm1, %%mm0 \n\t"
2988 "movq %%mm0, (%0, %1) \n\t"
2991 : "r" ((x86_reg
)step
), "m" (c
->pQPb
), "m"(eq_mask
)
2992 : "%"REG_a
, "%"REG_c
2996 STOP_TIMER("step16")
3003 static void RENAME(postProcess
)(const uint8_t src
[], int srcStride
, uint8_t dst
[], int dstStride
, int width
, int height
,
3004 const QP_STORE_T QPs
[], int QPStride
, int isColor
, PPContext
*c
);
3007 * Copies a block from src to dst and fixes the blacklevel.
3008 * levelFix == 0 -> do not touch the brighness & contrast
3012 static inline void RENAME(blockCopy
)(uint8_t dst
[], int dstStride
, const uint8_t src
[], int srcStride
,
3013 int levelFix
, int64_t *packedOffsetAndScale
)
3021 "movq (%%"REG_a
"), %%mm2 \n\t" // packedYOffset
3022 "movq 8(%%"REG_a
"), %%mm3 \n\t" // packedYScale
3023 "lea (%2,%4), %%"REG_a
" \n\t"
3024 "lea (%3,%5), %%"REG_d
" \n\t"
3025 "pxor %%mm4, %%mm4 \n\t"
3027 #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
3028 "movq " #src1 ", %%mm0 \n\t"\
3029 "movq " #src1 ", %%mm5 \n\t"\
3030 "movq " #src2 ", %%mm1 \n\t"\
3031 "movq " #src2 ", %%mm6 \n\t"\
3032 "punpcklbw %%mm0, %%mm0 \n\t"\
3033 "punpckhbw %%mm5, %%mm5 \n\t"\
3034 "punpcklbw %%mm1, %%mm1 \n\t"\
3035 "punpckhbw %%mm6, %%mm6 \n\t"\
3036 "pmulhuw %%mm3, %%mm0 \n\t"\
3037 "pmulhuw %%mm3, %%mm5 \n\t"\
3038 "pmulhuw %%mm3, %%mm1 \n\t"\
3039 "pmulhuw %%mm3, %%mm6 \n\t"\
3040 "psubw %%mm2, %%mm0 \n\t"\
3041 "psubw %%mm2, %%mm5 \n\t"\
3042 "psubw %%mm2, %%mm1 \n\t"\
3043 "psubw %%mm2, %%mm6 \n\t"\
3044 "packuswb %%mm5, %%mm0 \n\t"\
3045 "packuswb %%mm6, %%mm1 \n\t"\
3046 "movq %%mm0, " #dst1 " \n\t"\
3047 "movq %%mm1, " #dst2 " \n\t"\
3050 #define REAL_SCALED_CPY(src1, src2, dst1, dst2) \
3051 "movq " #src1 ", %%mm0 \n\t"\
3052 "movq " #src1 ", %%mm5 \n\t"\
3053 "punpcklbw %%mm4, %%mm0 \n\t"\
3054 "punpckhbw %%mm4, %%mm5 \n\t"\
3055 "psubw %%mm2, %%mm0 \n\t"\
3056 "psubw %%mm2, %%mm5 \n\t"\
3057 "movq " #src2 ", %%mm1 \n\t"\
3058 "psllw $6, %%mm0 \n\t"\
3059 "psllw $6, %%mm5 \n\t"\
3060 "pmulhw %%mm3, %%mm0 \n\t"\
3061 "movq " #src2 ", %%mm6 \n\t"\
3062 "pmulhw %%mm3, %%mm5 \n\t"\
3063 "punpcklbw %%mm4, %%mm1 \n\t"\
3064 "punpckhbw %%mm4, %%mm6 \n\t"\
3065 "psubw %%mm2, %%mm1 \n\t"\
3066 "psubw %%mm2, %%mm6 \n\t"\
3067 "psllw $6, %%mm1 \n\t"\
3068 "psllw $6, %%mm6 \n\t"\
3069 "pmulhw %%mm3, %%mm1 \n\t"\
3070 "pmulhw %%mm3, %%mm6 \n\t"\
3071 "packuswb %%mm5, %%mm0 \n\t"\
3072 "packuswb %%mm6, %%mm1 \n\t"\
3073 "movq %%mm0, " #dst1 " \n\t"\
3074 "movq %%mm1, " #dst2 " \n\t"\
3077 #define SCALED_CPY(src1, src2, dst1, dst2)\
3078 REAL_SCALED_CPY(src1, src2, dst1, dst2)
3080 SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
3081 SCALED_CPY((%2, %4, 2), (%%REGa
, %4, 2), (%3, %5, 2), (%%REGd
, %5, 2))
3082 SCALED_CPY((%2, %4, 4), (%%REGa
, %4, 4), (%3, %5, 4), (%%REGd
, %5, 4))
3083 "lea (%%"REG_a
",%4,4), %%"REG_a
" \n\t"
3084 "lea (%%"REG_d
",%5,4), %%"REG_d
" \n\t"
3085 SCALED_CPY((%%REGa
, %4), (%%REGa
, %4, 2), (%%REGd
, %5), (%%REGd
, %5, 2))
3088 : "=&a" (packedOffsetAndScale
)
3089 : "0" (packedOffsetAndScale
),
3092 "r" ((x86_reg
)srcStride
),
3093 "r" ((x86_reg
)dstStride
)
3098 memcpy( &(dst
[dstStride
*i
]),
3099 &(src
[srcStride
*i
]), BLOCK_SIZE
);
3104 "lea (%0,%2), %%"REG_a
" \n\t"
3105 "lea (%1,%3), %%"REG_d
" \n\t"
3107 #define REAL_SIMPLE_CPY(src1, src2, dst1, dst2) \
3108 "movq " #src1 ", %%mm0 \n\t"\
3109 "movq " #src2 ", %%mm1 \n\t"\
3110 "movq %%mm0, " #dst1 " \n\t"\
3111 "movq %%mm1, " #dst2 " \n\t"\
3113 #define SIMPLE_CPY(src1, src2, dst1, dst2)\
3114 REAL_SIMPLE_CPY(src1, src2, dst1, dst2)
3116 SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
3117 SIMPLE_CPY((%0, %2, 2), (%%REGa
, %2, 2), (%1, %3, 2), (%%REGd
, %3, 2))
3118 SIMPLE_CPY((%0, %2, 4), (%%REGa
, %2, 4), (%1, %3, 4), (%%REGd
, %3, 4))
3119 "lea (%%"REG_a
",%2,4), %%"REG_a
" \n\t"
3120 "lea (%%"REG_d
",%3,4), %%"REG_d
" \n\t"
3121 SIMPLE_CPY((%%REGa
, %2), (%%REGa
, %2, 2), (%%REGd
, %3), (%%REGd
, %3, 2))
3125 "r" ((x86_reg
)srcStride
),
3126 "r" ((x86_reg
)dstStride
)
3127 : "%"REG_a
, "%"REG_d
3131 memcpy( &(dst
[dstStride
*i
]),
3132 &(src
[srcStride
*i
]), BLOCK_SIZE
);
3138 * Duplicates the given 8 src pixels ? times upward
3140 static inline void RENAME(duplicate
)(uint8_t src
[], int stride
)
3144 "movq (%0), %%mm0 \n\t"
3146 "movq %%mm0, (%0) \n\t"
3147 "movq %%mm0, (%0, %1) \n\t"
3148 "movq %%mm0, (%0, %1, 2) \n\t"
3150 : "r" ((x86_reg
)-stride
)
3163 * Filters array of bytes (Y or U or V values)
3165 static void RENAME(postProcess
)(const uint8_t src
[], int srcStride
, uint8_t dst
[], int dstStride
, int width
, int height
,
3166 const QP_STORE_T QPs
[], int QPStride
, int isColor
, PPContext
*c2
)
3168 DECLARE_ALIGNED(8, PPContext
, c
)= *c2
; //copy to stack for faster access
3170 #ifdef COMPILE_TIME_MODE
3171 const int mode
= COMPILE_TIME_MODE
;
3173 const int mode
= isColor
? c
.ppMode
.chromMode
: c
.ppMode
.lumMode
;
3175 int black
=0, white
=255; // blackest black and whitest white in the picture
3176 int QPCorrecture
= 256*256;
3183 const int qpHShift
= isColor
? 4-c
.hChromaSubSample
: 4;
3184 const int qpVShift
= isColor
? 4-c
.vChromaSubSample
: 4;
3187 uint64_t * const yHistogram
= c
.yHistogram
;
3188 uint8_t * const tempSrc
= srcStride
> 0 ? c
.tempSrc
: c
.tempSrc
- 23*srcStride
;
3189 uint8_t * const tempDst
= dstStride
> 0 ? c
.tempDst
: c
.tempDst
- 23*dstStride
;
3190 //const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
3193 for(i
=0; i
<57; i
++){
3194 int offset
= ((i
*c
.ppMode
.baseDcDiff
)>>8) + 1;
3195 int threshold
= offset
*2 + 1;
3196 c
.mmxDcOffset
[i
]= 0x7F - offset
;
3197 c
.mmxDcThreshold
[i
]= 0x7F - threshold
;
3198 c
.mmxDcOffset
[i
]*= 0x0101010101010101LL
;
3199 c
.mmxDcThreshold
[i
]*= 0x0101010101010101LL
;
3203 if(mode
& CUBIC_IPOL_DEINT_FILTER
) copyAhead
=16;
3204 else if( (mode
& LINEAR_BLEND_DEINT_FILTER
)
3205 || (mode
& FFMPEG_DEINT_FILTER
)
3206 || (mode
& LOWPASS5_DEINT_FILTER
)) copyAhead
=14;
3207 else if( (mode
& V_DEBLOCK
)
3208 || (mode
& LINEAR_IPOL_DEINT_FILTER
)
3209 || (mode
& MEDIAN_DEINT_FILTER
)
3210 || (mode
& V_A_DEBLOCK
)) copyAhead
=13;
3211 else if(mode
& V_X1_FILTER
) copyAhead
=11;
3212 // else if(mode & V_RK1_FILTER) copyAhead=10;
3213 else if(mode
& DERING
) copyAhead
=9;
3221 uint64_t maxClipped
;
3226 // first frame is fscked so we ignore it
3227 if(c
.frameNum
== 1) yHistogram
[0]= width
*height
/64*15/256;
3229 for(i
=0; i
<256; i
++){
3230 sum
+= yHistogram
[i
];
3233 /* We always get a completely black picture first. */
3234 maxClipped
= (uint64_t)(sum
* c
.ppMode
.maxClippedThreshold
);
3237 for(black
=255; black
>0; black
--){
3238 if(clipped
< maxClipped
) break;
3239 clipped
-= yHistogram
[black
];
3243 for(white
=0; white
<256; white
++){
3244 if(clipped
< maxClipped
) break;
3245 clipped
-= yHistogram
[white
];
3248 scale
= (double)(c
.ppMode
.maxAllowedY
- c
.ppMode
.minAllowedY
) / (double)(white
-black
);
3251 c
.packedYScale
= (uint16_t)(scale
*256.0 + 0.5);
3252 c
.packedYOffset
= (((black
*c
.packedYScale
)>>8) - c
.ppMode
.minAllowedY
) & 0xFFFF;
3254 c
.packedYScale
= (uint16_t)(scale
*1024.0 + 0.5);
3255 c
.packedYOffset
= (black
- c
.ppMode
.minAllowedY
) & 0xFFFF;
3258 c
.packedYOffset
|= c
.packedYOffset
<<32;
3259 c
.packedYOffset
|= c
.packedYOffset
<<16;
3261 c
.packedYScale
|= c
.packedYScale
<<32;
3262 c
.packedYScale
|= c
.packedYScale
<<16;
3264 if(mode
& LEVEL_FIX
) QPCorrecture
= (int)(scale
*256*256 + 0.5);
3265 else QPCorrecture
= 256*256;
3267 c
.packedYScale
= 0x0100010001000100LL
;
3269 QPCorrecture
= 256*256;
3272 /* copy & deinterlace first row of blocks */
3275 const uint8_t *srcBlock
= &(src
[y
*srcStride
]);
3276 uint8_t *dstBlock
= tempDst
+ dstStride
;
3278 // From this point on it is guaranteed that we can read and write 16 lines downward
3279 // finish 1 block before the next otherwise we might have a problem
3280 // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
3281 for(x
=0; x
<width
; x
+=BLOCK_SIZE
){
3285 prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
3286 prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
3287 prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
3288 prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
3292 "mov %4, %%"REG_a
" \n\t"
3293 "shr $2, %%"REG_a
" \n\t"
3294 "and $6, %%"REG_a
" \n\t"
3295 "add %5, %%"REG_a
" \n\t"
3296 "mov %%"REG_a
", %%"REG_d
" \n\t"
3297 "imul %1, %%"REG_a
" \n\t"
3298 "imul %3, %%"REG_d
" \n\t"
3299 "prefetchnta 32(%%"REG_a
", %0) \n\t"
3300 "prefetcht0 32(%%"REG_d
", %2) \n\t"
3301 "add %1, %%"REG_a
" \n\t"
3302 "add %3, %%"REG_d
" \n\t"
3303 "prefetchnta 32(%%"REG_a
", %0) \n\t"
3304 "prefetcht0 32(%%"REG_d
", %2) \n\t"
3305 :: "r" (srcBlock
), "r" ((x86_reg
)srcStride
), "r" (dstBlock
), "r" ((x86_reg
)dstStride
),
3306 "g" ((x86_reg
)x
), "g" ((x86_reg
)copyAhead
)
3307 : "%"REG_a
, "%"REG_d
3311 //FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ...
3312 /* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
3313 prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
3314 prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
3315 prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
3319 RENAME(blockCopy
)(dstBlock
+ dstStride
*8, dstStride
,
3320 srcBlock
+ srcStride
*8, srcStride
, mode
& LEVEL_FIX
, &c
.packedYOffset
);
3322 RENAME(duplicate
)(dstBlock
+ dstStride
*8, dstStride
);
3324 if(mode
& LINEAR_IPOL_DEINT_FILTER
)
3325 RENAME(deInterlaceInterpolateLinear
)(dstBlock
, dstStride
);
3326 else if(mode
& LINEAR_BLEND_DEINT_FILTER
)
3327 RENAME(deInterlaceBlendLinear
)(dstBlock
, dstStride
, c
.deintTemp
+ x
);
3328 else if(mode
& MEDIAN_DEINT_FILTER
)
3329 RENAME(deInterlaceMedian
)(dstBlock
, dstStride
);
3330 else if(mode
& CUBIC_IPOL_DEINT_FILTER
)
3331 RENAME(deInterlaceInterpolateCubic
)(dstBlock
, dstStride
);
3332 else if(mode
& FFMPEG_DEINT_FILTER
)
3333 RENAME(deInterlaceFF
)(dstBlock
, dstStride
, c
.deintTemp
+ x
);
3334 else if(mode
& LOWPASS5_DEINT_FILTER
)
3335 RENAME(deInterlaceL5
)(dstBlock
, dstStride
, c
.deintTemp
+ x
, c
.deintTemp
+ width
+ x
);
3336 /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
3337 RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
3342 if(width
==FFABS(dstStride
))
3343 linecpy(dst
, tempDst
+ 9*dstStride
, copyAhead
, dstStride
);
3346 for(i
=0; i
<copyAhead
; i
++){
3347 memcpy(dst
+ i
*dstStride
, tempDst
+ (9+i
)*dstStride
, width
);
3352 for(y
=0; y
<height
; y
+=BLOCK_SIZE
){
3353 //1% speedup if these are here instead of the inner loop
3354 const uint8_t *srcBlock
= &(src
[y
*srcStride
]);
3355 uint8_t *dstBlock
= &(dst
[y
*dstStride
]);
3357 uint8_t *tempBlock1
= c
.tempBlocks
;
3358 uint8_t *tempBlock2
= c
.tempBlocks
+ 8;
3360 const int8_t *QPptr
= &QPs
[(y
>>qpVShift
)*QPStride
];
3361 int8_t *nonBQPptr
= &c
.nonBQPTable
[(y
>>qpVShift
)*FFABS(QPStride
)];
3363 /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
3364 if not than use a temporary buffer */
3367 /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
3368 blockcopy to dst later */
3369 linecpy(tempSrc
+ srcStride
*copyAhead
, srcBlock
+ srcStride
*copyAhead
,
3370 FFMAX(height
-y
-copyAhead
, 0), srcStride
);
3372 /* duplicate last line of src to fill the void upto line (copyAhead+7) */
3373 for(i
=FFMAX(height
-y
, 8); i
<copyAhead
+8; i
++)
3374 memcpy(tempSrc
+ srcStride
*i
, src
+ srcStride
*(height
-1), FFABS(srcStride
));
3376 /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
3377 linecpy(tempDst
, dstBlock
- dstStride
, FFMIN(height
-y
+1, copyAhead
+1), dstStride
);
3379 /* duplicate last line of dst to fill the void upto line (copyAhead) */
3380 for(i
=height
-y
+1; i
<=copyAhead
; i
++)
3381 memcpy(tempDst
+ dstStride
*i
, dst
+ dstStride
*(height
-1), FFABS(dstStride
));
3383 dstBlock
= tempDst
+ dstStride
;
3387 // From this point on it is guaranteed that we can read and write 16 lines downward
3388 // finish 1 block before the next otherwise we might have a problem
3389 // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
3390 for(x
=0; x
<width
; x
+=BLOCK_SIZE
){
3391 const int stride
= dstStride
;
3396 QP
= QPptr
[x
>>qpHShift
];
3397 c
.nonBQP
= nonBQPptr
[x
>>qpHShift
];
3400 QP
= (QP
* QPCorrecture
+ 256*128)>>16;
3401 c
.nonBQP
= nonBQPptr
[x
>>4];
3402 c
.nonBQP
= (c
.nonBQP
* QPCorrecture
+ 256*128)>>16;
3403 yHistogram
[ srcBlock
[srcStride
*12 + 4] ]++;
3408 "movd %1, %%mm7 \n\t"
3409 "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
3410 "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
3411 "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
3412 "movq %%mm7, %0 \n\t"
3421 prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
3422 prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
3423 prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
3424 prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
3428 "mov %4, %%"REG_a
" \n\t"
3429 "shr $2, %%"REG_a
" \n\t"
3430 "and $6, %%"REG_a
" \n\t"
3431 "add %5, %%"REG_a
" \n\t"
3432 "mov %%"REG_a
", %%"REG_d
" \n\t"
3433 "imul %1, %%"REG_a
" \n\t"
3434 "imul %3, %%"REG_d
" \n\t"
3435 "prefetchnta 32(%%"REG_a
", %0) \n\t"
3436 "prefetcht0 32(%%"REG_d
", %2) \n\t"
3437 "add %1, %%"REG_a
" \n\t"
3438 "add %3, %%"REG_d
" \n\t"
3439 "prefetchnta 32(%%"REG_a
", %0) \n\t"
3440 "prefetcht0 32(%%"REG_d
", %2) \n\t"
3441 :: "r" (srcBlock
), "r" ((x86_reg
)srcStride
), "r" (dstBlock
), "r" ((x86_reg
)dstStride
),
3442 "g" ((x86_reg
)x
), "g" ((x86_reg
)copyAhead
)
3443 : "%"REG_a
, "%"REG_d
3447 //FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ...
3448 /* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
3449 prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
3450 prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
3451 prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
3455 RENAME(blockCopy
)(dstBlock
+ dstStride
*copyAhead
, dstStride
,
3456 srcBlock
+ srcStride
*copyAhead
, srcStride
, mode
& LEVEL_FIX
, &c
.packedYOffset
);
3458 if(mode
& LINEAR_IPOL_DEINT_FILTER
)
3459 RENAME(deInterlaceInterpolateLinear
)(dstBlock
, dstStride
);
3460 else if(mode
& LINEAR_BLEND_DEINT_FILTER
)
3461 RENAME(deInterlaceBlendLinear
)(dstBlock
, dstStride
, c
.deintTemp
+ x
);
3462 else if(mode
& MEDIAN_DEINT_FILTER
)
3463 RENAME(deInterlaceMedian
)(dstBlock
, dstStride
);
3464 else if(mode
& CUBIC_IPOL_DEINT_FILTER
)
3465 RENAME(deInterlaceInterpolateCubic
)(dstBlock
, dstStride
);
3466 else if(mode
& FFMPEG_DEINT_FILTER
)
3467 RENAME(deInterlaceFF
)(dstBlock
, dstStride
, c
.deintTemp
+ x
);
3468 else if(mode
& LOWPASS5_DEINT_FILTER
)
3469 RENAME(deInterlaceL5
)(dstBlock
, dstStride
, c
.deintTemp
+ x
, c
.deintTemp
+ width
+ x
);
3470 /* else if(mode & CUBIC_BLEND_DEINT_FILTER)
3471 RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
3474 /* only deblock if we have 2 blocks */
3476 if(mode
& V_X1_FILTER
)
3477 RENAME(vertX1Filter
)(dstBlock
, stride
, &c
);
3478 else if(mode
& V_DEBLOCK
){
3479 const int t
= RENAME(vertClassify
)(dstBlock
, stride
, &c
);
3482 RENAME(doVertLowPass
)(dstBlock
, stride
, &c
);
3484 RENAME(doVertDefFilter
)(dstBlock
, stride
, &c
);
3485 }else if(mode
& V_A_DEBLOCK
){
3486 RENAME(do_a_deblock
)(dstBlock
, stride
, 1, &c
);
3491 RENAME(transpose1
)(tempBlock1
, tempBlock2
, dstBlock
, dstStride
);
3493 /* check if we have a previous block to deblock it with dstBlock */
3496 if(mode
& H_X1_FILTER
)
3497 RENAME(vertX1Filter
)(tempBlock1
, 16, &c
);
3498 else if(mode
& H_DEBLOCK
){
3500 const int t
= RENAME(vertClassify
)(tempBlock1
, 16, &c
);
3501 //STOP_TIMER("dc & minmax")
3503 RENAME(doVertLowPass
)(tempBlock1
, 16, &c
);
3505 RENAME(doVertDefFilter
)(tempBlock1
, 16, &c
);
3506 }else if(mode
& H_A_DEBLOCK
){
3507 RENAME(do_a_deblock
)(tempBlock1
, 16, 1, &c
);
3510 RENAME(transpose2
)(dstBlock
-4, dstStride
, tempBlock1
+ 4*16);
3513 if(mode
& H_X1_FILTER
)
3514 horizX1Filter(dstBlock
-4, stride
, QP
);
3515 else if(mode
& H_DEBLOCK
){
3517 DECLARE_ALIGNED(16, unsigned char, tempBlock
[272]);
3518 transpose_16x8_char_toPackedAlign_altivec(tempBlock
, dstBlock
- (4 + 1), stride
);
3520 const int t
=vertClassify_altivec(tempBlock
-48, 16, &c
);
3522 doVertLowPass_altivec(tempBlock
-48, 16, &c
);
3523 transpose_8x16_char_fromPackedAlign_altivec(dstBlock
- (4 + 1), tempBlock
, stride
);
3526 doVertDefFilter_altivec(tempBlock
-48, 16, &c
);
3527 transpose_8x16_char_fromPackedAlign_altivec(dstBlock
- (4 + 1), tempBlock
, stride
);
3530 const int t
= RENAME(horizClassify
)(dstBlock
-4, stride
, &c
);
3533 RENAME(doHorizLowPass
)(dstBlock
-4, stride
, &c
);
3535 RENAME(doHorizDefFilter
)(dstBlock
-4, stride
, &c
);
3537 }else if(mode
& H_A_DEBLOCK
){
3538 RENAME(do_a_deblock
)(dstBlock
-8, 1, stride
, &c
);
3542 //FIXME filter first line
3543 if(y
>0) RENAME(dering
)(dstBlock
- stride
- 8, stride
, &c
);
3546 if(mode
& TEMP_NOISE_FILTER
)
3548 RENAME(tempNoiseReducer
)(dstBlock
-8, stride
,
3549 c
.tempBlurred
[isColor
] + y
*dstStride
+ x
,
3550 c
.tempBlurredPast
[isColor
] + (y
>>3)*256 + (x
>>3),
3551 c
.ppMode
.maxTmpNoise
);
3559 tmpXchg
= tempBlock1
;
3560 tempBlock1
= tempBlock2
;
3561 tempBlock2
= tmpXchg
;
3566 if(y
> 0) RENAME(dering
)(dstBlock
- dstStride
- 8, dstStride
, &c
);
3569 if((mode
& TEMP_NOISE_FILTER
)){
3570 RENAME(tempNoiseReducer
)(dstBlock
-8, dstStride
,
3571 c
.tempBlurred
[isColor
] + y
*dstStride
+ x
,
3572 c
.tempBlurredPast
[isColor
] + (y
>>3)*256 + (x
>>3),
3573 c
.ppMode
.maxTmpNoise
);
3576 /* did we use a tmp buffer for the last lines*/
3578 uint8_t *dstBlock
= &(dst
[y
*dstStride
]);
3579 if(width
==FFABS(dstStride
))
3580 linecpy(dstBlock
, tempDst
+ dstStride
, height
-y
, dstStride
);
3583 for(i
=0; i
<height
-y
; i
++){
3584 memcpy(dstBlock
+ i
*dstStride
, tempDst
+ (i
+1)*dstStride
, width
);
3589 for(x=0; x<width; x+=32){
3591 i+= + dstBlock[x + 7*dstStride] + dstBlock[x + 8*dstStride]
3592 + dstBlock[x + 9*dstStride] + dstBlock[x +10*dstStride]
3593 + dstBlock[x +11*dstStride] + dstBlock[x +12*dstStride];
3594 + dstBlock[x +13*dstStride]
3595 + dstBlock[x +14*dstStride] + dstBlock[x +15*dstStride];
3599 __asm__
volatile("femms");
3601 __asm__
volatile("emms");
3604 #ifdef DEBUG_BRIGHTNESS
3608 for(i
=0; i
<256; i
++)
3609 if(yHistogram
[i
] > max
) max
=yHistogram
[i
];
3611 for(i
=1; i
<256; i
++){
3613 int start
=yHistogram
[i
-1]/(max
/256+1);
3614 int end
=yHistogram
[i
]/(max
/256+1);
3615 int inc
= end
> start
? 1 : -1;
3616 for(x
=start
; x
!=end
+inc
; x
+=inc
)
3617 dst
[ i
*dstStride
+ x
]+=128;
3620 for(i
=0; i
<100; i
+=2){
3621 dst
[ (white
)*dstStride
+ i
]+=128;
3622 dst
[ (black
)*dstStride
+ i
]+=128;
3627 *c2
= c
; //copy local context back