Skip to contentSkip to conversation

hexagon: add missing HVX float instructions

PATCH Superseded Matheus Tavares Bernardino 2 participants 32 messages Apr 8 – Apr 10 Arm/Amlogic Meson SoC support

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover hexagon: add missing HVX float instructions

This patchset adds 59 HVX floating point instructions from Hexagon revisions v68 and v73 that were missing in qemu. Tests are also added at the end.

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

Changes in v3:
- replaced uint32_t/uint16_t in MMVector with float32/float16, making it clearer and greatly reducing the code size.
- Many functions were inlined (now that we don't have to use make_float, the functions were mostly one-liners).

Brian Cain (1):
tests/docker: Update hexagon cross toolchain to 22.1.0

Matheus Tavares Bernardino (15):
target/hexagon: fix incorrect/too-permissive HVX encodings target/hexagon/cpu: add HVX IEEE FP extension
hexagon: group cpu configurations in their own struct
hexagon: print info on "-d in_asm" for disabled IEEE FP instructions target/hexagon: add v68 HVX IEEE float arithmetic insns target/hexagon: add v68 HVX IEEE float min/max insns target/hexagon: add v68 HVX IEEE float misc insns target/hexagon: add v68 HVX IEEE float conversion insns target/hexagon: add v68 HVX IEEE float compare insns target/hexagon: add v73 HVX IEEE bfloat16 insns tests/hexagon: add tests for v68 HVX IEEE float arithmetics tests/hexagon: add tests for v68 HVX IEEE float min/max tests/hexagon: add tests for v68 HVX IEEE float conversions tests/hexagon: add tests for v68 HVX IEEE float comparisons tests/hexagon: add tests for HVX bfloat

 target/hexagon/cpu.h                          |  10 +-
 target/hexagon/cpu_bits.h                     |  10 +-
 target/hexagon/mmvec/hvx_ieee_fp.h            |  69 ++++
 target/hexagon/mmvec/macros.h                 |   8 +
 target/hexagon/mmvec/mmvec.h                  |   3 +
 target/hexagon/printinsn.h                    |   2 +-
 target/hexagon/translate.h                    |   1 +
 tests/tcg/hexagon/hex_test.h                  |  32 ++
 tests/tcg/hexagon/hvx_misc.h                  |  73 ++++
 target/hexagon/attribs_def.h.inc              |   9 +
 disas/hexagon.c                               |   3 +-
 target/hexagon/arch.c                         |   8 +
 target/hexagon/cpu.c                          |  18 +-
 target/hexagon/decode.c                       |   4 +-
 target/hexagon/mmvec/hvx_ieee_fp.c            | 136 +++++++
 target/hexagon/printinsn.c                    |   7 +-
 target/hexagon/translate.c                    |   5 +-
 tests/tcg/hexagon/fp_hvx.c                    | 226 +++++++++++
 tests/tcg/hexagon/fp_hvx_cmp.c                | 279 +++++++++++++
 tests/tcg/hexagon/fp_hvx_cvt.c                | 219 +++++++++++
 tests/tcg/hexagon/fp_hvx_disabled.c           |  57 +++
 target/hexagon/gen_tcg_funcs.py               |  11 +
 target/hexagon/hex_common.py                  |  37 ++
 target/hexagon/imported/mmvec/encode_ext.def  | 126 ++++--
 target/hexagon/imported/mmvec/ext.idef        | 369 +++++++++++++++++-
 target/hexagon/meson.build                    |   1 +
 .../dockerfiles/debian-hexagon-cross.docker   |  10 +-
 tests/tcg/hexagon/Makefile.target             |  14 +
 28 files changed, 1699 insertions(+), 48 deletions(-)
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.h
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.c
 create mode 100644 tests/tcg/hexagon/fp_hvx.c
 create mode 100644 tests/tcg/hexagon/fp_hvx_cmp.c
 create mode 100644 tests/tcg/hexagon/fp_hvx_cvt.c
 create mode 100644 tests/tcg/hexagon/fp_hvx_disabled.c

Range-diff against v2:

 -:  ---------- >  1:  a04c3c5feb tests/docker: Update hexagon cross toolchain to 22.1.0
 -:  ---------- >  2:  c63e568f6c target/hexagon: fix incorrect/too-permissive HVX encodings
 -:  ---------- >  3:  bd05d9aa88 target/hexagon/cpu: add HVX IEEE FP extension
 -:  ---------- >  4:  d7cc954b23 hexagon: group cpu configurations in their own struct
 -:  ---------- >  5:  192fd1ca5c hexagon: print info on "-d in_asm" for disabled IEEE FP instructions
 1:  fd24bfcb36 !  6:  42b4b2d1c6 target/hexagon: add v68 HVX IEEE float arithmetic insns
    @@ target/hexagon/mmvec/hvx_ieee_fp.h (new)
     +
     +#include "fpu/softfloat.h"
     +
    -+/* Hexagon canonical NaN */
    -+#define FP32_DEF_NAN      0x7FFFFFFF
    -+#define FP16_DEF_NAN      0x7FFF
    ++#define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
     +
    -+/*
    -+ * IEEE - FP ADD/SUB/MPY instructions
    -+ */
    -+uint32_t fp_mult_sf_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    -+uint32_t fp_add_sf_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    -+uint32_t fp_sub_sf_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    -+
    -+uint16_t fp_mult_hf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+uint16_t fp_add_hf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+uint16_t fp_sub_hf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+
    -+uint32_t fp_mult_sf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+uint32_t fp_add_sf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+uint32_t fp_sub_sf_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+
    -+/*
    -+ * IEEE - FP Accumulate instructions
    -+ */
    -+uint16_t fp_mult_hf_hf_acc(uint16_t a1, uint16_t a2, uint16_t acc,
    -+                           float_status *fp_status);
    -+uint32_t fp_mult_sf_hf_acc(uint16_t a1, uint16_t a2, uint32_t acc,
    -+                           float_status *fp_status);
    -+
    -+/*
    -+ * IEEE - FP Reduce instructions
    -+ */
    -+uint32_t fp_vdmpy(uint16_t a1, uint16_t a2, uint16_t a3, uint16_t a4,
    -+                  float_status *fp_status);
    -+uint32_t fp_vdmpy_acc(uint32_t acc, uint16_t a1, uint16_t a2, uint16_t a3,
    -+                      uint16_t a4, float_status *fp_status);
    ++float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
    ++float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
    ++                 float_status *fp_status);
     +
     +#endif
     
    @@ target/hexagon/mmvec/mmvec.h: typedef union {
          int16_t   h[MAX_VEC_SIZE_BYTES / 2];
          uint8_t  ub[MAX_VEC_SIZE_BYTES / 1];
          int8_t    b[MAX_VEC_SIZE_BYTES / 1];
    -+    int32_t  sf[MAX_VEC_SIZE_BYTES / 4];   /* single float (32-bit) */
    -+    int16_t  hf[MAX_VEC_SIZE_BYTES / 2];   /* half float (16-bit) */
    ++    float32  sf[MAX_VEC_SIZE_BYTES / 4];
    ++    float16  hf[MAX_VEC_SIZE_BYTES / 2];
      } MMVector;
      
      typedef union {
    @@ target/hexagon/mmvec/hvx_ieee_fp.c (new)
     +#include "qemu/osdep.h"
     +#include "hvx_ieee_fp.h"
     +
    -+#define DEF_FP_INSN_2(name, rt, a1t, a2t, op) \
    -+    uint##rt##_t fp_##name(uint##a1t##_t a1, uint##a2t##_t a2, \
    -+                           float_status *fp_status) { \
    -+        float##a1t f1 = make_float##a1t(a1); \
    -+        float##a2t f2 = make_float##a2t(a2); \
    -+        return (op); \
    -+    }
    -+
    -+#define DEF_FP_INSN_3(name, rt, a1t, a2t, a3t, op) \
    -+    uint##rt##_t fp_##name(uint##a1t##_t a1, uint##a2t##_t a2, \
    -+                           uint##a3t##_t a3, float_status *fp_status) { \
    -+        float##a1t f1 = make_float##a1t(a1); \
    -+        float##a2t f2 = make_float##a2t(a2); \
    -+        float##a3t f3 = make_float##a3t(a3); \
    -+        return (op); \
    -+    }
    -+
    -+DEF_FP_INSN_2(mult_sf_sf, 32, 32, 32, float32_mul(f1, f2, fp_status))
    -+DEF_FP_INSN_2(add_sf_sf, 32, 32, 32, float32_add(f1, f2, fp_status))
    -+DEF_FP_INSN_2(sub_sf_sf, 32, 32, 32, float32_sub(f1, f2, fp_status))
    -+
    -+DEF_FP_INSN_2(mult_hf_hf, 16, 16, 16, float16_mul(f1, f2, fp_status))
    -+DEF_FP_INSN_2(add_hf_hf, 16, 16, 16, float16_add(f1, f2, fp_status))
    -+DEF_FP_INSN_2(sub_hf_hf, 16, 16, 16, float16_sub(f1, f2, fp_status))
    -+
    -+DEF_FP_INSN_2(mult_sf_hf, 32, 16, 16,
    -+              float32_mul(float16_to_float32(f1, true, fp_status),
    -+                          float16_to_float32(f2, true, fp_status),
    -+                          fp_status))
    -+DEF_FP_INSN_2(add_sf_hf, 32, 16, 16,
    -+              float32_add(float16_to_float32(f1, true, fp_status),
    -+                          float16_to_float32(f2, true, fp_status),
    -+                          fp_status))
    -+DEF_FP_INSN_2(sub_sf_hf, 32, 16, 16,
    -+              float32_sub(float16_to_float32(f1, true, fp_status),
    -+                          float16_to_float32(f2, true, fp_status),
    -+                          fp_status))
    -+
    -+DEF_FP_INSN_3(mult_hf_hf_acc, 16, 16, 16, 16,
    -+              float16_muladd(f1, f2, f3, 0, fp_status))
    -+DEF_FP_INSN_3(mult_sf_hf_acc, 32, 16, 16, 32,
    -+              float32_muladd(float16_to_float32(f1, true, fp_status),
    -+                             float16_to_float32(f2, true, fp_status),
    -+                             f3, 0, fp_status))
    -+
    -+uint32_t fp_vdmpy(uint16_t a1, uint16_t a2, uint16_t a3, uint16_t a4,
    -+                 float_status *fp_status)
    ++float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status)
     +{
    -+    float32 prod1 = fp_mult_sf_hf(a1, a3, fp_status);
    -+    float32 prod2 = fp_mult_sf_hf(a2, a4, fp_status);
    -+    return fp_add_sf_sf(float32_val(prod1), float32_val(prod2), fp_status);
    ++    return float32_mul(float16_to_float32(a1, true, fp_status),
    ++                       float16_to_float32(a2, true, fp_status), fp_status);
     +}
     +
    -+uint32_t fp_vdmpy_acc(uint32_t acc, uint16_t a1, uint16_t a2,
    -+                      uint16_t a3, uint16_t a4,
    -+                      float_status *fp_status)
    ++float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
    ++                 float_status *fp_status)
     +{
    -+    float32 red = fp_vdmpy(a1, a2, a3, a4, fp_status);
    -+    return fp_add_sf_sf(float32_val(red), acc, fp_status);
    ++    return float32_add(fp_mult_sf_hf(a1, a3, fp_status),
    ++                       fp_mult_sf_hf(a2, a4, fp_status), fp_status);
     +}
     
      ## target/hexagon/hex_common.py ##
    @@ target/hexagon/imported/mmvec/ext.idef: EXTINSN(V6_vprefixqw,"Vd32.w=prefixsum(Q
     +/* IEEE FP multiply instructions */
     +ITERATOR_INSN_IEEE_FP_DOUBLE_SINGLE_32(32, vmpy_sf_sf,
     +    "Vd32.sf=vmpy(Vu32.sf,Vv32.sf)", "Vector IEEE mul: sf",
    -+    VdV.sf[i] = fp_mult_sf_sf(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
    ++    VdV.sf[i] = float32_mul(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vmpy_sf_hf,
     +    "Vdd32.sf=vmpy(Vu32.hf,Vv32.hf)", "Vector IEEE mul: hf widen to sf",
     +    VddV.v[0].sf[i] = fp_mult_sf_hf(VuV.hf[2*i], VvV.hf[2*i], &env->hvx_fp_status);
     +    VddV.v[1].sf[i] = fp_mult_sf_hf(VuV.hf[2*i+1], VvV.hf[2*i+1], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16(16, vmpy_hf_hf,     "Vd32.hf=vmpy(Vu32.hf,Vv32.hf)",
     +    "Vector IEEE mul: hf",
    -+    VdV.hf[i] = fp_mult_hf_hf(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
    ++    VdV.hf[i] = float16_mul(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_32(32, vdmpy_sf_hf,     "Vd32.sf=vdmpy(Vu32.hf,Vv32.hf)",
     +    "Vector IEEE mul reduction: hf widen to sf",
     +    VdV.sf[i] = fp_vdmpy(VuV.hf[2*i+1], VuV.hf[2*i], VvV.hf[2*i+1],
    @@ target/hexagon/imported/mmvec/ext.idef: EXTINSN(V6_vprefixqw,"Vd32.w=prefixsum(Q
     +/* IEEE FP multiply-accumulate instructions */
     +ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vmpy_sf_hf_acc,
     +    "Vxx32.sf+=vmpy(Vu32.hf,Vv32.hf)", "Vector IEEE fma: hf widen to sf",
    -+    VxxV.v[0].sf[i] = fp_mult_sf_hf_acc(VuV.hf[2*i], VvV.hf[2*i],
    -+        VxxV.v[0].sf[i], &env->hvx_fp_status);
    -+    VxxV.v[1].sf[i] = fp_mult_sf_hf_acc(VuV.hf[2*i+1], VvV.hf[2*i+1],
    -+        VxxV.v[1].sf[i], &env->hvx_fp_status))
    ++    VxxV.v[0].sf[i] = float32_muladd(f16_to_f32(VuV.hf[2*i]),
    ++                                     f16_to_f32(VvV.hf[2*i]),
    ++                                     VxxV.v[0].sf[i], 0, &env->hvx_fp_status);
    ++    VxxV.v[1].sf[i] = float32_muladd(f16_to_f32(VuV.hf[2*i+1]),
    ++                                     f16_to_f32(VvV.hf[2*i+1]),
    ++                                     VxxV.v[1].sf[i], 0, &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_ACC_16(16, vmpy_hf_hf_acc,
     +    "Vx32.hf+=vmpy(Vu32.hf,Vv32.hf)", "Vector IEEE fma: hf",
    -+    VxV.hf[i] = fp_mult_hf_hf_acc(VuV.hf[i], VvV.hf[i], VxV.hf[i], &env->hvx_fp_status))
    ++    VxV.hf[i] = float16_muladd(VuV.hf[i], VvV.hf[i], VxV.hf[i], 0, &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_ACC_32(32, vdmpy_sf_hf_acc,
     +    "Vx32.sf+=vdmpy(Vu32.hf,Vv32.hf)", "Vector IEEE fma reduce: hf widen to sf",
    -+    VxV.sf[i] = fp_vdmpy_acc(VxV.sf[i], VuV.hf[2*i+1], VuV.hf[2*i], VvV.hf[2*i+1],
    -+        VvV.hf[2*i], &env->hvx_fp_status))
    ++    VxV.sf[i] = float32_add(fp_vdmpy(VuV.hf[2*i+1], VuV.hf[2*i],
    ++                                     VvV.hf[2*i+1], VvV.hf[2*i],
    ++                                     &env->hvx_fp_status),
    ++                            VxV.sf[i], &env->hvx_fp_status))
     +
     +/* IEEE FP add/sub instructions */
     +ITERATOR_INSN_IEEE_FP_32(32, vadd_sf_sf, "Vd32.sf=vadd(Vu32.sf,Vv32.sf)",
     +    "Vector IEEE add: sf",
    -+    VdV.sf[i] = fp_add_sf_sf(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
    ++    VdV.sf[i] = float32_add(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_32(32, vsub_sf_sf, "Vd32.sf=vsub(Vu32.sf,Vv32.sf)",
     +    "Vector IEEE sub: sf",
    -+    VdV.sf[i] = fp_sub_sf_sf(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
    ++    VdV.sf[i] = float32_sub(VuV.sf[i], VvV.sf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16(16, vadd_hf_hf, "Vd32.hf=vadd(Vu32.hf,Vv32.hf)",
     +    "Vector IEEE add: hf",
    -+    VdV.hf[i] = fp_add_hf_hf(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
    ++    VdV.hf[i] = float16_add(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16(16, vsub_hf_hf, "Vd32.hf=vsub(Vu32.hf,Vv32.hf)",
     +    "Vector IEEE sub: hf",
    -+    VdV.hf[i] = fp_sub_hf_hf(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
    ++    VdV.hf[i] = float16_sub(VuV.hf[i], VvV.hf[i], &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vadd_sf_hf,
     +    "Vdd32.sf=vadd(Vu32.hf,Vv32.hf)",  "Vector IEEE add: hf widen to sf",
    -+    VddV.v[0].sf[i] = fp_add_sf_hf(VuV.hf[2*i], VvV.hf[2*i], &env->hvx_fp_status);
    -+    VddV.v[1].sf[i] = fp_add_sf_hf(VuV.hf[2*i+1], VvV.hf[2*i+1], &env->hvx_fp_status))
    ++    VddV.v[0].sf[i] = float32_add(f16_to_f32(VuV.hf[2*i]),
    ++                                  f16_to_f32(VvV.hf[2*i]), &env->hvx_fp_status);
    ++    VddV.v[1].sf[i] = float32_add(f16_to_f32(VuV.hf[2*i+1]),
    ++                                  f16_to_f32(VvV.hf[2*i+1]), &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vsub_sf_hf,
     +    "Vdd32.sf=vsub(Vu32.hf,Vv32.hf)",  "Vector IEEE sub: hf widen to sf",
    -+    VddV.v[0].sf[i] = fp_sub_sf_hf(VuV.hf[2*i], VvV.hf[2*i], &env->hvx_fp_status);
    -+    VddV.v[1].sf[i] = fp_sub_sf_hf(VuV.hf[2*i+1], VvV.hf[2*i+1], &env->hvx_fp_status))
    ++    VddV.v[0].sf[i] = float32_sub(f16_to_f32(VuV.hf[2*i]),
    ++                                  f16_to_f32(VvV.hf[2*i]), &env->hvx_fp_status);
    ++    VddV.v[1].sf[i] = float32_sub(f16_to_f32(VuV.hf[2*i+1]),
    ++                                  f16_to_f32(VvV.hf[2*i+1]), &env->hvx_fp_status))
      
      /******************************************************************************
       DEBUG Vector/Register Printing
 2:  30254b5750 !  7:  0104072468 target/hexagon: add v68 HVX IEEE float min/max insns
    @@ Commit message
         Signed-off-by: Matheus Tavares Bernardino <[email protected]>
     
      ## target/hexagon/mmvec/hvx_ieee_fp.h ##
    -@@ target/hexagon/mmvec/hvx_ieee_fp.h: uint32_t fp_vdmpy(uint16_t a1, uint16_t a2, uint16_t a3, uint16_t a4,
    - uint32_t fp_vdmpy_acc(uint32_t acc, uint16_t a1, uint16_t a2, uint16_t a3,
    -                       uint16_t a4, float_status *fp_status);
    +@@ target/hexagon/mmvec/hvx_ieee_fp.h: float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
    + float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
    +                  float_status *fp_status);
      
    -+/* IEEE - FP min/max instructions */
    -+uint32_t fp_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    -+uint32_t fp_max_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    -+uint16_t fp_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+uint16_t fp_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
    -+
     +/* Qfloat min/max treat +NaN as greater than +INF and -NaN as smaller than -INF */
     +uint32_t qf_max_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
     +uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    @@ target/hexagon/mmvec/hvx_ieee_fp.h: uint32_t fp_vdmpy(uint16_t a1, uint16_t a2,
     +
      #endif
     
    + ## target/hexagon/attribs_def.h.inc ##
    +@@ target/hexagon/attribs_def.h.inc: DEF_ATTRIB(CVI_SCATTER, "CVI Scatter operation", "", "")
    + DEF_ATTRIB(CVI_SCATTER_RELEASE, "CVI Store Release for scatter", "", "")
    + DEF_ATTRIB(CVI_TMP_DST, "CVI instruction that doesn't write a register", "", "")
    + DEF_ATTRIB(CVI_SLOT23, "Can execute in slot 2 or slot 3 (HVX)", "", "")
    ++DEF_ATTRIB(CVI_VA_2SRC, "Execs on multimedia vector engine; requires two srcs", "", "")
    + 
    + DEF_ATTRIB(VTCM_ALLBANK_ACCESS, "Allocates in all VTCM schedulers.", "", "")
    + 
    +@@ target/hexagon/attribs_def.h.inc: DEF_ATTRIB(HVX_IEEE_FP_ACC, "HVX IEEE FP accumulate instruction", "", "")
    + 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", "", "")
    ++DEF_ATTRIB(HVX_FLT, "This a floating point HVX instruction.", "", "")
    + 
    + /* Keep this as the last attribute: */
    + DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
    +
      ## target/hexagon/mmvec/hvx_ieee_fp.c ##
    -@@ target/hexagon/mmvec/hvx_ieee_fp.c: uint32_t fp_vdmpy_acc(uint32_t acc, uint16_t a1, uint16_t a2,
    -     float32 red = fp_vdmpy(a1, a2, a3, a4, fp_status);
    -     return fp_add_sf_sf(float32_val(red), acc, fp_status);
    +@@ target/hexagon/mmvec/hvx_ieee_fp.c: float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
    +     return float32_add(fp_mult_sf_hf(a1, a3, fp_status),
    +                        fp_mult_sf_hf(a2, a4, fp_status), fp_status);
      }
     +
    -+DEF_FP_INSN_2(min_sf, 32, 32, 32, float32_min(f1, f2, fp_status))
    -+DEF_FP_INSN_2(max_sf, 32, 32, 32, float32_max(f1, f2, fp_status))
    -+DEF_FP_INSN_2(min_hf, 16, 16, 16, float16_min(f1, f2, fp_status))
    -+DEF_FP_INSN_2(max_hf, 16, 16, 16, float16_max(f1, f2, fp_status))
    -+
     +#define float32_is_pos_nan(X) (float32_is_any_nan(X) && !float32_is_neg(X))
     +#define float32_is_neg_nan(X) (float32_is_any_nan(X) && float32_is_neg(X))
     +#define float16_is_pos_nan(X) (float16_is_any_nan(X) && !float16_is_neg(X))
     +#define float16_is_neg_nan(X) (float16_is_any_nan(X) && float16_is_neg(X))
     +
    -+uint32_t qf_max_sf(uint32_t a1, uint32_t a2, float_status *fp_status)
    ++float32 qf_max_sf(float32 a1, float32 a2, float_status *fp_status)
     +{
    -+    float32 f1 = make_float32(a1);
    -+    float32 f2 = make_float32(a2);
    -+    if (float32_is_pos_nan(f1) || float32_is_neg_nan(f2)) {
    ++    if (float32_is_pos_nan(a1) || float32_is_neg_nan(a2)) {
     +        return a1;
     +    }
    -+    if (float32_is_pos_nan(f2) || float32_is_neg_nan(f1)) {
    ++    if (float32_is_pos_nan(a2) || float32_is_neg_nan(a1)) {
     +        return a2;
     +    }
    -+    return fp_max_sf(a1, a2, fp_status);
    ++    return float32_max(a1, a2, fp_status);
     +}
     +
    -+uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status)
    ++float32 qf_min_sf(float32 a1, float32 a2, float_status *fp_status)
     +{
    -+    float32 f1 = make_float32(a1);
    -+    float32 f2 = make_float32(a2);
    -+    if (float32_is_pos_nan(f1) || float32_is_neg_nan(f2)) {
    ++    if (float32_is_pos_nan(a1) || float32_is_neg_nan(a2)) {
     +        return a2;
     +    }
    -+    if (float32_is_pos_nan(f2) || float32_is_neg_nan(f1)) {
    ++    if (float32_is_pos_nan(a2) || float32_is_neg_nan(a1)) {
     +        return a1;
     +    }
    -+    return fp_min_sf(a1, a2, fp_status);
    ++    return float32_min(a1, a2, fp_status);
     +}
     +
    -+uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
    ++float16 qf_max_hf(float16 a1, float16 a2, float_status *fp_status)
     +{
    -+    float16 f1 = make_float16(a1);
    -+    float16 f2 = make_float16(a2);
    -+    if (float16_is_pos_nan(f1) || float16_is_neg_nan(f2)) {
    ++    if (float16_is_pos_nan(a1) || float16_is_neg_nan(a2)) {
     +        return a1;
     +    }
    -+    if (float16_is_pos_nan(f2) || float16_is_neg_nan(f1)) {
    ++    if (float16_is_pos_nan(a2) || float16_is_neg_nan(a1)) {
     +        return a2;
     +    }
    -+    return fp_max_hf(a1, a2, fp_status);
    ++    return float16_max(a1, a2, fp_status);
     +}
     +
    -+uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
    ++float16 qf_min_hf(float16 a1, float16 a2, float_status *fp_status)
     +{
    -+    float16 f1 = make_float16(a1);
    -+    float16 f2 = make_float16(a2);
    -+    if (float16_is_pos_nan(f1) || float16_is_neg_nan(f2)) {
    ++    if (float16_is_pos_nan(a1) || float16_is_neg_nan(a2)) {
     +        return a2;
     +    }
    -+    if (float16_is_pos_nan(f2) || float16_is_neg_nan(f1)) {
    ++    if (float16_is_pos_nan(a2) || float16_is_neg_nan(a1)) {
     +        return a1;
     +    }
    -+    return fp_min_hf(a1, a2, fp_status);
    ++    return float16_min(a1, a2, fp_status);
     +}
     
    + ## target/hexagon/hex_common.py ##
    +@@ target/hexagon/hex_common.py: def need_env(tag):
    +             "A_CVI_GATHER" in attribdict[tag] or
    +             "A_CVI_SCATTER" in attribdict[tag] or
    +             "A_HVX_IEEE_FP" in attribdict[tag] or
    ++            "A_HVX_FLT" in attribdict[tag] or
    +             "A_IMPLICIT_WRITES_USR" in attribdict[tag])
    + 
    + 
    +
      ## target/hexagon/imported/mmvec/encode_ext.def ##
     @@ target/hexagon/imported/mmvec/encode_ext.def: DEF_ENC(V6_vsub_sf_hf,"00011111100vvvvvPP1uuuuu101ddddd")
      DEF_ENC(V6_vadd_hf_hf,"00011111101vvvvvPP1uuuuu111ddddd")
    @@ target/hexagon/imported/mmvec/ext.idef
      #define ITERATOR_INSN2_ANY_SLOT(WIDTH,TAG,SYNTAX,SYNTAX2,DESCR,CODE) \
      ITERATOR_INSN_ANY_SLOT(WIDTH,TAG,SYNTAX2,DESCR,CODE)
     @@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vsub_sf_hf,
    -     VddV.v[0].sf[i] = fp_sub_sf_hf(VuV.hf[2*i], VvV.hf[2*i], &env->hvx_fp_status);
    -     VddV.v[1].sf[i] = fp_sub_sf_hf(VuV.hf[2*i+1], VvV.hf[2*i+1], &env->hvx_fp_status))
    +     VddV.v[1].sf[i] = float32_sub(f16_to_f32(VuV.hf[2*i+1]),
    +                                   f16_to_f32(VvV.hf[2*i+1]), &env->hvx_fp_status))
      
     +#define ITERATOR_INSN_IEEE_FP_16_32_LATE(WIDTH,TAG,SYNTAX,DESCR,CODE) \
     +EXTINSN(V6_##TAG, SYNTAX, \
    @@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vsub
     +
     +/* IEEE FP min/max instructions */
     +ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfmin_hf, "Vd32.hf=vfmin(Vu32.hf,Vv32.hf)", \
    -+    "Vector IEEE min: hf",  VdV.hf[i] = fp_min_hf(VuV.hf[i], VvV.hf[i], \
    ++    "Vector IEEE min: hf",  VdV.hf[i] = float16_min(VuV.hf[i], VvV.hf[i], \
     +	&env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfmin_sf, "Vd32.sf=vfmin(Vu32.sf,Vv32.sf)", \
    -+    "Vector IEEE min: sf",  VdV.sf[i] = fp_min_sf(VuV.sf[i], VvV.sf[i], \
    ++    "Vector IEEE min: sf",  VdV.sf[i] = float32_min(VuV.sf[i], VvV.sf[i], \
     +	&env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfmax_hf,  "Vd32.hf=vfmax(Vu32.hf,Vv32.hf)", \
    -+    "Vector IEEE max: hf", VdV.hf[i] = fp_max_hf(VuV.hf[i], VvV.hf[i], \
    ++    "Vector IEEE max: hf", VdV.hf[i] = float16_max(VuV.hf[i], VvV.hf[i], \
     +	&env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfmax_sf,  "Vd32.sf=vfmax(Vu32.sf,Vv32.sf)", \
    -+    "Vector IEEE max: sf", VdV.sf[i] = fp_max_sf(VuV.sf[i], VvV.sf[i], \
    ++    "Vector IEEE max: sf", VdV.sf[i] = float32_max(VuV.sf[i], VvV.sf[i], \
     +	&env->hvx_fp_status))
     +
     +ITERATOR_INSN_ANY_SLOT_2SRC(32,vmax_sf,"Vd32.sf=vmax(Vu32.sf,Vv32.sf)", \
 3:  c6fe780abf =  8:  2aa7f10503 target/hexagon: add v68 HVX IEEE float misc insns
 4:  85dccc1913 !  9:  99bac24648 target/hexagon: add v68 HVX IEEE float conversion insns
    @@ Commit message
         Signed-off-by: Matheus Tavares Bernardino <[email protected]>
     
      ## target/hexagon/mmvec/hvx_ieee_fp.h ##
    +@@
    + #include "fpu/softfloat.h"
    + 
    + #define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
    ++#define f32_to_f16(A) float32_to_float16((A), true, &env->hvx_fp_status)
    + 
    + float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
    + float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
     @@ target/hexagon/mmvec/hvx_ieee_fp.h: uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
      uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
      uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
      
    -+/*
    -+ * IEEE - FP Convert instructions
    -+ */
    -+uint16_t f32_to_f16(uint32_t a, float_status *fp_status);
    -+uint32_t f16_to_f32(uint16_t a, float_status *fp_status);
    -+
    -+uint16_t f16_to_uh(uint16_t op1, float_status *fp_status);
    -+int16_t  f16_to_h(uint16_t op1, float_status *fp_status);
    -+uint8_t  f16_to_ub(uint16_t op1, float_status *fp_status);
    -+int8_t   f16_to_b(uint16_t op1, float_status *fp_status);
    -+
    -+uint16_t uh_to_f16(uint16_t op1);
    -+uint16_t h_to_f16(int16_t op1);
    -+uint16_t ub_to_f16(uint8_t op1);
    -+uint16_t b_to_f16(int8_t op1);
    -+
    -+int32_t conv_sf_w(int32_t a, float_status *fp_status);
    -+int16_t conv_hf_h(int16_t a, float_status *fp_status);
    -+int32_t conv_w_sf(uint32_t a, float_status *fp_status);
    -+int16_t conv_h_hf(uint16_t a, float_status *fp_status);
    ++int32_t conv_w_sf(float32 a, float_status *fp_status);
    ++int16_t conv_h_hf(float16 a, float_status *fp_status);
     +
      #endif
     
      ## target/hexagon/mmvec/hvx_ieee_fp.c ##
    -@@ target/hexagon/mmvec/hvx_ieee_fp.c: uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
    +@@ target/hexagon/mmvec/hvx_ieee_fp.c: float16 qf_min_hf(float16 a1, float16 a2, float_status *fp_status)
          }
    -     return fp_min_hf(a1, a2, fp_status);
    +     return float16_min(a1, a2, fp_status);
      }
     +
    -+uint16_t f32_to_f16(uint32_t a, float_status *fp_status)
    ++int32_t conv_w_sf(float32 a, float_status *fp_status)
     +{
    -+    return float16_val(float32_to_float16(make_float32(a), true, fp_status));
    -+}
    -+
    -+uint32_t f16_to_f32(uint16_t a, float_status *fp_status)
    -+{
    -+    return float32_val(float16_to_float32(make_float16(a), true, fp_status));
    -+}
    -+
    -+uint16_t f16_to_uh(uint16_t op1, float_status *fp_status)
    -+{
    -+    return float16_to_uint16_scalbn(make_float16(op1),
    -+                                    float_round_nearest_even,
    -+                                    0, fp_status);
    -+}
    -+
    -+int16_t f16_to_h(uint16_t op1, float_status *fp_status)
    -+{
    -+    return float16_to_int16_scalbn(make_float16(op1),
    -+                                   float_round_nearest_even,
    -+                                   0, fp_status);
    -+}
    -+
    -+uint8_t f16_to_ub(uint16_t op1, float_status *fp_status)
    -+{
    -+    return float16_to_uint8_scalbn(make_float16(op1),
    -+                                   float_round_nearest_even,
    -+                                   0, fp_status);
    -+}
    -+
    -+int8_t f16_to_b(uint16_t op1, float_status *fp_status)
    -+{
    -+    return float16_to_int8_scalbn(make_float16(op1),
    -+                                   float_round_nearest_even,
    -+                                   0, fp_status);
    -+}
    -+
    -+uint16_t uh_to_f16(uint16_t op1)
    -+{
    -+    return uint64_to_float16_scalbn(op1, float_round_nearest_even, 0);
    -+}
    -+
    -+uint16_t h_to_f16(int16_t op1)
    -+{
    -+    return int64_to_float16_scalbn(op1, float_round_nearest_even, 0);
    -+}
    -+
    -+uint16_t ub_to_f16(uint8_t op1)
    -+{
    -+    return uint64_to_float16_scalbn(op1, float_round_nearest_even, 0);
    -+}
    -+
    -+uint16_t b_to_f16(int8_t op1)
    -+{
    -+    return int64_to_float16_scalbn(op1, float_round_nearest_even, 0);
    -+}
    -+
    -+int32_t conv_sf_w(int32_t a, float_status *fp_status)
    -+{
    -+    return float32_val(int32_to_float32(a, fp_status));
    -+}
    -+
    -+int16_t conv_hf_h(int16_t a, float_status *fp_status)
    -+{
    -+    return float16_val(int16_to_float16(a, fp_status));
    -+}
    -+
    -+int32_t conv_w_sf(uint32_t a, float_status *fp_status)
    -+{
    -+    float32 f1 = make_float32(a);
     +    /* float32_to_int32 converts any NaN to MAX, hexagon looks at the sign. */
    -+    if (float32_is_any_nan(f1)) {
    -+        return float32_is_neg(f1) ? INT32_MIN : INT32_MAX;
    ++    if (float32_is_any_nan(a)) {
    ++        return float32_is_neg(a) ? INT32_MIN : INT32_MAX;
     +    }
    -+    return float32_to_int32_round_to_zero(f1, fp_status);
    ++    return float32_to_int32_round_to_zero(a, fp_status);
     +}
     +
    -+int16_t conv_h_hf(uint16_t a, float_status *fp_status)
    ++int16_t conv_h_hf(float16 a, float_status *fp_status)
     +{
    -+    float16 f1 = make_float16(a);
     +    /* float16_to_int16 converts any NaN to MAX, hexagon looks at the sign. */
    -+    if (float16_is_any_nan(f1)) {
    -+        return float16_is_neg(f1) ? INT16_MIN : INT16_MAX;
    ++    if (float16_is_any_nan(a)) {
    ++        return float16_is_neg(a) ? INT16_MIN : INT16_MAX;
     +    }
    -+    return float16_to_int16_round_to_zero(f1, fp_status);
    ++    return float16_to_int16_round_to_zero(a, fp_status);
     +}
     
      ## target/hexagon/imported/mmvec/encode_ext.def ##
    @@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vab
     +
     +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32,  vcvt_hf_ub, "Vdd32.hf=vcvt(Vu32.ub)",
     +    "Vector IEEE cvt from int: ub widen to hf",
    -+    VddV.v[0].hf[2*i]   = ub_to_f16(VuV.ub[4*i]);
    -+    VddV.v[0].hf[2*i+1] = ub_to_f16(VuV.ub[4*i+1]);
    -+    VddV.v[1].hf[2*i]   = ub_to_f16(VuV.ub[4*i+2]);
    -+    VddV.v[1].hf[2*i+1] = ub_to_f16(VuV.ub[4*i+3]))
    ++    VddV.v[0].hf[2*i]   = uint64_to_float16_scalbn(VuV.ub[4*i], float_round_nearest_even, 0);
    ++    VddV.v[0].hf[2*i+1] = uint64_to_float16_scalbn(VuV.ub[4*i+1], float_round_nearest_even, 0);
    ++    VddV.v[1].hf[2*i]   = uint64_to_float16_scalbn(VuV.ub[4*i+2], float_round_nearest_even, 0);
    ++    VddV.v[1].hf[2*i+1] = uint64_to_float16_scalbn(VuV.ub[4*i+3], float_round_nearest_even, 0))
     +
     +ITERATOR_INSN_IEEE_FP_DOUBLE_16(32,  vcvt_hf_b,  "Vdd32.hf=vcvt(Vu32.b)",
     +    "Vector IEEE cvt from int: b widen to hf",
    -+    VddV.v[0].hf[2*i]   = b_to_f16(VuV.b[4*i]);
    -+    VddV.v[0].hf[2*i+1] = b_to_f16(VuV.b[4*i+1]);
    -+    VddV.v[1].hf[2*i]   = b_to_f16(VuV.b[4*i+2]);
    -+    VddV.v[1].hf[2*i+1] = b_to_f16(VuV.b[4*i+3]))
    ++    VddV.v[0].hf[2*i]   = int64_to_float16_scalbn(VuV.b[4*i], float_round_nearest_even, 0);
    ++    VddV.v[0].hf[2*i+1] = int64_to_float16_scalbn(VuV.b[4*i+1], float_round_nearest_even, 0);
    ++    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))
     +
     +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], &env->hvx_fp_status);
    -+    VddV.v[1].sf[i] = f16_to_f32(VuV.hf[2*i+1], &env->hvx_fp_status))
    ++    VddV.v[0].sf[i] = f16_to_f32(VuV.hf[2*i]);
    ++    VddV.v[1].sf[i] = f16_to_f32(VuV.hf[2*i+1]))
     +
     +ITERATOR_INSN_IEEE_FP_16(16,    vcvt_hf_uh, "Vd32.hf=vcvt(Vu32.uh)",
     +    "Vector IEEE cvt from int: uh to hf",
    -+    VdV.hf[i] = uh_to_f16(VuV.uh[i]))
    ++    VdV.hf[i] = uint64_to_float16_scalbn(VuV.uh[i], float_round_nearest_even, 0))
     +ITERATOR_INSN_IEEE_FP_16(16,    vcvt_hf_h,  "Vd32.hf=vcvt(Vu32.h)",
     +    "Vector IEEE cvt from int: h to hf",
    -+    VdV.hf[i] = h_to_f16(VuV.h[i]))
    ++    VdV.hf[i] = int64_to_float16_scalbn(VuV.h[i], float_round_nearest_even, 0))
     +ITERATOR_INSN_IEEE_FP_16_32(16, vcvt_uh_hf, "Vd32.uh=vcvt(Vu32.hf)",
     +    "Vector IEEE cvt to int: hf to uh",
    -+    VdV.uh[i] = f16_to_uh(VuV.hf[i], &env->hvx_fp_status))
    ++    VdV.uh[i] = float16_to_uint16_scalbn(VuV.hf[i], float_round_nearest_even, 0, &env->hvx_fp_status))
     +ITERATOR_INSN_IEEE_FP_16_32(16, vcvt_h_hf,  "Vd32.h=vcvt(Vu32.hf)",
     +    "Vector IEEE cvt to int: hf to h",
    -+    VdV.h[i]  = f16_to_h(VuV.hf[i], &env->hvx_fp_status))
    ++    VdV.h[i]  = float16_to_int16_scalbn(VuV.hf[i], float_round_nearest_even, 0, &env->hvx_fp_status))
     +
     +ITERATOR_INSN_IEEE_FP_16(32, vcvt_hf_sf, "Vd32.hf=vcvt(Vu32.sf,Vv32.sf)",
     +    "Vector IEEE cvt: sf to hf",
    -+    VdV.hf[2*i]   = f32_to_f16(VuV.sf[i], &env->hvx_fp_status);
    -+    VdV.hf[2*i+1] = f32_to_f16(VvV.sf[i], &env->hvx_fp_status))
    ++    VdV.hf[2*i]   = f32_to_f16(VuV.sf[i]);
    ++    VdV.hf[2*i+1] = f32_to_f16(VvV.sf[i]))
     +
     +ITERATOR_INSN_IEEE_FP_16_32(32, vcvt_ub_hf, "Vd32.ub=vcvt(Vu32.hf,Vv32.hf)", "Vector cvt to int: hf narrow to ub",
    -+    VdV.ub[4*i]   = f16_to_ub(VuV.hf[2*i], &env->hvx_fp_status);
    -+    VdV.ub[4*i+1] = f16_to_ub(VuV.hf[2*i+1], &env->hvx_fp_status);
    -+    VdV.ub[4*i+2] = f16_to_ub(VvV.hf[2*i], &env->hvx_fp_status);
    -+    VdV.ub[4*i+3] = f16_to_ub(VvV.hf[2*i+1], &env->hvx_fp_status))
    ++    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(VuV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status);
    ++    VdV.ub[4*i+2] = float16_to_uint8_scalbn(VvV.hf[2*i], 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, vcvt_b_hf,  "Vd32.b=vcvt(Vu32.hf,Vv32.hf)",
     +    "Vector cvt to int: hf narrow to b",
    -+    VdV.b[4*i]   = f16_to_b(VuV.hf[2*i], &env->hvx_fp_status);
    -+    VdV.b[4*i+1] = f16_to_b(VuV.hf[2*i+1], &env->hvx_fp_status);
    -+    VdV.b[4*i+2] = f16_to_b(VvV.hf[2*i], &env->hvx_fp_status);
    -+    VdV.b[4*i+3] = f16_to_b(VvV.hf[2*i+1], &env->hvx_fp_status))
    ++    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(VuV.hf[2*i+1], float_round_nearest_even, 0, &env->hvx_fp_status);
    ++    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_SHIFT_SLOT_FLT(32, vconv_w_sf,"Vd32.w=Vu32.sf",
     +    "Vector conversion of sf32 format to int w",
    @@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vab
     +
     +ITERATOR_INSN_SHIFT_SLOT_FLT(32, vconv_sf_w,"Vd32.sf=Vu32.w",
     +    "Vector conversion of int w format to sf32",
    -+    VdV.sf[i] = conv_sf_w(VuV.w[i], &env->hvx_fp_status))
    ++    VdV.sf[i] = int32_to_float32(VuV.w[i], &env->hvx_fp_status))
     +
     +ITERATOR_INSN_SHIFT_SLOT_FLT(16, vconv_hf_h,"Vd32.hf=Vu32.h",
     +    "Vector conversion of int hw format to hf16",
    -+    VdV.hf[i] = conv_hf_h(VuV.h[i], &env->hvx_fp_status))
    ++    VdV.hf[i] = float16_val(int16_to_float16(VuV.h[i], &env->hvx_fp_status)))
     +
      /******************************************************************************
       DEBUG Vector/Register Printing

5: 9ac626fa17 ! 10: 9518dd95bd target/hexagon: add v68 HVX IEEE float compare insns
@@ Commit message

## target/hexagon/mmvec/hvx_ieee_fp.h ##
-@@ target/hexagon/mmvec/hvx_ieee_fp.h: uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
- uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
- uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+@@ target/hexagon/mmvec/hvx_ieee_fp.h: uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+ int32_t conv_w_sf(float32 a, float_status *fp_status);
+ int16_t conv_h_hf(float16 a, float_status *fp_status);

+/* IEEE - FP compare instructions */
+uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status); +uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status); +
- /*
- * IEEE - FP Convert instructions
- */
+ #endif

## target/hexagon/mmvec/macros.h ##
@@
@@ target/hexagon/mmvec/macros.h
+
#endif

- ## target/hexagon/attribs_def.h.inc ##
-@@ target/hexagon/attribs_def.h.inc: DEF_ATTRIB(CVI_SCATTER, "CVI Scatter operation", "", "")
- DEF_ATTRIB(CVI_SCATTER_RELEASE, "CVI Store Release for scatter", "", "")
- DEF_ATTRIB(CVI_TMP_DST, "CVI instruction that doesn't write a register", "", "")
- DEF_ATTRIB(CVI_SLOT23, "Can execute in slot 2 or slot 3 (HVX)", "", "") -+DEF_ATTRIB(CVI_VA_2SRC, "Execs on multimedia vector engine; requires two srcs", "", "")
-
- DEF_ATTRIB(VTCM_ALLBANK_ACCESS, "Allocates in all VTCM schedulers.", "", "")
-
-@@ target/hexagon/attribs_def.h.inc: DEF_ATTRIB(HVX_IEEE_FP_ACC, "HVX IEEE FP accumulate instruction", "", "")
- 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", "", "") -+DEF_ATTRIB(HVX_FLT, "This a floating point HVX instruction.", "", "")
-
- /* Keep this as the last attribute: */
- DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
-
## target/hexagon/mmvec/hvx_ieee_fp.c ##
-@@ target/hexagon/mmvec/hvx_ieee_fp.c: int16_t conv_h_hf(uint16_t a, float_status *fp_status) +@@ target/hexagon/mmvec/hvx_ieee_fp.c: int16_t conv_h_hf(float16 a, float_status *fp_status)
}
- return float16_to_int16_round_to_zero(f1, fp_status);
+ return float16_to_int16_round_to_zero(a, fp_status);
}
+
+/*
@@ target/hexagon/mmvec/hvx_ieee_fp.c: int16_t conv_h_hf(uint16_t a, float_status *
+ return float16_is_neg(f1) ? !result : result;
+}
+
-+uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status)
++uint32_t cmpgt_sf(float32 a1, float32 a2, float_status *fp_status)
+{
-+ float32 f1 = make_float32(a1);
-+ float32 f2 = make_float32(a2);
-+ if (float32_is_any_nan(f1) || float32_is_any_nan(f2)) {
-+ return float32_nan_compare(f1, f2, fp_status);
++ if (float32_is_any_nan(a1) || float32_is_any_nan(a2)) {
++ return float32_nan_compare(a1, a2, fp_status);
+ }
+ return float32_compare(a1, a2, fp_status) == float_relation_greater;
+}
+
-+uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
++uint16_t cmpgt_hf(float16 a1, float16 a2, float_status *fp_status)
+{
-+ float16 f1 = make_float16(a1);
-+ float16 f2 = make_float16(a2);
-+ if (float16_is_any_nan(f1) || float16_is_any_nan(f2)) {
-+ return float16_nan_compare(f1, f2, fp_status);
++ if (float16_is_any_nan(a1) || float16_is_any_nan(a2)) {
++ return float16_nan_compare(a1, a2, fp_status);
+ }
+ return float16_compare(a1, a2, fp_status) == float_relation_greater;
+}

- ## target/hexagon/hex_common.py ##
-@@ target/hexagon/hex_common.py: def need_env(tag):
- "A_CVI_GATHER" in attribdict[tag] or
- "A_CVI_SCATTER" in attribdict[tag] or
- "A_HVX_IEEE_FP" in attribdict[tag] or
-+ "A_HVX_FLT" in attribdict[tag] or
- "A_IMPLICIT_WRITES_USR" in attribdict[tag])
-
-
-
## target/hexagon/imported/mmvec/encode_ext.def ##
@@ target/hexagon/imported/mmvec/encode_ext.def: DEF_ENC(V6_vconv_w_sf,"00011110--0--101PP1uuuuu001ddddd")
DEF_ENC(V6_vconv_hf_h,"00011110--0--101PP1uuuuu100ddddd")
@@ target/hexagon/imported/mmvec/encode_ext.def: DEF_ENC(V6_vconv_w_sf,"00011110--0
## target/hexagon/imported/mmvec/ext.idef ##
@@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_SHIFT_SLOT_FLT(16, vconv_hf_h,"Vd32.hf=Vu32.h",
"Vector conversion of int hw format to hf16",
- VdV.hf[i] = conv_hf_h(VuV.h[i], &env->hvx_fp_status))
+ VdV.hf[i] = float16_val(int16_to_float16(VuV.h[i], &env->hvx_fp_status)))

+/******************************************************************************
+ * IEEE FP compare instructions
6: b12d94be22 ! 11: f84d180547 target/hexagon: add v73 HVX IEEE bfloat16 insns

    @@ Commit message
         Signed-off-by: Matheus Tavares Bernardino <[email protected]>
     
      ## target/hexagon/mmvec/hvx_ieee_fp.h ##
    -@@ target/hexagon/mmvec/hvx_ieee_fp.h: int16_t conv_hf_h(int16_t a, float_status *fp_status);
    - int32_t conv_w_sf(uint32_t a, float_status *fp_status);
    - int16_t conv_h_hf(uint16_t a, float_status *fp_status);
    +@@
    + 
    + #include "fpu/softfloat.h"
    + 
    ++#define FP32_DEF_NAN 0x7FFFFFFF
    ++
    + #define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
    + #define f32_to_f16(A) float32_to_float16((A), true, &env->hvx_fp_status)
    ++#define bf_to_sf(A) bfloat16_to_float32(A, &env->hvx_fp_status)
    + 
    + float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
    + float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
    +@@ target/hexagon/mmvec/hvx_ieee_fp.h: int16_t conv_h_hf(float16 a, float_status *fp_status);
    + uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
    + uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
      
     +/* IEEE BFloat instructions */
     +
     +#define fp_mult_sf_bf(A, B) \
    -+    fp_mult_sf_sf(bfloat16_to_float32(A, &env->hvx_fp_status), \
    -+                  bfloat16_to_float32(B, &env->hvx_fp_status), \
    -+                  &env->hvx_fp_status)
    ++    float32_mul(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
    ++
     +#define fp_add_sf_bf(A, B) \
    -+    fp_add_sf_sf(bfloat16_to_float32(A, &env->hvx_fp_status), \
    -+                 bfloat16_to_float32(B, &env->hvx_fp_status), \
    -+                 &env->hvx_fp_status)
    ++    float32_add(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
    ++
     +#define fp_sub_sf_bf(A, B) \
    -+    fp_sub_sf_sf(bfloat16_to_float32(A, &env->hvx_fp_status), \
    -+                 bfloat16_to_float32(B, &env->hvx_fp_status), \
    -+                 &env->hvx_fp_status)
    ++    float32_sub(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
     +
    -+uint32_t fp_mult_sf_bf_acc(uint16_t op1, uint16_t op2, uint32_t acc,
    -+                           float_status *fp_status);
    -+
    -+#define bf_to_sf(A, fp_status) bfloat16_to_float32(A, fp_status)
    ++#define fp_mult_sf_bf_acc(f1, f2, f3) \
    ++    float32_muladd(bf_to_sf(f1), bf_to_sf(f2), f3, 0, &env->hvx_fp_status)
     +
     +static inline uint16_t sf_to_bf(int32_t A, float_status *fp_status)
     +{
    @@ target/hexagon/mmvec/hvx_ieee_fp.h: int16_t conv_hf_h(int16_t a, float_status *f
     +}
     +
     +#define fp_min_bf(A, B) \
    -+    sf_to_bf(fp_min_sf(bf_to_sf(A, &env->hvx_fp_status), \
    -+                       bf_to_sf(B, &env->hvx_fp_status), \
    -+                       &env->hvx_fp_status), \
    ++    sf_to_bf(float32_min(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status), \
     +             &env->hvx_fp_status);
     +
     +#define fp_max_bf(A, B) \
    -+    sf_to_bf(fp_max_sf(bf_to_sf(A, &env->hvx_fp_status), \
    -+                       bf_to_sf(B, &env->hvx_fp_status), \
    -+                       &env->hvx_fp_status), \
    ++    sf_to_bf(float32_max(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status), \
     +             &env->hvx_fp_status);
     +
      #endif
    @@ target/hexagon/mmvec/macros.h
      ## target/hexagon/mmvec/mmvec.h ##
     @@ target/hexagon/mmvec/mmvec.h: typedef union {
          int8_t    b[MAX_VEC_SIZE_BYTES / 1];
    -     int32_t  sf[MAX_VEC_SIZE_BYTES / 4];   /* single float (32-bit) */
    -     int16_t  hf[MAX_VEC_SIZE_BYTES / 2];   /* half float (16-bit) */
    -+    uint16_t bf[MAX_VEC_SIZE_BYTES / 2];   /* bfloat16 */
    +     float32  sf[MAX_VEC_SIZE_BYTES / 4];
    +     float16  hf[MAX_VEC_SIZE_BYTES / 2];
    ++    bfloat16 bf[MAX_VEC_SIZE_BYTES / 2];
      } MMVector;
      
      typedef union {
     
    - ## target/hexagon/mmvec/hvx_ieee_fp.c ##
    -@@ target/hexagon/mmvec/hvx_ieee_fp.c: uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
    -     }
    -     return float16_compare(a1, a2, fp_status) == float_relation_greater;
    - }
    -+
    -+DEF_FP_INSN_3(mult_sf_bf_acc, 32, 16, 16, 32,
    -+              float32_muladd(bf_to_sf(f1, fp_status), bf_to_sf(f2, fp_status),
    -+                             f3, 0, fp_status))
    -
      ## target/hexagon/imported/mmvec/encode_ext.def ##
     @@ target/hexagon/imported/mmvec/encode_ext.def: DEF_ENC(V6_vgthf_or,"00011100100vvvvvPP1uuuuu001101xx")
      DEF_ENC(V6_vgtsf_xor,"00011100100vvvvvPP1uuuuu111010xx")
    @@ target/hexagon/imported/mmvec/ext.idef: ITERATOR_INSN_SHIFT_SLOT_FLT(16, vconv_h
     +    VddV.v[1].sf[i] = fp_mult_sf_bf(VuV.bf[2*i+1], VvV.bf[2*i+1]); fBFLOAT())
     +ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vmpy_sf_bf_acc,
     +    "Vxx32.sf+=vmpy(Vu32.bf,Vv32.bf)", "Vector IEEE fma: hf widen to sf",
    -+    VxxV.v[0].sf[i] = fp_mult_sf_bf_acc(VuV.bf[2*i], VvV.bf[2*i],
    -+                                        VxxV.v[0].sf[i], &env->hvx_fp_status);
    -+    VxxV.v[1].sf[i] = fp_mult_sf_bf_acc(VuV.bf[2*i+1], VvV.bf[2*i+1],
    -+                                        VxxV.v[1].sf[i], &env->hvx_fp_status);
    ++    VxxV.v[0].sf[i] = fp_mult_sf_bf_acc(VuV.bf[2*i], VvV.bf[2*i], VxxV.v[0].sf[i]);
    ++    VxxV.v[1].sf[i] = fp_mult_sf_bf_acc(VuV.bf[2*i+1], VvV.bf[2*i+1], VxxV.v[1].sf[i]);
     +    fCVI_VX_NO_TMP_LD(); fBFLOAT())
     +ITERATOR_INSN_IEEE_FP_16(32, vcvt_bf_sf,
     +    "Vd32.bf=vcvt(Vu32.sf,Vv32.sf)",   "Vector IEEE cvt: sf to bf",
 7:  0cfe85d9fb = 12:  e66f33dc97 tests/hexagon: add tests for v68 HVX IEEE float arithmetics
 8:  eb66aadfac = 13:  5055daa72b tests/hexagon: add tests for v68 HVX IEEE float min/max
 9:  166c7bc232 = 14:  e0d756ec35 tests/hexagon: add tests for v68 HVX IEEE float conversions
10:  cdc88a2115 = 15:  f46538124c tests/hexagon: add tests for v68 HVX IEEE float comparisons
11:  54d79eb29d = 16:  12d1c25d33 tests/hexagon: add tests for HVX bfloat
Signature · 1 line
2.37.2
#1 lore raw

PATCH v3 1/16 tests/docker: Update hexagon cross toolchain to 22.1.0

From: Brian Cain <[email protected]>

Update the hexagon cross-compiler Docker container to use toolchain version 22.1.0, replacing the previous 12.Dec.2023 release.

Changes to accommodate the new toolchain:

- Add libc++1, libc++abi1, libunwind-19 runtime deps for the new LLVM-based toolchain
- Add zstd for the new .tar.zst archive format
- Update artifact URL domain to artifacts.codelinaro.org

---
 tests/docker/dockerfiles/debian-hexagon-cross.docker | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tests/docker/dockerfiles/debian-hexagon-cross.docker +7 -3
index 91d4b71ac9..636d0ca8a0 100644
@@ -19,7 +19,11 @@ RUN apt-get update && \
         curl \
         ccache \
         xz-utils \
+        zstd \
         ca-certificates \
+        libc++1 \
+        libc++abi1 \
+        libunwind-19 \
         bison \
         flex \
         git \
@@ -40,12 +44,12 @@ RUN apt-get update && \
     dpkg-query --showformat '${Package}_${Version}_${Architecture}\n' --show > /packages.txt
 
 ENV TOOLCHAIN_INSTALL /opt
-ENV TOOLCHAIN_RELEASE 12.Dec.2023
+ENV TOOLCHAIN_RELEASE 22.1.0
 ENV TOOLCHAIN_BASENAME "clang+llvm-${TOOLCHAIN_RELEASE}-cross-hexagon-unknown-linux-musl"
-ENV TOOLCHAIN_URL https://codelinaro.jfrog.io/artifactory/codelinaro-toolchain-for-hexagon/${TOOLCHAIN_RELEASE}/${TOOLCHAIN_BASENAME}.tar.xz
+ENV TOOLCHAIN_URL https://artifacts.codelinaro.org/artifactory/codelinaro-toolchain-for-hexagon/${TOOLCHAIN_RELEASE}_/${TOOLCHAIN_BASENAME}.tar.zst
 ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers"
 
-RUN curl -#SL "$TOOLCHAIN_URL" | tar -xJC "$TOOLCHAIN_INSTALL"
+RUN curl -#SL "$TOOLCHAIN_URL" | tar --zstd -xC "$TOOLCHAIN_INSTALL"
 ENV PATH $PATH:${TOOLCHAIN_INSTALL}/${TOOLCHAIN_BASENAME}/x86_64-linux-gnu/bin
 ENV MAKE /usr/bin/make
 # As a final step configure the user (if env is defined)
Signature · 1 line
2.37.2
#2 lore raw

PATCH v3 2/16 target/hexagon: fix incorrect/too-permissive HVX encodings

In reply to Matheus Tavares Bernardino

The following encodings have become stricter since v68:

- V6_vunpackob, V6_vunpackoh: ---00 -> --000
- V6_vaddbq/hq/wq, V6_vaddbnq/hnq/wnq: ---01 -> --001
- V6_vsubbq/hq, V6_vsubwq/bnq/hnq/wnq: ---01/---10 -> --001/--010
- V6_vhist, V6_vwhist128/256, V6_vwhist128/256_sat: ---00 -> --000
- V6_vhistq, V6_vwhist128/256q, V6_vwhist128/256q_sat: ---10 -> --010

Pre v68 compilers, by default, already use "0" for the non-specified bit that changed in v68, so unless someone is manually writing the binary encoding, this should not cause any backwards incompatibility with pre-v68 binaries.

---
 target/hexagon/imported/mmvec/encode_ext.def | 48 ++++++++++----------
 1 file changed, 24 insertions(+), 24 deletions(-)
target/hexagon/imported/mmvec/encode_ext.def +24 -24
index 402438f566..6d70086b5f 100644
@@ -647,36 +647,36 @@ DEF_ENC(V6_vsubububb_sat,    ICLASS_CJ" 1 110 101 vvvvv PP 0 uuuuu 101 ddddd")
 DEF_ENC(V6_vmpyewuh_64,        ICLASS_CJ" 1 110 101 vvvvv PP 0 uuuuu 110 ddddd")
 
 DEF_FIELDROW_DESC32(        ICLASS_CJ" 1 110 --0 ----- PP 1 ----- ----- ---","Vx32=Vu32")
-DEF_ENC(V6_vunpackob,         ICLASS_CJ" 1 110 --0 ---00 PP 1 uuuuu 000 xxxxx") //
-DEF_ENC(V6_vunpackoh,         ICLASS_CJ" 1 110 --0 ---00 PP 1 uuuuu 001 xxxxx") //
+DEF_ENC(V6_vunpackob,         ICLASS_CJ" 1 110 --0 --000 PP 1 uuuuu 000 xxxxx") //
+DEF_ENC(V6_vunpackoh,         ICLASS_CJ" 1 110 --0 --000 PP 1 uuuuu 001 xxxxx") //
 //DEF_ENC(V6_vunpackow,     ICLASS_CJ" 1 110 --0 ---00 PP 1 uuuuu 010 xxxxx") //
 
-DEF_ENC(V6_vhist,            ICLASS_CJ" 1 110 --0 ---00 PP 1 -000- 100 -----")
-DEF_ENC(V6_vwhist256,        ICLASS_CJ" 1 110 --0 ---00 PP 1 -0010 100 -----")
-DEF_ENC(V6_vwhist256_sat,    ICLASS_CJ" 1 110 --0 ---00 PP 1 -0011 100 -----")
-DEF_ENC(V6_vwhist128,        ICLASS_CJ" 1 110 --0 ---00 PP 1 -010- 100 -----")
-DEF_ENC(V6_vwhist128m,        ICLASS_CJ" 1 110 --0 ---00 PP 1 -011i 100 -----")
+DEF_ENC(V6_vhist,            ICLASS_CJ" 1 110 --0 --000 PP 1 -000- 100 -----")
+DEF_ENC(V6_vwhist256,        ICLASS_CJ" 1 110 --0 --000 PP 1 -0010 100 -----")
+DEF_ENC(V6_vwhist256_sat,    ICLASS_CJ" 1 110 --0 --000 PP 1 -0011 100 -----")
+DEF_ENC(V6_vwhist128,        ICLASS_CJ" 1 110 --0 --000 PP 1 -010- 100 -----")
+DEF_ENC(V6_vwhist128m,        ICLASS_CJ" 1 110 --0 --000 PP 1 -011i 100 -----")
 
 DEF_FIELDROW_DESC32(        ICLASS_CJ" 1 110 --0 ----- PP 1 ----- ----- ---","if (Qv4) Vx32=Vu32")
-DEF_ENC(V6_vaddbq,             ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 000 xxxxx") //
-DEF_ENC(V6_vaddhq,             ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 001 xxxxx") //
-DEF_ENC(V6_vaddwq,             ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 010 xxxxx") //
-DEF_ENC(V6_vaddbnq,         ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 011 xxxxx") //
-DEF_ENC(V6_vaddhnq,         ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 100 xxxxx") //
-DEF_ENC(V6_vaddwnq,         ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 101 xxxxx") //
-DEF_ENC(V6_vsubbq,             ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 110 xxxxx") //
-DEF_ENC(V6_vsubhq,             ICLASS_CJ" 1 110 vv0 ---01 PP 1 uuuuu 111 xxxxx") //
+DEF_ENC(V6_vaddbq,             ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 000 xxxxx") //
+DEF_ENC(V6_vaddhq,             ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 001 xxxxx") //
+DEF_ENC(V6_vaddwq,             ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 010 xxxxx") //
+DEF_ENC(V6_vaddbnq,         ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 011 xxxxx") //
+DEF_ENC(V6_vaddhnq,         ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 100 xxxxx") //
+DEF_ENC(V6_vaddwnq,         ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 101 xxxxx") //
+DEF_ENC(V6_vsubbq,             ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 110 xxxxx") //
+DEF_ENC(V6_vsubhq,             ICLASS_CJ" 1 110 vv0 --001 PP 1 uuuuu 111 xxxxx") //
 
-DEF_ENC(V6_vsubwq,             ICLASS_CJ" 1 110 vv0 ---10 PP 1 uuuuu 000 xxxxx") //
-DEF_ENC(V6_vsubbnq,         ICLASS_CJ" 1 110 vv0 ---10 PP 1 uuuuu 001 xxxxx") //
-DEF_ENC(V6_vsubhnq,         ICLASS_CJ" 1 110 vv0 ---10 PP 1 uuuuu 010 xxxxx") //
-DEF_ENC(V6_vsubwnq,         ICLASS_CJ" 1 110 vv0 ---10 PP 1 uuuuu 011 xxxxx") //
+DEF_ENC(V6_vsubwq,             ICLASS_CJ" 1 110 vv0 --010 PP 1 uuuuu 000 xxxxx") //
+DEF_ENC(V6_vsubbnq,         ICLASS_CJ" 1 110 vv0 --010 PP 1 uuuuu 001 xxxxx") //
+DEF_ENC(V6_vsubhnq,         ICLASS_CJ" 1 110 vv0 --010 PP 1 uuuuu 010 xxxxx") //
+DEF_ENC(V6_vsubwnq,         ICLASS_CJ" 1 110 vv0 --010 PP 1 uuuuu 011 xxxxx") //
 
-DEF_ENC(V6_vhistq,            ICLASS_CJ" 1 110 vv0 ---10 PP 1 --00- 100 -----")
-DEF_ENC(V6_vwhist256q,        ICLASS_CJ" 1 110 vv0 ---10 PP 1 --010 100 -----")
-DEF_ENC(V6_vwhist256q_sat,    ICLASS_CJ" 1 110 vv0 ---10 PP 1 --011 100 -----")
-DEF_ENC(V6_vwhist128q,        ICLASS_CJ" 1 110 vv0 ---10 PP 1 --10- 100 -----")
-DEF_ENC(V6_vwhist128qm,        ICLASS_CJ" 1 110 vv0 ---10 PP 1 --11i 100 -----")
+DEF_ENC(V6_vhistq,            ICLASS_CJ" 1 110 vv0 --010 PP 1 --00- 100 -----")
+DEF_ENC(V6_vwhist256q,        ICLASS_CJ" 1 110 vv0 --010 PP 1 --010 100 -----")
+DEF_ENC(V6_vwhist256q_sat,    ICLASS_CJ" 1 110 vv0 --010 PP 1 --011 100 -----")
+DEF_ENC(V6_vwhist128q,        ICLASS_CJ" 1 110 vv0 --010 PP 1 --10- 100 -----")
+DEF_ENC(V6_vwhist128qm,        ICLASS_CJ" 1 110 vv0 --010 PP 1 --11i 100 -----")
 
 
 DEF_ENC(V6_vandvqv,            ICLASS_CJ" 1 110 vv0 ---11 PP 1 uuuuu 000 ddddd")
Signature · 1 line
2.37.2
#3 lore raw

PATCH v3 3/16 target/hexagon/cpu: add HVX IEEE FP extension

In reply to Matheus Tavares Bernardino

This flag will be used to control the HVX IEEE float instructions, which are only available at some Hexagon cores. When unavailable, the instruction effectively only set the destination registers to 0.

---
 target/hexagon/cpu.h             |  1 +
 target/hexagon/translate.h       |  1 +
 target/hexagon/attribs_def.h.inc |  3 +++
 target/hexagon/cpu.c             |  1 +
 target/hexagon/translate.c       |  1 +
 target/hexagon/gen_tcg_funcs.py  | 11 ++++++++++
 target/hexagon/hex_common.py     | 35 ++++++++++++++++++++++++++++++++
 7 files changed, 53 insertions(+)
target/hexagon/cpu.h +1 -0
index 85afd59277..77822a48b6 100644
@@ -127,6 +127,7 @@ struct ArchCPU {
     bool lldb_compat;
     target_ulong lldb_stack_adjust;
     bool short_circuit;
+    bool ieee_fp_extension;
 };
 
 #include "cpu_bits.h"
target/hexagon/translate.h +1 -0
index b37cb49238..516aab7038 100644
@@ -70,6 +70,7 @@ typedef struct DisasContext {
     target_ulong branch_dest;
     bool is_tight_loop;
     bool short_circuit;
+    bool ieee_fp_extension;
     bool read_after_write;
     bool has_hvx_overlap;
     TCGv new_value[TOTAL_PER_THREAD_REGS];
target/hexagon/attribs_def.h.inc +3 -0
index 9e3a05f882..c85cd5d17c 100644
@@ -173,5 +173,8 @@ DEF_ATTRIB(NOTE_SHIFT_RESOURCE, "Uses the HVX shift resource.", "", "")
 DEF_ATTRIB(RESTRICT_NOSLOT1_STORE, "Packet must not have slot 1 store", "", "")
 DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be used as a .new.", "", "")
 
+/* HVX IEEE FP extension attributes */
+DEF_ATTRIB(HVX_IEEE_FP, "HVX IEEE FP extension instruction", "", "")
+
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/cpu.c +1 -0
index ffd14bb467..8b72a5d3c8 100644
@@ -54,6 +54,7 @@ static const Property hexagon_cpu_properties[] = {
     DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, lldb_stack_adjust, 0,
                          qdev_prop_uint32, target_ulong),
     DEFINE_PROP_BOOL("short-circuit", HexagonCPU, short_circuit, true),
+    DEFINE_PROP_BOOL("ieee-fp", HexagonCPU, ieee_fp_extension, true),
 };
 
 const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = {
target/hexagon/translate.c +1 -0
index 633401451d..fa8f615a9e 100644
@@ -988,6 +988,7 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
     ctx->branch_cond = TCG_COND_NEVER;
     ctx->is_tight_loop = FIELD_EX32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP);
     ctx->short_circuit = hex_cpu->short_circuit;
+    ctx->ieee_fp_extension = hex_cpu->ieee_fp_extension;
 }
 
 static void hexagon_tr_tb_start(DisasContextBase *db, CPUState *cpu)
target/hexagon/gen_tcg_funcs.py +11 -0
index 87b7f10d7f..b752ec883c 100755
@@ -22,6 +22,14 @@
 import string
 import hex_common
 
+def gen_disabled_ieee_insn(f, tag, regs):
+    f.write("    if (!ctx->ieee_fp_extension) {\n")
+    for regtype, regid in regs:
+        reg = hex_common.get_register(tag, regtype, regid)
+        if reg.is_hvx_reg() and reg.is_written():
+            reg.gen_zero(f)
+    f.write("        return;\n")
+    f.write("    }\n")
 
 ##
 ## Generate the TCG code to call the helper
@@ -62,6 +70,9 @@ def gen_tcg_func(f, tag, regs, imms):
         i = 1 if immlett.isupper() else 0
         f.write(f"    int {hex_common.imm_name(immlett)} = insn->immed[{i}];\n")
 
+    if "A_HVX_IEEE_FP" in hex_common.attribdict[tag]:
+        gen_disabled_ieee_insn(f, tag, regs)
+
     if hex_common.is_idef_parser_enabled(tag):
         declared = []
         ## Handle registers
target/hexagon/hex_common.py +35 -0
index c0e9f26aeb..32a61505ce 100755
@@ -723,6 +723,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -789,6 +794,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -821,6 +831,11 @@ def decl_tcg(self, f, tag, regno):
                                  vreg_src_off(ctx, {self.reg_num}),
                                  sizeof(MMVector), sizeof(MMVector));
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write(ctx, {self.hvx_off()}, {self.reg_num},
@@ -854,6 +869,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -913,6 +933,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num},
@@ -946,6 +971,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMQReg), sizeof(MMQReg), 0);
+        """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -993,6 +1023,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMQReg), sizeof(MMQReg), 0);
+        """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
Signature · 1 line
2.37.2
#4 lore raw

Re: [PATCH v3 03/16] target/hexagon/cpu: add HVX IEEE FP extension

Quoted 89 lines · Matheus Tavares Bernardino

This flag will be used to control the HVX IEEE float instructions, which are only available at some Hexagon cores. When unavailable, the instruction effectively only set the destination registers to 0.

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/cpu.h             |  1 +
 target/hexagon/translate.h       |  1 +
 target/hexagon/attribs_def.h.inc |  3 +++
 target/hexagon/cpu.c             |  1 +
 target/hexagon/translate.c       |  1 +
 target/hexagon/gen_tcg_funcs.py  | 11 ++++++++++
 target/hexagon/hex_common.py     | 35 ++++++++++++++++++++++++++++++++
 7 files changed, 53 insertions(+)
target/hexagon/cpu.h +1 -0
index 85afd59277..77822a48b6 100644
@@ -127,6 +127,7 @@ struct ArchCPU {
     bool lldb_compat;
     target_ulong lldb_stack_adjust;
     bool short_circuit;
+    bool ieee_fp_extension;
 };
 
 #include "cpu_bits.h"
target/hexagon/translate.h +1 -0
index b37cb49238..516aab7038 100644
@@ -70,6 +70,7 @@ typedef struct DisasContext {
     target_ulong branch_dest;
     bool is_tight_loop;
     bool short_circuit;
+    bool ieee_fp_extension;
     bool read_after_write;
     bool has_hvx_overlap;
     TCGv new_value[TOTAL_PER_THREAD_REGS];
target/hexagon/attribs_def.h.inc +3 -0
index 9e3a05f882..c85cd5d17c 100644
@@ -173,5 +173,8 @@ DEF_ATTRIB(NOTE_SHIFT_RESOURCE, "Uses the HVX shift
 resource.", "", "")
 DEF_ATTRIB(RESTRICT_NOSLOT1_STORE, "Packet must not have slot 1 store",
 "", "")
 DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be used as a .new.", "",
 "")
 
+/* HVX IEEE FP extension attributes */
+DEF_ATTRIB(HVX_IEEE_FP, "HVX IEEE FP extension instruction", "", "")
+
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/cpu.c +1 -0
index ffd14bb467..8b72a5d3c8 100644
@@ -54,6 +54,7 @@ static const Property hexagon_cpu_properties[] = {
     DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU,
 lldb_stack_adjust, 0,
                          qdev_prop_uint32, target_ulong),
     DEFINE_PROP_BOOL("short-circuit", HexagonCPU, short_circuit, true),
+    DEFINE_PROP_BOOL("ieee-fp", HexagonCPU, ieee_fp_extension, true),
 };
 

const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = {

target/hexagon/translate.c +1 -0
index 633401451d..fa8f615a9e 100644
@@ -988,6 +988,7 @@ static void
 hexagon_tr_init_disas_context(DisasContextBase *dcbase,
     ctx->branch_cond = TCG_COND_NEVER;
     ctx->is_tight_loop = FIELD_EX32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP);
     ctx->short_circuit = hex_cpu->short_circuit;
+    ctx->ieee_fp_extension = hex_cpu->ieee_fp_extension;
 }
 

static void hexagon_tr_tb_start(DisasContextBase *db, CPUState *cpu)

target/hexagon/gen_tcg_funcs.py +0 -0
index 87b7f10d7f..b752ec883c 100755

target/hexagon/gen_tcg_funcs.py line 31

Quoted 10 lines
target/hexagon/gen_tcg_funcs.py +6 -0
@@ -22,6 +22,14 @@
 import string
 import hex_common
 
+def gen_disabled_ieee_insn(f, tag, regs):
+    f.write("    if (!ctx->ieee_fp_extension) {\n")
+    for regtype, regid in regs:
+        reg = hex_common.get_register(tag, regtype, regid)
+        if reg.is_hvx_reg() and reg.is_written():
+            reg.gen_zero(f)
 

What happens to the non-HVX registers that are written (e.g., address for a post-increment load)? I assume they should also be set to zero.

Quoted 85 lines
target/hexagon/gen_tcg_funcs.py +2 -0
+    f.write("        return;\n")
+    f.write("    }\n")
 
 ##

## Generate the TCG code to call the helper

target/hexagon/gen_tcg_funcs.py +3 -0
@@ -62,6 +70,9 @@ def gen_tcg_func(f, tag, regs, imms):
         i = 1 if immlett.isupper() else 0
         f.write(f"    int {hex_common.imm_name(immlett)} =
 insn->immed[{i}];\n")
 
+    if "A_HVX_IEEE_FP" in hex_common.attribdict[tag]:
+        gen_disabled_ieee_insn(f, tag, regs)
+
     if hex_common.is_idef_parser_enabled(tag):
         declared = []

## Handle registers

target/hexagon/hex_common.py +5 -0
index c0e9f26aeb..32a61505ce 100755
@@ -723,6 +723,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass

def helper_hvx_desc(self, f):

target/hexagon/hex_common.py +5 -0
@@ -789,6 +794,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass

def helper_hvx_desc(self, f):

target/hexagon/hex_common.py +10 -0
@@ -821,6 +831,11 @@ def decl_tcg(self, f, tag, regno):
                                  vreg_src_off(ctx, {self.reg_num}),
                                  sizeof(MMVector), sizeof(MMVector));
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write(ctx, {self.hvx_off()}, {self.reg_num},
@@ -854,6 +869,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         pass

def helper_hvx_desc(self, f):

target/hexagon/hex_common.py +5 -0
@@ -913,6 +933,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num},

target/hexagon/hex_common.py def decl_tcg(self, f, tag, regno): · line 980

Quoted 10 lines
target/hexagon/hex_common.py +5 -0
@@ -946,6 +971,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMQReg), sizeof(MMQReg), 0);
+        """))
 

Do any of these instructions write QRegs? If not, this isn't needed.

Quoted 4 lines
target/hexagon/hex_common.py +0 -0
     def gen_write(self, f, tag):

pass
def helper_hvx_desc(self, f):

target/hexagon/hex_common.py def decl_tcg(self, f, tag, regno): · line 1032

Quoted 10 lines
target/hexagon/hex_common.py +5 -0
@@ -993,6 +1023,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env,
 {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMQReg), sizeof(MMQReg), 0);
+        """))
 

Ditto

Quoted 7 lines
target/hexagon/hex_common.py +0 -0
     def gen_write(self, f, tag):

pass
def helper_hvx_desc(self, f):
--
2.37.2

#5 lore raw

Re: [PATCH v3 03/16] target/hexagon/cpu: add HVX IEEE FP extension

Quoted 89 lines · Taylor Simpson
Quoted 85 lines · Matheus Tavares Bernardino

This flag will be used to control the HVX IEEE float instructions, which are only available at some Hexagon cores. When unavailable, the instruction effectively only set the destination registers to 0.

---
 target/hexagon/cpu.h             |  1 +
 target/hexagon/translate.h       |  1 +
 target/hexagon/attribs_def.h.inc |  3 +++
 target/hexagon/cpu.c             |  1 +
 target/hexagon/translate.c       |  1 +
 target/hexagon/gen_tcg_funcs.py  | 11 ++++++++++
 target/hexagon/hex_common.py     | 35 ++++++++++++++++++++++++++++++++
 7 files changed, 53 insertions(+)
target/hexagon/cpu.h +1 -0
index 85afd59277..77822a48b6 100644
@@ -127,6 +127,7 @@ struct ArchCPU {
     bool lldb_compat;
     target_ulong lldb_stack_adjust;
     bool short_circuit;
+    bool ieee_fp_extension;
 };
 
 #include "cpu_bits.h"
target/hexagon/translate.h +1 -0
index b37cb49238..516aab7038 100644
@@ -70,6 +70,7 @@ typedef struct DisasContext {
     target_ulong branch_dest;
     bool is_tight_loop;
     bool short_circuit;
+    bool ieee_fp_extension;
     bool read_after_write;
     bool has_hvx_overlap;
     TCGv new_value[TOTAL_PER_THREAD_REGS];
target/hexagon/attribs_def.h.inc +3 -0
index 9e3a05f882..c85cd5d17c 100644
@@ -173,5 +173,8 @@ DEF_ATTRIB(NOTE_SHIFT_RESOURCE, "Uses the HVX shift resource.", "", "")
 DEF_ATTRIB(RESTRICT_NOSLOT1_STORE, "Packet must not have slot 1 store", "", "")
 DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be used as a .new.", "", "")
 
+/* HVX IEEE FP extension attributes */
+DEF_ATTRIB(HVX_IEEE_FP, "HVX IEEE FP extension instruction", "", "")
+
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/cpu.c +1 -0
index ffd14bb467..8b72a5d3c8 100644
@@ -54,6 +54,7 @@ static const Property hexagon_cpu_properties[] = {
     DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, lldb_stack_adjust, 0,
                          qdev_prop_uint32, target_ulong),
     DEFINE_PROP_BOOL("short-circuit", HexagonCPU, short_circuit, true),
+    DEFINE_PROP_BOOL("ieee-fp", HexagonCPU, ieee_fp_extension, true),
 };
 
 const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = {
target/hexagon/translate.c +1 -0
index 633401451d..fa8f615a9e 100644
@@ -988,6 +988,7 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
     ctx->branch_cond = TCG_COND_NEVER;
     ctx->is_tight_loop = FIELD_EX32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP);
     ctx->short_circuit = hex_cpu->short_circuit;
+    ctx->ieee_fp_extension = hex_cpu->ieee_fp_extension;
 }
 
 static void hexagon_tr_tb_start(DisasContextBase *db, CPUState *cpu)
target/hexagon/gen_tcg_funcs.py +0 -0
index 87b7f10d7f..b752ec883c 100755
@@ -22,6 +22,14 @@
 import string
 import hex_common
 
Quoted 9 lines

target/hexagon/gen_tcg_funcs.py line 30

Quoted 6 lines
target/hexagon/gen_tcg_funcs.py +6 -0
+def gen_disabled_ieee_insn(f, tag, regs):
+    f.write("    if (!ctx->ieee_fp_extension) {\n")
+    for regtype, regid in regs:
+        reg = hex_common.get_register(tag, regtype, regid)
+        if reg.is_hvx_reg() and reg.is_written():
+            reg.gen_zero(f)

What happens to the non-HVX registers that are written (e.g., address for a post-increment load)? I assume they should also be set to zero.

None of these instructions write to non-HVX registers.

Quoted 84 lines
Quoted 84 lines
target/hexagon/gen_tcg_funcs.py +5 -0
+    f.write("        return;\n")
+    f.write("    }\n")
 
 ##
 ## Generate the TCG code to call the helper
@@ -62,6 +70,9 @@ def gen_tcg_func(f, tag, regs, imms):
         i = 1 if immlett.isupper() else 0
         f.write(f"    int {hex_common.imm_name(immlett)} = insn->immed[{i}];\n")
 
+    if "A_HVX_IEEE_FP" in hex_common.attribdict[tag]:
+        gen_disabled_ieee_insn(f, tag, regs)
+
     if hex_common.is_idef_parser_enabled(tag):
         declared = []
         ## Handle registers
target/hexagon/hex_common.py +25 -0
index c0e9f26aeb..32a61505ce 100755
@@ -723,6 +723,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -789,6 +794,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -821,6 +831,11 @@ def decl_tcg(self, f, tag, regno):
                                  vreg_src_off(ctx, {self.reg_num}),
                                  sizeof(MMVector), sizeof(MMVector));
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+                tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                    sizeof(MMVector), sizeof(MMVector), 0);
+            """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write(ctx, {self.hvx_off()}, {self.reg_num},
@@ -854,6 +869,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         pass
     def helper_hvx_desc(self, f):
@@ -913,6 +933,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMVectorPair), sizeof(MMVectorPair), 0);
+        """))
     def gen_write(self, f, tag):
         f.write(code_fmt(f"""\
             gen_vreg_write_pair(ctx, {self.hvx_off()}, {self.reg_num},
@@ -946,6 +971,11 @@ def decl_tcg(self, f, tag, regno):
                 TCGv_ptr {self.reg_tcg()} = tcg_temp_new_ptr();
                 tcg_gen_addi_ptr({self.reg_tcg()}, tcg_env, {self.hvx_off()});
             """))
Quoted 8 lines

target/hexagon/hex_common.py def decl_tcg(self, f, tag, regno): · line 978

Quoted 5 lines
target/hexagon/hex_common.py +5 -0
+    def gen_zero(self, f):
+        f.write(code_fmt(f"""\
+            tcg_gen_gvec_dup_imm(MO_64, {self.hvx_off()},
+                sizeof(MMQReg), sizeof(MMQReg), 0);
+        """))

Do any of these instructions write QRegs? If not, this isn't needed.

They do not. Let me remove this.

#6 lore raw

PATCH v3 4/16 hexagon: group cpu configurations in their own struct

In reply to Matheus Tavares Bernardino

This will be used in a follow up commit.

---
 target/hexagon/cpu.h       | 10 +++-------
 target/hexagon/cpu_bits.h  |  7 +++++++
 target/hexagon/cpu.c       | 14 +++++++-------
 target/hexagon/translate.c |  6 +++---
 4 files changed, 20 insertions(+), 17 deletions(-)
target/hexagon/cpu.h +3 -7
index 77822a48b6..d28beaa92f 100644
@@ -119,19 +119,15 @@ typedef struct HexagonCPUClass {
     ResettablePhases parent_phases;
 } HexagonCPUClass;
 
+#include "cpu_bits.h"
+
 struct ArchCPU {
     CPUState parent_obj;
 
     CPUHexagonState env;
-
-    bool lldb_compat;
-    target_ulong lldb_stack_adjust;
-    bool short_circuit;
-    bool ieee_fp_extension;
+    HexagonCPUConfig cfg;
 };
 
-#include "cpu_bits.h"
-
 FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1)
 
 G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
target/hexagon/cpu_bits.h +7 -0
index 19beca81c0..83d13de569 100644
@@ -20,6 +20,13 @@
 
 #include "qemu/bitops.h"
 
+typedef struct HexagonCPUConfig {
+    bool lldb_compat;
+    uint32_t lldb_stack_adjust;
+    bool short_circuit;
+    bool ieee_fp_extension;
+} HexagonCPUConfig;
+
 #define PCALIGN 4
 #define PCALIGN_MASK (PCALIGN - 1)
 
target/hexagon/cpu.c +7 -7
index 8b72a5d3c8..5470d9c7ce 100644
@@ -50,11 +50,11 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model)
 }
 
 static const Property hexagon_cpu_properties[] = {
-    DEFINE_PROP_BOOL("lldb-compat", HexagonCPU, lldb_compat, false),
-    DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, lldb_stack_adjust, 0,
-                         qdev_prop_uint32, target_ulong),
-    DEFINE_PROP_BOOL("short-circuit", HexagonCPU, short_circuit, true),
-    DEFINE_PROP_BOOL("ieee-fp", HexagonCPU, ieee_fp_extension, true),
+    DEFINE_PROP_BOOL("lldb-compat", HexagonCPU, cfg.lldb_compat, false),
+    DEFINE_PROP_UNSIGNED("lldb-stack-adjust", HexagonCPU, cfg.lldb_stack_adjust,
+                         0, qdev_prop_uint32, target_ulong),
+    DEFINE_PROP_BOOL("short-circuit", HexagonCPU, cfg.short_circuit, true),
+    DEFINE_PROP_BOOL("ieee-fp", HexagonCPU, cfg.ieee_fp_extension, true),
 };
 
 const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = {
@@ -77,7 +77,7 @@ const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS] = {
 static target_ulong adjust_stack_ptrs(CPUHexagonState *env, target_ulong addr)
 {
     HexagonCPU *cpu = env_archcpu(env);
-    target_ulong stack_adjust = cpu->lldb_stack_adjust;
+    target_ulong stack_adjust = cpu->cfg.lldb_stack_adjust;
     target_ulong stack_start = env->stack_start;
     target_ulong stack_size = 0x10000;
 
@@ -181,7 +181,7 @@ static void hexagon_dump(CPUHexagonState *env, FILE *f, int flags)
 {
     HexagonCPU *cpu = env_archcpu(env);
 
-    if (cpu->lldb_compat) {
+    if (cpu->cfg.lldb_compat) {
         /*
          * When comparing with LLDB, it doesn't step through single-cycle
          * hardware loops the same way.  So, we just skip them here
target/hexagon/translate.c +3 -3
index fa8f615a9e..ce3af96675 100644
@@ -987,8 +987,8 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
     ctx->num_hvx_insns = 0;
     ctx->branch_cond = TCG_COND_NEVER;
     ctx->is_tight_loop = FIELD_EX32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP);
-    ctx->short_circuit = hex_cpu->short_circuit;
-    ctx->ieee_fp_extension = hex_cpu->ieee_fp_extension;
+    ctx->short_circuit = hex_cpu->cfg.short_circuit;
+    ctx->ieee_fp_extension = hex_cpu->cfg.ieee_fp_extension;
 }
 
 static void hexagon_tr_tb_start(DisasContextBase *db, CPUState *cpu)
@@ -1041,7 +1041,7 @@ static void hexagon_tr_translate_packet(DisasContextBase *dcbase, CPUState *cpu)
          * so end the TLB after every packet.
          */
         HexagonCPU *hex_cpu = env_archcpu(env);
-        if (hex_cpu->lldb_compat && qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
+        if (hex_cpu->cfg.lldb_compat && qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
             ctx->base.is_jmp = DISAS_TOO_MANY;
         }
     }
Signature · 1 line
2.37.2
Reviewed-by on v3 4/16
#7 lore raw

Re: [PATCH v3 04/16] hexagon: group cpu configurations in their own struct

Quoted 11 lines · Matheus Tavares Bernardino

This will be used in a follow up commit.

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/cpu.h       | 10 +++-------
 target/hexagon/cpu_bits.h  |  7 +++++++
 target/hexagon/cpu.c       | 14 +++++++-------
 target/hexagon/translate.c |  6 +++---
 4 files changed, 20 insertions(+), 17 deletions(-)
#8 lore raw

PATCH v3 5/16 hexagon: print info on "-d in_asm" for disabled IEEE FP instructions

In reply to Matheus Tavares Bernardino

When cpu->cfg.ieee_fp_extension is off, IEEE FP instructions don't get executed. Let's print that info on the "-d in_asm" output to help users. This will generate an output like the following:

0x00020e30: 0x1f82e1c0 { V0.sf = vadd(V1.sf,V2.sf) (disabled: no ieee_fp) }

---
 target/hexagon/cpu_bits.h  | 3 ++-
 target/hexagon/printinsn.h | 2 +-
 disas/hexagon.c            | 3 ++-
 target/hexagon/cpu.c       | 2 ++
 target/hexagon/decode.c    | 4 ++--
 target/hexagon/printinsn.c | 7 ++++++-
 6 files changed, 15 insertions(+), 6 deletions(-)
target/hexagon/cpu_bits.h +2 -1
index 83d13de569..1f9e617d72 100644
@@ -72,6 +72,7 @@ static inline bool is_packet_end(uint32_t endocing)
     return ((bits == 0x3) || (bits == 0x0));
 }
 
-int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc, GString *buf);
+int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc,
+                        GString *buf, const HexagonCPUConfig *cfg);
 
 #endif
target/hexagon/printinsn.h +1 -1
index 2ecd1731d0..6a45ec571f 100644
@@ -21,7 +21,7 @@
 #include "insn.h"
 
 void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words,
-                         target_ulong pc);
+                         target_ulong pc, const HexagonCPUConfig *cfg);
 void snprint_a_pkt_debug(GString *buf, Packet *pkt);
 
 #endif
disas/hexagon.c +2 -1
index c1a4ffc5f6..e2d3804606 100644
@@ -57,8 +57,9 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
         return PACKET_WORDS_MAX * sizeof(uint32_t);
     }
 
+    const HexagonCPUConfig *cfg = info->target_info;
     buf = g_string_sized_new(PACKET_BUFFER_LEN);
-    len = disassemble_hexagon(words, i, memaddr, buf);
+    len = disassemble_hexagon(words, i, memaddr, buf, cfg);
     (*info->fprintf_func)(info->stream, "%s", buf->str);
     g_string_free(buf, true);
 
target/hexagon/cpu.c +2 -0
index 5470d9c7ce..d7f4df5f96 100644
@@ -307,6 +307,8 @@ static void hexagon_cpu_disas_set_info(const CPUState *cs,
 {
     info->print_insn = print_insn_hexagon;
     info->endian = BFD_ENDIAN_LITTLE;
+    HexagonCPU *cpu = HEXAGON_CPU(cs);
+    info->target_info = &cpu->cfg;
 }
 
 static void hexagon_cpu_realize(DeviceState *dev, Error **errp)
target/hexagon/decode.c +2 -2
index dbc9c630e8..d7ce8c8e1b 100644
@@ -801,7 +801,7 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,
 
 /* Used for "-d in_asm" logging */
 int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc,
-                        GString *buf)
+                        GString *buf, const HexagonCPUConfig *cfg)
 {
     DisasContext ctx;
     Packet pkt;
@@ -810,7 +810,7 @@ int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc,
     ctx.pkt = &pkt;
 
     if (decode_packet(&ctx, nwords, words, &pkt, true) > 0) {
-        snprint_a_pkt_disas(buf, &pkt, words, pc);
+        snprint_a_pkt_disas(buf, &pkt, words, pc, cfg);
         return pkt.encod_pkt_size_in_bytes;
     } else {
         g_string_assign(buf, "<invalid>");
target/hexagon/printinsn.c +6 -1
index 4865cdd133..85527f56e2 100644
@@ -51,7 +51,7 @@ static void snprintinsn(GString *buf, Insn *insn)
 }
 
 void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words,
-                         target_ulong pc)
+                         target_ulong pc, const HexagonCPUConfig *cfg)
 {
     bool has_endloop0 = false;
     bool has_endloop1 = false;
@@ -85,6 +85,11 @@ void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words,
         g_string_append(buf, "\t");
         snprintinsn(buf, &(pkt->insn[i]));
 
+        if (!cfg->ieee_fp_extension &&
+            GET_ATTRIB(pkt->insn[i].opcode, A_HVX_IEEE_FP)) {
+            g_string_append(buf, " (disabled: no ieee_fp)");
+        }
+
         if (i < pkt->num_insns - 1) {
             /*
              * Subinstructions are two instructions encoded
Signature · 1 line
2.37.2
Reviewed-by on v3 5/16
#9 lore raw

Re: [PATCH v3 05/16] hexagon: print info on "-d in_asm" for disabled IEEE FP instructions

Quoted 9 lines · Matheus Tavares Bernardino

When cpu->cfg.ieee_fp_extension is off, IEEE FP instructions don't get executed. Let's print that info on the "-d in_asm" output to help users. This will generate an output like the following:

0x00020e30: 0x1f82e1c0 { V0.sf = vadd(V1.sf,V2.sf) (disabled: no
ieee_fp) }

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

Quoted 9 lines
---
 target/hexagon/cpu_bits.h  | 3 ++-
 target/hexagon/printinsn.h | 2 +-
 disas/hexagon.c            | 3 ++-
 target/hexagon/cpu.c       | 2 ++
 target/hexagon/decode.c    | 4 ++--
 target/hexagon/printinsn.c | 7 ++++++-
 6 files changed, 15 insertions(+), 6 deletions(-)
#10 lore raw

PATCH v3 6/16 target/hexagon: add v68 HVX IEEE float arithmetic insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE floating-point arithmetic instructions:
- vmpy_sf_sf, vmpy_sf_hf, vmpy_hf_hf: multiply operations
- vdmpy_sf_hf: dot-product multiply
- vmpy_sf_hf_acc, vmpy_hf_hf_acc, vdmpy_sf_hf_acc: multiply-accumulate
- vadd_sf_sf, vsub_sf_sf, vadd_sf_hf, vsub_sf_hf: add/sub with sf output
- vadd_hf_hf, vsub_hf_hf: add/sub with hf output

---
 target/hexagon/cpu.h                         |   1 +
 target/hexagon/mmvec/hvx_ieee_fp.h           |  18 ++++
 target/hexagon/mmvec/macros.h                |   1 +
 target/hexagon/mmvec/mmvec.h                 |   2 +
 target/hexagon/attribs_def.h.inc             |   4 +
 target/hexagon/arch.c                        |   8 ++
 target/hexagon/cpu.c                         |   3 +
 target/hexagon/mmvec/hvx_ieee_fp.c           |  21 ++++
 target/hexagon/hex_common.py                 |   1 +
 target/hexagon/imported/mmvec/encode_ext.def |  18 ++++
 target/hexagon/imported/mmvec/ext.idef       | 101 +++++++++++++++++++
 target/hexagon/meson.build                   |   1 +
 12 files changed, 179 insertions(+)
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.h
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.c
target/hexagon/cpu.h +1 -0
index d28beaa92f..5a008d1949 100644
@@ -87,6 +87,7 @@ typedef struct CPUArchState {
     MemLog mem_log_stores[STORES_MAX];
 
     float_status fp_status;
+    float_status hvx_fp_status;
 
     target_ulong llsc_addr;
     target_ulong llsc_val;
target/hexagon/mmvec/hvx_ieee_fp.h new file +18 -0
new file mode 100644
index 0000000000..75008deb3b
@@ -0,0 +1,18 @@
+/*
+ *  Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HVX_IEEE_H
+#define HEXAGON_HVX_IEEE_H
+
+#include "fpu/softfloat.h"
+
+#define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
+
+float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
+float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
+                 float_status *fp_status);
+
+#endif
target/hexagon/mmvec/macros.h +1 -0
index c7840fbf2e..ac709d8993 100644
@@ -23,6 +23,7 @@
 #include "mmvec/system_ext_mmvec.h"
 #include "accel/tcg/getpc.h"
 #include "accel/tcg/probe.h"
+#include "mmvec/hvx_ieee_fp.h"
 
 #ifndef QEMU_GENERATE
 #define VdV      (*(MMVector *restrict)(VdV_void))
target/hexagon/mmvec/mmvec.h +2 -0
index 52d470709c..31909303b5 100644
@@ -38,6 +38,8 @@ typedef union {
     int16_t   h[MAX_VEC_SIZE_BYTES / 2];
     uint8_t  ub[MAX_VEC_SIZE_BYTES / 1];
     int8_t    b[MAX_VEC_SIZE_BYTES / 1];
+    float32  sf[MAX_VEC_SIZE_BYTES / 4];
+    float16  hf[MAX_VEC_SIZE_BYTES / 2];
 } MMVector;
 
 typedef union {
target/hexagon/attribs_def.h.inc +4 -0
index c85cd5d17c..d3c4bf6301 100644
@@ -175,6 +175,10 @@ DEF_ATTRIB(RESTRICT_LATEPRED, "Predicate can not be used as a .new.", "", "")
 
 /* 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_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", "", "")
 
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/arch.c +8 -0
index e17e714a6a..358aa71e03 100644
@@ -199,6 +199,10 @@ void arch_fpop_start(CPUHexagonState *env)
     set_float_rounding_mode(
         softfloat_roundingmodes[fREAD_REG_FIELD(USR, USR_FPRND)],
         &env->fp_status);
+    /*
+     * No need to check env->hvx_fp_status, these instructions don't
+     * raise exceptions nor interact with usr fields.
+     */
 }
 
 #ifdef CONFIG_USER_ONLY
@@ -232,6 +236,10 @@ void arch_fpop_end(CPUHexagonState *env, bool pkt_need_commit)
         SOFTFLOAT_TEST_FLAG(float_flag_overflow, FPOVFF, FPOVFE);
         SOFTFLOAT_TEST_FLAG(float_flag_underflow, FPUNFF, FPUNFE);
     }
+    /*
+     * No need to check env->hvx_fp_status, these instructions don't
+     * raise exceptions nor interact with usr fields.
+     */
 }
 
 int arch_sf_recip_common(float32 *Rs, float32 *Rt, float32 *Rd, int *adjust,
target/hexagon/cpu.c +3 -0
index d7f4df5f96..d6ca51f175 100644
@@ -300,6 +300,9 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)
     set_float_detect_tininess(float_tininess_before_rounding, &env->fp_status);
     /* Default NaN value: sign bit set, all frac bits set */
     set_float_default_nan_pattern(0b11111111, &env->fp_status);
+
+    set_default_nan_mode(1, &env->hvx_fp_status);
+    set_float_default_nan_pattern(0b01111111, &env->hvx_fp_status);
 }
 
 static void hexagon_cpu_disas_set_info(const CPUState *cs,
target/hexagon/mmvec/hvx_ieee_fp.c new file +21 -0
new file mode 100644
index 0000000000..3367226998
@@ -0,0 +1,21 @@
+/*
+ *  Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hvx_ieee_fp.h"
+
+float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status)
+{
+    return float32_mul(float16_to_float32(a1, true, fp_status),
+                       float16_to_float32(a2, true, fp_status), fp_status);
+}
+
+float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
+                 float_status *fp_status)
+{
+    return float32_add(fp_mult_sf_hf(a1, a3, fp_status),
+                       fp_mult_sf_hf(a2, a4, fp_status), fp_status);
+}
target/hexagon/hex_common.py +1 -0
index 32a61505ce..9e8bcfdcf0 100755
@@ -215,6 +215,7 @@ def need_env(tag):
             "A_LOAD" in attribdict[tag] or
             "A_CVI_GATHER" in attribdict[tag] or
             "A_CVI_SCATTER" in attribdict[tag] or
+            "A_HVX_IEEE_FP" in attribdict[tag] or
             "A_IMPLICIT_WRITES_USR" in attribdict[tag])
 
 
target/hexagon/imported/mmvec/encode_ext.def +18 -0
index 6d70086b5f..4ce87d09fd 100644
@@ -804,5 +804,23 @@ DEF_ENC(V6_vmpyewuh,    ICLASS_CJ" 1 111 111 vvvvv PP 0 uuuuu 101 ddddd")
 DEF_ENC(V6_vmpyowh,        ICLASS_CJ" 1 111 111 vvvvv PP 0 uuuuu 111 ddddd")
 DEF_ENC(V6_vmpyuhvs,"00011111110vvvvvPP1uuuuu111ddddd")
 
+/* IEEE FP multiply instructions */
+DEF_ENC(V6_vmpy_sf_sf,"00011111100vvvvvPP1uuuuu001ddddd")
+DEF_ENC(V6_vmpy_sf_hf,"00011111100vvvvvPP1uuuuu010ddddd")
+DEF_ENC(V6_vmpy_hf_hf,"00011111100vvvvvPP1uuuuu011ddddd")
+DEF_ENC(V6_vdmpy_sf_hf,"00011111101vvvvvPP1uuuuu110ddddd")
+
+/* IEEE FP multiply-accumulate instructions */
+DEF_ENC(V6_vmpy_sf_hf_acc,"00011100010vvvvvPP1uuuuu001xxxxx")
+DEF_ENC(V6_vmpy_hf_hf_acc,"00011100010vvvvvPP1uuuuu010xxxxx")
+DEF_ENC(V6_vdmpy_sf_hf_acc,"00011100010vvvvvPP1uuuuu011xxxxx")
+
+/* IEEE FP add/sub instructions */
+DEF_ENC(V6_vadd_sf_sf,"00011111100vvvvvPP1uuuuu110ddddd")
+DEF_ENC(V6_vsub_sf_sf,"00011111100vvvvvPP1uuuuu111ddddd")
+DEF_ENC(V6_vadd_sf_hf,"00011111100vvvvvPP1uuuuu100ddddd")
+DEF_ENC(V6_vsub_sf_hf,"00011111100vvvvvPP1uuuuu101ddddd")
+DEF_ENC(V6_vadd_hf_hf,"00011111101vvvvvPP1uuuuu111ddddd")
+DEF_ENC(V6_vsub_hf_hf,"00011111011vvvvvPP1uuuuu000ddddd")
 
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +101 -0

110 lines not on this page · raw message

target/hexagon/meson.build +1 -0
index d169cf71b2..9195014821 100644
@@ -250,6 +250,7 @@ hexagon_ss.add(files(
     'fma_emu.c',
     'mmvec/decode_ext_mmvec.c',
     'mmvec/system_ext_mmvec.c',
+    'mmvec/hvx_ieee_fp.c',
 ))
 
 #
Signature · 1 line
2.37.2
Reviewed-by on v3 6/16
#11 lore raw

Re: [PATCH v3 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns

Quoted 59 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point arithmetic instructions:
- vmpy_sf_sf, vmpy_sf_hf, vmpy_hf_hf: multiply operations
- vdmpy_sf_hf: dot-product multiply
- vmpy_sf_hf_acc, vmpy_hf_hf_acc, vdmpy_sf_hf_acc: multiply-accumulate
- vadd_sf_sf, vsub_sf_sf, vadd_sf_hf, vsub_sf_hf: add/sub with sf output
- vadd_hf_hf, vsub_hf_hf: add/sub with hf output

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/cpu.h                         |   1 +
 target/hexagon/mmvec/hvx_ieee_fp.h           |  18 ++++
 target/hexagon/mmvec/macros.h                |   1 +
 target/hexagon/mmvec/mmvec.h                 |   2 +
 target/hexagon/attribs_def.h.inc             |   4 +
 target/hexagon/arch.c                        |   8 ++
 target/hexagon/cpu.c                         |   3 +
 target/hexagon/mmvec/hvx_ieee_fp.c           |  21 ++++
 target/hexagon/hex_common.py                 |   1 +
 target/hexagon/imported/mmvec/encode_ext.def |  18 ++++
 target/hexagon/imported/mmvec/ext.idef       | 101 +++++++++++++++++++
 target/hexagon/meson.build                   |   1 +
 12 files changed, 179 insertions(+)
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.h
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.c
target/hexagon/mmvec/hvx_ieee_fp.h new file +3 -1
new file mode 100644
index 0000000000..75008deb3b
--- /dev/null
 
+
+#define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
+
target/hexagon/mmvec/hvx_ieee_fp.c new file +13 -0
new file mode 100644
index 0000000000..3367226998
@@ -0,0 +1,21 @@
+/*
+ *  Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hvx_ieee_fp.h"
+
+float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status)
+{
+    return float32_mul(float16_to_float32(a1, true, fp_status),
+                       float16_to_float32(a2, true, fp_status),
Quoted 2 lines

fp_status);

Use f16_to_f32.

Otherwise

#12 lore raw

Re: [PATCH v3 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns

Quoted 56 lines · Taylor Simpson
Quoted 52 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point arithmetic instructions:
- vmpy_sf_sf, vmpy_sf_hf, vmpy_hf_hf: multiply operations
- vdmpy_sf_hf: dot-product multiply
- vmpy_sf_hf_acc, vmpy_hf_hf_acc, vdmpy_sf_hf_acc: multiply-accumulate
- vadd_sf_sf, vsub_sf_sf, vadd_sf_hf, vsub_sf_hf: add/sub with sf output
- vadd_hf_hf, vsub_hf_hf: add/sub with hf output

---
 target/hexagon/cpu.h                         |   1 +
 target/hexagon/mmvec/hvx_ieee_fp.h           |  18 ++++
 target/hexagon/mmvec/macros.h                |   1 +
 target/hexagon/mmvec/mmvec.h                 |   2 +
 target/hexagon/attribs_def.h.inc             |   4 +
 target/hexagon/arch.c                        |   8 ++
 target/hexagon/cpu.c                         |   3 +
 target/hexagon/mmvec/hvx_ieee_fp.c           |  21 ++++
 target/hexagon/hex_common.py                 |   1 +
 target/hexagon/imported/mmvec/encode_ext.def |  18 ++++
 target/hexagon/imported/mmvec/ext.idef       | 101 +++++++++++++++++++
 target/hexagon/meson.build                   |   1 +
 12 files changed, 179 insertions(+)
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.h
 create mode 100644 target/hexagon/mmvec/hvx_ieee_fp.c
target/hexagon/mmvec/hvx_ieee_fp.h new file +3 -1
new file mode 100644
index 0000000000..75008deb3b
--- /dev/null
 
+
+#define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
+
target/hexagon/mmvec/hvx_ieee_fp.c new file +8 -0
new file mode 100644
index 0000000000..3367226998
@@ -0,0 +1,21 @@
+/*
+ *  Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hvx_ieee_fp.h"
Quoted 8 lines

target/hexagon/mmvec/hvx_ieee_fp.c line 13

Quoted 5 lines
target/hexagon/mmvec/hvx_ieee_fp.c new file +5 -0
+
+float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status)
+{
+    return float32_mul(float16_to_float32(a1, true, fp_status),
+                       float16_to_float32(a2, true, fp_status), fp_status);

Use f16_to_f32.

We cannot use it here, as this macro assumes "env" is available to use &env->hvx_fp_status. We don't have env here, and we do have an fp_status to be used.

#13 lore raw

PATCH v3 7/16 target/hexagon: add v68 HVX IEEE float min/max insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE floating-point min/max instructions:
- vfmin_hf, vfmin_sf: IEEE floating-point minimum
- vfmax_hf, vfmax_sf: IEEE floating-point maximum
- vmax_hf, vmax_sf: qfloat IEEE maximum
- vmin_hf, vmin_sf: qfloat IEEE minimum

The Hexagon qfloat variants are similar to the IEEE-754 ones, but they handle NaN slightly differently. See comment on hvx_ieee_fp.h

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  6 +++
 target/hexagon/attribs_def.h.inc             |  2 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 49 ++++++++++++++++++++
 target/hexagon/hex_common.py                 |  1 +
 target/hexagon/imported/mmvec/encode_ext.def | 10 ++++
 target/hexagon/imported/mmvec/ext.idef       | 36 +++++++++++++-
 6 files changed, 103 insertions(+), 1 deletion(-)
target/hexagon/mmvec/hvx_ieee_fp.h +6 -0
index 75008deb3b..ed8e4f2da9 100644
@@ -15,4 +15,10 @@ float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
 float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
                  float_status *fp_status);
 
+/* Qfloat min/max treat +NaN as greater than +INF and -NaN as smaller than -INF */
+uint32_t qf_max_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+
 #endif
target/hexagon/attribs_def.h.inc +2 -0
index d3c4bf6301..2d0fc7e9c0 100644
@@ -81,6 +81,7 @@ DEF_ATTRIB(CVI_SCATTER, "CVI Scatter operation", "", "")
 DEF_ATTRIB(CVI_SCATTER_RELEASE, "CVI Store Release for scatter", "", "")
 DEF_ATTRIB(CVI_TMP_DST, "CVI instruction that doesn't write a register", "", "")
 DEF_ATTRIB(CVI_SLOT23, "Can execute in slot 2 or slot 3 (HVX)", "", "")
+DEF_ATTRIB(CVI_VA_2SRC, "Execs on multimedia vector engine; requires two srcs", "", "")
 
 DEF_ATTRIB(VTCM_ALLBANK_ACCESS, "Allocates in all VTCM schedulers.", "", "")
 
@@ -179,6 +180,7 @@ DEF_ATTRIB(HVX_IEEE_FP_ACC, "HVX IEEE FP accumulate instruction", "", "")
 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", "", "")
+DEF_ATTRIB(HVX_FLT, "This a floating point HVX instruction.", "", "")
 
 /* Keep this as the last attribute: */
 DEF_ATTRIB(ZZ_LASTATTRIB, "Last attribute in the file", "", "")
target/hexagon/mmvec/hvx_ieee_fp.c +49 -0

52 lines not on this page · raw message

target/hexagon/hex_common.py +1 -0
index 9e8bcfdcf0..c81dd5b836 100755
@@ -216,6 +216,7 @@ def need_env(tag):
             "A_CVI_GATHER" in attribdict[tag] or
             "A_CVI_SCATTER" in attribdict[tag] or
             "A_HVX_IEEE_FP" in attribdict[tag] or
+            "A_HVX_FLT" in attribdict[tag] or
             "A_IMPLICIT_WRITES_USR" in attribdict[tag])
 
 
target/hexagon/imported/mmvec/encode_ext.def +10 -0
index 4ce87d09fd..d7f50db778 100644
@@ -823,4 +823,14 @@ DEF_ENC(V6_vsub_sf_hf,"00011111100vvvvvPP1uuuuu101ddddd")
 DEF_ENC(V6_vadd_hf_hf,"00011111101vvvvvPP1uuuuu111ddddd")
 DEF_ENC(V6_vsub_hf_hf,"00011111011vvvvvPP1uuuuu000ddddd")
 
+/* IEEE FP min/max instructions */
+DEF_ENC(V6_vfmin_hf,"00011100011vvvvvPP1uuuuu000ddddd")
+DEF_ENC(V6_vfmin_sf,"00011100011vvvvvPP1uuuuu001ddddd")
+DEF_ENC(V6_vfmax_hf,"00011100011vvvvvPP1uuuuu010ddddd")
+DEF_ENC(V6_vfmax_sf,"00011100011vvvvvPP1uuuuu011ddddd")
+DEF_ENC(V6_vmax_sf,"00011111110vvvvvPP1uuuuu001ddddd")
+DEF_ENC(V6_vmin_sf,"00011111110vvvvvPP1uuuuu010ddddd")
+DEF_ENC(V6_vmax_hf,"00011111110vvvvvPP1uuuuu011ddddd")
+DEF_ENC(V6_vmin_hf,"00011111110vvvvvPP1uuuuu100ddddd")
+
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +35 -1
index 14df8e4790..0e9cace203 100644
@@ -43,7 +43,9 @@
 EXTINSN(V6_##TAG, SYNTAX, ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VA),  \
 DESCR, DO_FOR_EACH_CODE(WIDTH, CODE))
 
-
+#define ITERATOR_INSN_ANY_SLOT_2SRC(WIDTH,TAG,SYNTAX,DESCR,CODE) \
+EXTINSN(V6_##TAG, SYNTAX, ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VA,A_CVI_VA_2SRC,A_HVX_FLT),  \
+DESCR, DO_FOR_EACH_CODE(WIDTH, CODE))
 
 #define ITERATOR_INSN2_ANY_SLOT(WIDTH,TAG,SYNTAX,SYNTAX2,DESCR,CODE) \
 ITERATOR_INSN_ANY_SLOT(WIDTH,TAG,SYNTAX2,DESCR,CODE)
@@ -3000,6 +3002,38 @@ ITERATOR_INSN_IEEE_FP_DOUBLE_32(32, vsub_sf_hf,
     VddV.v[1].sf[i] = float32_sub(f16_to_f32(VuV.hf[2*i+1]),
                                   f16_to_f32(VvV.hf[2*i+1]), &env->hvx_fp_status))
 
+#define ITERATOR_INSN_IEEE_FP_16_32_LATE(WIDTH,TAG,SYNTAX,DESCR,CODE) \
+EXTINSN(V6_##TAG, SYNTAX, \
+        ATTRIBS(A_EXTENSION,A_HVX_IEEE_FP,A_CVI,A_CVI_VX,A_HVX_IEEE_FP_OUT_16,A_HVX_IEEE_FP_OUT_32), \
+        DESCR, DO_FOR_EACH_CODE(WIDTH, CODE))
+
+/* IEEE FP min/max instructions */
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfmin_hf, "Vd32.hf=vfmin(Vu32.hf,Vv32.hf)", \
+    "Vector IEEE min: hf",  VdV.hf[i] = float16_min(VuV.hf[i], VvV.hf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfmin_sf, "Vd32.sf=vfmin(Vu32.sf,Vv32.sf)", \
+    "Vector IEEE min: sf",  VdV.sf[i] = float32_min(VuV.sf[i], VvV.sf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfmax_hf,  "Vd32.hf=vfmax(Vu32.hf,Vv32.hf)", \
+    "Vector IEEE max: hf", VdV.hf[i] = float16_max(VuV.hf[i], VvV.hf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfmax_sf,  "Vd32.sf=vfmax(Vu32.sf,Vv32.sf)", \
+    "Vector IEEE max: sf", VdV.sf[i] = float32_max(VuV.sf[i], VvV.sf[i], \
+	&env->hvx_fp_status))
+
+ITERATOR_INSN_ANY_SLOT_2SRC(32,vmax_sf,"Vd32.sf=vmax(Vu32.sf,Vv32.sf)", \
+    "Vector max of sf input", VdV.sf[i] = qf_max_sf(VuV.sf[i], VvV.sf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_ANY_SLOT_2SRC(32,vmin_sf,"Vd32.sf=vmin(Vu32.sf,Vv32.sf)", \
+    "Vector min of sf input", VdV.sf[i] = qf_min_sf(VuV.sf[i], VvV.sf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_ANY_SLOT_2SRC(16,vmax_hf,"Vd32.hf=vmax(Vu32.hf,Vv32.hf)", \
+    "Vector max of hf input", VdV.hf[i] = qf_max_hf(VuV.hf[i], VvV.hf[i], \
+	&env->hvx_fp_status))
+ITERATOR_INSN_ANY_SLOT_2SRC(16,vmin_hf,"Vd32.hf=vmin(Vu32.hf,Vv32.hf)", \
+    "Vector min of hf input", VdV.hf[i] = qf_min_hf(VuV.hf[i], VvV.hf[i], \
+	&env->hvx_fp_status))
+
 /******************************************************************************
  DEBUG Vector/Register Printing
  ******************************************************************************/
Signature · 1 line
2.37.2
Reviewed-by on v3 7/16
#14 lore raw

Re: [PATCH v3 07/16] target/hexagon: add v68 HVX IEEE float min/max insns

Quoted 33 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point min/max instructions:
- vfmin_hf, vfmin_sf: IEEE floating-point minimum
- vfmax_hf, vfmax_sf: IEEE floating-point maximum
- vmax_hf, vmax_sf: qfloat IEEE maximum
- vmin_hf, vmin_sf: qfloat IEEE minimum

The Hexagon qfloat variants are similar to the IEEE-754 ones, but they handle NaN slightly differently. See comment on hvx_ieee_fp.h

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  6 +++
 target/hexagon/attribs_def.h.inc             |  2 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 49 ++++++++++++++++++++
 target/hexagon/hex_common.py                 |  1 +
 target/hexagon/imported/mmvec/encode_ext.def | 10 ++++
 target/hexagon/imported/mmvec/ext.idef       | 36 +++++++++++++-
 6 files changed, 103 insertions(+), 1 deletion(-)
target/hexagon/mmvec/hvx_ieee_fp.h +1 -0
index 75008deb3b..ed8e4f2da9 100644
@@ -15,4 +15,10 @@ float32 fp_mult_sf_hf(float16 a1, float16 a2,
 float_status *fp_status);
 float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
                  float_status *fp_status);
 
+/* Qfloat min/max treat +NaN as greater than +INF and -NaN as smaller

than -INF */

target/hexagon/mmvec/hvx_ieee_fp.h float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status); · line 22

Quoted 4 lines
target/hexagon/mmvec/hvx_ieee_fp.h +4 -0
+uint32_t qf_max_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);

Use float32/float16 instead of uint32_t/uint16_t. That's what the implementations below have.

Quoted 19 lines
target/hexagon/mmvec/hvx_ieee_fp.h +1 -0
+
 #endif
target/hexagon/mmvec/hvx_ieee_fp.c +2 -0
index 3367226998..868c0c5b18 100644
@@ -19,3 +19,52 @@ float32 fp_vdmpy(float16 a1, float16 a2, float16 a3,
 float16 a4,
     return float32_add(fp_mult_sf_hf(a1, a3, fp_status),
                        fp_mult_sf_hf(a2, a4, fp_status), fp_status);
 }
+
+#define float32_is_pos_nan(X) (float32_is_any_nan(X) &&

!float32_is_neg(X))

target/hexagon/mmvec/hvx_ieee_fp.c +2 -0
+#define float32_is_neg_nan(X) (float32_is_any_nan(X) && float32_is_neg(X))
+#define float16_is_pos_nan(X) (float16_is_any_nan(X) &&

!float16_is_neg(X))

target/hexagon/mmvec/hvx_ieee_fp.c

Quoted 2 lines
target/hexagon/mmvec/hvx_ieee_fp.c +2 -0
+#define float16_is_neg_nan(X) (float16_is_any_nan(X) && float16_is_neg(X))
+

I would go ahead and repeat the comment here
/* Qfloat min/max treat +NaN as greater than +INF and -NaN as smaller than -INF */

target/hexagon/mmvec/hvx_ieee_fp.c float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4, · line 37

Quoted 11 lines
target/hexagon/mmvec/hvx_ieee_fp.c +10 -0
+float32 qf_max_sf(float32 a1, float32 a2, float_status *fp_status)
+{
+    if (float32_is_pos_nan(a1) || float32_is_neg_nan(a2)) {
+        return a1;
+    }
+    if (float32_is_pos_nan(a2) || float32_is_neg_nan(a1)) {
+        return a2;
+    }
+    return float32_max(a1, a2, fp_status);
+}

Otherwise

#15 lore raw

PATCH v3 8/16 target/hexagon: add v68 HVX IEEE float misc insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE floating-point miscellaneous instructions:
- vassign_fp (vfmv): vector move
- vfneg_hf, vfneg_sf: vector floating-point negate
- vabs_hf, vabs_sf: vector absolute value

---
 target/hexagon/imported/mmvec/encode_ext.def |  7 +++++++
 target/hexagon/imported/mmvec/ext.idef       | 12 ++++++++++++
 2 files changed, 19 insertions(+)
target/hexagon/imported/mmvec/encode_ext.def +7 -0
index d7f50db778..72daf8724c 100644
@@ -833,4 +833,11 @@ DEF_ENC(V6_vmin_sf,"00011111110vvvvvPP1uuuuu010ddddd")
 DEF_ENC(V6_vmax_hf,"00011111110vvvvvPP1uuuuu011ddddd")
 DEF_ENC(V6_vmin_hf,"00011111110vvvvvPP1uuuuu100ddddd")
 
+/* IEEE FP move, negate, abs instructions */
+DEF_ENC(V6_vassign_fp,"00011110--0-0110PP1uuuuu001ddddd")
+DEF_ENC(V6_vfneg_hf,"00011110--0-0110PP1uuuuu010ddddd")
+DEF_ENC(V6_vfneg_sf,"00011110--0-0110PP1uuuuu011ddddd")
+DEF_ENC(V6_vabs_hf,"00011110--0-0110PP1uuuuu100ddddd")
+DEF_ENC(V6_vabs_sf,"00011110--0-0110PP1uuuuu101ddddd")
+
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +12 -0
index 0e9cace203..5312661684 100644
@@ -3034,6 +3034,18 @@ ITERATOR_INSN_ANY_SLOT_2SRC(16,vmin_hf,"Vd32.hf=vmin(Vu32.hf,Vv32.hf)", \
     "Vector min of hf input", VdV.hf[i] = qf_min_hf(VuV.hf[i], VvV.hf[i], \
 	&env->hvx_fp_status))
 
+/* IEEE FP move, negate, abs instructions */
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vassign_fp, "Vd32.w=vfmv(Vu32.w)", \
+    "Vector IEEE move", VdV.w[i]  = VuV.w[i])
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfneg_hf, "Vd32.hf=vfneg(Vu32.hf)", \
+    "Vector IEEE neg: hf", VdV.hf[i] = float16_chs(VuV.hf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfneg_sf, "Vd32.sf=vfneg(Vu32.sf)", \
+    "Vector IEEE neg: sf", VdV.sf[i] = float32_chs(VuV.sf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vabs_hf,  "Vd32.hf=vabs(Vu32.hf)", \
+    "Vector IEEE abs: hf", VdV.hf[i] = float16_abs(VuV.hf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vabs_sf,  "Vd32.sf=vabs(Vu32.sf)", \
+    "Vector IEEE abs: sf", VdV.hf[i] = float32_abs(VuV.hf[i]))
+
 /******************************************************************************
  DEBUG Vector/Register Printing
  ******************************************************************************/
Signature · 1 line
2.37.2
Reviewed-by on v3 8/16
#16 lore raw

Re: [PATCH v3 08/16] target/hexagon: add v68 HVX IEEE float misc insns

Quoted 24 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point miscellaneous instructions:
- vassign_fp (vfmv): vector move
- vfneg_hf, vfneg_sf: vector floating-point negate
- vabs_hf, vabs_sf: vector absolute value

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/imported/mmvec/encode_ext.def |  7 +++++++
 target/hexagon/imported/mmvec/ext.idef       | 12 ++++++++++++
 2 files changed, 19 insertions(+)
target/hexagon/imported/mmvec/ext.idef +1 -0
index 0e9cace203..5312661684 100644
@@ -3034,6 +3034,18 @@
 ITERATOR_INSN_ANY_SLOT_2SRC(16,vmin_hf,"Vd32.hf=vmin(Vu32.hf,Vv32.hf)", \
     "Vector min of hf input", VdV.hf[i] = qf_min_hf(VuV.hf[i], VvV.hf[i],
 \
        &env->hvx_fp_status))
 
+/* IEEE FP move, negate, abs instructions */

target/hexagon/imported/mmvec/ext.idef line 3049

Quoted 10 lines
target/hexagon/imported/mmvec/ext.idef +10 -0
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vassign_fp, "Vd32.w=vfmv(Vu32.w)", \
+    "Vector IEEE move", VdV.w[i]  = VuV.w[i])
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vfneg_hf, "Vd32.hf=vfneg(Vu32.hf)", \
+    "Vector IEEE neg: hf", VdV.hf[i] = float16_chs(VuV.hf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vfneg_sf, "Vd32.sf=vfneg(Vu32.sf)", \
+    "Vector IEEE neg: sf", VdV.sf[i] = float32_chs(VuV.sf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(16, vabs_hf,  "Vd32.hf=vabs(Vu32.hf)", \
+    "Vector IEEE abs: hf", VdV.hf[i] = float16_abs(VuV.hf[i]))
+ITERATOR_INSN_IEEE_FP_16_32_LATE(32, vabs_sf,  "Vd32.sf=vabs(Vu32.sf)", \
+    "Vector IEEE abs: sf", VdV.hf[i] = float32_abs(VuV.hf[i]))

Should be VdV.sf[i] = float32_abs(vuV.sf[i]) I'm surprised there isn't a test case that catches this.

Otherwise

#17 lore raw

PATCH v3 9/16 target/hexagon: add v68 HVX IEEE float conversion insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE floating-point conversion instructions:
- vconv_hf_h, vconv_h_hf, vconv_sf_w, vconv_w_sf: vconv operations
- vcvt_hf_sf, vcvt_sf_hf: float <-> half float conversions
- vcvt_hf_b, vcvt_hf_h, vcvt_hf_ub, vcvt_hf_uh: int to half float
- vcvt_b_hf, vcvt_h_hf, vcvt_ub_hf, vcvt_uh_hf: half float to int

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  4 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 18 ++++
 target/hexagon/imported/mmvec/encode_ext.def | 18 ++++
 target/hexagon/imported/mmvec/ext.idef       | 97 ++++++++++++++++++++
 4 files changed, 137 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +4 -0
index ed8e4f2da9..d55837b756 100644
@@ -10,6 +10,7 @@
 #include "fpu/softfloat.h"
 
 #define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
+#define f32_to_f16(A) float32_to_float16((A), true, &env->hvx_fp_status)
 
 float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
 float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
@@ -21,4 +22,7 @@ uint32_t qf_min_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
 uint16_t qf_max_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
 uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
 
+int32_t conv_w_sf(float32 a, float_status *fp_status);
+int16_t conv_h_hf(float16 a, float_status *fp_status);
+
 #endif
target/hexagon/mmvec/hvx_ieee_fp.c +18 -0
index 868c0c5b18..0d9ff8bd5f 100644
@@ -68,3 +68,21 @@ float16 qf_min_hf(float16 a1, float16 a2, float_status *fp_status)
     }
     return float16_min(a1, a2, fp_status);
 }
+
+int32_t conv_w_sf(float32 a, float_status *fp_status)
+{
+    /* float32_to_int32 converts any NaN to MAX, hexagon looks at the sign. */
+    if (float32_is_any_nan(a)) {
+        return float32_is_neg(a) ? INT32_MIN : INT32_MAX;
+    }
+    return float32_to_int32_round_to_zero(a, fp_status);
+}
+
+int16_t conv_h_hf(float16 a, float_status *fp_status)
+{
+    /* float16_to_int16 converts any NaN to MAX, hexagon looks at the sign. */
+    if (float16_is_any_nan(a)) {
+        return float16_is_neg(a) ? INT16_MIN : INT16_MAX;
+    }
+    return float16_to_int16_round_to_zero(a, fp_status);
+}
target/hexagon/imported/mmvec/encode_ext.def +18 -0
index 72daf8724c..c1ed1b6c23 100644
@@ -840,4 +840,22 @@ DEF_ENC(V6_vfneg_sf,"00011110--0-0110PP1uuuuu011ddddd")
 DEF_ENC(V6_vabs_hf,"00011110--0-0110PP1uuuuu100ddddd")
 DEF_ENC(V6_vabs_sf,"00011110--0-0110PP1uuuuu101ddddd")
 
+/* IEEE FP vcvt instructions */
+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_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")
+
+/* IEEE FP vconv instructions */
+DEF_ENC(V6_vconv_sf_w,"00011110--0--101PP1uuuuu011ddddd")
+DEF_ENC(V6_vconv_w_sf,"00011110--0--101PP1uuuuu001ddddd")
+DEF_ENC(V6_vconv_hf_h,"00011110--0--101PP1uuuuu100ddddd")
+DEF_ENC(V6_vconv_h_hf,"00011110--0--101PP1uuuuu010ddddd")
+
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +97 -0

109 lines not on this page · raw message

Signature · 1 line
2.37.2
Reviewed-by on v3 9/16
#18 lore raw

Re: [PATCH v3 09/16] target/hexagon: add v68 HVX IEEE float conversion insns

Quoted 6 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point conversion instructions:
- vconv_hf_h, vconv_h_hf, vconv_sf_w, vconv_w_sf: vconv operations
- vcvt_hf_sf, vcvt_sf_hf: float <-> half float conversions
- vcvt_hf_b, vcvt_hf_h, vcvt_hf_ub, vcvt_hf_uh: int to half float
- vcvt_b_hf, vcvt_h_hf, vcvt_ub_hf, vcvt_uh_hf: half float to int

Quoted 9 lines

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  4 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 18 ++++
 target/hexagon/imported/mmvec/encode_ext.def | 18 ++++
 target/hexagon/imported/mmvec/ext.idef       | 97 ++++++++++++++++++++
 4 files changed, 137 insertions(+)
#19 lore raw

PATCH v3 10/16 target/hexagon: add v68 HVX IEEE float compare insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE floating-point compare instructions:
- V6_vgthf, V6_vgtsf: greater-than compare
- V6_vgthf_and, V6_vgtsf_and: greater-than with predicate-and
- V6_vgthf_or, V6_vgtsf_or: greater-than with predicate-or
- V6_vgthf_xor, V6_vgtsf_xor: greater-than with predicate-xor

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  4 ++
 target/hexagon/mmvec/macros.h                |  3 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 48 +++++++++++++++
 target/hexagon/imported/mmvec/encode_ext.def | 10 ++++
 target/hexagon/imported/mmvec/ext.idef       | 61 ++++++++++++++++++++
 5 files changed, 126 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +4 -0
index d55837b756..ad854b905d 100644
@@ -25,4 +25,8 @@ uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
 int32_t conv_w_sf(float32 a, float_status *fp_status);
 int16_t conv_h_hf(float16 a, float_status *fp_status);
 
+/* IEEE - FP compare instructions */
+uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
+
 #endif
target/hexagon/mmvec/macros.h +3 -0
index ac709d8993..318d44efb7 100644
@@ -356,4 +356,7 @@
                extract32(VAL, POS * 8, 8); \
     } while (0);
 
+#define fCMPGT_SF(A, B) cmpgt_sf(A, B, &env->hvx_fp_status)
+#define fCMPGT_HF(A, B) cmpgt_hf(A, B, &env->hvx_fp_status)
+
 #endif
target/hexagon/mmvec/hvx_ieee_fp.c +48 -0

51 lines not on this page · raw message

target/hexagon/imported/mmvec/encode_ext.def +10 -0
index c1ed1b6c23..3572e4de4c 100644
@@ -858,4 +858,14 @@ DEF_ENC(V6_vconv_w_sf,"00011110--0--101PP1uuuuu001ddddd")
 DEF_ENC(V6_vconv_hf_h,"00011110--0--101PP1uuuuu100ddddd")
 DEF_ENC(V6_vconv_h_hf,"00011110--0--101PP1uuuuu010ddddd")
 
+/* IEEE FP compare instructions */
+DEF_ENC(V6_vgtsf,"00011100100vvvvvPP1uuuuu011100dd")
+DEF_ENC(V6_vgthf,"00011100100vvvvvPP1uuuuu011101dd")
+DEF_ENC(V6_vgtsf_and,"00011100100vvvvvPP1uuuuu110010xx")
+DEF_ENC(V6_vgthf_and,"00011100100vvvvvPP1uuuuu110011xx")
+DEF_ENC(V6_vgtsf_or,"00011100100vvvvvPP1uuuuu001100xx")
+DEF_ENC(V6_vgthf_or,"00011100100vvvvvPP1uuuuu001101xx")
+DEF_ENC(V6_vgtsf_xor,"00011100100vvvvvPP1uuuuu111010xx")
+DEF_ENC(V6_vgthf_xor,"00011100100vvvvvPP1uuuuu111011xx")
+
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +61 -0

67 lines not on this page · raw message

Signature · 1 line
2.37.2
Reviewed-by on v3 10/16
#20 lore raw

Re: [PATCH v3 10/16] target/hexagon: add v68 HVX IEEE float compare insns

Quoted 23 lines · Matheus Tavares Bernardino

Add HVX IEEE floating-point compare instructions:
- V6_vgthf, V6_vgtsf: greater-than compare
- V6_vgthf_and, V6_vgtsf_and: greater-than with predicate-and
- V6_vgthf_or, V6_vgtsf_or: greater-than with predicate-or
- V6_vgthf_xor, V6_vgtsf_xor: greater-than with predicate-xor

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/mmvec/hvx_ieee_fp.h           |  4 ++
 target/hexagon/mmvec/macros.h                |  3 +
 target/hexagon/mmvec/hvx_ieee_fp.c           | 48 +++++++++++++++
 target/hexagon/imported/mmvec/encode_ext.def | 10 ++++
 target/hexagon/imported/mmvec/ext.idef       | 61 ++++++++++++++++++++
 5 files changed, 126 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +0 -0
index d55837b756..ad854b905d 100644

target/hexagon/mmvec/hvx_ieee_fp.h uint16_t qf_min_hf(uint16_t a1, uint16_t a2, · line 31

Quoted 7 lines
target/hexagon/mmvec/hvx_ieee_fp.h +3 -0
@@ -25,4 +25,8 @@ uint16_t qf_min_hf(uint16_t a1, uint16_t a2,
 float_status *fp_status);
 int32_t conv_w_sf(float32 a, float_status *fp_status);
 int16_t conv_h_hf(float16 a, float_status *fp_status);
 
+/* IEEE - FP compare instructions */
+uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
+uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status);

Use float32/float16 instead of uint32_t/uint16_t for the args. That's what the implementations below use.
The return type should be bool.

Otherwise

#21 lore raw

PATCH v3 11/16 target/hexagon: add v73 HVX IEEE bfloat16 insns

In reply to Matheus Tavares Bernardino

Add HVX IEEE bfloat16 (bf16) instructions:

Arithmetic operations:
- V6_vadd_sf_bf, V6_vsub_sf_bf: add/sub bf16 widening to sf output
- V6_vmpy_sf_bf: multiply bf16 widening to sf output
- V6_vmpy_sf_bf_acc: multiply-accumulate bf16 widening to sf output

Min/Max operations:
- V6_vmin_bf, V6_vmax_bf: bf16 min/max

Comparison operations:
- V6_vgtbf: greater-than compare
- V6_vgtbf_and, V6_vgtbf_or, V6_vgtbf_xor: predicate variants

Conversion operations:
- V6_vcvt_bf_sf: convert sf to bf16

---
 target/hexagon/mmvec/hvx_ieee_fp.h           | 37 ++++++++++++
 target/hexagon/mmvec/macros.h                |  4 ++
 target/hexagon/mmvec/mmvec.h                 |  1 +
 target/hexagon/imported/mmvec/encode_ext.def | 15 +++++
 target/hexagon/imported/mmvec/ext.idef       | 62 ++++++++++++++++++++
 5 files changed, 119 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +37 -0
index ad854b905d..21883c0fad 100644
@@ -9,8 +9,11 @@
 
 #include "fpu/softfloat.h"
 
+#define FP32_DEF_NAN 0x7FFFFFFF
+
 #define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
 #define f32_to_f16(A) float32_to_float16((A), true, &env->hvx_fp_status)
+#define bf_to_sf(A) bfloat16_to_float32(A, &env->hvx_fp_status)
 
 float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
 float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
@@ -29,4 +32,38 @@ int16_t conv_h_hf(float16 a, float_status *fp_status);
 uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
 uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
 
+/* IEEE BFloat instructions */
+
+#define fp_mult_sf_bf(A, B) \
+    float32_mul(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_add_sf_bf(A, B) \
+    float32_add(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_sub_sf_bf(A, B) \
+    float32_sub(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_mult_sf_bf_acc(f1, f2, f3) \
+    float32_muladd(bf_to_sf(f1), bf_to_sf(f2), f3, 0, &env->hvx_fp_status)
+
+static inline uint16_t sf_to_bf(int32_t A, float_status *fp_status)
+{
+    uint32_t rslt = A;
+    if ((rslt & 0x1FFFF) == 0x08000) {
+        /* do not round up if exactly .5 and even already */
+    } else if ((rslt & 0x8000) == 0x8000) {
+        rslt += 0x8000; /* rounding to nearest number */
+    }
+    rslt = float32_is_any_nan(A) ? FP32_DEF_NAN : rslt;
+    return float32_to_bfloat16(rslt, fp_status);
+}
+
+#define fp_min_bf(A, B) \
+    sf_to_bf(float32_min(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status), \
+             &env->hvx_fp_status);
+
+#define fp_max_bf(A, B) \
+    sf_to_bf(float32_max(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status), \
+             &env->hvx_fp_status);
+
 #endif
target/hexagon/mmvec/macros.h +4 -0
index 318d44efb7..4945a61194 100644
@@ -25,6 +25,9 @@
 #include "accel/tcg/probe.h"
 #include "mmvec/hvx_ieee_fp.h"
 
+#define fBFLOAT()
+#define fCVI_VX_NO_TMP_LD()
+
 #ifndef QEMU_GENERATE
 #define VdV      (*(MMVector *restrict)(VdV_void))
 #define VsV      (*(MMVector *restrict)(VsV_void))
@@ -358,5 +361,6 @@
 
 #define fCMPGT_SF(A, B) cmpgt_sf(A, B, &env->hvx_fp_status)
 #define fCMPGT_HF(A, B) cmpgt_hf(A, B, &env->hvx_fp_status)
+#define fCMPGT_BF(A, B) fCMPGT_SF((uint32_t)(A) << 16, (uint32_t)(B) << 16)
 
 #endif
target/hexagon/mmvec/mmvec.h +1 -0
index 31909303b5..ab991471b1 100644
@@ -40,6 +40,7 @@ typedef union {
     int8_t    b[MAX_VEC_SIZE_BYTES / 1];
     float32  sf[MAX_VEC_SIZE_BYTES / 4];
     float16  hf[MAX_VEC_SIZE_BYTES / 2];
+    bfloat16 bf[MAX_VEC_SIZE_BYTES / 2];
 } MMVector;
 
 typedef union {
target/hexagon/imported/mmvec/encode_ext.def +15 -0
index 3572e4de4c..16f043b77d 100644
@@ -868,4 +868,19 @@ DEF_ENC(V6_vgthf_or,"00011100100vvvvvPP1uuuuu001101xx")
 DEF_ENC(V6_vgtsf_xor,"00011100100vvvvvPP1uuuuu111010xx")
 DEF_ENC(V6_vgthf_xor,"00011100100vvvvvPP1uuuuu111011xx")
 
+/* BFLOAT instructions */
+DEF_ENC(V6_vmpy_sf_bf,"00011101010vvvvvPP1uuuuu100ddddd")
+DEF_ENC(V6_vmpy_sf_bf_acc,"00011101000vvvvvPP1uuuuu000xxxxx")
+DEF_ENC(V6_vadd_sf_bf,"00011101010vvvvvPP1uuuuu110ddddd")
+DEF_ENC(V6_vsub_sf_bf,"00011101010vvvvvPP1uuuuu101ddddd")
+DEF_ENC(V6_vmax_bf,"00011101010vvvvvPP1uuuuu111ddddd")
+DEF_ENC(V6_vmin_bf,"00011101010vvvvvPP1uuuuu000ddddd")
+DEF_ENC(V6_vcvt_bf_sf,"00011101010vvvvvPP1uuuuu011ddddd")
+
+/* BFLOAT compare instructions */
+DEF_ENC(V6_vgtbf,"00011100100vvvvvPP1uuuuu011110dd")
+DEF_ENC(V6_vgtbf_and,"00011100100vvvvvPP1uuuuu110100xx")
+DEF_ENC(V6_vgtbf_or,"00011100100vvvvvPP1uuuuu001110xx")
+DEF_ENC(V6_vgtbf_xor,"00011100100vvvvvPP1uuuuu111100xx")
+
 #endif /* NO MMVEC */
target/hexagon/imported/mmvec/ext.idef +62 -0

76 lines not on this page · raw message

Signature · 1 line
2.37.2
Reviewed-by on v3 11/16
#22 lore raw

Re: [PATCH v3 11/16] target/hexagon: add v73 HVX IEEE bfloat16 insns

Quoted 33 lines · Matheus Tavares Bernardino

Add HVX IEEE bfloat16 (bf16) instructions:

Arithmetic operations:
- V6_vadd_sf_bf, V6_vsub_sf_bf: add/sub bf16 widening to sf output
- V6_vmpy_sf_bf: multiply bf16 widening to sf output
- V6_vmpy_sf_bf_acc: multiply-accumulate bf16 widening to sf output

Min/Max operations:
- V6_vmin_bf, V6_vmax_bf: bf16 min/max

Comparison operations:
- V6_vgtbf: greater-than compare
- V6_vgtbf_and, V6_vgtbf_or, V6_vgtbf_xor: predicate variants

Conversion operations:
- V6_vcvt_bf_sf: convert sf to bf16

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 target/hexagon/mmvec/hvx_ieee_fp.h           | 37 ++++++++++++
 target/hexagon/mmvec/macros.h                |  4 ++
 target/hexagon/mmvec/mmvec.h                 |  1 +
 target/hexagon/imported/mmvec/encode_ext.def | 15 +++++
 target/hexagon/imported/mmvec/ext.idef       | 62 ++++++++++++++++++++
 5 files changed, 119 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +0 -0
index ad854b905d..21883c0fad 100644

target/hexagon/mmvec/hvx_ieee_fp.h line 17

Quoted 9 lines
target/hexagon/mmvec/hvx_ieee_fp.h +3 -0
@@ -9,8 +9,11 @@
 
 #include "fpu/softfloat.h"
 
+#define FP32_DEF_NAN 0x7FFFFFFF
+
 #define f16_to_f32(A) float16_to_float32((A), true, &env->hvx_fp_status)
 #define f32_to_f16(A) float32_to_float16((A), true, &env->hvx_fp_status)
+#define bf_to_sf(A) bfloat16_to_float32(A, &env->hvx_fp_status)
 

Better to follow the naming convention of the previous macros

    bf16_to_f32
Quoted 13 lines
target/hexagon/mmvec/hvx_ieee_fp.h +6 -0
 float32 fp_mult_sf_hf(float16 a1, float16 a2, float_status *fp_status);
 float32 fp_vdmpy(float16 a1, float16 a2, float16 a3, float16 a4,
@@ -29,4 +32,38 @@ int16_t conv_h_hf(float16 a, float_status *fp_status);
 uint32_t cmpgt_sf(uint32_t a1, uint32_t a2, float_status *fp_status);
 uint16_t cmpgt_hf(uint16_t a1, uint16_t a2, float_status *fp_status);
 
+/* IEEE BFloat instructions */
+
+#define fp_mult_sf_bf(A, B) \
+    float32_mul(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_add_sf_bf(A, B) \

target/hexagon/mmvec/hvx_ieee_fp.h int16_t conv_h_hf(float16 a, float_status *fp_status); · line 50

Quoted 10 lines
target/hexagon/mmvec/hvx_ieee_fp.h +9 -0
+    float32_add(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_sub_sf_bf(A, B) \
+    float32_sub(bf_to_sf(A), bf_to_sf(B), &env->hvx_fp_status)
+
+#define fp_mult_sf_bf_acc(f1, f2, f3) \
+    float32_muladd(bf_to_sf(f1), bf_to_sf(f2), f3, 0, &env->hvx_fp_status)
+
+static inline uint16_t sf_to_bf(int32_t A, float_status *fp_status)
 

Use bfloat16 instead of uint16_t and float32 instead of int32_t.

Otherwise

#23 lore raw

PATCH v3 12/16 tests/hexagon: add tests for v68 HVX IEEE float arithmetics

In reply to Matheus Tavares Bernardino
---
 tests/tcg/hexagon/hex_test.h        |   4 +
 tests/tcg/hexagon/hvx_misc.h        |  41 ++++++++
 tests/tcg/hexagon/fp_hvx.c          | 155 ++++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_disabled.c |  57 ++++++++++
 tests/tcg/hexagon/Makefile.target   |   8 ++
 5 files changed, 265 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx.c
 create mode 100644 tests/tcg/hexagon/fp_hvx_disabled.c
tests/tcg/hexagon/hex_test.h +4 -0
index cfed06a58b..e7a6644d41 100644
@@ -19,6 +19,8 @@
 #ifndef HEX_TEST_H
 #define HEX_TEST_H
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 static inline void __check32(int line, uint32_t val, uint32_t expect)
 {
     if (val != expect) {
@@ -110,6 +112,7 @@ static inline void __check64_ne(int line, uint64_t val, uint64_t expect)
 
 /* Some useful floating point values */
 const uint32_t SF_INF =              0x7f800000;
+const uint32_t SF_INF_neg =          0xff800000;
 const uint32_t SF_QNaN =             0x7fc00000;
 const uint32_t SF_QNaN_special =     0x7f800001;
 const uint32_t SF_SNaN =             0x7fb00000;
@@ -128,6 +131,7 @@ const uint32_t SF_large_pos =        0x5afa572e;
 const uint32_t SF_any =              0x3f800000;
 const uint32_t SF_denorm =           0x00000001;
 const uint32_t SF_random =           0x346001d6;
+const uint32_t SF_neg_two =          0xc0000000;
 
 const uint64_t DF_QNaN =             0x7ff8000000000000ULL;
 const uint64_t DF_SNaN =             0x7ff7000000000000ULL;
tests/tcg/hexagon/hvx_misc.h +41 -0

72 lines not on this page · raw message

tests/tcg/hexagon/fp_hvx.c new file +155 -0

155 lines not on this page · raw message

tests/tcg/hexagon/fp_hvx_disabled.c new file +57 -0

57 lines not on this page · raw message

tests/tcg/hexagon/Makefile.target +8 -0
index 549c95082f..789721bdac 100644
@@ -50,6 +50,8 @@ HEX_TESTS += vector_add_int
 HEX_TESTS += scatter_gather
 HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
+HEX_TESTS += fp_hvx
+HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding
 HEX_TESTS += multiple-writes
@@ -126,6 +128,12 @@ v68_hvx: CFLAGS += -mhvx -Wno-unused-function
 v69_hvx: v69_hvx.c hvx_misc.h
 v69_hvx: CFLAGS += -mhvx -Wno-unused-function
 v73_scalar: CFLAGS += -Wno-unused-function
+fp_hvx: fp_hvx.c hvx_misc.h
+fp_hvx: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
+fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
+
+run-fp_hvx_disabled: QEMU_OPTS += -cpu v73,ieee-fp=false
 
 hvx_histogram: hvx_histogram.c hvx_histogram_row.S
 	$(CC) $(CFLAGS) $(CROSS_CC_GUEST_CFLAGS) $^ -o $@ $(LDFLAGS)
Signature · 1 line
2.37.2
Reviewed-by on v3 12/16
#24 lore raw

Re: [PATCH v3 12/16] tests/hexagon: add tests for v68 HVX IEEE float arithmetics

Quoted 16 lines · Matheus Tavares Bernardino

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 tests/tcg/hexagon/hex_test.h        |   4 +
 tests/tcg/hexagon/hvx_misc.h        |  41 ++++++++
 tests/tcg/hexagon/fp_hvx.c          | 155 ++++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_disabled.c |  57 ++++++++++
 tests/tcg/hexagon/Makefile.target   |   8 ++
 5 files changed, 265 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx.c
 create mode 100644 tests/tcg/hexagon/fp_hvx_disabled.c
tests/tcg/hexagon/fp_hvx.c new file +0 -0
new file mode 100644
index 0000000000..0365833753

tests/tcg/hexagon/fp_hvx.c line 117

Quoted 5 lines
tests/tcg/hexagon/fp_hvx.c new file +3 -1
--- /dev/null
 
+static void test_new(void)
+{
+    asm volatile("r0 = #0x2\n"

Use SF_two

tests/tcg/hexagon/fp_hvx.c line 120

Quoted 4 lines
tests/tcg/hexagon/fp_hvx.c new file +3 -0
+                 "v0 = vsplat(r0)\n"
+                 "vmem(%1 + #0) = v0\n"
+                 "r1 = #0x1\n"

Use SF_one

Quoted 33 lines
tests/tcg/hexagon/fp_hvx.c new file +11 -0
+                 "v1 = vsplat(r1)\n"
+                 "v2 = vsplat(r1)\n"
+                 "{\n"
+                 "  v0.sf = vadd(v1.sf, v2.sf)\n"
+                 "  vmem(%0 + #0) = v0.new\n"
+                 "}\n"
+                 :
+                 : "r"(output), "r"(expect)
+                 : "r0", "r1", "v0", "v1", "v2", "memory");
+    check_output_w(__LINE__, 1);
+}
tests/tcg/hexagon/fp_hvx_disabled.c new file +11 -0
new file mode 100644
index 0000000000..388a42e2b7
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <hexagon_types.h>
+#include <hvx_hexagon_protos.h>
+

tests/tcg/hexagon/fp_hvx_disabled.c line 21

Quoted 10 lines
tests/tcg/hexagon/fp_hvx_disabled.c new file +10 -0
+int err;
+#include "hvx_misc.h"
+
+static void test_disabled(void)
+{
+    memset(output, 0xAA, sizeof(output));
+    memset(expect, 0, sizeof(expect));
+    asm volatile("r0 = #0xff\n"
+                 "v0 = vsplat(r0)\n"
+                 "r1 = #0x1\n"

Minor nit - consider known floating point values (e.g., SF_one) (but since the vadd is going to write zeros, it really doesn't matter).

Quoted 8 lines
tests/tcg/hexagon/fp_hvx_disabled.c new file +7 -0
+                 "v1 = vsplat(r1)\n"
+                 "v2 = vsplat(r1)\n"
+                 "v0.sf = vadd(v1.sf, v2.sf)\n"
+                 "vmem(%0 + #0) = v0\n"
+                 :
+                 : "r"(output)
+                 : "r0", "r1", "v0", "v1", "v2", "memory");

tests/tcg/hexagon/fp_hvx_disabled.c line 38

Quoted 10 lines
tests/tcg/hexagon/fp_hvx_disabled.c new file +10 -0
+    check_output_w(__LINE__, 1);
+}
+
+static void test_disabled_with_new(void)
+{
+    memset(output, 0xAA, sizeof(output));
+    memset(expect, 0, sizeof(expect));
+    asm volatile("r0 = #0xff\n"
+                 "v0 = vsplat(r0)\n"
+                 "r1 = #0x1\n"

Ditto

Quoted 34 lines
tests/tcg/hexagon/fp_hvx_disabled.c new file +19 -0
+                 "v1 = vsplat(r1)\n"
+                 "v2 = vsplat(r1)\n"
+                 "{\n"
+                 "    v0.sf = vadd(v1.sf, v2.sf)\n"
+                 "    vmem(%0 + #0) = v0.new\n"
+                 "}\n"
+                 :
+                 : "r"(output)
+                 : "r0", "r1", "v0", "v1", "v2", "memory");
+    check_output_w(__LINE__, 1);
+}
+
+int main(void)
+{
+    test_disabled();
+    test_disabled_with_new();
+    puts(err ? "FAIL" : "PASS");
+    return err ? 1 : 0;
+}
tests/tcg/hexagon/Makefile.target +2 -0
index 549c95082f..789721bdac 100644
@@ -50,6 +50,8 @@ HEX_TESTS += vector_add_int
 HEX_TESTS += scatter_gather
 HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
+HEX_TESTS += fp_hvx
+HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding
 HEX_TESTS += multiple-writes

tests/tcg/hexagon/Makefile.target v68_hvx: CFLAGS += -mhvx -Wno-unused-function · line 132

Quoted 5 lines
tests/tcg/hexagon/Makefile.target +1 -0
@@ -126,6 +128,12 @@ v68_hvx: CFLAGS += -mhvx -Wno-unused-function
 v69_hvx: v69_hvx.c hvx_misc.h
 v69_hvx: CFLAGS += -mhvx -Wno-unused-function
 v73_scalar: CFLAGS += -Wno-unused-function
+fp_hvx: fp_hvx.c hvx_misc.h
 

Also hex_test.h

tests/tcg/hexagon/Makefile.target v68_hvx: CFLAGS += -mhvx -Wno-unused-function · line 137

Quoted 3 lines
tests/tcg/hexagon/Makefile.target +2 -0
+fp_hvx: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
 

Also hex_test.h

Quoted 7 lines
tests/tcg/hexagon/Makefile.target +3 -0
+fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
+
+run-fp_hvx_disabled: QEMU_OPTS += -cpu v73,ieee-fp=false
 

hvx_histogram: hvx_histogram.c hvx_histogram_row.S

        $(CC) $(CFLAGS) $(CROSS_CC_GUEST_CFLAGS) $^ -o $@ $(LDFLAGS)

Otherwise

#25 lore raw

PATCH v3 13/16 tests/hexagon: add tests for v68 HVX IEEE float min/max

In reply to Matheus Tavares Bernardino
---
 tests/tcg/hexagon/fp_hvx.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
tests/tcg/hexagon/fp_hvx.c +30 -0
index 0365833753..46f49c0d3c 100644
@@ -73,6 +73,30 @@ DEF_TEST_OP_2(vsub, SUB_HF, hf, hf);
 DEF_TEST_OP_2(vmpy, MULT_SF, sf, sf);
 DEF_TEST_OP_2(vmpy, MULT_HF, hf, hf);
 
+#define signbit_fp(X) \
+    (sizeof(X) == bytes_hf ? ((raw_hf(X) & 0x8000) != 0) : \
+                             ((raw_sf(X) & 0x80000000) != 0))
+
+#define STD_MIN(X, Y) ((X) < (Y) ? (X) : (Y))
+#define STD_MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+
+#define MIN(X, Y, DEF_NAN) \
+    ((isnan(X) || isnan(Y)) ? DEF_NAN : \
+     ((X) != (Y)) ? STD_MIN(X, Y) : (signbit_fp(X) ? (X) : (Y))) /* -0 < +0 */
+#define MAX(X, Y, DEF_NAN) \
+    ((isnan(X) || isnan(Y)) ? DEF_NAN : \
+     ((X) != (Y)) ? STD_MAX(X, Y) : (signbit_fp(X) ? (Y) : (X))) /* -0 < +0 */
+
+#define MIN_HF(X, Y) MIN(X, Y, NAN_HF)
+#define MAX_HF(X, Y) MAX(X, Y, NAN_HF)
+#define MIN_SF(X, Y) MIN(X, Y, NAN_SF)
+#define MAX_SF(X, Y) MAX(X, Y, NAN_SF)
+
+DEF_TEST_OP_2(vfmin, MIN_SF, sf, sf);
+DEF_TEST_OP_2(vfmax, MAX_SF, sf, sf);
+DEF_TEST_OP_2(vfmin, MIN_HF, hf, hf);
+DEF_TEST_OP_2(vfmax, MAX_HF, hf, hf);
+
 /******************************************************************************
  * Other tests
  *****************************************************************************/
@@ -150,6 +174,12 @@ int main(void)
 
     test_new();
 
+    /* min/max */
+    test_vfmin_sf_sf();
+    test_vfmin_hf_hf();
+    test_vfmax_sf_sf();
+    test_vfmax_hf_hf();
+
     puts(err ? "FAIL" : "PASS");
     return err ? 1 : 0;
 }
Signature · 1 line
2.37.2
#26 lore raw

PATCH v3 14/16 tests/hexagon: add tests for v68 HVX IEEE float conversions

In reply to Matheus Tavares Bernardino
---
 tests/tcg/hexagon/hex_test.h      |  14 +++
 tests/tcg/hexagon/hvx_misc.h      |   2 +
 tests/tcg/hexagon/fp_hvx_cvt.c    | 188 ++++++++++++++++++++++++++++++
 tests/tcg/hexagon/Makefile.target |   3 +
 4 files changed, 207 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx_cvt.c
tests/tcg/hexagon/hex_test.h +14 -0
index e7a6644d41..d5da8ad240 100644
@@ -111,6 +111,20 @@ static inline void __check64_ne(int line, uint64_t val, uint64_t expect)
     "usr = r2\n\t"
 
 /* Some useful floating point values */
+const uint16_t HF_INF = 0x7c00;
+const uint16_t HF_INF_neg = 0xfc00;
+const uint16_t HF_QNaN = 0x7e00;
+const uint16_t HF_SNaN = 0x7d00;
+const uint16_t HF_QNaN_neg = 0xfe00;
+const uint16_t HF_zero = 0x0000;
+const uint16_t HF_zero_neg = 0x8000;
+const uint16_t HF_one = 0x3c00;
+const uint16_t HF_one_recip = 0x3bf9;
+const uint16_t HF_two = 0x4000;
+const uint16_t HF_small_neg = 0x8010;
+const uint16_t HF_any = 0x3c00;
+const uint16_t HF_neg_two = 0xc000;
+
 const uint32_t SF_INF =              0x7f800000;
 const uint32_t SF_INF_neg =          0xff800000;
 const uint32_t SF_QNaN =             0x7fc00000;
tests/tcg/hexagon/hvx_misc.h +2 -0
index 0330cb289d..43de20da6a 100644
@@ -69,7 +69,9 @@ CHECK_OUTPUT_FUNC(d,  8)
 CHECK_OUTPUT_FUNC(w,  4)
 CHECK_OUTPUT_FUNC(sf, 4)
 CHECK_OUTPUT_FUNC(h,  2)
+CHECK_OUTPUT_FUNC(uh, 2)
 CHECK_OUTPUT_FUNC(hf, 2)
+CHECK_OUTPUT_FUNC(ub,  1)
 CHECK_OUTPUT_FUNC(b,  1)
 
 static inline void init_buffers(void)
tests/tcg/hexagon/fp_hvx_cvt.c new file +188 -0

188 lines not on this page · raw message

tests/tcg/hexagon/Makefile.target +3 -0
index 789721bdac..83969e0e73 100644
@@ -51,6 +51,7 @@ HEX_TESTS += scatter_gather
 HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
 HEX_TESTS += fp_hvx
+HEX_TESTS += fp_hvx_cvt
 HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding
@@ -132,6 +133,8 @@ fp_hvx: fp_hvx.c hvx_misc.h
 fp_hvx: CFLAGS += -mhvx -mhvx-ieee-fp
 fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
 fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_cvt: fp_hvx_cvt.c hvx_misc.h
+fp_hvx_cvt: CFLAGS += -mhvx -mhvx-ieee-fp
 
 run-fp_hvx_disabled: QEMU_OPTS += -cpu v73,ieee-fp=false
 
Signature · 1 line
2.37.2
Reviewed-by on v3 14/16
#27 lore raw

Re: [PATCH v3 14/16] tests/hexagon: add tests for v68 HVX IEEE float conversions

Quoted 24 lines · Matheus Tavares Bernardino

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 tests/tcg/hexagon/hex_test.h      |  14 +++
 tests/tcg/hexagon/hvx_misc.h      |   2 +
 tests/tcg/hexagon/fp_hvx_cvt.c    | 188 ++++++++++++++++++++++++++++++
 tests/tcg/hexagon/Makefile.target |   3 +
 4 files changed, 207 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx_cvt.c
tests/tcg/hexagon/Makefile.target +1 -0
index 789721bdac..83969e0e73 100644
@@ -51,6 +51,7 @@ HEX_TESTS += scatter_gather
 HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
 HEX_TESTS += fp_hvx
+HEX_TESTS += fp_hvx_cvt
 HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding

tests/tcg/hexagon/Makefile.target fp_hvx: fp_hvx.c hvx_misc.h · line 137

Quoted 5 lines
tests/tcg/hexagon/Makefile.target +1 -0
@@ -132,6 +133,8 @@ fp_hvx: fp_hvx.c hvx_misc.h
 fp_hvx: CFLAGS += -mhvx -mhvx-ieee-fp
 fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
 fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_cvt: fp_hvx_cvt.c hvx_misc.h
 

Also hex_test.h

Otherwise

#28 lore raw

PATCH v3 15/16 tests/hexagon: add tests for v68 HVX IEEE float comparisons

In reply to Matheus Tavares Bernardino
---
 tests/tcg/hexagon/hex_test.h      |   1 +
 tests/tcg/hexagon/fp_hvx_cmp.c    | 227 ++++++++++++++++++++++++++++++
 tests/tcg/hexagon/Makefile.target |   3 +
 3 files changed, 231 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx_cmp.c
tests/tcg/hexagon/hex_test.h +1 -0
index d5da8ad240..79d30ec61c 100644
@@ -115,6 +115,7 @@ const uint16_t HF_INF = 0x7c00;
 const uint16_t HF_INF_neg = 0xfc00;
 const uint16_t HF_QNaN = 0x7e00;
 const uint16_t HF_SNaN = 0x7d00;
+const uint16_t HF_SNaN_neg = 0xfd00;
 const uint16_t HF_QNaN_neg = 0xfe00;
 const uint16_t HF_zero = 0x0000;
 const uint16_t HF_zero_neg = 0x8000;
tests/tcg/hexagon/fp_hvx_cmp.c new file +227 -0

227 lines not on this page · raw message

tests/tcg/hexagon/Makefile.target +3 -0
index 83969e0e73..76ba245add 100644
@@ -52,6 +52,7 @@ HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
 HEX_TESTS += fp_hvx
 HEX_TESTS += fp_hvx_cvt
+HEX_TESTS += fp_hvx_cmp
 HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding
@@ -135,6 +136,8 @@ fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
 fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
 fp_hvx_cvt: fp_hvx_cvt.c hvx_misc.h
 fp_hvx_cvt: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_cmp: fp_hvx_cmp.c hvx_misc.h
+fp_hvx_cmp: CFLAGS += -mhvx -mhvx-ieee-fp
 
 run-fp_hvx_disabled: QEMU_OPTS += -cpu v73,ieee-fp=false
 
Signature · 1 line
2.37.2
Reviewed-by on v3 15/16
#29 lore raw

Re: [PATCH v3 15/16] tests/hexagon: add tests for v68 HVX IEEE float comparisons

Quoted 13 lines · Matheus Tavares Bernardino

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 tests/tcg/hexagon/hex_test.h      |   1 +
 tests/tcg/hexagon/fp_hvx_cmp.c    | 227 ++++++++++++++++++++++++++++++
 tests/tcg/hexagon/Makefile.target |   3 +
 3 files changed, 231 insertions(+)
 create mode 100644 tests/tcg/hexagon/fp_hvx_cmp.c
tests/tcg/hexagon/fp_hvx_cmp.c new file +0 -0
new file mode 100644

tests/tcg/hexagon/fp_hvx_cmp.c line 167

Quoted 5 lines
tests/tcg/hexagon/fp_hvx_cmp.c new file +5 -0
+static void test_cmp_variants(void)
+{
+    HVX_VectorPred true_pred, false_pred, pred;
+    memset(&true_pred, 0xff, sizeof(true_pred));
+    memset(&false_pred, 0, sizeof(false_pred));

Minor nit - Use a single vector with a mix of true/false values instead of one test with all-true and another test with all-false.

Quoted 46 lines
tests/tcg/hexagon/fp_hvx_cmp.c new file +23 -0
+
+    PREP_TEST();
+    ADD_TEST_CMP(sf, SF_one,  SF_zero, true);
+    ADD_TEST_CMP(sf, SF_zero, SF_one,  false);
+    ADD_TEST_CMP(sf, SF_one,  SF_zero, true);
+    ADD_TEST_CMP(sf, SF_zero, SF_one,  false);
+
+    /* greater and */
+    pred = Q6_Q_vcmp_gtand_QVsfVsf(true_pred, buffers[0], buffers[1]);
+    *hvx_output = Q6_V_vmux_QVV(pred, true_vec, false_vec);
+    for (int j = 0; j < 4; j++) {
+        int exp = j % 2 ? 0 : 0xffffffff;
+        if (output[0].sf[j] != exp) {
+            printf("ERROR line %d: gtand %d: expected 0x%x got 0x%x\n",
+                   __LINE__, j, exp, output[0].sf[j]);
+            err++;
+        }
+    }
+    pred = Q6_Q_vcmp_gtand_QVsfVsf(false_pred, buffers[0], buffers[1]);
+    *hvx_output = Q6_V_vmux_QVV(pred, true_vec, false_vec);
+    for (int j = 0; j < 4; j++) {
+        if (output[0].sf[j]) {
+            printf("ERROR line %d: gtand %d: expected false\n", __LINE__,

j);

tests/tcg/hexagon/fp_hvx_cmp.c new file +20 -0
+            err++;
+        }
+    }
+
+    /* greater or */
+    pred = Q6_Q_vcmp_gtor_QVsfVsf(false_pred, buffers[0], buffers[1]);
+    *hvx_output = Q6_V_vmux_QVV(pred, true_vec, false_vec);
+    for (int j = 0; j < 4; j++) {
+        int exp = j % 2 ? 0 : 0xffffffff;
+        if (output[0].sf[j] != exp) {
+            printf("ERROR line %d: gtor %d: expected 0x%x got 0x%x\n",
+                   __LINE__, j, exp, output[0].sf[j]);
+            err++;
+        }
+    }
+    pred = Q6_Q_vcmp_gtor_QVsfVsf(true_pred, buffers[0], buffers[1]);
+    *hvx_output = Q6_V_vmux_QVV(pred, true_vec, false_vec);
+    for (int j = 0; j < 4; j++) {
+        if (!output[0].sf[j]) {
+            printf("ERROR line %d: gtor %d: expected true\n", __LINE__,

j);

tests/tcg/hexagon/fp_hvx_cmp.c

Quoted 2 lines
tests/tcg/hexagon/fp_hvx_cmp.c new file +2 -0
+            err++;
+        }

Add a test for xor

Quoted 29 lines
tests/tcg/hexagon/fp_hvx_cmp.c new file +15 -0
+    }
+}
+
+int main(void)
+{
+    memset(&true_vec, 0xff, sizeof(true_vec));
+    memset(&false_vec, 0, sizeof(false_vec));
+
+    test_cmp_sf();
+    test_cmp_hf();
+    test_cmp_variants();
+
+    puts(err ? "FAIL" : "PASS");
+    return err ? 1 : 0;
+}
tests/tcg/hexagon/Makefile.target +1 -0
index 83969e0e73..76ba245add 100644
@@ -52,6 +52,7 @@ HEX_TESTS += hvx_misc
 HEX_TESTS += hvx_histogram
 HEX_TESTS += fp_hvx
 HEX_TESTS += fp_hvx_cvt
+HEX_TESTS += fp_hvx_cmp
 HEX_TESTS += fp_hvx_disabled
 HEX_TESTS += invalid-slots
 HEX_TESTS += invalid-encoding

tests/tcg/hexagon/Makefile.target fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h · line 140

Quoted 5 lines
tests/tcg/hexagon/Makefile.target +1 -0
@@ -135,6 +136,8 @@ fp_hvx_disabled: fp_hvx_disabled.c hvx_misc.h
 fp_hvx_disabled: CFLAGS += -mhvx -mhvx-ieee-fp
 fp_hvx_cvt: fp_hvx_cvt.c hvx_misc.h
 fp_hvx_cvt: CFLAGS += -mhvx -mhvx-ieee-fp
+fp_hvx_cmp: fp_hvx_cmp.c hvx_misc.h
 

Also hex_test.h

Otherwise

#30 lore raw

PATCH v3 16/16 tests/hexagon: add tests for HVX bfloat

In reply to Matheus Tavares Bernardino
---
 tests/tcg/hexagon/hex_test.h   | 13 +++++++++
 tests/tcg/hexagon/hvx_misc.h   | 30 ++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx.c     | 41 +++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_cmp.c | 52 ++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_cvt.c | 31 ++++++++++++++++++++
 5 files changed, 167 insertions(+)
tests/tcg/hexagon/hex_test.h +13 -0
index 79d30ec61c..f86e6e1a69 100644
@@ -126,6 +126,19 @@ const uint16_t HF_small_neg = 0x8010;
 const uint16_t HF_any = 0x3c00;
 const uint16_t HF_neg_two = 0xc000;
 
+const uint16_t BF_INF           = 0x7f80;
+const uint16_t BF_INF_neg       = 0xff80;
+const uint16_t BF_QNaN          = 0x7fc0;
+const uint16_t BF_SNaN          = 0x7f81;
+const uint16_t BF_QNaN_neg      = 0xffc0;
+const uint16_t BF_SNaN_neg      = 0xff81;
+const uint16_t BF_HEX_NaN       = 0x7fff;
+const uint16_t BF_zero          = 0x0000;
+const uint16_t BF_zero_neg      = 0x8000;
+const uint16_t BF_one           = 0x3f80;
+const uint16_t BF_two           = 0x4000;
+const uint16_t BF_four          = 0x4080;
+
 const uint32_t SF_INF =              0x7f800000;
 const uint32_t SF_INF_neg =          0xff800000;
 const uint32_t SF_QNaN =             0x7fc00000;
tests/tcg/hexagon/hvx_misc.h +30 -0
index 43de20da6a..c21ea975c1 100644
@@ -41,6 +41,7 @@ typedef union {
     uint16_t uh[MAX_VEC_SIZE_BYTES / 2];
     uint16_t hf[MAX_VEC_SIZE_BYTES / 2]; /* convenience alias */
     int16_t   h[MAX_VEC_SIZE_BYTES / 2];
+    uint16_t  bf[MAX_VEC_SIZE_BYTES / 2];
     uint8_t  ub[MAX_VEC_SIZE_BYTES / 1];
     int8_t    b[MAX_VEC_SIZE_BYTES / 1];
 } MMVector;
@@ -73,6 +74,7 @@ CHECK_OUTPUT_FUNC(uh, 2)
 CHECK_OUTPUT_FUNC(hf, 2)
 CHECK_OUTPUT_FUNC(ub,  1)
 CHECK_OUTPUT_FUNC(b,  1)
+CHECK_OUTPUT_FUNC(bf,  2)
 
 static inline void init_buffers(void)
 {
@@ -97,6 +99,12 @@ static const uint32_t FP_VALUES[] = {
 };
 #define FP_VALUES_MAX ARRAY_SIZE(FP_VALUES)
 
+static const uint16_t BF_VALUES[] = {
+    BF_INF, BF_INF_neg, BF_QNaN, BF_SNaN, BF_QNaN_neg, BF_SNaN_neg,
+    BF_HEX_NaN, BF_zero, BF_zero_neg, BF_one, BF_two, BF_four,
+};
+#define BF_VALUES_MAX ARRAY_SIZE(BF_VALUES)
+
 static inline void init_buffers_fp(void)
 {
     _Static_assert(BUFSIZE * (MAX_VEC_SIZE_BYTES / 4) >
@@ -116,6 +124,25 @@ static inline void init_buffers_fp(void)
     }
 }
 
+static inline void init_buffers_bf(void)
+{
+    _Static_assert(BUFSIZE * (MAX_VEC_SIZE_BYTES / 2) >
+                   BF_VALUES_MAX * BF_VALUES_MAX,
+                   "test arrays can't fit all BF_VALUES combinations");
+    int counter1 = 0, counter2 = 0;
+    for (int i = 0; i < BUFSIZE; i++) {
+        for (int j = 0; j < MAX_VEC_SIZE_BYTES / 2; j++) {
+            buffer0[i].bf[j] = BF_VALUES[counter1];
+            buffer1[i].bf[j] = BF_VALUES[counter2];
+            counter2++;
+            if (counter2 == BF_VALUES_MAX) {
+                counter2 = 0;
+                counter1 = (counter1 + 1) % BF_VALUES_MAX;
+            }
+        }
+    }
+}
+
 #define VEC_OP1(ASM, EL, IN, OUT) \
     asm("v2 = vmem(%0 + #0)\n\t" \
         "v2" #EL " = " #ASM "(v2" #EL ")\n\t" \
@@ -212,10 +239,13 @@ static inline void test_##NAME(bool invert) \
 
 #define float_sf(x) ({ typeof(x) _x = (x); *((float *)&(_x)); })
 #define float_hf(x) ({ typeof(x) _x = (x); *((_Float16 *) &(_x)); })
+#define float_bf(x) ({ uint32_t _u = ((uint32_t)(x)) << 16; *((float *)&(_u)); })
 #define raw_sf(x) ({ typeof(x) _x = (x); *((uint32_t *)&(_x)); })
 #define raw_hf(x) ({ typeof(x) _x = (x); *((uint16_t *)&(_x)); })
+#define raw_bf(x) ({ typeof(x) _x = (x); (uint16_t)(*((uint32_t *)&(_x)) >> 16); })
 #define float_hf_to_sf(x) ((float)x)
 #define bytes_hf 2
 #define bytes_sf 4
+#define bytes_bf 2
 
 #endif
tests/tcg/hexagon/fp_hvx.c +41 -0

64 lines not on this page · raw message

tests/tcg/hexagon/fp_hvx_cmp.c +52 -0

73 lines not on this page · raw message

tests/tcg/hexagon/fp_hvx_cvt.c +31 -0
index 71c3f0fd4f..bd8d39d6b6 100644
@@ -19,6 +19,8 @@ int err;
 #include "hvx_misc.h"
 #include "hex_test.h"
 
+#define NAN_BF 0x7FFF
+
 #define TEST_EXP(TO, FROM, VAL, EXP) do { \
     ((MMVector *)&buffer)->FROM[index] = VAL; \
     expect[0].TO[index] = EXP; \
@@ -172,6 +174,34 @@ DEF_TEST_VCONV(sf, w, { \
     TEST_EXP(sf, w, 16777219, raw_sf((float)16777220)); /* rounds UP */ \
 })
 
+#define TEST_EXP_BF(VAL, EXP) do { \
+    ((MMVector *)&buffers[1])->sf[index] = VAL; \
+    ((MMVector *)&buffers[0])->sf[index] = VAL; \
+    expect[0].bf[2 * index] = EXP; \
+    expect[0].bf[2 * index + 1] = EXP; \
+    index++; \
+} while (0)
+
+static void test_vconv_bf_sf(void)
+{
+    HVX_Vector *hvx_output = (HVX_Vector *)&output[0];
+    HVX_Vector buffers[2];
+    int index = 0;
+    memset(&buffers, 0, sizeof(buffers));
+    memset(expect, 0, sizeof(expect));
+
+    TEST_EXP_BF(SF_QNaN, NAN_BF);
+    TEST_EXP_BF(SF_SNaN, NAN_BF);
+    TEST_EXP_BF(SF_QNaN_neg, NAN_BF);
+    TEST_EXP_BF(SF_INF, BF_INF);
+    TEST_EXP_BF(SF_INF_neg, BF_INF_neg);
+    TEST_EXP_BF(SF_one, BF_one);
+    TEST_EXP_BF(SF_zero_neg, BF_zero_neg);
+
+    *hvx_output = Q6_Vbf_vcvt_VsfVsf(buffers[0], buffers[1]);
+    check_output_hf(__LINE__, 1);
+}
+
 int main(void)
 {
     test_vcvt_uh_hf();
@@ -182,6 +212,7 @@ int main(void)
     test_vconv_sf_w();
     test_vconv_h_hf();
     test_vconv_hf_h();
+    test_vconv_bf_sf();
 
     puts(err ? "FAIL" : "PASS");
     return err ? 1 : 0;
Signature · 1 line
2.37.2
Reviewed-by on v3 16/16
#31 lore raw

Re: [PATCH v3 16/16] tests/hexagon: add tests for HVX bfloat

Quoted 17 lines · Matheus Tavares Bernardino

Signed-off-by: Matheus Tavares Bernardino <
[email protected]>

---
 tests/tcg/hexagon/hex_test.h   | 13 +++++++++
 tests/tcg/hexagon/hvx_misc.h   | 30 ++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx.c     | 41 +++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_cmp.c | 52 ++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/fp_hvx_cvt.c | 31 ++++++++++++++++++++
 5 files changed, 167 insertions(+)
tests/tcg/hexagon/fp_hvx_cmp.c +0 -0
index c4e1c81ce5..4417e736f9 100644

tests/tcg/hexagon/fp_hvx_cmp.c int err; · line 26

Quoted 5 lines
tests/tcg/hexagon/fp_hvx_cmp.c +1 -0
@@ -22,9 +22,11 @@ int err;
 
 #define MAX_TESTS_hf (MAX_VEC_SIZE_BYTES / 2)
 #define MAX_TESTS_sf (MAX_VEC_SIZE_BYTES / 4)
+#define MAX_TESTS_bf (MAX_VEC_SIZE_BYTES / 4)
 

Divide by 2, not 4.

Otherwise