Skip to contentSkip to conversation

target/riscv: Add RISC-V Zvfofp8min extension support

PATCH Superseded Max Chou 2 participants 13 messages Apr 27 – May 27 RISC-V

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Max Chou

author
#0 lore raw

v5 cover target/riscv: Add RISC-V Zvfofp8min extension support

This patchset adds support for the RISC-V Zvfofp8min isa extension that provide conversion operations for OCP FP formats.

* riscv-isa-manual tag: https://github.com/riscv/riscv-isa-manual/releases/tag/zvfofp8min-0.9

Zvfofp8min (v0.9):
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)

Changes in v5
- Drop Zvfofp4min which is not going through the RVIA ratification process yet.
- Fix typos.
- Rebase on riscv-to-apply.next (commit bf76a00)

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

v4: <[email protected]>
v3: <[email protected]>
v2: <[email protected]>
v1: <[email protected]>

References
* OCP FP8 specification:
https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1

Max Chou (9):
target/riscv: rvv: Fix NOP_UU_B vs2 width
target/riscv: Add cfg property 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 property
disas/riscv: Add support of Zvfofp8min extension

 disas/riscv.c                              |   9 ++
 target/riscv/cpu.c                         |  15 ++-
 target/riscv/cpu_cfg_fields.h.inc          |   1 +
 target/riscv/helper.h                      |  12 +++
 target/riscv/insn32.decode                 |   5 +
 target/riscv/insn_trans/trans_rvbf16.c.inc |  32 +++++--
 target/riscv/insn_trans/trans_rvofp8.c.inc | 105 +++++++++++++++++++++
 target/riscv/insn_trans/trans_rvv.c.inc    |  39 ++++++++
 target/riscv/tcg/tcg-cpu.c                 |   5 +
 target/riscv/translate.c                   |   1 +
 target/riscv/vector_helper.c               | 104 +++++++++++++++++++-
 11 files changed, 315 insertions(+), 13 deletions(-)
 create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
Signature · 1 line
2.52.0
author
#1 lore raw

PATCH v5 1/9 target/riscv: rvv: Fix NOP_UU_B vs2 width

---
 target/riscv/vector_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/vector_helper.c +1 -1
index 538168efc9..60e2d42301 100644
@@ -4973,7 +4973,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. */
Signature · 1 line
2.52.0
author
#2 lore raw

PATCH v5 2/9 target/riscv: Add cfg property for Zvfofp8min extension

In reply to Max Chou

According to the ISA spec of Zvfofp8min extension,

"The Zvfofp8min extension requires on the Zve32f extension."

---
 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(-)
target/riscv/cpu.c +1 -0
index ce15a17c37..855c6bd4a9 100644
@@ -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),
target/riscv/cpu_cfg_fields.h.inc +1 -0
index 734fa079f2..f9cd79bae0 100644
@@ -105,6 +105,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)
target/riscv/tcg/tcg-cpu.c +5 -0
index f3f7808895..40e7c72976 100644
@@ -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;
target/riscv/vector_helper.c +2 -1
index 60e2d42301..73437c1d20 100644
@@ -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 {
Signature · 1 line
2.52.0
author
#3 lore raw

PATCH v5 3/9 target/riscv: Add implied rules for Zvfofp8min extension

In reply to Max Chou

Add implied rules to enable the implied extensions of Zvfofp8min extension recursively.

---
 target/riscv/cpu.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
target/riscv/cpu.c +11 -2
index 855c6bd4a9..3746c79b01 100644
@@ -2512,6 +2512,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 = {
@@ -2649,8 +2658,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
Signature · 1 line
2.52.0
author
#4 lore raw

PATCH v5 4/9 target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion for Zvfofp8min extension

In reply to Max Chou

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

---
 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(-)
target/riscv/helper.h +12 -0
index 54d2331966..508314e154 100644
@@ -1249,6 +1249,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)
target/riscv/insn_trans/trans_rvbf16.c.inc +12 -4
index 066dc364c5..86eb86f615 100644
@@ -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;
     }
target/riscv/vector_helper.c +98 -1

111 lines not on this page · raw message

Signature · 1 line
2.52.0
author
#5 lore raw

PATCH v5 5/9 target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 conversion for Zvfofp8min extension

In reply to Max Chou

According to the Zvfofp8min extension, the vfncvtbf16.f.f.w instruction supports BF16 to OFP8 conversion without saturation 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

---
 target/riscv/insn_trans/trans_rvbf16.c.inc | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
target/riscv/insn_trans/trans_rvbf16.c.inc +12 -4
index 86eb86f615..7e9b0a53a4 100644
@@ -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;
     }
Signature · 1 line
2.52.0
author
#6 lore raw

PATCH v5 6/9 target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction for Zvfofp8min extension

In reply to Max Chou

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

---
 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
target/riscv/insn32.decode +3 -0
index 6e35c4b1e6..49201c0c20 100644
@@ -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
target/riscv/insn_trans/trans_rvofp8.c.inc new file +42 -0

42 lines not on this page · raw message

target/riscv/translate.c +1 -0
index 81087e0a5d..88d6efbc80 100644
@@ -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 "decode-xlrbr.c.inc"
Signature · 1 line
2.52.0
author
#7 lore raw

PATCH v5 7/9 target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions for Zvfofp8min extension

In reply to Max Chou

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

---
 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(+)
target/riscv/insn32.decode +2 -0
index 49201c0c20..f2b413c7d4 100644
@@ -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 ***
target/riscv/insn_trans/trans_rvofp8.c.inc +63 -0

72 lines not on this page · raw message

target/riscv/insn_trans/trans_rvv.c.inc +39 -0
index 5b72926b3c..2108a0fd4c 100644
@@ -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.
  *
Signature · 1 line
2.52.0
author
#8 lore raw

PATCH v5 8/9 target/riscv: Expose Zvfofp8min property

In reply to Max Chou
---
 target/riscv/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
index 3746c79b01..4bd7075427 100644
@@ -1273,6 +1273,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
     MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false),
     MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
     MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false),
+    MULTI_EXT_CFG_BOOL("zvfofp8min", ext_zvfofp8min, false),
     MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true),
     MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false),
     MULTI_EXT_CFG_BOOL("sspm", ext_sspm, false),
Signature · 1 line
2.52.0
author
#9 lore raw

PATCH v5 9/9 disas/riscv: Add support of Zvfofp8min extension

In reply to Max Chou

This patch adds support to disassemble Zvfofp8min instructions.

---
 disas/riscv.c | 9 +++++++++
 1 file changed, 9 insertions(+)
disas/riscv.c +9 -0
index d416a4d6b3..8a169deba0 100644
@@ -985,6 +985,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 */
@@ -2255,6 +2258,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 */
@@ -3631,7 +3637,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:
Signature · 1 line
2.52.0
author
#10 lore raw
In reply to Max Chou

Gental ping.

Quoted 94 lines · Max Chou

This patchset adds support for the RISC-V Zvfofp8min isa extension that provide conversion operations for OCP FP formats.

* riscv-isa-manual tag: https://github.com/riscv/riscv-isa-manual/releases/tag/zvfofp8min-0.9

Zvfofp8min (v0.9):
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)

Changes in v5
- Drop Zvfofp4min which is not going through the RVIA ratification process yet.
- Fix typos.
- Rebase on riscv-to-apply.next (commit bf76a00)

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

v4: <[email protected]>
v3: <[email protected]>
v2: <[email protected]>
v1: <[email protected]>

References
* OCP FP8 specification:
https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1

Max Chou (9):
target/riscv: rvv: Fix NOP_UU_B vs2 width
target/riscv: Add cfg property 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 property
disas/riscv: Add support of Zvfofp8min extension

 disas/riscv.c                              |   9 ++
 target/riscv/cpu.c                         |  15 ++-
 target/riscv/cpu_cfg_fields.h.inc          |   1 +
 target/riscv/helper.h                      |  12 +++
 target/riscv/insn32.decode                 |   5 +
 target/riscv/insn_trans/trans_rvbf16.c.inc |  32 +++++--
 target/riscv/insn_trans/trans_rvofp8.c.inc | 105 +++++++++++++++++++++
 target/riscv/insn_trans/trans_rvv.c.inc    |  39 ++++++++
 target/riscv/tcg/tcg-cpu.c                 |   5 +
 target/riscv/translate.c                   |   1 +
 target/riscv/vector_helper.c               | 104 +++++++++++++++++++-
 11 files changed, 315 insertions(+), 13 deletions(-)
 create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc
Signature · 1 line
2.52.0
#11 lore raw

Hi Max!

Quoted 1 line · Max Chou

Gental ping.

I believe we'll need a resend with a rebase due to changes done in the last PR, in particular a change I did where I removed the riscv_cpu_* arrays. In other words: we don't need patch 8 anymore.

Thanks,
Daniel

Quoted 96 lines · Max Chou
Quoted 94 lines

This patchset adds support for the RISC-V Zvfofp8min isa extension that provide conversion operations for OCP FP formats.

* riscv-isa-manual tag: https://github.com/riscv/riscv-isa-manual/releases/tag/zvfofp8min-0.9

Zvfofp8min (v0.9):
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)

Changes in v5
- Drop Zvfofp4min which is not going through the RVIA ratification process yet.
- Fix typos.
- Rebase on riscv-to-apply.next (commit bf76a00)

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

v4: <[email protected]>
v3: <[email protected]>
v2: <[email protected]>
v1: <[email protected]>

References
* OCP FP8 specification:

   https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1

Max Chou (9):
target/riscv: rvv: Fix NOP_UU_B vs2 width
target/riscv: Add cfg property 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 property
disas/riscv: Add support of Zvfofp8min extension

  disas/riscv.c                              |   9 ++
  target/riscv/cpu.c                         |  15 ++-
  target/riscv/cpu_cfg_fields.h.inc          |   1 +
  target/riscv/helper.h                      |  12 +++
  target/riscv/insn32.decode                 |   5 +
  target/riscv/insn_trans/trans_rvbf16.c.inc |  32 +++++--
  target/riscv/insn_trans/trans_rvofp8.c.inc | 105 +++++++++++++++++++++
  target/riscv/insn_trans/trans_rvv.c.inc    |  39 ++++++++
  target/riscv/tcg/tcg-cpu.c                 |   5 +
  target/riscv/translate.c                   |   1 +
  target/riscv/vector_helper.c               | 104 +++++++++++++++++++-
  11 files changed, 315 insertions(+), 13 deletions(-)

create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc

Signature · 1 line
2.52.0
author
#12 lore raw

Hi Daniel,

Thank you for the information.
I'll rebase this patchset and send out v6

Thank,
rnax

Quoted 111 lines · Daniel Henrique Barboza

Hi Max!

Quoted 1 line · Max Chou

Gental ping.

I believe we'll need a resend with a rebase due to changes done in the last PR, in particular a change I did where I removed the riscv_cpu_* arrays. In other words: we don't need patch 8 anymore.

Thanks,
Daniel

Quoted 96 lines · Max Chou
Quoted 94 lines

This patchset adds support for the RISC-V Zvfofp8min isa extension that provide conversion operations for OCP FP formats.

* riscv-isa-manual tag: https://github.com/riscv/riscv-isa-manual/releases/tag/zvfofp8min-0.9

Zvfofp8min (v0.9):
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)

Changes in v5
- Drop Zvfofp4min which is not going through the RVIA ratification process yet.
- Fix typos.
- Rebase on riscv-to-apply.next (commit bf76a00)

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

v4: <[email protected]>
v3: <[email protected]>
v2: <[email protected]>
v1: <[email protected]>

References
* OCP FP8 specification:

   https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1

Max Chou (9):
target/riscv: rvv: Fix NOP_UU_B vs2 width
target/riscv: Add cfg property 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 property
disas/riscv: Add support of Zvfofp8min extension

  disas/riscv.c                              |   9 ++
  target/riscv/cpu.c                         |  15 ++-
  target/riscv/cpu_cfg_fields.h.inc          |   1 +
  target/riscv/helper.h                      |  12 +++
  target/riscv/insn32.decode                 |   5 +
  target/riscv/insn_trans/trans_rvbf16.c.inc |  32 +++++--
  target/riscv/insn_trans/trans_rvofp8.c.inc | 105 +++++++++++++++++++++
  target/riscv/insn_trans/trans_rvv.c.inc    |  39 ++++++++
  target/riscv/tcg/tcg-cpu.c                 |   5 +
  target/riscv/translate.c                   |   1 +
  target/riscv/vector_helper.c               | 104 +++++++++++++++++++-
  11 files changed, 315 insertions(+), 13 deletions(-)

create mode 100644 target/riscv/insn_trans/trans_rvofp8.c.inc

Signature · 1 line
2.52.0