support subsets of Float-Point in Integer Registers extensions
v2 cover support subsets of Float-Point in Integer Registers extensions
This patchset implements RISC-V Float-Point in Integer Registers extensions(Version 1.0.0-rc), which includes Zfinx, Zdinx, Zhinx and Zhinxmin extension.
Specification:
https://github.com/riscv/riscv-zfinx/blob/main/zfinx-1.0.0-rc.pdf
The port is available here:
https://github.com/plctlab/plct-qemu/tree/plct-zfinx-upstream-v2
To test this implementation, specify cpu argument with 'Zfinx =true,Zdinx=true,Zhinx=true,Zhinxmin=true' with 'g=false,f=false,d=false,Zfh=false,Zfhmin=false' This implementation can pass gcc tests, ci result can be found in https://ci.rvperf.org/job/plct-qemu-zfinx-upstream/
v2:
* hardwire mstatus.FS to zero when enable zfinx
* do register-pair check at the begin of translation
* optimize partial implemention as suggested
liweiwei (6):
target/riscv: add cfg properties for zfinx, zdinx and zhinx{min} target/riscv: hardwire mstatus.FS to zero when enable zfinx target/riscv: add support for zfinx
target/riscv: add support for zdinx
target/riscv: add support for zhinx/zhinxmin target/riscv: expose zfinx, zdinx, zhinx{min} properties
target/riscv/cpu.c | 20 ++ target/riscv/cpu.h | 4 + target/riscv/cpu_helper.c | 6 +- target/riscv/csr.c | 24 +- target/riscv/fpu_helper.c | 178 ++++++------ target/riscv/helper.h | 4 +- target/riscv/insn_trans/trans_rvd.c.inc | 319 ++++++++++++++++----- target/riscv/insn_trans/trans_rvf.c.inc | 314 +++++++++++++------- target/riscv/insn_trans/trans_rvzfh.c.inc | 332 +++++++++++++++------- target/riscv/internals.h | 32 ++- target/riscv/translate.c | 161 +++++++++++ 11 files changed, 1023 insertions(+), 371 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/6 target/riscv: add cfg properties for zfinx, zdinx and zhinx{min}
From: liweiwei <[email protected]>
--- target/riscv/cpu.c | 12 ++++++++++++ target/riscv/cpu.h | 4 ++++ target/riscv/translate.c | 8 ++++++++ 3 files changed, 24 insertions(+)
target/riscv/cpu.c +12 -0
@@ -491,6 +491,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) cpu->cfg.ext_d = true; } +if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || + cpu->cfg.ext_zhinxmin) { + cpu->cfg.ext_zfinx = true; + } +/* Set the ISA extensions, checks should have happened above */ if (cpu->cfg.ext_i) { ext |=RVI ;
@@ -565,6 +570,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)if (cpu->cfg.ext_j) { ext |=RVJ ; } +if (cpu->cfg.ext_zfinx && ((ext & (RVF |RVD )) || cpu->cfg.ext_zfh || + cpu->cfg.ext_zfhmin)) { +error_setg (errp, +"'Zfinx' cannot be supported together with 'F', 'D', 'Zfh'," +" 'Zfhmin'" ); +return ; + }set_misa (env, env->misa_mxl, ext); }
target/riscv/cpu.h +4 -0
@@ -315,8 +315,12 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zdinx;bool ext_zfh;bool ext_zfhmin; +bool ext_zfinx; +bool ext_zhinx; +bool ext_zhinxmin;char *priv_spec;char *user_spec;
target/riscv/translate.c +8 -0
@@ -76,8 +76,12 @@ typedef struct DisasContext {RISCVMXL ol;bool virt_enabled;bool ext_ifencei; +bool ext_zdinx;bool ext_zfh;bool ext_zfhmin; +bool ext_zfinx; +bool ext_zhinx; +bool ext_zhinxmin;bool hlsx;/* vector extension */ bool vill;
@@ -703,8 +707,12 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa_ext = env->misa_ext; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; + ctx->ext_zdinx = cpu->cfg.ext_zdinx; ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; + ctx->ext_zfinx = cpu->cfg.ext_zfinx; + ctx->ext_zhinx = cpu->cfg.ext_zhinx; + ctx->ext_zhinxmin = cpu->cfg.ext_zhinxmin; ctx->vlen = cpu->cfg.vlen; ctx->elen = cpu->cfg.elen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS );
Signature · 1 line
2.17.1
Re: [PATCH v2 1/6] target/riscv: add cfg properties for zfinx, zdinx and zhinx{min}
Quoted 2 lines · Weiwei Li
From: liweiwei <[email protected]>
You missed here, "From" should match "SoB" name
Quoted 79 lines
Co-authored-by ardxwe <[email protected]>Signed-off-by Weiwei Li <[email protected]>Signed-off-by Junqiang Wang <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/riscv/cpu.c | 12 ++++++++++++ target/riscv/cpu.h | 4 ++++ target/riscv/translate.c | 8 ++++++++ 3 files changed, 24 insertions(+)target/riscv/cpu.c +12
-0@@ -491,6 +491,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) cpu->cfg.ext_d = true; } +if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || + cpu->cfg.ext_zhinxmin) { + cpu->cfg.ext_zfinx = true; + } +/* Set the ISA extensions, checks should have happened above */ if (cpu->cfg.ext_i) { ext |=RVI ;@@ -565,6 +570,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)if (cpu->cfg.ext_j) { ext |=RVJ ; } +if (cpu->cfg.ext_zfinx && ((ext & (RVF |RVD )) || cpu->cfg.ext_zfh || + cpu->cfg.ext_zfhmin)) { +error_setg (errp, +"'Zfinx' cannot be supported together with 'F', 'D', 'Zfh'," +" 'Zfhmin'" ); +return ; + }set_misa (env, env->misa_mxl, ext); }target/riscv/cpu.h +4
-0@@ -315,8 +315,12 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zdinx;bool ext_zfh;bool ext_zfhmin; +bool ext_zfinx; +bool ext_zhinx; +bool ext_zhinxmin;char *priv_spec;char *user_spec;target/riscv/translate.c +4
-0@@ -76,8 +76,12 @@ typedef struct DisasContext {RISCVMXL ol;bool virt_enabled;bool ext_ifencei; +bool ext_zdinx;bool ext_zfh;bool ext_zfhmin; +bool ext_zfinx; +bool ext_zhinx; +bool ext_zhinxmin;bool hlsx;/* vector extension */ bool vill;@@ -703,8 +707,12 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa_ext = env->misa_ext; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei;
target/riscv/translate.c static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
Quoted 10 lines
target/riscv/translate.c +4
-1+ ctx->ext_zdinx = cpu->cfg.ext_zdinx; ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; + ctx->ext_zfinx = cpu->cfg.ext_zfinx; + ctx->ext_zhinx = cpu->cfg.ext_zhinx; + ctx->ext_zhinxmin = cpu->cfg.ext_zhinxmin; ctx->vlen = cpu->cfg.vlen; ctx->elen = cpu->cfg.elen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); --
Regards,
Bin
PATCH v2 2/6 target/riscv: hardwire mstatus.FS to zero when enable zfinx
In reply to Weiwei LiFrom: liweiwei <[email protected]>
--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu_helper.c | 6 +++++- target/riscv/csr.c | 24 +++++++++++++++++++----- target/riscv/translate.c | 5 +++++ 4 files changed, 33 insertions(+), 6 deletions(-)
target/riscv/cpu.c +4 -0
@@ -363,6 +363,10 @@ static void riscv_cpu_reset(DeviceState *dev) env->misa_mxl = env->misa_mxl_max; env->priv =PRV_M ; env->mstatus &= ~(MSTATUS_MIE |MSTATUS_MPRV ); +/* hardwire mstatus.FS to zero when enable zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + env->mstatus &= ~MSTATUS_FS ; + }if (env->misa_mxl >MXL_RV32 ) {/* * The reset status of SXL/UXL is undefined, but mstatus is WARL
target/riscv/cpu_helper.c +5 -1
@@ -222,9 +222,13 @@ bool riscv_cpu_vector_enabled(CPURISCVState *env)void riscv_cpu_swap_hypervisor_regs (CPURISCVState *env) { -uint64_t mstatus_mask =MSTATUS_MXR |MSTATUS_SUM |MSTATUS_FS | +uint64_t mstatus_mask =MSTATUS_MXR |MSTATUS_SUM |MSTATUS_SPP |MSTATUS_SPIE |MSTATUS_SIE |MSTATUS64_UXL |MSTATUS_VS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + mstatus_mask |=MSTATUS_FS ; + }bool current_virt =riscv_cpu_virt_enabled (env);g_assert (riscv_has_ext (env,RVH ));
target/riscv/csr.c +19 -5
@@ -38,7 +38,8 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops)static RISCVException fs (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY ) -if (!env->debugger && !riscv_cpu_fp_enabled (env)) { +if (!env->debugger && !riscv_cpu_fp_enabled (env) && + !RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) {return RISCV_EXCP_ILLEGAL_INST ; }#endif
@@ -234,7 +235,10 @@ static RISCVException write_fflags(CPURISCVState *env, int csrno, target_ulong val) {#if !defined(CONFIG_USER_ONLY ) - env->mstatus |=MSTATUS_FS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + env->mstatus |=MSTATUS_FS ; + }#endif riscv_cpu_set_fflags (env, val & (FSR_AEXC >>FSR_AEXC_SHIFT ));return RISCV_EXCP_NONE ;
@@ -251,7 +255,10 @@ static RISCVException write_frm(CPURISCVState *env, int csrno, target_ulong val) {#if !defined(CONFIG_USER_ONLY ) - env->mstatus |=MSTATUS_FS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + env->mstatus |=MSTATUS_FS ; + }#endif env->frm = val & (FSR_RD >>FSR_RD_SHIFT );return RISCV_EXCP_NONE ;
@@ -269,7 +276,10 @@ static RISCVException write_fcsr(CPURISCVState *env, int csrno, target_ulong val) {#if !defined(CONFIG_USER_ONLY ) - env->mstatus |=MSTATUS_FS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + env->mstatus |=MSTATUS_FS ; + }#endif env->frm = (val &FSR_RD ) >>FSR_RD_SHIFT ;riscv_cpu_set_fflags (env, (val &FSR_AEXC ) >>FSR_AEXC_SHIFT );
@@ -562,9 +572,13 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,tlb_flush (env_cpu (env)); } mask =MSTATUS_SIE |MSTATUS_SPIE |MSTATUS_MIE |MSTATUS_MPIE | -MSTATUS_SPP |MSTATUS_FS |MSTATUS_MPRV |MSTATUS_SUM | +MSTATUS_SPP |MSTATUS_MPRV |MSTATUS_SUM |MSTATUS_MPP |MSTATUS_MXR |MSTATUS_TVM |MSTATUS_TSR |MSTATUS_TW |MSTATUS_VS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + mask |=MSTATUS_FS ; + }if (riscv_cpu_mxl (env) !=MXL_RV32 ) {/*
target/riscv/translate.c +5 -0
@@ -342,6 +342,11 @@ static void mark_fs_dirty(DisasContext *ctx) {TCGv tmp; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (ctx->ext_zfinx) { +return ; + } +if (ctx->mstatus_fs !=MSTATUS_FS ) {/* Remember the state change for the rest of the TB. */ ctx->mstatus_fs =MSTATUS_FS ;
Signature · 1 line
2.17.1
Re: [PATCH v2 2/6] target/riscv: hardwire mstatus.FS to zero when enable zfinx
target/riscv/cpu.c static void riscv_cpu_reset(DeviceState *dev) · line 369
Quoted 8 lines · Weiwei Li
target/riscv/cpu.c +4
-0@@ -363,6 +363,10 @@ static void riscv_cpu_reset(DeviceState *dev) env->misa_mxl = env->misa_mxl_max; env->priv =PRV_M ; env->mstatus &= ~(MSTATUS_MIE |MSTATUS_MPRV ); +/* hardwire mstatus.FS to zero when enable zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + env->mstatus &= ~MSTATUS_FS ; + }
This shouldn't be necessary because it should never have been set.
target/riscv/cpu_helper.c bool riscv_cpu_vector_enabled(CPURISCVState *env) · line 231
Quoted 8 lines
target/riscv/cpu_helper.c +5
-1-uint64_t mstatus_mask =MSTATUS_MXR |MSTATUS_SUM |MSTATUS_FS | +uint64_t mstatus_mask =MSTATUS_MXR |MSTATUS_SUM |MSTATUS_SPP |MSTATUS_SPIE |MSTATUS_SIE |MSTATUS64_UXL |MSTATUS_VS ; +/* hardwire mstatus.FS to zero when enable zfinx */ +if (!RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + mstatus_mask |=MSTATUS_FS ; + }
I would think it would be more correct to have a positive test for RVF, rather than a negative test for ZFINX?
r~
Re: [PATCH v2 2/6] target/riscv: hardwire mstatus.FS to zero when enable zfinx
Thanks for your comments.
Quoted 11 lines · Richard Henderson
target/riscv/cpu.c static void riscv_cpu_reset(DeviceState *dev) · line 369
Quoted 8 lines · Weiwei Li
target/riscv/cpu.c +4
-0@@ -363,6 +363,10 @@ static void riscv_cpu_reset(DeviceState *dev) env->misa_mxl = env->misa_mxl_max; env->priv = PRV_M; env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV); + /* hardwire mstatus.FS to zero when enable zfinx */ + if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) { + env->mstatus &= ~MSTATUS_FS; + }This shouldn't be necessary because it should never have been set.
Yes, I think so. However, I have a question about MSTATUS_MIE and MSTATUS_MPRV, will they be set before cpu reset?
Quoted 11 lines
Quoted 9 lines
target/riscv/cpu_helper.c +1
-1- uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS | + uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM|
MSTATUS_SPP|MSTATUS_SPIE|MSTATUS_SIE|MSTATUS64_UXL|MSTATUS_VS;
+ /* hardwire mstatus.FS to zero when enable zfinx */
+ if (!RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+mstatus_mask|=MSTATUS_FS;
+ }I would think it would be more correct to have a positive test for RVF, rather than a negative test for ZFINX?
It may deviate from the original value of mstatus_mask with a positive test for RVF.
Quoted 3 lines
r~
Re: [PATCH v2 2/6] target/riscv: hardwire mstatus.FS to zero when enable zfinx
Quoted 2 lines · Weiwei Li
Quoted 1 line
This shouldn't be necessary because it should never have been set.
Yes, I think so. However, I have a question about
MSTATUS_MIEandMSTATUS_MPRV, will they be set before cpu reset?
Yes, via warm reset.
Quoted 2 lines
Quoted 1 line
I would think it would be more correct to have a positive test for RVF, rather than a negative test for ZFINX?
It may deviate from the original value of
mstatus_maskwith a positive test for RVF.
Oh, you mean misa_ext? Hmm. Interesting point.
When F extension is not implemented, FS is either hardwired to zero (without S-mode) or optionally zero. So this looks like an existing bug to be fixed.
r~
Re: [PATCH v2 2/6] target/riscv: hardwire mstatus.FS to zero when enable zfinx
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Weiwei Li
Quoted 1 line
This shouldn't be necessary because it should never have been set.
Yes, I think so. However, I have a question about
MSTATUS_MIEandMSTATUS_MPRV, will they be set before cpu reset?Yes, via warm reset.
Thanks. I'll fix this later.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
I would think it would be more correct to have a positive test for RVF, rather than a negative test for ZFINX?
It may deviate from the original value of
mstatus_maskwith a positive test for RVF.Oh, you mean misa_ext? Hmm. Interesting point.
When F extension is not implemented, FS is either hardwired to zero (without S-mode) or optionally zero. So this looks like an existing bug to be fixed.
OK. There is similar logic in write_mstatus and . I'll fix it too.
I'll also update write_frm, write_fflags and write_fflags to have a positive test for RVF .
Quoted 2 lines
r~
PATCH v2 3/6 target/riscv: add support for zfinx
In reply to Weiwei LiFrom: liweiwei <[email protected]>
- update extension check REQUIRE_ZFINX_OR_F
- update single float point register read/write
- disable nanbox_s check
--- target/riscv/fpu_helper.c | 89 +++---- target/riscv/helper.h | 2 +- target/riscv/insn_trans/trans_rvf.c.inc | 314 ++++++++++++++++-------- target/riscv/internals.h | 16 +- target/riscv/translate.c | 90 +++++++ 5 files changed, 367 insertions(+), 144 deletions(-)
target/riscv/fpu_helper.c +45 -44
@@ -98,10 +98,11 @@ static uint64_t do_fmadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2,static uint64_t do_fmadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2,uint64_t rs3,int flags) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -float32 frs3 =check_nanbox_s (rs3); -return nanbox_s (float32_muladd (frs1, frs2, frs3, flags, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +float32 frs3 =check_nanbox_s (env, rs3); +return nanbox_s (env,float32_muladd (frs1, frs2, frs3, flags, + &env->fp_status)); } uint64_t helper_fmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2,
@@ -183,124 +184,124 @@ uint64_t helper_fnmadd_h(CPURISCVState *env, uint64_t frs1, uint64_t frs2,uint64_t helper_fadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (float32_add (frs1, frs2, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env,float32_add (frs1, frs2, &env->fp_status)); }uint64_t helper_fsub_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (float32_sub (frs1, frs2, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env,float32_sub (frs1, frs2, &env->fp_status)); }uint64_t helper_fmul_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (float32_mul (frs1, frs2, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env,float32_mul (frs1, frs2, &env->fp_status)); }uint64_t helper_fdiv_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (float32_div (frs1, frs2, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env,float32_div (frs1, frs2, &env->fp_status)); }uint64_t helper_fmin_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (env->priv_ver <PRIV_VERSION_1_11_0 ? +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env, env->priv_ver <PRIV_VERSION_1_11_0 ?float32_minnum (frs1, frs2, &env->fp_status) :float32_minimum_number (frs1, frs2, &env->fp_status)); }uint64_t helper_fmax_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); -return nanbox_s (env->priv_ver <PRIV_VERSION_1_11_0 ? +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2); +return nanbox_s (env, env->priv_ver <PRIV_VERSION_1_11_0 ?float32_maxnum (frs1, frs2, &env->fp_status) :float32_maximum_number (frs1, frs2, &env->fp_status)); }uint64_t helper_fsqrt_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); -return nanbox_s (float32_sqrt (frs1, &env->fp_status)); +float32 frs1 =check_nanbox_s (env, rs1); +return nanbox_s (env,float32_sqrt (frs1, &env->fp_status)); }target_ulong helper_fle_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2);return float32_le (frs1, frs2, &env->fp_status); }target_ulong helper_flt_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2);return float32_lt (frs1, frs2, &env->fp_status); }target_ulong helper_feq_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float32 frs1 =check_nanbox_s (rs1); -float32 frs2 =check_nanbox_s (rs2); +float32 frs1 =check_nanbox_s (env, rs1); +float32 frs2 =check_nanbox_s (env, rs2);return float32_eq_quiet (frs1, frs2, &env->fp_status); }target_ulong helper_fcvt_w_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return float32_to_int32 (frs1, &env->fp_status); }target_ulong helper_fcvt_wu_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return (int32_t )float32_to_uint32 (frs1, &env->fp_status); }target_ulong helper_fcvt_l_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return float32_to_int64 (frs1, &env->fp_status); }target_ulong helper_fcvt_lu_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return float32_to_uint64 (frs1, &env->fp_status); }uint64_t helper_fcvt_s_w (CPURISCVState *env,target_ulong rs1) { -return nanbox_s (int32_to_float32 ((int32_t )rs1, &env->fp_status)); +return nanbox_s (env,int32_to_float32 ((int32_t )rs1, &env->fp_status)); }uint64_t helper_fcvt_s_wu (CPURISCVState *env,target_ulong rs1) { -return nanbox_s (uint32_to_float32 ((uint32_t )rs1, &env->fp_status)); +return nanbox_s (env,uint32_to_float32 ((uint32_t )rs1, &env->fp_status)); }uint64_t helper_fcvt_s_l (CPURISCVState *env,target_ulong rs1) { -return nanbox_s (int64_to_float32 (rs1, &env->fp_status)); +return nanbox_s (env,int64_to_float32 (rs1, &env->fp_status)); }uint64_t helper_fcvt_s_lu (CPURISCVState *env,target_ulong rs1) { -return nanbox_s (uint64_to_float32 (rs1, &env->fp_status)); +return nanbox_s (env,uint64_to_float32 (rs1, &env->fp_status)); } -target_ulong helper_fclass_s (uint64_t rs1) +target_ulong helper_fclass_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return fclass_s (frs1); }
@@ -340,12 +341,12 @@ uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)uint64_t helper_fcvt_s_d (CPURISCVState *env,uint64_t rs1) { -return nanbox_s (float64_to_float32 (rs1, &env->fp_status)); +return nanbox_s (env,float64_to_float32 (rs1, &env->fp_status)); }uint64_t helper_fcvt_d_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return float32_to_float64 (frs1, &env->fp_status); }
@@ -539,14 +540,14 @@ uint64_t helper_fcvt_h_lu(CPURISCVState *env, target_ulong rs1)uint64_t helper_fcvt_h_s (CPURISCVState *env,uint64_t rs1) { -float32 frs1 =check_nanbox_s (rs1); +float32 frs1 =check_nanbox_s (env, rs1);return nanbox_h (float32_to_float16 (frs1, true, &env->fp_status)); }uint64_t helper_fcvt_s_h (CPURISCVState *env,uint64_t rs1) {float16 frs1 =check_nanbox_h (rs1); -return nanbox_s (float16_to_float32 (frs1, true, &env->fp_status)); +return nanbox_s (env,float16_to_float32 (frs1, true, &env->fp_status)); }uint64_t helper_fcvt_h_d (CPURISCVState *env,uint64_t rs1)
target/riscv/helper.h +1 -1
@@ -38,7 +38,7 @@ DEF_HELPER_FLAGS_2(fcvt_s_w, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl) -DEF_HELPER_FLAGS_1 (fclass_s,TCG_CALL_NO_RWG_SE , tl, i64) +DEF_HELPER_FLAGS_2 (fclass_s,TCG_CALL_NO_RWG_SE , tl, env, i64) /* Floating Point - Double Precision */DEF_HELPER_FLAGS_3 (fadd_d,TCG_CALL_NO_RWG , i64, env, i64, i64)
target/riscv/insn_trans/trans_rvf.c.inc +218 -96
589 lines not on this page · raw message
target/riscv/internals.h +13 -3
@@ -46,13 +46,23 @@ enum { RISCV_FRM_ROD = 8, /* Round to Odd */ }; -static inline uint64_t nanbox_s (float32 f) +static inline uint64_t nanbox_s (CPURISCVState *env,float32 f) { -return f |MAKE_64BIT_MASK (32 ,32 ); +/* the value is sign-extended instead of NaN-boxing for zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { +return (int32_t )f; + }else { +return f |MAKE_64BIT_MASK (32 ,32 ); + } } -static inline float32 check_nanbox_s (uint64_t f) +static inline float32 check_nanbox_s (CPURISCVState *env,uint64_t f) { +/* Disable NaN-boxing check when enable zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { +return (uint32_t )f; + } +uint64_t mask =MAKE_64BIT_MASK (32 ,32 );if (likely ((f & mask) == mask)) {
target/riscv/translate.c +90 -0
118 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 3/6] target/riscv: add support for zfinx
Quoted 9 lines · Weiwei Li
From: liweiwei<[email protected]>
- update extension check
REQUIRE_ZFINX_OR_F
- update single float point register read/write
- disablenanbox_scheckCo-authored-by ardxwe<[email protected]>Signed-off-by Weiwei Li<[email protected]>Signed-off-by Junqiang Wang<[email protected]>
Quoted 7 lines
--- target/riscv/fpu_helper.c | 89 +++---- target/riscv/helper.h | 2 +- target/riscv/insn_trans/trans_rvf.c.inc | 314 ++++++++++++++++-------- target/riscv/internals.h | 16 +- target/riscv/translate.c | 90 +++++++ 5 files changed, 367 insertions(+), 144 deletions(-)
r~
Re: [PATCH v2 3/6] target/riscv: add support for zfinx
In reply to Weiwei Litarget/riscv/translate.c static void gen_set_gpr(DisasContext *ctx, int reg_num, TCGv t) · line 364
Quoted 2 lines · Weiwei Li
target/riscv/translate.c +2
-0+if (reg_num !=0 ) { +switch (get_ol (ctx)) {
Oh, you should be using get_xl here and elsewhere in this patch, not get_ol.
r~
Re: [PATCH v2 3/6] target/riscv: add support for zfinx
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Weiwei Li
+ if (
reg_num!= 0) {
+ switch (get_ol(ctx)) {Oh, you should be using
get_xlhere and elsewhere in this patch, notget_ol.
Sorry. I don't know the difference between get_xl and get_ol. From gpr register read/write function, It seems get_ol is used in register read, and get_xl is used in register write.
However, "ctx->ol= ctx->xl;" is executed before translate instruction.
"
Quoted 3 lines
r~
Re: [PATCH v2 3/6] target/riscv: add support for zfinx
Quoted 10 lines · Weiwei Li
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Weiwei Li
+ if (
reg_num!= 0) {
+ switch (get_ol(ctx)) {Oh, you should be using
get_xlhere and elsewhere in this patch, notget_ol.Sorry. I don't know the difference between
get_xlandget_ol. From gpr register read/write function, It seemsget_olis used in register read, andget_xlis used in register write.However, "ctx->ol=
ctx->xl;" is executed before translate instruction.
ol is the operation length; xl is the register length.
In this case, the operation length doesn't matter -- we're interested in distinguishing RV32 and RV64, because that's where the change in semantics comes from.
r~
Re: [PATCH v2 3/6] target/riscv: add support for zfinx
Quoted 4 lines · Richard Henderson
ol is the operation length; xl is the register length.
In this case, the operation length doesn't matter -- we're interested in distinguishing RV32 and RV64, because that's where the change in semantics comes from.
So both read and write fpr should use get_xl from this point.
Quoted 2 lines
r~
PATCH v2 4/6 target/riscv: add support for zdinx
In reply to Weiwei LiFrom: liweiwei <[email protected]>
-- update extension check REQUIRE_ZDINX_OR_D -- update double float point register read/write
--- target/riscv/insn_trans/trans_rvd.c.inc | 319 ++++++++++++++++++------ target/riscv/translate.c | 58 +++++ 2 files changed, 299 insertions(+), 78 deletions(-)
target/riscv/insn_trans/trans_rvd.c.inc +241 -78
@@ -18,6 +18,19 @@ * this program. If not, see <http://www.gnu.org/licenses/>. */ +#define REQUIRE_ZDINX_OR_D(ctx) do { \ + if (!ctx->ext_zdinx) { \ + REQUIRE_EXT(ctx, RVD); \ + } \ +} while (0) + +#define REQUIRE_EVEN(ctx, reg) do { \ + if (ctx->ext_zdinx && (get_xl(ctx) == MXL_RV32) && \ + (reg & 0x1)) { \ + return false; \ + } \ +} while (0) + static bool trans_fld(DisasContext *ctx, arg_fld *a) { TCGv addr;
@@ -62,10 +75,20 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) static bool trans_fmadd_d(DisasContext *ctx, arg_fmadd_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + REQUIRE_EVEN(ctx, a->rs3); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + TCGv_i64 src3 = get_fpr_d(ctx, a->rs3); + gen_set_rm(ctx, a->rm); - gen_helper_fmadd_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], - cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + gen_helper_fmadd_d(dest, cpu_env, src1, src2, src3); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -73,10 +96,20 @@ static bool trans_fmadd_d(DisasContext *ctx, arg_fmadd_d *a) static bool trans_fmsub_d(DisasContext *ctx, arg_fmsub_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + REQUIRE_EVEN(ctx, a->rs3); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + TCGv_i64 src3 = get_fpr_d(ctx, a->rs3); + gen_set_rm(ctx, a->rm); - gen_helper_fmsub_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], - cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + gen_helper_fmsub_d(dest, cpu_env, src1, src2, src3); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -84,10 +117,20 @@ static bool trans_fmsub_d(DisasContext *ctx, arg_fmsub_d *a) static bool trans_fnmsub_d(DisasContext *ctx, arg_fnmsub_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + REQUIRE_EVEN(ctx, a->rs3); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + TCGv_i64 src3 = get_fpr_d(ctx, a->rs3); + gen_set_rm(ctx, a->rm); - gen_helper_fnmsub_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], - cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + gen_helper_fnmsub_d(dest, cpu_env, src1, src2, src3); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -95,10 +138,20 @@ static bool trans_fnmsub_d(DisasContext *ctx, arg_fnmsub_d *a) static bool trans_fnmadd_d(DisasContext *ctx, arg_fnmadd_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + REQUIRE_EVEN(ctx, a->rs3); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + TCGv_i64 src3 = get_fpr_d(ctx, a->rs3); + gen_set_rm(ctx, a->rm); - gen_helper_fnmadd_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], - cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + gen_helper_fnmadd_d(dest, cpu_env, src1, src2, src3); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -106,12 +159,18 @@ static bool trans_fnmadd_d(DisasContext *ctx, arg_fnmadd_d *a) static bool trans_fadd_d(DisasContext *ctx, arg_fadd_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_set_rm(ctx, a->rm); - gen_helper_fadd_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_set_rm(ctx, a->rm); + gen_helper_fadd_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -119,12 +178,18 @@ static bool trans_fadd_d(DisasContext *ctx, arg_fadd_d *a) static bool trans_fsub_d(DisasContext *ctx, arg_fsub_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_set_rm(ctx, a->rm); - gen_helper_fsub_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_set_rm(ctx, a->rm); + gen_helper_fsub_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -132,12 +197,18 @@ static bool trans_fsub_d(DisasContext *ctx, arg_fsub_d *a) static bool trans_fmul_d(DisasContext *ctx, arg_fmul_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_set_rm(ctx, a->rm); - gen_helper_fmul_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_set_rm(ctx, a->rm); + gen_helper_fmul_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -145,12 +216,18 @@ static bool trans_fmul_d(DisasContext *ctx, arg_fmul_d *a) static bool trans_fdiv_d(DisasContext *ctx, arg_fdiv_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_set_rm(ctx, a->rm); - gen_helper_fdiv_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_set_rm(ctx, a->rm); + gen_helper_fdiv_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -158,23 +235,37 @@ static bool trans_fdiv_d(DisasContext *ctx, arg_fdiv_d *a) static bool trans_fsqrt_d(DisasContext *ctx, arg_fsqrt_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); - gen_set_rm(ctx, a->rm); - gen_helper_fsqrt_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + gen_set_rm(ctx, a->rm); + gen_helper_fsqrt_d(dest, cpu_env, src1); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; } static bool trans_fsgnj_d(DisasContext *ctx, arg_fsgnj_d *a) { + REQUIRE_FPU; + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); if (a->rs1 == a->rs2) { /* FMOV */ - tcg_gen_mov_i64(cpu_fpr[a->rd], cpu_fpr[a->rs1]); + dest = get_fpr_d(ctx, a->rs1); } else { - tcg_gen_deposit_i64(cpu_fpr[a->rd], cpu_fpr[a->rs2], - cpu_fpr[a->rs1], 0, 63); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + tcg_gen_deposit_i64(dest, src2, src1, 0, 63); } + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -182,15 +273,24 @@ static bool trans_fsgnj_d(DisasContext *ctx, arg_fsgnj_d *a) static bool trans_fsgnjn_d(DisasContext *ctx, arg_fsgnjn_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + if (a->rs1 == a->rs2) { /* FNEG */ - tcg_gen_xori_i64(cpu_fpr[a->rd], cpu_fpr[a->rs1], INT64_MIN); + tcg_gen_xori_i64(dest, src1, INT64_MIN); } else { + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); TCGv_i64 t0 = tcg_temp_new_i64(); - tcg_gen_not_i64(t0, cpu_fpr[a->rs2]); - tcg_gen_deposit_i64(cpu_fpr[a->rd], t0, cpu_fpr[a->rs1], 0, 63); + tcg_gen_not_i64(t0, src2); + tcg_gen_deposit_i64(dest, t0, src1, 0, 63); tcg_temp_free_i64(t0); } + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -198,15 +298,24 @@ static bool trans_fsgnjn_d(DisasContext *ctx, arg_fsgnjn_d *a) static bool trans_fsgnjx_d(DisasContext *ctx, arg_fsgnjx_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); + + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + if (a->rs1 == a->rs2) { /* FABS */ - tcg_gen_andi_i64(cpu_fpr[a->rd], cpu_fpr[a->rs1], ~INT64_MIN); + tcg_gen_andi_i64(dest, src1, ~INT64_MIN); } else { + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); TCGv_i64 t0 = tcg_temp_new_i64(); - tcg_gen_andi_i64(t0, cpu_fpr[a->rs2], INT64_MIN); - tcg_gen_xor_i64(cpu_fpr[a->rd], cpu_fpr[a->rs1], t0); + tcg_gen_andi_i64(t0, src2, INT64_MIN); + tcg_gen_xor_i64(dest, src1, t0); tcg_temp_free_i64(t0); } + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -214,11 +323,17 @@ static bool trans_fsgnjx_d(DisasContext *ctx, arg_fsgnjx_d *a) static bool trans_fmin_d(DisasContext *ctx, arg_fmin_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_helper_fmin_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_helper_fmin_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -226,11 +341,17 @@ static bool trans_fmin_d(DisasContext *ctx, arg_fmin_d *a) static bool trans_fmax_d(DisasContext *ctx, arg_fmax_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); - gen_helper_fmax_d(cpu_fpr[a->rd], cpu_env, - cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); + gen_helper_fmax_d(dest, cpu_env, src1, src2); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -238,11 +359,15 @@ static bool trans_fmax_d(DisasContext *ctx, arg_fmax_d *a) static bool trans_fcvt_s_d(DisasContext *ctx, arg_fcvt_s_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); - gen_set_rm(ctx, a->rm); - gen_helper_fcvt_s_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_s_d(dest, cpu_env, src1); + gen_set_fpr_hs(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -250,11 +375,15 @@ static bool trans_fcvt_s_d(DisasContext *ctx, arg_fcvt_s_d *a) static bool trans_fcvt_d_s(DisasContext *ctx, arg_fcvt_d_s *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); - gen_set_rm(ctx, a->rm); - gen_helper_fcvt_d_s(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + TCGv_i64 dest = dest_fpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1); + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_d_s(dest, cpu_env, src1); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true; }
@@ -262,11 +391,15 @@ static bool trans_fcvt_d_s(DisasContext *ctx, arg_fcvt_d_s *a) static bool trans_feq_d(DisasContext *ctx, arg_feq_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); - gen_helper_feq_d(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_helper_feq_d(dest, cpu_env, src1, src2); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -274,11 +407,15 @@ static bool trans_feq_d(DisasContext *ctx, arg_feq_d *a) static bool trans_flt_d(DisasContext *ctx, arg_flt_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); - gen_helper_flt_d(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_helper_flt_d(dest, cpu_env, src1, src2); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -286,11 +423,15 @@ static bool trans_flt_d(DisasContext *ctx, arg_flt_d *a) static bool trans_fle_d(DisasContext *ctx, arg_fle_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); + REQUIRE_EVEN(ctx, a->rs2); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); + TCGv_i64 src2 = get_fpr_d(ctx, a->rs2); - gen_helper_fle_d(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_helper_fle_d(dest, cpu_env, src1, src2); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -298,11 +439,13 @@ static bool trans_fle_d(DisasContext *ctx, arg_fle_d *a) static bool trans_fclass_d(DisasContext *ctx, arg_fclass_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); - gen_helper_fclass_d(dest, cpu_fpr[a->rs1]); + gen_helper_fclass_d(dest, src1); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -310,12 +453,14 @@ static bool trans_fclass_d(DisasContext *ctx, arg_fclass_d *a) static bool trans_fcvt_w_d(DisasContext *ctx, arg_fcvt_w_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_w_d(dest, cpu_env, cpu_fpr[a->rs1]); + gen_helper_fcvt_w_d(dest, cpu_env, src1); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -323,12 +468,14 @@ static bool trans_fcvt_w_d(DisasContext *ctx, arg_fcvt_w_d *a) static bool trans_fcvt_wu_d(DisasContext *ctx, arg_fcvt_wu_d *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_wu_d(dest, cpu_env, cpu_fpr[a->rs1]); + gen_helper_fcvt_wu_d(dest, cpu_env, src1); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -336,12 +483,15 @@ static bool trans_fcvt_wu_d(DisasContext *ctx, arg_fcvt_wu_d *a) static bool trans_fcvt_d_w(DisasContext *ctx, arg_fcvt_d_w *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv src = get_gpr(ctx, a->rs1, EXT_SIGN); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_d_w(cpu_fpr[a->rd], cpu_env, src); + gen_helper_fcvt_d_w(dest, cpu_env, src); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true;
@@ -350,12 +500,15 @@ static bool trans_fcvt_d_w(DisasContext *ctx, arg_fcvt_d_w *a) static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a) { REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv src = get_gpr(ctx, a->rs1, EXT_ZERO); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_d_wu(cpu_fpr[a->rd], cpu_env, src); + gen_helper_fcvt_d_wu(dest, cpu_env, src); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true;
@@ -365,12 +518,14 @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a) { REQUIRE_64BIT(ctx); REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_l_d(dest, cpu_env, cpu_fpr[a->rs1]); + gen_helper_fcvt_l_d(dest, cpu_env, src1); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -379,12 +534,14 @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a) { REQUIRE_64BIT(ctx); REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rs1); TCGv dest = dest_gpr(ctx, a->rd); + TCGv_i64 src1 = get_fpr_d(ctx, a->rs1); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_lu_d(dest, cpu_env, cpu_fpr[a->rs1]); + gen_helper_fcvt_lu_d(dest, cpu_env, src1); gen_set_gpr(ctx, a->rd, dest); return true; }
@@ -407,12 +564,15 @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a) { REQUIRE_64BIT(ctx); REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv src = get_gpr(ctx, a->rs1, EXT_SIGN); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_d_l(cpu_fpr[a->rd], cpu_env, src); + gen_helper_fcvt_d_l(dest, cpu_env, src); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true;
@@ -422,12 +582,15 @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a) { REQUIRE_64BIT(ctx); REQUIRE_FPU; - REQUIRE_EXT(ctx, RVD); + REQUIRE_ZDINX_OR_D(ctx); + REQUIRE_EVEN(ctx, a->rd); + TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv src = get_gpr(ctx, a->rs1, EXT_ZERO); gen_set_rm(ctx, a->rm); - gen_helper_fcvt_d_lu(cpu_fpr[a->rd], cpu_env, src); + gen_helper_fcvt_d_lu(dest, cpu_env, src); + gen_set_fpr_d(ctx, a->rd, dest); mark_fs_dirty(ctx); return true;
target/riscv/translate.c +58 -0
70 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 4/6] target/riscv: add support for zdinx
target/riscv/translate.c static void gen_set_fpr_hs(DisasContext *ctx, int reg_num, TCGv_i64 t) · line 420
Quoted 2 lines · Weiwei Li
target/riscv/translate.c +2
-0+if (reg_num !=0 ) { +switch (get_ol (ctx)) {
get_xl, not get_ol, two instances.
target/riscv/translate.c static TCGv_i64 get_fpr_hs(DisasContext *ctx, int reg_num) · line 356
Quoted 12 lines
target/riscv/translate.c +12
-0+#ifdef TARGET_RISCV32 + { +TCGv_i64 t =ftemp_new (ctx); +tcg_gen_concat_i32_i64 (t, cpu_gpr[reg_num], cpu_gpr[reg_num +1 ]); +return t; + } +#else + { +TCGv_i64 t =ftemp_new (ctx); +tcg_gen_deposit_i64 (t, cpu_gpr[reg_num], cpu_gpr[reg_num +1 ],32 ,32 ); +return t; + }
Unify these two cases and use tcg_gen_concat_tl_i64.
r~
Re: [PATCH v2 4/6] target/riscv: add support for zdinx
Quoted 7 lines · Richard Henderson
Quoted 2 lines · Weiwei Li
+ if (
reg_num!= 0) {
+ switch (get_ol(ctx)) {
get_xl, notget_ol, two instances.
Quoted 16 lines
Quoted 11 lines
target/riscv/translate.c +11
-0+#ifdef TARGET_RISCV32 + { + TCGv_i64 t = ftemp_new(ctx); + tcg_gen_concat_i32_i64(t, cpu_gpr[reg_num], cpu_gpr[reg_num + 1]); + return t; + } +#else + { + TCGv_i64 t = ftemp_new(ctx); + tcg_gen_deposit_i64(t, cpu_gpr[reg_num], cpu_gpr[reg_num +Quoted 3 lines
1], 32, 32);
+ return t;
+ }Unify these two cases and use
tcg_gen_concat_tl_i64.
OK. I'll fix this.
Quoted 3 lines
r~
PATCH v2 5/6 target/riscv: add support for zhinx/zhinxmin
In reply to Weiwei LiFrom: liweiwei <[email protected]>
- update extension check REQUIRE_ZHINX_OR_ZFH and REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN
- update half float point register read/write
- disable nanbox_h check
--- target/riscv/fpu_helper.c | 89 +++--- target/riscv/helper.h | 2 +- target/riscv/insn_trans/trans_rvzfh.c.inc | 332 +++++++++++++++------- target/riscv/internals.h | 16 +- 4 files changed, 296 insertions(+), 143 deletions(-)
target/riscv/fpu_helper.c +45 -44
@@ -89,10 +89,11 @@ void helper_set_rod_rounding_mode(CPURISCVState *env)static uint64_t do_fmadd_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2,uint64_t rs3,int flags) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -float16 frs3 =check_nanbox_h (rs3); -return nanbox_h (float16_muladd (frs1, frs2, frs3, flags, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +float16 frs3 =check_nanbox_h (env, rs3); +return nanbox_h (env,float16_muladd (frs1, frs2, frs3, flags, + &env->fp_status)); } static uint64_t do_fmadd_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2,
@@ -417,146 +418,146 @@ target_ulong helper_fclass_d(uint64_t frs1)uint64_t helper_fadd_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (float16_add (frs1, frs2, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env,float16_add (frs1, frs2, &env->fp_status)); }uint64_t helper_fsub_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (float16_sub (frs1, frs2, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env,float16_sub (frs1, frs2, &env->fp_status)); }uint64_t helper_fmul_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (float16_mul (frs1, frs2, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env,float16_mul (frs1, frs2, &env->fp_status)); }uint64_t helper_fdiv_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (float16_div (frs1, frs2, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env,float16_div (frs1, frs2, &env->fp_status)); }uint64_t helper_fmin_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (env->priv_ver <PRIV_VERSION_1_11_0 ? +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env, env->priv_ver <PRIV_VERSION_1_11_0 ?float16_minnum (frs1, frs2, &env->fp_status) :float16_minimum_number (frs1, frs2, &env->fp_status)); }uint64_t helper_fmax_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); -return nanbox_h (env->priv_ver <PRIV_VERSION_1_11_0 ? +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2); +return nanbox_h (env, env->priv_ver <PRIV_VERSION_1_11_0 ?float16_maxnum (frs1, frs2, &env->fp_status) :float16_maximum_number (frs1, frs2, &env->fp_status)); }uint64_t helper_fsqrt_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); -return nanbox_h (float16_sqrt (frs1, &env->fp_status)); +float16 frs1 =check_nanbox_h (env, rs1); +return nanbox_h (env,float16_sqrt (frs1, &env->fp_status)); }target_ulong helper_fle_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2);return float16_le (frs1, frs2, &env->fp_status); }target_ulong helper_flt_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2);return float16_lt (frs1, frs2, &env->fp_status); }target_ulong helper_feq_h (CPURISCVState *env,uint64_t rs1,uint64_t rs2) { -float16 frs1 =check_nanbox_h (rs1); -float16 frs2 =check_nanbox_h (rs2); +float16 frs1 =check_nanbox_h (env, rs1); +float16 frs2 =check_nanbox_h (env, rs2);return float16_eq_quiet (frs1, frs2, &env->fp_status); } -target_ulong helper_fclass_h (uint64_t rs1) +target_ulong helper_fclass_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return fclass_h (frs1); }target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return float16_to_int32 (frs1, &env->fp_status); }target_ulong helper_fcvt_wu_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return (int32_t )float16_to_uint32 (frs1, &env->fp_status); }target_ulong helper_fcvt_l_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return float16_to_int64 (frs1, &env->fp_status); }target_ulong helper_fcvt_lu_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return float16_to_uint64 (frs1, &env->fp_status); }uint64_t helper_fcvt_h_w (CPURISCVState *env,target_ulong rs1) { -return nanbox_h (int32_to_float16 ((int32_t )rs1, &env->fp_status)); +return nanbox_h (env,int32_to_float16 ((int32_t )rs1, &env->fp_status)); }uint64_t helper_fcvt_h_wu (CPURISCVState *env,target_ulong rs1) { -return nanbox_h (uint32_to_float16 ((uint32_t )rs1, &env->fp_status)); +return nanbox_h (env,uint32_to_float16 ((uint32_t )rs1, &env->fp_status)); }uint64_t helper_fcvt_h_l (CPURISCVState *env,target_ulong rs1) { -return nanbox_h (int64_to_float16 (rs1, &env->fp_status)); +return nanbox_h (env,int64_to_float16 (rs1, &env->fp_status)); }uint64_t helper_fcvt_h_lu (CPURISCVState *env,target_ulong rs1) { -return nanbox_h (uint64_to_float16 (rs1, &env->fp_status)); +return nanbox_h (env,uint64_to_float16 (rs1, &env->fp_status)); }uint64_t helper_fcvt_h_s (CPURISCVState *env,uint64_t rs1) {float32 frs1 =check_nanbox_s (env, rs1); -return nanbox_h (float32_to_float16 (frs1, true, &env->fp_status)); +return nanbox_h (env,float32_to_float16 (frs1, true, &env->fp_status)); }uint64_t helper_fcvt_s_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return nanbox_s (env,float16_to_float32 (frs1, true, &env->fp_status)); }uint64_t helper_fcvt_h_d (CPURISCVState *env,uint64_t rs1) { -return nanbox_h (float64_to_float16 (rs1, true, &env->fp_status)); +return nanbox_h (env,float64_to_float16 (rs1, true, &env->fp_status)); }uint64_t helper_fcvt_d_h (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (rs1); +float16 frs1 =check_nanbox_h (env, rs1);return float16_to_float64 (frs1, true, &env->fp_status); }
target/riscv/helper.h +1 -1
@@ -90,7 +90,7 @@ DEF_HELPER_FLAGS_2(fcvt_h_w, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_h_wu, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_h_l, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_h_lu, TCG_CALL_NO_RWG, i64, env, tl) -DEF_HELPER_FLAGS_1 (fclass_h,TCG_CALL_NO_RWG_SE , tl, i64) +DEF_HELPER_FLAGS_2 (fclass_h,TCG_CALL_NO_RWG_SE , tl, env, i64) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn_trans/trans_rvzfh.c.inc +237 -95
633 lines not on this page · raw message
target/riscv/internals.h +13 -3
@@ -72,13 +72,23 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f) } } -static inline uint64_t nanbox_h (float16 f) +static inline uint64_t nanbox_h (CPURISCVState *env,float16 f) { -return f |MAKE_64BIT_MASK (16 ,48 ); +/* the value is sign-extended instead of NaN-boxing for zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { +return (int16_t )f; + }else { +return f |MAKE_64BIT_MASK (16 ,48 ); + } } -static inline float16 check_nanbox_h (uint64_t f) +static inline float16 check_nanbox_h (CPURISCVState *env,uint64_t f) { +/* Disable nanbox check when enable zfinx */ +if (RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { +return (uint16_t )f; + } +uint64_t mask =MAKE_64BIT_MASK (16 ,48 );if (likely ((f & mask) == mask)) {
Signature · 1 line
2.17.1
Re: [PATCH v2 5/6] target/riscv: add support for zhinx/zhinxmin
Quoted 6 lines · Weiwei Li
From: liweiwei<[email protected]>
- update extension check
REQUIRE_ZHINX_OR_ZFHandREQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN
- update half float point register read/write
- disablenanbox_hcheck
Quoted 8 lines
Signed-off-by Weiwei Li<[email protected]>Signed-off-by Junqiang Wang<[email protected]>--- target/riscv/fpu_helper.c | 89 +++--- target/riscv/helper.h | 2 +- target/riscv/insn_trans/trans_rvzfh.c.inc | 332 +++++++++++++++------- target/riscv/internals.h | 16 +- 4 files changed, 296 insertions(+), 143 deletions(-)
r~
PATCH v2 6/6 target/riscv: expose zfinx, zdinx, zhinx{min} properties
In reply to Weiwei LiFrom: liweiwei <[email protected]>
--- target/riscv/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
target/riscv/cpu.c +4 -0
@@ -661,6 +661,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("zbb" ,RISCVCPU , cfg.ext_zbb, true),DEFINE_PROP_BOOL ("zbc" ,RISCVCPU , cfg.ext_zbc, true),DEFINE_PROP_BOOL ("zbs" ,RISCVCPU , cfg.ext_zbs, true), +DEFINE_PROP_BOOL ("Zdinx" ,RISCVCPU , cfg.ext_zdinx, false), +DEFINE_PROP_BOOL ("Zfinx" ,RISCVCPU , cfg.ext_zfinx, false), +DEFINE_PROP_BOOL ("Zhinx" ,RISCVCPU , cfg.ext_zhinx, false), +DEFINE_PROP_BOOL ("Zhinxmin" ,RISCVCPU , cfg.ext_zhinxmin, false),DEFINE_PROP_BOOL ("x-h" ,RISCVCPU , cfg.ext_h, false), DEFINE_PROP_BOOL("x-j", RISCVCPU, cfg.ext_j, false),/* ePMP 0.9.3 */
Signature · 1 line
2.17.1