aboutsummaryrefslogtreecommitdiffstats
path: root/libavdevice
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi@remlab.net>2024-06-08 10:57:15 +0300
committerRémi Denis-Courmont <remi@remlab.net>2024-06-11 20:12:37 +0300
commit378d1b06c350e09ac604566130b39126fd858478 (patch)
tree979428e0a8b12b6ef16fae5dfe205618f16ca731 /libavdevice
parent18adaf9fe558587cb1b707c647af83015b69da48 (diff)
downloadffmpeg-378d1b06c350e09ac604566130b39126fd858478.tar.gz
riscv: probe for Zbb extension at load time
Due to hysterical raisins, most RISC-V Linux distributions target a RV64GC baseline excluding the Bit-manipulation ISA extensions, most notably: - Zba: address generation extension and - Zbb: basic bit manipulation extension. Most CPUs that would make sense to run FFmpeg on support Zba and Zbb (including the current FATE runner), so it makes sense to optimise for them. In fact a large chunk of existing assembler optimisations relies on Zba and/or Zbb. Since we cannot patch shared library code, the next best thing is to carry a flag initialised at load-time and check it on need basis. This results in 3 instructions overhead on isolated use, e.g.: 1: AUIPC rd, %pcrel_hi(ff_rv_zbb_supported) LBU rd, %pcrel_lo(1b)(rd) BEQZ rd, non_Zbb_fallback_code // Zbb code here The C compiler will typically load the flag ahead of time to reducing latency, and can also keep it around if Zbb is used multiple times in a single optimisation scope. For this to work, the flag symbol must be hidden; otherwise the optimisation degrades with a GOT look-up to support interposition: 1: AUIPC rd, GOT_OFFSET_HI LD rd, GOT_OFFSET_LO(rd) LBU rd, (rd) BEQZ rd, non_Zbb_fallback_code // Zbb code here This patch adds code to provision the flag in libraries using bit manipulation functions from libavutil: byte-swap, bit-weight and counting leading or trailing zeroes.
Diffstat (limited to 'libavdevice')
-rw-r--r--libavdevice/riscv/Makefile1
-rw-r--r--libavdevice/riscv/cpu_common.c1
2 files changed, 2 insertions, 0 deletions
diff --git a/libavdevice/riscv/Makefile b/libavdevice/riscv/Makefile
new file mode 100644
index 0000000000..52857aacba
--- /dev/null
+++ b/libavdevice/riscv/Makefile
@@ -0,0 +1 @@
+SHLIBOBJS += riscv/cpu_common.o
diff --git a/libavdevice/riscv/cpu_common.c b/libavdevice/riscv/cpu_common.c
new file mode 100644
index 0000000000..17c9b392c9
--- /dev/null
+++ b/libavdevice/riscv/cpu_common.c
@@ -0,0 +1 @@
+#include "libavutil/riscv/cpu_common.c"