* [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support
@ 2026-03-04 13:39 Max Chou
2026-03-04 13:39 ` [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
` (15 more replies)
0 siblings, 16 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou
This patchset adds support for the RISC-V Zvfofp8min and Zvfofp4min isa
extensions that provide conversion operations for OCP FP8/FP4 formats.
* Zvfofp8min (Version 0.2.1):
The Zvfofp8min extension provides minimal vector conversion support
for OFP8 formats. It requires the Zve32f extension and leverages the
altfmt field in the VTYPE CSR (introduced by Zvfbfa) to select between
E4M3 (altfmt=0) and E5M2 (altfmt=1) formats.
- Canonical NaN for both E4M3 and E5M2 is 0x7f
- All NaNs are treated as quiet NaNs
Instructions added/extended:
- vfwcvtbf16.f.f.v: OFP8 to BF16 widening conversion
- vfncvtbf16.f.f.w: BF16 to OFP8 narrowing conversion
- vfncvtbf16.sat.f.f.w: BF16 to OFP8 with saturation (new)
- vfncvt.f.f.q: FP32 to OFP8 quad-narrowing conversion (new)
- vfncvt.sat.f.f.q: FP32 to OFP8 with saturation (new)
* Zvfofp4min (Version 0.1):
The Zvfofp4min extension provides minimal vector conversion support
for the OFP4 E2M1 format. It requires the Zve32f extension.
Instructions added:
- vfext.vf2: OFP4 E2M1 to OFP8 E4M3 widening conversion
Chagnes in v4
- Rebase on riscv-to-apply.next (commit 21101a7)
- Remove the softfloat library related patches (Thanks for RH's help to
split this part)
- Add missing illegal ALTFMT SEW pattern checking for Zvfofp8min in
patch 4 (target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
conversion for Zvfofp8min extension)
Changes in v3
- Add floatN_nan_is_snan to simply the quiet/signaling NaN checking flow
in patch 2 & 3
- Add patch 4 to fix pseudo-NaN handling in FPATAN/FYL2XP1/FYL2X helpers
Changes in v2
- Merged v1 patch 2 & 3 to v2 patch 3, v1 patch 4 & 5 to v2 patch 4
- Added new v2 patch 2 to refactor the IEEE format NaN classification
functions (float16, bfloat16, float32, float64) to use internal helper
functions, reducing code duplication and improving maintainability.
The OCP FP8 NaN classification functions follow the same pattern.
- Refactored softfloat implementation to use capability-based FloatFmt
flags (no_infinity, limited_nan, overflow_raises_invalid, normal_frac_max)
instead of monolithic flags
- Removed ocp_fp8e5m2_no_signal_nan and ocp_fp8_same_canonical_nan flags
from float_status; now using local float_status with no_signaling_nans
and default_nan_pattern for RISC-V Zvfofp8min instructions
- Rebased on latest riscv-to-apply.next with zvfbfa v3 patchset
v3: <20260204051756.667397-1-max.chou@sifive.com>
v2: <20260127063723.442734-1-max.chou@sifive.com>
v1: <20260108151650.16329-1-max.chou@sifive.com>
References
* OCP FP8 specification:
https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1
* Zvfofp8min specification (v0.2.1 commit e1e20a7):
https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp8min.adoc
* Zvfofp4min specification (v0.1 commit e1e20a7):
https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp4min.adoc
Based-on: <20260304132514.2889449-1-max.chou@sifive.com>
([v4,0/9] Add Zvfbfa extension support)
Based-on: <20260226071817.1417875-1-max.chou@sifive.com>
([v2,0/2] fpu: Fix OCP FP8 E4M3 conversion issues)
rnax
Max Chou (14):
target/riscv: rvv: Fix NOP_UU_B vs2 width
target/riscv: Add cfg properity for Zvfofp8min extension
target/riscv: Add implied rules for Zvfofp8min extension
target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
conversion for Zvfofp8min extension
target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8
conversion for Zvfofp8min extension
target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction for Zvfofp8min
extension
target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions
for Zvfofp8min extension
target/riscv: Expose Zvfofp8min properity
disas/riscv: Add support of Zvfofp8min extension
target/riscv: Add cfg properity for Zvfofp4min extension
target/riscv: Add implied rules for Zvfofp4min extension
target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
target/riscv: Expose Zvfofp4min properity
disas/riscv: Add support of Zvfofp4min extension
disas/riscv.c | 12 ++
target/riscv/cpu.c | 29 ++++-
target/riscv/cpu_cfg_fields.h.inc | 2 +
target/riscv/helper.h | 15 +++
target/riscv/insn32.decode | 8 ++
target/riscv/insn_trans/trans_rvbf16.c.inc | 32 +++--
target/riscv/insn_trans/trans_rvofp4.c.inc | 43 +++++++
target/riscv/insn_trans/trans_rvofp8.c.inc | 105 ++++++++++++++++
target/riscv/insn_trans/trans_rvv.c.inc | 39 ++++++
target/riscv/tcg/tcg-cpu.c | 10 ++
target/riscv/translate.c | 2 +
target/riscv/vector_helper.c | 137 ++++++++++++++++++++-
12 files changed, 421 insertions(+), 13 deletions(-)
create mode 100644 target/riscv/insn_trans/trans_rvofp4.c.inc
create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
--
2.52.0
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-05 2:32 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
` (14 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/vector_helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
index f75177b0fc..b2315ecf9c 100644
--- a/target/riscv/vector_helper.c
+++ b/target/riscv/vector_helper.c
@@ -4982,7 +4982,7 @@ GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v, 4)
/* Narrowing Floating-Point/Integer Type-Convert Instructions */
/* (TD, T2, TX2) */
-#define NOP_UU_B uint8_t, uint16_t, uint32_t
+#define NOP_UU_B uint8_t, uint16_t, uint16_t
#define NOP_UU_H uint16_t, uint32_t, uint32_t
#define NOP_UU_W uint32_t, uint64_t, uint64_t
/* vfncvt.xu.f.v vd, vs2, vm # Convert float to unsigned integer. */
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
2026-03-04 13:39 ` [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-04 15:01 ` Chao Liu
2026-03-05 2:39 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 03/14] target/riscv: Add implied rules " Max Chou
` (13 subsequent siblings)
15 siblings, 2 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
According to the ISA spec of Zvfofp8min extension,
"The Zvfofp8min extension requires on the Zve32f extension."
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 1 +
target/riscv/cpu_cfg_fields.h.inc | 1 +
target/riscv/tcg/tcg-cpu.c | 5 +++++
target/riscv/vector_helper.c | 3 ++-
4 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 73cfcbdf6f..c3ddcefedc 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
+ ISA_EXT_DATA_ENTRY(zvfofp8min, PRIV_VERSION_1_12_0, ext_zvfofp8min),
ISA_EXT_DATA_ENTRY(zvkb, PRIV_VERSION_1_12_0, ext_zvkb),
ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg),
ISA_EXT_DATA_ENTRY(zvkn, PRIV_VERSION_1_12_0, ext_zvkn),
diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_fields.h.inc
index 3696f02ee0..59302894af 100644
--- a/target/riscv/cpu_cfg_fields.h.inc
+++ b/target/riscv/cpu_cfg_fields.h.inc
@@ -104,6 +104,7 @@ BOOL_FIELD(ext_zvfbfmin)
BOOL_FIELD(ext_zvfbfwma)
BOOL_FIELD(ext_zvfh)
BOOL_FIELD(ext_zvfhmin)
+BOOL_FIELD(ext_zvfofp8min)
BOOL_FIELD(ext_smaia)
BOOL_FIELD(ext_ssaia)
BOOL_FIELD(ext_smctr)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 378b298886..ba89436f13 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -710,6 +710,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
return;
}
+ if (cpu->cfg.ext_zvfofp8min && !cpu->cfg.ext_zve32f) {
+ error_setg(errp, "Zvfofp8min extension depends on Zve32f extension");
+ return;
+ }
+
if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) {
error_setg(errp, "Zvfh extensions requires Zfhmin extension");
return;
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
index b2315ecf9c..57221ab884 100644
--- a/target/riscv/vector_helper.c
+++ b/target/riscv/vector_helper.c
@@ -38,7 +38,8 @@ static target_ulong vtype_reserved(CPURISCVState *env, target_ulong vtype)
int xlen = riscv_cpu_xlen(env);
target_ulong reserved = 0;
- if (riscv_cpu_cfg(env)->ext_zvfbfa) {
+ if (riscv_cpu_cfg(env)->ext_zvfbfa ||
+ riscv_cpu_cfg(env)->ext_zvfofp8min) {
reserved = vtype & MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT,
xlen - 1 - R_VTYPE_RESERVED_SHIFT);
} else {
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 03/14] target/riscv: Add implied rules for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
2026-03-04 13:39 ` [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
2026-03-04 13:39 ` [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-05 2:40 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion " Max Chou
` (12 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
Add implied rules to enable the implied extensions of Zvfofp8min
extension recursively.
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index c3ddcefedc..1cd74f01b7 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2508,6 +2508,15 @@ static RISCVCPUImpliedExtsRule ZVFHMIN_IMPLIED = {
},
};
+static RISCVCPUImpliedExtsRule ZVFOFP8MIN_IMPLIED = {
+ .ext = CPU_CFG_OFFSET(ext_zvfofp8min),
+ .implied_multi_exts = {
+ CPU_CFG_OFFSET(ext_zve32f),
+
+ RISCV_IMPLIED_EXTS_RULE_END
+ },
+};
+
static RISCVCPUImpliedExtsRule ZVKN_IMPLIED = {
.ext = CPU_CFG_OFFSET(ext_zvkn),
.implied_multi_exts = {
@@ -2645,8 +2654,8 @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = {
&ZKS_IMPLIED, &ZVBB_IMPLIED, &ZVE32F_IMPLIED,
&ZVE32X_IMPLIED, &ZVE64D_IMPLIED, &ZVE64F_IMPLIED, &ZVE64X_IMPLIED,
&ZVFBFA_IMPLIED, &ZVFBFMIN_IMPLIED, &ZVFBFWMA_IMPLIED,
- &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED,
- &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
+ &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVFOFP8MIN_IMPLIED,
+ &ZVKN_IMPLIED, &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
&ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED,
&SUPM_IMPLIED, &SSPM_IMPLIED, &SMCTR_IMPLIED, &SSCTR_IMPLIED,
NULL
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (2 preceding siblings ...)
2026-03-04 13:39 ` [PATCH v4 03/14] target/riscv: Add implied rules " Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-04 15:02 ` Chao Liu
2026-03-04 13:39 ` [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 " Max Chou
` (11 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
According to the Zvfofp8min extension, the vfwcvtbf16.f.f.v instruction
supports OFP8 to BF16 conversion when SEW is 8.
And the VTYPE.altfmt field is used to select the OFP8 format.
* altfmt = 0: OFP8.e4m3 to BF16
* altfmt = 1: OFP8.e5m2 to BF16
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/helper.h | 12 +++
target/riscv/insn_trans/trans_rvbf16.c.inc | 16 +++-
target/riscv/vector_helper.c | 99 +++++++++++++++++++++-
3 files changed, 122 insertions(+), 5 deletions(-)
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
index eb0a488ba8..356c24d9fb 100644
--- a/target/riscv/helper.h
+++ b/target/riscv/helper.h
@@ -1247,6 +1247,18 @@ DEF_HELPER_5(vfwcvtbf16_f_f_v, void, ptr, ptr, ptr, env, i32)
DEF_HELPER_6(vfwmaccbf16_vv, void, ptr, ptr, ptr, ptr, env, i32)
DEF_HELPER_6(vfwmaccbf16_vf, void, ptr, ptr, i64, ptr, env, i32)
+/* OFP8 functions */
+DEF_HELPER_5(vfwcvtbf16_f_f_v_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfwcvtbf16_f_f_v_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvtbf16_f_f_w_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvtbf16_f_f_w_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvtbf16_sat_f_f_w_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvtbf16_sat_f_f_w_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvt_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvt_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
+DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+
/* Vector crypto functions */
DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32)
DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32)
diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
index 6cfda03d2e..9aafd4d2ef 100644
--- a/target/riscv/insn_trans/trans_rvbf16.c.inc
+++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
@@ -92,11 +92,20 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
{
REQUIRE_FPU;
- REQUIRE_ZVFBFMIN(ctx);
- if (opfv_widen_check(ctx, a) && (ctx->sew == MO_16)) {
+ if (opfv_widen_check(ctx, a) &&
+ ((ctx->sew == MO_16 && ctx->cfg_ptr->ext_zvfbfmin) ||
+ (ctx->sew == MO_8 && ctx->cfg_ptr->ext_zvfofp8min))) {
+ gen_helper_gvec_3_ptr *fn;
uint32_t data = 0;
+ if (ctx->sew == MO_16) {
+ fn = gen_helper_vfwcvtbf16_f_f_v;
+ } else {
+ fn = ctx->altfmt ? gen_helper_vfwcvtbf16_f_f_v_ofp8e5m2 :
+ gen_helper_vfwcvtbf16_f_f_v_ofp8e4m3;
+ }
+
gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
data = FIELD_DP32(data, VDATA, VM, a->vm);
@@ -106,8 +115,7 @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
vreg_ofs(ctx, a->rs2), tcg_env,
ctx->cfg_ptr->vlenb,
- ctx->cfg_ptr->vlenb, data,
- gen_helper_vfwcvtbf16_f_f_v);
+ ctx->cfg_ptr->vlenb, data, fn);
finalize_rvv_inst(ctx);
return true;
}
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
index 57221ab884..e7b187a57d 100644
--- a/target/riscv/vector_helper.c
+++ b/target/riscv/vector_helper.c
@@ -89,7 +89,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
switch (vsew) {
case MO_8:
- ill_altfmt &= !(cpu->cfg.ext_zvfbfa);
+ ill_altfmt &= !(cpu->cfg.ext_zvfbfa || cpu->cfg.ext_zvfofp8min);
break;
case MO_16:
ill_altfmt &= !(cpu->cfg.ext_zvfbfa);
@@ -5034,6 +5034,103 @@ GEN_VEXT_V_ENV(vfncvt_f_f_w_w, 4)
RVVCALL(OPFVV1, vfncvtbf16_f_f_w, NOP_UU_H, H2, H4, float32_to_bfloat16)
GEN_VEXT_V_ENV(vfncvtbf16_f_f_w, 2)
+/*
+ * OCP FP8 Narrowing Conversions (BF16/F32 -> FP8)
+ * 1. Initialize a local float_status with RISC-V specific NaN handling
+ * 2. Call the softfloat conversion function with saturation parameter
+ * 3. Merge exception flags back to the original status
+ */
+#define GEN_OCP_FP8_NARROW(NAME, CONVERT_FN, SATURATE, IN_TYPE) \
+static uint8_t NAME(IN_TYPE a, float_status *s) \
+{ \
+ float_status local = *s; \
+ local.default_nan_pattern = 0x70; \
+ local.default_nan_mode = true; \
+ uint8_t result = CONVERT_FN(a, SATURATE, &local); \
+ s->float_exception_flags |= local.float_exception_flags; \
+ return result; \
+}
+
+/* BF16 -> E4M3/E5M2 conversions */
+GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e4m3, bfloat16_to_float8_e4m3, false,
+ uint16_t)
+GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e5m2, bfloat16_to_float8_e5m2, false,
+ uint16_t)
+GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e4m3_sat, bfloat16_to_float8_e4m3, true,
+ uint16_t)
+GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e5m2_sat, bfloat16_to_float8_e5m2, true,
+ uint16_t)
+
+/* F32 -> E4M3/E5M2 conversions */
+GEN_OCP_FP8_NARROW(vfncvt_f32_to_e4m3, float32_to_float8_e4m3, false, uint32_t)
+GEN_OCP_FP8_NARROW(vfncvt_f32_to_e5m2, float32_to_float8_e5m2, false, uint32_t)
+GEN_OCP_FP8_NARROW(vfncvt_f32_to_e4m3_sat, float32_to_float8_e4m3, true,
+ uint32_t)
+GEN_OCP_FP8_NARROW(vfncvt_f32_to_e5m2_sat, float32_to_float8_e5m2, true,
+ uint32_t)
+
+/*
+ * OCP FP8 Widening Conversions (FP8 -> BF16)
+ * According to Zvfofp8min isa specification: "No rounding occurs, and no
+ * floating-point exception flags are set."
+ * 1. Initialize a local float_status with no_signaling_nans=true
+ * 2. Call the softfloat conversion function
+ * 3. Intentionally DISCARD exception flags (not merged back)
+ */
+#define GEN_OCP_FP8_WIDEN(NAME, CONVERT_FN) \
+static uint16_t NAME(uint8_t a, float_status *s) \
+{ \
+ float_status local = *s; \
+ local.no_signaling_nans = true; \
+ return CONVERT_FN(a, &local); \
+}
+
+GEN_OCP_FP8_WIDEN(vfwcvt_e4m3_to_bf16, float8_e4m3_to_bfloat16)
+GEN_OCP_FP8_WIDEN(vfwcvt_e5m2_to_bf16, float8_e5m2_to_bfloat16)
+
+/* vfwcvtbf16.f.f.w vd, vs2, vm # Convert OFP8 to BF16. */
+RVVCALL(OPFVV1, vfwcvtbf16_f_f_v_ofp8e4m3, WOP_UU_B, H2, H1,
+ vfwcvt_e4m3_to_bf16)
+RVVCALL(OPFVV1, vfwcvtbf16_f_f_v_ofp8e5m2, WOP_UU_B, H2, H1,
+ vfwcvt_e5m2_to_bf16)
+GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v_ofp8e4m3, 2)
+GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v_ofp8e5m2, 2)
+
+/* vfncvtbf16.f.f.w vd, vs2, vm # Convert BF16 to OFP8 without saturation. */
+RVVCALL(OPFVV1, vfncvtbf16_f_f_w_ofp8e4m3, NOP_UU_B, H1, H2,
+ vfncvt_bf16_to_e4m3)
+RVVCALL(OPFVV1, vfncvtbf16_f_f_w_ofp8e5m2, NOP_UU_B, H1, H2,
+ vfncvt_bf16_to_e5m2)
+GEN_VEXT_V_ENV(vfncvtbf16_f_f_w_ofp8e4m3, 1)
+GEN_VEXT_V_ENV(vfncvtbf16_f_f_w_ofp8e5m2, 1)
+
+/* vfncvtbf16.sat.f.f.w vd, vs2, vm # Convert BF16 to OFP8 with saturation. */
+RVVCALL(OPFVV1, vfncvtbf16_sat_f_f_w_ofp8e4m3, NOP_UU_B, H1, H2,
+ vfncvt_bf16_to_e4m3_sat)
+RVVCALL(OPFVV1, vfncvtbf16_sat_f_f_w_ofp8e5m2, NOP_UU_B, H1, H2,
+ vfncvt_bf16_to_e5m2_sat)
+GEN_VEXT_V_ENV(vfncvtbf16_sat_f_f_w_ofp8e4m3, 1)
+GEN_VEXT_V_ENV(vfncvtbf16_sat_f_f_w_ofp8e5m2, 1)
+
+/* Quad-width narrowing type for FP32 to OFP8 */
+#define QOP_UU_B uint8_t, uint32_t, uint32_t
+
+/* vfncvt.f.f.q vd, vs2, vm # Convert FP32 to OFP8. */
+RVVCALL(OPFVV1, vfncvt_f_f_q_ofp8e4m3, QOP_UU_B, H1, H4,
+ vfncvt_f32_to_e4m3)
+RVVCALL(OPFVV1, vfncvt_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
+ vfncvt_f32_to_e5m2)
+GEN_VEXT_V_ENV(vfncvt_f_f_q_ofp8e4m3, 1)
+GEN_VEXT_V_ENV(vfncvt_f_f_q_ofp8e5m2, 1)
+
+/* vfncvt.sat.f.f.q vd, vs2, vm # Convert FP32 to OFP8 with saturation. */
+RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e4m3, QOP_UU_B, H1, H4,
+ vfncvt_f32_to_e4m3_sat)
+RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
+ vfncvt_f32_to_e5m2_sat)
+GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e4m3, 1)
+GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e5m2, 1)
+
/*
* Vector Reduction Operations
*/
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 conversion for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (3 preceding siblings ...)
2026-03-04 13:39 ` [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion " Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-04 15:03 ` Chao Liu
2026-03-04 13:39 ` [PATCH v4 06/14] target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction " Max Chou
` (10 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
According to the Zvfofp8min extension, the vfncvtbf16.f.f.w instruction
supports BF16 to OFP8 conversion without satuation when SEW is 8.
And the VTYPE.altfmt field is used to select the OFP8 format.
* altfmt = 0: BF16 to OFP8.e4m3
* altfmt = 1: BF16 to OFP8.e5m2
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/insn_trans/trans_rvbf16.c.inc | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
index 9aafd4d2ef..16f4403909 100644
--- a/target/riscv/insn_trans/trans_rvbf16.c.inc
+++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
@@ -67,11 +67,20 @@ static bool trans_fcvt_s_bf16(DisasContext *ctx, arg_fcvt_s_bf16 *a)
static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
{
REQUIRE_FPU;
- REQUIRE_ZVFBFMIN(ctx);
- if (opfv_narrow_check(ctx, a) && (ctx->sew == MO_16)) {
+ if (opfv_narrow_check(ctx, a) &&
+ ((ctx->sew == MO_16 && ctx->cfg_ptr->ext_zvfbfmin) ||
+ (ctx->sew == MO_8 && ctx->cfg_ptr->ext_zvfofp8min))) {
+ gen_helper_gvec_3_ptr *fn;
uint32_t data = 0;
+ if (ctx->sew == MO_16) {
+ fn = gen_helper_vfncvtbf16_f_f_w;
+ } else {
+ fn = ctx->altfmt ? gen_helper_vfncvtbf16_f_f_w_ofp8e5m2 :
+ gen_helper_vfncvtbf16_f_f_w_ofp8e4m3;
+ }
+
gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
data = FIELD_DP32(data, VDATA, VM, a->vm);
@@ -81,8 +90,7 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
vreg_ofs(ctx, a->rs2), tcg_env,
ctx->cfg_ptr->vlenb,
- ctx->cfg_ptr->vlenb, data,
- gen_helper_vfncvtbf16_f_f_w);
+ ctx->cfg_ptr->vlenb, data, fn);
finalize_rvv_inst(ctx);
return true;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 06/14] target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (4 preceding siblings ...)
2026-03-04 13:39 ` [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 " Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-04 13:39 ` [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions " Max Chou
` (9 subsequent siblings)
15 siblings, 0 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
The vfncvtbf16.sat.f.f.w instruction converts a vector of 16-bit
floating-point numbers to a vector of 8-bit floating-point numbers with
saturation.
The VTYPE.altfmt field is used to select the format of the 8-bit floating-point
numbers.
* altfmt = 0: BF16 to OFP8.e4m3
* altfmt = 1: BF16 to OFP8.e5m2
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/insn32.decode | 3 ++
target/riscv/insn_trans/trans_rvofp8.c.inc | 42 ++++++++++++++++++++++
target/riscv/translate.c | 1 +
3 files changed, 46 insertions(+)
create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
index 6e35c4b1e6..49201c0c20 100644
--- a/target/riscv/insn32.decode
+++ b/target/riscv/insn32.decode
@@ -973,6 +973,9 @@ vfwcvtbf16_f_f_v 010010 . ..... 01101 001 ..... 1010111 @r2_vm
vfwmaccbf16_vv 111011 . ..... ..... 001 ..... 1010111 @r_vm
vfwmaccbf16_vf 111011 . ..... ..... 101 ..... 1010111 @r_vm
+# *** Zvfofp8min Extension ***
+vfncvtbf16_sat_f_f_w 010010 . ..... 11111 001 ..... 1010111 @r2_vm
+
# *** Zvbc vector crypto extension ***
vclmul_vv 001100 . ..... ..... 010 ..... 1010111 @r_vm
vclmul_vx 001100 . ..... ..... 110 ..... 1010111 @r_vm
diff --git a/target/riscv/insn_trans/trans_rvofp8.c.inc b/target/riscv/insn_trans/trans_rvofp8.c.inc
new file mode 100644
index 0000000000..d28f92e050
--- /dev/null
+++ b/target/riscv/insn_trans/trans_rvofp8.c.inc
@@ -0,0 +1,42 @@
+/*
+ * RISC-V translation routines for the OFP8 Standard Extensions.
+ *
+ * Copyright (C) 2025 SiFive, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#define REQUIRE_ZVFOFP8MIN(ctx) do { \
+ if (!ctx->cfg_ptr->ext_zvfofp8min) { \
+ return false; \
+ } \
+} while (0)
+
+
+static bool trans_vfncvtbf16_sat_f_f_w(DisasContext *ctx, arg_rmr *a)
+{
+ REQUIRE_FPU;
+ REQUIRE_ZVFOFP8MIN(ctx);
+
+ if (opfv_narrow_check(ctx, a) && ctx->sew == MO_8) {
+ gen_helper_gvec_3_ptr *fn;
+ uint32_t data = 0;
+
+ fn = ctx->altfmt ? gen_helper_vfncvtbf16_sat_f_f_w_ofp8e5m2 :
+ gen_helper_vfncvtbf16_sat_f_f_w_ofp8e4m3;
+
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
+
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
+ tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
+ vreg_ofs(ctx, a->rs2), tcg_env,
+ ctx->cfg_ptr->vlenb,
+ ctx->cfg_ptr->vlenb, data, fn);
+ finalize_rvv_inst(ctx);
+ return true;
+ }
+ return false;
+}
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index d9df6a35ca..0c546a3aff 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1220,6 +1220,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
#include "insn_trans/trans_privileged.c.inc"
#include "insn_trans/trans_svinval.c.inc"
#include "insn_trans/trans_rvbf16.c.inc"
+#include "insn_trans/trans_rvofp8.c.inc"
#include "decode-xthead.c.inc"
#include "decode-xmips.c.inc"
#include "insn_trans/trans_xthead.c.inc"
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions for Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (5 preceding siblings ...)
2026-03-04 13:39 ` [PATCH v4 06/14] target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction " Max Chou
@ 2026-03-04 13:39 ` Max Chou
2026-03-04 15:06 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity Max Chou
` (8 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:39 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
The vfncvt.f.f.q and vfncvt.sat.f.f.q instructions convert a vector of
FP32 elements to a vector of OFP8 elements. The vfncvt.sat.f.fq instruction
converts a vector of FP32 elements to a vector of OFP8 elements with saturation.
The VTYPE.altfmt field is used to select the OFP8 format.
* altfmt = 0: FP32 to OFP8.e4m3
* altfmt = 1: FP32 to OFP8.e5m2
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/insn32.decode | 2 +
target/riscv/insn_trans/trans_rvofp8.c.inc | 63 ++++++++++++++++++++++
target/riscv/insn_trans/trans_rvv.c.inc | 39 ++++++++++++++
3 files changed, 104 insertions(+)
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
index 49201c0c20..f2b413c7d4 100644
--- a/target/riscv/insn32.decode
+++ b/target/riscv/insn32.decode
@@ -974,6 +974,8 @@ vfwmaccbf16_vv 111011 . ..... ..... 001 ..... 1010111 @r_vm
vfwmaccbf16_vf 111011 . ..... ..... 101 ..... 1010111 @r_vm
# *** Zvfofp8min Extension ***
+vfncvt_f_f_q 010010 . ..... 11001 001 ..... 1010111 @r2_vm
+vfncvt_sat_f_f_q 010010 . ..... 11011 001 ..... 1010111 @r2_vm
vfncvtbf16_sat_f_f_w 010010 . ..... 11111 001 ..... 1010111 @r2_vm
# *** Zvbc vector crypto extension ***
diff --git a/target/riscv/insn_trans/trans_rvofp8.c.inc b/target/riscv/insn_trans/trans_rvofp8.c.inc
index d28f92e050..619ee4d773 100644
--- a/target/riscv/insn_trans/trans_rvofp8.c.inc
+++ b/target/riscv/insn_trans/trans_rvofp8.c.inc
@@ -12,6 +12,13 @@
} \
} while (0)
+static bool zvfofp8min_narrow_quad_check(DisasContext *s, arg_rmr *a)
+{
+ return require_rvv(s) &&
+ vext_check_isa_ill(s) &&
+ vext_check_sq(s, a->rd, a->rs2, a->vm) &&
+ (s->sew == MO_8);
+}
static bool trans_vfncvtbf16_sat_f_f_w(DisasContext *ctx, arg_rmr *a)
{
@@ -40,3 +47,59 @@ static bool trans_vfncvtbf16_sat_f_f_w(DisasContext *ctx, arg_rmr *a)
}
return false;
}
+
+static bool trans_vfncvt_f_f_q(DisasContext *ctx, arg_rmr *a)
+{
+ REQUIRE_FPU;
+ REQUIRE_ZVFOFP8MIN(ctx);
+
+ if (zvfofp8min_narrow_quad_check(ctx, a)) {
+ gen_helper_gvec_3_ptr *fn;
+ uint32_t data = 0;
+
+ fn = ctx->altfmt ? gen_helper_vfncvt_f_f_q_ofp8e5m2 :
+ gen_helper_vfncvt_f_f_q_ofp8e4m3;
+
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
+
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
+ tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
+ vreg_ofs(ctx, a->rs2), tcg_env,
+ ctx->cfg_ptr->vlenb,
+ ctx->cfg_ptr->vlenb, data, fn);
+ finalize_rvv_inst(ctx);
+ return true;
+ }
+ return false;
+}
+
+static bool trans_vfncvt_sat_f_f_q(DisasContext *ctx, arg_rmr *a)
+{
+ REQUIRE_FPU;
+ REQUIRE_ZVFOFP8MIN(ctx);
+
+ if (zvfofp8min_narrow_quad_check(ctx, a)) {
+ gen_helper_gvec_3_ptr *fn;
+ uint32_t data = 0;
+
+ fn = ctx->altfmt ? gen_helper_vfncvt_sat_f_f_q_ofp8e5m2 :
+ gen_helper_vfncvt_sat_f_f_q_ofp8e4m3;
+
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
+
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
+ tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
+ vreg_ofs(ctx, a->rs2), tcg_env,
+ ctx->cfg_ptr->vlenb,
+ ctx->cfg_ptr->vlenb, data, fn);
+ finalize_rvv_inst(ctx);
+ return true;
+ }
+ return false;
+}
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
index 161bf94a07..bbe864dd7c 100644
--- a/target/riscv/insn_trans/trans_rvv.c.inc
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
@@ -621,6 +621,45 @@ static bool vext_check_sds(DisasContext *s, int vd, int vs1, int vs2, int vm)
require_align(vs1, s->lmul);
}
+/*
+ * Common check function for vector narrowing instructions
+ * of single-width result (SEW) and quad-width source (4*SEW).
+ *
+ * Rules to be checked here:
+ * 1. The largest vector register group used by an instruction
+ * can not be greater than 8 vector registers
+ * (Section 31.5.2)
+ * 2. Quad-width SEW cannot greater than ELEN.
+ * (Section 31.2)
+ * 3. Source vector register number is multiples of 4 * LMUL.
+ * (Section 31.3.4.2)
+ * 4. Destination vector register number is multiples of LMUL.
+ * (Section 31.3.4.2)
+ * 5. Destination vector register group for a masked vector
+ * instruction cannot overlap the source mask register (v0).
+ * (Section 31.5.3)
+ * risc-v unprivileged spec
+ */
+static bool vext_quad_narrow_check_common(DisasContext *s, int vd, int vs2,
+ int vm)
+{
+ return (s->lmul <= 1) &&
+ (s->sew < MO_32) &&
+ ((s->sew + 2) <= (s->cfg_ptr->elen >> 4)) &&
+ require_align(vs2, s->lmul + 2) &&
+ require_align(vd, s->lmul) &&
+ require_vm(vm, vd);
+}
+
+static bool vext_check_sq(DisasContext *s, int vd, int vs, int vm)
+{
+ bool ret = vext_quad_narrow_check_common(s, vd, vs, vm);
+ if (vd != vs) {
+ ret &= require_noover(vd, s->lmul, vs, s->lmul + 2);
+ }
+ return ret;
+}
+
/*
* Check function for vector reduction instructions.
*
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (6 preceding siblings ...)
2026-03-04 13:39 ` [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions " Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 15:06 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 09/14] disas/riscv: Add support of Zvfofp8min extension Max Chou
` (7 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 1cd74f01b7..9b98e18189 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1382,6 +1382,9 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
MULTI_EXT_CFG_BOOL("x-svukte", ext_svukte, false),
MULTI_EXT_CFG_BOOL("x-zvfbfa", ext_zvfbfa, false),
+ /* Zvfofp8min extension for OFP8 conversion */
+ MULTI_EXT_CFG_BOOL("x-zvfofp8min", ext_zvfofp8min, false),
+
{ },
};
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 09/14] disas/riscv: Add support of Zvfofp8min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (7 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 13:40 ` [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension Max Chou
` (6 subsequent siblings)
15 siblings, 0 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou
This patch adds support to disassemble Zvfofp8min instructions.
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
disas/riscv.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/disas/riscv.c b/disas/riscv.c
index 6f2667482d..30f585772a 100644
--- a/disas/riscv.c
+++ b/disas/riscv.c
@@ -984,6 +984,9 @@ typedef enum {
rv_op_ssamoswap_d = 953,
rv_op_c_sspush = 954,
rv_op_c_sspopchk = 955,
+ rv_op_vfncvtbf16_sat_f_f_w = 956,
+ rv_op_vfncvt_f_f_q = 957,
+ rv_op_vfncvt_sat_f_f_q = 958,
} rv_op;
/* register names */
@@ -2254,6 +2257,9 @@ const rv_opcode_data rvi_opcode_data[] = {
rv_op_sspush, 0 },
{ "c.sspopchk", rv_codec_cmop_ss, rv_fmt_rs1, NULL, rv_op_sspopchk,
rv_op_sspopchk, 0 },
+ { "vfncvtbf16.sat.f.f.w", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
+ { "vfncvt.f.f.q", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
+ { "vfncvt.sat.f.f.q", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
};
/* CSR names */
@@ -3630,7 +3636,10 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
case 21: op = rv_op_vfncvt_rod_f_f_w; break;
case 22: op = rv_op_vfncvt_rtz_xu_f_w; break;
case 23: op = rv_op_vfncvt_rtz_x_f_w; break;
+ case 25: op = rv_op_vfncvt_f_f_q; break;
+ case 27: op = rv_op_vfncvt_sat_f_f_q; break;
case 29: op = rv_op_vfncvtbf16_f_f_w; break;
+ case 31: op = rv_op_vfncvtbf16_sat_f_f_w; break;
}
break;
case 19:
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (8 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 09/14] disas/riscv: Add support of Zvfofp8min extension Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 15:07 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 11/14] target/riscv: Add implied rules " Max Chou
` (5 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
According to the ISA spec of Zvfofp4min extension,
"The Zvfofp4min extension requires on the Zve32f extension."
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 1 +
target/riscv/cpu_cfg_fields.h.inc | 1 +
target/riscv/tcg/tcg-cpu.c | 5 +++++
3 files changed, 7 insertions(+)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 9b98e18189..03eaa12028 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
+ ISA_EXT_DATA_ENTRY(zvfofp4min, PRIV_VERSION_1_12_0, ext_zvfofp4min),
ISA_EXT_DATA_ENTRY(zvfofp8min, PRIV_VERSION_1_12_0, ext_zvfofp8min),
ISA_EXT_DATA_ENTRY(zvkb, PRIV_VERSION_1_12_0, ext_zvkb),
ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg),
diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_fields.h.inc
index 59302894af..353a932c36 100644
--- a/target/riscv/cpu_cfg_fields.h.inc
+++ b/target/riscv/cpu_cfg_fields.h.inc
@@ -104,6 +104,7 @@ BOOL_FIELD(ext_zvfbfmin)
BOOL_FIELD(ext_zvfbfwma)
BOOL_FIELD(ext_zvfh)
BOOL_FIELD(ext_zvfhmin)
+BOOL_FIELD(ext_zvfofp4min)
BOOL_FIELD(ext_zvfofp8min)
BOOL_FIELD(ext_smaia)
BOOL_FIELD(ext_ssaia)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index ba89436f13..b1097e55a3 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -715,6 +715,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
return;
}
+ if (cpu->cfg.ext_zvfofp4min && !cpu->cfg.ext_zve32f) {
+ error_setg(errp, "Zvfofp4min extension depends on Zve32f extension");
+ return;
+ }
+
if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) {
error_setg(errp, "Zvfh extensions requires Zfhmin extension");
return;
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 11/14] target/riscv: Add implied rules for Zvfofp4min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (9 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 13:40 ` [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction " Max Chou
` (4 subsequent siblings)
15 siblings, 0 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
Add implied rules to enable the implied extensions of Zvfofp4min
extension recursively.
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 03eaa12028..3e655ab43d 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2521,6 +2521,15 @@ static RISCVCPUImpliedExtsRule ZVFOFP8MIN_IMPLIED = {
},
};
+static RISCVCPUImpliedExtsRule ZVFOFP4MIN_IMPLIED = {
+ .ext = CPU_CFG_OFFSET(ext_zvfofp4min),
+ .implied_multi_exts = {
+ CPU_CFG_OFFSET(ext_zve32f),
+
+ RISCV_IMPLIED_EXTS_RULE_END
+ },
+};
+
static RISCVCPUImpliedExtsRule ZVKN_IMPLIED = {
.ext = CPU_CFG_OFFSET(ext_zvkn),
.implied_multi_exts = {
@@ -2658,7 +2667,7 @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = {
&ZKS_IMPLIED, &ZVBB_IMPLIED, &ZVE32F_IMPLIED,
&ZVE32X_IMPLIED, &ZVE64D_IMPLIED, &ZVE64F_IMPLIED, &ZVE64X_IMPLIED,
&ZVFBFA_IMPLIED, &ZVFBFMIN_IMPLIED, &ZVFBFWMA_IMPLIED,
- &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVFOFP8MIN_IMPLIED,
+ &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVFOFP4MIN_IMPLIED, &ZVFOFP8MIN_IMPLIED,
&ZVKN_IMPLIED, &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
&ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED,
&SUPM_IMPLIED, &SSPM_IMPLIED, &SMCTR_IMPLIED, &SSCTR_IMPLIED,
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (10 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 11/14] target/riscv: Add implied rules " Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 15:13 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity Max Chou
` (3 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
The vfext.vf2 instruction converts a vector of OCP FP4 E2M1
floating-point numbers to a vector of OFP FP8 E4M3 floating-points
numbers.
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/helper.h | 3 ++
target/riscv/insn32.decode | 3 ++
target/riscv/insn_trans/trans_rvofp4.c.inc | 43 ++++++++++++++++++++++
target/riscv/translate.c | 1 +
target/riscv/vector_helper.c | 33 +++++++++++++++++
5 files changed, 83 insertions(+)
create mode 100644 target/riscv/insn_trans/trans_rvofp4.c.inc
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
index 356c24d9fb..162303fb6c 100644
--- a/target/riscv/helper.h
+++ b/target/riscv/helper.h
@@ -1259,6 +1259,9 @@ DEF_HELPER_5(vfncvt_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
+/* OFP4 function */
+DEF_HELPER_5(vfext_vf2, void, ptr, ptr, ptr, env, i32)
+
/* Vector crypto functions */
DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32)
DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32)
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
index f2b413c7d4..c58223ebd8 100644
--- a/target/riscv/insn32.decode
+++ b/target/riscv/insn32.decode
@@ -754,6 +754,9 @@ vsext_vf2 010010 . ..... 00111 010 ..... 1010111 @r2_vm
vsext_vf4 010010 . ..... 00101 010 ..... 1010111 @r2_vm
vsext_vf8 010010 . ..... 00011 010 ..... 1010111 @r2_vm
+# Zvfofp4min Extension
+vfext_vf2 010010 . ..... 10110 010 ..... 1010111 @r2_vm
+
vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm11
vsetivli 11 .......... ..... 111 ..... 1010111 @r2_zimm10
vsetvl 1000000 ..... ..... 111 ..... 1010111 @r
diff --git a/target/riscv/insn_trans/trans_rvofp4.c.inc b/target/riscv/insn_trans/trans_rvofp4.c.inc
new file mode 100644
index 0000000000..0fb5d7d534
--- /dev/null
+++ b/target/riscv/insn_trans/trans_rvofp4.c.inc
@@ -0,0 +1,43 @@
+/*
+ * RISC-V translation routines for the OFP4 Standard Extensions.
+ *
+ * Copyright (C) 2025 SiFive, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+static bool vext_zvfofp4min_check(DisasContext *s, arg_rmr *a)
+{
+ return s->cfg_ptr->ext_zvfofp4min &&
+ (s->sew == MO_8) &&
+ vext_check_altfmt(s, -1) &&
+ (s->lmul >= -2) &&
+ require_rvv(s) &&
+ vext_check_isa_ill(s) &&
+ (a->rd != a->rs2) &&
+ require_align(a->rd, s->lmul) &&
+ require_align(a->rs2, s->lmul - 1) &&
+ require_vm(a->vm, a->rd) &&
+ require_noover(a->rd, s->lmul, a->rs2, s->lmul - 1);
+}
+
+static bool trans_vfext_vf2(DisasContext *s, arg_rmr *a)
+{
+ if (vext_zvfofp4min_check(s, a)) {
+ uint32_t data = 0;
+
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
+ data = FIELD_DP32(data, VDATA, LMUL, s->lmul);
+ data = FIELD_DP32(data, VDATA, VTA, s->vta);
+ data = FIELD_DP32(data, VDATA, VMA, s->vma);
+ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0),
+ vreg_ofs(s, a->rs2), tcg_env,
+ s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, data,
+ gen_helper_vfext_vf2);
+ tcg_gen_movi_tl(cpu_vstart, 0);
+ finalize_rvv_inst(s);
+
+ return true;
+ }
+ return false;
+}
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 0c546a3aff..4311b388cb 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1221,6 +1221,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
#include "insn_trans/trans_svinval.c.inc"
#include "insn_trans/trans_rvbf16.c.inc"
#include "insn_trans/trans_rvofp8.c.inc"
+#include "insn_trans/trans_rvofp4.c.inc"
#include "decode-xthead.c.inc"
#include "decode-xmips.c.inc"
#include "insn_trans/trans_xthead.c.inc"
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
index e7b187a57d..86a174ed9d 100644
--- a/target/riscv/vector_helper.c
+++ b/target/riscv/vector_helper.c
@@ -5131,6 +5131,7 @@ RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e4m3, 1)
GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e5m2, 1)
+/* Zvfofp4min: vfext.vf2 - OFP4 E2M1 to OFP8 E4M3 conversion */
/*
* Vector Reduction Operations
*/
@@ -5930,3 +5931,35 @@ GEN_VEXT_INT_EXT(vsext_vf2_d, int64_t, int32_t, H8, H4)
GEN_VEXT_INT_EXT(vsext_vf4_w, int32_t, int8_t, H4, H1)
GEN_VEXT_INT_EXT(vsext_vf4_d, int64_t, int16_t, H8, H2)
GEN_VEXT_INT_EXT(vsext_vf8_d, int64_t, int8_t, H8, H1)
+
+
+void HELPER(vfext_vf2)(void *vd, void *v0, void *vs2, CPURISCVState *env,
+ uint32_t desc)
+{
+ float_status fp_status = env->fp_status;
+ uint32_t vl = env->vl;
+ uint32_t vm = vext_vm(desc);
+ uint32_t esz = sizeof(uint8_t);
+ uint32_t total_elems = vext_get_total_elems(env, desc, esz);
+ uint32_t vta = vext_vta(desc);
+ uint32_t vma = vext_vma(desc);
+ uint32_t i;
+
+ VSTART_CHECK_EARLY_EXIT(env, vl);
+
+ for (i = env->vstart; i < vl; ++i) {
+ if (!vm && !vext_elem_mask(v0, i)) {
+ /* set masked-off elements to 1s */
+ vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz);
+ continue;
+ }
+
+ uint8_t input = *((uint8_t *)vs2 + H1((i % 2 ? i - 1 : i) / 2));
+ input = (i % 2) ? ((input >> 4) & 0xf) : (input & 0xf);
+ *((uint8_t *)vd + H1(i)) = float4_e2m1_to_float8_e4m3(input,
+ &fp_status);
+ }
+ env->vstart = 0;
+ /* set tail elements to 1s */
+ vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz);
+}
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (11 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction " Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 15:14 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 14/14] disas/riscv: Add support of Zvfofp4min extension Max Chou
` (2 subsequent siblings)
15 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou, Alistair Francis
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 3e655ab43d..8966beed38 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1385,6 +1385,8 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
/* Zvfofp8min extension for OFP8 conversion */
MULTI_EXT_CFG_BOOL("x-zvfofp8min", ext_zvfofp8min, false),
+ /* Zvfofp4min extension for OFP4 conversion */
+ MULTI_EXT_CFG_BOOL("x-zvfofp4min", ext_zvfofp4min, false),
{ },
};
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v4 14/14] disas/riscv: Add support of Zvfofp4min extension
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (12 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity Max Chou
@ 2026-03-04 13:40 ` Max Chou
2026-03-04 15:20 ` [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Chao Liu
2026-04-14 20:41 ` Daniel Henrique Barboza
15 siblings, 0 replies; 30+ messages in thread
From: Max Chou @ 2026-03-04 13:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu, Max Chou
This patch adds support to disassemble Zvfofp4min instructions.
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Signed-off-by: Max Chou <max.chou@sifive.com>
---
disas/riscv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/disas/riscv.c b/disas/riscv.c
index 30f585772a..5dbeb52c20 100644
--- a/disas/riscv.c
+++ b/disas/riscv.c
@@ -987,6 +987,7 @@ typedef enum {
rv_op_vfncvtbf16_sat_f_f_w = 956,
rv_op_vfncvt_f_f_q = 957,
rv_op_vfncvt_sat_f_f_q = 958,
+ rv_op_vfext_vf2 = 959,
} rv_op;
/* register names */
@@ -2260,6 +2261,7 @@ const rv_opcode_data rvi_opcode_data[] = {
{ "vfncvtbf16.sat.f.f.w", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
{ "vfncvt.f.f.q", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
{ "vfncvt.sat.f.f.q", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
+ { "vfext.vf2", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
};
/* CSR names */
@@ -3715,6 +3717,7 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
case 12: op = rv_op_vclz_v; break;
case 13: op = rv_op_vctz_v; break;
case 14: op = rv_op_vcpop_v; break;
+ case 22: op = rv_op_vfext_vf2; break;
}
break;
case 20:
--
2.52.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
@ 2026-03-04 15:01 ` Chao Liu
2026-03-05 2:39 ` Alistair Francis
1 sibling, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:01 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:39:54PM +0800, Max Chou wrote:
> According to the ISA spec of Zvfofp8min extension,
>
> "The Zvfofp8min extension requires on the Zve32f extension."
>
typo in commit subject -- "properity" should be "property".
Thanks,
Chao
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/cpu.c | 1 +
> target/riscv/cpu_cfg_fields.h.inc | 1 +
> target/riscv/tcg/tcg-cpu.c | 5 +++++
> target/riscv/vector_helper.c | 3 ++-
> 4 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 73cfcbdf6f..c3ddcefedc 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
> ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
> ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
> ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
> + ISA_EXT_DATA_ENTRY(zvfofp8min, PRIV_VERSION_1_12_0, ext_zvfofp8min),
> ISA_EXT_DATA_ENTRY(zvkb, PRIV_VERSION_1_12_0, ext_zvkb),
> ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg),
> ISA_EXT_DATA_ENTRY(zvkn, PRIV_VERSION_1_12_0, ext_zvkn),
> diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_fields.h.inc
> index 3696f02ee0..59302894af 100644
> --- a/target/riscv/cpu_cfg_fields.h.inc
> +++ b/target/riscv/cpu_cfg_fields.h.inc
> @@ -104,6 +104,7 @@ BOOL_FIELD(ext_zvfbfmin)
> BOOL_FIELD(ext_zvfbfwma)
> BOOL_FIELD(ext_zvfh)
> BOOL_FIELD(ext_zvfhmin)
> +BOOL_FIELD(ext_zvfofp8min)
> BOOL_FIELD(ext_smaia)
> BOOL_FIELD(ext_ssaia)
> BOOL_FIELD(ext_smctr)
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index 378b298886..ba89436f13 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -710,6 +710,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
> return;
> }
>
> + if (cpu->cfg.ext_zvfofp8min && !cpu->cfg.ext_zve32f) {
> + error_setg(errp, "Zvfofp8min extension depends on Zve32f extension");
> + return;
> + }
> +
> if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) {
> error_setg(errp, "Zvfh extensions requires Zfhmin extension");
> return;
> diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
> index b2315ecf9c..57221ab884 100644
> --- a/target/riscv/vector_helper.c
> +++ b/target/riscv/vector_helper.c
> @@ -38,7 +38,8 @@ static target_ulong vtype_reserved(CPURISCVState *env, target_ulong vtype)
> int xlen = riscv_cpu_xlen(env);
> target_ulong reserved = 0;
>
> - if (riscv_cpu_cfg(env)->ext_zvfbfa) {
> + if (riscv_cpu_cfg(env)->ext_zvfbfa ||
> + riscv_cpu_cfg(env)->ext_zvfofp8min) {
> reserved = vtype & MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT,
> xlen - 1 - R_VTYPE_RESERVED_SHIFT);
> } else {
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion " Max Chou
@ 2026-03-04 15:02 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:02 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:39:56PM +0800, Max Chou wrote:
> According to the Zvfofp8min extension, the vfwcvtbf16.f.f.v instruction
> supports OFP8 to BF16 conversion when SEW is 8.
> And the VTYPE.altfmt field is used to select the OFP8 format.
> * altfmt = 0: OFP8.e4m3 to BF16
> * altfmt = 1: OFP8.e5m2 to BF16
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/helper.h | 12 +++
> target/riscv/insn_trans/trans_rvbf16.c.inc | 16 +++-
> target/riscv/vector_helper.c | 99 +++++++++++++++++++++-
> 3 files changed, 122 insertions(+), 5 deletions(-)
>
> diff --git a/target/riscv/helper.h b/target/riscv/helper.h
> index eb0a488ba8..356c24d9fb 100644
> --- a/target/riscv/helper.h
> +++ b/target/riscv/helper.h
> @@ -1247,6 +1247,18 @@ DEF_HELPER_5(vfwcvtbf16_f_f_v, void, ptr, ptr, ptr, env, i32)
> DEF_HELPER_6(vfwmaccbf16_vv, void, ptr, ptr, ptr, ptr, env, i32)
> DEF_HELPER_6(vfwmaccbf16_vf, void, ptr, ptr, i64, ptr, env, i32)
>
> +/* OFP8 functions */
> +DEF_HELPER_5(vfwcvtbf16_f_f_v_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfwcvtbf16_f_f_v_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvtbf16_f_f_w_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvtbf16_f_f_w_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvtbf16_sat_f_f_w_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvtbf16_sat_f_f_w_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvt_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvt_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> +DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> +
> /* Vector crypto functions */
> DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32)
> DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32)
> diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
> index 6cfda03d2e..9aafd4d2ef 100644
> --- a/target/riscv/insn_trans/trans_rvbf16.c.inc
> +++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
> @@ -92,11 +92,20 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
> static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
> {
> REQUIRE_FPU;
> - REQUIRE_ZVFBFMIN(ctx);
>
> - if (opfv_widen_check(ctx, a) && (ctx->sew == MO_16)) {
> + if (opfv_widen_check(ctx, a) &&
> + ((ctx->sew == MO_16 && ctx->cfg_ptr->ext_zvfbfmin) ||
> + (ctx->sew == MO_8 && ctx->cfg_ptr->ext_zvfofp8min))) {
> + gen_helper_gvec_3_ptr *fn;
> uint32_t data = 0;
>
> + if (ctx->sew == MO_16) {
> + fn = gen_helper_vfwcvtbf16_f_f_v;
> + } else {
> + fn = ctx->altfmt ? gen_helper_vfwcvtbf16_f_f_v_ofp8e5m2 :
> + gen_helper_vfwcvtbf16_f_f_v_ofp8e4m3;
> + }
> +
> gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
>
> data = FIELD_DP32(data, VDATA, VM, a->vm);
> @@ -106,8 +115,7 @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
> tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
> vreg_ofs(ctx, a->rs2), tcg_env,
> ctx->cfg_ptr->vlenb,
> - ctx->cfg_ptr->vlenb, data,
> - gen_helper_vfwcvtbf16_f_f_v);
> + ctx->cfg_ptr->vlenb, data, fn);
> finalize_rvv_inst(ctx);
> return true;
> }
> diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
> index 57221ab884..e7b187a57d 100644
> --- a/target/riscv/vector_helper.c
> +++ b/target/riscv/vector_helper.c
> @@ -89,7 +89,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
>
> switch (vsew) {
> case MO_8:
> - ill_altfmt &= !(cpu->cfg.ext_zvfbfa);
> + ill_altfmt &= !(cpu->cfg.ext_zvfbfa || cpu->cfg.ext_zvfofp8min);
> break;
> case MO_16:
> ill_altfmt &= !(cpu->cfg.ext_zvfbfa);
> @@ -5034,6 +5034,103 @@ GEN_VEXT_V_ENV(vfncvt_f_f_w_w, 4)
> RVVCALL(OPFVV1, vfncvtbf16_f_f_w, NOP_UU_H, H2, H4, float32_to_bfloat16)
> GEN_VEXT_V_ENV(vfncvtbf16_f_f_w, 2)
>
> +/*
> + * OCP FP8 Narrowing Conversions (BF16/F32 -> FP8)
> + * 1. Initialize a local float_status with RISC-V specific NaN handling
> + * 2. Call the softfloat conversion function with saturation parameter
> + * 3. Merge exception flags back to the original status
> + */
> +#define GEN_OCP_FP8_NARROW(NAME, CONVERT_FN, SATURATE, IN_TYPE) \
> +static uint8_t NAME(IN_TYPE a, float_status *s) \
> +{ \
> + float_status local = *s; \
> + local.default_nan_pattern = 0x70; \
> + local.default_nan_mode = true; \
> + uint8_t result = CONVERT_FN(a, SATURATE, &local); \
> + s->float_exception_flags |= local.float_exception_flags; \
> + return result; \
> +}
> +
> +/* BF16 -> E4M3/E5M2 conversions */
> +GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e4m3, bfloat16_to_float8_e4m3, false,
> + uint16_t)
> +GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e5m2, bfloat16_to_float8_e5m2, false,
> + uint16_t)
> +GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e4m3_sat, bfloat16_to_float8_e4m3, true,
> + uint16_t)
> +GEN_OCP_FP8_NARROW(vfncvt_bf16_to_e5m2_sat, bfloat16_to_float8_e5m2, true,
> + uint16_t)
> +
> +/* F32 -> E4M3/E5M2 conversions */
> +GEN_OCP_FP8_NARROW(vfncvt_f32_to_e4m3, float32_to_float8_e4m3, false, uint32_t)
> +GEN_OCP_FP8_NARROW(vfncvt_f32_to_e5m2, float32_to_float8_e5m2, false, uint32_t)
> +GEN_OCP_FP8_NARROW(vfncvt_f32_to_e4m3_sat, float32_to_float8_e4m3, true,
> + uint32_t)
> +GEN_OCP_FP8_NARROW(vfncvt_f32_to_e5m2_sat, float32_to_float8_e5m2, true,
> + uint32_t)
> +
> +/*
> + * OCP FP8 Widening Conversions (FP8 -> BF16)
> + * According to Zvfofp8min isa specification: "No rounding occurs, and no
> + * floating-point exception flags are set."
> + * 1. Initialize a local float_status with no_signaling_nans=true
> + * 2. Call the softfloat conversion function
> + * 3. Intentionally DISCARD exception flags (not merged back)
> + */
> +#define GEN_OCP_FP8_WIDEN(NAME, CONVERT_FN) \
> +static uint16_t NAME(uint8_t a, float_status *s) \
> +{ \
> + float_status local = *s; \
> + local.no_signaling_nans = true; \
> + return CONVERT_FN(a, &local); \
> +}
The widening conversion correctly discards exception
flags per spec ("No rounding occurs, and no floating-
point exception flags are set."). Good.
Thanks,
Chao
> +
> +GEN_OCP_FP8_WIDEN(vfwcvt_e4m3_to_bf16, float8_e4m3_to_bfloat16)
> +GEN_OCP_FP8_WIDEN(vfwcvt_e5m2_to_bf16, float8_e5m2_to_bfloat16)
> +
> +/* vfwcvtbf16.f.f.w vd, vs2, vm # Convert OFP8 to BF16. */
> +RVVCALL(OPFVV1, vfwcvtbf16_f_f_v_ofp8e4m3, WOP_UU_B, H2, H1,
> + vfwcvt_e4m3_to_bf16)
> +RVVCALL(OPFVV1, vfwcvtbf16_f_f_v_ofp8e5m2, WOP_UU_B, H2, H1,
> + vfwcvt_e5m2_to_bf16)
> +GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v_ofp8e4m3, 2)
> +GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v_ofp8e5m2, 2)
> +
> +/* vfncvtbf16.f.f.w vd, vs2, vm # Convert BF16 to OFP8 without saturation. */
> +RVVCALL(OPFVV1, vfncvtbf16_f_f_w_ofp8e4m3, NOP_UU_B, H1, H2,
> + vfncvt_bf16_to_e4m3)
> +RVVCALL(OPFVV1, vfncvtbf16_f_f_w_ofp8e5m2, NOP_UU_B, H1, H2,
> + vfncvt_bf16_to_e5m2)
> +GEN_VEXT_V_ENV(vfncvtbf16_f_f_w_ofp8e4m3, 1)
> +GEN_VEXT_V_ENV(vfncvtbf16_f_f_w_ofp8e5m2, 1)
> +
> +/* vfncvtbf16.sat.f.f.w vd, vs2, vm # Convert BF16 to OFP8 with saturation. */
> +RVVCALL(OPFVV1, vfncvtbf16_sat_f_f_w_ofp8e4m3, NOP_UU_B, H1, H2,
> + vfncvt_bf16_to_e4m3_sat)
> +RVVCALL(OPFVV1, vfncvtbf16_sat_f_f_w_ofp8e5m2, NOP_UU_B, H1, H2,
> + vfncvt_bf16_to_e5m2_sat)
> +GEN_VEXT_V_ENV(vfncvtbf16_sat_f_f_w_ofp8e4m3, 1)
> +GEN_VEXT_V_ENV(vfncvtbf16_sat_f_f_w_ofp8e5m2, 1)
> +
> +/* Quad-width narrowing type for FP32 to OFP8 */
> +#define QOP_UU_B uint8_t, uint32_t, uint32_t
> +
> +/* vfncvt.f.f.q vd, vs2, vm # Convert FP32 to OFP8. */
> +RVVCALL(OPFVV1, vfncvt_f_f_q_ofp8e4m3, QOP_UU_B, H1, H4,
> + vfncvt_f32_to_e4m3)
> +RVVCALL(OPFVV1, vfncvt_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
> + vfncvt_f32_to_e5m2)
> +GEN_VEXT_V_ENV(vfncvt_f_f_q_ofp8e4m3, 1)
> +GEN_VEXT_V_ENV(vfncvt_f_f_q_ofp8e5m2, 1)
> +
> +/* vfncvt.sat.f.f.q vd, vs2, vm # Convert FP32 to OFP8 with saturation. */
> +RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e4m3, QOP_UU_B, H1, H4,
> + vfncvt_f32_to_e4m3_sat)
> +RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
> + vfncvt_f32_to_e5m2_sat)
> +GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e4m3, 1)
> +GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e5m2, 1)
> +
> /*
> * Vector Reduction Operations
> */
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 conversion for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 " Max Chou
@ 2026-03-04 15:03 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:03 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:39:57PM +0800, Max Chou wrote:
> According to the Zvfofp8min extension, the vfncvtbf16.f.f.w instruction
> supports BF16 to OFP8 conversion without satuation when SEW is 8.
"satuation" should be "saturation".
Thanks,
Chao
> And the VTYPE.altfmt field is used to select the OFP8 format.
> * altfmt = 0: BF16 to OFP8.e4m3
> * altfmt = 1: BF16 to OFP8.e5m2
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/insn_trans/trans_rvbf16.c.inc | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
> index 9aafd4d2ef..16f4403909 100644
> --- a/target/riscv/insn_trans/trans_rvbf16.c.inc
> +++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
> @@ -67,11 +67,20 @@ static bool trans_fcvt_s_bf16(DisasContext *ctx, arg_fcvt_s_bf16 *a)
> static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
> {
> REQUIRE_FPU;
> - REQUIRE_ZVFBFMIN(ctx);
>
> - if (opfv_narrow_check(ctx, a) && (ctx->sew == MO_16)) {
> + if (opfv_narrow_check(ctx, a) &&
> + ((ctx->sew == MO_16 && ctx->cfg_ptr->ext_zvfbfmin) ||
> + (ctx->sew == MO_8 && ctx->cfg_ptr->ext_zvfofp8min))) {
> + gen_helper_gvec_3_ptr *fn;
> uint32_t data = 0;
>
> + if (ctx->sew == MO_16) {
> + fn = gen_helper_vfncvtbf16_f_f_w;
> + } else {
> + fn = ctx->altfmt ? gen_helper_vfncvtbf16_f_f_w_ofp8e5m2 :
> + gen_helper_vfncvtbf16_f_f_w_ofp8e4m3;
> + }
> +
> gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
>
> data = FIELD_DP32(data, VDATA, VM, a->vm);
> @@ -81,8 +90,7 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
> tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
> vreg_ofs(ctx, a->rs2), tcg_env,
> ctx->cfg_ptr->vlenb,
> - ctx->cfg_ptr->vlenb, data,
> - gen_helper_vfncvtbf16_f_f_w);
> + ctx->cfg_ptr->vlenb, data, fn);
> finalize_rvv_inst(ctx);
> return true;
> }
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions " Max Chou
@ 2026-03-04 15:06 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:06 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:39:59PM +0800, Max Chou wrote:
> The vfncvt.f.f.q and vfncvt.sat.f.f.q instructions convert a vector of
> FP32 elements to a vector of OFP8 elements. The vfncvt.sat.f.fq instruction
> converts a vector of FP32 elements to a vector of OFP8 elements with saturation.
> The VTYPE.altfmt field is used to select the OFP8 format.
> * altfmt = 0: FP32 to OFP8.e4m3
> * altfmt = 1: FP32 to OFP8.e5m2
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/insn32.decode | 2 +
> target/riscv/insn_trans/trans_rvofp8.c.inc | 63 ++++++++++++++++++++++
> target/riscv/insn_trans/trans_rvv.c.inc | 39 ++++++++++++++
> 3 files changed, 104 insertions(+)
>
> diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
> index 49201c0c20..f2b413c7d4 100644
> --- a/target/riscv/insn32.decode
> +++ b/target/riscv/insn32.decode
> @@ -974,6 +974,8 @@ vfwmaccbf16_vv 111011 . ..... ..... 001 ..... 1010111 @r_vm
> vfwmaccbf16_vf 111011 . ..... ..... 101 ..... 1010111 @r_vm
>
> # *** Zvfofp8min Extension ***
> +vfncvt_f_f_q 010010 . ..... 11001 001 ..... 1010111 @r2_vm
> +vfncvt_sat_f_f_q 010010 . ..... 11011 001 ..... 1010111 @r2_vm
> vfncvtbf16_sat_f_f_w 010010 . ..... 11111 001 ..... 1010111 @r2_vm
>
> # *** Zvbc vector crypto extension ***
> diff --git a/target/riscv/insn_trans/trans_rvofp8.c.inc b/target/riscv/insn_trans/trans_rvofp8.c.inc
> index d28f92e050..619ee4d773 100644
> --- a/target/riscv/insn_trans/trans_rvofp8.c.inc
> +++ b/target/riscv/insn_trans/trans_rvofp8.c.inc
> @@ -12,6 +12,13 @@
> } \
> } while (0)
>
> +static bool zvfofp8min_narrow_quad_check(DisasContext *s, arg_rmr *a)
> +{
> + return require_rvv(s) &&
> + vext_check_isa_ill(s) &&
> + vext_check_sq(s, a->rd, a->rs2, a->vm) &&
> + (s->sew == MO_8);
> +}
>
> static bool trans_vfncvtbf16_sat_f_f_w(DisasContext *ctx, arg_rmr *a)
> {
> @@ -40,3 +47,59 @@ static bool trans_vfncvtbf16_sat_f_f_w(DisasContext *ctx, arg_rmr *a)
> }
> return false;
> }
> +
> +static bool trans_vfncvt_f_f_q(DisasContext *ctx, arg_rmr *a)
> +{
> + REQUIRE_FPU;
> + REQUIRE_ZVFOFP8MIN(ctx);
> +
> + if (zvfofp8min_narrow_quad_check(ctx, a)) {
> + gen_helper_gvec_3_ptr *fn;
> + uint32_t data = 0;
> +
> + fn = ctx->altfmt ? gen_helper_vfncvt_f_f_q_ofp8e5m2 :
> + gen_helper_vfncvt_f_f_q_ofp8e4m3;
> +
> + gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
> +
> + data = FIELD_DP32(data, VDATA, VM, a->vm);
> + data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
> + data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
> + data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
> + tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
> + vreg_ofs(ctx, a->rs2), tcg_env,
> + ctx->cfg_ptr->vlenb,
> + ctx->cfg_ptr->vlenb, data, fn);
> + finalize_rvv_inst(ctx);
> + return true;
> + }
> + return false;
> +}
> +
> +static bool trans_vfncvt_sat_f_f_q(DisasContext *ctx, arg_rmr *a)
> +{
> + REQUIRE_FPU;
> + REQUIRE_ZVFOFP8MIN(ctx);
> +
> + if (zvfofp8min_narrow_quad_check(ctx, a)) {
> + gen_helper_gvec_3_ptr *fn;
> + uint32_t data = 0;
> +
> + fn = ctx->altfmt ? gen_helper_vfncvt_sat_f_f_q_ofp8e5m2 :
> + gen_helper_vfncvt_sat_f_f_q_ofp8e4m3;
> +
> + gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
> +
> + data = FIELD_DP32(data, VDATA, VM, a->vm);
> + data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
> + data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
> + data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
> + tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
> + vreg_ofs(ctx, a->rs2), tcg_env,
> + ctx->cfg_ptr->vlenb,
> + ctx->cfg_ptr->vlenb, data, fn);
> + finalize_rvv_inst(ctx);
> + return true;
> + }
> + return false;
> +}
> diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
> index 161bf94a07..bbe864dd7c 100644
> --- a/target/riscv/insn_trans/trans_rvv.c.inc
> +++ b/target/riscv/insn_trans/trans_rvv.c.inc
> @@ -621,6 +621,45 @@ static bool vext_check_sds(DisasContext *s, int vd, int vs1, int vs2, int vm)
> require_align(vs1, s->lmul);
> }
>
> +/*
> + * Common check function for vector narrowing instructions
> + * of single-width result (SEW) and quad-width source (4*SEW).
> + *
> + * Rules to be checked here:
> + * 1. The largest vector register group used by an instruction
> + * can not be greater than 8 vector registers
> + * (Section 31.5.2)
> + * 2. Quad-width SEW cannot greater than ELEN.
> + * (Section 31.2)
> + * 3. Source vector register number is multiples of 4 * LMUL.
> + * (Section 31.3.4.2)
> + * 4. Destination vector register number is multiples of LMUL.
> + * (Section 31.3.4.2)
> + * 5. Destination vector register group for a masked vector
> + * instruction cannot overlap the source mask register (v0).
> + * (Section 31.5.3)
> + * risc-v unprivileged spec
> + */
> +static bool vext_quad_narrow_check_common(DisasContext *s, int vd, int vs2,
> + int vm)
> +{
> + return (s->lmul <= 1) &&
> + (s->sew < MO_32) &&
> + ((s->sew + 2) <= (s->cfg_ptr->elen >> 4)) &&
> + require_align(vs2, s->lmul + 2) &&
> + require_align(vd, s->lmul) &&
> + require_vm(vm, vd);
> +}
The quad-narrow check logic is correct:
- lmul <= 1 caps source at 8 regs (4 * LMUL = 4 * 2 = 8)
- sew < MO_32 prevents quad SEW exceeding 128 bits
- elen check verified for both ELEN = 32 and 64
Thanks,
Chao
> +
> +static bool vext_check_sq(DisasContext *s, int vd, int vs, int vm)
> +{
> + bool ret = vext_quad_narrow_check_common(s, vd, vs, vm);
> + if (vd != vs) {
> + ret &= require_noover(vd, s->lmul, vs, s->lmul + 2);
> + }
> + return ret;
> +}
> +
> /*
> * Check function for vector reduction instructions.
> *
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity
2026-03-04 13:40 ` [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity Max Chou
@ 2026-03-04 15:06 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:06 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:40:00PM +0800, Max Chou wrote:
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
same "properity" -> "property" typo in subject.
Thanks,
Chao
> ---
> target/riscv/cpu.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 1cd74f01b7..9b98e18189 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -1382,6 +1382,9 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
> MULTI_EXT_CFG_BOOL("x-svukte", ext_svukte, false),
> MULTI_EXT_CFG_BOOL("x-zvfbfa", ext_zvfbfa, false),
>
> + /* Zvfofp8min extension for OFP8 conversion */
> + MULTI_EXT_CFG_BOOL("x-zvfofp8min", ext_zvfofp8min, false),
> +
> { },
> };
>
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension
2026-03-04 13:40 ` [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension Max Chou
@ 2026-03-04 15:07 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:07 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:40:02PM +0800, Max Chou wrote:
> According to the ISA spec of Zvfofp4min extension,
> "The Zvfofp4min extension requires on the Zve32f extension."
>
same "properity" -> "property" typo in subject.
Thanks,
Chao
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/cpu.c | 1 +
> target/riscv/cpu_cfg_fields.h.inc | 1 +
> target/riscv/tcg/tcg-cpu.c | 5 +++++
> 3 files changed, 7 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 9b98e18189..03eaa12028 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
> ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
> ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
> ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
> + ISA_EXT_DATA_ENTRY(zvfofp4min, PRIV_VERSION_1_12_0, ext_zvfofp4min),
> ISA_EXT_DATA_ENTRY(zvfofp8min, PRIV_VERSION_1_12_0, ext_zvfofp8min),
> ISA_EXT_DATA_ENTRY(zvkb, PRIV_VERSION_1_12_0, ext_zvkb),
> ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg),
> diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_fields.h.inc
> index 59302894af..353a932c36 100644
> --- a/target/riscv/cpu_cfg_fields.h.inc
> +++ b/target/riscv/cpu_cfg_fields.h.inc
> @@ -104,6 +104,7 @@ BOOL_FIELD(ext_zvfbfmin)
> BOOL_FIELD(ext_zvfbfwma)
> BOOL_FIELD(ext_zvfh)
> BOOL_FIELD(ext_zvfhmin)
> +BOOL_FIELD(ext_zvfofp4min)
> BOOL_FIELD(ext_zvfofp8min)
> BOOL_FIELD(ext_smaia)
> BOOL_FIELD(ext_ssaia)
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index ba89436f13..b1097e55a3 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -715,6 +715,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
> return;
> }
>
> + if (cpu->cfg.ext_zvfofp4min && !cpu->cfg.ext_zve32f) {
> + error_setg(errp, "Zvfofp4min extension depends on Zve32f extension");
> + return;
> + }
> +
> if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) {
> error_setg(errp, "Zvfh extensions requires Zfhmin extension");
> return;
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
2026-03-04 13:40 ` [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction " Max Chou
@ 2026-03-04 15:13 ` Chao Liu
2026-04-16 10:28 ` Max Chou
0 siblings, 1 reply; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:13 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:40:04PM +0800, Max Chou wrote:
> The vfext.vf2 instruction converts a vector of OCP FP4 E2M1
> floating-point numbers to a vector of OFP FP8 E4M3 floating-points
> numbers.
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
> ---
> target/riscv/helper.h | 3 ++
> target/riscv/insn32.decode | 3 ++
> target/riscv/insn_trans/trans_rvofp4.c.inc | 43 ++++++++++++++++++++++
> target/riscv/translate.c | 1 +
> target/riscv/vector_helper.c | 33 +++++++++++++++++
> 5 files changed, 83 insertions(+)
> create mode 100644 target/riscv/insn_trans/trans_rvofp4.c.inc
>
> diff --git a/target/riscv/helper.h b/target/riscv/helper.h
> index 356c24d9fb..162303fb6c 100644
> --- a/target/riscv/helper.h
> +++ b/target/riscv/helper.h
> @@ -1259,6 +1259,9 @@ DEF_HELPER_5(vfncvt_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
> DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e4m3, void, ptr, ptr, ptr, env, i32)
> DEF_HELPER_5(vfncvt_sat_f_f_q_ofp8e5m2, void, ptr, ptr, ptr, env, i32)
>
> +/* OFP4 function */
> +DEF_HELPER_5(vfext_vf2, void, ptr, ptr, ptr, env, i32)
> +
> /* Vector crypto functions */
> DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32)
> DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32)
> diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
> index f2b413c7d4..c58223ebd8 100644
> --- a/target/riscv/insn32.decode
> +++ b/target/riscv/insn32.decode
> @@ -754,6 +754,9 @@ vsext_vf2 010010 . ..... 00111 010 ..... 1010111 @r2_vm
> vsext_vf4 010010 . ..... 00101 010 ..... 1010111 @r2_vm
> vsext_vf8 010010 . ..... 00011 010 ..... 1010111 @r2_vm
>
> +# Zvfofp4min Extension
> +vfext_vf2 010010 . ..... 10110 010 ..... 1010111 @r2_vm
> +
> vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm11
> vsetivli 11 .......... ..... 111 ..... 1010111 @r2_zimm10
> vsetvl 1000000 ..... ..... 111 ..... 1010111 @r
> diff --git a/target/riscv/insn_trans/trans_rvofp4.c.inc b/target/riscv/insn_trans/trans_rvofp4.c.inc
> new file mode 100644
> index 0000000000..0fb5d7d534
> --- /dev/null
> +++ b/target/riscv/insn_trans/trans_rvofp4.c.inc
> @@ -0,0 +1,43 @@
> +/*
> + * RISC-V translation routines for the OFP4 Standard Extensions.
> + *
> + * Copyright (C) 2025 SiFive, Inc.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +static bool vext_zvfofp4min_check(DisasContext *s, arg_rmr *a)
> +{
> + return s->cfg_ptr->ext_zvfofp4min &&
> + (s->sew == MO_8) &&
> + vext_check_altfmt(s, -1) &&
> + (s->lmul >= -2) &&
> + require_rvv(s) &&
> + vext_check_isa_ill(s) &&
> + (a->rd != a->rs2) &&
> + require_align(a->rd, s->lmul) &&
> + require_align(a->rs2, s->lmul - 1) &&
> + require_vm(a->vm, a->rd) &&
> + require_noover(a->rd, s->lmul, a->rs2, s->lmul - 1);
> +}
> +
> +static bool trans_vfext_vf2(DisasContext *s, arg_rmr *a)
> +{
> + if (vext_zvfofp4min_check(s, a)) {
Missing REQUIRE_FPU here.
All other FP vector instruction translation functions
in this series (trans_vfncvtbf16_sat_f_f_w, trans_vfncvt_f_f_q,
trans_vfncvt_sat_f_f_q, trans_vfwcvtbf16_f_f_v,
trans_vfncvtbf16_f_f_w) have REQUIRE_FPU at the top.
Without it, this instruction could execute even when FPU
is disabled.
> + uint32_t data = 0;
> +
> + data = FIELD_DP32(data, VDATA, VM, a->vm);
> + data = FIELD_DP32(data, VDATA, LMUL, s->lmul);
> + data = FIELD_DP32(data, VDATA, VTA, s->vta);
> + data = FIELD_DP32(data, VDATA, VMA, s->vma);
> + tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0),
> + vreg_ofs(s, a->rs2), tcg_env,
> + s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, data,
> + gen_helper_vfext_vf2);
> + tcg_gen_movi_tl(cpu_vstart, 0);
> + finalize_rvv_inst(s);
the explicit tcg_gen_movi_tl(cpu_vstart, 0)
is redundant since HELPER(vfext_vf2) already sets
env->vstart = 0 at the end.
I noticed the other trans functions in this series don't have
this extra line. It's not a bug, just inconsistent.
Thanks,
Chao
> +
> + return true;
> + }
> + return false;
> +}
> diff --git a/target/riscv/translate.c b/target/riscv/translate.c
> index 0c546a3aff..4311b388cb 100644
> --- a/target/riscv/translate.c
> +++ b/target/riscv/translate.c
> @@ -1221,6 +1221,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
> #include "insn_trans/trans_svinval.c.inc"
> #include "insn_trans/trans_rvbf16.c.inc"
> #include "insn_trans/trans_rvofp8.c.inc"
> +#include "insn_trans/trans_rvofp4.c.inc"
> #include "decode-xthead.c.inc"
> #include "decode-xmips.c.inc"
> #include "insn_trans/trans_xthead.c.inc"
> diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
> index e7b187a57d..86a174ed9d 100644
> --- a/target/riscv/vector_helper.c
> +++ b/target/riscv/vector_helper.c
> @@ -5131,6 +5131,7 @@ RVVCALL(OPFVV1, vfncvt_sat_f_f_q_ofp8e5m2, QOP_UU_B, H1, H4,
> GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e4m3, 1)
> GEN_VEXT_V_ENV(vfncvt_sat_f_f_q_ofp8e5m2, 1)
>
> +/* Zvfofp4min: vfext.vf2 - OFP4 E2M1 to OFP8 E4M3 conversion */
> /*
> * Vector Reduction Operations
> */
> @@ -5930,3 +5931,35 @@ GEN_VEXT_INT_EXT(vsext_vf2_d, int64_t, int32_t, H8, H4)
> GEN_VEXT_INT_EXT(vsext_vf4_w, int32_t, int8_t, H4, H1)
> GEN_VEXT_INT_EXT(vsext_vf4_d, int64_t, int16_t, H8, H2)
> GEN_VEXT_INT_EXT(vsext_vf8_d, int64_t, int8_t, H8, H1)
> +
> +
> +void HELPER(vfext_vf2)(void *vd, void *v0, void *vs2, CPURISCVState *env,
> + uint32_t desc)
> +{
> + float_status fp_status = env->fp_status;
> + uint32_t vl = env->vl;
> + uint32_t vm = vext_vm(desc);
> + uint32_t esz = sizeof(uint8_t);
> + uint32_t total_elems = vext_get_total_elems(env, desc, esz);
> + uint32_t vta = vext_vta(desc);
> + uint32_t vma = vext_vma(desc);
> + uint32_t i;
> +
> + VSTART_CHECK_EARLY_EXIT(env, vl);
> +
> + for (i = env->vstart; i < vl; ++i) {
> + if (!vm && !vext_elem_mask(v0, i)) {
> + /* set masked-off elements to 1s */
> + vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz);
> + continue;
> + }
> +
> + uint8_t input = *((uint8_t *)vs2 + H1((i % 2 ? i - 1 : i) / 2));
> + input = (i % 2) ? ((input >> 4) & 0xf) : (input & 0xf);
> + *((uint8_t *)vd + H1(i)) = float4_e2m1_to_float8_e4m3(input,
> + &fp_status);
> + }
> + env->vstart = 0;
> + /* set tail elements to 1s */
> + vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz);
> +}
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity
2026-03-04 13:40 ` [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity Max Chou
@ 2026-03-04 15:14 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:14 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Wed, Mar 04, 2026 at 09:40:05PM +0800, Max Chou wrote:
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
same "properity" -> "property" typo in subject.
Thanks,
Chao
> ---
> target/riscv/cpu.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 3e655ab43d..8966beed38 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -1385,6 +1385,8 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
>
> /* Zvfofp8min extension for OFP8 conversion */
> MULTI_EXT_CFG_BOOL("x-zvfofp8min", ext_zvfofp8min, false),
> + /* Zvfofp4min extension for OFP4 conversion */
> + MULTI_EXT_CFG_BOOL("x-zvfofp4min", ext_zvfofp4min, false),
>
> { },
> };
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (13 preceding siblings ...)
2026-03-04 13:40 ` [PATCH v4 14/14] disas/riscv: Add support of Zvfofp4min extension Max Chou
@ 2026-03-04 15:20 ` Chao Liu
2026-04-14 20:41 ` Daniel Henrique Barboza
15 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-03-04 15:20 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
Hi Max,
On Wed, Mar 04, 2026 at 09:39:52PM +0800, Max Chou wrote:
> This patchset adds support for the RISC-V Zvfofp8min and Zvfofp4min isa
> extensions that provide conversion operations for OCP FP8/FP4 formats.
>
> * Zvfofp8min (Version 0.2.1):
> The Zvfofp8min extension provides minimal vector conversion support
> for OFP8 formats. It requires the Zve32f extension and leverages the
> altfmt field in the VTYPE CSR (introduced by Zvfbfa) to select between
> E4M3 (altfmt=0) and E5M2 (altfmt=1) formats.
> - Canonical NaN for both E4M3 and E5M2 is 0x7f
> - All NaNs are treated as quiet NaNs
> Instructions added/extended:
> - vfwcvtbf16.f.f.v: OFP8 to BF16 widening conversion
> - vfncvtbf16.f.f.w: BF16 to OFP8 narrowing conversion
> - vfncvtbf16.sat.f.f.w: BF16 to OFP8 with saturation (new)
> - vfncvt.f.f.q: FP32 to OFP8 quad-narrowing conversion (new)
> - vfncvt.sat.f.f.q: FP32 to OFP8 with saturation (new)
>
> * Zvfofp4min (Version 0.1):
> The Zvfofp4min extension provides minimal vector conversion support
> for the OFP4 E2M1 format. It requires the Zve32f extension.
> Instructions added:
> - vfext.vf2: OFP4 E2M1 to OFP8 E4M3 widening conversion
>
> Chagnes in v4
> - Rebase on riscv-to-apply.next (commit 21101a7)
> - Remove the softfloat library related patches (Thanks for RH's help to
> split this part)
> - Add missing illegal ALTFMT SEW pattern checking for Zvfofp8min in
> patch 4 (target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
> conversion for Zvfofp8min extension)
>
Thanks for this v4 series! I learned a lot about the OCP
FP8/FP4 formats and the Zvfofp8min/Zvfofp4min extensions
while reviewing these patches.
I've been preparing an RFC patchset that provides basic
tests for the OCP FP8/FP4 specification, to complement
QEMU's existing fp test coverage. It's not quite ready
yet, but I plan to post it upstream soon for discussion.
A few minor issues noted in individual patch replies
(missing REQUIRE_FPU in patch 12, typos in commit
subjects). Otherwise the series looks good overall.
Thanks,
Chao
> Changes in v3
> - Add floatN_nan_is_snan to simply the quiet/signaling NaN checking flow
> in patch 2 & 3
> - Add patch 4 to fix pseudo-NaN handling in FPATAN/FYL2XP1/FYL2X helpers
>
> Changes in v2
> - Merged v1 patch 2 & 3 to v2 patch 3, v1 patch 4 & 5 to v2 patch 4
> - Added new v2 patch 2 to refactor the IEEE format NaN classification
> functions (float16, bfloat16, float32, float64) to use internal helper
> functions, reducing code duplication and improving maintainability.
> The OCP FP8 NaN classification functions follow the same pattern.
> - Refactored softfloat implementation to use capability-based FloatFmt
> flags (no_infinity, limited_nan, overflow_raises_invalid, normal_frac_max)
> instead of monolithic flags
> - Removed ocp_fp8e5m2_no_signal_nan and ocp_fp8_same_canonical_nan flags
> from float_status; now using local float_status with no_signaling_nans
> and default_nan_pattern for RISC-V Zvfofp8min instructions
> - Rebased on latest riscv-to-apply.next with zvfbfa v3 patchset
>
> v3: <20260204051756.667397-1-max.chou@sifive.com>
> v2: <20260127063723.442734-1-max.chou@sifive.com>
> v1: <20260108151650.16329-1-max.chou@sifive.com>
>
> References
> * OCP FP8 specification:
> https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1
> * Zvfofp8min specification (v0.2.1 commit e1e20a7):
> https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp8min.adoc
> * Zvfofp4min specification (v0.1 commit e1e20a7):
> https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp4min.adoc
>
> Based-on: <20260304132514.2889449-1-max.chou@sifive.com>
> ([v4,0/9] Add Zvfbfa extension support)
> Based-on: <20260226071817.1417875-1-max.chou@sifive.com>
> ([v2,0/2] fpu: Fix OCP FP8 E4M3 conversion issues)
>
> rnax
>
>
> Max Chou (14):
> target/riscv: rvv: Fix NOP_UU_B vs2 width
> target/riscv: Add cfg properity for Zvfofp8min extension
> target/riscv: Add implied rules for Zvfofp8min extension
> target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
> conversion for Zvfofp8min extension
> target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8
> conversion for Zvfofp8min extension
> target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction for Zvfofp8min
> extension
> target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions
> for Zvfofp8min extension
> target/riscv: Expose Zvfofp8min properity
> disas/riscv: Add support of Zvfofp8min extension
> target/riscv: Add cfg properity for Zvfofp4min extension
> target/riscv: Add implied rules for Zvfofp4min extension
> target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
> target/riscv: Expose Zvfofp4min properity
> disas/riscv: Add support of Zvfofp4min extension
>
> disas/riscv.c | 12 ++
> target/riscv/cpu.c | 29 ++++-
> target/riscv/cpu_cfg_fields.h.inc | 2 +
> target/riscv/helper.h | 15 +++
> target/riscv/insn32.decode | 8 ++
> target/riscv/insn_trans/trans_rvbf16.c.inc | 32 +++--
> target/riscv/insn_trans/trans_rvofp4.c.inc | 43 +++++++
> target/riscv/insn_trans/trans_rvofp8.c.inc | 105 ++++++++++++++++
> target/riscv/insn_trans/trans_rvv.c.inc | 39 ++++++
> target/riscv/tcg/tcg-cpu.c | 10 ++
> target/riscv/translate.c | 2 +
> target/riscv/vector_helper.c | 137 ++++++++++++++++++++-
> 12 files changed, 421 insertions(+), 13 deletions(-)
> create mode 100644 target/riscv/insn_trans/trans_rvofp4.c.inc
> create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
>
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width
2026-03-04 13:39 ` [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
@ 2026-03-05 2:32 ` Alistair Francis
0 siblings, 0 replies; 30+ messages in thread
From: Alistair Francis @ 2026-03-05 2:32 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei, Chao Liu
On Wed, Mar 4, 2026 at 11:42 PM Max Chou <max.chou@sifive.com> wrote:
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/vector_helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
> index f75177b0fc..b2315ecf9c 100644
> --- a/target/riscv/vector_helper.c
> +++ b/target/riscv/vector_helper.c
> @@ -4982,7 +4982,7 @@ GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v, 4)
>
> /* Narrowing Floating-Point/Integer Type-Convert Instructions */
> /* (TD, T2, TX2) */
> -#define NOP_UU_B uint8_t, uint16_t, uint32_t
> +#define NOP_UU_B uint8_t, uint16_t, uint16_t
> #define NOP_UU_H uint16_t, uint32_t, uint32_t
> #define NOP_UU_W uint32_t, uint64_t, uint64_t
> /* vfncvt.xu.f.v vd, vs2, vm # Convert float to unsigned integer. */
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
2026-03-04 15:01 ` Chao Liu
@ 2026-03-05 2:39 ` Alistair Francis
1 sibling, 0 replies; 30+ messages in thread
From: Alistair Francis @ 2026-03-05 2:39 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei, Chao Liu
On Wed, Mar 4, 2026 at 11:43 PM Max Chou <max.chou@sifive.com> wrote:
>
> According to the ISA spec of Zvfofp8min extension,
>
> "The Zvfofp8min extension requires on the Zve32f extension."
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 1 +
> target/riscv/cpu_cfg_fields.h.inc | 1 +
> target/riscv/tcg/tcg-cpu.c | 5 +++++
> target/riscv/vector_helper.c | 3 ++-
> 4 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 73cfcbdf6f..c3ddcefedc 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
> ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
> ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
> ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
> + ISA_EXT_DATA_ENTRY(zvfofp8min, PRIV_VERSION_1_12_0, ext_zvfofp8min),
> ISA_EXT_DATA_ENTRY(zvkb, PRIV_VERSION_1_12_0, ext_zvkb),
> ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg),
> ISA_EXT_DATA_ENTRY(zvkn, PRIV_VERSION_1_12_0, ext_zvkn),
> diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_fields.h.inc
> index 3696f02ee0..59302894af 100644
> --- a/target/riscv/cpu_cfg_fields.h.inc
> +++ b/target/riscv/cpu_cfg_fields.h.inc
> @@ -104,6 +104,7 @@ BOOL_FIELD(ext_zvfbfmin)
> BOOL_FIELD(ext_zvfbfwma)
> BOOL_FIELD(ext_zvfh)
> BOOL_FIELD(ext_zvfhmin)
> +BOOL_FIELD(ext_zvfofp8min)
> BOOL_FIELD(ext_smaia)
> BOOL_FIELD(ext_ssaia)
> BOOL_FIELD(ext_smctr)
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index 378b298886..ba89436f13 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -710,6 +710,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
> return;
> }
>
> + if (cpu->cfg.ext_zvfofp8min && !cpu->cfg.ext_zve32f) {
> + error_setg(errp, "Zvfofp8min extension depends on Zve32f extension");
> + return;
> + }
> +
> if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) {
> error_setg(errp, "Zvfh extensions requires Zfhmin extension");
> return;
> diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
> index b2315ecf9c..57221ab884 100644
> --- a/target/riscv/vector_helper.c
> +++ b/target/riscv/vector_helper.c
> @@ -38,7 +38,8 @@ static target_ulong vtype_reserved(CPURISCVState *env, target_ulong vtype)
> int xlen = riscv_cpu_xlen(env);
> target_ulong reserved = 0;
>
> - if (riscv_cpu_cfg(env)->ext_zvfbfa) {
> + if (riscv_cpu_cfg(env)->ext_zvfbfa ||
> + riscv_cpu_cfg(env)->ext_zvfofp8min) {
> reserved = vtype & MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT,
> xlen - 1 - R_VTYPE_RESERVED_SHIFT);
> } else {
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 03/14] target/riscv: Add implied rules for Zvfofp8min extension
2026-03-04 13:39 ` [PATCH v4 03/14] target/riscv: Add implied rules " Max Chou
@ 2026-03-05 2:40 ` Alistair Francis
0 siblings, 0 replies; 30+ messages in thread
From: Alistair Francis @ 2026-03-05 2:40 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei, Chao Liu
On Wed, Mar 4, 2026 at 11:42 PM Max Chou <max.chou@sifive.com> wrote:
>
> Add implied rules to enable the implied extensions of Zvfofp8min
> extension recursively.
>
> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
> Signed-off-by: Max Chou <max.chou@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index c3ddcefedc..1cd74f01b7 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -2508,6 +2508,15 @@ static RISCVCPUImpliedExtsRule ZVFHMIN_IMPLIED = {
> },
> };
>
> +static RISCVCPUImpliedExtsRule ZVFOFP8MIN_IMPLIED = {
> + .ext = CPU_CFG_OFFSET(ext_zvfofp8min),
> + .implied_multi_exts = {
> + CPU_CFG_OFFSET(ext_zve32f),
> +
> + RISCV_IMPLIED_EXTS_RULE_END
> + },
> +};
> +
> static RISCVCPUImpliedExtsRule ZVKN_IMPLIED = {
> .ext = CPU_CFG_OFFSET(ext_zvkn),
> .implied_multi_exts = {
> @@ -2645,8 +2654,8 @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = {
> &ZKS_IMPLIED, &ZVBB_IMPLIED, &ZVE32F_IMPLIED,
> &ZVE32X_IMPLIED, &ZVE64D_IMPLIED, &ZVE64F_IMPLIED, &ZVE64X_IMPLIED,
> &ZVFBFA_IMPLIED, &ZVFBFMIN_IMPLIED, &ZVFBFWMA_IMPLIED,
> - &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED,
> - &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
> + &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVFOFP8MIN_IMPLIED,
> + &ZVKN_IMPLIED, &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED,
> &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED,
> &SUPM_IMPLIED, &SSPM_IMPLIED, &SMCTR_IMPLIED, &SSCTR_IMPLIED,
> NULL
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
` (14 preceding siblings ...)
2026-03-04 15:20 ` [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Chao Liu
@ 2026-04-14 20:41 ` Daniel Henrique Barboza
15 siblings, 0 replies; 30+ messages in thread
From: Daniel Henrique Barboza @ 2026-04-14 20:41 UTC (permalink / raw)
To: Max Chou, qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
Weiwei Li, Liu Zhiwei, Chao Liu
Greetings,
Seems like we can queue this up for the next release. Maybe a rebase + resend
is in order to address Chao's comments.
Thanks,
Daniel
On 3/4/2026 10:39 AM, Max Chou wrote:
> This patchset adds support for the RISC-V Zvfofp8min and Zvfofp4min isa
> extensions that provide conversion operations for OCP FP8/FP4 formats.
>
> * Zvfofp8min (Version 0.2.1):
> The Zvfofp8min extension provides minimal vector conversion support
> for OFP8 formats. It requires the Zve32f extension and leverages the
> altfmt field in the VTYPE CSR (introduced by Zvfbfa) to select between
> E4M3 (altfmt=0) and E5M2 (altfmt=1) formats.
> - Canonical NaN for both E4M3 and E5M2 is 0x7f
> - All NaNs are treated as quiet NaNs
> Instructions added/extended:
> - vfwcvtbf16.f.f.v: OFP8 to BF16 widening conversion
> - vfncvtbf16.f.f.w: BF16 to OFP8 narrowing conversion
> - vfncvtbf16.sat.f.f.w: BF16 to OFP8 with saturation (new)
> - vfncvt.f.f.q: FP32 to OFP8 quad-narrowing conversion (new)
> - vfncvt.sat.f.f.q: FP32 to OFP8 with saturation (new)
>
> * Zvfofp4min (Version 0.1):
> The Zvfofp4min extension provides minimal vector conversion support
> for the OFP4 E2M1 format. It requires the Zve32f extension.
> Instructions added:
> - vfext.vf2: OFP4 E2M1 to OFP8 E4M3 widening conversion
>
> Chagnes in v4
> - Rebase on riscv-to-apply.next (commit 21101a7)
> - Remove the softfloat library related patches (Thanks for RH's help to
> split this part)
> - Add missing illegal ALTFMT SEW pattern checking for Zvfofp8min in
> patch 4 (target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
> conversion for Zvfofp8min extension)
>
> Changes in v3
> - Add floatN_nan_is_snan to simply the quiet/signaling NaN checking flow
> in patch 2 & 3
> - Add patch 4 to fix pseudo-NaN handling in FPATAN/FYL2XP1/FYL2X helpers
>
> Changes in v2
> - Merged v1 patch 2 & 3 to v2 patch 3, v1 patch 4 & 5 to v2 patch 4
> - Added new v2 patch 2 to refactor the IEEE format NaN classification
> functions (float16, bfloat16, float32, float64) to use internal helper
> functions, reducing code duplication and improving maintainability.
> The OCP FP8 NaN classification functions follow the same pattern.
> - Refactored softfloat implementation to use capability-based FloatFmt
> flags (no_infinity, limited_nan, overflow_raises_invalid, normal_frac_max)
> instead of monolithic flags
> - Removed ocp_fp8e5m2_no_signal_nan and ocp_fp8_same_canonical_nan flags
> from float_status; now using local float_status with no_signaling_nans
> and default_nan_pattern for RISC-V Zvfofp8min instructions
> - Rebased on latest riscv-to-apply.next with zvfbfa v3 patchset
>
> v3: <20260204051756.667397-1-max.chou@sifive.com>
> v2: <20260127063723.442734-1-max.chou@sifive.com>
> v1: <20260108151650.16329-1-max.chou@sifive.com>
>
> References
> * OCP FP8 specification:
> https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1
> * Zvfofp8min specification (v0.2.1 commit e1e20a7):
> https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp8min.adoc
> * Zvfofp4min specification (v0.1 commit e1e20a7):
> https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp4min.adoc
>
> Based-on: <20260304132514.2889449-1-max.chou@sifive.com>
> ([v4,0/9] Add Zvfbfa extension support)
> Based-on: <20260226071817.1417875-1-max.chou@sifive.com>
> ([v2,0/2] fpu: Fix OCP FP8 E4M3 conversion issues)
>
> rnax
>
>
> Max Chou (14):
> target/riscv: rvv: Fix NOP_UU_B vs2 width
> target/riscv: Add cfg properity for Zvfofp8min extension
> target/riscv: Add implied rules for Zvfofp8min extension
> target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16
> conversion for Zvfofp8min extension
> target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8
> conversion for Zvfofp8min extension
> target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction for Zvfofp8min
> extension
> target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions
> for Zvfofp8min extension
> target/riscv: Expose Zvfofp8min properity
> disas/riscv: Add support of Zvfofp8min extension
> target/riscv: Add cfg properity for Zvfofp4min extension
> target/riscv: Add implied rules for Zvfofp4min extension
> target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
> target/riscv: Expose Zvfofp4min properity
> disas/riscv: Add support of Zvfofp4min extension
>
> disas/riscv.c | 12 ++
> target/riscv/cpu.c | 29 ++++-
> target/riscv/cpu_cfg_fields.h.inc | 2 +
> target/riscv/helper.h | 15 +++
> target/riscv/insn32.decode | 8 ++
> target/riscv/insn_trans/trans_rvbf16.c.inc | 32 +++--
> target/riscv/insn_trans/trans_rvofp4.c.inc | 43 +++++++
> target/riscv/insn_trans/trans_rvofp8.c.inc | 105 ++++++++++++++++
> target/riscv/insn_trans/trans_rvv.c.inc | 39 ++++++
> target/riscv/tcg/tcg-cpu.c | 10 ++
> target/riscv/translate.c | 2 +
> target/riscv/vector_helper.c | 137 ++++++++++++++++++++-
> 12 files changed, 421 insertions(+), 13 deletions(-)
> create mode 100644 target/riscv/insn_trans/trans_rvofp4.c.inc
> create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
2026-03-04 15:13 ` Chao Liu
@ 2026-04-16 10:28 ` Max Chou
2026-04-17 1:59 ` Chao Liu
0 siblings, 1 reply; 30+ messages in thread
From: Max Chou @ 2026-04-16 10:28 UTC (permalink / raw)
To: Chao Liu
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On 2026-03-04 23:13, Chao Liu wrote:
> > +static bool trans_vfext_vf2(DisasContext *s, arg_rmr *a)
> > +{
> > + if (vext_zvfofp4min_check(s, a)) {
> Missing REQUIRE_FPU here.
>
> All other FP vector instruction translation functions
> in this series (trans_vfncvtbf16_sat_f_f_w, trans_vfncvt_f_f_q,
> trans_vfncvt_sat_f_f_q, trans_vfwcvtbf16_f_f_v,
> trans_vfncvtbf16_f_f_w) have REQUIRE_FPU at the top.
>
> Without it, this instruction could execute even when FPU
> is disabled.
According to the Zvfofp4min specification,
"The vfext.vf2 instruction does not access the fcsr and is not considered
a floating-point instruction for the purposes of the floating-point
context status (FS) settings."
As a result, the vfext.vf2 instruction will not raise an illegal
instruction exception when the mstatus.fs flag is disabled.
rnax
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction for Zvfofp4min extension
2026-04-16 10:28 ` Max Chou
@ 2026-04-17 1:59 ` Chao Liu
0 siblings, 0 replies; 30+ messages in thread
From: Chao Liu @ 2026-04-17 1:59 UTC (permalink / raw)
To: Max Chou
Cc: qemu-devel, qemu-riscv, Palmer Dabbelt, Alistair Francis,
Daniel Henrique Barboza, Weiwei Li, Liu Zhiwei
On Thu, Apr 16, 2026 at 06:28:04PM +0800, Max Chou wrote:
> On 2026-03-04 23:13, Chao Liu wrote:
> > > +static bool trans_vfext_vf2(DisasContext *s, arg_rmr *a)
> > > +{
> > > + if (vext_zvfofp4min_check(s, a)) {
> > Missing REQUIRE_FPU here.
> >
> > All other FP vector instruction translation functions
> > in this series (trans_vfncvtbf16_sat_f_f_w, trans_vfncvt_f_f_q,
> > trans_vfncvt_sat_f_f_q, trans_vfwcvtbf16_f_f_v,
> > trans_vfncvtbf16_f_f_w) have REQUIRE_FPU at the top.
> >
> > Without it, this instruction could execute even when FPU
> > is disabled.
>
> According to the Zvfofp4min specification,
>
> "The vfext.vf2 instruction does not access the fcsr and is not considered
> a floating-point instruction for the purposes of the floating-point
> context status (FS) settings."
>
Thanks for the clarification.
> As a result, the vfext.vf2 instruction will not raise an illegal
> instruction exception when the mstatus.fs flag is disabled.
That makes sense, since it doesn't access fcsr, the REQUIRE_FPU guard
would be incorrect here.
Thanks,
Chao
>
> rnax
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2026-04-17 2:00 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 13:39 [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
2026-03-04 13:39 ` [PATCH v4 01/14] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
2026-03-05 2:32 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 02/14] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
2026-03-04 15:01 ` Chao Liu
2026-03-05 2:39 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 03/14] target/riscv: Add implied rules " Max Chou
2026-03-05 2:40 ` Alistair Francis
2026-03-04 13:39 ` [PATCH v4 04/14] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion " Max Chou
2026-03-04 15:02 ` Chao Liu
2026-03-04 13:39 ` [PATCH v4 05/14] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 " Max Chou
2026-03-04 15:03 ` Chao Liu
2026-03-04 13:39 ` [PATCH v4 06/14] target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction " Max Chou
2026-03-04 13:39 ` [PATCH v4 07/14] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions " Max Chou
2026-03-04 15:06 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 08/14] target/riscv: Expose Zvfofp8min properity Max Chou
2026-03-04 15:06 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 09/14] disas/riscv: Add support of Zvfofp8min extension Max Chou
2026-03-04 13:40 ` [PATCH v4 10/14] target/riscv: Add cfg properity for Zvfofp4min extension Max Chou
2026-03-04 15:07 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 11/14] target/riscv: Add implied rules " Max Chou
2026-03-04 13:40 ` [PATCH v4 12/14] target/riscv: rvv: Add vfext.vf2 instruction " Max Chou
2026-03-04 15:13 ` Chao Liu
2026-04-16 10:28 ` Max Chou
2026-04-17 1:59 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 13/14] target/riscv: Expose Zvfofp4min properity Max Chou
2026-03-04 15:14 ` Chao Liu
2026-03-04 13:40 ` [PATCH v4 14/14] disas/riscv: Add support of Zvfofp4min extension Max Chou
2026-03-04 15:20 ` [PATCH v4 00/14] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Chao Liu
2026-04-14 20:41 ` Daniel Henrique Barboza
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.