dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>

Originally committed as revision 205 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Arpi 2001-11-03 02:22:48 +00:00
parent 4949028f85
commit 7f3f5ec87b

View File

@ -65,6 +65,86 @@ void MPV_frame_start(MpegEncContext *s)
static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL; static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL;
static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL; static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
static void dct_unquantize_h263_mmx(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, qmul, qadd;
qmul = s->qscale << 1;
qadd = (s->qscale - 1) | 1;
if (s->mb_intra) {
if (n < 4)
block[0] = block[0] * s->y_dc_scale;
else
block[0] = block[0] * s->c_dc_scale;
for(i=1; i<8; i++) {
level = block[i];
if (level) {
if (level < 0) {
level = level * qmul - qadd;
} else {
level = level * qmul + qadd;
}
block[i] = level;
}
}
} else {
i = 0;
}
asm volatile(
"movd %1, %%mm6 \n\t" //qmul
"packssdw %%mm6, %%mm6 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"movd %2, %%mm5 \n\t" //qadd
"pxor %%mm7, %%mm7 \n\t"
"packssdw %%mm5, %%mm5 \n\t"
"packssdw %%mm5, %%mm5 \n\t"
"psubw %%mm5, %%mm7 \n\t"
"pxor %%mm4, %%mm4 \n\t"
"1: \n\t"
"movq (%0, %3), %%mm0 \n\t"
"movq 8(%0, %3), %%mm1 \n\t"
"pmullw %%mm6, %%mm0 \n\t"
"pmullw %%mm6, %%mm1 \n\t"
"movq (%0, %3), %%mm2 \n\t"
"movq 8(%0, %3), %%mm3 \n\t"
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
"pxor %%mm2, %%mm0 \n\t"
"pxor %%mm3, %%mm1 \n\t"
"paddw %%mm7, %%mm0 \n\t"
"paddw %%mm7, %%mm1 \n\t"
"pxor %%mm0, %%mm2 \n\t"
"pxor %%mm1, %%mm3 \n\t"
"pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
"pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
"pandn %%mm2, %%mm0 \n\t"
"pandn %%mm3, %%mm1 \n\t"
"movq %%mm0, (%0, %3) \n\t"
"movq %%mm1, 8(%0, %3) \n\t"
"addl $16, %3 \n\t"
"cmpl $128, %3 \n\t"
"jb 1b \n\t"
::"r" (block), "g"(qmul), "g" (qadd), "r" (2*i)
: "memory"
);
}
/* /*
NK: NK:
Note: looking at PARANOID: Note: looking at PARANOID:
@ -142,9 +222,9 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
"pcmpgtw %%mm6, %%mm2\n\t" "pcmpgtw %%mm6, %%mm2\n\t"
"pmullw %2, %%mm1\n\t" "pmullw %2, %%mm1\n\t"
"pandn %%mm4, %%mm2\n\t" "pandn %%mm4, %%mm2\n\t"
"por %%mm5, %%mm2\n\t" "por %%mm5, %%mm2\n\t"
"pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */ "pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */
"pcmpeqw %%mm6, %%mm3\n\t" "pcmpeqw %%mm6, %%mm3\n\t"
"pmullw %%mm0, %%mm1\n\t" "pmullw %%mm0, %%mm1\n\t"
"psraw $3, %%mm1\n\t" "psraw $3, %%mm1\n\t"
@ -164,7 +244,7 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
unquant_even: unquant_even:
quant_matrix = s->non_intra_matrix; quant_matrix = s->non_intra_matrix;
/* Align on 4 elements boundary */ /* Align on 4 elements boundary */
while(i&3) while(i&7)
{ {
level = block[i]; level = block[i];
if (level) { if (level) {
@ -177,6 +257,61 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
} }
i++; i++;
} }
asm volatile(
"pcmpeqw %%mm7, %%mm7 \n\t"
"psrlw $15, %%mm7 \n\t"
"movd %2, %%mm6 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq (%0, %3), %%mm0 \n\t"
"movq 8(%0, %3), %%mm1 \n\t"
"movq (%1, %3), %%mm4 \n\t"
"movq 8(%1, %3), %%mm5 \n\t"
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
"pxor %%mm2, %%mm2 \n\t"
"pxor %%mm3, %%mm3 \n\t"
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
"pxor %%mm2, %%mm0 \n\t"
"pxor %%mm3, %%mm1 \n\t"
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
"paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
"paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
"paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
"paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
"pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
"pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
"pxor %%mm4, %%mm4 \n\t"
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
"pcmpeqw (%0, %3), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
"pcmpeqw 8(%0, %3), %%mm5 \n\t" // block[i] == 0 ? -1 : 0
"psraw $4, %%mm0 \n\t"
"psraw $4, %%mm1 \n\t"
"psubw %%mm7, %%mm0 \n\t"
"psubw %%mm7, %%mm1 \n\t"
"por %%mm7, %%mm0 \n\t"
"por %%mm7, %%mm1 \n\t"
"pxor %%mm2, %%mm0 \n\t"
"pxor %%mm3, %%mm1 \n\t"
"psubw %%mm2, %%mm0 \n\t"
"psubw %%mm3, %%mm1 \n\t"
"pandn %%mm0, %%mm4 \n\t"
"pandn %%mm1, %%mm5 \n\t"
"movq %%mm4, (%0, %3) \n\t"
"movq %%mm5, 8(%0, %3) \n\t"
"addl $16, %3 \n\t"
"cmpl $128, %3 \n\t"
"jb 1b \n\t"
::"r" (block), "r"(quant_matrix), "g" (qscale), "r" (2*i)
: "memory"
);
#if 0
__asm __volatile( __asm __volatile(
"movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */ "movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */
"punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */ "punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */
@ -185,7 +320,7 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
"movq %1, %%mm5\n\t" "movq %1, %%mm5\n\t"
"packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */ "packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */
"pxor %%mm6, %%mm6\n\t" "pxor %%mm6, %%mm6\n\t"
::"g"(qscale),"m"(mm_wone),"m"(mm_wabs):"memory"); ::"g"(qscale),"m"(mm_wone),"m"(mm_wabs));
for(;i<64;i+=4) { for(;i<64;i+=4) {
__asm __volatile( __asm __volatile(
"movq %1, %%mm0\n\t" "movq %1, %%mm0\n\t"
@ -195,11 +330,11 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
"pcmpgtw %%mm6, %%mm2\n\t" "pcmpgtw %%mm6, %%mm2\n\t"
"pmullw %2, %%mm1\n\t" "pmullw %2, %%mm1\n\t"
"pandn %%mm4, %%mm2\n\t" "pandn %%mm4, %%mm2\n\t"
"por %%mm5, %%mm2\n\t" "por %%mm5, %%mm2\n\t"
"pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */ "pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */
"psllw $1, %%mm0\n\t" /* block[i] <<= 1 */ "psllw $1, %%mm0\n\t" /* block[i] <<= 1 */
"paddw %%mm5, %%mm0\n\t" /* block[i] ++ */ "paddw %%mm5, %%mm0\n\t" /* block[i] ++ */
"pmullw %%mm0, %%mm1\n\t" "pmullw %%mm0, %%mm1\n\t"
"psraw $4, %%mm1\n\t" "psraw $4, %%mm1\n\t"
"pcmpeqw %%mm6, %%mm3\n\t" "pcmpeqw %%mm6, %%mm3\n\t"
@ -211,17 +346,18 @@ static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
"pand %%mm3, %%mm1\n\t" /* nullify if was zero */ "pand %%mm3, %%mm1\n\t" /* nullify if was zero */
"movq %%mm1, %0" "movq %%mm1, %0"
:"=m"(block[i]) :"=m"(block[i])
:"m"(block[i]), "m"(quant_matrix[i]) :"m"(block[i]), "m"(quant_matrix[i]));
:"memory");
} }
#endif
} }
} }
void MPV_common_init_mmx(MpegEncContext *s) void MPV_common_init_mmx(MpegEncContext *s)
{ {
if (mm_flags & MM_MMX) { if (mm_flags & MM_MMX) {
/* XXX: should include h263 optimization too. It would go even if (s->out_format == FMT_H263)
faster! */ s->dct_unquantize = dct_unquantize_h263_mmx;
s->dct_unquantize = dct_unquantize_mpeg1_mmx; else
s->dct_unquantize = dct_unquantize_mpeg1_mmx;
} }
} }