summaryrefslogtreecommitdiff
path: root/vpx_ports
diff options
context:
space:
mode:
authorJin Bo <jinbo@loongson.cn>2021-07-06 17:18:48 +0800
committeryuanhecai <yuanhecai@loongson.cn>2022-01-28 16:05:51 +0800
commit479758aeb15c82c8faf6d7a905999c7512284c64 (patch)
tree4a4de00d15e4eee635acf7cb3ce14bd48e02128b /vpx_ports
parentf7941622f22215f332e82362e8318ae304e471cf (diff)
downloadlibvpx-479758aeb15c82c8faf6d7a905999c7512284c64.tar
libvpx-479758aeb15c82c8faf6d7a905999c7512284c64.tar.gz
libvpx-479758aeb15c82c8faf6d7a905999c7512284c64.tar.bz2
libvpx-479758aeb15c82c8faf6d7a905999c7512284c64.zip
libvpx[loongarch]: Add loongarch support.
LSX and LASX are enabled by default if compiler supports them. Bug: webm:1754 Change-Id: Ic36b113bc4313c50e9d2bbab91199b3aa46d00dc
Diffstat (limited to 'vpx_ports')
-rw-r--r--vpx_ports/loongarch.h29
-rw-r--r--vpx_ports/loongarch_cpudetect.c40
-rw-r--r--vpx_ports/vpx_ports.mk3
3 files changed, 72 insertions, 0 deletions
diff --git a/vpx_ports/loongarch.h b/vpx_ports/loongarch.h
new file mode 100644
index 000000000..d93ff9f5f
--- /dev/null
+++ b/vpx_ports/loongarch.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ * Contributed by Jin Bo <jinbo@loongson.cn>
+ * Contributed by Lu Wang <wanglu@loongson.cn>
+ *
+ * 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_VPX_PORTS_LOONGARCH_H_
+#define VPX_VPX_PORTS_LOONGARCH_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define HAS_LSX 0x01
+#define HAS_LASX 0x02
+
+int loongarch_cpu_caps(void);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // VPX_VPX_PORTS_LOONGARCH_H_
diff --git a/vpx_ports/loongarch_cpudetect.c b/vpx_ports/loongarch_cpudetect.c
new file mode 100644
index 000000000..7b4322d35
--- /dev/null
+++ b/vpx_ports/loongarch_cpudetect.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ * Contributed by Jin Bo <jinbo@loongson.cn>
+ * Contributed by Lu Wang <wanglu@loongson.cn>
+ *
+ * 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 "./vpx_config.h"
+#include "vpx_ports/loongarch.h"
+
+#define LOONGARCH_CFG2 0x02
+#define LOONGARCH_CFG2_LSX (1 << 6)
+#define LOONGARCH_CFG2_LASX (1 << 7)
+
+#if CONFIG_RUNTIME_CPU_DETECT
+#if defined(__loongarch__) && defined(__linux__)
+int loongarch_cpu_caps(void) {
+ int reg = 0;
+ int flag = 0;
+
+ __asm__ volatile("cpucfg %0, %1 \n\t" : "+&r"(reg) : "r"(LOONGARCH_CFG2));
+ if (reg & LOONGARCH_CFG2_LSX) flag |= HAS_LSX;
+
+ if (reg & LOONGARCH_CFG2_LASX) flag |= HAS_LASX;
+
+ return flag;
+}
+#else /* end __loongarch__ && __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 loongarch_cpu_caps(void) { return 0; }
+#endif
diff --git a/vpx_ports/vpx_ports.mk b/vpx_ports/vpx_ports.mk
index e5001be49..e30e87cef 100644
--- a/vpx_ports/vpx_ports.mk
+++ b/vpx_ports/vpx_ports.mk
@@ -45,6 +45,9 @@ PORTS_SRCS-$(VPX_ARCH_PPC) += ppc.h
PORTS_SRCS-$(VPX_ARCH_MIPS) += mips_cpudetect.c
PORTS_SRCS-$(VPX_ARCH_MIPS) += mips.h
+PORTS_SRCS-$(VPX_ARCH_LOONGARCH) += loongarch_cpudetect.c
+PORTS_SRCS-$(VPX_ARCH_LOONGARCH) += loongarch.h
+
ifeq ($(VPX_ARCH_MIPS), yes)
PORTS_SRCS-yes += asmdefs_mmi.h
endif