2 * Optimized for ia32 CPUs by Nick Kurshev <nickols_k@mail.ru>
3 * h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/cpu.h"
23 #include "libavutil/x86/asm.h"
24 #include "libavcodec/avcodec.h"
25 #include "libavcodec/dsputil.h"
26 #include "libavcodec/mpegvideo.h"
27 #include "dsputil_mmx.h"
31 static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,
32 DCTELEM *block, int n, int qscale)
34 x86_reg level, qmul, qadd, nCoeffs;
38 assert(s->block_last_index[n]>=0 || s->h263_aic);
42 level = block[0] * s->y_dc_scale;
44 level = block[0] * s->c_dc_scale;
45 qadd = (qscale - 1) | 1;
53 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
56 "movd %1, %%mm6 \n\t" //qmul
57 "packssdw %%mm6, %%mm6 \n\t"
58 "packssdw %%mm6, %%mm6 \n\t"
59 "movd %2, %%mm5 \n\t" //qadd
60 "pxor %%mm7, %%mm7 \n\t"
61 "packssdw %%mm5, %%mm5 \n\t"
62 "packssdw %%mm5, %%mm5 \n\t"
63 "psubw %%mm5, %%mm7 \n\t"
64 "pxor %%mm4, %%mm4 \n\t"
67 "movq (%0, %3), %%mm0 \n\t"
68 "movq 8(%0, %3), %%mm1 \n\t"
70 "pmullw %%mm6, %%mm0 \n\t"
71 "pmullw %%mm6, %%mm1 \n\t"
73 "movq (%0, %3), %%mm2 \n\t"
74 "movq 8(%0, %3), %%mm3 \n\t"
76 "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
77 "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
79 "pxor %%mm2, %%mm0 \n\t"
80 "pxor %%mm3, %%mm1 \n\t"
82 "paddw %%mm7, %%mm0 \n\t"
83 "paddw %%mm7, %%mm1 \n\t"
85 "pxor %%mm0, %%mm2 \n\t"
86 "pxor %%mm1, %%mm3 \n\t"
88 "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
89 "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
91 "pandn %%mm2, %%mm0 \n\t"
92 "pandn %%mm3, %%mm1 \n\t"
94 "movq %%mm0, (%0, %3) \n\t"
95 "movq %%mm1, 8(%0, %3) \n\t"
99 ::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
106 static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,
107 DCTELEM *block, int n, int qscale)
109 x86_reg qmul, qadd, nCoeffs;
112 qadd = (qscale - 1) | 1;
114 assert(s->block_last_index[n]>=0 || s->h263_aic);
116 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
119 "movd %1, %%mm6 \n\t" //qmul
120 "packssdw %%mm6, %%mm6 \n\t"
121 "packssdw %%mm6, %%mm6 \n\t"
122 "movd %2, %%mm5 \n\t" //qadd
123 "pxor %%mm7, %%mm7 \n\t"
124 "packssdw %%mm5, %%mm5 \n\t"
125 "packssdw %%mm5, %%mm5 \n\t"
126 "psubw %%mm5, %%mm7 \n\t"
127 "pxor %%mm4, %%mm4 \n\t"
130 "movq (%0, %3), %%mm0 \n\t"
131 "movq 8(%0, %3), %%mm1 \n\t"
133 "pmullw %%mm6, %%mm0 \n\t"
134 "pmullw %%mm6, %%mm1 \n\t"
136 "movq (%0, %3), %%mm2 \n\t"
137 "movq 8(%0, %3), %%mm3 \n\t"
139 "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
140 "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
142 "pxor %%mm2, %%mm0 \n\t"
143 "pxor %%mm3, %%mm1 \n\t"
145 "paddw %%mm7, %%mm0 \n\t"
146 "paddw %%mm7, %%mm1 \n\t"
148 "pxor %%mm0, %%mm2 \n\t"
149 "pxor %%mm1, %%mm3 \n\t"
151 "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
152 "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
154 "pandn %%mm2, %%mm0 \n\t"
155 "pandn %%mm3, %%mm1 \n\t"
157 "movq %%mm0, (%0, %3) \n\t"
158 "movq %%mm1, 8(%0, %3) \n\t"
162 ::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
170 Note: looking at PARANOID:
171 "enable all paranoid tests for rounding, overflows, etc..."
174 if (level < -2048 || level > 2047)
175 fprintf(stderr, "unquant error %d %d\n", i, level);
177 We can suppose that result of two multiplications can't be greater than 0xFFFF
178 i.e. is 16-bit, so we use here only PMULLW instruction and can avoid
179 a complex multiplication.
180 =====================================================
181 Full formula for multiplication of 2 integer numbers
182 which are represent as high:low words:
183 input: value1 = high1:low1
185 output: value3 = value1*value2
186 value3=high3:low3 (on overflow: modulus 2^32 wrap-around)
187 this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4
188 but this algorithm will compute only 0x66cb0ce4
189 this limited by 16-bit size of operands
190 ---------------------------------
193 tlow1 = tlow1 + tlow2
194 high3:low3 = low1*low2
197 static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,
198 DCTELEM *block, int n, int qscale)
201 const uint16_t *quant_matrix;
204 assert(s->block_last_index[n]>=0);
206 nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
209 block0 = block[0] * s->y_dc_scale;
211 block0 = block[0] * s->c_dc_scale;
212 /* XXX: only mpeg1 */
213 quant_matrix = s->intra_matrix;
215 "pcmpeqw %%mm7, %%mm7 \n\t"
216 "psrlw $15, %%mm7 \n\t"
217 "movd %2, %%mm6 \n\t"
218 "packssdw %%mm6, %%mm6 \n\t"
219 "packssdw %%mm6, %%mm6 \n\t"
220 "mov %3, %%"REG_a" \n\t"
223 "movq (%0, %%"REG_a"), %%mm0 \n\t"
224 "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
225 "movq (%1, %%"REG_a"), %%mm4 \n\t"
226 "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
227 "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
228 "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
229 "pxor %%mm2, %%mm2 \n\t"
230 "pxor %%mm3, %%mm3 \n\t"
231 "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
232 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
233 "pxor %%mm2, %%mm0 \n\t"
234 "pxor %%mm3, %%mm1 \n\t"
235 "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
236 "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
237 "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
238 "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
239 "pxor %%mm4, %%mm4 \n\t"
240 "pxor %%mm5, %%mm5 \n\t" // FIXME slow
241 "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
242 "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
243 "psraw $3, %%mm0 \n\t"
244 "psraw $3, %%mm1 \n\t"
245 "psubw %%mm7, %%mm0 \n\t"
246 "psubw %%mm7, %%mm1 \n\t"
247 "por %%mm7, %%mm0 \n\t"
248 "por %%mm7, %%mm1 \n\t"
249 "pxor %%mm2, %%mm0 \n\t"
250 "pxor %%mm3, %%mm1 \n\t"
251 "psubw %%mm2, %%mm0 \n\t"
252 "psubw %%mm3, %%mm1 \n\t"
253 "pandn %%mm0, %%mm4 \n\t"
254 "pandn %%mm1, %%mm5 \n\t"
255 "movq %%mm4, (%0, %%"REG_a") \n\t"
256 "movq %%mm5, 8(%0, %%"REG_a") \n\t"
258 "add $16, %%"REG_a" \n\t"
260 ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
266 static void dct_unquantize_mpeg1_inter_mmx(MpegEncContext *s,
267 DCTELEM *block, int n, int qscale)
270 const uint16_t *quant_matrix;
272 assert(s->block_last_index[n]>=0);
274 nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
276 quant_matrix = s->inter_matrix;
278 "pcmpeqw %%mm7, %%mm7 \n\t"
279 "psrlw $15, %%mm7 \n\t"
280 "movd %2, %%mm6 \n\t"
281 "packssdw %%mm6, %%mm6 \n\t"
282 "packssdw %%mm6, %%mm6 \n\t"
283 "mov %3, %%"REG_a" \n\t"
286 "movq (%0, %%"REG_a"), %%mm0 \n\t"
287 "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
288 "movq (%1, %%"REG_a"), %%mm4 \n\t"
289 "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
290 "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
291 "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
292 "pxor %%mm2, %%mm2 \n\t"
293 "pxor %%mm3, %%mm3 \n\t"
294 "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
295 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
296 "pxor %%mm2, %%mm0 \n\t"
297 "pxor %%mm3, %%mm1 \n\t"
298 "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
299 "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
300 "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
301 "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
302 "paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
303 "paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
304 "pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
305 "pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
306 "pxor %%mm4, %%mm4 \n\t"
307 "pxor %%mm5, %%mm5 \n\t" // FIXME slow
308 "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
309 "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
310 "psraw $4, %%mm0 \n\t"
311 "psraw $4, %%mm1 \n\t"
312 "psubw %%mm7, %%mm0 \n\t"
313 "psubw %%mm7, %%mm1 \n\t"
314 "por %%mm7, %%mm0 \n\t"
315 "por %%mm7, %%mm1 \n\t"
316 "pxor %%mm2, %%mm0 \n\t"
317 "pxor %%mm3, %%mm1 \n\t"
318 "psubw %%mm2, %%mm0 \n\t"
319 "psubw %%mm3, %%mm1 \n\t"
320 "pandn %%mm0, %%mm4 \n\t"
321 "pandn %%mm1, %%mm5 \n\t"
322 "movq %%mm4, (%0, %%"REG_a") \n\t"
323 "movq %%mm5, 8(%0, %%"REG_a") \n\t"
325 "add $16, %%"REG_a" \n\t"
327 ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
332 static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
333 DCTELEM *block, int n, int qscale)
336 const uint16_t *quant_matrix;
339 assert(s->block_last_index[n]>=0);
341 if(s->alternate_scan) nCoeffs= 63; //FIXME
342 else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
345 block0 = block[0] * s->y_dc_scale;
347 block0 = block[0] * s->c_dc_scale;
348 quant_matrix = s->intra_matrix;
350 "pcmpeqw %%mm7, %%mm7 \n\t"
351 "psrlw $15, %%mm7 \n\t"
352 "movd %2, %%mm6 \n\t"
353 "packssdw %%mm6, %%mm6 \n\t"
354 "packssdw %%mm6, %%mm6 \n\t"
355 "mov %3, %%"REG_a" \n\t"
358 "movq (%0, %%"REG_a"), %%mm0 \n\t"
359 "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
360 "movq (%1, %%"REG_a"), %%mm4 \n\t"
361 "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
362 "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
363 "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
364 "pxor %%mm2, %%mm2 \n\t"
365 "pxor %%mm3, %%mm3 \n\t"
366 "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
367 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
368 "pxor %%mm2, %%mm0 \n\t"
369 "pxor %%mm3, %%mm1 \n\t"
370 "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
371 "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
372 "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
373 "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
374 "pxor %%mm4, %%mm4 \n\t"
375 "pxor %%mm5, %%mm5 \n\t" // FIXME slow
376 "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
377 "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
378 "psraw $3, %%mm0 \n\t"
379 "psraw $3, %%mm1 \n\t"
380 "pxor %%mm2, %%mm0 \n\t"
381 "pxor %%mm3, %%mm1 \n\t"
382 "psubw %%mm2, %%mm0 \n\t"
383 "psubw %%mm3, %%mm1 \n\t"
384 "pandn %%mm0, %%mm4 \n\t"
385 "pandn %%mm1, %%mm5 \n\t"
386 "movq %%mm4, (%0, %%"REG_a") \n\t"
387 "movq %%mm5, 8(%0, %%"REG_a") \n\t"
389 "add $16, %%"REG_a" \n\t"
391 ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
395 //Note, we do not do mismatch control for intra as errors cannot accumulate
398 static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
399 DCTELEM *block, int n, int qscale)
402 const uint16_t *quant_matrix;
404 assert(s->block_last_index[n]>=0);
406 if(s->alternate_scan) nCoeffs= 63; //FIXME
407 else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
409 quant_matrix = s->inter_matrix;
411 "pcmpeqw %%mm7, %%mm7 \n\t"
412 "psrlq $48, %%mm7 \n\t"
413 "movd %2, %%mm6 \n\t"
414 "packssdw %%mm6, %%mm6 \n\t"
415 "packssdw %%mm6, %%mm6 \n\t"
416 "mov %3, %%"REG_a" \n\t"
419 "movq (%0, %%"REG_a"), %%mm0 \n\t"
420 "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
421 "movq (%1, %%"REG_a"), %%mm4 \n\t"
422 "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
423 "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
424 "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
425 "pxor %%mm2, %%mm2 \n\t"
426 "pxor %%mm3, %%mm3 \n\t"
427 "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
428 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
429 "pxor %%mm2, %%mm0 \n\t"
430 "pxor %%mm3, %%mm1 \n\t"
431 "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
432 "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
433 "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
434 "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
435 "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*2*q
436 "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*2*q
437 "paddw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
438 "paddw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
439 "pxor %%mm4, %%mm4 \n\t"
440 "pxor %%mm5, %%mm5 \n\t" // FIXME slow
441 "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
442 "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
443 "psrlw $4, %%mm0 \n\t"
444 "psrlw $4, %%mm1 \n\t"
445 "pxor %%mm2, %%mm0 \n\t"
446 "pxor %%mm3, %%mm1 \n\t"
447 "psubw %%mm2, %%mm0 \n\t"
448 "psubw %%mm3, %%mm1 \n\t"
449 "pandn %%mm0, %%mm4 \n\t"
450 "pandn %%mm1, %%mm5 \n\t"
451 "pxor %%mm4, %%mm7 \n\t"
452 "pxor %%mm5, %%mm7 \n\t"
453 "movq %%mm4, (%0, %%"REG_a") \n\t"
454 "movq %%mm5, 8(%0, %%"REG_a") \n\t"
456 "add $16, %%"REG_a" \n\t"
458 "movd 124(%0, %3), %%mm0 \n\t"
459 "movq %%mm7, %%mm6 \n\t"
460 "psrlq $32, %%mm7 \n\t"
461 "pxor %%mm6, %%mm7 \n\t"
462 "movq %%mm7, %%mm6 \n\t"
463 "psrlq $16, %%mm7 \n\t"
464 "pxor %%mm6, %%mm7 \n\t"
465 "pslld $31, %%mm7 \n\t"
466 "psrlq $15, %%mm7 \n\t"
467 "pxor %%mm7, %%mm0 \n\t"
468 "movd %%mm0, 124(%0, %3) \n\t"
470 ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "r" (-2*nCoeffs)
475 static void denoise_dct_mmx(MpegEncContext *s, DCTELEM *block){
476 const int intra= s->mb_intra;
477 int *sum= s->dct_error_sum[intra];
478 uint16_t *offset= s->dct_offset[intra];
480 s->dct_count[intra]++;
483 "pxor %%mm7, %%mm7 \n\t"
485 "pxor %%mm0, %%mm0 \n\t"
486 "pxor %%mm1, %%mm1 \n\t"
487 "movq (%0), %%mm2 \n\t"
488 "movq 8(%0), %%mm3 \n\t"
489 "pcmpgtw %%mm2, %%mm0 \n\t"
490 "pcmpgtw %%mm3, %%mm1 \n\t"
491 "pxor %%mm0, %%mm2 \n\t"
492 "pxor %%mm1, %%mm3 \n\t"
493 "psubw %%mm0, %%mm2 \n\t"
494 "psubw %%mm1, %%mm3 \n\t"
495 "movq %%mm2, %%mm4 \n\t"
496 "movq %%mm3, %%mm5 \n\t"
497 "psubusw (%2), %%mm2 \n\t"
498 "psubusw 8(%2), %%mm3 \n\t"
499 "pxor %%mm0, %%mm2 \n\t"
500 "pxor %%mm1, %%mm3 \n\t"
501 "psubw %%mm0, %%mm2 \n\t"
502 "psubw %%mm1, %%mm3 \n\t"
503 "movq %%mm2, (%0) \n\t"
504 "movq %%mm3, 8(%0) \n\t"
505 "movq %%mm4, %%mm2 \n\t"
506 "movq %%mm5, %%mm3 \n\t"
507 "punpcklwd %%mm7, %%mm4 \n\t"
508 "punpckhwd %%mm7, %%mm2 \n\t"
509 "punpcklwd %%mm7, %%mm5 \n\t"
510 "punpckhwd %%mm7, %%mm3 \n\t"
511 "paddd (%1), %%mm4 \n\t"
512 "paddd 8(%1), %%mm2 \n\t"
513 "paddd 16(%1), %%mm5 \n\t"
514 "paddd 24(%1), %%mm3 \n\t"
515 "movq %%mm4, (%1) \n\t"
516 "movq %%mm2, 8(%1) \n\t"
517 "movq %%mm5, 16(%1) \n\t"
518 "movq %%mm3, 24(%1) \n\t"
524 : "+r" (block), "+r" (sum), "+r" (offset)
529 static void denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
530 const int intra= s->mb_intra;
531 int *sum= s->dct_error_sum[intra];
532 uint16_t *offset= s->dct_offset[intra];
534 s->dct_count[intra]++;
537 "pxor %%xmm7, %%xmm7 \n\t"
539 "pxor %%xmm0, %%xmm0 \n\t"
540 "pxor %%xmm1, %%xmm1 \n\t"
541 "movdqa (%0), %%xmm2 \n\t"
542 "movdqa 16(%0), %%xmm3 \n\t"
543 "pcmpgtw %%xmm2, %%xmm0 \n\t"
544 "pcmpgtw %%xmm3, %%xmm1 \n\t"
545 "pxor %%xmm0, %%xmm2 \n\t"
546 "pxor %%xmm1, %%xmm3 \n\t"
547 "psubw %%xmm0, %%xmm2 \n\t"
548 "psubw %%xmm1, %%xmm3 \n\t"
549 "movdqa %%xmm2, %%xmm4 \n\t"
550 "movdqa %%xmm3, %%xmm5 \n\t"
551 "psubusw (%2), %%xmm2 \n\t"
552 "psubusw 16(%2), %%xmm3 \n\t"
553 "pxor %%xmm0, %%xmm2 \n\t"
554 "pxor %%xmm1, %%xmm3 \n\t"
555 "psubw %%xmm0, %%xmm2 \n\t"
556 "psubw %%xmm1, %%xmm3 \n\t"
557 "movdqa %%xmm2, (%0) \n\t"
558 "movdqa %%xmm3, 16(%0) \n\t"
559 "movdqa %%xmm4, %%xmm6 \n\t"
560 "movdqa %%xmm5, %%xmm0 \n\t"
561 "punpcklwd %%xmm7, %%xmm4 \n\t"
562 "punpckhwd %%xmm7, %%xmm6 \n\t"
563 "punpcklwd %%xmm7, %%xmm5 \n\t"
564 "punpckhwd %%xmm7, %%xmm0 \n\t"
565 "paddd (%1), %%xmm4 \n\t"
566 "paddd 16(%1), %%xmm6 \n\t"
567 "paddd 32(%1), %%xmm5 \n\t"
568 "paddd 48(%1), %%xmm0 \n\t"
569 "movdqa %%xmm4, (%1) \n\t"
570 "movdqa %%xmm6, 16(%1) \n\t"
571 "movdqa %%xmm5, 32(%1) \n\t"
572 "movdqa %%xmm0, 48(%1) \n\t"
578 : "+r" (block), "+r" (sum), "+r" (offset)
580 XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
581 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
585 #endif /* HAVE_INLINE_ASM */
587 void ff_MPV_common_init_x86(MpegEncContext *s)
590 int mm_flags = av_get_cpu_flags();
592 if (mm_flags & AV_CPU_FLAG_MMX) {
593 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_mmx;
594 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
595 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
596 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
597 if(!(s->flags & CODEC_FLAG_BITEXACT))
598 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
599 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
601 if (mm_flags & AV_CPU_FLAG_SSE2) {
602 s->denoise_dct= denoise_dct_sse2;
604 s->denoise_dct= denoise_dct_mmx;
607 #endif /* HAVE_INLINE_ASM */