diff mbox series

[FFmpeg-devel,2/4] lavu/riscv: helper macro for VTYPE encoding

Message ID 20221005161256.27612-2-remi@remlab.net
State New
Headers show
Series RISC-V V Opus postfilter | 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. 5, 2022, 4:12 p.m. UTC
On most cases, the vector type (VTYPE) for the RISC-V Vector extension
is supplied as an immediate value, with either of the VSETVLI or
VSETIVLI instructions. There is however a third instruction VSETVL
which takes the vector type from a general purpose register. That is so
the type can be selected at run-time.

This introduces a macro to load a (valid) vector type into a register.
The syntax follows that of VSETVLI and VSETIVLI, with element size,
group multiplier, then tail and mask policies.
---
 libavutil/riscv/asm.S | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/riscv/asm.S b/libavutil/riscv/asm.S
index ffa0bd9068..6ca74f263a 100644
--- a/libavutil/riscv/asm.S
+++ b/libavutil/riscv/asm.S
@@ -92,3 +92,78 @@ 
         shnadd  3, \rd, \rs1, \rs2
         .endm
 #endif
+
+        /* Convenience macro to load a Vector type (vtype) as immediate */
+        .macro  lvtypei rd, e, m=m1, tp=tu, mp=mu
+
+        .ifc \e,e8
+        .equ ei, 0
+        .else
+        .ifc \e,e16
+        .equ ei, 8
+        .else
+        .ifc \e,e32
+        .equ ei, 16
+        .else
+        .ifc \e,e64
+        .equ ei, 24
+        .else
+        .error "Unknown element type"
+        .endif
+        .endif
+        .endif
+        .endif
+
+        .ifc \m,m1
+        .equ mi, 0
+        .else
+        .ifc \m,m2
+        .equ mi, 1
+        .else
+        .ifc \m,m4
+        .equ mi, 2
+        .else
+        .ifc \m,m8
+        .equ mi, 3
+        .else
+        .ifc \m,mf8
+        .equ mi, 5
+        .else
+        .ifc \m,mf4
+        .equ mi, 6
+        .else
+        .ifc \m,mf2
+        .equ mi, 7
+        .else
+        .error "Unknown multiplier"
+        .equ mi, 3
+        .endif
+        .endif
+        .endif
+        .endif
+        .endif
+        .endif
+        .endif
+
+        .ifc \tp,tu
+        .equ tpi, 0
+        .else
+        .ifc \tp,ta
+        .equ tpi, 64
+        .else
+        .error "Unknown tail policy"
+        .endif
+        .endif
+
+        .ifc \mp,mu
+        .equ mpi, 0
+        .else
+        .ifc \mp,ma
+        .equ mpi, 128
+        .else
+        .error "Unknown mask policy"
+        .endif
+        .endif
+
+        li      \rd, (ei | mi | tpi | mpi)
+        .endm