target/riscv: support Zfh, Zfhmin extension v0.1
v3 cover target/riscv: support Zfh, Zfhmin extension v0.1
From: Frank Chang <[email protected]>
Zfh - Half width floating point
Zfhmin - Subset of half width floating point
Zfh, Zfhmin v0.1 is now in public review period and is required by RVV extension:
https://groups.google.com/a/groups.riscv.org/g/isa-dev/c/63gDCinXTwE/m/871Wm9XIBQAJ
Zfh, Zfhmin can be enabled with -cpu option: Zfh=true and Zfhmin=true respectively.
The port is available at:
https://github.com/sifive/qemu/tree/zfh-upstream-v3
Note: This patchset depends on another patchset listed in Based-on
section below so it is not able to be built unless the patchset is applied.
Changelog:
v3:
* Use the renamed softfloat min/max APIs: *_minimum_number()
and *_maximum_number().
* Pick softfloat min/max APIs based on CPU privilege spec version.
* Add braces for if statements in REQUIRE_ZFH() and REQUIRE_ZFH_OR_ZFHMIN().
* Rearrange the positions of Zfh and Zfhmin cpu properties.
v2:
* Use {get,dest}_gpr APIs.
* Add Zfhmin extension.
Based-on: <[email protected]>
Frank Chang (1):
target/riscv: zfh: implement zfhmin extension
Kito Cheng (5):
target/riscv: zfh: half-precision load and store target/riscv: zfh: half-precision computational target/riscv: zfh: half-precision convert and move target/riscv: zfh: half-precision floating-point compare target/riscv: zfh: half-precision floating-point classify
target/riscv/cpu.c | 2 + target/riscv/cpu.h | 2 + target/riscv/fpu_helper.c | 180 ++++++++ target/riscv/helper.h | 29 ++ target/riscv/insn32.decode | 38 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 537 ++++++++++++++++++++++ target/riscv/internals.h | 16 + target/riscv/translate.c | 20 + 8 files changed, 824 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzfh.c.inc
--
2.25.1
PATCH v3 1/6 target/riscv: zfh: half-precision load and store
From: Kito Cheng <[email protected]>
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 65 +++++++++++++++++++++++ target/riscv/translate.c | 8 +++ 5 files changed, 79 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzfh.c.inc
target/riscv/cpu.c +1 -0
@@ -601,6 +601,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
target/riscv/cpu.h +1 -0
@@ -297,6 +297,7 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zfh;char *priv_spec;char *user_spec;
target/riscv/insn32.decode +4 -0
@@ -726,3 +726,7 @@ binv 0110100 .......... 001 ..... 0110011 @r binvi 01101. ........... 001 ..... 0010011 @sh bset 0010100 .......... 001 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh + +# *** RV32 Zfh Extension *** +flh ............ ..... 001 ..... 0000111 @i +fsh ....... ..... ..... 001 ..... 0100111 @s
target/riscv/insn_trans/trans_rvzfh.c.inc new file +65 -0
65 lines not on this page · raw message
target/riscv/translate.c +8 -0
@@ -69,6 +69,7 @@ typedef struct DisasContext {bool w;bool virt_enabled;bool ext_ifencei; +bool ext_zfh;bool hlsx;/* vector extension */ bool vill;
@@ -118,6 +119,11 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (32 ,32 )); } +static void gen_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (16 ,48 )); +} +/* * A narrow n-bit operation, where n < FLEN, checks that input operands * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1.
@@ -489,6 +495,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" /* Include the auto-generated decoder for 16 bit insn */
@@ -541,6 +548,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa = env->misa; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; + ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX );
Signature · 1 line
2.25.1
Re: [PATCH v3 1/6] target/riscv: zfh: half-precision load and store
Quoted 21 lines · On Sat, Oct 16, 2021 at 7:08 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 65 +++++++++++++++++++++++ target/riscv/translate.c | 8 +++ 5 files changed, 79 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzfh.c.inctarget/riscv/cpu.c +0
-0
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 604
Quoted 4 lines
target/riscv/cpu.c +1
-0@@ -601,6 +601,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), + DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false),
This change should be after patch 5. The idea is that we add the functionality and then allow users to enable it.
Otherwise:
Alistair
Quoted 142 lines
target/riscv/cpu.c +0
-0DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),target/riscv/cpu.h +1
-0@@ -297,6 +297,7 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zfh;char *priv_spec;char *user_spec;target/riscv/insn32.decode +4
-0@@ -726,3 +726,7 @@ binv 0110100 .......... 001 ..... 0110011 @r binvi 01101. ........... 001 ..... 0010011 @sh bset 0010100 .......... 001 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh + +# *** RV32 Zfh Extension *** +flh ............ ..... 001 ..... 0000111 @i +fsh ....... ..... ..... 001 ..... 0100111 @starget/riscv/insn_trans/trans_rvzfh.c.inc new file +65
-0@@ -0,0 +1,65 @@ +/* + * RISC-V translation routines for the RV64Zfh Standard Extension. + * + * Copyright (c) 2020 Chih-Min Chao, [email protected] + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZFH(ctx) do { \ + if (!ctx->ext_zfh) { \ + return false; \ + } \ +} while (0) + +static bool trans_flh(DisasContext *ctx, arg_flh *a) +{ + TCGv_i64 dest; + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = temp_new(ctx); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + dest = cpu_fpr[a->rd]; + tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, MO_TEUW); + gen_nanbox_h(dest, dest); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsh(DisasContext *ctx, arg_fsh *a) +{ + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = tcg_temp_new(); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEUW); + + return true; +}target/riscv/translate.c +8
-1@@ -69,6 +69,7 @@ typedef struct DisasContext {bool w;bool virt_enabled;bool ext_ifencei; +bool ext_zfh;bool hlsx;/* vector extension */ bool vill;@@ -118,6 +119,11 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (32 ,32 )); } +static void gen_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (16 ,48 )); +} +/* * A narrow n-bit operation, where n < FLEN, checks that input operands * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1. @@ -489,6 +495,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" /* Include the auto-generated decoder for 16 bit insn */ @@ -541,6 +548,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa = env->misa; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; + ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX ); --2.25.1
Re: [PATCH v3 1/6] target/riscv: zfh: half-precision load and store
Quoted 30 lines · Alistair Francis
Quoted 21 lines · On Sat, Oct 16, 2021 at 7:08 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 65 +++++++++++++++++++++++ target/riscv/translate.c | 8 +++ 5 files changed, 79 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzfh.c.inctarget/riscv/cpu.c +0
-0target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 604
Quoted 4 lines
target/riscv/cpu.c +1
-0@@ -601,6 +601,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), + DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false),This change should be after patch 5. The idea is that we add the functionality and then allow users to enable it.
Quoted 6 lines
Otherwise:
Reviewed-by Alistair Francis <[email protected]>Alistair
The reason why I put here is because REQUIRE_ZFH() uses ctx->zfh. I can separate ext_zfh field in DisasContext into this patch, and add cfg.ext_zfh in RISCVCPU after patch 5 in my next patchset.
Thanks,
Frank Chang
Quoted 151 lines
Review
Quoted 29 lines
target/riscv/cpu.c +0
-0DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),target/riscv/cpu.h +1
-0@@ -297,6 +297,7 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zfh;char *priv_spec;char *user_spec;target/riscv/insn32.decode +4
-0@@ -726,3 +726,7 @@ binv 0110100 .......... 001 ..... 0110011 @r binvi 01101. ........... 001 ..... 0010011 @sh bset 0010100 .......... 001 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh + +# *** RV32 Zfh Extension *** +flh ............ ..... 001 ..... 0000111 @i +fsh ....... ..... ..... 001 ..... 0100111 @s(quoted diff) +0
-0b/target/riscv/insn_trans/trans_rvzfh.c.inc
target/riscv/insn_trans/trans_rvzfh.c.inc line 6
Quoted 11 lines
new file mode 100644
index 00000000000..dad1d703d72target/riscv/insn_trans/trans_rvzfh.c.inc new file +6
-0@@ -0,0 +1,65 @@ +/* + * RISC-V translation routines for the RV64Zfh Standard Extension. + * + * Copyright (c) 2020 Chih-Min Chao, [email protected] + * + * This program is free software; you can redistribute it and/or modifyit
target/riscv/insn_trans/trans_rvzfh.c.inc
Quoted 4 lines
target/riscv/insn_trans/trans_rvzfh.c.inc new file +4
-0+ * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, butWITHOUT
target/riscv/insn_trans/trans_rvzfh.c.inc line 12
Quoted 2 lines
target/riscv/insn_trans/trans_rvzfh.c.inc new file +2
-0+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General PublicLicense for
target/riscv/insn_trans/trans_rvzfh.c.inc
Quoted 3 lines
target/riscv/insn_trans/trans_rvzfh.c.inc new file +3
-0+ * more details. + * + * You should have received a copy of the GNU General Public Licensealong with
target/riscv/translate.c static uint32_t opcode_at(DisasContextBase *dcbase,
Quoted 75 lines
target/riscv/insn_trans/trans_rvzfh.c.inc new file +50
-0+ * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZFH(ctx) do { \ + if (!ctx->ext_zfh) { \ + return false; \ + } \ +} while (0) + +static bool trans_flh(DisasContext *ctx, arg_flh *a) +{ + TCGv_i64 dest; + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = temp_new(ctx); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + dest = cpu_fpr[a->rd]; + tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, MO_TEUW); + gen_nanbox_h(dest, dest); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsh(DisasContext *ctx, arg_fsh *a) +{ + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = tcg_temp_new(); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEUW); + + return true; +}target/riscv/translate.c +6
-0@@ -69,6 +69,7 @@ typedef struct DisasContext {bool w;bool virt_enabled;bool ext_ifencei; +bool ext_zfh;bool hlsx;/* vector extension */ bool vill;@@ -118,6 +119,11 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (32 ,32 )); } +static void gen_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (16 ,48 )); +} +/* * A narrow n-bit operation, where n < FLEN, checks that input operands * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1. @@ -489,6 +495,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase,
target_ulongpc)target/riscv/translate.c static void
Quoted 8 lines
target/riscv/translate.c +1
-0#include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" /* Include the auto-generated decoder for 16 bit insn */ @@ -541,6 +548,7 @@ static void
riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)Quoted 11 lines
target/riscv/translate.c +1
-1ctx->misa = env->misa; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; + ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX ); --2.25.1
Re: [PATCH v3 1/6] target/riscv: zfh: half-precision load and store
Quoted 35 lines · Frank Chang
Quoted 33 lines · Alistair Francis
Quoted 21 lines · On Sat, Oct 16, 2021 at 7:08 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 65 +++++++++++++++++++++++ target/riscv/translate.c | 8 +++ 5 files changed, 79 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzfh.c.inctarget/riscv/cpu.c +0
-0target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 604
Quoted 4 lines
target/riscv/cpu.c +1
-0@@ -601,6 +601,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), + DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false),This change should be after patch 5. The idea is that we add the functionality and then allow users to enable it.
Otherwise:
Quoted 8 lines
Quoted 3 lines
Reviewed-by Alistair Francis <[email protected]>Alistair
The reason why I put here is because
REQUIRE_ZFH()usesctx->zfh. I can separateext_zfhfield in DisasContext into this patch, and add cfg.ext_zfh in RISCVCPU after patch 5 in my next patchset.
You can still add cfg.ext_zfh, it's just this public PROP that should be last.
Alistair
Quoted 148 lines
Thanks,
Frank ChangQuoted 144 lines
Quoted 144 lines
target/riscv/cpu.c +0
-0DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),target/riscv/cpu.h +1
-0@@ -297,6 +297,7 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zfh;char *priv_spec;char *user_spec;target/riscv/insn32.decode +4
-0@@ -726,3 +726,7 @@ binv 0110100 .......... 001 ..... 0110011 @r binvi 01101. ........... 001 ..... 0010011 @sh bset 0010100 .......... 001 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh + +# *** RV32 Zfh Extension *** +flh ............ ..... 001 ..... 0000111 @i +fsh ....... ..... ..... 001 ..... 0100111 @starget/riscv/insn_trans/trans_rvzfh.c.inc new file +65
-0@@ -0,0 +1,65 @@ +/* + * RISC-V translation routines for the RV64Zfh Standard Extension. + * + * Copyright (c) 2020 Chih-Min Chao, [email protected] + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZFH(ctx) do { \ + if (!ctx->ext_zfh) { \ + return false; \ + } \ +} while (0) + +static bool trans_flh(DisasContext *ctx, arg_flh *a) +{ + TCGv_i64 dest; + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = temp_new(ctx); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + dest = cpu_fpr[a->rd]; + tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, MO_TEUW); + gen_nanbox_h(dest, dest); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsh(DisasContext *ctx, arg_fsh *a) +{ + TCGv t0; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + t0 = get_gpr(ctx, a->rs1, EXT_NONE); + if (a->imm) { + TCGv temp = tcg_temp_new(); + tcg_gen_addi_tl(temp, t0, a->imm); + t0 = temp; + } + + tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEUW); + + return true; +}target/riscv/translate.c +8
-1@@ -69,6 +69,7 @@ typedef struct DisasContext {bool w;bool virt_enabled;bool ext_ifencei; +bool ext_zfh;bool hlsx;/* vector extension */ bool vill;@@ -118,6 +119,11 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (32 ,32 )); } +static void gen_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (16 ,48 )); +} +/* * A narrow n-bit operation, where n < FLEN, checks that input operands * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1. @@ -489,6 +495,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" /* Include the auto-generated decoder for 16 bit insn */ @@ -541,6 +548,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa = env->misa; ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; + ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX ); --2.25.1
PATCH v3 2/6 target/riscv: zfh: half-precision computational
In reply to [email protected]From: Kito Cheng <[email protected]>
--- target/riscv/fpu_helper.c | 86 +++++++++++++++ target/riscv/helper.h | 13 +++ target/riscv/insn32.decode | 11 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 129 ++++++++++++++++++++++ target/riscv/internals.h | 16 +++ 5 files changed, 255 insertions(+)
target/riscv/fpu_helper.c +86 -0
@@ -81,6 +81,15 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm)set_float_rounding_mode (softrm, &env->fp_status); } +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)); +} +static uint64_t do_fmadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2,uint64_t rs3,int flags) {
@@ -102,6 +111,12 @@ uint64_t helper_fmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2,return float64_muladd (frs1, frs2, frs3,0 , &env->fp_status); } +uint64_t helper_fmadd_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3,0 ); +} +uint64_t helper_fmsub_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {
@@ -115,6 +130,12 @@ uint64_t helper_fmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, &env->fp_status); } +uint64_t helper_fmsub_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, float_muladd_negate_c); +} +uint64_t helper_fnmsub_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {
@@ -128,6 +149,12 @@ uint64_t helper_fnmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, &env->fp_status); } +uint64_t helper_fnmsub_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, float_muladd_negate_product); +} +uint64_t helper_fnmadd_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {
@@ -142,6 +169,13 @@ uint64_t helper_fnmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, float_muladd_negate_product, &env->fp_status); } +uint64_t helper_fnmadd_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, + float_muladd_negate_c | float_muladd_negate_product); +} +uint64_t helper_fadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) {float32 frs1 =check_nanbox_s (rs1);
@@ -374,3 +408,55 @@ target_ulong helper_fclass_d(uint64_t frs1) {return fclass_d (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)); +} + +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)); +} + +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)); +} + +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)); +} + +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_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_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)); +}
target/riscv/helper.h +13 -0
@@ -7,12 +7,16 @@ DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32)/* Floating Point - fused */ DEF_HELPER_FLAGS_4(fmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fmadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmsub_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmsub_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fmsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmsub_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmsub_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fnmsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4 (fnmadd_h,TCG_CALL_NO_RWG , i64, env, i64, i64, i64) /* Floating Point - Single Precision */DEF_HELPER_FLAGS_3 (fadd_s,TCG_CALL_NO_RWG , i64, env, i64, i64)
@@ -62,6 +66,15 @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl)DEF_HELPER_FLAGS_2 (clmulr,TCG_CALL_NO_RWG_SE , tl, tl, tl) +/* Floating Point - Half Precision */ +DEF_HELPER_FLAGS_3(fadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmul_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_2 (fsqrt_h,TCG_CALL_NO_RWG , i64, env, i64) + /* Special functions */ DEF_HELPER_2(csrr, tl, env, int)DEF_HELPER_3 (csrw, void, env, int, tl)
target/riscv/insn32.decode +11 -0
@@ -730,3 +730,14 @@ bseti 00101. ........... 001 ..... 0010011 @sh # *** RV32 Zfh Extension *** flh ............ ..... 001 ..... 0000111 @i fsh ....... ..... ..... 001 ..... 0100111 @s +fmadd_h ..... 10 ..... ..... ... ..... 1000011 @r4_rm +fmsub_h ..... 10 ..... ..... ... ..... 1000111 @r4_rm +fnmsub_h ..... 10 ..... ..... ... ..... 1001011 @r4_rm +fnmadd_h ..... 10 ..... ..... ... ..... 1001111 @r4_rm +fadd_h 0000010 ..... ..... ... ..... 1010011 @r_rm +fsub_h 0000110 ..... ..... ... ..... 1010011 @r_rm +fmul_h 0001010 ..... ..... ... ..... 1010011 @r_rm +fdiv_h 0001110 ..... ..... ... ..... 1010011 @r_rm +fsqrt_h 0101110 00000 ..... ... ..... 1010011 @r2_rm +fmin_h 0010110 ..... ..... 000 ..... 1010011 @r +fmax_h 0010110 ..... ..... 001 ..... 1010011 @r
target/riscv/insn_trans/trans_rvzfh.c.inc +129 -0
132 lines not on this page · raw message
target/riscv/internals.h +16 -0
@@ -58,4 +58,20 @@ static inline float32 check_nanbox_s(uint64_t f) } } +static inline uint64_t nanbox_h (float16 f) +{ +return f |MAKE_64BIT_MASK (16 ,48 ); +} + +static inline float16 check_nanbox_h (uint64_t f) +{ +uint64_t mask =MAKE_64BIT_MASK (16 ,48 ); + +if (likely ((f & mask) == mask)) { +return (uint16_t )f; + }else { +return 0x7E00u ;/* default qnan */ + } +} +#endif
Signature · 1 line
2.25.1
Re: [PATCH v3 2/6] target/riscv: zfh: half-precision computational
Quoted 7 lines · On Sat, Oct 16, 2021 at 7:08 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 359 lines
--- target/riscv/fpu_helper.c | 86 +++++++++++++++ target/riscv/helper.h | 13 +++ target/riscv/insn32.decode | 11 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 129 ++++++++++++++++++++++ target/riscv/internals.h | 16 +++ 5 files changed, 255 insertions(+)target/riscv/fpu_helper.c +86
-0@@ -81,6 +81,15 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm)set_float_rounding_mode (softrm, &env->fp_status); } +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)); +} +static uint64_t do_fmadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2,uint64_t rs3,int flags) {@@ -102,6 +111,12 @@ uint64_t helper_fmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2,return float64_muladd (frs1, frs2, frs3,0 , &env->fp_status); } +uint64_t helper_fmadd_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3,0 ); +} +uint64_t helper_fmsub_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {@@ -115,6 +130,12 @@ uint64_t helper_fmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, &env->fp_status); } +uint64_t helper_fmsub_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, float_muladd_negate_c); +} +uint64_t helper_fnmsub_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {@@ -128,6 +149,12 @@ uint64_t helper_fnmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, &env->fp_status); } +uint64_t helper_fnmsub_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, float_muladd_negate_product); +} +uint64_t helper_fnmadd_s (CPURISCVState *env,uint64_t frs1,uint64_t frs2,uint64_t frs3) {@@ -142,6 +169,13 @@ uint64_t helper_fnmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, float_muladd_negate_product, &env->fp_status); } +uint64_t helper_fnmadd_h (CPURISCVState *env,uint64_t frs1,uint64_t frs2, +uint64_t frs3) +{ +return do_fmadd_h (env, frs1, frs2, frs3, + float_muladd_negate_c | float_muladd_negate_product); +} +uint64_t helper_fadd_s (CPURISCVState *env,uint64_t rs1,uint64_t rs2) {float32 frs1 =check_nanbox_s (rs1);@@ -374,3 +408,55 @@ target_ulong helper_fclass_d(uint64_t frs1) {return fclass_d (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)); +} + +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)); +} + +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)); +} + +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)); +} + +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_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_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)); +}target/riscv/helper.h +13
-0@@ -7,12 +7,16 @@ DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32)/* Floating Point - fused */ DEF_HELPER_FLAGS_4(fmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fmadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmsub_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmsub_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fmsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmsub_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmsub_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(fnmsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fnmadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4 (fnmadd_h,TCG_CALL_NO_RWG , i64, env, i64, i64, i64) /* Floating Point - Single Precision */DEF_HELPER_FLAGS_3 (fadd_s,TCG_CALL_NO_RWG , i64, env, i64, i64)@@ -62,6 +66,15 @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl)DEF_HELPER_FLAGS_2 (clmulr,TCG_CALL_NO_RWG_SE , tl, tl, tl) +/* Floating Point - Half Precision */ +DEF_HELPER_FLAGS_3(fadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmul_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_2 (fsqrt_h,TCG_CALL_NO_RWG , i64, env, i64) + /* Special functions */ DEF_HELPER_2(csrr, tl, env, int)DEF_HELPER_3 (csrw, void, env, int, tl)target/riscv/insn32.decode +11
-0@@ -730,3 +730,14 @@ bseti 00101. ........... 001 ..... 0010011 @sh # *** RV32 Zfh Extension *** flh ............ ..... 001 ..... 0000111 @i fsh ....... ..... ..... 001 ..... 0100111 @s +fmadd_h ..... 10 ..... ..... ... ..... 1000011 @r4_rm +fmsub_h ..... 10 ..... ..... ... ..... 1000111 @r4_rm +fnmsub_h ..... 10 ..... ..... ... ..... 1001011 @r4_rm +fnmadd_h ..... 10 ..... ..... ... ..... 1001111 @r4_rm +fadd_h 0000010 ..... ..... ... ..... 1010011 @r_rm +fsub_h 0000110 ..... ..... ... ..... 1010011 @r_rm +fmul_h 0001010 ..... ..... ... ..... 1010011 @r_rm +fdiv_h 0001110 ..... ..... ... ..... 1010011 @r_rm +fsqrt_h 0101110 00000 ..... ... ..... 1010011 @r2_rm +fmin_h 0010110 ..... ..... 000 ..... 1010011 @r +fmax_h 0010110 ..... ..... 001 ..... 1010011 @rtarget/riscv/insn_trans/trans_rvzfh.c.inc +129
-0@@ -63,3 +63,132 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) return true; } + +static bool trans_fmadd_h(DisasContext *ctx, arg_fmadd_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fmadd_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmsub_h(DisasContext *ctx, arg_fmsub_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fmsub_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fnmsub_h(DisasContext *ctx, arg_fnmsub_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fnmsub_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fnmadd_h(DisasContext *ctx, arg_fnmadd_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fnmadd_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2], cpu_fpr[a->rs3]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fadd_h(DisasContext *ctx, arg_fadd_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fadd_h(cpu_fpr[a->rd], cpu_env, + cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsub_h(DisasContext *ctx, arg_fsub_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fsub_h(cpu_fpr[a->rd], cpu_env, + cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmul_h(DisasContext *ctx, arg_fmul_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fmul_h(cpu_fpr[a->rd], cpu_env, + cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fdiv_h(DisasContext *ctx, arg_fdiv_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fdiv_h(cpu_fpr[a->rd], cpu_env, + cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsqrt_h(DisasContext *ctx, arg_fsqrt_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fsqrt_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmin_h(DisasContext *ctx, arg_fmin_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_helper_fmin_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_helper_fmax_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1], + cpu_fpr[a->rs2]); + mark_fs_dirty(ctx); + return true; +}target/riscv/internals.h +16
-1@@ -58,4 +58,20 @@ static inline float32 check_nanbox_s(uint64_t f) } } +static inline uint64_t nanbox_h (float16 f) +{ +return f |MAKE_64BIT_MASK (16 ,48 ); +} + +static inline float16 check_nanbox_h (uint64_t f) +{ +uint64_t mask =MAKE_64BIT_MASK (16 ,48 ); + +if (likely ((f & mask) == mask)) { +return (uint16_t )f; + }else { +return 0x7E00u ;/* default qnan */ + } +} +#endif --2.25.1
PATCH v3 3/6 target/riscv: zfh: half-precision convert and move
In reply to [email protected]From: Kito Cheng <[email protected]>
--- target/riscv/fpu_helper.c | 67 +++++ target/riscv/helper.h | 12 + target/riscv/insn32.decode | 19 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 288 ++++++++++++++++++++++ target/riscv/translate.c | 10 + 5 files changed, 396 insertions(+)
target/riscv/fpu_helper.c +67 -0
@@ -460,3 +460,70 @@ 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)); } + +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) +{ +float16 frs1 =check_nanbox_h (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); +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); +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); +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)); +} + +uint64_t helper_fcvt_h_wu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (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)); +} + +uint64_t helper_fcvt_h_lu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (uint64_to_float16 (rs1, &env->fp_status)); +} + +uint64_t helper_fcvt_h_s (CPURISCVState *env,uint64_t rs1) +{ +float32 frs1 =check_nanbox_s (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)); +} + +uint64_t helper_fcvt_h_d (CPURISCVState *env,uint64_t rs1) +{ +return nanbox_h (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); +return float16_to_float64 (frs1, true, &env->fp_status); +}
target/riscv/helper.h +12 -0
@@ -74,6 +74,18 @@ DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_d_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_d, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_w_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_wu_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_l_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_lu_h, TCG_CALL_NO_RWG, tl, env, i64) +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) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +19 -0
@@ -739,5 +739,24 @@ fsub_h 0000110 ..... ..... ... ..... 1010011 @r_rm fmul_h 0001010 ..... ..... ... ..... 1010011 @r_rm fdiv_h 0001110 ..... ..... ... ..... 1010011 @r_rm fsqrt_h 0101110 00000 ..... ... ..... 1010011 @r2_rm +fsgnj_h 0010010 ..... ..... 000 ..... 1010011 @r +fsgnjn_h 0010010 ..... ..... 001 ..... 1010011 @r +fsgnjx_h 0010010 ..... ..... 010 ..... 1010011 @r fmin_h 0010110 ..... ..... 000 ..... 1010011 @r fmax_h 0010110 ..... ..... 001 ..... 1010011 @r +fcvt_h_s 0100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_s_h 0100000 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_d 0100010 00001 ..... ... ..... 1010011 @r2_rm +fcvt_d_h 0100001 00010 ..... ... ..... 1010011 @r2_rm +fcvt_w_h 1100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_wu_h 1100010 00001 ..... ... ..... 1010011 @r2_rm +fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 +fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm +fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2 + +# *** RV64 Zfh Extension (in addition to RV32 Zfh) *** +fcvt_l_h 1100010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_lu_h 1100010 00011 ..... ... ..... 1010011 @r2_rm +fcvt_h_l 1101010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_lu 1101010 00011 ..... ... ..... 1010011 @r2_rm
target/riscv/insn_trans/trans_rvzfh.c.inc +288 -0
297 lines not on this page · raw message
target/riscv/translate.c +10 -0
@@ -132,6 +132,16 @@ static void gen_nanbox_h(TCGv_i64 out, TCGv_i64 in)* * Here, the result is always nan-boxed, even the canonical nan. */ +static void gen_check_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +TCGv_i64 t_max =tcg_const_i64 (0xffffffffffff0000ull ); +TCGv_i64 t_nan =tcg_const_i64 (0xffffffffffff7e00ull ); + +tcg_gen_movcond_i64 (TCG_COND_GEU , out, in, t_max, in, t_nan); +tcg_temp_free_i64 (t_max); +tcg_temp_free_i64 (t_nan); +} +static void gen_check_nanbox_s (TCGv_i64 out,TCGv_i64 in) {TCGv_i64 t_max =tcg_constant_i64 (0xffffffff00000000ull );
Signature · 1 line
2.25.1
Re: [PATCH v3 3/6] target/riscv: zfh: half-precision convert and move
Quoted 359 lines · On Sat, Oct 16, 2021 at 7:09 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/riscv/fpu_helper.c | 67 +++++ target/riscv/helper.h | 12 + target/riscv/insn32.decode | 19 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 288 ++++++++++++++++++++++ target/riscv/translate.c | 10 + 5 files changed, 396 insertions(+)target/riscv/fpu_helper.c +67
-0@@ -460,3 +460,70 @@ 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)); } + +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) +{ +float16 frs1 =check_nanbox_h (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); +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); +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); +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)); +} + +uint64_t helper_fcvt_h_wu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (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)); +} + +uint64_t helper_fcvt_h_lu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (uint64_to_float16 (rs1, &env->fp_status)); +} + +uint64_t helper_fcvt_h_s (CPURISCVState *env,uint64_t rs1) +{ +float32 frs1 =check_nanbox_s (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)); +} + +uint64_t helper_fcvt_h_d (CPURISCVState *env,uint64_t rs1) +{ +return nanbox_h (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); +return float16_to_float64 (frs1, true, &env->fp_status); +}target/riscv/helper.h +12
-0@@ -74,6 +74,18 @@ DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_d_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_d, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_w_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_wu_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_l_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_lu_h, TCG_CALL_NO_RWG, tl, env, i64) +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) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)target/riscv/insn32.decode +19
-0@@ -739,5 +739,24 @@ fsub_h 0000110 ..... ..... ... ..... 1010011 @r_rm fmul_h 0001010 ..... ..... ... ..... 1010011 @r_rm fdiv_h 0001110 ..... ..... ... ..... 1010011 @r_rm fsqrt_h 0101110 00000 ..... ... ..... 1010011 @r2_rm +fsgnj_h 0010010 ..... ..... 000 ..... 1010011 @r +fsgnjn_h 0010010 ..... ..... 001 ..... 1010011 @r +fsgnjx_h 0010010 ..... ..... 010 ..... 1010011 @r fmin_h 0010110 ..... ..... 000 ..... 1010011 @r fmax_h 0010110 ..... ..... 001 ..... 1010011 @r +fcvt_h_s 0100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_s_h 0100000 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_d 0100010 00001 ..... ... ..... 1010011 @r2_rm +fcvt_d_h 0100001 00010 ..... ... ..... 1010011 @r2_rm +fcvt_w_h 1100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_wu_h 1100010 00001 ..... ... ..... 1010011 @r2_rm +fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 +fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm +fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2 + +# *** RV64 Zfh Extension (in addition to RV32 Zfh) *** +fcvt_l_h 1100010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_lu_h 1100010 00011 ..... ... ..... 1010011 @r2_rm +fcvt_h_l 1101010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_lu 1101010 00011 ..... ... ..... 1010011 @r2_rmtarget/riscv/insn_trans/trans_rvzfh.c.inc +202
-0@@ -171,6 +171,93 @@ static bool trans_fsqrt_h(DisasContext *ctx, arg_fsqrt_h *a) return true; } +static bool trans_fsgnj_h(DisasContext *ctx, arg_fsgnj_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + if (a->rs1 == a->rs2) { /* FMOV */ + gen_check_nanbox_h(cpu_fpr[a->rd], cpu_fpr[a->rs1]); + } else { + TCGv_i64 rs1 = tcg_temp_new_i64(); + TCGv_i64 rs2 = tcg_temp_new_i64(); + + gen_check_nanbox_h(rs1, cpu_fpr[a->rs1]); + gen_check_nanbox_h(rs2, cpu_fpr[a->rs2]); + + /* This formulation retains the nanboxing of rs2. */ + tcg_gen_deposit_i64(cpu_fpr[a->rd], rs2, rs1, 0, 15); + tcg_temp_free_i64(rs1); + tcg_temp_free_i64(rs2); + } + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsgnjn_h(DisasContext *ctx, arg_fsgnjn_h *a) +{ + TCGv_i64 rs1, rs2, mask; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + rs1 = tcg_temp_new_i64(); + gen_check_nanbox_h(rs1, cpu_fpr[a->rs1]); + + if (a->rs1 == a->rs2) { /* FNEG */ + tcg_gen_xori_i64(cpu_fpr[a->rd], rs1, MAKE_64BIT_MASK(15, 1)); + } else { + rs2 = tcg_temp_new_i64(); + gen_check_nanbox_h(rs2, cpu_fpr[a->rs2]); + + /* + * Replace bit 15 in rs1 with inverse in rs2. + * This formulation retains the nanboxing of rs1. + */ + mask = tcg_const_i64(~MAKE_64BIT_MASK(15, 1)); + tcg_gen_not_i64(rs2, rs2); + tcg_gen_andc_i64(rs2, rs2, mask); + tcg_gen_and_i64(rs1, mask, rs1); + tcg_gen_or_i64(cpu_fpr[a->rd], rs1, rs2); + + tcg_temp_free_i64(mask); + tcg_temp_free_i64(rs2); + } + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsgnjx_h(DisasContext *ctx, arg_fsgnjx_h *a) +{ + TCGv_i64 rs1, rs2; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + rs1 = tcg_temp_new_i64(); + gen_check_nanbox_s(rs1, cpu_fpr[a->rs1]); + + if (a->rs1 == a->rs2) { /* FABS */ + tcg_gen_andi_i64(cpu_fpr[a->rd], rs1, ~MAKE_64BIT_MASK(15, 1)); + } else { + rs2 = tcg_temp_new_i64(); + gen_check_nanbox_s(rs2, cpu_fpr[a->rs2]); + + /* + * Xor bit 15 in rs1 with that in rs2. + * This formulation retains the nanboxing of rs1. + */ + tcg_gen_andi_i64(rs2, rs2, MAKE_64BIT_MASK(15, 1)); + tcg_gen_xor_i64(cpu_fpr[a->rd], rs1, rs2); + + tcg_temp_free_i64(rs2); + } + + mark_fs_dirty(ctx); + return true; +} + static bool trans_fmin_h(DisasContext *ctx, arg_fmin_h *a) { REQUIRE_FPU;@@ -192,3 +279,204 @@ static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) mark_fs_dirty(ctx); return true; } + +static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_s_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + REQUIRE_EXT(ctx, RVD); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_d_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + + return true; +} + +static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_s(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + REQUIRE_EXT(ctx, RVD); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_w_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_wu_h(DisasContext *ctx, arg_fcvt_wu_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_wu_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_h_w(DisasContext *ctx, arg_fcvt_h_w *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_w(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_wu(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); +
target/riscv/insn_trans/trans_rvzfh.c.inc static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) · line 406
Quoted 10 lines
target/riscv/insn_trans/trans_rvzfh.c.inc +10
-0+ TCGv dest = dest_gpr(ctx, a->rd); + +#if defined(TARGET_RISCV64) + /* 16 bits -> 64 bits */ + tcg_gen_ext16s_tl(dest, cpu_fpr[a->rs1]); +#else + /* 16 bits -> 32 bits */ + tcg_gen_extrl_i64_i32(dest, cpu_fpr[a->rs1]); + tcg_gen_ext16s_tl(dest, dest); +#endif
Can we use is_32bit(ctx) instead?
Alistair
Re: [PATCH v3 3/6] target/riscv: zfh: half-precision convert and move
Quoted 9 lines · Alistair Francis
target/riscv/insn_trans/trans_rvzfh.c.inc static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) · line 406
Quoted 8 lines
target/riscv/insn_trans/trans_rvzfh.c.inc +8
-0+#if defined(TARGET_RISCV64) + /* 16 bits -> 64 bits */ + tcg_gen_ext16s_tl(dest, cpu_fpr[a->rs1]); +#else + /* 16 bits -> 32 bits */ + tcg_gen_extrl_i64_i32(dest, cpu_fpr[a->rs1]); + tcg_gen_ext16s_tl(dest, dest); +#endifCan we use
is_32bit(ctx)instead?
No. This is about sizeof(target_long), not the current cpu state.
It would be possible to use
tcg_gen_trunc_i64_tl
tcg_gen_ext16s_tlbut we have a couple of other instances of the same thing.
r~
Re: [PATCH v3 3/6] target/riscv: zfh: half-precision convert and move
In reply to [email protected]Quoted 7 lines · On Sat, Oct 16, 2021 at 7:09 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 463 lines
--- target/riscv/fpu_helper.c | 67 +++++ target/riscv/helper.h | 12 + target/riscv/insn32.decode | 19 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 288 ++++++++++++++++++++++ target/riscv/translate.c | 10 + 5 files changed, 396 insertions(+)target/riscv/fpu_helper.c +67
-0@@ -460,3 +460,70 @@ 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)); } + +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) +{ +float16 frs1 =check_nanbox_h (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); +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); +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); +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)); +} + +uint64_t helper_fcvt_h_wu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (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)); +} + +uint64_t helper_fcvt_h_lu (CPURISCVState *env,target_ulong rs1) +{ +return nanbox_h (uint64_to_float16 (rs1, &env->fp_status)); +} + +uint64_t helper_fcvt_h_s (CPURISCVState *env,uint64_t rs1) +{ +float32 frs1 =check_nanbox_s (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)); +} + +uint64_t helper_fcvt_h_d (CPURISCVState *env,uint64_t rs1) +{ +return nanbox_h (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); +return float16_to_float64 (frs1, true, &env->fp_status); +}target/riscv/helper.h +12
-0@@ -74,6 +74,18 @@ DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_d_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_h_d, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_w_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_wu_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_l_h, TCG_CALL_NO_RWG, tl, env, i64) +DEF_HELPER_FLAGS_2(fcvt_lu_h, TCG_CALL_NO_RWG, tl, env, i64) +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) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)target/riscv/insn32.decode +19
-0@@ -739,5 +739,24 @@ fsub_h 0000110 ..... ..... ... ..... 1010011 @r_rm fmul_h 0001010 ..... ..... ... ..... 1010011 @r_rm fdiv_h 0001110 ..... ..... ... ..... 1010011 @r_rm fsqrt_h 0101110 00000 ..... ... ..... 1010011 @r2_rm +fsgnj_h 0010010 ..... ..... 000 ..... 1010011 @r +fsgnjn_h 0010010 ..... ..... 001 ..... 1010011 @r +fsgnjx_h 0010010 ..... ..... 010 ..... 1010011 @r fmin_h 0010110 ..... ..... 000 ..... 1010011 @r fmax_h 0010110 ..... ..... 001 ..... 1010011 @r +fcvt_h_s 0100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_s_h 0100000 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_d 0100010 00001 ..... ... ..... 1010011 @r2_rm +fcvt_d_h 0100001 00010 ..... ... ..... 1010011 @r2_rm +fcvt_w_h 1100010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_wu_h 1100010 00001 ..... ... ..... 1010011 @r2_rm +fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 +fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm +fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm +fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2 + +# *** RV64 Zfh Extension (in addition to RV32 Zfh) *** +fcvt_l_h 1100010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_lu_h 1100010 00011 ..... ... ..... 1010011 @r2_rm +fcvt_h_l 1101010 00010 ..... ... ..... 1010011 @r2_rm +fcvt_h_lu 1101010 00011 ..... ... ..... 1010011 @r2_rmtarget/riscv/insn_trans/trans_rvzfh.c.inc +288
-0@@ -171,6 +171,93 @@ static bool trans_fsqrt_h(DisasContext *ctx, arg_fsqrt_h *a) return true; } +static bool trans_fsgnj_h(DisasContext *ctx, arg_fsgnj_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + if (a->rs1 == a->rs2) { /* FMOV */ + gen_check_nanbox_h(cpu_fpr[a->rd], cpu_fpr[a->rs1]); + } else { + TCGv_i64 rs1 = tcg_temp_new_i64(); + TCGv_i64 rs2 = tcg_temp_new_i64(); + + gen_check_nanbox_h(rs1, cpu_fpr[a->rs1]); + gen_check_nanbox_h(rs2, cpu_fpr[a->rs2]); + + /* This formulation retains the nanboxing of rs2. */ + tcg_gen_deposit_i64(cpu_fpr[a->rd], rs2, rs1, 0, 15); + tcg_temp_free_i64(rs1); + tcg_temp_free_i64(rs2); + } + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsgnjn_h(DisasContext *ctx, arg_fsgnjn_h *a) +{ + TCGv_i64 rs1, rs2, mask; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + rs1 = tcg_temp_new_i64(); + gen_check_nanbox_h(rs1, cpu_fpr[a->rs1]); + + if (a->rs1 == a->rs2) { /* FNEG */ + tcg_gen_xori_i64(cpu_fpr[a->rd], rs1, MAKE_64BIT_MASK(15, 1)); + } else { + rs2 = tcg_temp_new_i64(); + gen_check_nanbox_h(rs2, cpu_fpr[a->rs2]); + + /* + * Replace bit 15 in rs1 with inverse in rs2. + * This formulation retains the nanboxing of rs1. + */ + mask = tcg_const_i64(~MAKE_64BIT_MASK(15, 1)); + tcg_gen_not_i64(rs2, rs2); + tcg_gen_andc_i64(rs2, rs2, mask); + tcg_gen_and_i64(rs1, mask, rs1); + tcg_gen_or_i64(cpu_fpr[a->rd], rs1, rs2); + + tcg_temp_free_i64(mask); + tcg_temp_free_i64(rs2); + } + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fsgnjx_h(DisasContext *ctx, arg_fsgnjx_h *a) +{ + TCGv_i64 rs1, rs2; + + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + rs1 = tcg_temp_new_i64(); + gen_check_nanbox_s(rs1, cpu_fpr[a->rs1]); + + if (a->rs1 == a->rs2) { /* FABS */ + tcg_gen_andi_i64(cpu_fpr[a->rd], rs1, ~MAKE_64BIT_MASK(15, 1)); + } else { + rs2 = tcg_temp_new_i64(); + gen_check_nanbox_s(rs2, cpu_fpr[a->rs2]); + + /* + * Xor bit 15 in rs1 with that in rs2. + * This formulation retains the nanboxing of rs1. + */ + tcg_gen_andi_i64(rs2, rs2, MAKE_64BIT_MASK(15, 1)); + tcg_gen_xor_i64(cpu_fpr[a->rd], rs1, rs2); + + tcg_temp_free_i64(rs2); + } + + mark_fs_dirty(ctx); + return true; +} + static bool trans_fmin_h(DisasContext *ctx, arg_fmin_h *a) { REQUIRE_FPU;@@ -192,3 +279,204 @@ static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) mark_fs_dirty(ctx); return true; } + +static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_s_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + REQUIRE_EXT(ctx, RVD); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_d_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + + return true; +} + +static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_s(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + REQUIRE_EXT(ctx, RVD); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_d(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]); + + mark_fs_dirty(ctx); + + return true; +} + +static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_w_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_wu_h(DisasContext *ctx, arg_fcvt_wu_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_wu_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_h_w(DisasContext *ctx, arg_fcvt_h_w *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_w(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_wu(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + +#if defined(TARGET_RISCV64) + /* 16 bits -> 64 bits */ + tcg_gen_ext16s_tl(dest, cpu_fpr[a->rs1]); +#else + /* 16 bits -> 32 bits */ + tcg_gen_extrl_i64_i32(dest, cpu_fpr[a->rs1]); + tcg_gen_ext16s_tl(dest, dest); +#endif + + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fmv_h_x(DisasContext *ctx, arg_fmv_h_x *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_ZERO); + + tcg_gen_extu_tl_i64(cpu_fpr[a->rd], t0); + gen_nanbox_h(cpu_fpr[a->rd], cpu_fpr[a->rd]); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fcvt_l_h(DisasContext *ctx, arg_fcvt_l_h *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_l_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_lu_h(DisasContext *ctx, arg_fcvt_lu_h *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_lu_h(dest, cpu_env, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_fcvt_h_l(DisasContext *ctx, arg_fcvt_h_l *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_l(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +} + +static bool trans_fcvt_h_lu(DisasContext *ctx, arg_fcvt_h_lu *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv t0 = get_gpr(ctx, a->rs1, EXT_SIGN); + + gen_set_rm(ctx, a->rm); + gen_helper_fcvt_h_lu(cpu_fpr[a->rd], cpu_env, t0); + + mark_fs_dirty(ctx); + return true; +}target/riscv/translate.c +10
-1@@ -132,6 +132,16 @@ static void gen_nanbox_h(TCGv_i64 out, TCGv_i64 in)* * Here, the result is always nan-boxed, even the canonical nan. */ +static void gen_check_nanbox_h (TCGv_i64 out,TCGv_i64 in) +{ +TCGv_i64 t_max =tcg_const_i64 (0xffffffffffff0000ull ); +TCGv_i64 t_nan =tcg_const_i64 (0xffffffffffff7e00ull ); + +tcg_gen_movcond_i64 (TCG_COND_GEU , out, in, t_max, in, t_nan); +tcg_temp_free_i64 (t_max); +tcg_temp_free_i64 (t_nan); +} +static void gen_check_nanbox_s (TCGv_i64 out,TCGv_i64 in) {TCGv_i64 t_max =tcg_constant_i64 (0xffffffff00000000ull ); --2.25.1
PATCH v3 4/6 target/riscv: zfh: half-precision floating-point compare
In reply to [email protected]From: Kito Cheng <[email protected]>
--- target/riscv/fpu_helper.c | 21 +++++++++++++ target/riscv/helper.h | 3 ++ target/riscv/insn32.decode | 3 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 37 +++++++++++++++++++++++ 4 files changed, 64 insertions(+)
target/riscv/fpu_helper.c +21 -0
@@ -461,6 +461,27 @@ uint64_t helper_fsqrt_h(CPURISCVState *env, uint64_t rs1)return nanbox_h (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); +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); +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); +return float16_eq_quiet (frs1, frs2, &env->fp_status); +} +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) {float16 frs1 =check_nanbox_h (rs1);
target/riscv/helper.h +3 -0
@@ -74,6 +74,9 @@ DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_3(fle_h, TCG_CALL_NO_RWG, tl, env, i64, i64) +DEF_HELPER_FLAGS_3(flt_h, TCG_CALL_NO_RWG, tl, env, i64, i64) +DEF_HELPER_FLAGS_3(feq_h, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64) DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64)DEF_HELPER_FLAGS_2 (fcvt_d_h,TCG_CALL_NO_RWG , i64, env, i64)
target/riscv/insn32.decode +3 -0
@@ -751,6 +751,9 @@ fcvt_d_h 0100001 00010 ..... ... ..... 1010011 @r2_rm fcvt_w_h 1100010 00000 ..... ... ..... 1010011 @r2_rm fcvt_wu_h 1100010 00001 ..... ... ..... 1010011 @r2_rm fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 +feq_h 1010010 ..... ..... 010 ..... 1010011 @r +flt_h 1010010 ..... ..... 001 ..... 1010011 @r +fle_h 1010010 ..... ..... 000 ..... 1010011 @r fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2
target/riscv/insn_trans/trans_rvzfh.c.inc +37 -0
@@ -335,6 +335,43 @@ static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) return true; } +static bool trans_feq_h(DisasContext *ctx, arg_feq_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_feq_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_flt_h(DisasContext *ctx, arg_flt_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_flt_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + + return true; +} + +static bool trans_fle_h(DisasContext *ctx, arg_fle_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_fle_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) { REQUIRE_FPU;
Signature · 1 line
2.25.1
Re: [PATCH v3 4/6] target/riscv: zfh: half-precision floating-point compare
Quoted 7 lines · On Sat, Oct 16, 2021 at 7:12 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 119 lines
--- target/riscv/fpu_helper.c | 21 +++++++++++++ target/riscv/helper.h | 3 ++ target/riscv/insn32.decode | 3 ++ target/riscv/insn_trans/trans_rvzfh.c.inc | 37 +++++++++++++++++++++++ 4 files changed, 64 insertions(+)target/riscv/fpu_helper.c +21
-0@@ -461,6 +461,27 @@ uint64_t helper_fsqrt_h(CPURISCVState *env, uint64_t rs1)return nanbox_h (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); +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); +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); +return float16_eq_quiet (frs1, frs2, &env->fp_status); +} +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) {float16 frs1 =check_nanbox_h (rs1);target/riscv/helper.h +3
-0@@ -74,6 +74,9 @@ DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64) DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_3(fle_h, TCG_CALL_NO_RWG, tl, env, i64, i64) +DEF_HELPER_FLAGS_3(flt_h, TCG_CALL_NO_RWG, tl, env, i64, i64) +DEF_HELPER_FLAGS_3(feq_h, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64) DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64)DEF_HELPER_FLAGS_2 (fcvt_d_h,TCG_CALL_NO_RWG , i64, env, i64)target/riscv/insn32.decode +3
-0@@ -751,6 +751,9 @@ fcvt_d_h 0100001 00010 ..... ... ..... 1010011 @r2_rm fcvt_w_h 1100010 00000 ..... ... ..... 1010011 @r2_rm fcvt_wu_h 1100010 00001 ..... ... ..... 1010011 @r2_rm fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 +feq_h 1010010 ..... ..... 010 ..... 1010011 @r +flt_h 1010010 ..... ..... 001 ..... 1010011 @r +fle_h 1010010 ..... ..... 000 ..... 1010011 @r fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2target/riscv/insn_trans/trans_rvzfh.c.inc +37
-1@@ -335,6 +335,43 @@ static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) return true; } +static bool trans_feq_h(DisasContext *ctx, arg_feq_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_feq_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_flt_h(DisasContext *ctx, arg_flt_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_flt_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + + return true; +} + +static bool trans_fle_h(DisasContext *ctx, arg_fle_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_fle_h(dest, cpu_env, cpu_fpr[a->rs1], cpu_fpr[a->rs2]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) { REQUIRE_FPU; --2.25.1
PATCH v3 5/6 target/riscv: zfh: half-precision floating-point classify
In reply to [email protected]From: Kito Cheng <[email protected]>
--- target/riscv/fpu_helper.c | 6 ++++++ target/riscv/helper.h | 1 + target/riscv/insn32.decode | 1 + target/riscv/insn_trans/trans_rvzfh.c.inc | 12 ++++++++++++ 4 files changed, 20 insertions(+)
target/riscv/fpu_helper.c +6 -0
@@ -482,6 +482,12 @@ target_ulong helper_feq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)return float16_eq_quiet (frs1, frs2, &env->fp_status); } +target_ulong helper_fclass_h (uint64_t rs1) +{ +float16 frs1 =check_nanbox_h (rs1); +return fclass_h (frs1); +} +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) {float16 frs1 =check_nanbox_h (rs1);
target/riscv/helper.h +1 -0
@@ -89,6 +89,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) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +1 -0
@@ -754,6 +754,7 @@ fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 feq_h 1010010 ..... ..... 010 ..... 1010011 @r flt_h 1010010 ..... ..... 001 ..... 1010011 @r fle_h 1010010 ..... ..... 000 ..... 1010011 @r +fclass_h 1110010 00000 ..... 001 ..... 1010011 @r2 fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2
target/riscv/insn_trans/trans_rvzfh.c.inc +12 -0
@@ -372,6 +372,18 @@ static bool trans_fle_h(DisasContext *ctx, arg_fle_h *a) return true; } +static bool trans_fclass_h(DisasContext *ctx, arg_fclass_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_fclass_h(dest, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) { REQUIRE_FPU;
Signature · 1 line
2.25.1
Re: [PATCH v3 5/6] target/riscv: zfh: half-precision floating-point classify
Quoted 7 lines · On Sat, Oct 16, 2021 at 7:11 PM <[email protected]> wrote:
From: Kito Cheng <[email protected]>
Signed-off-by Kito Cheng <[email protected]>Signed-off-by Chih-Min Chao <[email protected]>Signed-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 75 lines
--- target/riscv/fpu_helper.c | 6 ++++++ target/riscv/helper.h | 1 + target/riscv/insn32.decode | 1 + target/riscv/insn_trans/trans_rvzfh.c.inc | 12 ++++++++++++ 4 files changed, 20 insertions(+)target/riscv/fpu_helper.c +6
-0@@ -482,6 +482,12 @@ target_ulong helper_feq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)return float16_eq_quiet (frs1, frs2, &env->fp_status); } +target_ulong helper_fclass_h (uint64_t rs1) +{ +float16 frs1 =check_nanbox_h (rs1); +return fclass_h (frs1); +} +target_ulong helper_fcvt_w_h (CPURISCVState *env,uint64_t rs1) {float16 frs1 =check_nanbox_h (rs1);target/riscv/helper.h +1
-0@@ -89,6 +89,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) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)target/riscv/insn32.decode +1
-0@@ -754,6 +754,7 @@ fmv_x_h 1110010 00000 ..... 000 ..... 1010011 @r2 feq_h 1010010 ..... ..... 010 ..... 1010011 @r flt_h 1010010 ..... ..... 001 ..... 1010011 @r fle_h 1010010 ..... ..... 000 ..... 1010011 @r +fclass_h 1110010 00000 ..... 001 ..... 1010011 @r2 fcvt_h_w 1101010 00000 ..... ... ..... 1010011 @r2_rm fcvt_h_wu 1101010 00001 ..... ... ..... 1010011 @r2_rm fmv_h_x 1111010 00000 ..... 000 ..... 1010011 @r2target/riscv/insn_trans/trans_rvzfh.c.inc +12
-1@@ -372,6 +372,18 @@ static bool trans_fle_h(DisasContext *ctx, arg_fle_h *a) return true; } +static bool trans_fclass_h(DisasContext *ctx, arg_fclass_h *a) +{ + REQUIRE_FPU; + REQUIRE_ZFH(ctx); + + TCGv dest = dest_gpr(ctx, a->rd); + + gen_helper_fclass_h(dest, cpu_fpr[a->rs1]); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_fcvt_w_h(DisasContext *ctx, arg_fcvt_w_h *a) { REQUIRE_FPU; --2.25.1
PATCH v3 6/6 target/riscv: zfh: implement zfhmin extension
In reply to [email protected]From: Frank Chang <[email protected]>
Zfhmin extension is a subset of Zfh extension, consisting only of data transfer and conversion instructions.
If enabled, only the following instructions from Zfh extension are included:
* flh, fsh, fmv.x.h, fmv.h.x, fcvt.s.h, fcvt.h.s
* If D extension is present: fcvt.d.h, fcvt.h.d
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn_trans/trans_rvzfh.c.inc | 22 ++++++++++++++-------- target/riscv/translate.c | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-)
target/riscv/cpu.c +1 -0
@@ -602,6 +602,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false), +DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
target/riscv/cpu.h +1 -0
@@ -298,6 +298,7 @@ struct RISCVCPU {bool ext_ifencei;bool ext_icsr;bool ext_zfh; +bool ext_zfhmin;char *priv_spec;char *user_spec;
target/riscv/insn_trans/trans_rvzfh.c.inc +14 -8
@@ -22,13 +22,19 @@ } \ } while (0) +#define REQUIRE_ZFH_OR_ZFHMIN(ctx) do { \ + if (!(ctx->ext_zfh || ctx->ext_zfhmin)) { \ + return false; \ + } \ +} while (0) + static bool trans_flh(DisasContext *ctx, arg_flh *a) { TCGv_i64 dest; TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) {
@@ -50,7 +56,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) {
@@ -283,7 +289,7 @@ static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); gen_set_rm(ctx, a->rm); gen_helper_fcvt_s_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]);
@@ -296,7 +302,7 @@ static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); REQUIRE_EXT(ctx, RVD); gen_set_rm(ctx, a->rm);
@@ -311,7 +317,7 @@ static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); gen_set_rm(ctx, a->rm); gen_helper_fcvt_h_s(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]);
@@ -324,7 +330,7 @@ static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); REQUIRE_EXT(ctx, RVD); gen_set_rm(ctx, a->rm);
@@ -441,7 +447,7 @@ static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a) static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); TCGv dest = dest_gpr(ctx, a->rd);
@@ -461,7 +467,7 @@ static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) static bool trans_fmv_h_x(DisasContext *ctx, arg_fmv_h_x *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); TCGv t0 = get_gpr(ctx, a->rs1, EXT_ZERO);
target/riscv/translate.c +2 -0
@@ -70,6 +70,7 @@ typedef struct DisasContext {bool virt_enabled;bool ext_ifencei;bool ext_zfh; +bool ext_zfhmin;bool hlsx;/* vector extension */ bool vill;
@@ -559,6 +560,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; ctx->ext_zfh = cpu->cfg.ext_zfh; + ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX );
Signature · 1 line
2.25.1
Re: [PATCH v3 6/6] target/riscv: zfh: implement zfhmin extension
Quoted 6 lines · On Sat, Oct 16, 2021 at 7:13 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Zfhmin extension is a subset of Zfh extension, consisting only of data transfer and conversion instructions.
Quoted 7 lines
If enabled, only the following instructions from Zfh extension are included:
* flh, fsh,fmv.x.h, fmv.h.x,fcvt.s.h, fcvt.h.s
* If D extension is present:fcvt.d.h, fcvt.h.dSigned-off-by Frank Chang <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 143 lines
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn_trans/trans_rvzfh.c.inc | 22 ++++++++++++++-------- target/riscv/translate.c | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-)target/riscv/cpu.c +1
-0@@ -602,6 +602,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false), +DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),target/riscv/cpu.h +1
-0@@ -298,6 +298,7 @@ struct RISCVCPU {bool ext_ifencei;bool ext_icsr;bool ext_zfh; +bool ext_zfhmin;char *priv_spec;char *user_spec;target/riscv/insn_trans/trans_rvzfh.c.inc +14
-8@@ -22,13 +22,19 @@ } \ } while (0) +#define REQUIRE_ZFH_OR_ZFHMIN(ctx) do { \ + if (!(ctx->ext_zfh || ctx->ext_zfhmin)) { \ + return false; \ + } \ +} while (0) + static bool trans_flh(DisasContext *ctx, arg_flh *a) { TCGv_i64 dest; TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) {@@ -50,7 +56,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) {@@ -283,7 +289,7 @@ static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); gen_set_rm(ctx, a->rm); gen_helper_fcvt_s_h(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]);@@ -296,7 +302,7 @@ static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); REQUIRE_EXT(ctx, RVD); gen_set_rm(ctx, a->rm);@@ -311,7 +317,7 @@ static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); gen_set_rm(ctx, a->rm); gen_helper_fcvt_h_s(cpu_fpr[a->rd], cpu_env, cpu_fpr[a->rs1]);@@ -324,7 +330,7 @@ static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); REQUIRE_EXT(ctx, RVD); gen_set_rm(ctx, a->rm);@@ -441,7 +447,7 @@ static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a) static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); TCGv dest = dest_gpr(ctx, a->rd);@@ -461,7 +467,7 @@ static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) static bool trans_fmv_h_x(DisasContext *ctx, arg_fmv_h_x *a) { REQUIRE_FPU; - REQUIRE_ZFH(ctx); + REQUIRE_ZFH_OR_ZFHMIN(ctx); TCGv t0 = get_gpr(ctx, a->rs1, EXT_ZERO);target/riscv/translate.c +2
-1@@ -70,6 +70,7 @@ typedef struct DisasContext {bool virt_enabled;bool ext_ifencei;bool ext_zfh; +bool ext_zfhmin;bool hlsx;/* vector extension */ bool vill;@@ -559,6 +560,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->frm =-1 ;/* unknown rounding mode */ ctx->ext_ifencei = cpu->cfg.ext_ifencei; ctx->ext_zfh = cpu->cfg.ext_zfh; + ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; ctx->vlen = cpu->cfg.vlen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX ); --2.25.1
Quoted 6 lines · On 10/16/21 2:07 AM, [email protected] wrote:
Changelog:
v3:
* Use the renamed softfloat min/max APIs:*_minimum_number()and *_maximum_number().* Pick softfloat min/max APIs based on CPU privilege spec version.
So... Given that Zfh 0.1 post-dates F 2.2, does that mean that Zfh should always use the 2019 functions?
r~
Quoted 12 lines · Richard Henderson
Quoted 6 lines · On 10/16/21 2:07 AM, [email protected] wrote:
Changelog:
v3:
* Use the renamed softfloat min/max APIs:*_minimum_number()and *_maximum_number().* Pick softfloat min/max APIs based on CPU privilege spec version.
So... Given that Zfh 0.1 post-dates F 2.2, does that mean that Zfh should always use the
2019 functions?
Hi Richard,
That's what I thought, but Zfh spec says:
"This chapter describes the Zfh standard extension for 16-bit half-precision binary floating-point
instructions compliant with the IEEE 754-2008 arithmetic standard. The Zfh extension depends on
the single-precision floating-point extension, F."
The spec doesn't illustrate too much about how fmin.h/fmax.h should behave, so that's why I took the same approach just like fmin and fmax for RVF in my other patchset.
If that's not acceptable, I can change back to use IEEE 754-2019 for Zfh extension.
Thanks,
Frank Chang
Quoted 3 lines
r~