* [FFmpeg-devel] [PATCH 1/3] lavc/vc1dsp: factor R-V V inv_trans_8 code
@ 2024-06-27 19:04 Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 2/3] lavc/vc1dsp: fix overflow in R-V V inv_trans_8 Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 3/3] lavc/vc1dsp: fix potential overflow in R-V V inv_trans_4 Rémi Denis-Courmont
0 siblings, 2 replies; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-27 19:04 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/riscv/vc1dsp_rvv.S | 64 +++++++++++++----------------------
1 file changed, 23 insertions(+), 41 deletions(-)
diff --git a/libavcodec/riscv/vc1dsp_rvv.S b/libavcodec/riscv/vc1dsp_rvv.S
index 7e1fb84b0c..b3a1f55ab9 100644
--- a/libavcodec/riscv/vc1dsp_rvv.S
+++ b/libavcodec/riscv/vc1dsp_rvv.S
@@ -165,6 +165,7 @@ func ff_vc1_inv_trans_8_rvv, zve32x
vsll.vi v23, v7, 4
vsub.vv v20, v20, v21
vsub.vv v22, v22, v23
+ srli t2, t1, 2
vadd.vv v0, v28, v16
vadd.vv v19, v20, v22 # t4
vadd.vv v1, v29, v17
@@ -174,6 +175,14 @@ func ff_vc1_inv_trans_8_rvv, zve32x
vsub.vv v5, v30, v18
vsub.vv v6, v29, v17
vsub.vv v7, v28, v16
+ beqz t2, 1f # faster than 4x add t2=zero
+ .irp n,4,5,6,7
+ vadd.vi v\n, v\n, 1
+ .endr
+1:
+ .irp n,0,1,2,3,4,5,6,7
+ vssra.vx v\n, v\n, t1
+ .endr
jr t0
endfunc
@@ -220,35 +229,22 @@ func ff_vc1_inv_trans_8x8_rvv, zve32x
addi a7, a0, 7 * 8 * 2
vle16.v v6, (a6)
vle16.v v7, (a7)
+ li t1, 3
jal t0, ff_vc1_inv_trans_8_rvv
- .irp n,0,1,2,3,4,5,6,7
- vssra.vi v\n, v\n, 3
- .endr
vsseg8e16.v v0, (a0)
.irp n,0,1,2,3,4,5,6,7
vle16.v v\n, (a\n)
.endr
+ li t1, 7
jal t0, ff_vc1_inv_trans_8_rvv
- vadd.vi v4, v4, 1
- vadd.vi v5, v5, 1
- vssra.vi v4, v4, 7
- vssra.vi v5, v5, 7
- vse16.v v4, (a4)
- vadd.vi v6, v6, 1
- vse16.v v5, (a5)
- vadd.vi v7, v7, 1
- vssra.vi v6, v6, 7
- vssra.vi v7, v7, 7
- vse16.v v6, (a6)
- vssra.vi v0, v0, 7
- vse16.v v7, (a7)
- vssra.vi v1, v1, 7
vse16.v v0, (a0)
- vssra.vi v2, v2, 7
vse16.v v1, (a1)
- vssra.vi v3, v3, 7
vse16.v v2, (a2)
vse16.v v3, (a3)
+ vse16.v v4, (a4)
+ vse16.v v5, (a5)
+ vse16.v v6, (a6)
+ vse16.v v7, (a7)
ret
endfunc
@@ -256,10 +252,8 @@ func ff_vc1_inv_trans_8x4_rvv, zve32x
csrwi vxrm, 0
vsetivli zero, 4, e16, mf2, ta, ma
vlseg8e16.v v0, (a2)
+ li t1, 3
jal t0, ff_vc1_inv_trans_8_rvv
- .irp n,0,1,2,3,4,5,6,7
- vssra.vi v\n, v\n, 3
- .endr
vsseg8e16.v v0, (a2)
addi a3, a2, 1 * 8 * 2
vsetivli zero, 8, e16, m1, ta, ma
@@ -323,33 +317,21 @@ func ff_vc1_inv_trans_4x8_rvv, zve32x
addi t1, a2, 7 * 8 * 2
vle16.v v6, (t6)
vle16.v v7, (t1)
-
+ li t1, 7
jal t0, ff_vc1_inv_trans_8_rvv
- vadd.vi v4, v4, 1
add t0, a1, a0
- vadd.vi v5, v5, 1
- vadd.vi v6, v6, 1
- add t1, a1, t0
- vadd.vi v7, v7, 1
- vssra.vi v0, v0, 7
- add t2, a1, t1
- vssra.vi v1, v1, 7
- vssra.vi v2, v2, 7
- add t3, a1, t2
- vssra.vi v3, v3, 7
- vssra.vi v4, v4, 7
- add t4, a1, t3
- vssra.vi v5, v5, 7
- vssra.vi v6, v6, 7
- add t5, a1, t4
- vssra.vi v7, v7, 7
vle8.v v8, (a0)
- add t6, a1, t5
+ add t1, a1, t0
vle8.v v9, (t0)
+ add t2, a1, t1
vle8.v v10, (t1)
+ add t3, a1, t2
vle8.v v11, (t2)
+ add t4, a1, t3
vle8.v v12, (t3)
+ add t5, a1, t4
vle8.v v13, (t4)
+ add t6, a1, t5
vle8.v v14, (t5)
vle8.v v15, (t6)
vsetvli zero, zero, e8, mf4, ta, ma
--
2.45.2
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] lavc/vc1dsp: fix overflow in R-V V inv_trans_8
2024-06-27 19:04 [FFmpeg-devel] [PATCH 1/3] lavc/vc1dsp: factor R-V V inv_trans_8 code Rémi Denis-Courmont
@ 2024-06-27 19:04 ` Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 3/3] lavc/vc1dsp: fix potential overflow in R-V V inv_trans_4 Rémi Denis-Courmont
1 sibling, 0 replies; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-27 19:04 UTC (permalink / raw)
To: ffmpeg-devel
The last set of additions/subtractions can break the 16-bit limit, and
require 17 bits of precision. This uses widening adds accordingly to fix
the MSS2 FATE tests.
---
libavcodec/riscv/vc1dsp_rvv.S | 37 ++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/libavcodec/riscv/vc1dsp_rvv.S b/libavcodec/riscv/vc1dsp_rvv.S
index b3a1f55ab9..d038981a02 100644
--- a/libavcodec/riscv/vc1dsp_rvv.S
+++ b/libavcodec/riscv/vc1dsp_rvv.S
@@ -145,44 +145,49 @@ func ff_vc1_inv_trans_8_rvv, zve32x
vadd.vv v20, v20, v21
vadd.vv v22, v22, v23
vsll.vi v21, v3, 2
- vadd.vv v16, v20, v22 # t1
+ vadd.vv v24, v20, v22 # t1
vmul.vx v20, v1, t5
vsll.vi v22, v5, 4
vmul.vx v23, v7, t3
vsub.vv v20, v20, v21
vadd.vv v22, v22, v23
vsll.vi v21, v3, 4
- vsub.vv v17, v20, v22 # t2
+ vsub.vv v25, v20, v22 # t2
vmul.vx v20, v1, t3
vsll.vi v22, v5, 2
vmul.vx v23, v7, t5
vsub.vv v20, v20, v21
vadd.vv v22, v22, v23
vmul.vx v21, v3, t3
- vadd.vv v18, v20, v22 # t3
+ vadd.vv v26, v20, v22 # t3
vsll.vi v20, v1, 2
vmul.vx v22, v5, t5
vsll.vi v23, v7, 4
vsub.vv v20, v20, v21
vsub.vv v22, v22, v23
+ vadd.vv v27, v20, v22 # t4
srli t2, t1, 2
- vadd.vv v0, v28, v16
- vadd.vv v19, v20, v22 # t4
- vadd.vv v1, v29, v17
- vadd.vv v2, v30, v18
- vadd.vv v3, v31, v19
- vsub.vv v4, v31, v19
- vsub.vv v5, v30, v18
- vsub.vv v6, v29, v17
- vsub.vv v7, v28, v16
+ vwadd.vv v8, v28, v24
+ vwadd.vv v10, v29, v25
+ vwadd.vv v12, v30, v26
+ vwadd.vv v14, v31, v27
beqz t2, 1f # faster than 4x add t2=zero
- .irp n,4,5,6,7
+ .irp n,31,30,29,28
vadd.vi v\n, v\n, 1
.endr
1:
- .irp n,0,1,2,3,4,5,6,7
- vssra.vx v\n, v\n, t1
- .endr
+ vwsub.vv v16, v31, v27
+ vwsub.vv v18, v30, v26
+ vwsub.vv v20, v29, v25
+ vwsub.vv v22, v28, v24
+ vnclip.wx v0, v8, t1
+ vnclip.wx v1, v10, t1
+ vnclip.wx v2, v12, t1
+ vnclip.wx v3, v14, t1
+ vnclip.wx v4, v16, t1
+ vnclip.wx v5, v18, t1
+ vnclip.wx v6, v20, t1
+ vnclip.wx v7, v22, t1
jr t0
endfunc
--
2.45.2
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] lavc/vc1dsp: fix potential overflow in R-V V inv_trans_4
2024-06-27 19:04 [FFmpeg-devel] [PATCH 1/3] lavc/vc1dsp: factor R-V V inv_trans_8 code Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 2/3] lavc/vc1dsp: fix overflow in R-V V inv_trans_8 Rémi Denis-Courmont
@ 2024-06-27 19:04 ` Rémi Denis-Courmont
1 sibling, 0 replies; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-27 19:04 UTC (permalink / raw)
To: ffmpeg-devel
Judging by the coefficients, the last round of add/sub can overflow
to 17 bits with a very small probability just as with the 8-point
transform. This is not observed under FATE, but better safe than sorry.
---
libavcodec/riscv/vc1dsp_rvv.S | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/libavcodec/riscv/vc1dsp_rvv.S b/libavcodec/riscv/vc1dsp_rvv.S
index d038981a02..e857805ccf 100644
--- a/libavcodec/riscv/vc1dsp_rvv.S
+++ b/libavcodec/riscv/vc1dsp_rvv.S
@@ -206,13 +206,14 @@ func ff_vc1_inv_trans_4_rvv, zve32x
vmul.vx v20, v1, t2
vadd.vv v26, v14, v16 # t3
vsub.vv v27, v18, v20 # t4
- vadd.vv v0, v24, v26
- vsub.vv v1, v25, v27
- vadd.vv v2, v25, v27
- vsub.vv v3, v24, v26
- .irp n,0,1,2,3
- vssra.vx v\n, v\n, t1 # + 4 >> 3 or + 64 >> 7
- .endr
+ vwadd.vv v8, v24, v26
+ vwsub.vv v10, v25, v27
+ vwadd.vv v12, v25, v27
+ vwsub.vv v14, v24, v26
+ vnclip.wx v0, v8, t1
+ vnclip.wx v1, v10, t1
+ vnclip.wx v2, v12, t1
+ vnclip.wx v3, v14, t1
jr t0
endfunc
--
2.45.2
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-27 19:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27 19:04 [FFmpeg-devel] [PATCH 1/3] lavc/vc1dsp: factor R-V V inv_trans_8 code Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 2/3] lavc/vc1dsp: fix overflow in R-V V inv_trans_8 Rémi Denis-Courmont
2024-06-27 19:04 ` [FFmpeg-devel] [PATCH 3/3] lavc/vc1dsp: fix potential overflow in R-V V inv_trans_4 Rémi Denis-Courmont
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git