Skip to contentSkip to conversation

Hexagon: Add v79, v81 HVX fp/vcvt instructions

PATCH In review Brian Cain 2 participants 6 messages Oct 30 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

v3 cover Hexagon: Add v79, v81 HVX fp/vcvt instructions

Add support for some missing HVX IEEE fp instructions.

In v3:
- Rebased, reworded some comments from feedback.

In v2:
- moved tests into corresponding feature commits

v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/

Brian Cain (3):
target/hexagon: add v79 HVX vcvt2 instructions target/hexagon: add v79 HVX FP8 instructions target/hexagon: add v81 HVX FP8 and qf16 conversions

 target/hexagon/mmvec/hvx_ieee_fp.h           |  35 ++
 target/hexagon/mmvec/macros.h                |  20 +
 target/hexagon/mmvec/mmvec.h                 |   1 +
 target/hexagon/attribs_def.h.inc             |   1 +
 target/hexagon/reg_fields_def.h.inc          |   1 +
 target/hexagon/genptr.c                      |   7 +-
 target/hexagon/mmvec/hvx_ieee_fp.c           | 146 +++++-
 tests/tcg/hexagon/check_rev_gating.c         |  30 ++
 tests/tcg/hexagon/fp_hvx_v79.c               | 443 +++++++++++++++++++
 tests/tcg/hexagon/qfloat_v81.c               | 111 +++++
 target/hexagon/tag_rev_info.c.inc            |  18 +
 target/hexagon/imported/mmvec/encode_ext.def |  18 +
 target/hexagon/imported/mmvec/ext.idef       | 117 +++++
 tests/tcg/hexagon/meson.build                |   2 +
 14 files changed, 944 insertions(+), 6 deletions(-)
 create mode 100644 tests/tcg/hexagon/fp_hvx_v79.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/3 target/hexagon: add v79 HVX vcvt2 instructions

Add V6_vcvt2_{hf_ub,hf_b,ub_hf,b_hf}, which differ from vcvt only in element interleaving.

---
 tests/tcg/hexagon/check_rev_gating.c         |   6 +
 tests/tcg/hexagon/fp_hvx_v79.c               | 110 +++++++++++++++++++
 target/hexagon/tag_rev_info.c.inc            |   4 +
 target/hexagon/imported/mmvec/encode_ext.def |   4 +
 target/hexagon/imported/mmvec/ext.idef       |  33 ++++++
 tests/tcg/hexagon/meson.build                |   2 +
 6 files changed, 159 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx_v79.c
tests/tcg/hexagon/check_rev_gating.c +6 -0
index 3a5ed9c71ca..529cae70d85 100644
@@ -131,6 +131,10 @@ TRY_FUNC(v83_vsfadd,
 
 TRY_FUNC(v79hvx_vmerge_qf,
          ".word 0x1f01e0e2    /* v2 = vmerge(v0.x, v1.w) */\n")
+TRY_FUNC(v79hvx_vcvt2_hf_ub,
+         ".word 0x1ed5e0e2    /* v3:2.hf = vcvt2(v0.ub) */\n")
+TRY_FUNC(v79hvx_vcvt2_b_hf,
+         ".word 0x1ac1e0c2    /* v2.b = vcvt2(v0.hf, v1.hf) */\n")
 
 TRY_FUNC(v81hvx_veqhf,
          ".word 0x1f82c11c    /* q0 = vcmp.eq(v1.hf, v2.hf) */\n")
@@ -177,6 +181,8 @@ int main(void)
     assert(try_v83_vsfadd() == SIGILL);
 
     assert(try_v79hvx_vmerge_qf() == SIGILL);
+    assert(try_v79hvx_vcvt2_hf_ub() == SIGILL);
+    assert(try_v79hvx_vcvt2_b_hf() == SIGILL);
 
     assert(try_v81hvx_veqhf() == SIGILL);
 
tests/tcg/hexagon/fp_hvx_v79.c new file +110 -0

110 lines not on this page · raw message

target/hexagon/tag_rev_info.c.inc +4 -0
index da0b1a648cf..ea586e1613e 100644
@@ -664,6 +664,10 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
     },
     [V6_vconv_qf32_sf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt2_b_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt2_hf_b] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt2_hf_ub] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt2_ub_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_qf16] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_qf32] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
target/hexagon/imported/mmvec/encode_ext.def +4 -0
index 34e63b89743..9605e870a1e 100644
@@ -846,12 +846,16 @@ DEF_ENC(V6_vcvt_sf_hf,"00011110--0-0100PP1uuuuu100ddddd")
 DEF_ENC(V6_vcvt_hf_sf,"00011111011vvvvvPP1uuuuu001ddddd")
 DEF_ENC(V6_vcvt_hf_ub,"00011110--0-0100PP1uuuuu001ddddd")
 DEF_ENC(V6_vcvt_hf_b,"00011110--0-0100PP1uuuuu010ddddd")
+DEF_ENC(V6_vcvt2_hf_ub,"0001111011010101PP1uuuuu111ddddd")
+DEF_ENC(V6_vcvt2_hf_b,"0001111011010101PP1uuuuu110ddddd")
 DEF_ENC(V6_vcvt_hf_uh,"00011110--0-0100PP1uuuuu101ddddd")
 DEF_ENC(V6_vcvt_hf_h,"00011110--0-0100PP1uuuuu111ddddd")
 DEF_ENC(V6_vcvt_uh_hf,"00011110--0--101PP1uuuuu000ddddd")
 DEF_ENC(V6_vcvt_h_hf,"00011110--0-0110PP1uuuuu000ddddd")
 DEF_ENC(V6_vcvt_ub_hf,"00011111110vvvvvPP1uuuuu101ddddd")
 DEF_ENC(V6_vcvt_b_hf,"00011111110vvvvvPP1uuuuu110ddddd")
+DEF_ENC(V6_vcvt2_ub_hf,"00011010110vvvvvPP1uuuuu111ddddd")
+DEF_ENC(V6_vcvt2_b_hf,"00011010110vvvvvPP1uuuuu110ddddd")
 
 /* IEEE FP vconv instructions */
 DEF_ENC(V6_vconv_sf_w,"00011110--0--101PP1uuuuu011ddddd")
target/hexagon/imported/mmvec/ext.idef +33 -0
index 3592930777e..b9a4858d0c1 100644
@@ -3103,6 +3103,25 @@ ITERATOR_INSN_IEEE_FP_DOUBLE_16(32,  vcvt_hf_b,  "Vdd32.hf=vcvt(Vu32.b)",
     VddV.v[1].hf[2*i]   = int64_to_float16_scalbn(VuV.b[4*i+2], float_round_nearest_even, 0);
     VddV.v[1].hf[2*i+1] = int64_to_float16_scalbn(VuV.b[4*i+3], float_round_nearest_even, 0))
 
+/*
+ * The vcvt2 variants differ from vcvt only in which source elements land in
+ * which half of the result pair: the even source bytes go to the first
+ * vector and the odd ones to the second.
+ */
+ITERATOR_INSN_IEEE_FP_DOUBLE_16(32,  vcvt2_hf_ub, "Vdd32.hf=vcvt2(Vu32.ub)",
+    "Vector IEEE cvt2 from int: ub widen to hf",
+    VddV.v[0].hf[2*i]   = uint64_to_float16_scalbn(VuV.ub[4*i], 0, &env->hvx_fp_status);
+    VddV.v[0].hf[2*i+1] = uint64_to_float16_scalbn(VuV.ub[4*i+2], 0, &env->hvx_fp_status);
+    VddV.v[1].hf[2*i]   = uint64_to_float16_scalbn(VuV.ub[4*i+1], 0, &env->hvx_fp_status);
+    VddV.v[1].hf[2*i+1] = uint64_to_float16_scalbn(VuV.ub[4*i+3], 0, &env->hvx_fp_status))
+
+ITERATOR_INSN_IEEE_FP_DOUBLE_16(32,  vcvt2_hf_b,  "Vdd32.hf=vcvt2(Vu32.b)",
+    "Vector IEEE cvt2 from int: b widen to hf",
+    VddV.v[0].hf[2*i]   = int64_to_float16_scalbn(VuV.b[4*i], 0, &env->hvx_fp_status);
+    VddV.v[0].hf[2*i+1] = int64_to_float16_scalbn(VuV.b[4*i+2], 0, &env->hvx_fp_status);
+    VddV.v[1].hf[2*i]   = int64_to_float16_scalbn(VuV.b[4*i+1], 0, &env->hvx_fp_status);
+    VddV.v[1].hf[2*i+1] = int64_to_float16_scalbn(VuV.b[4*i+3], 0, &env->hvx_fp_status))
+
 ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vcvt_sf_hf, "Vdd32.sf=vcvt(Vu32.hf)",
     "Vector IEEE cvt: hf widen to sf",
     VddV.v[0].sf[i] = f16_to_f32(VuV.hf[2*i]);
@@ -3139,6 +3158,20 @@ ITERATOR_INSN_IEEE_FP_16_32(32, vcvt_b_hf,  "Vd32.b=vcvt(Vu32.hf,Vv32.hf)",
     VdV.b[4*i+2] = float16_to_int8_scalbn(VvV.hf[2*i], float_round_nearest_even, 0, &env->hvx_fp_status);
     VdV.b[4*i+3] = float16_to_int8_scalbn(VvV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status))
 
+ITERATOR_INSN_IEEE_FP_16_32(32, vcvt2_ub_hf, "Vd32.ub=vcvt2(Vu32.hf,Vv32.hf)",
+    "Vector cvt2 to int: hf narrow to ub",
+    VdV.ub[4*i]   = float16_to_uint8_scalbn(VuV.hf[2*i], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.ub[4*i+1] = float16_to_uint8_scalbn(VvV.hf[2*i], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.ub[4*i+2] = float16_to_uint8_scalbn(VuV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.ub[4*i+3] = float16_to_uint8_scalbn(VvV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status))
+
+ITERATOR_INSN_IEEE_FP_16_32(32, vcvt2_b_hf,  "Vd32.b=vcvt2(Vu32.hf,Vv32.hf)",
+    "Vector cvt2 to int: hf narrow to b",
+    VdV.b[4*i]   = float16_to_int8_scalbn(VuV.hf[2*i], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.b[4*i+1] = float16_to_int8_scalbn(VvV.hf[2*i], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.b[4*i+2] = float16_to_int8_scalbn(VuV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status);
+    VdV.b[4*i+3] = float16_to_int8_scalbn(VvV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status))
+
 ITERATOR_INSN_SHIFT_SLOT_FLT(32, vconv_w_sf,"Vd32.w=Vu32.sf",
     "Vector conversion of sf32 format to int w",
     VdV.w[i] = conv_w_sf(VuV.sf[i], &env->hvx_fp_status))
tests/tcg/hexagon/meson.build +2 -0
index 2b924598640..c38d2bea84f 100644
@@ -54,6 +54,8 @@ tests += {
                         'qemu_args': ['-cpu', 'v73,ieee-fp=false']},
   'fp_hvx_cvt.c': {'cflags': [cflags, '-mv73', '-mhvx', '-mhvx-ieee-fp']},
   'fp_hvx_cmp.c': {'cflags': [cflags, '-mv73', '-mhvx', '-mhvx-ieee-fp']},
+  'fp_hvx_v79.c': {'cflags': [cflags, '-mv79', '-mhvx', '-mhvx-ieee-fp'],
+                   'qemu_args': ['-cpu', 'v79']},
   'v81_hvx.c': {'cflags': [cflags, '-mv81', '-mhvx', '-mhvx-ieee-fp'],
                'qemu_args': ['-cpu', 'v81']},
   'qfloat_v81.c': {'cflags': [cflags, '-mv81', '-mhvx', '-mhvx-ieee-fp'],
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v3 2/3 target/hexagon: add v79 HVX FP8 instructions

In reply to Brian Cain

Add the E4M3FNUZ FP8 add, sub, mpy, convert, neg, abs, min and max instructions, and the USR.FPSAT bit that controls saturation.

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  27 ++
 target/hexagon/mmvec/mmvec.h                 |   1 +
 target/hexagon/attribs_def.h.inc             |   1 +
 target/hexagon/reg_fields_def.h.inc          |   1 +
 target/hexagon/genptr.c                      |   7 +-
 target/hexagon/mmvec/hvx_ieee_fp.c           | 125 ++++++-
 tests/tcg/hexagon/check_rev_gating.c         |  18 +
 tests/tcg/hexagon/fp_hvx_v79.c               | 361 ++++++++++++++++++-
 target/hexagon/tag_rev_info.c.inc            |  12 +
 target/hexagon/imported/mmvec/encode_ext.def |  12 +
 target/hexagon/imported/mmvec/ext.idef       |  78 ++++
 11 files changed, 623 insertions(+), 20 deletions(-)
target/hexagon/mmvec/hvx_ieee_fp.h +27 -0
index 6efc39eb203..229ee0ee516 100644
@@ -35,6 +35,33 @@ uint16_t cmpgt_hf(float16 a1, float16 a2, float_status *fp_status);
 uint32_t cmpeq_sf(float32 a1, float32 a2, float_status *fp_status);
 uint16_t cmpeq_hf(float16 a1, float16 a2, float_status *fp_status);
 
+/*
+ * FP8 instructions.  The FP8 format is E4M3FNUZ: one sign bit, four exponent
+ * bits (bias 8) and three fraction bits, with no infinities and no negative
+ * zero.  The encoding that would be negative zero, 0x80, is the only NaN.
+ * softfloat has no such format, so values are widened to float16 (which holds
+ * every FP8 value exactly) to operate on them.
+ */
+#define F8_NAN 0x80
+#define F8_MAX_NORM 0x7f
+
+float16 f8_to_f16(uint8_t a, float_status *fp_status);
+/*
+ * Narrow with round-to-nearest-even.  Infinity and results too large for FP8
+ * become the largest normal number if sat is set and NaN otherwise.
+ */
+uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status);
+
+float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
+float16 fp_sub_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
+float16 fp_mult_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
+float16 fp_mult_hf_f8_acc(uint8_t a1, uint8_t a2, float16 acc,
+                          float_status *fp_status);
+uint8_t fp_neg_f8(uint8_t a);
+uint8_t fp_abs_f8(uint8_t a);
+uint8_t fp_min_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
+uint8_t fp_max_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
+
 /* IEEE BFloat instructions */
 
 #define fp_mult_sf_bf(A, B) \
target/hexagon/mmvec/mmvec.h +1 -0
index de36e12e30a..7b8cce3a37b 100644
@@ -55,6 +55,7 @@ typedef struct {
         int8_t    b[MAX_VEC_SIZE_BYTES / 1];
         float32  sf[MAX_VEC_SIZE_BYTES / 4];
         float16  hf[MAX_VEC_SIZE_BYTES / 2];
+        uint8_t  f8[MAX_VEC_SIZE_BYTES / 1];
         bfloat16 bf[MAX_VEC_SIZE_BYTES / 2];
         /* qfloat "visible" mantissa/exponent, sans the extended bits below */
         int32_t  qf32[MAX_VEC_SIZE_BYTES / 4];
target/hexagon/attribs_def.h.inc +1 -0
index 96ad1fd2f8e..ac086cb099b 100644
@@ -205,6 +205,7 @@ DEF_ATTRIB(RESTRICT_TARGET, "Restricted branch target instruction", "", "")
 /* HVX IEEE FP extension attributes */
 DEF_ATTRIB(HVX_IEEE_FP, "HVX IEEE FP extension instruction", "", "")
 DEF_ATTRIB(HVX_IEEE_FP_ACC, "HVX IEEE FP accumulate instruction", "", "")
+DEF_ATTRIB(HVX_IEEE_FP_OUT_8, "HVX IEEE FP 8-bit output", "", "")
 DEF_ATTRIB(HVX_IEEE_FP_OUT_16, "HVX IEEE FP 16-bit output", "", "")
 DEF_ATTRIB(HVX_IEEE_FP_OUT_32, "HVX IEEE FP 32-bit output", "", "")
 DEF_ATTRIB(CVI_VX_NO_TMP_LD, "HVX multiply without tmp load", "", "")
target/hexagon/reg_fields_def.h.inc +1 -0
index 21babbbb982..2ae5d7ffe8e 100644
@@ -35,6 +35,7 @@ DEF_REG_FIELD(USR_LPCFG,          8, 2)
 DEF_REG_FIELD(USR_FPDAZ,         17, 1)
 
 DEF_REG_FIELD(USR_FPRND,         22, 2)
+DEF_REG_FIELD(USR_FPSAT,         24, 1)
 
 DEF_REG_FIELD(USR_FPINVE,        25, 1)
 DEF_REG_FIELD(USR_FPDBZE,        26, 1)
target/hexagon/genptr.c +6 -1
index 7ef36e336fa..255db6d35c9 100644
@@ -552,7 +552,12 @@ static inline void gen_write_ctrl_reg(DisasContext *ctx, int reg_num,
     if (reg_num == HEX_REG_P3_0_ALIASED) {
         gen_write_p3_0(ctx, val);
     } else {
-        const target_ulong reg_mask = reg_immut_masks[reg_num];
+        target_ulong reg_mask = reg_immut_masks[reg_num];
+        if (reg_num == HEX_REG_USR &&
+            ctx->hex_def->hex_version >= HEX_VER_V79) {
+            /* USR.FPSAT is reserved before v79 */
+            reg_mask &= ~fGET_REG_FIELD_MASK(USR_FPSAT);
+        }
         gen_masked_reg_write(val, hex_gpr[reg_num], reg_mask);
         tcg_gen_mov_tl(get_result_gpr(ctx, reg_num), val);
         if (reg_num == HEX_REG_QEMU_PKT_CNT) {
target/hexagon/mmvec/hvx_ieee_fp.c +120 -5

140 lines not on this page · raw message

tests/tcg/hexagon/check_rev_gating.c +18 -0
index 529cae70d85..df6cb426c62 100644
@@ -135,6 +135,18 @@ TRY_FUNC(v79hvx_vcvt2_hf_ub,
          ".word 0x1ed5e0e2    /* v3:2.hf = vcvt2(v0.ub) */\n")
 TRY_FUNC(v79hvx_vcvt2_b_hf,
          ".word 0x1ac1e0c2    /* v2.b = vcvt2(v0.hf, v1.hf) */\n")
+TRY_FUNC(v79hvx_vcvt_f8_hf,
+         ".word 0x1fe1e040    /* v0.f8 = vcvt(v0.hf, v1.hf) */\n")
+TRY_FUNC(v79hvx_vcvt_hf_f8,
+         ".word 0x1e05e0a2    /* v3:2.hf = vcvt(v0.f8) */\n")
+TRY_FUNC(v79hvx_vmpy_hf_f8,
+         ".word 0x1f80c0c0    /* v1:0.hf = vmpy(v0.f8, v0.f8) */\n")
+TRY_FUNC(v79hvx_vmpy_hf_f8_acc,
+         ".word 0x1f80c0e0    /* v1:0.hf += vmpy(v0.f8, v0.f8) */\n")
+TRY_FUNC(v79hvx_vfneg_f8,
+         ".word 0x1c66e0e2    /* v2.f8 = vfneg(v0.f8) */\n")
+TRY_FUNC(v79hvx_vfmin_f8,
+         ".word 0x1c61e082    /* v2.f8 = vfmin(v0.f8, v1.f8) */\n")
 
 TRY_FUNC(v81hvx_veqhf,
          ".word 0x1f82c11c    /* q0 = vcmp.eq(v1.hf, v2.hf) */\n")
@@ -183,6 +195,12 @@ int main(void)
     assert(try_v79hvx_vmerge_qf() == SIGILL);
     assert(try_v79hvx_vcvt2_hf_ub() == SIGILL);
     assert(try_v79hvx_vcvt2_b_hf() == SIGILL);
+    assert(try_v79hvx_vcvt_f8_hf() == SIGILL);
+    assert(try_v79hvx_vcvt_hf_f8() == SIGILL);
+    assert(try_v79hvx_vmpy_hf_f8() == SIGILL);
+    assert(try_v79hvx_vmpy_hf_f8_acc() == SIGILL);
+    assert(try_v79hvx_vfneg_f8() == SIGILL);
+    assert(try_v79hvx_vfmin_f8() == SIGILL);
 
     assert(try_v81hvx_veqhf() == SIGILL);
 
tests/tcg/hexagon/fp_hvx_v79.c +347 -14

379 lines not on this page · raw message

target/hexagon/tag_rev_info.c.inc +12 -0
index ea586e1613e..92559052516 100644
@@ -648,6 +648,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
     },
     [V6_set_qfext] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vabs_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vabs_qf16_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vabs_qf16_qf16] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
@@ -656,6 +657,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
     },
     [V6_vabs_qf32_sf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vadd_hf_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vconv_qf16_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vconv_qf16_qf16] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
@@ -668,11 +670,20 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
     [V6_vcvt2_hf_b] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vcvt2_hf_ub] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vcvt2_ub_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt_f8_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vcvt_hf_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vfmax_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vfmin_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vfneg_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_qf16] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_qf32] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vilog2_sf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vmerge_qf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vmpy_hf_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vmpy_hf_f8_acc] = {
+        .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
+    },
     [V6_vmpy_rt_hf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vmpy_rt_qf16] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vmpy_rt_sf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
@@ -684,6 +695,7 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
         .introduced = HEX_VER_V79, .removed = HEX_VER_NONE
     },
     [V6_vneg_qf32_sf] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
+    [V6_vsub_hf_f8] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vsub_hf_mix] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
     [V6_vsub_sf_mix] = { .introduced = HEX_VER_V79, .removed = HEX_VER_NONE },
 
target/hexagon/imported/mmvec/encode_ext.def +12 -0
index 9605e870a1e..5941e09df93 100644
@@ -882,6 +882,18 @@ DEF_ENC(V6_veqhf_or,"00011100100vvvvvPP1uuuuu010111xx")
 DEF_ENC(V6_veqsf_xor,"00011100100vvvvvPP1uuuuu100011xx")
 DEF_ENC(V6_veqhf_xor,"00011100100vvvvvPP1uuuuu100111xx")
 
+/* FP8 instructions */
+DEF_ENC(V6_vadd_hf_f8,"00011111100vvvvvPP0uuuuu100ddddd")
+DEF_ENC(V6_vsub_hf_f8,"00011111100vvvvvPP0uuuuu101ddddd")
+DEF_ENC(V6_vmpy_hf_f8,"00011111100vvvvvPP0uuuuu110ddddd")
+DEF_ENC(V6_vmpy_hf_f8_acc,"00011111100vvvvvPP0uuuuu111xxxxx")
+DEF_ENC(V6_vfmin_f8,"00011100011vvvvvPP1uuuuu100ddddd")
+DEF_ENC(V6_vfmax_f8,"00011100011vvvvvPP1uuuuu101ddddd")
+DEF_ENC(V6_vabs_f8,"00011100011--110PP1uuuuu110ddddd")
+DEF_ENC(V6_vfneg_f8,"00011100011--110PP1uuuuu111ddddd")
+DEF_ENC(V6_vcvt_f8_hf,"00011111111vvvvvPP1uuuuu010ddddd")
+DEF_ENC(V6_vcvt_hf_f8,"00011110--0--101PP1uuuuu101ddddd")
+
 /* BFLOAT instructions */
 DEF_ENC(V6_vmpy_sf_bf,"00011101010vvvvvPP1uuuuu100ddddd")
 DEF_ENC(V6_vmpy_sf_bf_acc,"00011101000vvvvvPP1uuuuu000xxxxx")
target/hexagon/imported/mmvec/ext.idef +78 -0

90 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] target/hexagon: add v79 HVX FP8 instructions

Quoted 5 lines · Brian Cain

Add the E4M3FNUZ FP8 add, sub, mpy, convert, neg, abs, min and max instructions, and the USR.FPSAT bit that controls saturation.

Quoted 14 lines
---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  27 ++
 target/hexagon/mmvec/mmvec.h                 |   1 +
 target/hexagon/attribs_def.h.inc             |   1 +
 target/hexagon/reg_fields_def.h.inc          |   1 +
 target/hexagon/genptr.c                      |   7 +-
 target/hexagon/mmvec/hvx_ieee_fp.c           | 125 ++++++-
 tests/tcg/hexagon/check_rev_gating.c         |  18 +
 tests/tcg/hexagon/fp_hvx_v79.c               | 361 ++++++++++++++++++-
 target/hexagon/tag_rev_info.c.inc            |  12 +
 target/hexagon/imported/mmvec/encode_ext.def |  12 +
 target/hexagon/imported/mmvec/ext.idef       |  78 ++++
 11 files changed, 623 insertions(+), 20 deletions(-)
author
#4 lore raw

PATCH v3 3/3 target/hexagon: add v81 HVX FP8 and qf16 conversions

In reply to Brian Cain

Add V6_vconv_qf16_f8 and V6_vconv_f8_qf16, which use FP8 with exponent bias 7.

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |   8 ++
 target/hexagon/mmvec/macros.h                |  20 ++++
 target/hexagon/mmvec/hvx_ieee_fp.c           |  21 ++++
 tests/tcg/hexagon/check_rev_gating.c         |   6 +
 tests/tcg/hexagon/qfloat_v81.c               | 111 +++++++++++++++++++
 target/hexagon/tag_rev_info.c.inc            |   2 +
 target/hexagon/imported/mmvec/encode_ext.def |   2 +
 target/hexagon/imported/mmvec/ext.idef       |   6 +
 8 files changed, 176 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +8 -0
index 229ee0ee516..996feae67b3 100644
@@ -52,6 +52,14 @@ float16 f8_to_f16(uint8_t a, float_status *fp_status);
  */
 uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status);
 
+/*
+ * The v81 conversions between FP8 and qf16 read the same encoding with
+ * exponent bias 7 instead of 8, so every value is twice as large.
+ * NaN is still 0x80 and narrowing never saturates.
+ */
+float16 f8_bias7_to_f16(uint8_t a, float_status *fp_status);
+uint8_t f16_to_f8_bias7(float16 a, float_status *fp_status);
+
 float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
 float16 fp_sub_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
 float16 fp_mult_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status);
target/hexagon/mmvec/macros.h +20 -0
index 0e643b29109..8ac685bdc57 100644
@@ -417,6 +417,26 @@
 
 #define fQF_VILOG2(TYPE, A, AEXT) qf_vilog2(TYPE, A, AEXT)
 
+/*
+ * Convert an FP8 element to the qf16 element (V).qf16[i].  FP8 is exactly
+ * representable in hf, so go through that.  The one FP8 NaN becomes the
+ * negative qf16 NaN.
+ */
+#define fCONVERT_F8_TO_QF16(V, A) \
+    do { \
+        if ((A) == F8_NAN) { \
+            (V).qf16[i] = extqf16_neg_nan >> 4; \
+            set_extended_bits(&(V), i, 16, \
+                              extqf16_neg_nan & EXT16_BITMASK); \
+        } else { \
+            unfloat u = fPARSEHF(f8_bias7_to_f16(A, &env->hvx_fp_status)); \
+            INIT_UNFLOAT(v) \
+            v.exp = E_MIN_EXTQF16; \
+            v.sign = 1; \
+            fQFADD(16, V, u, v); \
+        } \
+    } while (0)
+
 #define fCONVERT_QF32_TO_SF(A, AEXT) \
     (qfloat_is_extended(env) ? \
      conv_sf_extqf32(A, AEXT, CVI_QFRND_MODE) : legacy_conv_sf_qf32(A))
target/hexagon/mmvec/hvx_ieee_fp.c +21 -0
index 6394c175a13..be8bc9b9485 100644
@@ -215,6 +215,27 @@ uint8_t f16_to_f8(float16 a, bool sat, float_status *fp_status)
     return code ? sign | code : 0;
 }
 
+float16 f8_bias7_to_f16(uint8_t a, float_status *fp_status)
+{
+    float_status exact = { 0 };
+
+    /* Preserve NaN's default value from fp_status. */
+    return a == F8_NAN ? f8_to_f16(a, fp_status) :
+           float16_mul(f8_to_f16(a, fp_status), make_float16(0x4000), &exact);
+}
+
+uint8_t f16_to_f8_bias7(float16 a, float_status *fp_status)
+{
+    float_status halve = { 0 };
+
+    if (float16_is_any_nan(a)) {
+        return F8_NAN;
+    }
+    /* Halving only loses insignificant bits before FP8 rounding. */
+    return f16_to_f8(float16_mul(a, make_float16(0x3800), &halve), false,
+                     fp_status);
+}
+
 float16 fp_add_hf_f8(uint8_t a1, uint8_t a2, float_status *fp_status)
 {
     return float16_add(f8_to_f16(a1, fp_status), f8_to_f16(a2, fp_status),
tests/tcg/hexagon/check_rev_gating.c +6 -0
index df6cb426c62..015ce607ec7 100644
@@ -150,6 +150,10 @@ TRY_FUNC(v79hvx_vfmin_f8,
 
 TRY_FUNC(v81hvx_veqhf,
          ".word 0x1f82c11c    /* q0 = vcmp.eq(v1.hf, v2.hf) */\n")
+TRY_FUNC(v81hvx_vconv_qf16_f8,
+         ".word 0x1e0ce2a0    /* v1:0.qf16 = v2.f8 */\n")
+TRY_FUNC(v81hvx_vconv_f8_qf16,
+         ".word 0x1e0ce4e3    /* v3.f8 = v4.qf16 */\n")
 
 int main(void)
 {
@@ -203,6 +207,8 @@ int main(void)
     assert(try_v79hvx_vfmin_f8() == SIGILL);
 
     assert(try_v81hvx_veqhf() == SIGILL);
+    assert(try_v81hvx_vconv_qf16_f8() == SIGILL);
+    assert(try_v81hvx_vconv_f8_qf16() == SIGILL);
 
     assert(signals_handled == expected_signals);
 
tests/tcg/hexagon/qfloat_v81.c +111 -0

122 lines not on this page · raw message

target/hexagon/tag_rev_info.c.inc +2 -0
index 92559052516..61ada1f7bf9 100644
@@ -713,6 +713,8 @@ static const struct tag_rev_info tag_rev_info[XX_LAST_OPCODE] = {
     [V6_vconv_h_hf_rnd] = {
         .introduced = HEX_VER_V81, .removed = HEX_VER_NONE
     },
+    [V6_vconv_f8_qf16] = { .introduced = HEX_VER_V81, .removed = HEX_VER_NONE },
+    [V6_vconv_qf16_f8] = { .introduced = HEX_VER_V81, .removed = HEX_VER_NONE },
     [V6_vconv_bf_qf32] = { .introduced = HEX_VER_V81, .removed = HEX_VER_NONE },
 
     [V2_vallocframe_imm] = { .introduced = HEX_VER_V83,
target/hexagon/imported/mmvec/encode_ext.def +2 -0
index 5941e09df93..7139be12e59 100644
@@ -928,7 +928,9 @@ DEF_ENC(V6_vconv_bf_qf32,"00011110--0-0110PP1uuuuu111ddddd")
 DEF_ENC(V6_vconv_hf_qf16,"00011110--0-0100PP1uuuuu011ddddd")
 DEF_ENC(V6_vconv_hf_qf32,"00011110--0-0100PP1uuuuu110ddddd")
 DEF_ENC(V6_vconv_qf16_hf,"00011110--0-1100PP1uuuuu100ddddd")
+DEF_ENC(V6_vconv_qf16_f8,"00011110--0-1100PP1uuuuu101ddddd")
 DEF_ENC(V6_vconv_qf16_qf16,"00011110--0-1100PP1uuuuu110ddddd")
+DEF_ENC(V6_vconv_f8_qf16,"00011110--0-1100PP1uuuuu111ddddd")
 DEF_ENC(V6_vconv_qf32_qf32,"00011110--0-1101PP1uuuuu111ddddd")
 DEF_ENC(V6_vconv_qf32_sf,"00011110--0-1101PP1uuuuu110ddddd")
 DEF_ENC(V6_vconv_sf_qf32,"00011110--0-0100PP1uuuuu000ddddd")
target/hexagon/imported/mmvec/ext.idef +6 -0
index 1b8afee8b6f..aa74f4f423a 100644
@@ -3519,6 +3519,12 @@ EXTINSN(V6_vconv_hf_qf32,"Vd32.hf=Vuu32.qf32",ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VS
 EXTINSN(V6_vconv_qf16_hf,"Vd32.qf16=Vu32.hf",ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VS,A_HVX_FLT),"Vector conversion of qf16 format to ieee HF",
 { fHIDE(int i;) fVFOREACH(16, i) { fHIDE(unfloat )u = fPARSEHF(VuV.hf[i]); INIT_UNFLOAT(v) v.exp = E_MIN_EXTQF16; v.sign = 1; fQFADD(16,VdV,u,v)  ; } })
 
+EXTINSN(V6_vconv_qf16_f8,"Vdd32.qf16=Vu32.f8",ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VP_VS,A_HVX_FLT),"Vector convert to qf16: f8 widen to qf16",
+{ fHIDE(int i;) fVFOREACH(16, i) { fCONVERT_F8_TO_QF16(VddV.v[0], VuV.f8[2*i]); fCONVERT_F8_TO_QF16(VddV.v[1], VuV.f8[2*i+1]); } })
+
+EXTINSN(V6_vconv_f8_qf16,"Vd32.f8=Vu32.qf16",ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VS,A_HVX_FLT),"Vector convert qf16 to f8",
+{ fHIDE(int i;) fVFOREACH(16, i) { VdV.uh[i] = f16_to_f8_bias7(fCONVERT_QF16_TO_HF(VuV.qf16[i], GET_VEXT(VuV, i, 16)), &env->hvx_fp_status); } })
+
 EXTINSN(V6_vconv_qf16_qf16,"Vd32.qf16=Vu32.qf16",ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VS,A_HVX_FLT),"Vector conversion of qf16 to qf16",
 { fHIDE(int i;) fVFOREACH(16, i) { fHIDE(unfloat )u = fPARSEQF_EXT(16,VuV,i); INIT_UNFLOAT(v) v.exp = E_MIN_EXTQF16; v.sign = 1; fQFADD(16,VdV,u,v)  ; } })
 
Signature · 1 line
2.34.1
Reviewed-by on v3 3/3
#5 lore raw

Re: [PATCH v3 3/3] target/hexagon: add v81 HVX FP8 and qf16 conversions

Quoted 5 lines · Brian Cain

Add V6_vconv_qf16_f8 and V6_vconv_f8_qf16, which use FP8 with exponent bias 7.

Quoted 11 lines
---
 target/hexagon/mmvec/hvx_ieee_fp.h           |   8 ++
 target/hexagon/mmvec/macros.h                |  20 ++++
 target/hexagon/mmvec/hvx_ieee_fp.c           |  21 ++++
 tests/tcg/hexagon/check_rev_gating.c         |   6 +
 tests/tcg/hexagon/qfloat_v81.c               | 111 +++++++++++++++++++
 target/hexagon/tag_rev_info.c.inc            |   2 +
 target/hexagon/imported/mmvec/encode_ext.def |   2 +
 target/hexagon/imported/mmvec/ext.idef       |   6 +
 8 files changed, 176 insertions(+)