2
* The simplest mpeg encoder (well, it was the simplest!)
3
* Copyright (c) 2000,2001 Fabrice Bellard.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
* Optimized for ia32 cpus by Nick Kurshev <nickols_k@mail.ru>
20
* h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
23
#include "../dsputil.h"
24
#include "../mpegvideo.h"
25
#include "../avcodec.h"
28
extern uint8_t zigzag_direct_noperm[64];
29
extern uint16_t inv_zigzag_direct16[64];
31
static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL;
32
static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
35
static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,
36
DCTELEM *block, int n, int qscale)
38
long level, qmul, qadd, nCoeffs;
42
assert(s->block_last_index[n]>=0 || s->h263_aic);
46
level = block[0] * s->y_dc_scale;
48
level = block[0] * s->c_dc_scale;
49
qadd = (qscale - 1) | 1;
57
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
58
//printf("%d %d ", qmul, qadd);
60
"movd %1, %%mm6 \n\t" //qmul
61
"packssdw %%mm6, %%mm6 \n\t"
62
"packssdw %%mm6, %%mm6 \n\t"
63
"movd %2, %%mm5 \n\t" //qadd
64
"pxor %%mm7, %%mm7 \n\t"
65
"packssdw %%mm5, %%mm5 \n\t"
66
"packssdw %%mm5, %%mm5 \n\t"
67
"psubw %%mm5, %%mm7 \n\t"
68
"pxor %%mm4, %%mm4 \n\t"
71
"movq (%0, %3), %%mm0 \n\t"
72
"movq 8(%0, %3), %%mm1 \n\t"
74
"pmullw %%mm6, %%mm0 \n\t"
75
"pmullw %%mm6, %%mm1 \n\t"
77
"movq (%0, %3), %%mm2 \n\t"
78
"movq 8(%0, %3), %%mm3 \n\t"
80
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
81
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
83
"pxor %%mm2, %%mm0 \n\t"
84
"pxor %%mm3, %%mm1 \n\t"
86
"paddw %%mm7, %%mm0 \n\t"
87
"paddw %%mm7, %%mm1 \n\t"
89
"pxor %%mm0, %%mm2 \n\t"
90
"pxor %%mm1, %%mm3 \n\t"
92
"pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
93
"pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
95
"pandn %%mm2, %%mm0 \n\t"
96
"pandn %%mm3, %%mm1 \n\t"
98
"movq %%mm0, (%0, %3) \n\t"
99
"movq %%mm1, 8(%0, %3) \n\t"
103
::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(-nCoeffs))
110
static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,
111
DCTELEM *block, int n, int qscale)
113
long qmul, qadd, nCoeffs;
116
qadd = (qscale - 1) | 1;
118
assert(s->block_last_index[n]>=0 || s->h263_aic);
120
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
121
//printf("%d %d ", qmul, qadd);
123
"movd %1, %%mm6 \n\t" //qmul
124
"packssdw %%mm6, %%mm6 \n\t"
125
"packssdw %%mm6, %%mm6 \n\t"
126
"movd %2, %%mm5 \n\t" //qadd
127
"pxor %%mm7, %%mm7 \n\t"
128
"packssdw %%mm5, %%mm5 \n\t"
129
"packssdw %%mm5, %%mm5 \n\t"
130
"psubw %%mm5, %%mm7 \n\t"
131
"pxor %%mm4, %%mm4 \n\t"
134
"movq (%0, %3), %%mm0 \n\t"
135
"movq 8(%0, %3), %%mm1 \n\t"
137
"pmullw %%mm6, %%mm0 \n\t"
138
"pmullw %%mm6, %%mm1 \n\t"
140
"movq (%0, %3), %%mm2 \n\t"
141
"movq 8(%0, %3), %%mm3 \n\t"
143
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
144
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
146
"pxor %%mm2, %%mm0 \n\t"
147
"pxor %%mm3, %%mm1 \n\t"
149
"paddw %%mm7, %%mm0 \n\t"
150
"paddw %%mm7, %%mm1 \n\t"
152
"pxor %%mm0, %%mm2 \n\t"
153
"pxor %%mm1, %%mm3 \n\t"
155
"pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
156
"pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
158
"pandn %%mm2, %%mm0 \n\t"
159
"pandn %%mm3, %%mm1 \n\t"
161
"movq %%mm0, (%0, %3) \n\t"
162
"movq %%mm1, 8(%0, %3) \n\t"
166
::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(-nCoeffs))
174
Note: looking at PARANOID:
175
"enable all paranoid tests for rounding, overflows, etc..."
178
if (level < -2048 || level > 2047)
179
fprintf(stderr, "unquant error %d %d\n", i, level);
181
We can suppose that result of two multiplications can't be greate of 0xFFFF
182
i.e. is 16-bit, so we use here only PMULLW instruction and can avoid
183
a complex multiplication.
184
=====================================================
185
Full formula for multiplication of 2 integer numbers
186
which are represent as high:low words:
187
input: value1 = high1:low1
189
output: value3 = value1*value2
190
value3=high3:low3 (on overflow: modulus 2^32 wrap-around)
191
this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4
192
but this algorithm will compute only 0x66cb0ce4
193
this limited by 16-bit size of operands
194
---------------------------------
197
tlow1 = tlow1 + tlow2
198
high3:low3 = low1*low2
201
static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,
202
DCTELEM *block, int n, int qscale)
205
const uint16_t *quant_matrix;
208
assert(s->block_last_index[n]>=0);
210
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
213
block0 = block[0] * s->y_dc_scale;
215
block0 = block[0] * s->c_dc_scale;
216
/* XXX: only mpeg1 */
217
quant_matrix = s->intra_matrix;
219
"pcmpeqw %%mm7, %%mm7 \n\t"
220
"psrlw $15, %%mm7 \n\t"
221
"movd %2, %%mm6 \n\t"
222
"packssdw %%mm6, %%mm6 \n\t"
223
"packssdw %%mm6, %%mm6 \n\t"
224
"mov %3, %%"REG_a" \n\t"
227
"movq (%0, %%"REG_a"), %%mm0 \n\t"
228
"movq 8(%0, %%"REG_a"), %%mm1 \n\t"
229
"movq (%1, %%"REG_a"), %%mm4 \n\t"
230
"movq 8(%1, %%"REG_a"), %%mm5 \n\t"
231
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
232
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
233
"pxor %%mm2, %%mm2 \n\t"
234
"pxor %%mm3, %%mm3 \n\t"
235
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
236
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
237
"pxor %%mm2, %%mm0 \n\t"
238
"pxor %%mm3, %%mm1 \n\t"
239
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
240
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
241
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
242
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
243
"pxor %%mm4, %%mm4 \n\t"
244
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
245
"pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
246
"pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
247
"psraw $3, %%mm0 \n\t"
248
"psraw $3, %%mm1 \n\t"
249
"psubw %%mm7, %%mm0 \n\t"
250
"psubw %%mm7, %%mm1 \n\t"
251
"por %%mm7, %%mm0 \n\t"
252
"por %%mm7, %%mm1 \n\t"
253
"pxor %%mm2, %%mm0 \n\t"
254
"pxor %%mm3, %%mm1 \n\t"
255
"psubw %%mm2, %%mm0 \n\t"
256
"psubw %%mm3, %%mm1 \n\t"
257
"pandn %%mm0, %%mm4 \n\t"
258
"pandn %%mm1, %%mm5 \n\t"
259
"movq %%mm4, (%0, %%"REG_a") \n\t"
260
"movq %%mm5, 8(%0, %%"REG_a") \n\t"
262
"add $16, %%"REG_a" \n\t"
264
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
270
static void dct_unquantize_mpeg1_inter_mmx(MpegEncContext *s,
271
DCTELEM *block, int n, int qscale)
274
const uint16_t *quant_matrix;
276
assert(s->block_last_index[n]>=0);
278
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
280
quant_matrix = s->inter_matrix;
282
"pcmpeqw %%mm7, %%mm7 \n\t"
283
"psrlw $15, %%mm7 \n\t"
284
"movd %2, %%mm6 \n\t"
285
"packssdw %%mm6, %%mm6 \n\t"
286
"packssdw %%mm6, %%mm6 \n\t"
287
"mov %3, %%"REG_a" \n\t"
290
"movq (%0, %%"REG_a"), %%mm0 \n\t"
291
"movq 8(%0, %%"REG_a"), %%mm1 \n\t"
292
"movq (%1, %%"REG_a"), %%mm4 \n\t"
293
"movq 8(%1, %%"REG_a"), %%mm5 \n\t"
294
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
295
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
296
"pxor %%mm2, %%mm2 \n\t"
297
"pxor %%mm3, %%mm3 \n\t"
298
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
299
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
300
"pxor %%mm2, %%mm0 \n\t"
301
"pxor %%mm3, %%mm1 \n\t"
302
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
303
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
304
"paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
305
"paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
306
"paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
307
"paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
308
"pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
309
"pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
310
"pxor %%mm4, %%mm4 \n\t"
311
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
312
"pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
313
"pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
314
"psraw $4, %%mm0 \n\t"
315
"psraw $4, %%mm1 \n\t"
316
"psubw %%mm7, %%mm0 \n\t"
317
"psubw %%mm7, %%mm1 \n\t"
318
"por %%mm7, %%mm0 \n\t"
319
"por %%mm7, %%mm1 \n\t"
320
"pxor %%mm2, %%mm0 \n\t"
321
"pxor %%mm3, %%mm1 \n\t"
322
"psubw %%mm2, %%mm0 \n\t"
323
"psubw %%mm3, %%mm1 \n\t"
324
"pandn %%mm0, %%mm4 \n\t"
325
"pandn %%mm1, %%mm5 \n\t"
326
"movq %%mm4, (%0, %%"REG_a") \n\t"
327
"movq %%mm5, 8(%0, %%"REG_a") \n\t"
329
"add $16, %%"REG_a" \n\t"
331
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
336
static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
337
DCTELEM *block, int n, int qscale)
340
const uint16_t *quant_matrix;
343
assert(s->block_last_index[n]>=0);
345
if(s->alternate_scan) nCoeffs= 63; //FIXME
346
else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
349
block0 = block[0] * s->y_dc_scale;
351
block0 = block[0] * s->c_dc_scale;
352
quant_matrix = s->intra_matrix;
354
"pcmpeqw %%mm7, %%mm7 \n\t"
355
"psrlw $15, %%mm7 \n\t"
356
"movd %2, %%mm6 \n\t"
357
"packssdw %%mm6, %%mm6 \n\t"
358
"packssdw %%mm6, %%mm6 \n\t"
359
"mov %3, %%"REG_a" \n\t"
362
"movq (%0, %%"REG_a"), %%mm0 \n\t"
363
"movq 8(%0, %%"REG_a"), %%mm1 \n\t"
364
"movq (%1, %%"REG_a"), %%mm4 \n\t"
365
"movq 8(%1, %%"REG_a"), %%mm5 \n\t"
366
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
367
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
368
"pxor %%mm2, %%mm2 \n\t"
369
"pxor %%mm3, %%mm3 \n\t"
370
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
371
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
372
"pxor %%mm2, %%mm0 \n\t"
373
"pxor %%mm3, %%mm1 \n\t"
374
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
375
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
376
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
377
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
378
"pxor %%mm4, %%mm4 \n\t"
379
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
380
"pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
381
"pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
382
"psraw $3, %%mm0 \n\t"
383
"psraw $3, %%mm1 \n\t"
384
"pxor %%mm2, %%mm0 \n\t"
385
"pxor %%mm3, %%mm1 \n\t"
386
"psubw %%mm2, %%mm0 \n\t"
387
"psubw %%mm3, %%mm1 \n\t"
388
"pandn %%mm0, %%mm4 \n\t"
389
"pandn %%mm1, %%mm5 \n\t"
390
"movq %%mm4, (%0, %%"REG_a") \n\t"
391
"movq %%mm5, 8(%0, %%"REG_a") \n\t"
393
"add $16, %%"REG_a" \n\t"
395
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
399
//Note, we dont do mismatch control for intra as errors cannot accumulate
402
static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
403
DCTELEM *block, int n, int qscale)
406
const uint16_t *quant_matrix;
408
assert(s->block_last_index[n]>=0);
410
if(s->alternate_scan) nCoeffs= 63; //FIXME
411
else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
413
quant_matrix = s->inter_matrix;
415
"pcmpeqw %%mm7, %%mm7 \n\t"
416
"psrlq $48, %%mm7 \n\t"
417
"movd %2, %%mm6 \n\t"
418
"packssdw %%mm6, %%mm6 \n\t"
419
"packssdw %%mm6, %%mm6 \n\t"
420
"mov %3, %%"REG_a" \n\t"
423
"movq (%0, %%"REG_a"), %%mm0 \n\t"
424
"movq 8(%0, %%"REG_a"), %%mm1 \n\t"
425
"movq (%1, %%"REG_a"), %%mm4 \n\t"
426
"movq 8(%1, %%"REG_a"), %%mm5 \n\t"
427
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
428
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
429
"pxor %%mm2, %%mm2 \n\t"
430
"pxor %%mm3, %%mm3 \n\t"
431
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
432
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
433
"pxor %%mm2, %%mm0 \n\t"
434
"pxor %%mm3, %%mm1 \n\t"
435
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
436
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
437
"paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
438
"paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
439
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*2*q
440
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*2*q
441
"paddw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
442
"paddw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
443
"pxor %%mm4, %%mm4 \n\t"
444
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
445
"pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
446
"pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
447
"psrlw $4, %%mm0 \n\t"
448
"psrlw $4, %%mm1 \n\t"
449
"pxor %%mm2, %%mm0 \n\t"
450
"pxor %%mm3, %%mm1 \n\t"
451
"psubw %%mm2, %%mm0 \n\t"
452
"psubw %%mm3, %%mm1 \n\t"
453
"pandn %%mm0, %%mm4 \n\t"
454
"pandn %%mm1, %%mm5 \n\t"
455
"pxor %%mm4, %%mm7 \n\t"
456
"pxor %%mm5, %%mm7 \n\t"
457
"movq %%mm4, (%0, %%"REG_a") \n\t"
458
"movq %%mm5, 8(%0, %%"REG_a") \n\t"
460
"add $16, %%"REG_a" \n\t"
462
"movd 124(%0, %3), %%mm0 \n\t"
463
"movq %%mm7, %%mm6 \n\t"
464
"psrlq $32, %%mm7 \n\t"
465
"pxor %%mm6, %%mm7 \n\t"
466
"movq %%mm7, %%mm6 \n\t"
467
"psrlq $16, %%mm7 \n\t"
468
"pxor %%mm6, %%mm7 \n\t"
469
"pslld $31, %%mm7 \n\t"
470
"psrlq $15, %%mm7 \n\t"
471
"pxor %%mm7, %%mm0 \n\t"
472
"movd %%mm0, 124(%0, %3) \n\t"
474
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "r" (-2*nCoeffs)
479
/* draw the edges of width 'w' of an image of size width, height
480
this mmx version can only handle w==8 || w==16 */
481
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
483
uint8_t *ptr, *last_line;
486
last_line = buf + (height - 1) * wrap;
493
"movd (%0), %%mm0 \n\t"
494
"punpcklbw %%mm0, %%mm0 \n\t"
495
"punpcklwd %%mm0, %%mm0 \n\t"
496
"punpckldq %%mm0, %%mm0 \n\t"
497
"movq %%mm0, -8(%0) \n\t"
498
"movq -8(%0, %2), %%mm1 \n\t"
499
"punpckhbw %%mm1, %%mm1 \n\t"
500
"punpckhwd %%mm1, %%mm1 \n\t"
501
"punpckhdq %%mm1, %%mm1 \n\t"
502
"movq %%mm1, (%0, %2) \n\t"
507
: "r" ((long)wrap), "r" ((long)width), "r" (ptr + wrap*height)
514
"movd (%0), %%mm0 \n\t"
515
"punpcklbw %%mm0, %%mm0 \n\t"
516
"punpcklwd %%mm0, %%mm0 \n\t"
517
"punpckldq %%mm0, %%mm0 \n\t"
518
"movq %%mm0, -8(%0) \n\t"
519
"movq %%mm0, -16(%0) \n\t"
520
"movq -8(%0, %2), %%mm1 \n\t"
521
"punpckhbw %%mm1, %%mm1 \n\t"
522
"punpckhwd %%mm1, %%mm1 \n\t"
523
"punpckhdq %%mm1, %%mm1 \n\t"
524
"movq %%mm1, (%0, %2) \n\t"
525
"movq %%mm1, 8(%0, %2) \n\t"
530
: "r" ((long)wrap), "r" ((long)width), "r" (ptr + wrap*height)
535
/* top and bottom (and hopefully also the corners) */
536
ptr= buf - (i + 1) * wrap - w;
539
"movq (%1, %0), %%mm0 \n\t"
540
"movq %%mm0, (%0) \n\t"
541
"movq %%mm0, (%0, %2) \n\t"
542
"movq %%mm0, (%0, %2, 2) \n\t"
543
"movq %%mm0, (%0, %3) \n\t"
548
: "r" ((long)buf - (long)ptr - w), "r" ((long)-wrap), "r" ((long)-wrap*3), "r" (ptr+width+2*w)
550
ptr= last_line + (i + 1) * wrap - w;
553
"movq (%1, %0), %%mm0 \n\t"
554
"movq %%mm0, (%0) \n\t"
555
"movq %%mm0, (%0, %2) \n\t"
556
"movq %%mm0, (%0, %2, 2) \n\t"
557
"movq %%mm0, (%0, %3) \n\t"
562
: "r" ((long)last_line - (long)ptr - w), "r" ((long)wrap), "r" ((long)wrap*3), "r" (ptr+width+2*w)
567
static void denoise_dct_mmx(MpegEncContext *s, DCTELEM *block){
568
const int intra= s->mb_intra;
569
int *sum= s->dct_error_sum[intra];
570
uint16_t *offset= s->dct_offset[intra];
572
s->dct_count[intra]++;
575
"pxor %%mm7, %%mm7 \n\t"
577
"pxor %%mm0, %%mm0 \n\t"
578
"pxor %%mm1, %%mm1 \n\t"
579
"movq (%0), %%mm2 \n\t"
580
"movq 8(%0), %%mm3 \n\t"
581
"pcmpgtw %%mm2, %%mm0 \n\t"
582
"pcmpgtw %%mm3, %%mm1 \n\t"
583
"pxor %%mm0, %%mm2 \n\t"
584
"pxor %%mm1, %%mm3 \n\t"
585
"psubw %%mm0, %%mm2 \n\t"
586
"psubw %%mm1, %%mm3 \n\t"
587
"movq %%mm2, %%mm4 \n\t"
588
"movq %%mm3, %%mm5 \n\t"
589
"psubusw (%2), %%mm2 \n\t"
590
"psubusw 8(%2), %%mm3 \n\t"
591
"pxor %%mm0, %%mm2 \n\t"
592
"pxor %%mm1, %%mm3 \n\t"
593
"psubw %%mm0, %%mm2 \n\t"
594
"psubw %%mm1, %%mm3 \n\t"
595
"movq %%mm2, (%0) \n\t"
596
"movq %%mm3, 8(%0) \n\t"
597
"movq %%mm4, %%mm2 \n\t"
598
"movq %%mm5, %%mm3 \n\t"
599
"punpcklwd %%mm7, %%mm4 \n\t"
600
"punpckhwd %%mm7, %%mm2 \n\t"
601
"punpcklwd %%mm7, %%mm5 \n\t"
602
"punpckhwd %%mm7, %%mm3 \n\t"
603
"paddd (%1), %%mm4 \n\t"
604
"paddd 8(%1), %%mm2 \n\t"
605
"paddd 16(%1), %%mm5 \n\t"
606
"paddd 24(%1), %%mm3 \n\t"
607
"movq %%mm4, (%1) \n\t"
608
"movq %%mm2, 8(%1) \n\t"
609
"movq %%mm5, 16(%1) \n\t"
610
"movq %%mm3, 24(%1) \n\t"
616
: "+r" (block), "+r" (sum), "+r" (offset)
621
static void denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){
622
const int intra= s->mb_intra;
623
int *sum= s->dct_error_sum[intra];
624
uint16_t *offset= s->dct_offset[intra];
626
s->dct_count[intra]++;
629
"pxor %%xmm7, %%xmm7 \n\t"
631
"pxor %%xmm0, %%xmm0 \n\t"
632
"pxor %%xmm1, %%xmm1 \n\t"
633
"movdqa (%0), %%xmm2 \n\t"
634
"movdqa 16(%0), %%xmm3 \n\t"
635
"pcmpgtw %%xmm2, %%xmm0 \n\t"
636
"pcmpgtw %%xmm3, %%xmm1 \n\t"
637
"pxor %%xmm0, %%xmm2 \n\t"
638
"pxor %%xmm1, %%xmm3 \n\t"
639
"psubw %%xmm0, %%xmm2 \n\t"
640
"psubw %%xmm1, %%xmm3 \n\t"
641
"movdqa %%xmm2, %%xmm4 \n\t"
642
"movdqa %%xmm3, %%xmm5 \n\t"
643
"psubusw (%2), %%xmm2 \n\t"
644
"psubusw 16(%2), %%xmm3 \n\t"
645
"pxor %%xmm0, %%xmm2 \n\t"
646
"pxor %%xmm1, %%xmm3 \n\t"
647
"psubw %%xmm0, %%xmm2 \n\t"
648
"psubw %%xmm1, %%xmm3 \n\t"
649
"movdqa %%xmm2, (%0) \n\t"
650
"movdqa %%xmm3, 16(%0) \n\t"
651
"movdqa %%xmm4, %%xmm6 \n\t"
652
"movdqa %%xmm5, %%xmm0 \n\t"
653
"punpcklwd %%xmm7, %%xmm4 \n\t"
654
"punpckhwd %%xmm7, %%xmm6 \n\t"
655
"punpcklwd %%xmm7, %%xmm5 \n\t"
656
"punpckhwd %%xmm7, %%xmm0 \n\t"
657
"paddd (%1), %%xmm4 \n\t"
658
"paddd 16(%1), %%xmm6 \n\t"
659
"paddd 32(%1), %%xmm5 \n\t"
660
"paddd 48(%1), %%xmm0 \n\t"
661
"movdqa %%xmm4, (%1) \n\t"
662
"movdqa %%xmm6, 16(%1) \n\t"
663
"movdqa %%xmm5, 32(%1) \n\t"
664
"movdqa %%xmm0, 48(%1) \n\t"
670
: "+r" (block), "+r" (sum), "+r" (offset)
676
#define RENAME(a) a ## _MMX
677
#define RENAMEl(a) a ## _mmx
678
#include "mpegvideo_mmx_template.c"
683
#define RENAME(a) a ## _MMX2
684
#define RENAMEl(a) a ## _mmx2
685
#include "mpegvideo_mmx_template.c"
689
#define RENAME(a) a ## _SSE2
690
#define RENAMEl(a) a ## _sse2
691
#include "mpegvideo_mmx_template.c"
693
void MPV_common_init_mmx(MpegEncContext *s)
695
if (mm_flags & MM_MMX) {
696
const int dct_algo = s->avctx->dct_algo;
698
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_mmx;
699
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
700
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
701
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
702
if(!(s->flags & CODEC_FLAG_BITEXACT))
703
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
704
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
706
draw_edges = draw_edges_mmx;
708
if (mm_flags & MM_SSE2) {
709
s->denoise_dct= denoise_dct_sse2;
711
s->denoise_dct= denoise_dct_mmx;
714
if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
715
if(mm_flags & MM_SSE2){
716
s->dct_quantize= dct_quantize_SSE2;
717
} else if(mm_flags & MM_MMXEXT){
718
s->dct_quantize= dct_quantize_MMX2;
720
s->dct_quantize= dct_quantize_MMX;