[FFmpeg-devel] [PATCH] avcodec: loongson3 optimized h264dsp weighted mc with mmi

周晓勇 zhouxiaoyong at loongson.cn
Wed May 13 09:18:04 CEST 2015


>From 1d06af967f8578387fc84d4eb268d31ecba1353d Mon Sep 17 00:00:00 2001
From: ZhouXiaoyong <zhouxiaoyong at loongson.cn>
Date: Wed, 13 May 2015 22:51:59 +0800
Subject: [PATCH] avcodec: loongson3 optimized h264dsp weighted mc with mmi

Signed-off-by: ZhouXiaoyong <zhouxiaoyong at loongson.cn>
---
 libavcodec/mips/Makefile            |   1 +
 libavcodec/mips/h264dsp_init_mips.c |  21 +++
 libavcodec/mips/h264dsp_mips.h      |  16 +++
 libavcodec/mips/h264dsp_mmi.c       | 278 ++++++++++++++++++++++++++++++++++++
 4 files changed, 316 insertions(+)

diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile
index eaedd7f..25813e7 100644
--- a/libavcodec/mips/Makefile
+++ b/libavcodec/mips/Makefile
@@ -22,3 +22,4 @@ OBJS-$(CONFIG_HEVC_DECODER)               += mips/hevcdsp_init_mips.o
 OBJS-$(CONFIG_H264DSP)                    += mips/h264dsp_init_mips.o
 MSA-OBJS-$(CONFIG_HEVC_DECODER)           += mips/hevcdsp_msa.o
 MSA-OBJS-$(CONFIG_H264DSP)                += mips/h264dsp_msa.o
+LOONGSON3-OBJS-$(CONFIG_H264DSP)          += mips/h264dsp_mmi.o
diff --git a/libavcodec/mips/h264dsp_init_mips.c b/libavcodec/mips/h264dsp_init_mips.c
index 8d3d760..d9182f2 100644
--- a/libavcodec/mips/h264dsp_init_mips.c
+++ b/libavcodec/mips/h264dsp_init_mips.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Parag Salasakar (Parag.Salasakar at imgtec.com)
+ * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong at loongson.cn>
  *
  * This file is part of FFmpeg.
  *
@@ -65,10 +66,30 @@ static av_cold void h264dsp_init_msa(H264DSPContext *c,
 }
 #endif  // #if HAVE_MSA
 
+#if HAVE_LOONGSON3
+static av_cold void h264dsp_init_mmi(H264DSPContext * c,
+                                     const int bit_depth,
+                                     const int chroma_format_idc)
+{
+    if (bit_depth == 8) {
+        c->weight_h264_pixels_tab[0] = ff_h264_weight_pixels16_8_mmi;
+        c->weight_h264_pixels_tab[1] = ff_h264_weight_pixels8_8_mmi;
+        c->weight_h264_pixels_tab[2] = ff_h264_weight_pixels4_8_mmi;
+
+        c->biweight_h264_pixels_tab[0] = ff_h264_biweight_pixels16_8_mmi;
+        c->biweight_h264_pixels_tab[1] = ff_h264_biweight_pixels8_8_mmi;
+        c->biweight_h264_pixels_tab[2] = ff_h264_biweight_pixels4_8_mmi;
+    }
+}
+#endif /* HAVE_LOONGSON3 */
+
 av_cold void ff_h264dsp_init_mips(H264DSPContext *c, const int bit_depth,
                                   const int chroma_format_idc)
 {
 #if HAVE_MSA
     h264dsp_init_msa(c, bit_depth, chroma_format_idc);
 #endif  // #if HAVE_MSA
+#if HAVE_LOONGSON3
+    h264dsp_init_mmi(c, bit_depth, chroma_format_idc);
+#endif /* HAVE_LOONGSON3 */
 }
diff --git a/libavcodec/mips/h264dsp_mips.h b/libavcodec/mips/h264dsp_mips.h
index df9b0b2..319f6d3 100644
--- a/libavcodec/mips/h264dsp_mips.h
+++ b/libavcodec/mips/h264dsp_mips.h
@@ -68,4 +68,20 @@ void ff_weight_h264_pixels8_8_msa(uint8_t *src, int stride, int height,
 void ff_weight_h264_pixels4_8_msa(uint8_t *src, int stride, int height,
                                   int log2_denom, int weight, int offset);
 
+void ff_h264_weight_pixels16_8_mmi(uint8_t *block, int stride, int height,
+        int log2_denom, int weight, int offset);
+void ff_h264_biweight_pixels16_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset);
+void ff_h264_weight_pixels8_8_mmi(uint8_t *block, int stride, int height,
+        int log2_denom, int weight, int offset);
+void ff_h264_biweight_pixels8_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset);
+void ff_h264_weight_pixels4_8_mmi(uint8_t *block, int stride, int height,
+        int log2_denom, int weight, int offset);
+void ff_h264_biweight_pixels4_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset);
+
 #endif  // #ifndef H264_DSP_MIPS_H
diff --git a/libavcodec/mips/h264dsp_mmi.c b/libavcodec/mips/h264dsp_mmi.c
new file mode 100644
index 0000000..5776b88
--- /dev/null
+++ b/libavcodec/mips/h264dsp_mmi.c
@@ -0,0 +1,278 @@
+/*
+ * Loongson SIMD optimized h264dsp
+ *
+ * Copyright (c) 2015 Loongson Technology Corporation Limited
+ * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong at loongson.cn>
+ *                    Zhang Shuangshuang <zhangshuangshuang at ict.ac.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 "libavcodec/bit_depth_template.c"
+#include "h264dsp_mips.h"
+
+void ff_h264_weight_pixels16_8_mmi(uint8_t *block, int stride,
+        int height, int log2_denom, int weight, int offset)
+{
+    int y;
+
+    offset <<= log2_denom;
+
+    if (log2_denom)
+        offset += 1 << (log2_denom - 1);
+
+    for (y=0; y<height; y++, block+=stride) {
+        __asm__ volatile (
+            "ldc1 $f2, %0                   \r\n"
+            "ldc1 $f4, %1                   \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "mtc1 %2, $f6                   \r\n"
+            "mtc1 %3, $f8                   \r\n"
+            "mtc1 %4, $f10                  \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "punpckhbh $f14, $f2, $f20      \r\n"
+            "punpckhbh $f16, $f4, $f20      \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "punpcklbh $f4, $f4, $f20       \r\n"
+            "pmullh $f14, $f14, $f6         \r\n"
+            "pmullh $f16, $f16, $f6         \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "pmullh $f4, $f4, $f6           \r\n"
+            "paddh $f14, $f14, $f8          \r\n"
+            "paddh $f16, $f16, $f8          \r\n"
+            "paddh $f2, $f2, $f8            \r\n"
+            "paddh $f4, $f4, $f8            \r\n"
+            "psrah $f14, $f14, $f10         \r\n"
+            "psrah $f16, $f16, $f10         \r\n"
+            "psrah $f2, $f2, $f10           \r\n"
+            "psrah $f4, $f4, $f10           \r\n"
+            "packushb $f2, $f2, $f14        \r\n"
+            "packushb $f4, $f4, $f16        \r\n"
+            "sdc1 $f2, %0                   \r\n"
+            "sdc1 $f4, %1                   \r\n"
+            : "=m"(*block),"=m"(*(block + 8))
+            : "r"(weight),"r"(offset),"r"(log2_denom)
+        );
+    }
+}
+
+void ff_h264_biweight_pixels16_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset)
+{
+    int y;
+
+    offset = ((offset + 1) | 1) << log2_denom;
+
+    for (y=0; y<height; y++, dst+=stride, src+=stride) {
+        __asm__ volatile (
+            "ldc1 $f2, %2                   \r\n"
+            "ldc1 $f4, %3                   \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "mtc1 %6, $f6                   \r\n"
+            "mtc1 %7, $f8                   \r\n"
+            "mtc1 %8, $f10                  \r\n"
+            "mtc1 %9, $f12                  \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "pshufh $f10, $f10, $f20        \r\n"
+            "punpckhbh $f14, $f2, $f20      \r\n"
+            "punpckhbh $f16, $f4, $f20      \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "punpcklbh $f4, $f4, $f20       \r\n"
+            "pmullh $f14, $f14, $f6         \r\n"
+            "pmullh $f16, $f16, $f8         \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "pmullh $f4, $f4, $f8           \r\n"
+            "paddh $f14, $f14, $f10         \r\n"
+            "paddh $f2, $f2, $f10           \r\n"
+            "paddh $f14, $f14, $f16         \r\n"
+            "paddh $f2, $f2, $f4            \r\n"
+            "psrlh $f14, $f14, $f12         \r\n"
+            "psrlh $f2, $f2, $f12           \r\n"
+            "packushb $f2, $f2, $f14        \r\n"
+            "sdc1 $f2, %0                   \r\n"
+            "ldc1 $f2, %4                   \r\n"
+            "ldc1 $f4, %5                   \r\n"
+            "punpckhbh $f14, $f2, $f20      \r\n"
+            "punpckhbh $f16, $f4, $f20      \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "punpcklbh $f4, $f4, $f20       \r\n"
+            "pmullh $f14, $f14, $f6         \r\n"
+            "pmullh $f16, $f16, $f8         \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "pmullh $f4, $f4, $f8           \r\n"
+            "paddh $f14, $f14, $f10         \r\n"
+            "paddh $f2, $f2, $f10           \r\n"
+            "paddh $f14, $f14, $f16         \r\n"
+            "paddh $f2, $f2, $f4            \r\n"
+            "psrlh $f14, $f14, $f12         \r\n"
+            "psrlh $f2, $f2, $f12           \r\n"
+            "packushb $f2, $f2, $f14        \r\n"
+            "sdc1 $f2, %1                   \r\n"
+            : "=m"(*dst),"=m"(*(dst+8))
+            : "m"(*src),"m"(*dst),"m"(*(src+8)),"m"(*(dst+8)),
+              "r"(weights),"r"(weightd),"r"(offset),"r"(log2_denom+1)
+        );
+    }
+}
+
+void ff_h264_weight_pixels8_8_mmi(uint8_t *block, int stride, int height,
+        int log2_denom, int weight, int offset)
+{
+    int y;
+
+    offset <<= log2_denom;
+
+    if (log2_denom)
+        offset += 1 << (log2_denom - 1);
+
+    for (y=0; y<height; y++, block+=stride) {
+        __asm__ volatile (
+            "ldc1 $f2, %0                   \r\n"
+            "mtc1 %1, $f6                   \r\n"
+            "mtc1 %2, $f8                   \r\n"
+            "mtc1 %3, $f10                  \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "punpckhbh $f14, $f2, $f20      \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "pmullh $f14, $f14, $f6         \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "paddh $f14, $f14, $f8          \r\n"
+            "paddh $f2, $f2, $f8            \r\n"
+            "psrah $f14, $f14, $f10         \r\n"
+            "psrah $f2, $f2, $f10           \r\n"
+            "packushb $f2, $f2, $f14        \r\n"
+            "sdc1 $f2, %0                   \r\n"
+            : "=m"(*block)
+            : "r"(weight),"r"(offset),"r"(log2_denom)
+        );
+    }
+}
+
+void ff_h264_biweight_pixels8_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset)
+{
+    int y;
+
+    offset = ((offset + 1) | 1) << log2_denom;
+
+    for (y=0; y<height; y++, dst+=stride, src+=stride) {
+        __asm__ volatile (
+            "ldc1 $f2, %1                   \r\n"
+            "ldc1 $f4, %2                   \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "mtc1 %3, $f6                   \r\n"
+            "mtc1 %4, $f8                   \r\n"
+            "mtc1 %5, $f10                  \r\n"
+            "mtc1 %6, $f12                  \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "pshufh $f10, $f10, $f20        \r\n"
+            "punpckhbh $f14, $f2, $f20      \r\n"
+            "punpckhbh $f16, $f4, $f20      \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "punpcklbh $f4, $f4, $f20       \r\n"
+            "pmullh $f14, $f14, $f6         \r\n"
+            "pmullh $f16, $f16, $f8         \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "pmullh $f4, $f4, $f8           \r\n"
+            "paddh $f14, $f14, $f10         \r\n"
+            "paddh $f2, $f2, $f10           \r\n"
+            "paddh $f14, $f14, $f16         \r\n"
+            "paddh $f2, $f2, $f4            \r\n"
+            "psrah $f14, $f14, $f12         \r\n"
+            "psrah $f2, $f2, $f12           \r\n"
+            "packushb $f2, $f2, $f14        \r\n"
+            "sdc1 $f2, %0                   \r\n"
+            : "=m"(*dst)
+            : "m"(*src),"m"(*dst),"r"(weights),
+              "r"(weightd),"r"(offset),"r"(log2_denom+1)
+        );
+    }
+}
+
+void ff_h264_weight_pixels4_8_mmi(uint8_t *block, int stride, int height,
+        int log2_denom, int weight, int offset)
+{
+    int y;
+
+    offset <<= log2_denom;
+
+    if (log2_denom)
+        offset += 1 << (log2_denom - 1);
+
+    for (y=0; y<height; y++, block+=stride) {
+        __asm__ volatile (
+            "lwc1 $f2, %0                   \r\n"
+            "mtc1 %1, $f6                   \r\n"
+            "mtc1 %2, $f8                   \r\n"
+            "mtc1 %3, $f10                  \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "paddh $f2, $f2, $f8            \r\n"
+            "psrah $f2, $f2, $f10           \r\n"
+            "packushb $f2, $f2, $f20        \r\n"
+            "swc1 $f2, %0                   \r\n"
+            : "=m"(*block)
+            : "r"(weight),"r"(offset),"r"(log2_denom)
+        );
+    }
+}
+
+void ff_h264_biweight_pixels4_8_mmi(uint8_t *dst, uint8_t *src,
+        int stride, int height, int log2_denom, int weightd, int weights,
+        int offset)
+{
+    int y;
+
+    offset = ((offset + 1) | 1) << log2_denom;
+
+    for (y=0; y<height; y++, dst+=stride, src+=stride) {
+        __asm__ volatile (
+            "lwc1 $f2, %1                   \r\n"
+            "lwc1 $f4, %2                   \r\n"
+            "dmtc1 $0, $f20                 \r\n"
+            "mtc1 %3, $f6                   \r\n"
+            "mtc1 %4, $f8                   \r\n"
+            "mtc1 %5, $f10                  \r\n"
+            "mtc1 %6, $f12                  \r\n"
+            "pshufh $f6, $f6, $f20          \r\n"
+            "pshufh $f8, $f8, $f20          \r\n"
+            "pshufh $f10, $f10, $f20        \r\n"
+            "punpcklbh $f2, $f2, $f20       \r\n"
+            "punpcklbh $f4, $f4, $f20       \r\n"
+            "pmullh $f2, $f2, $f6           \r\n"
+            "pmullh $f4, $f4, $f8           \r\n"
+            "paddh $f2, $f2, $f10           \r\n"
+            "paddh $f2, $f2, $f4            \r\n"
+            "psrah $f2, $f2, $f12           \r\n"
+            "packushb $f2, $f2, $f20        \r\n"
+            "swc1 $f2, %0                   \r\n"
+            : "=m"(*dst)
+            : "m"(*src),"m"(*dst),"r"(weights),
+              "r"(weightd),"r"(offset),"r"(log2_denom+1)
+        );
+    }
+}
--
2.1.4



More information about the ffmpeg-devel mailing list