diff mbox series

[FFmpeg-devel] riscv: fix scalar product initialisation

Message ID 20221003150642.5411-1-remi@remlab.net
State Accepted
Commit 96a83ceea434911d825223eaafa0f999e2a9d1fa
Headers show
Series [FFmpeg-devel] riscv: fix scalar product initialisation | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Rémi Denis-Courmont Oct. 3, 2022, 3:06 p.m. UTC
From: Rémi Denis-Courmont <remi@remlab.net>

VSETVLI xd, x0, ...' has rather nonobvious semantics:
- If xd is x0, then it preserves the current vector length.
- If xd is not x0, it sets the vector length to the supported maximum.

Also somewhat confusingly, while VMV.X.S always does its thing
regardless of the selected vector length, VMV.S.X does _nothing_ if the
selected vector length is zero.

So the current code breaks fails to initialise the accumulator if we
are unlucky to have a selected vector length of zero on entry. Fix it
by forcing the vector length to one.
---
 libavcodec/riscv/audiodsp_rvv.S | 2 +-
 libavutil/riscv/float_dsp_rvv.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Rémi Denis-Courmont Oct. 12, 2022, 5:04 p.m. UTC | #1
Le maanantaina 3. lokakuuta 2022, 18.06.42 EEST remi@remlab.net a écrit :
> From: Rémi Denis-Courmont <remi@remlab.net>
> 
> VSETVLI xd, x0, ...' has rather nonobvious semantics:
> - If xd is x0, then it preserves the current vector length.
> - If xd is not x0, it sets the vector length to the supported maximum.
> 
> Also somewhat confusingly, while VMV.X.S always does its thing
> regardless of the selected vector length, VMV.S.X does _nothing_ if the
> selected vector length is zero.
> 
> So the current code breaks fails to initialise the accumulator if we
> are unlucky to have a selected vector length of zero on entry. Fix it
> by forcing the vector length to one.

Ping.

The issue becomes systematically reproducible with the checkasm support.
diff mbox series

Patch

diff --git a/libavcodec/riscv/audiodsp_rvv.S b/libavcodec/riscv/audiodsp_rvv.S
index f4308f27c5..8e8bbd2058 100644
--- a/libavcodec/riscv/audiodsp_rvv.S
+++ b/libavcodec/riscv/audiodsp_rvv.S
@@ -21,7 +21,7 @@ 
 #include "libavutil/riscv/asm.S"
 
 func ff_scalarproduct_int16_rvv, zve32x
-        vsetvli     zero, zero, e16, m1, ta, ma
+        vsetivli    zero, 1, e16, m1, ta, ma
         vmv.s.x     v8, zero
 1:
         vsetvli     t0, a2, e16, m1, ta, ma
diff --git a/libavutil/riscv/float_dsp_rvv.S b/libavutil/riscv/float_dsp_rvv.S
index ab2e0c42d7..e105f2d574 100644
--- a/libavutil/riscv/float_dsp_rvv.S
+++ b/libavutil/riscv/float_dsp_rvv.S
@@ -167,7 +167,7 @@  endfunc
 
 // a0 = (a0).(a1) [0..a2-1]
 func ff_scalarproduct_float_rvv, zve32f
-        vsetvli      zero, zero, e32, m1, ta, ma
+        vsetivli     zero, 1, e32, m1, ta, ma
         vmv.s.x      v8, zero
 1:
         vsetvli      t0, a2, e32, m1, ta, ma