avcodec/x86/mpegvideo: Port dct_unquantize_h263_{intra,inter}_mmx to SSSE3

It benefits from wider registers and psignw.

Benchmarks:
dct_unquantize_h263_inter_c:                            88.3 ( 1.00x)
dct_unquantize_h263_inter_mmx:                          24.7 ( 3.58x)
dct_unquantize_h263_inter_ssse3:                         9.3 ( 9.47x)
dct_unquantize_h263_intra_c:                            93.7 ( 1.00x)
dct_unquantize_h263_intra_mmx:                          30.6 ( 3.06x)
dct_unquantize_h263_intra_ssse3:                        16.5 ( 5.69x)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-11-04 07:53:09 +01:00
parent a9a23925df
commit 1cb987d25b
+62 -84
View File
@@ -30,8 +30,13 @@
#if HAVE_MMX_INLINE
static void dct_unquantize_h263_intra_mmx(const MPVContext *s,
int16_t *block, int n, int qscale)
#define SPLATW(reg) "punpcklwd %%" #reg ", %%" #reg "\n\t" \
"pshufd $0, %%" #reg ", %%" #reg "\n\t"
#if HAVE_SSSE3_INLINE
static void dct_unquantize_h263_intra_ssse3(const MPVContext *s,
int16_t *block, int n, int qscale)
{
x86_reg qmul = (unsigned)qscale << 1;
int level, qadd;
@@ -51,61 +56,45 @@ static void dct_unquantize_h263_intra_mmx(const MPVContext *s,
x86_reg offset = s->ac_pred ? 63 << 1 : s->intra_scantable.raster_end[s->block_last_index[n]] << 1;
__asm__ volatile(
"movd %k1, %%mm6 \n\t" //qmul
"lea (%2, %0), %1 \n\t"
"neg %0 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"movd %3, %%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"
".p2align 4 \n\t"
"1: \n\t"
"movq (%1, %0), %%mm0 \n\t"
"movq 8(%1, %0), %%mm1 \n\t"
"movd %k1, %%xmm0 \n\t" //qmul
"lea (%2, %0), %1 \n\t"
"neg %0 \n\t"
"movd %3, %%xmm1 \n\t" //qadd
SPLATW(xmm0)
SPLATW(xmm1)
"pmullw %%mm6, %%mm0 \n\t"
"pmullw %%mm6, %%mm1 \n\t"
".p2align 4 \n\t"
"1: \n\t"
"movdqa (%1, %0), %%xmm2 \n\t"
"movdqa 16(%1, %0), %%xmm3 \n\t"
"movq (%1, %0), %%mm2 \n\t"
"movq 8(%1, %0), %%mm3 \n\t"
"movdqa %%xmm1, %%xmm4 \n\t"
"movdqa %%xmm1, %%xmm5 \n\t"
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
"psignw %%xmm2, %%xmm4 \n\t" // sgn(block[i])*qadd
"psignw %%xmm3, %%xmm5 \n\t" // sgn(block[i])*qadd
"pxor %%mm2, %%mm0 \n\t"
"pxor %%mm3, %%mm1 \n\t"
"pmullw %%xmm0, %%xmm2 \n\t"
"pmullw %%xmm0, %%xmm3 \n\t"
"paddw %%mm7, %%mm0 \n\t"
"paddw %%mm7, %%mm1 \n\t"
"paddw %%xmm4, %%xmm2 \n\t"
"paddw %%xmm5, %%xmm3 \n\t"
"pxor %%mm0, %%mm2 \n\t"
"pxor %%mm1, %%mm3 \n\t"
"movdqa %%xmm2, (%1, %0) \n\t"
"movdqa %%xmm3, 16(%1, %0) \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, (%1, %0) \n\t"
"movq %%mm1, 8(%1, %0) \n\t"
"add $16, %0 \n\t"
"jng 1b \n\t"
"add $32, %0 \n\t"
"jng 1b \n\t"
: "+r"(offset), "+r"(qmul)
: "r" (block), "rm" (qadd)
: "memory"
: XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5",) "memory"
);
block[0]= level;
}
static void dct_unquantize_h263_inter_mmx(const MPVContext *s,
int16_t *block, int n, int qscale)
static void dct_unquantize_h263_inter_ssse3(const MPVContext *s,
int16_t *block, int n, int qscale)
{
int qmul = qscale << 1;
int qadd = (qscale - 1) | 1;
@@ -115,56 +104,41 @@ static void dct_unquantize_h263_inter_mmx(const MPVContext *s,
x86_reg offset = s->inter_scantable.raster_end[s->block_last_index[n]] << 1;
__asm__ volatile(
"movd %2, %%mm6 \n\t" //qmul
"packssdw %%mm6, %%mm6 \n\t"
"packssdw %%mm6, %%mm6 \n\t"
"movd %3, %%mm5 \n\t" //qadd
"add %1, %0 \n\t"
"neg %1 \n\t"
"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"
".p2align 4 \n\t"
"1: \n\t"
"movq (%0, %1), %%mm0 \n\t"
"movq 8(%0, %1), %%mm1 \n\t"
"movd %2, %%xmm0 \n\t" //qmul
"movd %3, %%xmm1 \n\t" //qadd
"add %1, %0 \n\t"
"neg %1 \n\t"
SPLATW(xmm0)
SPLATW(xmm1)
"pmullw %%mm6, %%mm0 \n\t"
"pmullw %%mm6, %%mm1 \n\t"
".p2align 4 \n\t"
"1: \n\t"
"movdqa (%0, %1), %%xmm2 \n\t"
"movdqa 16(%0, %1), %%xmm3 \n\t"
"movq (%0, %1), %%mm2 \n\t"
"movq 8(%0, %1), %%mm3 \n\t"
"movdqa %%xmm1, %%xmm4 \n\t"
"movdqa %%xmm1, %%xmm5 \n\t"
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
"psignw %%xmm2, %%xmm4 \n\t" // sgn(block[i])*qadd
"psignw %%xmm3, %%xmm5 \n\t" // sgn(block[i])*qadd
"pxor %%mm2, %%mm0 \n\t"
"pxor %%mm3, %%mm1 \n\t"
"pmullw %%xmm0, %%xmm2 \n\t"
"pmullw %%xmm0, %%xmm3 \n\t"
"paddw %%mm7, %%mm0 \n\t"
"paddw %%mm7, %%mm1 \n\t"
"paddw %%xmm4, %%xmm2 \n\t"
"paddw %%xmm5, %%xmm3 \n\t"
"pxor %%mm0, %%mm2 \n\t"
"pxor %%mm1, %%mm3 \n\t"
"movdqa %%xmm2, (%0, %1) \n\t"
"movdqa %%xmm3, 16(%0, %1) \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, %1) \n\t"
"movq %%mm1, 8(%0, %1) \n\t"
"add $16, %1 \n\t"
"jng 1b \n\t"
"add $32, %1 \n\t"
"jng 1b \n\t"
: "+r" (block), "+r" (offset)
: "rm"(qmul), "rm" (qadd)
: "memory"
: XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5",) "memory"
);
}
#endif
static void dct_unquantize_mpeg1_intra_mmx(const MPVContext *s,
int16_t *block, int n, int qscale)
@@ -443,13 +417,17 @@ av_cold void ff_mpv_unquantize_init_x86(MPVUnquantDSPContext *s, int bitexact)
int cpu_flags = av_get_cpu_flags();
if (INLINE_MMX(cpu_flags)) {
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_mmx;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
if (!bitexact)
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
}
#if HAVE_SSSE3_INLINE
if (INLINE_SSSE3(cpu_flags)) {
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_ssse3;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_ssse3;
}
#endif /* HAVE_SSSE3_INLINE */
#endif /* HAVE_MMX_INLINE */
}