diff options
author | Wang Chen <wangchen20@iscas.ac.cn> | 2023-07-10 09:01:07 +0800 |
---|---|---|
committer | Chen Wang <unicorn_wang@outlook.com> | 2023-07-10 11:15:18 +0800 |
commit | b8fdf4909a12c40fd373cfba0e212d45b021549f (patch) | |
tree | b65c094194aa118862a483082093ea50babdf416 | |
parent | 38a474e0892eddf549e2c9d96b5ead6e1377653d (diff) | |
download | libvpx-b8fdf4909a12c40fd373cfba0e212d45b021549f.tar libvpx-b8fdf4909a12c40fd373cfba0e212d45b021549f.tar.gz libvpx-b8fdf4909a12c40fd373cfba0e212d45b021549f.tar.bz2 libvpx-b8fdf4909a12c40fd373cfba0e212d45b021549f.zip |
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 <wangchen20@iscas.ac.cn>
Co-authored-by: sun min <sunmin89@outlook.com>
-rwxr-xr-x | build/make/rtcd.pl | 34 | ||||
-rw-r--r-- | vpx_ports/riscv.h | 26 | ||||
-rw-r--r-- | vpx_ports/riscv_cpudetect.c | 53 | ||||
-rw-r--r-- | vpx_ports/vpx_ports.mk | 3 |
4 files changed, 116 insertions, 0 deletions
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 <<EOF; +#include "vpx_config.h" + +#ifdef RTCD_C +#include "vpx_ports/riscv.h" +static void setup_rtcd_internal(void) +{ + int flags = riscv_cpu_caps(); + + (void)flags; +EOF + + set_function_pointers("c", @ALL_ARCHS); + + print <<EOF; +} +#endif +EOF + common_bottom; +} + sub unoptimized() { determine_indirection "c"; common_top; @@ -497,6 +528,9 @@ if ($opts{arch} eq 'x86') { } elsif ($opts{arch} =~ /loongarch/ ) { @ALL_ARCHS = filter(qw/lsx lasx/); loongarch; +} elsif ($opts{arch} =~ /riscv/ ) { + @ALL_ARCHS = filter(qw/rvv/); + riscv; } else { unoptimized; } diff --git a/vpx_ports/riscv.h b/vpx_ports/riscv.h new file mode 100644 index 000000000..7feb763d5 --- /dev/null +++ b/vpx_ports/riscv.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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_VPX_PORTS_RISCV_H_ +#define VPX_VPX_PORTS_RISCV_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define HAS_RVV 0x01 + +int riscv_cpu_caps(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VPX_VPX_PORTS_RISCV_H_
\ No newline at end of file diff --git a/vpx_ports/riscv_cpudetect.c b/vpx_ports/riscv_cpudetect.c new file mode 100644 index 000000000..830b18869 --- /dev/null +++ b/vpx_ports/riscv_cpudetect.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 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 <fcntl.h> +#include <unistd.h> +#include <stdint.h> + +#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 |