avcodec: loongson optimize pixblockdsp with mmi
author周晓勇 <zhouxiaoyong@loongson.cn>
Wed, 22 Jul 2015 07:10:38 +0000 (15:10 +0800)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 22 Jul 2015 10:11:31 +0000 (12:11 +0200)
Signed-off-by: ZhouXiaoyong <zhouxiaoyong@loongson.cn>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/mips/Makefile
libavcodec/mips/pixblockdsp_init_mips.c
libavcodec/mips/pixblockdsp_mips.h
libavcodec/mips/pixblockdsp_mmi.c [new file with mode: 0644]

index da91608..1c4991a 100644 (file)
@@ -68,3 +68,4 @@ MMI-OBJS-$(CONFIG_IDCTDSP)                += mips/idctdsp_mmi.o           \
                                              mips/simple_idct_mmi.o
 MMI-OBJS-$(CONFIG_MPEG4_DECODER)          += mips/xvid_idct_mmi.o
 MMI-OBJS-$(CONFIG_BLOCKDSP)               += mips/blockdsp_mmi.o
+MMI-OBJS-$(CONFIG_PIXBLOCKDSP)            += mips/pixblockdsp_mmi.o
index 0f2fb15..1b3741e 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Shivraj Patil (Shivraj.Patil@imgtec.com)
+ *                    Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
  *
  * This file is part of FFmpeg.
  *
@@ -44,10 +45,25 @@ static av_cold void pixblockdsp_init_msa(PixblockDSPContext *c,
 }
 #endif  // #if HAVE_MSA
 
+#if HAVE_MMI
+static av_cold void pixblockdsp_init_mmi(PixblockDSPContext *c,
+        AVCodecContext *avctx, unsigned high_bit_depth)
+{
+    c->diff_pixels = ff_diff_pixels_mmi;
+
+    if (!high_bit_depth || avctx->codec_type != AVMEDIA_TYPE_VIDEO) {
+        c->get_pixels = ff_get_pixels_8_mmi;
+    }
+}
+#endif /* HAVE_MMI */
+
 void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx,
                               unsigned high_bit_depth)
 {
 #if HAVE_MSA
     pixblockdsp_init_msa(c, avctx, high_bit_depth);
 #endif  // #if HAVE_MSA
+#if HAVE_MMI
+    pixblockdsp_init_mmi(c, avctx, high_bit_depth);
+#endif /* HAVE_MMI */
 }
index 3eee6e0..7f8cc96 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Shivraj Patil (Shivraj.Patil@imgtec.com)
+ *                    Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
  *
  * This file is part of FFmpeg.
  *
@@ -30,4 +31,9 @@ void ff_get_pixels_16_msa(int16_t *restrict dst, const uint8_t *src,
 void ff_get_pixels_8_msa(int16_t *restrict dst, const uint8_t *src,
                          ptrdiff_t stride);
 
+void ff_get_pixels_8_mmi(int16_t *av_restrict block, const uint8_t *pixels,
+        ptrdiff_t line_size);
+void ff_diff_pixels_mmi(int16_t *av_restrict block, const uint8_t *src1,
+        const uint8_t *src2, int stride);
+
 #endif  // #ifndef AVCODEC_MIPS_PIXBLOCKDSP_MIPS_H
diff --git a/libavcodec/mips/pixblockdsp_mmi.c b/libavcodec/mips/pixblockdsp_mmi.c
new file mode 100644 (file)
index 0000000..30631d8
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Loongson SIMD optimized pixblockdsp
+ *
+ * Copyright (c) 2015 Loongson Technology Corporation Limited
+ * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "pixblockdsp_mips.h"
+
+void ff_get_pixels_8_mmi(int16_t *av_restrict block, const uint8_t *pixels,
+        ptrdiff_t line_size)
+{
+    __asm__ volatile (
+        "move $8, $0                    \n\t"
+        "xor $f0, $f0, $f0              \n\t"
+        "1:                             \n\t"
+        "gsldlc1 $f2, 7(%1)             \n\t"
+        "gsldrc1 $f2, 0(%1)             \n\t"
+        "punpcklbh $f4, $f2, $f0        \n\t"
+        "punpckhbh $f6, $f2, $f0        \n\t"
+        "gssdxc1 $f4, 0(%0, $8)         \n\t"
+        "gssdxc1 $f6, 8(%0, $8)         \n\t"
+        "daddiu $8, $8, 16              \n\t"
+        "daddu %1, %1, %2               \n\t"
+        "daddi %3, %3, -1               \n\t"
+        "bnez %3, 1b                    \n\t"
+        ::"r"((uint8_t *)block),"r"(pixels),"r"(line_size),"r"(8)
+        : "$8","memory"
+    );
+}
+
+void ff_diff_pixels_mmi(int16_t *av_restrict block, const uint8_t *src1,
+        const uint8_t *src2, int stride)
+{
+    __asm__ volatile (
+        "dli $2, 8                     \n\t"
+        "xor $f14, $f14, $f14          \n\t"
+        "1:                            \n\t"
+        "gsldlc1 $f0, 7(%1)            \n\t"
+        "gsldrc1 $f0, 0(%1)            \n\t"
+        "or $f2, $f0, $f0              \n\t"
+        "gsldlc1 $f4, 7(%2)            \n\t"
+        "gsldrc1 $f4, 0(%2)            \n\t"
+        "or $f6, $f4, $f4              \n\t"
+        "punpcklbh $f0, $f0, $f14      \n\t"
+        "punpckhbh $f2, $f2, $f14      \n\t"
+        "punpcklbh $f4, $f4, $f14      \n\t"
+        "punpckhbh $f6, $f6, $f14      \n\t"
+        "psubh $f0, $f0, $f4           \n\t"
+        "psubh $f2, $f2, $f6           \n\t"
+        "gssdlc1 $f0, 7(%0)            \n\t"
+        "gssdrc1 $f0, 0(%0)            \n\t"
+        "gssdlc1 $f2, 15(%0)           \n\t"
+        "gssdrc1 $f2, 8(%0)            \n\t"
+        "daddi %0, %0, 16              \n\t"
+        "daddu %1, %1, %3              \n\t"
+        "daddu %2, %2, %3              \n\t"
+        "daddi $2, $2, -1              \n\t"
+        "bgtz $2, 1b                   \n\t"
+        ::"r"(block),"r"(src1),"r"(src2),"r"(stride)
+        : "$2","memory"
+    );
+}