[FFmpeg-devel] [PATCH v4 3/4] libavutil: Detect MMI and MSA flags for MIPS

Shiyou Yin yinshiyou-hf at loongson.cn
Tue Jun 9 14:43:12 EEST 2020


>-----Original Message-----
>From: ffmpeg-devel-bounces at ffmpeg.org [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf Of
>Jiaxun Yang
>Sent: Monday, June 8, 2020 11:32 AM
>To: ffmpeg-devel at ffmpeg.org
>Cc: yinshiyou at loongson.cn; Jiaxun Yang
>Subject: [FFmpeg-devel] [PATCH v4 3/4] libavutil: Detect MMI and MSA flags for MIPS
>
>Add MMI & MSA runtime detection for MIPS.
>
>Basically there are two code pathes. For systems that
>natively support CPUCFG instruction or kernel emulated
>that instruction, we'll sense this feature from HWCAP and
>report the flags according to values grab from CPUCFG. For
>systems that have no CPUCFG (or not export it in HWCAP),
>we'll parse /proc/cpuinfo instead.
>
>Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
>---
>v2: Implement CPUCFG code path as CPUCFG emulation and HWCAP
>	have accepted by Linux Kernel upstream.
>---
> libavutil/cpu.c           |  10 +++
> libavutil/cpu.h           |   3 +
> libavutil/cpu_internal.h  |   2 +
> libavutil/mips/Makefile   |   2 +-
> libavutil/mips/cpu.c      | 134 ++++++++++++++++++++++++++++++++++++++
> libavutil/mips/cpu.h      |  28 ++++++++
> libavutil/tests/cpu.c     |   3 +
> tests/checkasm/checkasm.c |   3 +
> 8 files changed, 184 insertions(+), 1 deletion(-)
> create mode 100644 libavutil/mips/cpu.c
> create mode 100644 libavutil/mips/cpu.h
>
>diff --git a/libavutil/mips/cpu.c b/libavutil/mips/cpu.c
>new file mode 100644
>index 0000000000..e9e291a45a
>--- /dev/null
>+++ b/libavutil/mips/cpu.c
>@@ -0,0 +1,134 @@
>+/*
>+ * 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 "libavutil/cpu.h"
>+#include "libavutil/cpu_internal.h"
>+#include "config.h"
>+#if defined __linux__ || defined __ANDROID__
>+#include <stdint.h>
>+#include <stdio.h>
>+#include <string.h>
>+#include <sys/auxv.h>
>+#include "asmdefs.h"
>+#include "libavutil/avstring.h"
>+#endif
>+
>+#if defined __linux__ || defined __ANDROID__
>+
>+#define HWCAP_LOONGSON_CPUCFG (1 << 14)
>+
>+static int cpucfg_available(void)
>+{
>+    return getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG;
>+}
>+
>+/* Most toolchains have no CPUCFG support yet */
>+static uint32_t read_cpucfg(uint32_t reg)
>+{
>+	uint32_t __res;
>+
>+	__asm__ __volatile__(
>+		"parse_r __res,%0\n\t"
>+		"parse_r reg,%1\n\t"
>+		".insn \n\t"
>+		".word (0xc8080118 | (reg << 21) | (__res << 11))\n\t"
>+		:"=r"(__res)
>+		:"r"(reg)
>+		:
>+		);
>+	return __res;
>+}
>+
>+#define LOONGSON_CFG1 0x1
>+
>+#define LOONGSON_CFG1_MMI	(1 << 4)
>+#define LOONGSON_CFG1_MSA1	(1 << 5)
>+
>+static int cpu_flags_cpucfg(void)
>+{
>+    int flags = 0;
>+    uint32_t cfg1 = read_cpucfg(LOONGSON_CFG1);
>+
>+    if (cfg1 & LOONGSON_CFG1_MMI)
>+        flags |= AV_CPU_FLAG_MMI;
>+
>+    if (cfg1 & LOONGSON_CFG1_MMI)
>+        flags |= AV_CPU_FLAG_MSA;

Should be LOONGSON_CFG1_MSA1.

>+
>+    return flags;
>+}
>+



More information about the ffmpeg-devel mailing list