From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 86DF84EA06
	for <ffmpegdev@gitmailbox.com>; Thu, 20 Mar 2025 09:30:21 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BAA99687BA0;
	Thu, 20 Mar 2025 11:30:17 +0200 (EET)
Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 579DF687A78
 for <ffmpeg-devel@ffmpeg.org>; Thu, 20 Mar 2025 11:30:09 +0200 (EET)
Received: from chengrong-ubuntu-02.home.arpa (unknown [124.16.138.129])
 by APP-03 (Coremail) with SMTP id rQCowACHbzIc4NtnEY3tFg--.17048S2;
 Thu, 20 Mar 2025 17:30:05 +0800 (CST)
From: daichengrong@iscas.ac.cn
To: ffmpeg-devel@ffmpeg.org
Date: Thu, 20 Mar 2025 17:30:01 +0800
Message-Id: <20250320093001.4117071-1-daichengrong@iscas.ac.cn>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
X-CM-TRANSID: rQCowACHbzIc4NtnEY3tFg--.17048S2
X-Coremail-Antispam: 1UD129KBjvJXoWxKry3Jr48KF18CryDZw4ruFg_yoW7uFW5pF
 Z3ur4xCF4xt34fWan2yF15uF1rXas5GF4DGryxuw4Dt3yj9rWUJr4qyw1ayry8GrWakF47
 ZF4Dtr4UC3WkJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
 9KBjDU0xBIdaVrnRJUUUvFb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2
 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw
 A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII
 jxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjc
 xK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVAC
 Y4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8Jr
 0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwAKzVCY07xG64k0F24l
 c2xSY4AK67AK6r4fMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I
 0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWU
 JVWUXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcV
 CY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAF
 wI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvj
 xUy2-eDUUUU
X-Originating-IP: [124.16.138.129]
X-CM-SenderInfo: pgdluxxhqj201qj6x2xfdvhtffof0/
Subject: [FFmpeg-devel] [PATCH] libswresample/riscv:add RVV optimized for
 conv_flt_to_s16
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250320093001.4117071-1-daichengrong@iscas.ac.cn/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

From: daichengrong <daichengrong@iscas.ac.cn>

This patch introduces RVV optimized for conv_flt_to_s16.
On Banana PI F3, it gets an average improvement of 5% for 20000 SAMPLES.
---
 libswresample/audioconvert.c             |  2 +
 libswresample/riscv/Makefile             |  3 ++
 libswresample/riscv/audio_convert_init.c | 50 ++++++++++++++++++++++++
 libswresample/riscv/audio_convert_rvv.S  | 46 ++++++++++++++++++++++
 libswresample/swresample_internal.h      |  4 ++
 5 files changed, 105 insertions(+)
 create mode 100644 libswresample/riscv/Makefile
 create mode 100644 libswresample/riscv/audio_convert_init.c
 create mode 100644 libswresample/riscv/audio_convert_rvv.S

diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index 04108fb966..49b56b6b5e 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -182,6 +182,8 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt,
     swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);
 #elif ARCH_AARCH64
     swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);
+#elif ARCH_RISCV
+    swri_audio_convert_init_riscv(ctx, out_fmt, in_fmt, channels);
 #endif
 
     return ctx;
diff --git a/libswresample/riscv/Makefile b/libswresample/riscv/Makefile
new file mode 100644
index 0000000000..01943cec64
--- /dev/null
+++ b/libswresample/riscv/Makefile
@@ -0,0 +1,3 @@
+OBJS                             += riscv/audio_convert_init.o 
+
+RVV-OBJS                        += riscv/audio_convert_rvv.o 
diff --git a/libswresample/riscv/audio_convert_init.c b/libswresample/riscv/audio_convert_init.c
new file mode 100644
index 0000000000..7bea7e6eb4
--- /dev/null
+++ b/libswresample/riscv/audio_convert_init.c
@@ -0,0 +1,50 @@
+/*
+ * This file is part of libswresample.
+ *
+ * libswresample 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.
+ *
+ * libswresample 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 libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/riscv/cpu.h"
+#include "libavutil/samplefmt.h"
+#include "libswresample/swresample_internal.h"
+#include "libswresample/audioconvert.h"
+
+void swri_oldapi_conv_flt_to_s16_rvv(int16_t *dst, const float *src, int len);
+
+static void conv_flt_to_s16_rvv(uint8_t **dst, const uint8_t **src, int len){
+    swri_oldapi_conv_flt_to_s16_rvv((int16_t*)*dst, (const float*)*src, len);
+}
+
+av_cold void swri_audio_convert_init_riscv(struct AudioConvert *ac,
+                                       enum AVSampleFormat out_fmt,
+                                       enum AVSampleFormat in_fmt,
+                                       int channels)
+{
+    int flags = av_get_cpu_flags();
+
+    ac->simd_f= NULL;
+
+#if HAVE_RVV
+    if (flags & AV_CPU_FLAG_RVV_F32) {
+        if(out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLTP)
+            ac->simd_f = conv_flt_to_s16_rvv;
+    }
+#endif
+}
diff --git a/libswresample/riscv/audio_convert_rvv.S b/libswresample/riscv/audio_convert_rvv.S
new file mode 100644
index 0000000000..d9d58d6d5e
--- /dev/null
+++ b/libswresample/riscv/audio_convert_rvv.S
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2025 daichengrong <daichengrong@iscas.ac.cn>
+ *
+ * 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/riscv/asm.S"
+
+func swri_oldapi_conv_flt_to_s16_rvv, zve32f
+        mv      t1, a0
+        mv      t2, a1
+        #mv t3, a2
+1:      vsetvli a4,a2,e32,m8,ta,ma
+        vle32.v v8,(t2)
+        sub     a2, a2, a4
+        li      t0, (1<<15)
+        sext.w  t0,t0
+        fcvt.s.w        fa2, t0
+        vfmul.vf        v16, v8, fa2
+        vfcvt.x.f.v     v8, v16
+        vsetvli zero,zero,e16,m4,ta,ma
+        vnclip.wi       v16, v8, 0
+        vse16.v v16,(t1)
+        sll     a4,a4,0x1
+        add     t1, t1, a4
+        sll     a4, a4, 0x1
+        add     t2, t2, a4
+        bnez    a2, 1b
+        mv      a0, t1
+        ret
+endfunc
\ No newline at end of file
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 7e46b16fb2..257f69f6dd 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -216,5 +216,9 @@ void swri_audio_convert_init_x86(struct AudioConvert *ac,
                                  enum AVSampleFormat out_fmt,
                                  enum AVSampleFormat in_fmt,
                                  int channels);
+void swri_audio_convert_init_riscv(struct AudioConvert *ac,
+                                 enum AVSampleFormat out_fmt,
+                                 enum AVSampleFormat in_fmt,
+                                 int channels);
 
 #endif
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".