From 5e4b142c314435635e9eb05c01adb29cae4bc258 Mon Sep 17 00:00:00 2001 From: LIU Zhiwei Date: Sun, 7 Mar 2021 11:30:13 -0500 Subject: [PATCH] target/riscv: vector single-width floating-point multiply/divide instructions Backports 0e0057cbe2169195a08ae8247504e69f9b80542b --- qemu/header_gen.py | 15 ++++++ qemu/riscv32.h | 15 ++++++ qemu/riscv64.h | 15 ++++++ qemu/target/riscv/helper.h | 16 +++++++ qemu/target/riscv/insn32.decode | 5 ++ qemu/target/riscv/insn_trans/trans_rvv.inc.c | 7 +++ qemu/target/riscv/vector_helper.c | 49 ++++++++++++++++++++ 7 files changed, 122 insertions(+) diff --git a/qemu/header_gen.py b/qemu/header_gen.py index 41799c30..63bb2c92 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -7008,6 +7008,21 @@ riscv_symbols = ( 'helper_vfwadd_wf_w', 'helper_vfwsub_wf_h', 'helper_vfwsub_wf_w', + 'helper_vfmul_vv_h', + 'helper_vfmul_vv_w', + 'helper_vfmul_vv_d', + 'helper_vfdiv_vv_h', + 'helper_vfdiv_vv_w', + 'helper_vfdiv_vv_d', + 'helper_vfmul_vf_h', + 'helper_vfmul_vf_w', + 'helper_vfmul_vf_d', + 'helper_vfdiv_vf_h', + 'helper_vfdiv_vf_w', + 'helper_vfdiv_vf_d', + 'helper_vfrdiv_vf_h', + 'helper_vfrdiv_vf_w', + 'helper_vfrdiv_vf_d', 'pmp_hart_has_privs', 'pmpaddr_csr_read', 'pmpaddr_csr_write', diff --git a/qemu/riscv32.h b/qemu/riscv32.h index fd7aa66b..c848b4a5 100644 --- a/qemu/riscv32.h +++ b/qemu/riscv32.h @@ -4444,6 +4444,21 @@ #define helper_vfwadd_wf_w helper_vfwadd_wf_w_riscv32 #define helper_vfwsub_wf_h helper_vfwsub_wf_h_riscv32 #define helper_vfwsub_wf_w helper_vfwsub_wf_w_riscv32 +#define helper_vfmul_vv_h helper_vfmul_vv_h_riscv32 +#define helper_vfmul_vv_w helper_vfmul_vv_w_riscv32 +#define helper_vfmul_vv_d helper_vfmul_vv_d_riscv32 +#define helper_vfdiv_vv_h helper_vfdiv_vv_h_riscv32 +#define helper_vfdiv_vv_w helper_vfdiv_vv_w_riscv32 +#define helper_vfdiv_vv_d helper_vfdiv_vv_d_riscv32 +#define helper_vfmul_vf_h helper_vfmul_vf_h_riscv32 +#define helper_vfmul_vf_w helper_vfmul_vf_w_riscv32 +#define helper_vfmul_vf_d helper_vfmul_vf_d_riscv32 +#define helper_vfdiv_vf_h helper_vfdiv_vf_h_riscv32 +#define helper_vfdiv_vf_w helper_vfdiv_vf_w_riscv32 +#define helper_vfdiv_vf_d helper_vfdiv_vf_d_riscv32 +#define helper_vfrdiv_vf_h helper_vfrdiv_vf_h_riscv32 +#define helper_vfrdiv_vf_w helper_vfrdiv_vf_w_riscv32 +#define helper_vfrdiv_vf_d helper_vfrdiv_vf_d_riscv32 #define pmp_hart_has_privs pmp_hart_has_privs_riscv32 #define pmpaddr_csr_read pmpaddr_csr_read_riscv32 #define pmpaddr_csr_write pmpaddr_csr_write_riscv32 diff --git a/qemu/riscv64.h b/qemu/riscv64.h index 59f75f60..388643f3 100644 --- a/qemu/riscv64.h +++ b/qemu/riscv64.h @@ -4444,6 +4444,21 @@ #define helper_vfwadd_wf_w helper_vfwadd_wf_w_riscv64 #define helper_vfwsub_wf_h helper_vfwsub_wf_h_riscv64 #define helper_vfwsub_wf_w helper_vfwsub_wf_w_riscv64 +#define helper_vfmul_vv_h helper_vfmul_vv_h_riscv64 +#define helper_vfmul_vv_w helper_vfmul_vv_w_riscv64 +#define helper_vfmul_vv_d helper_vfmul_vv_d_riscv64 +#define helper_vfdiv_vv_h helper_vfdiv_vv_h_riscv64 +#define helper_vfdiv_vv_w helper_vfdiv_vv_w_riscv64 +#define helper_vfdiv_vv_d helper_vfdiv_vv_d_riscv64 +#define helper_vfmul_vf_h helper_vfmul_vf_h_riscv64 +#define helper_vfmul_vf_w helper_vfmul_vf_w_riscv64 +#define helper_vfmul_vf_d helper_vfmul_vf_d_riscv64 +#define helper_vfdiv_vf_h helper_vfdiv_vf_h_riscv64 +#define helper_vfdiv_vf_w helper_vfdiv_vf_w_riscv64 +#define helper_vfdiv_vf_d helper_vfdiv_vf_d_riscv64 +#define helper_vfrdiv_vf_h helper_vfrdiv_vf_h_riscv64 +#define helper_vfrdiv_vf_w helper_vfrdiv_vf_w_riscv64 +#define helper_vfrdiv_vf_d helper_vfrdiv_vf_d_riscv64 #define pmp_hart_has_privs pmp_hart_has_privs_riscv64 #define pmpaddr_csr_read pmpaddr_csr_read_riscv64 #define pmpaddr_csr_write pmpaddr_csr_write_riscv64 diff --git a/qemu/target/riscv/helper.h b/qemu/target/riscv/helper.h index e154c524..4ae502a3 100644 --- a/qemu/target/riscv/helper.h +++ b/qemu/target/riscv/helper.h @@ -839,3 +839,19 @@ DEF_HELPER_6(vfwadd_wf_h, void, ptr, ptr, i64, ptr, env, i32) DEF_HELPER_6(vfwadd_wf_w, void, ptr, ptr, i64, ptr, env, i32) DEF_HELPER_6(vfwsub_wf_h, void, ptr, ptr, i64, ptr, env, i32) DEF_HELPER_6(vfwsub_wf_w, void, ptr, ptr, i64, ptr, env, i32) + +DEF_HELPER_6(vfmul_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfmul_vv_w, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfmul_vv_d, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfdiv_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfdiv_vv_w, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfdiv_vv_d, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vfmul_vf_h, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfmul_vf_w, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfmul_vf_d, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfdiv_vf_h, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfdiv_vf_w, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfdiv_vf_d, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfrdiv_vf_h, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfrdiv_vf_w, void, ptr, ptr, i64, ptr, env, i32) +DEF_HELPER_6(vfrdiv_vf_d, void, ptr, ptr, i64, ptr, env, i32) diff --git a/qemu/target/riscv/insn32.decode b/qemu/target/riscv/insn32.decode index 42d8a967..5db02f0c 100644 --- a/qemu/target/riscv/insn32.decode +++ b/qemu/target/riscv/insn32.decode @@ -458,6 +458,11 @@ vfwsub_vv 110010 . ..... ..... 001 ..... 1010111 @r_vm vfwsub_vf 110010 . ..... ..... 101 ..... 1010111 @r_vm vfwsub_wv 110110 . ..... ..... 001 ..... 1010111 @r_vm vfwsub_wf 110110 . ..... ..... 101 ..... 1010111 @r_vm +vfmul_vv 100100 . ..... ..... 001 ..... 1010111 @r_vm +vfmul_vf 100100 . ..... ..... 101 ..... 1010111 @r_vm +vfdiv_vv 100000 . ..... ..... 001 ..... 1010111 @r_vm +vfdiv_vf 100000 . ..... ..... 101 ..... 1010111 @r_vm +vfrdiv_vf 100001 . ..... ..... 101 ..... 1010111 @r_vm vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm vsetvl 1000000 ..... ..... 111 ..... 1010111 @r diff --git a/qemu/target/riscv/insn_trans/trans_rvv.inc.c b/qemu/target/riscv/insn_trans/trans_rvv.inc.c index b8906cc8..83b5f603 100644 --- a/qemu/target/riscv/insn_trans/trans_rvv.inc.c +++ b/qemu/target/riscv/insn_trans/trans_rvv.inc.c @@ -2082,3 +2082,10 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ GEN_OPFWF_WIDEN_TRANS(vfwadd_wf) GEN_OPFWF_WIDEN_TRANS(vfwsub_wf) + +/* Vector Single-Width Floating-Point Multiply/Divide Instructions */ +GEN_OPFVV_TRANS(vfmul_vv, opfvv_check) +GEN_OPFVV_TRANS(vfdiv_vv, opfvv_check) +GEN_OPFVF_TRANS(vfmul_vf, opfvf_check) +GEN_OPFVF_TRANS(vfdiv_vf, opfvf_check) +GEN_OPFVF_TRANS(vfrdiv_vf, opfvf_check) diff --git a/qemu/target/riscv/vector_helper.c b/qemu/target/riscv/vector_helper.c index 148d58b2..e8411471 100644 --- a/qemu/target/riscv/vector_helper.c +++ b/qemu/target/riscv/vector_helper.c @@ -3362,3 +3362,52 @@ RVVCALL(OPFVF2, vfwsub_wf_h, WOP_WUUU_H, H4, H2, vfwsubw16) RVVCALL(OPFVF2, vfwsub_wf_w, WOP_WUUU_W, H8, H4, vfwsubw32) GEN_VEXT_VF(vfwsub_wf_h, 2, 4, clearl) GEN_VEXT_VF(vfwsub_wf_w, 4, 8, clearq) + +/* Vector Single-Width Floating-Point Multiply/Divide Instructions */ +RVVCALL(OPFVV2, vfmul_vv_h, OP_UUU_H, H2, H2, H2, float16_mul) +RVVCALL(OPFVV2, vfmul_vv_w, OP_UUU_W, H4, H4, H4, float32_mul) +RVVCALL(OPFVV2, vfmul_vv_d, OP_UUU_D, H8, H8, H8, float64_mul) +GEN_VEXT_VV_ENV(vfmul_vv_h, 2, 2, clearh) +GEN_VEXT_VV_ENV(vfmul_vv_w, 4, 4, clearl) +GEN_VEXT_VV_ENV(vfmul_vv_d, 8, 8, clearq) +RVVCALL(OPFVF2, vfmul_vf_h, OP_UUU_H, H2, H2, float16_mul) +RVVCALL(OPFVF2, vfmul_vf_w, OP_UUU_W, H4, H4, float32_mul) +RVVCALL(OPFVF2, vfmul_vf_d, OP_UUU_D, H8, H8, float64_mul) +GEN_VEXT_VF(vfmul_vf_h, 2, 2, clearh) +GEN_VEXT_VF(vfmul_vf_w, 4, 4, clearl) +GEN_VEXT_VF(vfmul_vf_d, 8, 8, clearq) + +RVVCALL(OPFVV2, vfdiv_vv_h, OP_UUU_H, H2, H2, H2, float16_div) +RVVCALL(OPFVV2, vfdiv_vv_w, OP_UUU_W, H4, H4, H4, float32_div) +RVVCALL(OPFVV2, vfdiv_vv_d, OP_UUU_D, H8, H8, H8, float64_div) +GEN_VEXT_VV_ENV(vfdiv_vv_h, 2, 2, clearh) +GEN_VEXT_VV_ENV(vfdiv_vv_w, 4, 4, clearl) +GEN_VEXT_VV_ENV(vfdiv_vv_d, 8, 8, clearq) +RVVCALL(OPFVF2, vfdiv_vf_h, OP_UUU_H, H2, H2, float16_div) +RVVCALL(OPFVF2, vfdiv_vf_w, OP_UUU_W, H4, H4, float32_div) +RVVCALL(OPFVF2, vfdiv_vf_d, OP_UUU_D, H8, H8, float64_div) +GEN_VEXT_VF(vfdiv_vf_h, 2, 2, clearh) +GEN_VEXT_VF(vfdiv_vf_w, 4, 4, clearl) +GEN_VEXT_VF(vfdiv_vf_d, 8, 8, clearq) + +static uint16_t float16_rdiv(uint16_t a, uint16_t b, float_status *s) +{ + return float16_div(b, a, s); +} + +static uint32_t float32_rdiv(uint32_t a, uint32_t b, float_status *s) +{ + return float32_div(b, a, s); +} + +static uint64_t float64_rdiv(uint64_t a, uint64_t b, float_status *s) +{ + return float64_div(b, a, s); +} + +RVVCALL(OPFVF2, vfrdiv_vf_h, OP_UUU_H, H2, H2, float16_rdiv) +RVVCALL(OPFVF2, vfrdiv_vf_w, OP_UUU_W, H4, H4, float32_rdiv) +RVVCALL(OPFVF2, vfrdiv_vf_d, OP_UUU_D, H8, H8, float64_rdiv) +GEN_VEXT_VF(vfrdiv_vf_h, 2, 2, clearh) +GEN_VEXT_VF(vfrdiv_vf_w, 4, 4, clearl) +GEN_VEXT_VF(vfrdiv_vf_d, 8, 8, clearq)