Add Zvqdotq support
v2 cover Add Zvqdotq support
This patch series adds Zvqdotq support.
The isa spec of Zvqdotq extension is not ratified yet, so this patch series is based on the latest draft of the spec (v0.0.2) and make the Zvqdotq extension as an experimental extension.
The draft of the Zvqdotq isa spec:
https://github.com/riscv/riscv-dot-product
v2:
* Remove unnecessary variable and mask (Thanks for Richard Henderson's suggestion)
Max Chou (3):
target/riscv: Add Zvqdotq cfg property target/riscv: rvv: Add Zvqdotq support target/riscv: Expose Zvqdotq extension as a cpu property
target/riscv/cpu.c | 2 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/helper.h | 10 +++ target/riscv/insn32.decode | 9 +++ target/riscv/insn_trans/trans_rvzvqdotq.c.inc | 61 +++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 5 ++ target/riscv/translate.c | 1 + target/riscv/vector_helper.c | 61 +++++++++++++++++++ 8 files changed, 150 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzvqdotq.c.inc
--
2.39.3
RFC PATCH v2 1/3 target/riscv: Add Zvqdotq cfg property
The Zvqdotq extension is the vector dot-product extension of RISC-V.
--- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/tcg/tcg-cpu.c | 5 +++++ 3 files changed, 7 insertions(+)
target/riscv/cpu.c +1 -0
@@ -187,6 +187,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zvksg,PRIV_VERSION_1_12_0 , ext_zvksg),ISA_EXT_DATA_ENTRY (zvksh,PRIV_VERSION_1_12_0 , ext_zvksh),ISA_EXT_DATA_ENTRY (zvkt,PRIV_VERSION_1_12_0 , ext_zvkt), +ISA_EXT_DATA_ENTRY (zvqdotq,PRIV_VERSION_1_12_0 , ext_zvqdotq),ISA_EXT_DATA_ENTRY (zhinx,PRIV_VERSION_1_12_0 , ext_zhinx),ISA_EXT_DATA_ENTRY (zhinxmin,PRIV_VERSION_1_12_0 , ext_zhinxmin), ISA_EXT_DATA_ENTRY(sdtrig, PRIV_VERSION_1_12_0, debug),
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -100,6 +100,7 @@ BOOL_FIELD(ext_zvfbfmin) BOOL_FIELD(ext_zvfbfwma) BOOL_FIELD(ext_zvfh) BOOL_FIELD(ext_zvfhmin) +BOOL_FIELD(ext_zvqdotq) BOOL_FIELD(ext_smaia) BOOL_FIELD(ext_ssaia) BOOL_FIELD(ext_smctr)
target/riscv/tcg/tcg-cpu.c +5 -0
@@ -767,6 +767,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if (cpu->cfg.ext_zvqdotq && !cpu->cfg.ext_zve32x) { +error_setg (errp,"Zvqdotq extension requires V or Zve* extensions" ); +return ; + } +if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { error_setg( errp,
Signature · 1 line
2.39.3
RFC PATCH v2 2/3 target/riscv: rvv: Add Zvqdotq support
In reply to Max ChouSupport instructions for vector dot-product extension (Zvqdotq)
- vqdot.[vv,vx]
- vqdotu.[vv,vx]
- vqdotsu.[vv,vx]
- vqdotus.vx
--- target/riscv/helper.h | 10 +++ target/riscv/insn32.decode | 9 +++ target/riscv/insn_trans/trans_rvzvqdotq.c.inc | 61 +++++++++++++++++++ target/riscv/translate.c | 1 + target/riscv/vector_helper.c | 61 +++++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzvqdotq.c.inc
target/riscv/helper.h +10 -0
@@ -1284,3 +1284,13 @@ DEF_HELPER_4(vgmul_vv, void, ptr, ptr, env, i32) DEF_HELPER_5(vsm4k_vi, void, ptr, ptr, i32, env, i32) DEF_HELPER_4(vsm4r_vv, void, ptr, ptr, env, i32)DEF_HELPER_4 (vsm4r_vs, void, ptr, ptr, env, i32) + +/* Vector dot-product functions */ +DEF_HELPER_6(vqdot_vv, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vqdotu_vv, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vqdotsu_vv, void, ptr, ptr, ptr, ptr, env, i32) + +DEF_HELPER_6(vqdot_vx, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vqdotu_vx, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vqdotsu_vx, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6 (vqdotus_vx, void, ptr, ptr, tl, ptr, env, i32)
target/riscv/insn32.decode +9 -0
@@ -1066,3 +1066,12 @@ amominu_h 11000 . . ..... ..... 001 ..... 0101111 @atom_st amomaxu_h 11100 . . ..... ..... 001 ..... 0101111 @atom_st amocas_b 00101 . . ..... ..... 000 ..... 0101111 @atom_st amocas_h 00101 . . ..... ..... 001 ..... 0101111 @atom_st + +# *** Zvqdotq Vector Dot-Product Extension *** +vqdot_vv 101100 . ..... ..... 010 ..... 1010111 @r_vm +vqdot_vx 101100 . ..... ..... 110 ..... 1010111 @r_vm +vqdotu_vv 101000 . ..... ..... 010 ..... 1010111 @r_vm +vqdotu_vx 101000 . ..... ..... 110 ..... 1010111 @r_vm +vqdotsu_vv 101010 . ..... ..... 010 ..... 1010111 @r_vm +vqdotsu_vx 101010 . ..... ..... 110 ..... 1010111 @r_vm +vqdotus_vx 101110 . ..... ..... 110 ..... 1010111 @r_vm
target/riscv/insn_trans/trans_rvzvqdotq.c.inc new file +61 -0
61 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1190,6 +1190,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_rvk.c.inc" #include "insn_trans/trans_rvvk.c.inc" +#include "insn_trans/trans_rvzvqdotq.c.inc" #include "insn_trans/trans_privileged.c.inc" #include "insn_trans/trans_svinval.c.inc" #include "insn_trans/trans_rvbf16.c.inc"
target/riscv/vector_helper.c +61 -0
70 lines not on this page · raw message
Signature · 1 line
2.39.3
Re: [RFC PATCH v2 2/3] target/riscv: rvv: Add Zvqdotq support
Quoted 4 lines · Max Chou
target/riscv/vector_helper.c +4
-0+#define OPMVV_VQDOTQ (NAME ,TD ,T1 ,T2 ,TX1 ,TX2 ,HD ,HS1 ,HS2 ) \ +static void do_##NAME(void *vd, void *vs1, void *vs2, int i) \ +{ \ + int idx; \
target/riscv/vector_helper.c GEN_VEXT_INT_EXT(vsext_vf2_d, int64_t, int32_t, H8, H4) · line 5497
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+T1 r1; \ +T2 r2; \ +TX1 *r1_buf = (TX1 *)vs1 +HD (i); \ +TX2 *r2_buf = (TX2 *)vs2 +HD (i); \ +TD acc = ((TD *)vd)[HD (i)]; \ + \ +for (idx =0 ; idx <4 ; ++idx) { \ + r1 = (TD )(*((T1 *)r1_buf +HS1 (idx))); \ + r2 = (TD )(*((T2 *)r2_buf +HS2 (idx))); \ + acc += r1 * r2; \
Incorrect typing or casting, take your pick.
I suggest
for (int idx = 0; idx < 4; ++idx) {
T1 r1 = ((T1 *)r1_buf)[HS1(idx)];
T2 r2 = ((T2 *)r1_buf)[HS2(idx)];
acc += (TD)r1 * (TD)r2;
}r~
Re: [RFC PATCH v2 2/3] target/riscv: rvv: Add Zvqdotq support
In reply to Max ChouQuoted 4 lines · Max Chou
target/riscv/vector_helper.c +4
-0+#define OPMVX_VQDOTQ (NAME ,TD ,T1 ,T2 ,TX1 ,TX2 ,HD ,HS1 ,HS2 ) \ +static void do_##NAME(void *vd, target_long s1, void *vs2, int i) \ +{ \ + int idx; \
target/riscv/vector_helper.c GEN_VEXT_INT_EXT(vsext_vf2_d, int64_t, int32_t, H8, H4) · line 5523
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+T1 r1; \ +T2 r2; \ +TX1 *r1_buf = (TX1 *)&s1; \ +TX2 *r2_buf = (TX2 *)vs2 +HD (i); \ +TD acc = ((TD *)vd)[HD (i)]; \ + \ +for (idx =0 ; idx <4 ; ++idx) { \ + r1 = *((T1 *)r1_buf +HS1 (idx)); \ + r2 = *((T2 *)r2_buf +HS2 (idx)); \ + acc += r1 * r2; \
One could argue for a missing widening cast to TD here. You got away with it because the only uses happen to have small inputs and "int" sized outputs, so C arithmetic promotion worked for you.
You can move the variable declarations into the loop.
r~
Re: [RFC PATCH v2 2/3] target/riscv: rvv: Add Zvqdotq support
Quoted 30 lines · Richard Henderson
Quoted 1 line · Max Chou
+#define
OPMVX_VQDOTQ(NAME, TD, T1, T2, TX1, TX2, HD, HS1, HS2)\
Quoted 1 line
+static void do_##NAME(void *vd,
target_longs1, void *vs2, int i)\
Quoted 1 line
+{
\
Quoted 1 line
+ int idx;
\
Quoted 1 line
+ T1 r1;
\
Quoted 1 line
+ T2 r2;
\
Quoted 1 line
+ TX1
*r1_buf= (TX1 *)&s1;\
Quoted 1 line
+ TX2
*r2_buf= (TX2 *)vs2 + HD(i);\
Quoted 1 line
+ TD acc = ((TD *)vd)[HD(i)];
\
Quoted 1 line
+
\
Quoted 1 line
+ for (idx = 0; idx < 4; ++idx) {
\
Quoted 1 line
+ r1 = *((T1 *)r1_buf + HS1(idx));
\
Quoted 1 line
+ r2 = *((T2 *)r2_buf + HS2(idx));
\
Quoted 1 line
+ acc += r1 * r2;
\
Quoted 8 lines
One could argue for a missing widening cast to TD here. You got away with it because the
only uses happen to have small inputs and "int" sized outputs, so C arithmetic promotion
worked for you.You can move the variable declarations into the loop.
Thanks for the suggestions. I overlooked this part. I’ll update version 3 to include this part.
Thanks a lot,
Max
RFC PATCH v2 3/3 target/riscv: Expose Zvqdotq extension as a cpu property
In reply to Max Chou--- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
@@ -1373,6 +1373,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = {/* These are experimental so mark with 'x-' */ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {MULTI_EXT_CFG_BOOL ("x-svukte" , ext_svukte, false), +MULTI_EXT_CFG_BOOL ("x-zvqdotq" , ext_zvqdotq, false), { }, };
Signature · 1 line
2.39.3