summaryrefslogtreecommitdiff
path: root/vpx_ports
diff options
context:
space:
mode:
authorjinbo <jinbo-hf@loongson.cn>2020-08-15 17:20:36 +0800
committerjinbo <jinbo-hf@loongson.cn>2020-08-19 07:57:21 +0800
commitea6562f2fcd8ea6baa946eaad69cbb5aec5dd278 (patch)
tree64e1f0ad6c30e8f303e8beb7af9d5d13d092707d /vpx_ports
parent529c29bb0f6511a9b3e25177cece0d843827458b (diff)
downloadlibvpx-ea6562f2fcd8ea6baa946eaad69cbb5aec5dd278.tar
libvpx-ea6562f2fcd8ea6baa946eaad69cbb5aec5dd278.tar.gz
libvpx-ea6562f2fcd8ea6baa946eaad69cbb5aec5dd278.tar.bz2
libvpx-ea6562f2fcd8ea6baa946eaad69cbb5aec5dd278.zip
Refine MMI & MSA detection for mips
1.Add compile check to probe the native ability of toolchain to decide whether a feature can be enabled. 2.Add runtime check to probe cpu supported features. MSA will be prefered if MSA and MMI are both supported. 3.You can configure and build as following commands: ./configure --cpu=loongson3a && make -j4 Change-Id: I057553216dbc79cfaba9c691d5f4cdab144e1123
Diffstat (limited to 'vpx_ports')
-rw-r--r--vpx_ports/mips.h27
-rw-r--r--vpx_ports/mips_cpudetect.c57
-rw-r--r--vpx_ports/vpx_ports.mk3
3 files changed, 87 insertions, 0 deletions
diff --git a/vpx_ports/mips.h b/vpx_ports/mips.h
new file mode 100644
index 000000000..bdc7525f7
--- /dev/null
+++ b/vpx_ports/mips.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_PORTS_MIPS_H_
+#define VPX_PORTS_MIPS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define HAS_MMI 0x01
+#define HAS_MSA 0x02
+
+int mips_cpu_caps(void);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // VPX_PORTS_MIPS_H_
diff --git a/vpx_ports/mips_cpudetect.c b/vpx_ports/mips_cpudetect.c
new file mode 100644
index 000000000..e0eca2d48
--- /dev/null
+++ b/vpx_ports/mips_cpudetect.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include <stdio.h>
+#include <string.h>
+#include "./vpx_config.h"
+#include "vpx_ports/mips.h"
+
+#if CONFIG_RUNTIME_CPU_DETECT
+#if defined(__mips__) && defined(__linux__)
+int mips_cpu_caps(void) {
+ char cpuinfo_line[512];
+ int flag = 0x0;
+ FILE *f = fopen("/proc/cpuinfo", "r");
+ if (!f) {
+ // Assume nothing if /proc/cpuinfo is unavailable.
+ // This will occur for Chrome sandbox for Pepper or Render process.
+ return 0;
+ }
+ while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) {
+ if (memcmp(cpuinfo_line, "cpu model", 9) == 0) {
+ // Workaround early kernel without mmi in ASEs line.
+ if (strstr(cpuinfo_line, "Loongson-3")) {
+ flag |= HAS_MMI;
+ } else if (strstr(cpuinfo_line, "Loongson-2K")) {
+ flag |= HAS_MMI | HAS_MSA;
+ }
+ }
+ if (memcmp(cpuinfo_line, "ASEs implemented", 16) == 0) {
+ if (strstr(cpuinfo_line, "loongson-mmi") &&
+ strstr(cpuinfo_line, "loongson-ext")) {
+ flag |= HAS_MMI;
+ }
+ if (strstr(cpuinfo_line, "msa")) {
+ flag |= HAS_MSA;
+ }
+ // ASEs is the last line, so we can break here.
+ break;
+ }
+ }
+ fclose(f);
+ return flag;
+}
+#else /* end __mips__ && __linux__ */
+#error \
+ "--enable-runtime-cpu-detect selected, but no CPU detection method " \
+"available for your platform. Reconfigure with --disable-runtime-cpu-detect."
+#endif
+#else /* end CONFIG_RUNTIME_CPU_DETECT */
+int mips_cpu_caps(void) { return 0; }
+#endif
diff --git a/vpx_ports/vpx_ports.mk b/vpx_ports/vpx_ports.mk
index 233177369..e5001be49 100644
--- a/vpx_ports/vpx_ports.mk
+++ b/vpx_ports/vpx_ports.mk
@@ -42,6 +42,9 @@ PORTS_SRCS-$(VPX_ARCH_ARM) += arm.h
PORTS_SRCS-$(VPX_ARCH_PPC) += ppc_cpudetect.c
PORTS_SRCS-$(VPX_ARCH_PPC) += ppc.h
+PORTS_SRCS-$(VPX_ARCH_MIPS) += mips_cpudetect.c
+PORTS_SRCS-$(VPX_ARCH_MIPS) += mips.h
+
ifeq ($(VPX_ARCH_MIPS), yes)
PORTS_SRCS-yes += asmdefs_mmi.h
endif