hexagon: add missing HVX float instructions
v2 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.
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Changes in v2:
- Renamed kvx_ieee.{c,h} to hvx_ieee_fp.{c,h}
- Dedicated HVX floating-point status: Added a separate hvx_fp_status field in CPUArchState for HVX IEEE FP operations. This isolates HVX FP state from scalar FP operations and allows configuring the correct default NaN pattern for HVX (0x7FFF... instead of 0xFFFF...)
- Disabled IEEE FP behavior: When the HVX IEEE FP extension is disabled, instructions now zero out their destination registers instead of being complete no-ops. This matches actual hardware behavior more closely
- Fixed NaN comparison ordering: Rewrote the comparison functions (fCMPGT_SF, fCMPGT_HF, fCMPGT_BF) with proper NaN ordering
semantics: QNaN > SNaN > +Inf > numbers > -Inf > SNaN_neg > QNaN_neg
- Simplified FP helper macros: Removed redundant NaN checks from DEF_FP_INSN_2/DEF_FP_INSN_3 macros since the softfloat library handles NaN propagation correctly when default_nan_mode is enabled
- Expanded test coverage:
- Tests to cover NaN vs NaN, NaN vs Inf, and NaN vs regular numbers
- Added tests for vcmp_gtand/vcmp_gtor variants
- Added bfloat tests
- Added .new register usage tests for disabled IEEE FP
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 | 128 ++++++ 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 | 275 +++++++++++++ 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 | 363 +++++++++++++++++- target/hexagon/meson.build | 1 + .../dockerfiles/debian-hexagon-cross.docker | 10 +- tests/tcg/hexagon/Makefile.target | 14 + 28 files changed, 1891 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
Signature · 1 line
2.37.2
PATCH v2 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
@@ -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
PATCH v2 2/16 target/hexagon: fix incorrect/too-permissive HVX encodings
In reply to Matheus Tavares BernardinoThe 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
@@ -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
PATCH v2 3/16 target/hexagon/cpu: add HVX IEEE FP extension
In reply to Matheus Tavares BernardinoThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 4/16 hexagon: group cpu configurations in their own struct
In reply to Matheus Tavares BernardinoThis 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 5/16 hexagon: print info on "-d in_asm" for disabled IEEE FP instructions
In reply to Matheus Tavares BernardinoWhen 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 6/16 target/hexagon: add v68 HVX IEEE float arithmetic insns
In reply to Matheus Tavares BernardinoAdd 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 | 47 ++++++++++ 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 | 69 +++++++++++++++ target/hexagon/hex_common.py | 1 + target/hexagon/imported/mmvec/encode_ext.def | 18 ++++ target/hexagon/imported/mmvec/ext.idef | 93 ++++++++++++++++++++ target/hexagon/meson.build | 1 + 12 files changed, 248 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
@@ -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 +47 -0
47 lines not on this page · raw message
target/hexagon/mmvec/macros.h +1 -0
@@ -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
@@ -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 ]; +int32_t sf[MAX_VEC_SIZE_BYTES /4 ];/* single float (32-bit) */ +int16_t hf[MAX_VEC_SIZE_BYTES /2 ];/* half float (16-bit) */ } MMVector; typedef union {
target/hexagon/attribs_def.h.inc +4 -0
@@ -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
@@ -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
@@ -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 +69 -0
69 lines not on this page · raw message
target/hexagon/hex_common.py +1 -0
@@ -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
@@ -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 +93 -0
102 lines not on this page · raw message
target/hexagon/meson.build +1 -0
@@ -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
Re: [PATCH v2 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns
target/hexagon/cpu.c static void hexagon_cpu_reset_hold(Object *obj, ResetType type) · line 306
Quoted 12 lines · Matheus Tavares Bernardino
target/hexagon/cpu.c +3
-0@@ -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); }
Do you still want to detect tininess before rounding? I would find it unusual for two fp units to differ on this...
r~
Re: [PATCH v2 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns
Quoted 17 lines · Richard Henderson
target/hexagon/cpu.c static void hexagon_cpu_reset_hold(Object *obj, ResetType type) · line 306
Quoted 12 lines · Matheus Tavares Bernardino
target/hexagon/cpu.c +3
-0@@ -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); }Do you still want to detect tininess before rounding? I would find it unusual for two fp units to differ on this...
HVX IEEE FP operations don't raise floating-point exceptions like
underflow (with HVX we can have 32+ fp operations simultaneously, so the hardware is simplified not to produce exceptions), thus the tininess detection mode shouldn't matter for this unit.
Re: [PATCH v2 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns
In reply to Matheus Tavares BernardinoQuoted 17 lines · Matheus Tavares Bernardino
+++
b/target/hexagon/mmvec/hvx_ieee_fp.ctarget/hexagon/mmvec/hvx_ieee_fp.c new file +15
-0@@ -0,0 +1,69 @@ +/* +* 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" + +#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); \
target/hexagon/mmvec/hvx_ieee_fp.c line 25
Quoted 10 lines
target/hexagon/mmvec/hvx_ieee_fp.c new file +10
-0+ } + +#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); \ + }
Why are you using uint32_t and make_float instead of declaring with float32 in the first place?
r~
Re: [PATCH v2 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns
Quoted 24 lines · Richard Henderson
Quoted 22 lines · Matheus Tavares Bernardino
+++
b/target/hexagon/mmvec/hvx_ieee_fp.ctarget/hexagon/mmvec/hvx_ieee_fp.c new file +20
-0@@ -0,0 +1,69 @@ +/* +* 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" + +#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) { \
Quoted 8 lines
target/hexagon/mmvec/hvx_ieee_fp.c line 25
Quoted 5 lines
target/hexagon/mmvec/hvx_ieee_fp.c new file +5
-0+ float##a1t f1 = make_float##a1t(a1); \ + float##a2t f2 = make_float##a2t(a2); \ + float##a3t f3 = make_float##a3t(a3); \ + return (op); \ + }Why are you using
uint32_tandmake_floatinstead of declaring with float32 in the first place?
The helper functions receive raw bit values from the HVX vector registers via the generated TCG code. The idea behind using uint32_t/uint16_t in the signatures is to make the raw-bits interface explicit, since make_float* is essentially a no-op cast. But I can change to float32 if that's preferable.
Re: [PATCH v2 06/16] target/hexagon: add v68 HVX IEEE float arithmetic insns
Quoted 34 lines · Matheus Bernardino
Quoted 16 lines · Richard Henderson
Quoted 14 lines · Matheus Tavares Bernardino
+++
b/target/hexagon/mmvec/hvx_ieee_fp.ctarget/hexagon/mmvec/hvx_ieee_fp.c new file +12
-0@@ -0,0 +1,69 @@ +/* +* 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" + +#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) { \Quoted 8 lines
target/hexagon/mmvec/hvx_ieee_fp.c
Quoted 8 lines
target/hexagon/mmvec/hvx_ieee_fp.c new file +8
-0+ 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){ \
Quoted 7 lines
target/hexagon/mmvec/hvx_ieee_fp.c line 25
Quoted 5 lines
target/hexagon/mmvec/hvx_ieee_fp.c new file +5
-0+ float##a1t f1 = make_float##a1t(a1); \ + float##a2t f2 = make_float##a2t(a2); \ + float##a3t f3 = make_float##a3t(a3); \ + return (op); \ + }Why are you using
uint32_tandmake_floatinstead of declaring with
Quoted 9 lines
float32 in the first
Quoted 1 line
place?
The helper functions receive raw bit values from the HVX vector registers via the generated TCG code. The idea behind using uint32_t/uint16_t in the signatures is to make the raw-bits interface explicit, since make_float* is essentially a no-op cast. But I can change to float32 if that's preferable.
That will be better. Go all the way back to the sf/hf/bf fields in MMVector and change the types to float32/float16/bfloat16. The code will be much cleaner.
Taylor
PATCH v2 7/16 target/hexagon: add v68 HVX IEEE float min/max insns
In reply to Matheus Tavares BernardinoAdd 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 | 12 ++++ target/hexagon/mmvec/hvx_ieee_fp.c | 62 ++++++++++++++++++++ target/hexagon/imported/mmvec/encode_ext.def | 10 ++++ target/hexagon/imported/mmvec/ext.idef | 36 +++++++++++- 4 files changed, 119 insertions(+), 1 deletion(-)
target/hexagon/mmvec/hvx_ieee_fp.h +12 -0
@@ -44,4 +44,16 @@ 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); +/* 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); +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/mmvec/hvx_ieee_fp.c +62 -0
65 lines not on this page · raw message
target/hexagon/imported/mmvec/encode_ext.def +10 -0
@@ -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
@@ -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)
@@ -2992,6 +2994,38 @@ 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)) +#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] = fp_min_hf(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], \ + &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], \ + &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], \ + &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
PATCH v2 8/16 target/hexagon: add v68 HVX IEEE float misc insns
In reply to Matheus Tavares BernardinoAdd 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
@@ -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
@@ -3026,6 +3026,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
PATCH v2 9/16 target/hexagon: add v68 HVX IEEE float conversion insns
In reply to Matheus Tavares BernardinoAdd 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 | 21 +++++ target/hexagon/mmvec/hvx_ieee_fp.c | 88 ++++++++++++++++++ target/hexagon/imported/mmvec/encode_ext.def | 18 ++++ target/hexagon/imported/mmvec/ext.idef | 97 ++++++++++++++++++++ 4 files changed, 224 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +21 -0
@@ -56,4 +56,25 @@ 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); +#endif
target/hexagon/mmvec/hvx_ieee_fp.c +88 -0
91 lines not on this page · raw message
target/hexagon/imported/mmvec/encode_ext.def +18 -0
@@ -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
PATCH v2 10/16 target/hexagon: add v68 HVX IEEE float compare insns
In reply to Matheus Tavares BernardinoAdd 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/attribs_def.h.inc | 2 + target/hexagon/mmvec/hvx_ieee_fp.c | 52 +++++++++++++++++ target/hexagon/hex_common.py | 1 + target/hexagon/imported/mmvec/encode_ext.def | 10 ++++ target/hexagon/imported/mmvec/ext.idef | 61 ++++++++++++++++++++ 7 files changed, 133 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +4 -0
@@ -56,6 +56,10 @@ 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 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 */
target/hexagon/mmvec/macros.h +3 -0
@@ -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/attribs_def.h.inc +2 -0
@@ -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 +52 -0
55 lines not on this page · raw message
target/hexagon/hex_common.py +1 -0
@@ -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
@@ -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
PATCH v2 11/16 target/hexagon: add v73 HVX IEEE bfloat16 insns
In reply to Matheus Tavares BernardinoAdd 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 | 44 ++++++++++++++ target/hexagon/mmvec/macros.h | 4 ++ target/hexagon/mmvec/mmvec.h | 1 + target/hexagon/mmvec/hvx_ieee_fp.c | 4 ++ target/hexagon/imported/mmvec/encode_ext.def | 15 +++++ target/hexagon/imported/mmvec/ext.idef | 64 ++++++++++++++++++++ 6 files changed, 132 insertions(+)
target/hexagon/mmvec/hvx_ieee_fp.h +44 -0
@@ -81,4 +81,48 @@ 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); +/* 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) +#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) +#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) + +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) + +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(fp_min_sf(bf_to_sf(A, &env->hvx_fp_status), \ + bf_to_sf(B, &env->hvx_fp_status), \ + &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), \ + &env->hvx_fp_status); +#endif
target/hexagon/mmvec/macros.h +4 -0
@@ -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
@@ -40,6 +40,7 @@ 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 */ } MMVector; typedef union {
target/hexagon/mmvec/hvx_ieee_fp.c +4 -0
@@ -269,3 +269,7 @@ 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 +15 -0
@@ -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 +64 -0
78 lines not on this page · raw message
Signature · 1 line
2.37.2
PATCH v2 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
@@ -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
@@ -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
PATCH v2 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
@@ -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
PATCH v2 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
@@ -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
@@ -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
@@ -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
PATCH v2 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
@@ -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
@@ -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
PATCH v2 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
@@ -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
@@ -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
@@ -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