From b8fdf4909a12c40fd373cfba0e212d45b021549f Mon Sep 17 00:00:00 2001 From: Wang Chen Date: Mon, 10 Jul 2023 09:01:07 +0800 Subject: support framework for RunTime Cpu Detection Just add related code about RTCD to setup the framework. Have not support the actual runtime detection, and I have not understood how RTCD works, FIXME. More analysis please refer to https://github.com/aosp-riscv/libvpx/issues/8#issuecomment-1627896402. Signed-off-by: Wang Chen Co-authored-by: sun min --- build/make/rtcd.pl | 34 +++++++++++++++++++++++++++++ vpx_ports/riscv.h | 26 ++++++++++++++++++++++ vpx_ports/riscv_cpudetect.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ vpx_ports/vpx_ports.mk | 3 +++ 4 files changed, 116 insertions(+) create mode 100644 vpx_ports/riscv.h create mode 100644 vpx_ports/riscv_cpudetect.c diff --git a/build/make/rtcd.pl b/build/make/rtcd.pl index f4edeaad5..b7555ad7c 100755 --- a/build/make/rtcd.pl +++ b/build/make/rtcd.pl @@ -418,6 +418,37 @@ EOF common_bottom; } +sub riscv() { + 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 < +#include +#include + +#include "./vpx_config.h" +#include "vpx_ports/riscv.h" + +#if CONFIG_RUNTIME_CPU_DETECT +static int cpu_env_flags(int *flags) { + char *env; + env = getenv("VPX_SIMD_CAPS"); + if (env && *env) { + *flags = (int)strtol(env, NULL, 0); + return 0; + } + *flags = 0; + return -1; +} + +static int cpu_env_mask(void) { + char *env; + env = getenv("VPX_SIMD_CAPS_MASK"); + return env && *env ? (int)strtol(env, NULL, 0) : ~0; +} + +int riscv_cpu_caps(void) { + int flags = HAS_RVV; + int mask; + + // If VPX_SIMD_CAPS is set then allow only those capabilities. + if (!cpu_env_flags(&flags)) { + return flags; + } + + mask = cpu_env_mask(); + + return flags & mask; +} +#else +// If there is no RTCD the function pointers are not used and can not be +// changed. +int riscv_cpu_caps(void) { return 0; } +#endif // CONFIG_RUNTIME_CPU_DETECT diff --git a/vpx_ports/vpx_ports.mk b/vpx_ports/vpx_ports.mk index e30e87cef..8c57ab4ce 100644 --- a/vpx_ports/vpx_ports.mk +++ b/vpx_ports/vpx_ports.mk @@ -48,6 +48,9 @@ PORTS_SRCS-$(VPX_ARCH_MIPS) += mips.h PORTS_SRCS-$(VPX_ARCH_LOONGARCH) += loongarch_cpudetect.c PORTS_SRCS-$(VPX_ARCH_LOONGARCH) += loongarch.h +PORTS_SRCS-$(VPX_ARCH_RISCV64) += riscv_cpudetect.c +PORTS_SRCS-$(VPX_ARCH_RISCV64) += riscv.h + ifeq ($(VPX_ARCH_MIPS), yes) PORTS_SRCS-yes += asmdefs_mmi.h endif -- cgit v1.2.3