PR #26141 opened by Rodrigo Manuel Pita Camacho (R-Camacho)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26141
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26141.patch

```
checkasm:
 - CPU: SpacemiT, vendor arch 0x58000001, imp 0x1000000049772200
 - CPU: VLEN = 256 bits
 - Timing source: gettime
 - Bench duration: 1000 µs per function (1000000 nsecs)
 - Random seed: 570057552
RV_zve32x:
 - vf_limiter.limiter8  [OK]
 - vf_limiter.limiter16 [OK]
checkasm: all 2 tests passed
Benchmark results:
  name                  nsecs (vs ref)
  limiter8_c:         13683.9
  limiter8_rvv_i32:     534.0 (25.62x)
  limiter16_c:         7072.1
  limiter16_rvv_i32:    523.5 (13.50x)

Signed-off-by: Rodrigo Camacho <[email protected]>
```



From 1cfc5961d80ba21f09f16a3d3f2c4d30f07cb123 Mon Sep 17 00:00:00 2001
From: Rodrigo Camacho <[email protected]>
Date: Tue, 17 Nov 2026 20:11:28 +0000
Subject: [PATCH] =?UTF-8?q?avfilter/vf=5Flimiter:=20R-V=20V=20vf=5Flimiter?=
 =?UTF-8?q?=20checkasm:=20=20-=20CPU:=20SpacemiT,=20vendor=20arch=200x5800?=
 =?UTF-8?q?0001,=20imp=200x1000000049772200=20=20-=20CPU:=20VLEN=20=3D=202?=
 =?UTF-8?q?56=20bits=20=20-=20Timing=20source:=20gettime=20=20-=20Bench=20?=
 =?UTF-8?q?duration:=201000=20=C2=B5s=20per=20function=20(1000000=20nsecs)?=
 =?UTF-8?q?=20=20-=20Random=20seed:=20570057552=20RV=5Fzve32x:=20=20-=20vf?=
 =?UTF-8?q?=5Flimiter.limiter8=20=20[OK]=20=20-=20vf=5Flimiter.limiter16?=
 =?UTF-8?q?=20[OK]=20checkasm:=20all=202=20tests=20passed=20Benchmark=20re?=
 =?UTF-8?q?sults:=20=20=20name=20=20=20=20=20=20=20=20=20=20=20=20=20=20?=
 =?UTF-8?q?=20=20=20=20nsecs=20(vs=20ref)=20=20=20limiter8=5Fc:=20=20=20?=
 =?UTF-8?q?=20=20=20=20=20=2013683.9=20=20=20limiter8=5Frvv=5Fi32:=20=20?=
 =?UTF-8?q?=20=20=20534.0=20(25.62x)=20=20=20limiter16=5Fc:=20=20=20=20=20?=
 =?UTF-8?q?=20=20=20=207072.1=20=20=20limiter16=5Frvv=5Fi32:=20=20=20=2052?=
 =?UTF-8?q?3.5=20(13.50x)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rodrigo Camacho <[email protected]>
---
 libavfilter/limiter.h               |  1 +
 libavfilter/riscv/Makefile          |  2 +
 libavfilter/riscv/vf_limiter_init.c | 45 +++++++++++++++
 libavfilter/riscv/vf_limiter_rvv.S  | 89 +++++++++++++++++++++++++++++
 libavfilter/vf_limiter_init.h       |  3 +
 5 files changed, 140 insertions(+)
 create mode 100644 libavfilter/riscv/vf_limiter_init.c
 create mode 100644 libavfilter/riscv/vf_limiter_rvv.S

diff --git a/libavfilter/limiter.h b/libavfilter/limiter.h
index 54d423d1f4b..bc249b852d3 100644
--- a/libavfilter/limiter.h
+++ b/libavfilter/limiter.h
@@ -29,5 +29,6 @@ typedef struct LimiterDSPContext {
 } LimiterDSPContext;
 
 void ff_limiter_init_x86(LimiterDSPContext *dsp, int bpp);
+void ff_limiter_init_riscv(LimiterDSPContext *dsp, int bpp);
 
 #endif /* AVFILTER_LIMITER_H */
diff --git a/libavfilter/riscv/Makefile b/libavfilter/riscv/Makefile
index 3934b3da8be..15a63f73fea 100644
--- a/libavfilter/riscv/Makefile
+++ b/libavfilter/riscv/Makefile
@@ -4,5 +4,7 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER) += riscv/vf_blackdetect_init.o
 RVV-OBJS-$(CONFIG_BLACKDETECT_FILTER) += riscv/vf_blackdetect_rvv.o
 OBJS-$(CONFIG_SCENE_SAD)                     += riscv/scene_sad_init.o
 RVV-OBJS-$(CONFIG_SCENE_SAD)                 += riscv/scene_sad_rvv.o
+OBJS-$(CONFIG_LIMITER_FILTER)                += riscv/vf_limiter_init.o
+RVV-OBJS-$(CONFIG_LIMITER_FILTER)            += riscv/vf_limiter_rvv.o
 
 SHLIBOBJS += riscv/cpu_common.o
diff --git a/libavfilter/riscv/vf_limiter_init.c 
b/libavfilter/riscv/vf_limiter_init.c
new file mode 100644
index 00000000000..280c54650dd
--- /dev/null
+++ b/libavfilter/riscv/vf_limiter_init.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2026 Rodrigo Camacho.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "libavutil/cpu.h"
+#include "libavfilter/limiter.h"
+
+void ff_limiter_8_rvv(const uint8_t *src, uint8_t *dst,
+                      ptrdiff_t slinesize, ptrdiff_t dlinesize,
+                      int w, int h, int min, int max);
+
+void ff_limiter_16_rvv(const uint8_t *src, uint8_t *dst,
+                       ptrdiff_t slinesize, ptrdiff_t dlinesize,
+                       int w, int h, int min, int max);
+
+void ff_limiter_init_riscv(LimiterDSPContext *dsp, int bpp)
+{
+#if HAVE_RVV
+    int flags = av_get_cpu_flags();
+
+    if (flags & AV_CPU_FLAG_RVV_I32) {
+        if (bpp <= 8)
+            dsp->limiter = ff_limiter_8_rvv;
+        else
+            dsp->limiter = ff_limiter_16_rvv;
+    }
+#endif
+}
diff --git a/libavfilter/riscv/vf_limiter_rvv.S 
b/libavfilter/riscv/vf_limiter_rvv.S
new file mode 100644
index 00000000000..5cd61083785
--- /dev/null
+++ b/libavfilter/riscv/vf_limiter_rvv.S
@@ -0,0 +1,89 @@
+/*
+ * Copyright © 2026 Rodrigo Camacho.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/riscv/asm.S"
+
+/*
+ * void ff_limiter_8_rvv(const uint8_t *src, uint8_t *dst,
+ *                       ptrdiff_t slinesize, ptrdiff_t dlinesize,
+ *                       int w, int h, int min, int max);
+*/
+func ff_limiter_8_rvv, zve32x
+        lpad     0
+
+        sub      a2, a2, a4
+        sub      a3, a3, a4
+1:
+        mv       t0, a4
+        addi     a5, a5, -1
+2:
+        vsetvli  t1, t0, e8, m8, ta, ma
+        vle8.v   v8, (a0)
+        add      a0, a0, t1
+        vmaxu.vx v8, v8, a6
+        vminu.vx v8, v8, a7
+        sub      t0, t0, t1
+        vse8.v   v8, (a1)
+        add      a1, a1, t1
+
+        bnez     t0, 2b
+
+        add      a0, a0, a2
+        add      a1, a1, a3
+
+        bnez     a5, 1b
+
+        ret
+endfunc
+
+/*
+ * void ff_limiter_16_rvv(const uint8_t *src, uint8_t *dst,
+ *                        ptrdiff_t slinesize, ptrdiff_t dlinesize,
+ *                        int w, int h, int min, int max);
+*/
+func ff_limiter_16_rvv, zve32x
+        lpad      0
+
+        slli      t2, a4, 1
+        sub       a2, a2, t2
+        sub       a3, a3, t2
+1:
+        mv        t0, a4
+        addi      a5, a5, -1
+2:
+        vsetvli   t1, t0, e16, m8, ta, ma
+        vle16.v   v8, (a0)
+        slli      t2, t1, 1
+        vmaxu.vx  v8, v8, a6
+        sub       t0, t0, t1
+        vminu.vx  v8, v8, a7
+        add       a0, a0, t2
+        vse16.v   v8, (a1)
+        add       a1, a1, t2
+
+        bnez      t0, 2b
+
+        add       a0, a0, a2
+        add       a1, a1, a3
+
+        bnez      a5, 1b
+
+        ret
+endfunc
diff --git a/libavfilter/vf_limiter_init.h b/libavfilter/vf_limiter_init.h
index f257e706ad0..9394db96bcf 100644
--- a/libavfilter/vf_limiter_init.h
+++ b/libavfilter/vf_limiter_init.h
@@ -55,6 +55,9 @@ av_unused static void ff_limiter_init(LimiterDSPContext *s, 
int depth)
 #if ARCH_X86 && HAVE_X86ASM
     ff_limiter_init_x86(s, depth);
 #endif
+#if ARCH_RISCV
+    ff_limiter_init_riscv(s, depth);
+#endif
 
 }
 
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to