summaryrefslogtreecommitdiff
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
parentf7941622f22215f332e82362e8318ae304e471cf (diff)
downloadlibvpx-479758aeb15c82c8faf6d7a905999c7512284c64.tar.gz
libvpx[loongarch]: Add loongarch support.
LSX and LASX are enabled by default if compiler supports them. Bug: webm:1754 Change-Id: Ic36b113bc4313c50e9d2bbab91199b3aa46d00dc
-rw-r--r--build/make/Makefile6
-rw-r--r--build/make/configure.sh47
-rwxr-xr-xbuild/make/rtcd.pl47
-rwxr-xr-xconfigure5
-rw-r--r--vp8/common/generic/systemdependent.c4
-rw-r--r--vpx_ports/loongarch.h29
-rw-r--r--vpx_ports/loongarch_cpudetect.c40
-rw-r--r--vpx_ports/vpx_ports.mk3
8 files changed, 181 insertions, 0 deletions
diff --git a/build/make/Makefile b/build/make/Makefile
index 9ca97c8c6..b7a873cc8 100644
--- a/build/make/Makefile
+++ b/build/make/Makefile
@@ -151,6 +151,12 @@ $(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx
$(BUILD_PFX)%_msa.c.d: CFLAGS += -mmsa
$(BUILD_PFX)%_msa.c.o: CFLAGS += -mmsa
+# LOONGARCH
+$(BUILD_PFX)%_lsx.c.d: CFLAGS += -mlsx
+$(BUILD_PFX)%_lsx.c.o: CFLAGS += -mlsx
+$(BUILD_PFX)%_lasx.c.d: CFLAGS += -mlasx
+$(BUILD_PFX)%_lasx.c.o: CFLAGS += -mlasx
+
$(BUILD_PFX)%.c.d: %.c
$(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@)
diff --git a/build/make/configure.sh b/build/make/configure.sh
index b24e79a0d..581042e38 100644
--- a/build/make/configure.sh
+++ b/build/make/configure.sh
@@ -449,6 +449,17 @@ EOF
fi
}
+check_inline_asm() {
+ log check_inline_asm "$@"
+ name="$1"
+ code="$2"
+ shift 2
+ disable_feature $name
+ check_cc "$@" <<EOF && enable_feature $name
+void foo(void) { __asm__ volatile($code); }
+EOF
+}
+
write_common_config_banner() {
print_webm_license config.mk "##" ""
echo '# This file automatically generated by configure. Do not edit!' >> config.mk
@@ -766,6 +777,12 @@ process_common_toolchain() {
*mips32el*)
tgt_isa=mips32
;;
+ loongarch32*)
+ tgt_isa=loongarch32
+ ;;
+ loongarch64*)
+ tgt_isa=loongarch64
+ ;;
esac
# detect tgt_os
@@ -834,6 +851,11 @@ process_common_toolchain() {
ppc*)
enable_feature ppc
;;
+ loongarch*)
+ soft_enable lsx
+ soft_enable lasx
+ enable_feature loongarch
+ ;;
esac
# PIC is probably what we want when building shared libs
@@ -1419,6 +1441,15 @@ EOF
;;
esac
;;
+ loongarch*)
+ link_with_cc=gcc
+ setup_gnu_toolchain
+
+ enabled lsx && check_inline_asm lsx '"vadd.b $vr0, $vr1, $vr1"'
+ enabled lsx && soft_enable runtime_cpu_detect
+ enabled lasx && check_inline_asm lasx '"xvadd.b $xr0, $xr1, $xr1"'
+ enabled lasx && soft_enable runtime_cpu_detect
+ ;;
*-gcc|generic-gnu)
link_with_cc=gcc
enable_feature gcc
@@ -1521,6 +1552,22 @@ EOF
;;
esac
+ # only for LOONGARCH platforms
+ case ${toolchain} in
+ loongarch*)
+ if enabled big_endian; then
+ if enabled lsx; then
+ echo "lsx optimizations are available only for little endian platforms"
+ disable_feature lsx
+ fi
+ if enabled lasx; then
+ echo "lasx optimizations are available only for little endian platforms"
+ disable_feature lasx
+ fi
+ fi
+ ;;
+ esac
+
# glibc needs these
if enabled linux; then
add_cflags -D_LARGEFILE_SOURCE
diff --git a/build/make/rtcd.pl b/build/make/rtcd.pl
index acb9f6e46..8ed776add 100755
--- a/build/make/rtcd.pl
+++ b/build/make/rtcd.pl
@@ -387,6 +387,37 @@ EOF
common_bottom;
}
+sub loongarch() {
+ determine_indirection("c", @ALL_ARCHS);
+
+ # Assign the helper variable for each enabled extension
+ foreach my $opt (@ALL_ARCHS) {
+ my $opt_uc = uc $opt;
+ eval "\$have_${opt}=\"flags & HAS_${opt_uc}\"";
+ }
+
+ common_top;
+ print <<EOF;
+#include "vpx_config.h"
+
+#ifdef RTCD_C
+#include "vpx_ports/loongarch.h"
+static void setup_rtcd_internal(void)
+{
+ int flags = loongarch_cpu_caps();
+
+ (void)flags;
+EOF
+
+ set_function_pointers("c", @ALL_ARCHS);
+
+ print <<EOF;
+}
+#endif
+EOF
+ common_bottom;
+}
+
sub unoptimized() {
determine_indirection "c";
common_top;
@@ -462,6 +493,22 @@ if ($opts{arch} eq 'x86') {
} elsif ($opts{arch} =~ /^ppc/ ) {
@ALL_ARCHS = filter(qw/vsx/);
ppc;
+} elsif ($opts{arch} =~ /loongarch/ ) {
+ @ALL_ARCHS = filter("$opts{arch}");
+ open CONFIG_FILE, $opts{config} or
+ die "Error opening config file '$opts{config}': $!\n";
+ while (<CONFIG_FILE>) {
+ if (/HAVE_LSX=yes/) {
+ @ALL_ARCHS = filter("$opts{arch}", qw/lsx/);
+ last;
+ }
+ if (/HAVE_LASX=yes/) {
+ @ALL_ARCHS = filter("$opts{arch}", qw/lasx/);
+ last;
+ }
+ }
+ close CONFIG_FILE;
+ loongarch;
} else {
unoptimized;
}
diff --git a/configure b/configure
index b68f9fd78..434ebbe36 100755
--- a/configure
+++ b/configure
@@ -114,6 +114,8 @@ all_platforms="${all_platforms} armv7-win32-vs14"
all_platforms="${all_platforms} armv7-win32-vs15"
all_platforms="${all_platforms} armv7s-darwin-gcc"
all_platforms="${all_platforms} armv8-linux-gcc"
+all_platforms="${all_platforms} loongarch32-linux-gcc"
+all_platforms="${all_platforms} loongarch64-linux-gcc"
all_platforms="${all_platforms} mips32-linux-gcc"
all_platforms="${all_platforms} mips64-linux-gcc"
all_platforms="${all_platforms} ppc64le-linux-gcc"
@@ -237,6 +239,7 @@ ARCH_LIST="
x86
x86_64
ppc
+ loongarch
"
ARCH_EXT_LIST_X86="
mmx
@@ -252,6 +255,8 @@ ARCH_EXT_LIST_X86="
ARCH_EXT_LIST_LOONGSON="
mmi
+ lsx
+ lasx
"
ARCH_EXT_LIST="
diff --git a/vp8/common/generic/systemdependent.c b/vp8/common/generic/systemdependent.c
index cd1b02c9c..71529bdfd 100644
--- a/vp8/common/generic/systemdependent.c
+++ b/vp8/common/generic/systemdependent.c
@@ -18,6 +18,8 @@
#include "vpx_ports/ppc.h"
#elif VPX_ARCH_MIPS
#include "vpx_ports/mips.h"
+#elif VPX_ARCH_LOONGARCH
+#include "vpx_ports/loongarch.h"
#endif
#include "vp8/common/onyxc_int.h"
#include "vp8/common/systemdependent.h"
@@ -100,6 +102,8 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) {
ctx->cpu_caps = ppc_simd_caps();
#elif VPX_ARCH_MIPS
ctx->cpu_caps = mips_cpu_caps();
+#elif VPX_ARCH_LOONGARCH
+ ctx->cpu_caps = loongarch_cpu_caps();
#else
// generic-gnu targets.
ctx->cpu_caps = 0;
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