[FFmpeg-cvslog] avcodec: loongson optimize mpeg2 dct unquantize intra and denoise dct

周晓勇 git at videolan.org
Wed Sep 2 16:58:03 CEST 2015


ffmpeg | branch: master | 周晓勇 <zhouxiaoyong at loongson.cn> | Wed Sep  2 18:01:00 2015 +0800| [95010d49a2daf782cba7a261bde5c979cfd51c67] | committer: Michael Niedermayer

avcodec: loongson optimize mpeg2 dct unquantize intra and denoise dct

Change-Id: I2f391ae912a079fb32f0703841dca86358aac72a
Signed-off-by: ZhouXiaoyong <zhouxiaoyong at loongson.cn>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=95010d49a2daf782cba7a261bde5c979cfd51c67
---

 libavcodec/mips/mpegvideo_init_mips.c |    5 ++
 libavcodec/mips/mpegvideo_mips.h      |    3 +
 libavcodec/mips/mpegvideo_mmi.c       |  140 +++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)

diff --git a/libavcodec/mips/mpegvideo_init_mips.c b/libavcodec/mips/mpegvideo_init_mips.c
index 85a833c..e83aec5 100644
--- a/libavcodec/mips/mpegvideo_init_mips.c
+++ b/libavcodec/mips/mpegvideo_init_mips.c
@@ -37,6 +37,11 @@ static av_cold void dct_unquantize_init_mmi(MpegEncContext *s)
     s->dct_unquantize_h263_inter = ff_dct_unquantize_h263_inter_mmi;
     s->dct_unquantize_mpeg1_intra = ff_dct_unquantize_mpeg1_intra_mmi;
     s->dct_unquantize_mpeg1_inter = ff_dct_unquantize_mpeg1_inter_mmi;
+
+    if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT))
+      s->dct_unquantize_mpeg2_intra = ff_dct_unquantize_mpeg2_intra_mmi;
+
+    s->denoise_dct= ff_denoise_dct_mmi;
 }
 #endif /* HAVE_MMI */
 
diff --git a/libavcodec/mips/mpegvideo_mips.h b/libavcodec/mips/mpegvideo_mips.h
index dbcea6a..decacd4c 100644
--- a/libavcodec/mips/mpegvideo_mips.h
+++ b/libavcodec/mips/mpegvideo_mips.h
@@ -31,5 +31,8 @@ void ff_dct_unquantize_mpeg1_intra_mmi(MpegEncContext *s, int16_t *block,
         int n, int qscale);
 void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block,
         int n, int qscale);
+void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block,
+        int n, int qscale);
+void ff_denoise_dct_mmi(MpegEncContext *s, int16_t *block);
 
 #endif /* MPEGVIDEO_MIPS_H */
diff --git a/libavcodec/mips/mpegvideo_mmi.c b/libavcodec/mips/mpegvideo_mmi.c
index c8b1e16..94781e6 100644
--- a/libavcodec/mips/mpegvideo_mmi.c
+++ b/libavcodec/mips/mpegvideo_mmi.c
@@ -301,3 +301,143 @@ void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block,
         :"$8","$10","memory"
     );
 }
+
+void ff_denoise_dct_mmi(MpegEncContext *s, int16_t *block)
+{
+    const int intra = s->mb_intra;
+    int *sum = s->dct_error_sum[intra];
+    uint16_t *offset = s->dct_offset[intra];
+
+    s->dct_count[intra]++;
+
+    __asm__ volatile(
+        "xor $f14, $f14, $f14               \r\n"
+        "1:                                 \r\n"
+        "ldc1 $f4, 0(%[block])              \r\n"
+        "xor $f0, $f0, $f0                  \r\n"
+        "ldc1 $f6, 8(%[block])              \r\n"
+        "xor $f2, $f2, $f2                  \r\n"
+        "pcmpgth $f0, $f0, $f4              \r\n"
+        "pcmpgth $f2, $f2, $f6              \r\n"
+        "xor $f4, $f4, $f0                  \r\n"
+        "xor $f6, $f6, $f2                  \r\n"
+        "psubh $f4, $f4, $f0                \r\n"
+        "psubh $f6, $f6, $f2                \r\n"
+        "ldc1 $f12, 0(%[offset])            \r\n"
+        "mov.d $f8, $f4                     \r\n"
+        "psubush $f4, $f4, $f12             \r\n"
+        "ldc1 $f12, 8(%[offset])            \r\n"
+        "mov.d $f10, $f6                    \r\n"
+        "psubush $f6, $f6, $f12             \r\n"
+        "xor $f4, $f4, $f0                  \r\n"
+        "xor $f6, $f6, $f2                  \r\n"
+        "psubh $f4, $f4, $f0                \r\n"
+        "psubh $f6, $f6, $f2                \r\n"
+        "sdc1 $f4, 0(%[block])              \r\n"
+        "sdc1 $f6, 8(%[block])              \r\n"
+        "mov.d $f4, $f8                     \r\n"
+        "mov.d $f6, $f10                    \r\n"
+        "punpcklhw $f8, $f8, $f14           \r\n"
+        "punpckhhw $f4, $f4, $f14           \r\n"
+        "punpcklhw $f10, $f10, $f14         \r\n"
+        "punpckhhw $f6, $f6, $f14           \r\n"
+        "ldc1 $f0, 0(%[sum])                \r\n"
+        "paddw $f8, $f8, $f0                \r\n"
+        "ldc1 $f0, 8(%[sum])                \r\n"
+        "paddw $f4, $f4, $f0                \r\n"
+        "ldc1 $f0, 16(%[sum])               \r\n"
+        "paddw $f10, $f10, $f0              \r\n"
+        "ldc1 $f0, 24(%[sum])               \r\n"
+        "paddw $f6, $f6, $f0                \r\n"
+        "sdc1 $f8, 0(%[sum])                \r\n"
+        "sdc1 $f4, 8(%[sum])                \r\n"
+        "sdc1 $f10, 16(%[sum])              \r\n"
+        "sdc1 $f6, 24(%[sum])               \r\n"
+        "daddiu %[block], %[block], 16      \r\n"
+        "daddiu %[sum], %[sum], 32          \r\n"
+        "daddiu %[offset], %[offset], 16    \r\n"
+        "dsubu $8, %[block1], %[block]      \r\n"
+        "bgtz $8, 1b                        \r\n"
+        : [block]"+r"(block),[sum]"+r"(sum),[offset]"+r"(offset)
+        : [block1]"r"(block+64)
+        : "$8","$f0","$f2","$f4","$f6","$f8","$f10","$f12","$f14"
+    );
+}
+
+void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block,
+        int n, int qscale)
+{
+    uint64_t nCoeffs;
+    const uint16_t *quant_matrix;
+    int block0;
+
+    assert(s->block_last_index[n]>=0);
+
+    if (s->alternate_scan)
+        nCoeffs = 63;
+    else
+        nCoeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
+
+    if (n < 4)
+        block0 = block[0] * s->y_dc_scale;
+    else
+        block0 = block[0] * s->c_dc_scale;
+
+    quant_matrix = s->intra_matrix;
+
+    __asm__ volatile (
+        "pcmpeqh $f14, $f14, $f14           \r\n"
+        "dli $10, 15                        \r\n"
+        "dmtc1 $10, $f16                    \r\n"
+        "xor $f12, $f12, $f12               \r\n"
+        "lwc1 $f12, %[qscale]               \r\n"
+        "psrlh $f14, $f14, $f16             \r\n"
+        "packsswh $f12, $f12, $f12          \r\n"
+        "packsswh $f12, $f12, $f12          \r\n"
+        "or $8, %[ncoeffs], $0              \r\n"
+        ".p2align 4                         \r\n"
+        "1:                                 \r\n"
+        "gsldxc1 $f0, 0($8, %[block])       \r\n"
+        "gsldxc1 $f2, 8($8, %[block])       \r\n"
+        "mov.d $f16, $f0                    \r\n"
+        "mov.d $f18, $f2                    \r\n"
+        "gsldxc1 $f8, 0($8, %[quant])       \r\n"
+        "gsldxc1 $f10, 0($8, %[quant])      \r\n"
+        "pmullh $f8, $f8, $f12              \r\n"
+        "pmullh $f10, $f10, $f12            \r\n"
+        "xor $f4, $f4, $f4                  \r\n"
+        "xor $f6, $f6, $f6                  \r\n"
+        "pcmpgth $f4, $f4, $f0              \r\n"
+        "pcmpgth $f6, $f6, $f2              \r\n"
+        "xor $f0, $f0, $f4                  \r\n"
+        "xor $f2, $f2, $f6                  \r\n"
+        "psubh $f0, $f0, $f4                \r\n"
+        "psubh $f2, $f2, $f6                \r\n"
+        "pmullh $f0, $f0, $f8               \r\n"
+        "pmullh $f2, $f2, $f10              \r\n"
+        "xor $f8, $f8, $f8                  \r\n"
+        "xor $f10, $f10, $f10               \r\n"
+        "pcmpeqh $f8, $f8, $f16             \r\n"
+        "pcmpeqh $f10 ,$f10, $f18           \r\n"
+        "dli $10, 3                         \r\n"
+        "dmtc1 $10, $f16                    \r\n"
+        "psrah $f0, $f0, $f16               \r\n"
+        "psrah $f2, $f2, $f16               \r\n"
+        "xor $f0, $f0, $f4                  \r\n"
+        "xor $f2, $f2, $f6                  \r\n"
+        "psubh $f0, $f0, $f4                \r\n"
+        "psubh $f2, $f2, $f6                \r\n"
+        "pandn $f8, $f8, $f0                \r\n"
+        "pandn $f10, $f10, $f2              \r\n"
+        "gssdxc1 $f8, 0($8, %[block])       \r\n"
+        "gssdxc1 $f10, 8($8, %[block])      \r\n"
+        "daddiu $8, $8, 16                  \r\n"
+        "blez $8, 1b                        \r\n"
+        ::[block]"r"(block+nCoeffs),[quant]"r"(quant_matrix+nCoeffs),
+          [qscale]"m"(qscale),[ncoeffs]"g"(-2*nCoeffs)
+        : "$8","$10","$f0","$f2","$f4","$f6","$f8","$f10","$f12","$f14","$f16",
+          "$f18"
+    );
+
+    block[0]= block0;
+}



More information about the ffmpeg-cvslog mailing list