Skip to contentSkip to conversation

Hexagon patch series

RFC PATCH Superseded Taylor Simpson 2 participants 72 messages Feb 28, 2020 – Apr 30, 2020 exec and binfmt Page 1 of 2

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Hexagon patch series

This series adds support for the Hexagon processor with Linux user support

See patch 02/67 Hexagon README for detailed information.

The patches up to and including "Hexagon build infractructure" implement the base Hexagon core and the remainder add HVX. Once the build infrastructure patch is applied, you can build and qemu will execute non-HVX Hexagon programs.

We have a parallel effort to make the Hexagon Linux toolchain publically available.

*** Testing ***

The port passes the following tests
Directed unit tests will contributed when the Hexagon toolchain is available MUSL libc test suite (good coverage of Linux system calls)
https://git.musl-libc.org/cgit/libc-testsuite/
Internal compiler intrinsics test suite (good coverage of instructions) Hexagon machine learning library unit tests
TODO - pull these from the CAF repo
make check-tcg TIMEOUT=60

*** Known checkpatch issues ***

The following are known checkpatch errors in the series
include/disas/dis-asm.h space prohibited
(Follow convention of other targets on prior lines)
target/hexagon/reg_fields.h Complex macro
target/hexagon/attribs.h Complex macro
target/hexagon/decode.c Complex macro
target/hexagon/q6v_decode.c Macro needs do - while
target/hexagon/printinsn.c Macro needs do - while
target/hexagon/gen_semantics.c Suspicious ; after while (0)
target/hexagon/gen_dectree_import.c Complex macro target/hexagon/gen_dectree_import.c Suspicious ; after while (0)
target/hexagon/opcodes.c Complex macro
target/hexagon/iclass.h Complex macro
scripts/qemu-binfmt-conf.sh Line over 90 characters
target/hexagon/mmvec/macros.h Suspicious ; after while (0)

The following are known checkpatch warnings in the series
target/hexagon/fma_emu.c Comments inside macro definition
scripts/qemu-binfmt-conf.sh Line over 80 characters

*** Changes in v2 ***
- Use scripts/git.orderfile
- Create a README with the code overview in patch 0001
- Change #define's in hex_regs.h to an enum
- Replace hard coded disassembly buffer length (1028) with #define
- Move Hexagon architecture types patch earlier in series
- Replace #include standard header files with #include "qemu/osdep.h"
- Prefix all header file #ifndef's with HEXAGON_
- Update python version to python3
- #include "tcg/tcg.h" in genptr_helpers.h
- Change target/hexagon/Makefile.objs to support out-of-tree build
- Updated copyright to include year 2020
- Bug fixes
Fix some problems with HEX_DEBUG output
Fix bug in circular addressing
- Optimizations to reduce the amount of TCG code generated Change pred_written from an array to a bit mask Optimize readonly vector registers
Conditionally call gen_helper_commit_hvx_stores

Taylor Simpson (67):
Hexagon Maintainers
Hexagon README
Hexagon ELF Machine Definition
Hexagon CPU Scalar Core Definition
Hexagon register names
Hexagon Disassembler
Hexagon CPU Scalar Core Helpers
Hexagon GDB Stub
Hexagon architecture types
Hexagon instruction and packet types
Hexagon register fields
Hexagon instruction attributes
Hexagon register map
Hexagon instruction/packet decode
Hexagon instruction printing
Hexagon arch import - instruction semantics definitions Hexagon arch import - macro definitions
Hexagon arch import - instruction encoding
Hexagon instruction class definitions
Hexagon instruction utility functions
Hexagon generator phase 1 - C preprocessor for semantics Hexagon generator phase 2 - qemu_def_generated.h
Hexagon generator phase 2 - qemu_wrap_generated.h
Hexagon generator phase 2 - opcodes_def_generated.h Hexagon generator phase 2 - op_attribs_generated.h
Hexagon generator phase 2 - op_regs_generated.h
Hexagon generator phase 2 - printinsn-generated.h
Hexagon generator phase 3 - C preprocessor for decode tree Hexagon generater phase 4 - Decode tree
Hexagon opcode data structures
Hexagon macros to interface with the generator
Hexagon macros referenced in instruction semantics
Hexagon instruction classes
Hexagon TCG generation helpers - step 1
Hexagon TCG generation helpers - step 2
Hexagon TCG generation helpers - step 3
Hexagon TCG generation helpers - step 4
Hexagon TCG generation helpers - step 5
Hexagon TCG generation - step 01
Hexagon TCG generation - step 02
Hexagon TCG generation - step 03
Hexagon TCG generation - step 04
Hexagon TCG generation - step 05
Hexagon TCG generation - step 06
Hexagon TCG generation - step 07
Hexagon TCG generation - step 08
Hexagon TCG generation - step 09
Hexagon TCG generation - step 10
Hexagon TCG generation - step 11
Hexagon TCG generation - step 12
Hexagon translation
Hexagon Linux user emulation
Hexagon build infrastructure
Hexagon - Add Hexagon Vector eXtensions (HVX) to core definition Hexagon HVX support in gdbstub
Hexagon HVX import instruction encodings
Hexagon HVX import semantics
Hexagon HVX import macro definitions
Hexagon HVX semantics generator
Hexagon HVX instruction decoding
Hexagon HVX instruction utility functions
Hexagon HVX macros to interface with the generator
Hexagon HVX macros referenced in instruction semantics Hexagon HVX helper to commit vector stores (masked and scatter/gather) Hexagon HVX TCG generation
Hexagon HVX translation
Hexagon HVX build infrastructure

 configure                                    |    9 +
 default-configs/hexagon-linux-user.mak       |    1 +
 include/disas/dis-asm.h                      |    1 +
 include/elf.h                                |    2 +
 linux-user/hexagon/sockbits.h                |   18 +
 linux-user/hexagon/syscall_nr.h              |  346 +++
 linux-user/hexagon/target_cpu.h              |   44 +
 linux-user/hexagon/target_elf.h              |   38 +
 linux-user/hexagon/target_fcntl.h            |   18 +
 linux-user/hexagon/target_signal.h           |   34 +
 linux-user/hexagon/target_structs.h          |   46 +
 linux-user/hexagon/target_syscall.h          |   32 +
 linux-user/hexagon/termbits.h                |   18 +
 linux-user/syscall_defs.h                    |   33 +
 target/hexagon/arch.h                        |   62 +
 target/hexagon/attribs.h                     |   32 +
 target/hexagon/attribs_def.h                 |  404 +++
 target/hexagon/conv_emu.h                    |   50 +
 target/hexagon/cpu-param.h                   |   26 +
 target/hexagon/cpu.h                         |  207 ++
 target/hexagon/cpu_bits.h                    |   37 +
 target/hexagon/decode.h                      |   39 +
 target/hexagon/fma_emu.h                     |   30 +
 target/hexagon/genptr.h                      |   25 +
 target/hexagon/genptr_helpers.h              | 1049 +++++++
 target/hexagon/helper.h                      |   38 +
 target/hexagon/helper_overrides.h            | 1850 ++++++++++++
 target/hexagon/hex_arch_types.h              |   42 +
 target/hexagon/hex_regs.h                    |   99 +
 target/hexagon/iclass.h                      |   46 +
 target/hexagon/insn.h                        |  149 +
 target/hexagon/internal.h                    |   54 +
 target/hexagon/macros.h                      | 1474 ++++++++++
 target/hexagon/mmvec/decode_ext_mmvec.h      |   24 +
 target/hexagon/mmvec/macros.h                |  698 +++++
 target/hexagon/mmvec/mmvec.h                 |   87 +
 target/hexagon/mmvec/system_ext_mmvec.h      |   38 +
 target/hexagon/opcodes.h                     |   67 +
 target/hexagon/printinsn.h                   |   26 +
 target/hexagon/reg_fields.h                  |   40 +
 target/hexagon/reg_fields_def.h              |  109 +
 target/hexagon/regmap.h                      |   38 +
 target/hexagon/translate.h                   |  112 +
 disas/hexagon.c                              |   62 +
 linux-user/elfload.c                         |   16 +
 linux-user/hexagon/cpu_loop.c                |  173 ++
 linux-user/hexagon/signal.c                  |  276 ++
 linux-user/syscall.c                         |    2 +
 target/hexagon/arch.c                        |  663 +++++
 target/hexagon/conv_emu.c                    |  369 +++
 target/hexagon/cpu.c                         |  374 +++
 target/hexagon/decode.c                      |  788 +++++
 target/hexagon/fma_emu.c                     |  916 ++++++
 target/hexagon/gdbstub.c                     |  111 +
 target/hexagon/gen_dectree_import.c          |  205 ++
 target/hexagon/gen_semantics.c               |  101 +
 target/hexagon/genptr.c                      |   61 +
 target/hexagon/iclass.c                      |  107 +
 target/hexagon/mmvec/decode_ext_mmvec.c      |  670 +++++
 target/hexagon/mmvec/system_ext_mmvec.c      |  263 ++
 target/hexagon/op_helper.c                   |  509 ++++
 target/hexagon/opcodes.c                     |  217 ++
 target/hexagon/printinsn.c                   |   91 +
 target/hexagon/q6v_decode.c                  |  416 +++
 target/hexagon/reg_fields.c                  |   28 +
 target/hexagon/translate.c                   |  916 ++++++
 MAINTAINERS                                  |    8 +
 disas/Makefile.objs                          |    1 +
 scripts/qemu-binfmt-conf.sh                  |    6 +-
 target/hexagon/Makefile.objs                 |  127 +
 target/hexagon/README                        |  296 ++
 target/hexagon/dectree.py                    |  353 +++
 target/hexagon/do_qemu.py                    | 1194 ++++++++
 target/hexagon/imported/allext.idef          |   25 +
 target/hexagon/imported/allext_macros.def    |   25 +
 target/hexagon/imported/allextenc.def        |   20 +
 target/hexagon/imported/allidefs.def         |   92 +
 target/hexagon/imported/alu.idef             | 1335 +++++++++
 target/hexagon/imported/branch.idef          |  344 +++
 target/hexagon/imported/compare.idef         |  639 +++++
 target/hexagon/imported/encode.def           |  126 +
 target/hexagon/imported/encode_pp.def        | 2283 +++++++++++++++
 target/hexagon/imported/encode_subinsn.def   |  150 +
 target/hexagon/imported/float.idef           |  498 ++++
 target/hexagon/imported/iclass.def           |   52 +
 target/hexagon/imported/ldst.idef            |  421 +++
 target/hexagon/imported/macros.def           | 3970 ++++++++++++++++++++++++++
 target/hexagon/imported/mmvec/encode_ext.def |  830 ++++++
 target/hexagon/imported/mmvec/ext.idef       | 2780 ++++++++++++++++++
 target/hexagon/imported/mmvec/macros.def     | 1110 +++++++
 target/hexagon/imported/mpy.idef             | 1269 ++++++++
 target/hexagon/imported/shift.idef           | 1211 ++++++++
 target/hexagon/imported/subinsns.idef        |  152 +
 target/hexagon/imported/system.idef          |  302 ++
 tests/tcg/configure.sh                       |    4 +-
 tests/tcg/hexagon/float_convs.ref            |  748 +++++
 tests/tcg/hexagon/float_madds.ref            |  768 +++++
 97 files changed, 36063 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/hexagon-linux-user.mak
 create mode 100644 linux-user/hexagon/sockbits.h
 create mode 100644 linux-user/hexagon/syscall_nr.h
 create mode 100644 linux-user/hexagon/target_cpu.h
 create mode 100644 linux-user/hexagon/target_elf.h
 create mode 100644 linux-user/hexagon/target_fcntl.h
 create mode 100644 linux-user/hexagon/target_signal.h
 create mode 100644 linux-user/hexagon/target_structs.h
 create mode 100644 linux-user/hexagon/target_syscall.h
 create mode 100644 linux-user/hexagon/termbits.h
 create mode 100644 target/hexagon/arch.h
 create mode 100644 target/hexagon/attribs.h
 create mode 100644 target/hexagon/attribs_def.h
 create mode 100644 target/hexagon/conv_emu.h
 create mode 100644 target/hexagon/cpu-param.h
 create mode 100644 target/hexagon/cpu.h
 create mode 100644 target/hexagon/cpu_bits.h
 create mode 100644 target/hexagon/decode.h
 create mode 100644 target/hexagon/fma_emu.h
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/genptr_helpers.h
 create mode 100644 target/hexagon/helper.h
 create mode 100644 target/hexagon/helper_overrides.h
 create mode 100644 target/hexagon/hex_arch_types.h
 create mode 100644 target/hexagon/hex_regs.h
 create mode 100644 target/hexagon/iclass.h
 create mode 100644 target/hexagon/insn.h
 create mode 100644 target/hexagon/internal.h
 create mode 100644 target/hexagon/macros.h
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.h
 create mode 100644 target/hexagon/mmvec/macros.h
 create mode 100644 target/hexagon/mmvec/mmvec.h
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.h
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/reg_fields.h
 create mode 100644 target/hexagon/reg_fields_def.h
 create mode 100644 target/hexagon/regmap.h
 create mode 100644 target/hexagon/translate.h
 create mode 100644 disas/hexagon.c
 create mode 100644 linux-user/hexagon/cpu_loop.c
 create mode 100644 linux-user/hexagon/signal.c
 create mode 100644 target/hexagon/arch.c
 create mode 100644 target/hexagon/conv_emu.c
 create mode 100644 target/hexagon/cpu.c
 create mode 100644 target/hexagon/decode.c
 create mode 100644 target/hexagon/fma_emu.c
 create mode 100644 target/hexagon/gdbstub.c
 create mode 100644 target/hexagon/gen_dectree_import.c
 create mode 100644 target/hexagon/gen_semantics.c
 create mode 100644 target/hexagon/genptr.c
 create mode 100644 target/hexagon/iclass.c
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.c
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.c
 create mode 100644 target/hexagon/op_helper.c
 create mode 100644 target/hexagon/opcodes.c
 create mode 100644 target/hexagon/printinsn.c
 create mode 100644 target/hexagon/q6v_decode.c
 create mode 100644 target/hexagon/reg_fields.c
 create mode 100644 target/hexagon/translate.c
 create mode 100644 target/hexagon/Makefile.objs
 create mode 100644 target/hexagon/README
 create mode 100755 target/hexagon/dectree.py
 create mode 100755 target/hexagon/do_qemu.py
 create mode 100644 target/hexagon/imported/allext.idef
 create mode 100644 target/hexagon/imported/allext_macros.def
 create mode 100644 target/hexagon/imported/allextenc.def
 create mode 100644 target/hexagon/imported/allidefs.def
 create mode 100644 target/hexagon/imported/alu.idef
 create mode 100644 target/hexagon/imported/branch.idef
 create mode 100644 target/hexagon/imported/compare.idef
 create mode 100644 target/hexagon/imported/encode.def
 create mode 100644 target/hexagon/imported/encode_pp.def
 create mode 100644 target/hexagon/imported/encode_subinsn.def
 create mode 100644 target/hexagon/imported/float.idef
 create mode 100644 target/hexagon/imported/iclass.def
 create mode 100644 target/hexagon/imported/ldst.idef
 create mode 100755 target/hexagon/imported/macros.def
 create mode 100644 target/hexagon/imported/mmvec/encode_ext.def
 create mode 100644 target/hexagon/imported/mmvec/ext.idef
 create mode 100755 target/hexagon/imported/mmvec/macros.def
 create mode 100644 target/hexagon/imported/mpy.idef
 create mode 100644 target/hexagon/imported/shift.idef
 create mode 100644 target/hexagon/imported/subinsns.idef
 create mode 100644 target/hexagon/imported/system.idef
 create mode 100644 tests/tcg/hexagon/float_convs.ref
 create mode 100644 tests/tcg/hexagon/float_madds.ref
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH v2 1/67 Hexagon Maintainers

Add Taylor Simpson as the Hexagon target maintainer

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 36d94c1..85fc0ae 100644
@@ -172,6 +172,14 @@ F: include/hw/cris/
 F: tests/tcg/cris/
 F: disas/cris.c
 
+Hexagon TCG CPUs
+M: Taylor Simpson <[email protected]>
+S: Supported
+F: target/hexagon/
+F: linux-user/hexagon/
+F: disas/hexagon.c
+F: default-configs/hexagon-linux-user.mak
+
 HPPA (PA-RISC) TCG CPUs
 M: Richard Henderson <[email protected]>
 S: Maintained
Signature · 1 line
2.7.4
#2 lore raw

RFC PATCH v2 2/67 Hexagon README

In reply to Taylor Simpson

Gives an introduction and overview to the Hexagon target

---
 target/hexagon/README | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 296 insertions(+)
 create mode 100644 target/hexagon/README
target/hexagon/README new file +296 -0
new file mode 100644
index 0000000..6de71e2
@@ -0,0 +1,296 @@
+Hexagon is Qualcomm's very long instruction word (VLIW) digital signal
+processor(DSP).  We also support Hexagon Vector eXtensions (HVX).  HVX
+is a wide vector coprocessor designed for high performance computer vision,
+image processing, machine learning, and other workloads.
+
+The following versions of the Hexagon core are supported
+    Scalar core: v67
+    https://developer.qualcomm.com/downloads/qualcomm-hexagon-v67-programmer-s-reference-manual
+    HVX extension: v66
+    https://developer.qualcomm.com/downloads/qualcomm-hexagon-v66-hvx-programmer-s-reference-manual
+
+We presented an overview of the project at the 2019 KVM Forum.
+    https://kvmforum2019.sched.com/event/Tmwc/qemu-hexagon-automatic-translation-of-the-isa-manual-pseudcode-to-tiny-code-instructions-of-a-vliw-architecture-niccolo-izzo-revng-taylor-simpson-qualcomm-innovation-center
+
+*** Tour of the code ***
+
+The qemu-hexagon implementation is a combination of qemu and the Hexagon
+architecture library (aka archlib).  The three primary directories with
+Hexagon-specific code are
+
+    qemu/target/hexagon
+        This has all the instruction and packet semantics
+    qemu/target/hexagon/imported
+        These files are imported with very little modification from archlib
+        *.idef                  Instruction semantics definition
+        macros.def              Mapping of macros to instruction attributes
+        encode*.def             Encoding patterns for each instruction
+        iclass.def              Instruction class definitions used to determine
+                                legal VLIW slots for each instruction
+    qemu/linux-user/hexagon
+        Helpers for loading the ELF file and making Linux system calls,
+        signals, etc
+
+We start with a script that generates qemu helper for each instruction.  This
+is a two step process.  The first step is to use the C preprocessor to expand
+macros inside the architecture definition files.  This is done in
+target/hexagon/semantics.c.  This step produces
+    <BUILD_DIR>/hexagon-linux-user/semantics_generated.pyinc.
+That file is consumed by the do_qemu.py script.  This script generates
+several files.  All of the generated files end in "_generated.*".  The
+primary file produced is
+    <BUILD_DIR>/hexagon-linux-user/qemu_def_generated.h
+
+Qemu helper functions have 3 parts
+    DEF_HELPER declaration indicates the signature of the helper
+    gen_helper_<NAME> will generate a TCG call to the helper function
+    The helper implementation
+
+In the qemu_def_generated.h file, there is a DEF_QEMU macro for each user-space
+instruction.  The file is included several times with DEF_QEMU defined
+differently, depending on the context.  The macro has four arguments
+    The instruction tag
+    The semantics_short code
+    DEF_HELPER declaration
+    Call to the helper
+    Helper implementation
+
+Here's an example of the A2_add instruction.
+    Instruction tag        A2_add
+    Assembly syntax        "Rd32=add(Rs32,Rt32)"
+    Instruction semantics  "{ RdV=RsV+RtV;}"
+
+By convention, the operands are identified by letter
+    RdV is the destination register
+    RsV, RtV are source registers
+
+The generator uses the operand naming conventions (see large comment in
+do_qemu.py) to determine the signature of the helper function.  Here is the
+result for A2_add from qemu_def_generated.h
+
+DEF_QEMU(A2_add,{ RdV=RsV+RtV;},
+#ifndef fWRAP_A2_add
+DEF_HELPER_3(A2_add, s32, env, s32, s32)
+#endif
+,
+{
+/* A2_add */
+DECL_RREG_d(RdV, RdN, 0, 0);
+DECL_RREG_s(RsV, RsN, 1, 0);
+DECL_RREG_t(RtV, RtN, 2, 0);
+READ_RREG_s(RsV, RsN);
+READ_RREG_t(RtV, RtN);
+fWRAP_A2_add(
+do {
+gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
+} while (0),
+{ RdV=RsV+RtV;});
+WRITE_RREG_d(RdN, RdV);
+FREE_RREG_d(RdV);
+FREE_RREG_s(RsV);
+FREE_RREG_t(RtV);
+/* A2_add */
+},
+#ifndef fWRAP_A2_add
+int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV)
+{
+uint32_t slot = 4; slot = slot;
+int32_t RdV = 0;
+{ RdV=RsV+RtV;}
+COUNT_HELPER(A2_add);
+return RdV;
+}
+#endif
+)
+
+For each operand, there are macros for DECL, FREE, READ, WRITE.  These are
+defined in macros.h.  Note that we append the operand type to the macro name,
+which allows us to specialize the TCG code tenerated.  For read-only operands,
+DECL simply declares the TCGv variable (no need for tcg_temp_local_new()),
+and READ will assign from the TCGv corresponding to the GPR, and FREE doesn't
+have to do anything.  Also, note that the WRITE macros update the disassembly
+context to be processed when the packet commits (see "Packet Semantics" below).
+
+Note the fWRAP_A2_add macro around the gen_helper call.  Each instruction has a fWRAP_<tag> macro that takes 2 arguments
+    gen_helper call
+    C semantics (aka short code)
+
+This allows the code generator to override the auto-generated code.  In some
+cases this is necessary for correct execution.  We can also override for
+faster emulation.  For example, calling a helper for add is more expensive
+than generating a TCG add operation.
+
+The qemu_wrap_generated.h file contains a default fWRAP_<tag> for each
+instruction.  The default is to invoke the gen_helper code.
+    #ifndef fWRAP_A2_add
+    #define fWRAP_A2_add(GENHLPR, SHORTCODE) GENHLPR
+    #endif
+
+The helper_overrides.h file has any overrides. For example,
+    #define fWRAP_A2_add(GENHLPR, SHORTCODE) \
+        tcg_gen_add_tl(RdV, RsV, RtV)
+
+This file is included twice
+1) In genptr.c, it overrides the semantics of the desired instructions
+2) In helper.h, it prevents the generation of helpers for overridden
+   instructions.  Notice the #ifndef fWRAP_A2_add above.
+
+The instruction semantics C code heavily on macros.  In cases where the C
+semantics are specified only with macros, we can override the default with
+the short semantics option and #define the macros to generate TCG code.  One
+example is Y2_dczeroa (dc == data cache, zero == zero out the cache line,
+a == address: zero out the data cache line at the given address):
+    Instruction tag        Y2_dczeroa
+    Assembly syntax        "dczeroa(Rs32)"
+    Instruction semantics  "{fEA_REG(RsV); fDCZEROA(EA);}"
+
+In helper_overrides.h, we use the shortcode
+#define fWRAP_Y2_dczeroa(GENHLPR, SHORTCODE) SHORTCODE
+
+In other cases, just a little bit of wrapper code needs to be written.
+    #define fWRAP_tmp(SHORTCODE) \
+    { \
+        TCGv tmp = tcg_temp_new(); \
+        SHORTCODE; \
+        tcg_temp_free(tmp); \
+    }
+
+For example, some load instructions use a temporary for address computation.
+The SL2_loadrd_sp instruction needs a temporary to hold the value of the stack
+pointer (r29)
+    Instruction tag        SL2_loadrd_sp
+    Assembly syntax        "Rdd8=memd(r29+#u5:3)"
+    Instruction semantics  "{fEA_RI(fREAD_SP(),uiV); fLOAD(1,8,u,EA,RddV);}"
+
+In helper_overrides.h you'll see
+    #define fWRAP_SL2_loadrd_sp(GENHLPR, SHORTCODE)      fWRAP_tmp(SHORTCODE)
+
+There are also cases where we brute force the TCG code generation.  The
+allocframe and deallocframe instructions are examples.  Other examples are
+instructions with multiple definitions.  These require special handling
+because qemu helpers can only return a single value.
+
+In addition to instruction semantics, we use a generator to create the decode
+tree.  This generation is also a two step process.  The first step is to run
+target/hexagon/gen_dectree_import.c to produce
+    <BUILD_DIR>/hexagon-linux-user/iset.py
+This file is imported by target/hexagon/dectree.py to produce
+    <BUILD_DIR>/hexagon-linux-user/dectree_generated.h
+
+*** Key Files ***
+
+cpu.h
+
+This file contains the definition of the CPUHexagonState struct.  It is the
+runtime information for each thread and contains stuff like the GPR and
+predicate registers.
+
+macros.h
+mmvec/macros.h
+
+The Hexagon arch lib relies heavily on macros for the instruction semantics.
+This is a great advantage for qemu because we can override them for different
+purposes.  You will also notice there are sometimes two definitions of a macro.
+The QEMU_GENERATE variable determines whether we want the macro to generate TCG
+code.  If QEMU_GENERATE is not defined, we want the macro to generate vanilla
+C code that will work in the helper implementation.
+
+translate.c
+
+The functions in this file generate TCG code for a translation block.  Some
+important functions in this file are
+
+    gen_start_packet - initialize the data structures for packet semantics
+    gen_commit_packet - commit the register writes, stores, etc for a packet
+    decode_packet - disassemble a packet and generate code
+
+genptr.c
+genptr_helpers.h
+helper_overrides.h
+
+These file create a function for each instruction.  It is mostly composed of
+fWRAP_<tag> definitions followed by including qemu_def_generated.h.  The
+genptr_helpers.h file contains helper functions that are invoked by the macros
+in helper_overrides.h and macros.h
+
+op_helper.c
+
+This file contains the implementations of all the helpers.  There are a few
+general purpose helpers, but most of them are generated by including
+qemu_def_generated.h.  There are also several helpers used for debugging.
+
+
+*** Packet Semantics ***
+
+VLIW packet semantics differ from serial semantics in that all input operands
+are read, then the operations are performed, then all the results are written.
+For exmaple, this packet performs a swap of registers r0 and r1
+    { r0 = r1; r1 = r0 }
+Note that the result is different if the instructions are executed serially.
+
+Packet semantics dictate that we defer any changes of state until the entire
+packet is committed.  We record the results of each instruction in a side data
+structure, and update the visible processor state when we commit the packet.
+
+The data structures are divided between the runtime state and the translation
+context.
+
+During the TCG generation (see translate.[ch]), we use the DisasContext to
+track what needs to be done during packet commit.  Here are the relevant
+fields
+
+    ctx_reg_log            list of registers written
+    ctx_reg_log_idx        index into ctx_reg_log
+    ctx_pred_log           list of predicates written
+    ctx_pred_log_idx       index into ctx_pred_log
+    ctx_store_width        width of stores (indexed by slot)
+
+During runtime, the following fields in CPUHexagonState (see cpu.h) are used
+
+    new_value             new value of a given register
+    reg_written           boolean indicating if register was written
+    new_pred_value        new value of a predicate register
+    pred_written          boolean indicating if predicate was written
+    mem_log_stores        record of the stores (indexed by slot)
+
+For Hexagon Vector eXtensions (HVX), the following fields are used
+
+    future_VRegs
+    tmp_VRegs
+    future_ZRegs
+    ZRegs_updated
+    VRegs_updated_tmp
+    VRegs_updated
+    VRegs_select
+
+*** Debugging ***
+
+You can turn on a lot of debugging by changing the HEX_DEBUG macro to 1 in
+internal.h.  This will stream a lot of information as it generates TCG and
+executes the code.
+
+To track down nasty issues with Hexagon->TCG generation, we compare the
+execution results with actual hardware running on a Hexagon Linux target.
+Run qemu with the "-d cpu" option.  Then, we can diff the results and figure
+out where qemu and hardware behave differently.
+
+The stacks are located at different locations.  We handle this by changing
+env->stack_adjust in translate.c.  First, set this to zero and run qemu.
+Then, change env->stack_adjust to the difference between the two stack
+locations.  Then rebuild qemu and run again. That will produce a very
+clean diff.
+
+Here are some handy places to set breakpoints
+
+    At the call to gen_start_packet for a given PC (note that the line number
+        might change in the future)
+        br translate.c:602 if ctx->base.pc_next == 0xdeadbeef
+    The helper function for each instruction is named helper_<TAG>, so here's
+        an example that will set a breakpoint at the start
+        br helper_V6_vgathermh
+    If you have the HEX_DEBUG macro set, the following will be useful
+        At the start of execution of a packet for a given PC
+            br helper_debug_start_packet if env->gpr[41] == 0xdeadbeef
+        At the end of execution of a packet for a given PC
+            br helper_debug_commit_end if env->this_PC == 0xdeadbeef
+
Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH v2 3/67 Hexagon ELF Machine Definition

In reply to Taylor Simpson

Define EM_HEXAGON 164

---
 include/elf.h | 2 ++
 1 file changed, 2 insertions(+)
include/elf.h +2 -0
index 8fbfe60..d51e7d4 100644
@@ -170,6 +170,8 @@ typedef struct mips_elf_abiflags_v0 {
 
 #define EM_UNICORE32    110     /* UniCore32 */
 
+#define EM_HEXAGON     164     /* Qualcomm Hexagon */
+
 #define EM_RISCV        243     /* RISC-V */
 
 #define EM_NANOMIPS     249     /* Wave Computing nanoMIPS */
Signature · 1 line
2.7.4
#4 lore raw

RFC PATCH v2 4/67 Hexagon CPU Scalar Core Definition

In reply to Taylor Simpson

Add CPU state header, CPU definitions and initialization routines

---
 target/hexagon/cpu-param.h |  26 ++++
 target/hexagon/cpu.h       | 165 +++++++++++++++++++++++
 target/hexagon/cpu_bits.h  |  37 ++++++
 target/hexagon/internal.h  |  52 ++++++++
 target/hexagon/cpu.c       | 322 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 602 insertions(+)
 create mode 100644 target/hexagon/cpu-param.h
 create mode 100644 target/hexagon/cpu.h
 create mode 100644 target/hexagon/cpu_bits.h
 create mode 100644 target/hexagon/internal.h
 create mode 100644 target/hexagon/cpu.c
target/hexagon/cpu-param.h new file +26 -0
new file mode 100644
index 0000000..3a6b727
@@ -0,0 +1,26 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_CPU_PARAM_H
+#define HEXAGON_CPU_PARAM_H
+
+#define TARGET_PHYS_ADDR_SPACE_BITS 36
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
+#define NB_MMU_MODES 1
+
+#endif
target/hexagon/cpu.h new file +165 -0

165 lines not on this page · raw message

target/hexagon/cpu_bits.h new file +37 -0
new file mode 100644
index 0000000..3fedde7
@@ -0,0 +1,37 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_CPU_BITS_H
+#define HEXAGON_CPU_BITS_H
+
+#define HEX_EXCP_FETCH_NO_UPAGE  0x012
+#define HEX_EXCP_INVALID_PACKET  0x015
+#define HEX_EXCP_INVALID_OPCODE  0x015
+#define HEX_EXCP_PRIV_NO_UREAD   0x024
+#define HEX_EXCP_PRIV_NO_UWRITE  0x025
+
+#define HEX_EXCP_TRAP0           0x172
+#define HEX_EXCP_TRAP1           0x173
+#define HEX_EXCP_SC4             0x100
+#define HEX_EXCP_SC8             0x200
+
+#define PACKET_WORDS_MAX         4
+
+extern int disassemble_hexagon(uint32_t *words, int nwords,
+                               char *buf, int bufsize);
+
+#endif
target/hexagon/internal.h new file +52 -0

52 lines not on this page · raw message

target/hexagon/cpu.c new file +322 -0

322 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

RFC PATCH v2 5/67 Hexagon register names

In reply to Taylor Simpson
---
 target/hexagon/hex_regs.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 target/hexagon/hex_regs.h
target/hexagon/hex_regs.h new file +99 -0
new file mode 100644
index 0000000..670da1a
@@ -0,0 +1,99 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_REGS_H
+#define HEXAGON_REGS_H
+
+enum {
+    HEX_REG_R00              = 0,
+    HEX_REG_R01              = 1,
+    HEX_REG_R02              = 2,
+    HEX_REG_R03              = 3,
+    HEX_REG_R04              = 4,
+    HEX_REG_R05              = 5,
+    HEX_REG_R06              = 6,
+    HEX_REG_R07              = 7,
+    HEX_REG_R08              = 8,
+    HEX_REG_R09              = 9,
+    HEX_REG_R10              = 10,
+    HEX_REG_R11              = 11,
+    HEX_REG_R12              = 12,
+    HEX_REG_R13              = 13,
+    HEX_REG_R14              = 14,
+    HEX_REG_R15              = 15,
+    HEX_REG_R16              = 16,
+    HEX_REG_R17              = 17,
+    HEX_REG_R18              = 18,
+    HEX_REG_R19              = 19,
+    HEX_REG_R20              = 20,
+    HEX_REG_R21              = 21,
+    HEX_REG_R22              = 22,
+    HEX_REG_R23              = 23,
+    HEX_REG_R24              = 24,
+    HEX_REG_R25              = 25,
+    HEX_REG_R26              = 26,
+    HEX_REG_R27              = 27,
+    HEX_REG_R28              = 28,
+    HEX_REG_R29              = 29,
+    HEX_REG_SP               = 29,
+    HEX_REG_FP               = 30,
+    HEX_REG_R30              = 30,
+    HEX_REG_LR               = 31,
+    HEX_REG_R31              = 31,
+    HEX_REG_SA0              = 32,
+    HEX_REG_LC0              = 33,
+    HEX_REG_SA1              = 34,
+    HEX_REG_LC1              = 35,
+    HEX_REG_P3_0             = 36,
+    HEX_REG_M0               = 38,
+    HEX_REG_M1               = 39,
+    HEX_REG_USR              = 40,
+    HEX_REG_PC               = 41,
+    HEX_REG_UGP              = 42,
+    HEX_REG_GP               = 43,
+    HEX_REG_CS0              = 44,
+    HEX_REG_CS1              = 45,
+    HEX_REG_UPCYCLELO        = 46,
+    HEX_REG_UPCYCLEHI        = 47,
+    HEX_REG_FRAMELIMIT       = 48,
+    HEX_REG_FRAMEKEY         = 49,
+    HEX_REG_PKTCNTLO         = 50,
+    HEX_REG_PKTCNTHI         = 51,
+    /* Use reserved control registers for qemu execution counts */
+    HEX_REG_QEMU_PKT_CNT      = 52,
+    HEX_REG_QEMU_INSN_CNT     = 53,
+    HEX_REG_QEMU_HVX_CNT      = 54,
+    HEX_REG_UTIMERLO          = 62,
+    HEX_REG_UTIMERHI          = 63,
+
+#ifndef CONFIG_USER_ONLY
+    HEX_REG_SGP0              = 64,
+    HEX_REG_SGP1              = 65,
+    HEX_REG_STID              = 66,
+    HEX_REG_ELR               = 67,
+    HEX_REG_BADVA0            = 68,
+    HEX_REG_BADVA1            = 69,
+    HEX_REG_SSR               = 70,
+    HEX_REG_CCR               = 71,
+    HEX_REG_HTID              = 72,
+    HEX_REG_BADVA             = 73,
+    HEX_REG_IMASK             = 74,
+    HEX_REG_GEVB              = 75,
+#endif
+};
+
+#endif
Signature · 1 line
2.7.4
#6 lore raw

RFC PATCH v2 6/67 Hexagon Disassembler

In reply to Taylor Simpson

The Hexagon disassembler calls disassemble_hexagon to decode a packet and format it for printing

---
 include/disas/dis-asm.h |  1 +
 disas/hexagon.c         | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 disas/Makefile.objs     |  1 +
 3 files changed, 64 insertions(+)
 create mode 100644 disas/hexagon.c
include/disas/dis-asm.h +1 -0
index f87f468..a7fa82d 100644
@@ -436,6 +436,7 @@ int print_insn_little_nios2     (bfd_vma, disassemble_info*);
 int print_insn_xtensa           (bfd_vma, disassemble_info*);
 int print_insn_riscv32          (bfd_vma, disassemble_info*);
 int print_insn_riscv64          (bfd_vma, disassemble_info*);
+int print_insn_hexagon          (bfd_vma, disassemble_info*);
 
 #if 0
 /* Fetch the disassembler for a given BFD, if that support is available.  */
disas/hexagon.c new file +62 -0

62 lines not on this page · raw message

disas/Makefile.objs +1 -0
index 3c1cdce..0e86964 100644
@@ -24,6 +24,7 @@ common-obj-$(CONFIG_SH4_DIS) += sh4.o
 common-obj-$(CONFIG_SPARC_DIS) += sparc.o
 common-obj-$(CONFIG_LM32_DIS) += lm32.o
 common-obj-$(CONFIG_XTENSA_DIS) += xtensa.o
+common-obj-$(CONFIG_HEXAGON_DIS) += hexagon.o
 
 # TODO: As long as the TCG interpreter and its generated code depend
 # on the QEMU target, we cannot compile the disassembler here.
Signature · 1 line
2.7.4
#7 lore raw

RFC PATCH v2 7/67 Hexagon CPU Scalar Core Helpers

In reply to Taylor Simpson

The majority of helpers are generated. Define the helper functions needed then include the generated file

---
 target/hexagon/helper.h    |  37 ++++
 target/hexagon/op_helper.c | 434 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 471 insertions(+)
 create mode 100644 target/hexagon/helper.h
 create mode 100644 target/hexagon/op_helper.c
target/hexagon/helper.h new file +37 -0
new file mode 100644
index 0000000..8558da8
@@ -0,0 +1,37 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "helper_overrides.h"
+
+DEF_HELPER_2(raise_exception, noreturn, env, i32)
+DEF_HELPER_1(debug_start_packet, void, env)
+DEF_HELPER_2(new_value, s32, env, int)
+DEF_HELPER_3(debug_check_store_width, void, env, int, int)
+DEF_HELPER_3(debug_commit_end, void, env, int, int)
+DEF_HELPER_3(sfrecipa_val, s32, env, s32, s32)
+DEF_HELPER_3(sfrecipa_pred, s32, env, s32, s32)
+DEF_HELPER_2(sfinvsqrta_val, s32, env, s32)
+DEF_HELPER_2(sfinvsqrta_pred, s32, env, s32)
+DEF_HELPER_4(vacsh_val, s64, env, s64, s64, s64)
+DEF_HELPER_4(vacsh_pred, s32, env, s64, s64, s64)
+
+#define DEF_QEMU(TAG, SHORTCODE, HELPER, GENFN, HELPFN) HELPER
+#include "qemu_def_generated.h"
+#undef DEF_QEMU
+
+DEF_HELPER_2(debug_value, void, env, s32)
+DEF_HELPER_2(debug_value_i64, void, env, s64)
target/hexagon/op_helper.c new file +434 -0

434 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

RFC PATCH v2 8/67 Hexagon GDB Stub

In reply to Taylor Simpson

GDB register read and write routines

---
 target/hexagon/cpu.c     |  3 +++
 target/hexagon/gdbstub.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 target/hexagon/gdbstub.c
target/hexagon/cpu.c +3 -0
index 98d6bdc..576c566 100644
@@ -288,6 +288,9 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data)
     cc->dump_state = hexagon_dump_state;
     cc->set_pc = hexagon_cpu_set_pc;
     cc->synchronize_from_tb = hexagon_cpu_synchronize_from_tb;
+    cc->gdb_core_xml_file = "hexagon-core.xml";
+    cc->gdb_read_register = hexagon_gdb_read_register;
+    cc->gdb_write_register = hexagon_gdb_write_register;
     cc->gdb_num_core_regs = TOTAL_PER_THREAD_REGS;
     cc->gdb_stop_before_watchpoint = true;
     cc->disas_set_info = hexagon_cpu_disas_set_info;
target/hexagon/gdbstub.c new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

RFC PATCH v2 9/67 Hexagon architecture types

In reply to Taylor Simpson

Define types used in files imported from the Hexagon architecture library

---
 target/hexagon/hex_arch_types.h | 42 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 target/hexagon/hex_arch_types.h
target/hexagon/hex_arch_types.h new file +42 -0
new file mode 100644
index 0000000..bb58f49
@@ -0,0 +1,42 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_ARCH_TYPES_H
+#define HEXAGON_ARCH_TYPES_H
+
+/*
+ * These types are used by the code generated from the Hexagon
+ * architecture library.
+ */
+typedef unsigned char size1u_t;
+typedef char size1s_t;
+typedef unsigned short int size2u_t;
+typedef short size2s_t;
+typedef unsigned int size4u_t;
+typedef int size4s_t;
+typedef unsigned long long int size8u_t;
+typedef long long int size8s_t;
+typedef size8u_t paddr_t;
+typedef size4u_t vaddr_t;
+typedef size8u_t pcycles_t;
+
+typedef struct size16s {
+    size8s_t hi;
+    size8u_t lo;
+} size16s_t;
+
+#endif
Signature · 1 line
2.7.4
#10 lore raw

RFC PATCH v2 10/67 Hexagon instruction and packet types

In reply to Taylor Simpson

The insn_t and packet_t are the interface between instruction decoding and TCG code generation

---
 target/hexagon/insn.h | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
 create mode 100644 target/hexagon/insn.h
target/hexagon/insn.h new file +133 -0
new file mode 100644
index 0000000..a80bcb9
@@ -0,0 +1,133 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_INSN_H
+#define HEXAGON_INSN_H
+
+#include "cpu.h"
+#include "hex_arch_types.h"
+#include "translate.h"
+
+#define INSTRUCTIONS_MAX 7    /* 2 pairs + loopend */
+#define REG_OPERANDS_MAX 5
+#define IMMEDS_MAX 2
+
+struct Instruction;
+
+typedef void (*semantic_insn_t)(CPUHexagonState *env,
+                                DisasContext *ctx,
+                                struct Instruction *insn);
+
+struct Instruction {
+    semantic_insn_t generate;            /* pointer to genptr routine */
+    size1u_t regno[REG_OPERANDS_MAX];    /* reg operands including predicates */
+    size2u_t opcode;
+
+    size4u_t iclass:6;
+    size4u_t slot:3;
+    size4u_t part1:1;        /*
+                              * cmp-jumps are split into two insns.
+                              * set for the compare and clear for the jump
+                              */
+    size4u_t extension_valid:1;   /* Has a constant extender attached */
+    size4u_t which_extended:1;    /* If has an extender, which immediate */
+    size4u_t is_dcop:1;      /* Is a dcacheop */
+    size4u_t is_dcfetch:1;   /* Has an A_DCFETCH attribute */
+    size4u_t is_load:1;      /* Has A_LOAD attribute */
+    size4u_t is_store:1;     /* Has A_STORE attribute */
+    size4u_t is_memop:1;     /* Has A_MEMOP attribute */
+    size4u_t is_dealloc:1;   /* Is a dealloc return or dealloc frame */
+    size4u_t is_aia:1;       /* Is a post increment */
+    size4u_t is_endloop:1;   /* This is an end of loop */
+    size4u_t is_2nd_jump:1;  /* This is the second jump of a dual-jump packet */
+    size4u_t new_value_producer_slot:4;
+    size4s_t immed[IMMEDS_MAX];    /* immediate field */
+};
+
+typedef struct Instruction insn_t;
+
+struct Packet {
+    size2u_t num_insns;
+    size2u_t encod_pkt_size_in_bytes;
+
+    /* Pre-decodes about LD/ST */
+    size8u_t single_load:1;
+    size8u_t dual_load:1;
+    size8u_t single_store:1;
+    size8u_t dual_store:1;
+    size8u_t load_and_store:1;
+    size8u_t memop_or_nvstore:1;
+
+    /* Pre-decodes about COF */
+    size8u_t pkt_has_cof:1;          /* Has any change-of-flow */
+    size8u_t pkt_has_dual_jump:1;
+    size8u_t pkt_has_initloop:1;
+    size8u_t pkt_has_initloop0:1;
+    size8u_t pkt_has_initloop1:1;
+    size8u_t pkt_has_endloop:1;
+    size8u_t pkt_has_endloop0:1;
+    size8u_t pkt_has_endloop1:1;
+    size8u_t pkt_has_endloop01:1;
+    size8u_t pkt_has_call:1;
+    size8u_t pkt_has_jumpr:1;
+    size8u_t pkt_has_cjump:1;
+    size8u_t pkt_has_cjump_dotnew:1;
+    size8u_t pkt_has_cjump_dotold:1;
+    size8u_t pkt_has_cjump_newval:1;
+    size8u_t pkt_has_duplex:1;
+    size8u_t pkt_has_payload:1;      /* Contains a constant extender */
+    size8u_t pkt_has_dealloc_return:1;
+
+    /* Pre-decodes about SLOTS */
+    size8u_t slot0_valid:1;
+    size8u_t slot1_valid:1;
+    size8u_t slot2_valid:1;
+    size8u_t slot3_valid:1;
+
+    /* When a predicate cancels something, track that */
+    size8u_t pkt_has_fp_op:1;
+    size8u_t pkt_has_fpsp_op:1;
+    size8u_t pkt_has_fpdp_op:1;
+
+    /* Contains a cacheop */
+    size8u_t pkt_has_cacheop:1;
+    size8u_t pkt_has_dczeroa:1;
+    size8u_t pkt_has_ictagop:1;
+    size8u_t pkt_has_icflushop:1;
+    size8u_t pkt_has_dcflushop:1;
+    size8u_t pkt_has_dctagop:1;
+    size8u_t pkt_has_l2flushop:1;
+    size8u_t pkt_has_l2tagop:1;
+
+    /* load store for slots */
+    size8u_t pkt_has_load_s0:1;
+    size8u_t pkt_has_load_s1:1;
+    size8u_t pkt_has_store_s0:1;
+    size8u_t pkt_has_store_s1:1;
+
+    /* Misc */
+    size8u_t num_rops:4;            /* Num risc ops in the packet */
+    size8u_t pkt_access_count:2;    /* Is a vmem access going to VTCM */
+    size8u_t pkt_ldaccess_l2:2;     /* vmem ld access to l2 */
+    size8u_t pkt_ldaccess_vtcm:2;   /* vmem ld access to vtcm */
+
+    insn_t insn[INSTRUCTIONS_MAX];
+};
+
+typedef struct Packet packet_t;
+
+#endif
Signature · 1 line
2.7.4
#11 lore raw

RFC PATCH v2 11/67 Hexagon register fields

In reply to Taylor Simpson

Declare bitfields within registers such as user status register (USR)

---
 target/hexagon/reg_fields.h     |  40 +++++++++++++++
 target/hexagon/reg_fields_def.h | 109 ++++++++++++++++++++++++++++++++++++++++
 target/hexagon/reg_fields.c     |  28 +++++++++++
 3 files changed, 177 insertions(+)
 create mode 100644 target/hexagon/reg_fields.h
 create mode 100644 target/hexagon/reg_fields_def.h
 create mode 100644 target/hexagon/reg_fields.c
target/hexagon/reg_fields.h new file +40 -0
new file mode 100644
index 0000000..cf168f0
@@ -0,0 +1,40 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_REG_FIELDS_H
+#define HEXAGON_REG_FIELDS_H
+
+#define NUM_GEN_REGS 32
+
+typedef struct {
+    const char *name;
+    int offset;
+    int width;
+    const char *description;
+} reg_field_t;
+
+extern reg_field_t reg_field_info[];
+
+enum reg_fields_enum {
+#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \
+    TAG,
+#include "reg_fields_def.h"
+    NUM_REG_FIELDS
+#undef DEF_REG_FIELD
+};
+
+#endif
target/hexagon/reg_fields_def.h new file +109 -0

109 lines not on this page · raw message

target/hexagon/reg_fields.c new file +28 -0
new file mode 100644
index 0000000..2a3e4f5a
@@ -0,0 +1,28 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "reg_fields.h"
+
+reg_field_t reg_field_info[] = {
+#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION)    \
+      {NAME, START, WIDTH, DESCRIPTION},
+#include "reg_fields_def.h"
+      {NULL, 0, 0}
+#undef DEF_REG_FIELD
+};
+
Signature · 1 line
2.7.4
#12 lore raw

RFC PATCH v2 12/67 Hexagon instruction attributes

In reply to Taylor Simpson
---
 target/hexagon/attribs.h     |  32 ++++
 target/hexagon/attribs_def.h | 404 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 436 insertions(+)
 create mode 100644 target/hexagon/attribs.h
 create mode 100644 target/hexagon/attribs_def.h
target/hexagon/attribs.h new file +32 -0
new file mode 100644
index 0000000..d35af0c
@@ -0,0 +1,32 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_ATTRIBS_H
+#define HEXAGON_ATTRIBS_H
+
+enum {
+#define DEF_ATTRIB(NAME, ...) A_##NAME,
+#include "attribs_def.h"
+#undef DEF_ATTRIB
+};
+
+#define ATTRIB_WIDTH 32
+#define GET_ATTRIB(opcode, attrib) \
+    (((opcode_attribs[opcode][attrib / ATTRIB_WIDTH])\
+    >> (attrib % ATTRIB_WIDTH)) & 0x1)
+
+#endif /* ATTRIBS_H */
target/hexagon/attribs_def.h new file +404 -0

404 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw

RFC PATCH v2 13/67 Hexagon register map

In reply to Taylor Simpson

Certain operand types represent a non-contiguous set of values. For example, the compound compare-and-jump instruction can only access registers R0-R7 and R16-23.
This table represents the mapping from the encoding to the actual values.

---
 target/hexagon/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 target/hexagon/regmap.h
target/hexagon/regmap.h new file +38 -0
new file mode 100644
index 0000000..2bcc0de
@@ -0,0 +1,38 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ *  Certain operand types represent a non-contiguous set of values.
+ *  For example, the compound compare-and-jump instruction can only access
+ *  registers R0-R7 and R16-23.
+ *  This table represents the mapping from the encoding to the actual values.
+ */
+
+#ifndef HEXAGON_REGMAP_H
+#define HEXAGON_REGMAP_H
+
+        /* Name   Num Table */
+DEF_REGMAP(R_16,  16, 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23)
+DEF_REGMAP(R__8,  8,  0, 2, 4, 6, 16, 18, 20, 22)
+DEF_REGMAP(R__4,  4,  0, 2, 4, 6)
+DEF_REGMAP(R_4,   4,  0, 1, 2, 3)
+DEF_REGMAP(R_8S,  8,  0, 1, 2, 3, 16, 17, 18, 19)
+DEF_REGMAP(R_8,   8,  0, 1, 2, 3, 4, 5, 6, 7)
+DEF_REGMAP(V__8,  8,  0, 4, 8, 12, 16, 20, 24, 28)
+DEF_REGMAP(V__16, 16, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30)
+
+#endif
Signature · 1 line
2.7.4
#14 lore raw

RFC PATCH v2 14/67 Hexagon instruction/packet decode

In reply to Taylor Simpson

Take the words from instruction memory and build a packet_t for TCG code generation

The following operations are performed
Convert the .new encoded offset to the register number of the producer Reorder the instructions in the packet so .new producer is before consumer Apply constant extenders
Separate subinsn's into two instructions
Break compare-jumps into two instructions
Create instructions for :endloop

---
 target/hexagon/decode.h     |  39 +++
 target/hexagon/decode.c     | 769 ++++++++++++++++++++++++++++++++++++++++++++
 target/hexagon/q6v_decode.c | 402 +++++++++++++++++++++++
 3 files changed, 1210 insertions(+)
 create mode 100644 target/hexagon/decode.h
 create mode 100644 target/hexagon/decode.c
 create mode 100644 target/hexagon/q6v_decode.c
target/hexagon/decode.h new file +39 -0
new file mode 100644
index 0000000..7f63b1c
@@ -0,0 +1,39 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_DECODE_H
+#define HEXAGON_DECODE_H
+
+#include "cpu.h"
+#include "opcodes.h"
+#include "hex_arch_types.h"
+#include "insn.h"
+
+extern void decode_init(void);
+
+static inline int is_packet_end(uint32_t word)
+{
+    uint32_t bits = (word >> 14) & 0x3;
+    return ((bits == 0x3) || (bits == 0x0));
+}
+
+extern void decode_send_insn_to(packet_t *packet, int start, int newloc);
+
+extern packet_t *decode_this(int max_words, size4u_t *words,
+                             packet_t *decode_pkt);
+
+#endif
target/hexagon/decode.c new file +769 -0

769 lines not on this page · raw message

target/hexagon/q6v_decode.c new file +402 -0

402 lines not on this page · raw message

Signature · 1 line
2.7.4
#15 lore raw

RFC PATCH v2 15/67 Hexagon instruction printing

In reply to Taylor Simpson
---
 target/hexagon/printinsn.h | 26 +++++++++++++
 target/hexagon/printinsn.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/printinsn.c
target/hexagon/printinsn.h new file +26 -0
new file mode 100644
index 0000000..264b63c
@@ -0,0 +1,26 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_PRINTINSN_H
+#define HEXAGON_PRINTINSN_H
+
+#include "qemu/osdep.h"
+#include "insn.h"
+
+extern void snprint_a_pkt(char *buf, int n, packet_t *pkt);
+
+#endif
target/hexagon/printinsn.c new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.7.4
#16 lore raw

RFC PATCH v2 16/67 Hexagon arch import - instruction semantics definitions

In reply to Taylor Simpson

Imported from the Hexagon architecture library
imported/allidefs.def Top level instruction definition file
imported/*.idef Instruction definition files
These files are input to the first phase of the generator (gen_semantics.c) to create a python include file with the instruction semantics and attributes. The python include file is fed to the second phase (do_qemu.py).

---
 target/hexagon/imported/allidefs.def  |   91 +++
 target/hexagon/imported/alu.idef      | 1335 +++++++++++++++++++++++++++++++++
 target/hexagon/imported/branch.idef   |  344 +++++++++
 target/hexagon/imported/compare.idef  |  639 ++++++++++++++++
 target/hexagon/imported/float.idef    |  498 ++++++++++++
 target/hexagon/imported/ldst.idef     |  421 +++++++++++
 target/hexagon/imported/mpy.idef      | 1269 +++++++++++++++++++++++++++++++
 target/hexagon/imported/shift.idef    | 1211 ++++++++++++++++++++++++++++++
 target/hexagon/imported/subinsns.idef |  152 ++++
 target/hexagon/imported/system.idef   |  302 ++++++++
 10 files changed, 6262 insertions(+)
 create mode 100644 target/hexagon/imported/allidefs.def
 create mode 100644 target/hexagon/imported/alu.idef
 create mode 100644 target/hexagon/imported/branch.idef
 create mode 100644 target/hexagon/imported/compare.idef
 create mode 100644 target/hexagon/imported/float.idef
 create mode 100644 target/hexagon/imported/ldst.idef
 create mode 100644 target/hexagon/imported/mpy.idef
 create mode 100644 target/hexagon/imported/shift.idef
 create mode 100644 target/hexagon/imported/subinsns.idef
 create mode 100644 target/hexagon/imported/system.idef
target/hexagon/imported/allidefs.def new file +91 -0
new file mode 100644
index 0000000..d2f13a2
@@ -0,0 +1,91 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Top level instruction definition file
+ */
+
+#define DEF_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING), \
+		"Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \
+        Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING), \
+		"Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \
+		fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB))
+
+#define DEF_V2_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV2), \
+		"Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_V2_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \
+        Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV2), \
+		"Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \
+		fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB))
+
+#define DEF_V3_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV3), \
+		"Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_V3_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \
+        Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV3), \
+		"Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \
+		fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB))
+
+#define DEF_V4_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV4), \
+		"Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_V4_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \
+        Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV4), \
+		"Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \
+		fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB))
+
+#define DEF_V5_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV5), \
+		"Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_V5_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \
+        Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV5), \
+		"Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \
+		fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB))
+
+#define DEF_VECX_MAPPING(TAG,FROMSYN,TOSYN) \
+	EXTINSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_VECX), \
+		"VECX Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+#define DEF_CVI_MAPPING(TAG,FROMSYN,TOSYN) \
+	Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CVI), \
+		"CVI Mapping from " FROMSYN " to " TOSYN, \
+		fASM_MAP(FROMSYN,TOSYN))
+
+
+#include "branch.idef"
+#include "ldst.idef"
+#include "compare.idef"
+#include "mpy.idef"
+#include "alu.idef"
+#include "float.idef"
+#include "shift.idef"
+#include "system.idef"
+#include "subinsns.idef"
target/hexagon/imported/alu.idef new file +1335 -0

1,335 lines not on this page · raw message

target/hexagon/imported/branch.idef new file +344 -0

344 lines not on this page · raw message

target/hexagon/imported/compare.idef new file +639 -0

639 lines not on this page · raw message

target/hexagon/imported/float.idef new file +498 -0

498 lines not on this page · raw message

target/hexagon/imported/ldst.idef new file +421 -0

93 lines not on this page · raw message

target/hexagon/imported/mpy.idef new file +1269 -0

1,269 lines not on this page · raw message

target/hexagon/imported/shift.idef new file +1211 -0

1,211 lines not on this page · raw message

target/hexagon/imported/subinsns.idef new file +152 -0

152 lines not on this page · raw message

target/hexagon/imported/system.idef new file +302 -0

302 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.7.4

Part of the diff is not shown here. View the raw message.

#17 lore raw

RFC PATCH v2 17/67 Hexagon arch import - macro definitions

In reply to Taylor Simpson

Imported from the Hexagon architecture library
imported/macros.def Scalar core macro definitions
The macro definition files specify instruction attributes that are applied to each instruction that reverences the macro.

---
 target/hexagon/imported/macros.def | 3970 ++++++++++++++++++++++++++++++++++++
 1 file changed, 3970 insertions(+)
 create mode 100755 target/hexagon/imported/macros.def
target/hexagon/imported/macros.def new file +3970 -0
new file mode 100755
index 0000000..ace0432
@@ -0,0 +1,3970 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+DEF_MACRO(
+	LIKELY,		/* NAME */
+	(X),		/* PARAMS */
+	"X",		/* sdescr */
+	"X",		/* ldescr */
+	__builtin_expect((X),1), /* BEH */
+	()		/* attribs */
+)
+
+DEF_MACRO(
+	UNLIKELY,	/* NAME */
+	(X),		/* PARAMS */
+	"X",		/* sdescr */
+	"X",		/* ldescr */
+	__builtin_expect((X),0), /* BEH */
+	()		/* attribs */
+)
+
+DEF_MACRO(
+	CANCEL, /* macro name */
+	, /* parameters */
+	"NOP", /* short description */
+	"NOP this instruction", /* long description */
+	{if (thread->last_pkt) thread->last_pkt->slot_cancelled |= (1<<insn->slot); return;} , /* behavior */
+	(A_CONDEXEC)
+)
+
+DEF_MACRO(
+	STORE_ZERO, /* macro name */
+	, /* parameters */
+	"Zero Store", /* short description */
+	"NOP this instruction", /* long description */
+	{if (thread->last_pkt) thread->last_pkt->slot_zero_byte_store |= (1<<insn->slot); } , /* behavior */
+	(A_CONDEXEC)
+)
+
+DEF_MACRO(
+	LOAD_CANCEL, /* macro name */
+	(EA), /* parameters */
+	"NOP", /* short description */
+	"NOP this instruction", /* long description */
+	{mem_general_load_cancelled(thread,EA,insn);CANCEL;} , /* behavior */
+	(A_CONDEXEC)
+)
+
+DEF_MACRO(
+	STORE_CANCEL, /* macro name */
+	(EA), /* parameters */
+	"NOP", /* short description */
+	"NOP this instruction", /* long description */
+	{mem_general_store_cancelled(thread,EA,insn);CANCEL;} , /* behavior */
+	(A_CONDEXEC)
+)
+
+DEF_MACRO(
+	IS_CANCELLED, /* macro name */
+	(SLOT), /* parameters */
+	"", /* short description */
+	"", /* long description */
+	((thread->last_pkt->slot_cancelled >> SLOT)&1) , /* behavior */
+	/* attrib */
+)
+
+DEF_MACRO(
+	fMAX, /* macro name */
+	(A,B), /* parameters */
+	"max(A,B)", /* short description */
+	"the larger of A and B", /* long description */
+	(((A) > (B)) ? (A) : (B)), /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fMIN, /* macro name */
+	(A,B), /* parameters */
+	"min(A,B)", /* short description */
+	"the smaller of A and B", /* long description */
+	(((A) < (B)) ? (A) : (B)), /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fABS, /* macro name */
+	(A), /* parameters */
+	"ABS(A)", /* short description */
+	"if A is less than zero then A=-A", /* long description */
+	(((A)<0)?(-(A)):(A)), /* behavior */
+	/* optional attributes */
+)
+
+
+/* Bit insert */
+DEF_MACRO(
+	fINSERT_BITS,(REG,WIDTH,OFFSET,INVAL),
+	"REG[(WIDTH-1+OFFSET):OFFSET]=INVAL",
+	"REG[(WIDTH-1+OFFSET):OFFSET]=INVAL",
+        {
+	   REG = ((REG) & ~(((fCONSTLL(1)<<(WIDTH))-1)<<(OFFSET))) | (((INVAL) & ((fCONSTLL(1)<<(WIDTH))-1)) << (OFFSET));
+        },
+	/* attribs */
+)
+
+/* Bit extract */
+DEF_MACRO(
+	fEXTRACTU_BITS,(INREG,WIDTH,OFFSET),
+	"INREG[(WIDTH+OFFSET-1):OFFSET]",
+	"INREG[(WIDTH+OFFSET-1):OFFSET]",
+	(fZXTN(WIDTH,32,(INREG >> OFFSET))),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fEXTRACTU_BIDIR,(INREG,WIDTH,OFFSET),
+	"INREG[(WIDTH+OFFSET-1):OFFSET]",
+	"INREG[(WIDTH+OFFSET-1):OFFSET]",
+	(fZXTN(WIDTH,32,fBIDIR_LSHIFTR((INREG),(OFFSET),4_8))),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fEXTRACTU_RANGE,(INREG,HIBIT,LOWBIT),
+	"INREG[HIBIT:LOWBIT]",
+	"INREG[HIBIT:LOWBIT]",
+	(fZXTN((HIBIT-LOWBIT+1),32,(INREG >> LOWBIT))),
+	/* attribs */
+)
+
+
+DEF_MACRO(
+	fINSERT_RANGE,(INREG,HIBIT,LOWBIT,INVAL),
+	"INREG[HIBIT:LOWBIT]=INVAL",
+	"INREG[HIBIT:LOWBIT]=INVAL",
+        {
+          int offset=LOWBIT;
+          int width=HIBIT-LOWBIT+1;
+  	  /* clear bits where new bits go */
+	  INREG &= ~(((fCONSTLL(1)<<width)-1)<<offset);
+	  /* OR in new bits */
+	  INREG |= ((INVAL & ((fCONSTLL(1)<<width)-1)) << offset);
+        },
+	/* attribs */
+)
+
+
+DEF_MACRO(
+	f8BITSOF,(VAL),
+	"VAL ? 0xff : 0x00",
+	"VAL ? 0xff : 0x00",
+	( (VAL) ? 0xff : 0x00),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fLSBOLD,(VAL),
+	"VAL[0]",
+	"Least significant bit of VAL",
+	((VAL) & 1),
+	(A_DOTOLD)
+)
+
+DEF_MACRO(
+	fLSBNEW,(PNUM),
+	"PNUM.new[0]",
+	"Least significant bit of new PNUM",
+	predlog_read(thread,PNUM),
+	(A_DOTNEW)
+)
+
+DEF_MACRO(
+	fLSBNEW0,,
+	"P0.new[0]",
+	"Least significant bit of new P0",
+	predlog_read(thread,0),
+	(A_DOTNEW,A_IMPLICIT_READS_P0)
+)
+
+DEF_MACRO(
+	fLSBNEW1,,
+	"P1.new[0]",
+	"Least significant bit of new P1",
+	predlog_read(thread,1),
+	(A_DOTNEW,A_IMPLICIT_READS_P1)
+)
+
+DEF_MACRO(
+	fLSBOLDNOT,(VAL),
+	"!VAL[0]",
+	"!Least significant bit of VAL",
+	(!fLSBOLD(VAL)),
+	(A_DOTOLD,A_INVPRED)
+)
+
+DEF_MACRO(
+	fLSBNEWNOT,(PNUM),
+	"!PNUM.new[0]",
+	"!Least significant bit of new PNUM",
+	(!fLSBNEW(PNUM)),
+	(A_DOTNEW,A_INVPRED)
+)
+
+DEF_MACRO(
+	fLSBNEW0NOT,,
+	"!P0.new[0]",
+	"!Least significant bit of new P0",
+	(!fLSBNEW0),
+	(A_DOTNEW,A_INVPRED,A_IMPLICIT_READS_P0)
+)
+
+DEF_MACRO(
+	fLSBNEW1NOT,,
+	"P1.new[0]",
+	"Least significant bit of new P1",
+	(!fLSBNEW1),
+	(A_DOTNEW,A_INVPRED,A_IMPLICIT_READS_P1)
+)
+
+DEF_MACRO(
+	fNEWREG,(RNUM),
+	"RNUM.new",
+	"Register value produced in this packet",
+	({if (newvalue_missing(thread,RNUM) ||
+      IS_CANCELLED(insn->new_value_producer_slot)) CANCEL; reglog_read(thread,RNUM);}),
+	(A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY)
+)
+// Store new with a missing newvalue or cancelled goes out as a zero byte store in V65
+// take advantage of the fact that reglog_read returns zero for not valid rnum
+DEF_MACRO(
+	fNEWREG_ST,(RNUM),
+	"RNUM.new",
+	"Register value produced in this packet for store",
+	({if (newvalue_missing(thread,RNUM) ||
+      IS_CANCELLED(insn->new_value_producer_slot)) { STORE_ZERO; RNUM = -1; }; reglog_read(thread,RNUM);}),
+	(A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY)
+)
+
+DEF_MACRO(
+	fMEMZNEW,(RNUM),
+	"RNUM.new == 0",
+	"Newly loaded value is zero",
+	(RNUM == 0),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fMEMNZNEW,(RNUM),
+	"RNUM.new != 0",
+	"Newly loaded value is non-zero",
+	(RNUM != 0),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fVSATUVALN,(N,VAL),
+	"N-Bit Unsigned Saturation Value for sign of VAL",
+	"N-Bit Unsigned Saturation Value for sign of VAL",
+	({ ((VAL) < 0) ? 0 : ((1LL<<(N))-1);}),
+	(A_USATURATE)
+)
+
+DEF_MACRO(
+	fSATUVALN,(N,VAL),
+	"N-Bit Unsigned Saturation Value for sign of VAL",
+	"N-Bit Unsigned Saturation Value for sign of VAL",
+	({fSET_OVERFLOW(); ((VAL) < 0) ? 0 : ((1LL<<(N))-1);}),
+	(A_USATURATE)
+)
+
+DEF_MACRO(
+	fSATVALN,(N,VAL),
+	"N-Bit Saturation Value for sign of VAL",
+	"N-Bit Saturation Value for sign of VAL",
+	({fSET_OVERFLOW(); ((VAL) < 0) ? (-(1LL<<((N)-1))) : ((1LL<<((N)-1))-1);}),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fVSATVALN,(N,VAL),
+	"N-Bit Saturation Value for sign of VAL",
+	"N-Bit Saturation Value for sign of VAL",
+	({((VAL) < 0) ? (-(1LL<<((N)-1))) : ((1LL<<((N)-1))-1);}),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fZXTN, /* macro name */
+	(N,M,VAL),
+	"zxt_{N->M}(VAL)", /* short descr */
+	"Zero extend N bits from VAL",
+	((VAL) & ((1LL<<(N))-1)),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fSXTN, /* macro name */
+	(N,M,VAL),
+	"sxt_{N->M}(VAL)", /* short descr */
+	"Sign extend N bits from VAL",
+	((fZXTN(N,M,VAL) ^ (1LL<<((N)-1))) - (1LL<<((N)-1))),
+	/* attribs */
+)
+
+DEF_MACRO(
+	fSATN,
+	(N,VAL),
+	"sat_##N(VAL)", /* short descr */
+	"Saturate VAL to N bits",
+	((fSXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATVALN(N,VAL)),
+	(A_SATURATE)
+)
+DEF_MACRO(
+	fVSATN,
+	(N,VAL),
+	"sat_##N(VAL)", /* short descr */
+	"Saturate VAL to N bits",
+	((fSXTN(N,64,VAL) == (VAL)) ? (VAL) : fVSATVALN(N,VAL)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fADDSAT64,
+	(DST,A,B),
+	"DST=sat64(A+B)", /* short descr */
+	"DST=sat64(A+B)",
+	{
+	  size8u_t __a = fCAST8u(A);
+	  size8u_t __b = fCAST8u(B);
+	  size8u_t __sum = __a + __b;
+	  size8u_t __xor = __a ^ __b;
+	  const size8u_t __mask = 0x8000000000000000ULL;
+	  if (__xor & __mask) {
+		/* Opposite signs, OK */
+		DST = __sum;
+	  } else if ((__a ^ __sum) & __mask) {
+		/* Signs mismatch */
+		if (__sum & __mask) {
+			/* overflowed to negative, make max pos */
+			DST=0x7FFFFFFFFFFFFFFFLL; fSET_OVERFLOW();
+		} else {
+			/* overflowed to positive, make max neg */
+			DST=0x8000000000000000LL; fSET_OVERFLOW();
+		}
+	  } else {
+		/* signs did not mismatch, OK */
+		DST = __sum;
+	  }
+        },
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fVSATUN,
+	(N,VAL),
+	"usat_##N(VAL)", /* short descr */
+	"Saturate VAL to N bits",
+	((fZXTN(N,64,VAL) == (VAL)) ? (VAL) : fVSATUVALN(N,VAL)),
+	(A_USATURATE)
+)
+
+DEF_MACRO(
+	fSATUN,
+	(N,VAL),
+	"usat_##N(VAL)", /* short descr */
+	"Saturate VAL to N bits",
+	((fZXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATUVALN(N,VAL)),
+	(A_USATURATE)
+)
+
+DEF_MACRO(
+	fSATH,
+	(VAL),
+	"sat_16(VAL)", /* short descr */
+	"Saturate VAL to a signed half",
+	(fSATN(16,VAL)),
+	(A_SATURATE)
+)
+
+
+DEF_MACRO(
+	fSATUH,
+	(VAL),
+	"usat_16(VAL)", /* short descr */
+	"Saturate VAL to an unsigned half",
+	(fSATUN(16,VAL)),
+	(A_USATURATE)
+)
+
+DEF_MACRO(
+	fVSATH,
+	(VAL),
+	"sat_16(VAL)", /* short descr */
+	"Saturate VAL to a signed half",
+	(fVSATN(16,VAL)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fVSATUH,
+	(VAL),
+	"usat_16(VAL)", /* short descr */
+	"Saturate VAL to a signed half",
+	(fVSATUN(16,VAL)),
+	(A_USATURATE)
+)
+
+
+DEF_MACRO(
+	fSATUB,
+	(VAL),
+	"usat_8(VAL)", /* short descr */
+	"Saturate VAL to an unsigned byte",
+	(fSATUN(8,VAL)),
+	(A_USATURATE)
+)
+DEF_MACRO(
+	fSATB,
+	(VAL),
+	"sat_8(VAL)", /* short descr */
+	"Saturate VAL to a signed byte",
+	(fSATN(8,VAL)),
+	(A_SATURATE)
+)
+
+
+DEF_MACRO(
+	fVSATUB,
+	(VAL),
+	"usat_8(VAL)", /* short descr */
+	"Saturate VAL to a unsigned byte",
+	(fVSATUN(8,VAL)),
+	(A_USATURATE)
+)
+DEF_MACRO(
+	fVSATB,
+	(VAL),
+	"sat_8(VAL)", /* short descr */
+	"Saturate VAL to a signed byte",
+	(fVSATN(8,VAL)),
+	(A_SATURATE)
+)
+
+
+
+
+/*************************************/
+/* immediate extension               */
+/*************************************/
+
+DEF_MACRO(
+	fIMMEXT,
+	(IMM),
+	"apply_extension(IMM)",
+	"Apply extension to IMM",
+	(IMM = IMM /* (insn->extension_valid?(fGET_EXTENSION | fZXTN(6,32,(IMM))):(IMM)) */ ),
+	(A_EXTENDABLE)
+)
+
+DEF_MACRO(
+	fMUST_IMMEXT,
+	(IMM),
+	"apply_extension(IMM)",
+	"Apply extension to IMM",
+	fIMMEXT(IMM),
+	(A_EXTENDABLE,A_MUST_EXTEND)
+)
+
+DEF_MACRO(
+	fPCALIGN,
+	(IMM),
+	"IMM=IMM & ~PCALIGN_MASK",
+	"",
+	IMM=(IMM & ~PCALIGN_MASK),
+	(A_EXTENDABLE)
+)
+
+DEF_MACRO(
+	fGET_EXTENSION,
+	,
+	"extension",
+	"extension",
+	insn->extension,
+	/* attrs */
+)
+
+/*************************************/
+/* Read and Write Implicit Regs      */
+/*************************************/
+
+DEF_MACRO(
+	fREAD_IREG, /* read link register */
+	(VAL), /* parameters */
+	"I", /* short description */
+	"I", /* long description */
+	(fSXTN(11,64,(((VAL) & 0xf0000000)>>21) | ((VAL>>17)&0x7f) )),          /* behavior */
+	()
+)
+
+
+DEF_MACRO(
+	fREAD_R0, /* read r0 */
+	(), /* parameters */
+	"R0", /* short description */
+	"R0", /* long description */
+	(READ_RREG(0)),          /* behavior */
+	(A_IMPLICIT_READS_R00)
+)
+
+DEF_MACRO(
+	fREAD_LR, /* read link register */
+	(), /* parameters */
+	"LR", /* short description */
+	"LR", /* long description */
+	(READ_RREG(REG_LR)),          /* behavior */
+	(A_IMPLICIT_READS_LR)
+)
+
+DEF_MACRO(
+	fREAD_SSR, /* read link register */
+	(), /* parameters */
+	"SSR", /* short description */
+	"SSR", /* long description */
+	(READ_RREG(REG_SSR)),          /* behavior */
+	()
+)
+
+DEF_MACRO(
+	fWRITE_R0, /* write r0 */
+	(A), /* parameters */
+	"R0=A", /* short description */
+	"R0=A", /* long description */
+	WRITE_RREG(0,A),          /* behavior */
+	(A_IMPLICIT_WRITES_R00)
+)
+
+DEF_MACRO(
+	fWRITE_LR, /* write lr */
+	(A), /* parameters */
+	"LR=A", /* short description */
+	"LR=A", /* long description */
+	WRITE_RREG(REG_LR,A),          /* behavior */
+	(A_IMPLICIT_WRITES_LR)
+)
+
+DEF_MACRO(
+	fWRITE_FP, /* write sp */
+	(A), /* parameters */
+	"FP=A", /* short description */
+	"FP=A", /* long description */
+	WRITE_RREG(REG_FP,A),          /* behavior */
+	(A_IMPLICIT_WRITES_FP)
+)
+
+DEF_MACRO(
+	fWRITE_SP, /* write sp */
+	(A), /* parameters */
+	"SP=A", /* short description */
+	"SP=A", /* long description */
+        WRITE_RREG(REG_SP,A),          /* behavior */
+	(A_IMPLICIT_WRITES_SP)
+)
+
+DEF_MACRO(
+	fWRITE_GOSP, /* write gosp */
+	(A), /* parameters */
+	"GOSP=A", /* short description */
+	"GOSP=A", /* long description */
+        WRITE_RREG(REG_GOSP,A),          /* behavior */
+	(A_IMPLICIT_WRITES_GOSP)
+)
+
+DEF_MACRO(
+	fWRITE_GP, /* write gp */
+	(A), /* parameters */
+	"GP=A", /* short description */
+	"GP=A", /* long description */
+	WRITE_RREG(REG_GP,A),          /* behavior */
+	(A_IMPLICIT_WRITES_GP)
+)
+
+DEF_MACRO(
+	fREAD_SP, /* read stack pointer */
+	(), /* parameters */
+	"SP", /* short description */
+	"SP", /* long description */
+	(READ_RREG(REG_SP)),          /* behavior */
+	(A_IMPLICIT_READS_SP)
+)
+
+DEF_MACRO(
+	fREAD_GOSP, /* read guest other stack pointer */
+	(), /* parameters */
+	"GOSP", /* short description */
+	"GOSP", /* long description */
+	(READ_RREG(REG_GOSP)),          /* behavior */
+	(A_IMPLICIT_READS_GOSP)
+)
+
+DEF_MACRO(
+	fREAD_GELR, /* read guest other stack pointer */
+	(), /* parameters */
+	"GELR", /* short description */
+	"GELR", /* long description */
+	(READ_RREG(REG_GELR)),          /* behavior */
+	(A_IMPLICIT_READS_GELR)
+)
+
+DEF_MACRO(
+	fREAD_GEVB, /* read guest other stack pointer */
+	(), /* parameters */
+	"GEVB", /* short description */
+	"GEVB", /* long description */
+	(READ_RREG(REG_GEVB)),          /* behavior */
+	(A_IMPLICIT_READS_GEVB)
+)
+
+DEF_MACRO(
+	fREAD_CSREG, /* read stack pointer */
+	(N), /* parameters */
+	"CS N", /* short description */
+	"CS N", /* long description */
+	(READ_RREG(REG_CSA+N)),          /* behavior */
+	(A_IMPLICIT_READS_CS)
+)
+
+DEF_MACRO(
+	fREAD_LC0, /* read loop count */
+	, /* parameters */
+	"LC0", /* short description */
+	"LC0", /* long description */
+	(READ_RREG(REG_LC0)),          /* behavior */
+	(A_IMPLICIT_READS_LC0)
+)
+
+DEF_MACRO(
+	fREAD_LC1, /* read loop count */
+	, /* parameters */
+	"LC1", /* short description */
+	"LC1", /* long description */
+	(READ_RREG(REG_LC1)),          /* behavior */
+	(A_IMPLICIT_READS_LC1)
+)
+
+DEF_MACRO(
+	fREAD_SA0, /* read start addr */
+	, /* parameters */
+	"SA0", /* short description */
+	"SA0", /* long description */
+	(READ_RREG(REG_SA0)),          /* behavior */
+	(A_IMPLICIT_READS_SA0)
+)
+
+DEF_MACRO(
+	fREAD_SA1, /* read start addr */
+	, /* parameters */
+	"SA1", /* short description */
+	"SA1", /* long description */
+	(READ_RREG(REG_SA1)),          /* behavior */
+	(A_IMPLICIT_READS_SA1)
+)
+
+
+DEF_MACRO(
+	fREAD_FP, /* read stack pointer */
+	(), /* parameters */
+	"FP", /* short description */
+	"FP", /* long description */
+	(READ_RREG(REG_FP)),          /* behavior */
+	(A_IMPLICIT_READS_FP)
+)
+
+DEF_MACRO(
+	fREAD_GP, /* read global pointer */
+	(), /* parameters */
+	"(Constant_extended ? (0) : GP)", /* short description */
+	"(Constant_extended ? (0) : GP)", /* long description */
+	(insn->extension_valid ? 0 : READ_RREG(REG_GP)),          /* behavior */
+	(A_IMPLICIT_READS_GP)
+)
+
+DEF_MACRO(
+	fREAD_PC, /* read PC */
+	(), /* parameters */
+	"PC", /* short description */
+	"PC", /* long description */
+	(READ_RREG(REG_PC)),          /* behavior */
+	(A_IMPLICIT_READS_PC)
+)
+
+DEF_MACRO(
+	fREAD_NPC, /* read PC */
+	(), /* parameters */
+	"NPC", /* short description */
+	"NPC", /* long description */
+	(thread->next_PC & (0xfffffffe)),          /* behavior */
+	()
+)
+
+DEF_MACRO(
+	fREAD_P0, /* read Predicate 0 */
+	(), /* parameters */
+	"P0", /* short description */
+	"P0", /* long description */
+	(READ_PREG(0)),          /* behavior */
+	(A_IMPLICIT_READS_P0)
+)
+
+DEF_MACRO(
+	fREAD_P3, /* read Predicate 0 */
+	(), /* parameters */
+	"P3", /* short description */
+	"P3", /* long description */
+	(READ_PREG(3)),          /* behavior */
+	(A_IMPLICIT_READS_P3)
+)
+
+DEF_MACRO(
+	fNOATTRIB_READ_P3, /* read Predicate 0 */
+	(), /* parameters */
+	"P3", /* short description */
+	"P3", /* long description */
+	(READ_PREG(3)),          /* behavior */
+	()
+)
+
+DEF_MACRO(
+	fINVALID,(),
+	"Invalid instruction!",
+	"Invalid instruction!",
+	(register_error_exception(thread,PRECISE_CAUSE_INVALID_PACKET,thread->Regs[REG_BADVA0],thread->Regs[REG_BADVA1],GET_SSR_FIELD(SSR_BVS),GET_SSR_FIELD(SSR_V0),GET_SSR_FIELD(SSR_V1),0)),
+	()
+)
+
+DEF_MACRO(
+	fCHECK_PCALIGN, (A),
+	"",
+	"",
+	/* EJP: if exception already detected, do not trigger pc unaligned exception since we will be rewinding PC anyway. */
+	/* Maybe this will screw up prioritization logic... but probably it is ok?  Otherwise we can ditch out of dealloc_return early if EXCEPTION_DETECTED */
+	if (((A) & PCALIGN_MASK)) {
+		register_error_exception(thread,PRECISE_CAUSE_PC_NOT_ALIGNED,thread->Regs[REG_BADVA0],thread->Regs[REG_BADVA1],GET_SSR_FIELD(SSR_BVS),GET_SSR_FIELD(SSR_V0),GET_SSR_FIELD(SSR_V1),0);
+	},
+	()
+)
+
+DEF_MACRO(
+	fCUREXT,(),
+	"",
+	"",
+	GET_SSR_FIELD(SSR_XA),
+	()
+)
+
+DEF_MACRO(
+	fCUREXT_WRAP,(EXT_NO),
+	"",
+	"",
+	{
+		EXT_NO = fCUREXT();
+		if (thread->processor_ptr->arch_proc_options->ext_contexts)
+			EXT_NO &= (thread->processor_ptr->arch_proc_options->ext_contexts-1);
+		else
+			EXT_NO = 0;
+		EXT_NO = thread->processor_ptr->features->QDSP6_CP_PRESENT ? (EXT_NO & 0x3) : (EXT_NO+4);
+	},
+	()
+)
+
+DEF_MACRO(
+	fWRITE_NPC, /* write next PC */
+	(A), /* parameters */
+	"PC=A", /* short description */
+	"PC=A", /* long description */
+	if (!thread->branch_taken) {
+           if (A != thread->next_PC) {
+             thread->next_pkt_guess=thread->last_pkt->taken_ptr;
+           }
+	   fCHECK_PCALIGN(A);
+           thread->branched = 1; thread->branch_taken = 1; thread->next_PC = A; \
+           thread->branch_offset = insn->encoding_offset; thread->branch_opcode = insn->opcode;
+        }
+         ,          /* behavior */
+	(A_IMPLICIT_WRITES_PC,A_COF)
+)
+
+
+DEF_MACRO(
+	fLOOPSTATS,
+	(A),
+	"",
+	"",
+	/* INC_TSTAT(tloopends);
+  	   INC_TSTATN(tloopend_same_line,(thread->Regs[REG_PC] & -32) == ((A) & -32));
+	   INC_TSTATN(tloopend_samepc,(thread->Regs[REG_PC]) == (A));*/ ,
+	()
+)
+
+
+DEF_MACRO(
+	fCOF_CALLBACK,
+	(LOC,TYPE),
+	"",
+	"",
+  {
+    thread->cof_log_to_va = (LOC);
+    thread->cof_log_coftype = (TYPE);
+    thread->cof_log_valid = 1;
+  },
+	()
+)
+
+DEF_MACRO(
+	fBRANCH,
+	(LOC,TYPE),
+	"PC=LOC",
+	"PC=LOC",
+	fWRITE_NPC(LOC); fCOF_CALLBACK(LOC,TYPE),
+	()
+)
+
+DEF_MACRO(
+	fTIME_JUMPR,
+	(REGNO,TARGET,TYPE),
+	"",
+	"",
+	{ sys_branch_return(thread, insn->slot, TARGET, REGNO); },
+	(A_INDIRECT)
+)
+
+
+DEF_MACRO(
+	fJUMPR,	/* A jumpr has executed */
+	(REGNO,TARGET,TYPE),
+	"PC=TARGET",
+	"PC=TARGET",
+	{ fTIME_JUMPR(REGNO,TARGET,TYPE); fBRANCH(TARGET,COF_TYPE_JUMPR);},
+	(A_INDIRECT)
+)
+
+DEF_MACRO(
+	fHINTJR,	/* A hintjr instruction has executed */
+	(TARGET),
+	"",
+	"",
+	{ },
+)
+
+DEF_MACRO(
+	fBP_RAS_CALL,
+	(A),
+	"",
+	"",
+	{ sys_branch_call(thread, insn->slot, A, fREAD_NPC()); },
+)
+
+DEF_MACRO(
+	fCALL,	/* Do a call */
+	(A),
+	"fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);",
+	"fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);",
+	if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALL);},
+	(A_IMPLICIT_WRITES_PC,A_COF,A_IMPLICIT_WRITES_LR,A_CALL)
+)
+
+DEF_MACRO(
+	fCALLR,	/* Do a call Register */
+	(A),
+	"fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);",
+	"fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);",
+	if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALLR);},
+	(A_IMPLICIT_WRITES_PC,A_COF,A_IMPLICIT_WRITES_LR,A_CALL)
+)
+
+DEF_MACRO(
+	fWRITE_LOOP_REGS0, /* write ln,sa,ea,lc */
+	(START,COUNT), /* parameters */
+	"SA0=START; LC0=COUNT", /* short description */
+	"SA0=START; LC0=COUNT", /* short description */
+	{WRITE_RREG(REG_LC0,COUNT);
+         WRITE_RREG(REG_SA0,START);},
+	(A_IMPLICIT_WRITES_LC0,A_IMPLICIT_WRITES_SA0)
+)
+
+DEF_MACRO(
+	fWRITE_LOOP_REGS1, /* write ln,sa,ea,lc */
+	(START,COUNT), /* parameters */
+	"SA1=START; LC1=COUNT", /* short description */
+	"SA1=START; LC1=COUNT", /* short description */
+	{WRITE_RREG(REG_LC1,COUNT);
+         WRITE_RREG(REG_SA1,START);},
+	(A_IMPLICIT_WRITES_LC1,A_IMPLICIT_WRITES_SA1)
+)
+
+DEF_MACRO(
+	fWRITE_LC0,
+	(VAL), /* parameters */
+	"LC0=VAL", /* short description */
+	"LC0=VAL",
+	WRITE_RREG(REG_LC0,VAL),
+	(A_IMPLICIT_WRITES_LC0)
+)
+
+DEF_MACRO(
+	fWRITE_LC1,
+	(VAL), /* parameters */
+	"LC1=VAL", /* short description */
+	"LC1=VAL",
+	WRITE_RREG(REG_LC1,VAL),
+	(A_IMPLICIT_WRITES_LC1)
+)
+
+DEF_MACRO(
+	fCARRY_FROM_ADD,
+	(A,B,C),
+	"carry_from_add(A,B,C)",
+	"carry_from_add(A,B,C)",
+	carry_from_add64(A,B,C),
+	/* NOTHING */
+)
+
+DEF_MACRO(
+	fSETCV_ADD,
+	(A,B,CARRY),
+	"SR[CV]=FLAGS(A+B)",
+	"SR[CV]=FLAGS(A+B)",
+	do {
+		SET_USR_FIELD(USR_C,gen_carry_add((A),(B),((A)+(B))));
+		SET_USR_FIELD(USR_V,gen_overflow_add((A),(B),((A)+(B))));
+	} while (0),
+	(A_IMPLICIT_WRITES_CVBITS,A_NOTE_CVFLAGS,A_RESTRICT_NOSRMOVE)
+)
+DEF_MACRO(
+	fSETCV_SUB,
+	(A,B,CARRY),
+	"SR[CV]=FLAGS(A-B)",
+	"SR[CV]=FLAGS(A-B)",
+	do {
+		SET_USR_FIELD(USR_C,gen_carry_add((A),(B),((A)-(B))));
+		SET_USR_FIELD(USR_V,gen_overflow_add((A),(B),((A)-(B))));
+	} while (0),
+	(A_IMPLICIT_WRITES_CVBITS,A_NOTE_CVFLAGS,A_RESTRICT_NOSRMOVE)
+)
+
+DEF_MACRO(
+	fSET_OVERFLOW,
+	(),
+	"USR.OVF=1",
+	"USR.OVF=1",
+	SET_USR_FIELD(USR_OVF,1),
+	(A_IMPLICIT_WRITES_SRBIT,A_NOTE_SR_OVF_WHEN_SATURATING,A_RESTRICT_NOSRMOVE)
+)
+
+DEF_MACRO(
+	fSET_LPCFG,
+	(VAL), /* parameters */
+	"USR.LPCFG=VAL",
+	"USR.LPCFG=VAL",
+	SET_USR_FIELD(USR_LPCFG,(VAL)),
+	(A_IMPLICIT_WRITES_LPCFG,A_RESTRICT_NOSRMOVE)
+)
+
+
+DEF_MACRO(
+	fGET_LPCFG,
+	, /* parameters */
+	"USR.LPCFG",
+	"USR.LPCFG",
+	(GET_USR_FIELD(USR_LPCFG)),
+	()
+)
+
+
+
+DEF_MACRO(
+	fWRITE_P0, /* write Predicate 0 */
+	(VAL), /* parameters */
+	"P0=VAL", /* short description */
+	"P0=VAL", /* long description */
+	WRITE_PREG(0,VAL),          /* behavior */
+	(A_IMPLICIT_WRITES_P0)
+)
+
+DEF_MACRO(
+	fWRITE_P1, /* write Predicate 0 */
+	(VAL), /* parameters */
+	"P1=VAL", /* short description */
+	"P1=VAL", /* long description */
+	WRITE_PREG(1,VAL),          /* behavior */
+	(A_IMPLICIT_WRITES_P1)
+)
+
+DEF_MACRO(
+	fWRITE_P2, /* write Predicate 0 */
+	(VAL), /* parameters */
+	"P2=VAL", /* short description */
+	"P2=VAL", /* long description */
+	WRITE_PREG(2,VAL),          /* behavior */
+	(A_IMPLICIT_WRITES_P2)
+)
+
+DEF_MACRO(
+	fWRITE_P3, /* write Predicate 0 */
+	(VAL), /* parameters */
+	"P3=VAL", /* short description */
+	"P3=VAL", /* long description */
+	WRITE_PREG(3,VAL),     /* behavior */
+	(A_IMPLICIT_WRITES_P3)
+)
+
+DEF_MACRO(
+	fWRITE_P3_LATE, /* write Predicate 0 */
+	(VAL), /* parameters */
+	"P3=VAL", /* short description */
+	"P3=VAL", /* long description */
+	{WRITE_PREG(3,VAL); fHIDE(MARK_LATE_PRED_WRITE(3))} ,          /* behavior */
+	(A_IMPLICIT_WRITES_P3,A_RESTRICT_LATEPRED)
+)
+
+
+DEF_MACRO(
+	fPART1, /* write Predicate 0 */
+	(WORK), /* parameters */
+	"WORK", /* short description */
+	"WORK", /* long description */
+	if (insn->part1) { WORK; return; },          /* behavior */
+	/* optional attributes */
+)
+
+
+/*************************************/
+/* Casting, Sign-Zero extension, etc */
+/*************************************/
+
+DEF_MACRO(
+	fCAST4u, /* macro name */
+	(A), /* parameters */
+	"A.uw[0]", /* short description */
+	"unsigned 32-bit A", /* long description */
+	((size4u_t)(A)),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST4s, /* macro name */
+	(A), /* parameters */
+	"A.s32", /* short description */
+	"signed 32-bit A", /* long description */
+	((size4s_t)(A)),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST8u, /* macro name */
+	(A), /* parameters */
+	"A.u64", /* short description */
+	"unsigned 64-bit A", /* long description */
+	((size8u_t)(A)),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST8s, /* macro name */
+	(A), /* parameters */
+	"A.s64", /* short description */
+	"signed 64-bit A", /* long description */
+	((size8s_t)(A)),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST2_2s, /* macro name */
+	(A), /* params */
+	"A",
+	"signed 16-bit A",
+	((size2s_t)(A)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST2_2u, /* macro name */
+	(A), /* params */
+	"A",
+	"unsigned 16-bit A",
+	((size2u_t)(A)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST4_4s, /* macro name */
+	(A), /* params */
+	"A",
+	"signed 32-bit A",
+	((size4s_t)(A)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST4_4u, /* macro name */
+	(A), /* params */
+	"A",
+	"unsigned 32-bit A",
+	((size4u_t)(A)),
+	/* optional attributes */
+)
+
+
+DEF_MACRO(
+	fCAST4_8s, /* macro name */
+	(A), /* params */
+	"fSXTN(32,64,A)",
+	"32-bit A sign-extended to signed 64-bit",
+	((size8s_t)((size4s_t)(A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST4_8u, /* macro name */
+	(A), /* params */
+	"fZXTN(32,64,A)",
+	"32-bit A zero-extended to unsigned 64-bit",
+	((size8u_t)((size4u_t)(A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST8_8s, /* macro name */
+	(A), /* params */
+	"A",
+	"signed 64-bit A",
+	((size8s_t)(A)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST8_8u, /* macro name */
+	(A), /* params */
+	"A",
+	"unsigned 64-bit A",
+	((size8u_t)(A)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST2_8s, /* macro name */
+	(A), /* params */
+	"fSXTN(16,64,A)",
+	"16-bit A sign-extended to signed 64-bit",
+	((size8s_t)((size2s_t)(A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST2_8u, /* macro name */
+	(A), /* params */
+	"fZXTN(16,64,A)",
+	"16-bit A zero-extended to unsigned 64-bit",
+	((size8u_t)((size2u_t)(A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fZE8_16, /* zero-extend 8 to 16 */
+	(A),
+	"A",
+	"Unsigned low 8 bits of A",
+	((size2s_t)((size1u_t)(A))),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fSE8_16, /* sign-extend 8 to 16 */
+	(A),
+	"A",
+	"Signed low 8 bits of A",
+	((size2s_t)((size1s_t)(A))),
+	/* optional attributes */
+)
+
+
+DEF_MACRO(
+	fSE16_32, /* sign-extend 16 to 32 */
+	(A), /* parameters */
+	"A", /* short description */
+	"signed low 16-bits of A", /* long description */
+	((size4s_t)((size2s_t)(A))),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fZE16_32, /* zero-extend 16 to 32 */
+	(A), /* parameters */
+	"A", /* short description */
+	"signed low 16-bits of A", /* long description */
+	((size4u_t)((size2u_t)(A))),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fSE32_64,
+	(A), /* parameters */
+	"A", /* short description */
+	"A", /* long description */
+	( (size8s_t)((size4s_t)(A)) ),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fZE32_64,
+	(A), /* parameters */
+	"A", /* short description */
+	"zero-extend A from 32 to 64", /* long description */
+	( (size8u_t)((size4u_t)(A)) ),          /* behavior */
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fSE8_32, /* sign-extend 8 to 32 */
+	(A),
+	"A",
+	"Signed low 8 bits of A",
+	((size4s_t)((size1s_t)(A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fZE8_32, /* zero-extend 8 to 32 */
+	(A),
+	"A",
+	"Unsigned low 8 bits of A",
+	((size4s_t)((size1u_t)(A))),
+	/* optional attributes */
+)
+
+/*************************************/
+/* DSP arithmetic support            */
+/************************************/
+DEF_MACRO(
+	fMPY8UU, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"unsigned 8-bit multiply of A by B", /* long description */
+	(int)(fZE8_16(A)*fZE8_16(B)),     /* behavior */
+	(A_MPY)
+)
+DEF_MACRO(
+	fMPY8US, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"unsigned 8-bit multiply of A by signed B", /* long description */
+	(int)(fZE8_16(A)*fSE8_16(B)),     /* behavior */
+	(A_MPY)
+)
+DEF_MACRO(
+	fMPY8SU, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 8-bit multiply of A by unsigned B", /* long description */
+	(int)(fSE8_16(A)*fZE8_16(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY8SS, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 8-bit multiply of A by B", /* long description */
+	(int)((short)(A)*(short)(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY16SS, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 16-bit multiply of A by B", /* long description */
+	fSE32_64(fSE16_32(A)*fSE16_32(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY16UU, /* multiply unsigned half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"multiply unsigned A by unsigned B", /* long description */
+	fZE32_64(fZE16_32(A)*fZE16_32(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY16SU, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 16-bit A times unsigned 16-bit B", /* long description */
+	fSE32_64(fSE16_32(A)*fZE16_32(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY16US, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"unsigned 16-bit A times signed 16-bit B", /* long description */
+	fMPY16SU(B,A),
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY32SS, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 32-bit multiply of A by B", /* long description */
+	(fSE32_64(A)*fSE32_64(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY32UU, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"unsigned 32-bit multiply of A by B", /* long description */
+	(fZE32_64(A)*fZE32_64(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY32SU, /* multiply half integer */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"32-bit multiply of signed A by unsigned B", /* long description */
+	(fSE32_64(A)*fZE32_64(B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY3216SS, /* multiply mixed precision */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 16-bit multiply of A by B", /* long description */
+	(fSE32_64(A)*fSXTN(16,64,B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMPY3216SU, /* multiply mixed precision */
+	(A,B), /* parameters */
+	"(A * B)", /* short description */
+	"signed 16-bit multiply of A by unsigned B", /* long description */
+	(fSE32_64(A)*fZXTN(16,64,B)),     /* behavior */
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fROUND, /* optional rounding */
+	(A), /* parameters */
+	"round(A)", /* short description */
+	"round(A)", /* long description */
+	(A+0x8000),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCLIP, /* optional rounding */
+	(DST,SRC,U), /* parameters */
+	"DST=MIN((1<<U)-1,MAX(SRC,-(1<<U)))", /* short description */
+	"DST=IN((1<<U)-1,MAX(SRC,-(1<<U)))", /* long description */
+	{ size4s_t maxv = (1<<U)-1;
+	 size4s_t minv = -(1<<U);
+	 DST = fMIN(maxv,fMAX(SRC,minv));
+	},
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCRND, /* optional rounding */
+	(A), /* parameters */
+	"convround(A)", /* short description */
+	"convround(A)", /* long description */
+	((((A)&0x3)==0x3)?((A)+1):((A))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fRNDN, /* Rounding to a boundary */
+	(A,N), /* parameters */
+	"(N==0)?(A):round(A,2**(N-1))", /* short description */
+	"(N==0)?(A):round(A,2**(N-1))", /* long description */
+	((((N)==0)?(A):(((fSE32_64(A))+(1<<((N)-1)))))),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCRNDN, /* Rounding to a boundary */
+	(A,N), /* parameters */
+	"(N==0)?A:convround(A,2**(N-1))>>N", /* short description */
+	"(N==0)?A:convround(A,2**(N-1))>>N", /* long description */
+	(conv_round(A,N)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCRNDN64, /* Rounding to a boundary */
+	(A,N), /* parameters */
+	"(N==0)?A:convround(A,2**(N-1))>>N", /* short description */
+	"(N==0)?A:convround(A,2**(N-1))>>N", /* long description */
+	(conv_round64(A,N)),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fADD128, /* Rounding to a boundary */
+	(A,B), /* parameters */
+	"A+B", /* short description */
+	"", /* long description */
+	(add128(A, B)),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fSUB128, /* Rounding to a boundary */
+	(A,B), /* parameters */
+	"A-B", /* short description */
+	"", /* long description */
+	(sub128(A, B)),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fSHIFTR128, /* Rounding to a boundary */
+	(A,B), /* parameters */
+	"(size8s_t) (A >> B)", /* short description */
+	"", /* long description */
+	(shiftr128(A, B)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fSHIFTL128, /* Rounding to a boundary */
+	(A,B), /* parameters */
+	"(A << B)", /* short description */
+	"", /* long description */
+	(shiftl128(A, B)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fAND128, /* Rounding to a boundary */
+	(A,B), /* parameters */
+	"(A & B)", /* short description */
+	"", /* long description */
+	(and128(A, B)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fCAST8S_16S, /* Rounding to a boundary */
+	(A), /* parameters */
+	"sxt_{64->128}(A)", /* short description */
+	"", /* long description */
+	(cast8s_to_16s(A)),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fCAST16S_8S, /* Rounding to a boundary */
+	(A), /* parameters */
+	"sxt_{128->64}(A)", /* short description */
+	"", /* long description */
+	(cast16s_to_8s(A)),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fCAST16S_4S, /* Rounding to a boundary */
+	(A), /* parameters */
+	"sxt_{128->32}(A)", /* short description */
+	"", /* long description */
+	(cast16s_to_4s(A)),
+	/* optional attributes */
+)
+
+
+
+DEF_MACRO(
+	fEA_RI, /* Calculate EA with Register + Immediate Offset */
+	(REG,IMM),
+	"EA=REG+IMM",	/* short descr */
+	"EA=REG+IMM",	/* long descr */
+	do { EA=REG+IMM; fDOCHKPAGECROSS(REG,EA); } while (0),
+	(A_EA_REG_PLUS_IMM)
+)
+
+DEF_MACRO(
+	fEA_RRs, /* Calculate EA with Register + Registers scaled Offset */
+	(REG,REG2,SCALE),
+	"EA=REG+(REG2<<SCALE)",	/* short descr */
+	"EA=REG+(REG2<<SCALE)",	/* long descr */
+	do { EA=REG+(REG2<<SCALE); fDOCHKPAGECROSS(REG,EA); } while (0),
+	(A_EA_REG_PLUS_REGSCALED)
+)
+
+DEF_MACRO(
+	fEA_IRs, /* Calculate EA with Immediate + Registers scaled Offset */
+	(IMM,REG,SCALE),
+	"EA=IMM+(REG<<SCALE)",	/* short descr */
+	"EA=IMM+(REG<<SCALE)",	/* long descr */
+	do { EA=IMM+(REG<<SCALE); fDOCHKPAGECROSS(IMM,EA); } while (0),
+	(A_EA_IMM_PLUS_REGSCALED)
+)
+
+DEF_MACRO(
+	fEA_IMM, /* Calculate EA with Immediate */
+	(IMM),
+	"EA=IMM",	/* short descr */
+	"EA=IMM",	/* long descr */
+	EA=IMM,
+	(A_EA_IMM_ONLY)
+)
+
+DEF_MACRO(
+	fEA_REG, /* Calculate EA with REGISTER */
+	(REG),
+	"EA=REG",	/* short descr */
+	"EA=REG",	/* long descr */
+	EA=REG,
+	(A_EA_REG_ONLY)
+)
+
+DEF_MACRO(
+	fEA_BREVR, /* Calculate EA with bit reversed bottom of REGISTER */
+	(REG),
+	"EA=fbrev(REG)",	/* short descr */
+	"EA=fbrev(REG)",	/* long descr */
+	EA=fbrev(REG),
+	(A_EA_BREV_REG)
+)
+
+DEF_MACRO(
+	fEA_GPI, /* Calculate EA with Global Poitner + Immediate */
+	(IMM),
+	"EA=fREAD_GP()+IMM",	/* short descr */
+	"EA=fREAD_GP()+IMM",	/* long descr */
+    do { EA=fREAD_GP()+IMM; fGP_DOCHKPAGECROSS(fREAD_GP(),EA); } while (0),
+	(A_EA_GP_IMM)
+)
+
+DEF_MACRO(
+	fPM_I, /* Post Modify Register by Immediate*/
+	(REG,IMM),
+	"REG=REG+IMM",	/* short descr */
+	"REG=REG+IMM",	/* long descr */
+	do { REG = REG + IMM; fTIMING_AIA(EA,REG); } while (0),
+	(A_PM_I)
+)
+
+DEF_MACRO(
+	fPM_M, /* Post Modify Register by M register */
+	(REG,MVAL),
+	"REG=REG+MVAL",	/* short descr */
+	"REG=REG+MVAL",	/* long descr */
+	do { REG = REG + MVAL; fTIMING_AIA(EA,REG); } while (0),
+	(A_PM_M)
+)
+
+DEF_MACRO(
+	fPM_CIRI, /* Post Modify Register using Circular arithmetic by Immediate */
+	(REG,IMM,MVAL),
+	"REG=fcirc_add(REG,IMM,MVAL)",	/* short descr */
+	"REG=fcirc_add(REG,IMM,MVAL)",	/* long descr */
+	do { fcirc_add(REG,siV,MuV); fTIMING_AIA(EA,REG); } while (0),
+	(A_PM_CIRI)
+)
+
+DEF_MACRO(
+	fPM_CIRR, /* Post Modify Register using Circular arithmetic by register */
+	(REG,VAL,MVAL),
+	"REG=fcirc_add(REG,VAL,MVAL)",	/* short descr */
+	"REG=fcirc_add(REG,VAL,MVAL)",	/* long descr */
+	do { fcirc_add(REG,VAL,MuV); fTIMING_AIA(EA,REG); } while (0),
+	(A_PM_CIRR)
+)
+
+
+
+DEF_MACRO(
+	fMODCIRCU, /* modulo power of 2, positive output  */
+	(N,P), /* parameters */
+	"N modulo 2^P", /* short description */
+	"N modulo 2^P ", /* long description */
+	((N) & ((1<<(P))-1)),
+	/* optional attributes */
+)
+
+DEF_MACRO(
+	fSCALE, /* scale by N */
+	(N,A), /* parameters */
+	"A<<N", /* short description */
+	"A<<N", /* long description */
+	(((size8s_t)(A))<<N),
+	/* optional attributes */
+)
+DEF_MACRO(
+	fVSATW, /* saturating to 32-bits*/
+	(A), /* parameters */
+	"sat_32(A)", /* short description */
+	"saturate A to 32-bits", /* long description */
+	fVSATN(32,((long long)A)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fSATW, /* saturating to 32-bits*/
+	(A), /* parameters */
+	"sat_32(A)", /* short description */
+	"saturate A to 32-bits", /* long description */
+	fSATN(32,((long long)A)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fVSAT, /* saturating to 32-bits*/
+	(A), /* parameters */
+	"sat_32(A)", /* short description */
+	"saturate A to 32-bits", /* long description */
+	fVSATN(32,(A)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fSAT, /* saturating to 32-bits*/
+	(A), /* parameters */
+	"sat_32(A)", /* short description */
+	"saturate A to 32-bits", /* long description */
+	fSATN(32,(A)),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fSAT_ORIG_SHL, /* Saturating to 32-bits, with original value, for shift left */
+	(A,ORIG_REG), /* parameters */
+	"sat_32(A)", /* short description */
+	"saturate A to 32-bits for left shift", /* long description */
+	((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) ?
+		fSATVALN(32,((size4s_t)(ORIG_REG))) :
+		((((ORIG_REG) > 0) && ((A) == 0)) ?
+			fSATVALN(32,(ORIG_REG)) :
+			fSAT(A))),
+	(A_SATURATE)
+)
+
+DEF_MACRO(
+	fPASS,
+	(A),
+	"A", /* short description */
+	"", /* long description */
+	A,
+)
+
+DEF_MACRO(
+	fRND, /* saturating to 32-bits*/
+	(A), /* parameters */
+	"((A)+1)>>1", /* short description */
+	"round(A)", /* long description */
+	(((A)+1)>>1),
+)
+
+
+DEF_MACRO(
+	fBIDIR_SHIFTL,
+	(SRC,SHAMT,REGSTYPE),
+	"bidir_shiftl(SRC,SHAMT)",
+	"bidir_shiftl(SRC,SHAMT)",
+	(((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT))-1)) >>1) : (fCAST##REGSTYPE(SRC) << (SHAMT))),
+	(A_BIDIRSHIFTL)
+)
+
+DEF_MACRO(
+	fBIDIR_ASHIFTL,
+	(SRC,SHAMT,REGSTYPE),
+	"(SHAMT>0)?(fCAST##REGSTYPE##s(SRC)<<SHAMT):(fCAST##REGSTYPE##s(SRC)>>SHAMT)",
+	"bidir_asl(fCAST##REGSTYPE##s(SRC),SHAMT)",
+	fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##s),
+	(A_BIDIRSHIFTL)
+)
+
+DEF_MACRO(
+	fBIDIR_LSHIFTL,
+	(SRC,SHAMT,REGSTYPE),
+	"(SHAMT>0)?(fCAST##REGSTYPE##u(SRC)<<SHAMT):(fCAST##REGSTYPE##u(SRC)>>>SHAMT)",
+	"bidir_lsl(fCAST##REGSTYPE##u(SRC),SHAMT)",
+	fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##u),
+	(A_BIDIRSHIFTL)
+)
+
+DEF_MACRO(
+	fBIDIR_ASHIFTL_SAT,
+	(SRC,SHAMT,REGSTYPE),
+	"bidir_shiftl(SRC,SHAMT)",
+	"bidir_shiftl(SRC,SHAMT)",
+	(((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT))-1)) >>1) : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT),(SRC))),
+	(A_BIDIRSHIFTL)
+)
+
+
+DEF_MACRO(
+	fBIDIR_SHIFTR,
+	(SRC,SHAMT,REGSTYPE),
+	"bidir_shiftr(SRC,SHAMT)",
+	"bidir_shiftr(SRC,SHAMT)",
+	(((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT))-1)) << 1) : (fCAST##REGSTYPE(SRC) >> (SHAMT))),
+	(A_BIDIRSHIFTR)
+)
+
+DEF_MACRO(
+	fBIDIR_ASHIFTR,
+	(SRC,SHAMT,REGSTYPE),
+	"(SHAMT>0)?(fCAST##REGSTYPE##s(SRC)>>SHAMT):(fCAST##REGSTYPE##s(SRC)<<SHAMT)",
+	"bidir_asr(fCAST##REGSTYPE##s(SRC),SHAMT)",
+	fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##s),
+	(A_BIDIRSHIFTR)
+)
+
+DEF_MACRO(
+	fBIDIR_LSHIFTR,
+	(SRC,SHAMT,REGSTYPE),
+	"(SHAMT>0)?(fCAST##REGSTYPE##u(SRC)>>>SHAMT):(fCAST##REGSTYPE##u(SRC)<<SHAMT)",
+	"bidir_lsr(fCAST##REGSTYPE##u(SRC),SHAMT)",
+	fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##u),
+	(A_BIDIRSHIFTR)
+)
+
+DEF_MACRO(
+	fBIDIR_ASHIFTR_SAT,
+	(SRC,SHAMT,REGSTYPE),
+	"bidir_shiftr(SRC,SHAMT)",
+	"bidir_shiftr(SRC,SHAMT)",
+	(((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) << ((-(SHAMT))-1)) << 1,(SRC)) : (fCAST##REGSTYPE##s(SRC) >> (SHAMT))),
+	(A_BIDIRSHIFTR)
+)
+
+DEF_MACRO(
+	fASHIFTR,
+	(SRC,SHAMT,REGSTYPE),
+	"SRC >> SHAMT",
+	"asr(SRC,SHAMT)",
+	(fCAST##REGSTYPE##s(SRC) >> (SHAMT)),
+	/* */
+)
+
+DEF_MACRO(
+	fLSHIFTR,
+	(SRC,SHAMT,REGSTYPE),
+	"SRC >>> SHAMT",
+	"lsr(SRC,SHAMT)",
+	(((SHAMT) >= 64)?0:(fCAST##REGSTYPE##u(SRC) >> (SHAMT))),
+	/* */
+)
+
+DEF_MACRO(
+	fROTL,
+	(SRC,SHAMT,REGSTYPE),
+	"SRC <<_{R} SHAMT",
+	"rol(SRC,SHAMT)",
+	(((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) << (SHAMT)) | \
+		((fCAST##REGSTYPE##u(SRC) >> ((sizeof(SRC)*8)-(SHAMT)))))),
+	/* */
+)
+
+DEF_MACRO(
+	fROTR,
+	(SRC,SHAMT,REGSTYPE),
+	"SRC >>_{R} SHAMT",
+	"ror(SRC,SHAMT)",
+	(((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) >> (SHAMT)) | \
+		((fCAST##REGSTYPE##u(SRC) << ((sizeof(SRC)*8)-(SHAMT)))))),
+	/* */
+)
+
+DEF_MACRO(
+	fASHIFTL,
+	(SRC,SHAMT,REGSTYPE),
+	"fCAST##REGSTYPE##s(SRC) << SHAMT",
+	"asl(SRC,SHAMT)",
+	(((SHAMT) >= 64)?0:(fCAST##REGSTYPE##s(SRC) << (SHAMT))),
+	/* */
+)
+
+/*************************************/
+/* Floating-Point Support            */
+/************************************/
+
+DEF_MACRO(
+	fFLOAT, /* name */
+	(A), /* parameters */
+	"A", /* short description */
+	"A", /* long description */
+	({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; }),     /* behavior */
+	(A_FPOP,A_FPSINGLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND)
+)
+
+DEF_MACRO(
+	fUNFLOAT, /* multiply half integer */
+	(A), /* parameters */
+	"A", /* short description */
+	"A", /* long description */
+	({ union { float f; size4u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; }),     /* behavior */
+	(A_FPOP,A_FPSINGLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND)
+)
+
+DEF_MACRO(
+	fSFNANVAL,(),
+	"NaN",
+	"NaN",
+	0xffffffff,
+	()
+)
+
+DEF_MACRO(
+	fSFINFVAL,(A),
+	"sign(A) * Inf",
+	"sign(A) * Inf",
+	(((A) & 0x80000000) | 0x7f800000),
+	()
+)
+
+DEF_MACRO(
+	fSFONEVAL,(A),
+	"sign(A) * 1.0",
+	"sign(A) * 1.0",
+	(((A) & 0x80000000) | fUNFLOAT(1.0)),
+	()
+)
+
+DEF_MACRO(
+	fCHECKSFNAN,(DST,A),
+	"if (isnan(A)) DST = NaN;",
+	"if (isnan(A)) DST = NaN;",
+	do {
+		if (isnan(fFLOAT(A))) {
+			if ((fGETBIT(22,A)) == 0) fRAISEFLAGS(FE_INVALID);
+			DST = fSFNANVAL();
+		}
+	} while (0),
+	()
+)
+
+DEF_MACRO(
+	fCHECKSFNAN3,(DST,A,B,C),
+	"if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;",
+	"if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;",
+	do {
+		fCHECKSFNAN(DST,A);
+		fCHECKSFNAN(DST,B);
+		fCHECKSFNAN(DST,C);
+	} while (0),
+	()
+)
+
+DEF_MACRO(
+	fSF_BIAS,(),
+	"127",
+	"single precision bias",
+	127,
+	()
+)
+
+DEF_MACRO(
+	fSF_MANTBITS,(),
+	"23",
+	"single mantissa bits",
+	23,
+	()
+)
+
+DEF_MACRO(
+	fSF_RECIP_LOOKUP,(IDX),
+	"recip_lut[IDX]",
+	"Single Precision reciprocal Estimate",
+	arch_recip_lookup(IDX),
+	()
+)
+
+DEF_MACRO(
+	fSF_INVSQRT_LOOKUP,(IDX),
+	"invsqrt_lut[IDX]",
+	"Single Precision reciprocal Estimate",
+	arch_invsqrt_lookup(IDX),
+	()
+)
+
+DEF_MACRO(
+	fSF_MUL_POW2,(A,B),
+	"A * 2**B",
+	"A * 2**B",
+	(fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS()))),
+	()
+)
+
+DEF_MACRO(
+	fSF_GETEXP,(A),
+	"exponent(A)",
+	"exponent(A)",
+	(((A) >> fSF_MANTBITS()) & 0xff),
+	()
+)
+
+DEF_MACRO(
+	fSF_MAXEXP,(),
+	"254",
+	"SF maximum exponent",
+	(254),
+	()
+)
+
+DEF_MACRO(
+	fSF_RECIP_COMMON,(N,D,O,A),
+	"(N,D,O,A)=recip_common(N,D)",
+	"(N,D,O,A)=recip_common(N,D)",
+	arch_sf_recip_common(&N,&D,&O,&A),
+	(A_FPOP,A_IMPLICIT_WRITES_FPFLAGS)
+)
+
+DEF_MACRO(
+	fSF_INVSQRT_COMMON,(N,O,A),
+	"(N,O,A)=invsqrt_common(N)",
+	"(N,O,A)=invsqrt_common(N)",
+	arch_sf_invsqrt_common(&N,&O,&A),
+	(A_FPOP,A_IMPLICIT_WRITES_FPFLAGS)
+)
+
+DEF_MACRO(
+	fFMAFX,(A,B,C,ADJ),
+	"fmaf(A,B,C) * 2**(ADJ)",
+	"Fused Multiply Add w/ Scaling: (A*B+C)*2**ADJ",
+	internal_fmafx(A,B,C,fSXTN(8,64,ADJ)),
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fFMAF,(A,B,C),
+	"fmaf(A,B,C)",
+	"Fused Multiply Add: (A*B+C)",
+	internal_fmafx(A,B,C,0),
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fSFMPY,(A,B),
+	"A*B",
+	"Multiply: A*B",
+	internal_mpyf(A,B),
+	(A_MPY)
+)
+
+DEF_MACRO(
+	fMAKESF,(SIGN,EXP,MANT),
+	"-1**SIGN * 1.MANT * 2**(EXP-BIAS)",
+	"-1**SIGN * 1.MANT * 2**(EXP-BIAS)",
+	((((SIGN) & 1) << 31) | (((EXP) & 0xff) << fSF_MANTBITS()) |
+		((MANT) & ((1<<fSF_MANTBITS())-1))),
+	()
+)
+
+
+DEF_MACRO(
+	fDOUBLE, /* multiply half integer */
+	(A), /* parameters */
+	"A", /* short description */
+	"A", /* long description */
+	({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; }),     /* behavior */
+	(A_FPOP,A_FPDOUBLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND)
+)
+
+DEF_MACRO(
+	fUNDOUBLE, /* multiply half integer */
+	(A), /* parameters */
+	"A", /* short description */
+	"A", /* long description */
+	({ union { double f; size8u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; }),     /* behavior */
+	(A_FPOP,A_FPDOUBLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND)
+)
+
+DEF_MACRO(
+	fDFNANVAL,(),
+	"NaN",
+	"NaN",
+	0xffffffffffffffffULL,
+	()
+)
+
+DEF_MACRO(
+	fDFINFVAL,(A),
+	"sign(A) * Inf",
+	"sign(A) * Inf",
+	(((A) & 0x8000000000000000ULL) | 0x7ff0000000000000ULL),
+	()
+)
+
+DEF_MACRO(
+	fDFONEVAL,(A),
+	"sign(A) * 1.0",
+	"sign(A) * 1.0",
+	(((A) & 0x8000000000000000ULL) | fUNDOUBLE(1.0)),
+	()
+)
+
+DEF_MACRO(
+	fCHECKDFNAN,(DST,A),
+	"if (isnan(A)) DST = NaN;",
+	"if (isnan(A)) DST = NaN;",
+	do {
+		if (isnan(fDOUBLE(A))) {
+			if ((fGETBIT(51,A)) == 0) fRAISEFLAGS(FE_INVALID);
+			DST = fDFNANVAL();
+		}
+	} while (0),
+	()
+)
+
+DEF_MACRO(
+	fCHECKDFNAN3,(DST,A,B,C),
+	"if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;",
+	"if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;",
+	do {
+		fCHECKDFNAN(DST,A);
+		fCHECKDFNAN(DST,B);
+		fCHECKDFNAN(DST,C);
+	} while (0),
+	()
+)
+
+DEF_MACRO(
+	fDF_BIAS,(),
+	"1023",
+	"double precision bias",
+	1023,
+	()
+)
+
+DEF_MACRO(
+	fDF_ISNORMAL,(X),
+	"is_normal(X)",
+	"is X normal?",
+	(fpclassify(fDOUBLE(X)) == FP_NORMAL),
+	()
+)
+
+DEF_MACRO(
+	fDF_ISDENORM,(X),
+	"is_denormal(X)",
+	"is X denormal?",
+	(fpclassify(fDOUBLE(X)) == FP_SUBNORMAL),
+	()
+)
+
+DEF_MACRO(
+	fDF_ISBIG,(X),
+	"(df_exponent(X) >= 512)",
+	"is X sufficiently large for mpyfix (exp >= 512)?",
+	(fDF_GETEXP(X) >= 512),
+	()
+)
+
+DEF_MACRO(
+	fDF_MANTBITS,(),
+	"52",
+	"single mantissa bits",
+	52,
+	()
+)
+
+DEF_MACRO(
+	fDF_RECIP_LOOKUP,(IDX),
+	"recip_lut[IDX]",
+	"Single Precision reciprocal Estimate",
+	(size8u_t)(arch_recip_lookup(IDX)),
+	()
+)
+
+DEF_MACRO(
+	fDF_INVSQRT_LOOKUP,(IDX),
+	"invsqrt_lut[IDX]",
+	"Single Precision reciprocal square root Estimate",
+	(size8u_t)(arch_invsqrt_lookup(IDX)),
+	()
+)
+
+DEF_MACRO(
+	fDF_MUL_POW2,(A,B),
+	"A * 2**B",
+	"A * 2**B",
+	(fUNDOUBLE(fDOUBLE(A) * fDOUBLE((0ULL + fDF_BIAS() + (B)) << fDF_MANTBITS()))),
+	()
+)
+
+DEF_MACRO(
+	fDF_GETEXP,(A),
+	"exponent(A)",
+	"exponent(A)",
+	(((A) >> fDF_MANTBITS()) & 0x7ff),
+	()
+)
+
+DEF_MACRO(
+	fDF_MAXEXP,(),
+	"2046",
+	"SF maximum exponent",
+	(2046),
+	()
+)
+
+DEF_MACRO(
+	fDF_RECIP_COMMON,(N,D,O,A),
+	"(N,D,O,A)=recip_common(N,D)",
+	"(N,D,O,A)=recip_common(N,D)",
+	arch_df_recip_common(&N,&D,&O,&A),
+	(A_FPOP)
+)
+
+DEF_MACRO(
+	fDF_INVSQRT_COMMON,(N,O,A),
+	"(N,O,A)=invsqrt_common(N)",
+	"(N,O,A)=invsqrt_common(N)",
+	arch_df_invsqrt_common(&N,&O,&A),
+	(A_FPOP)
+)
+
+DEF_MACRO(
+	fFMA, (A,B,C),
+	"fma(A,B,C)",
+	"Fused Multiply Add: A*B+C",
+	internal_fma(A,B,C),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fDFMPY, (A,B),
+	"A*B",
+	"Multiply: A*B",
+	internal_mpy(A,B),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fDF_MPY_HH, (A,B,ACC),
+	"A*B with partial product ACC",
+	"Multiply: A*B with partial product ACC",
+	internal_mpyhh(A,B,ACC),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fFMAX, (A,B,C,ADJ),
+	"fma(A,B,C)*2**(2*ADJ)",
+	"Fused Multiply Add: (A*B+C)*2**(2*ADJ)",
+	internal_fmax(A,B,C,fSXTN(8,64,ADJ)*2),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fMAKEDF,(SIGN,EXP,MANT),
+	"-1**SIGN * 1.MANT * 2**(EXP-BIAS)",
+	"-1**SIGN * 1.MANT * 2**(EXP-BIAS)",
+	((((SIGN) & 1ULL) << 63) | (((EXP) & 0x7ffULL) << fDF_MANTBITS()) |
+		((MANT) & ((1ULL<<fDF_MANTBITS())-1))),
+	()
+)
+
+DEF_MACRO(
+	fFPOP_START,
+	(),
+	"fpop_start",
+	"Begin floating point operation",
+	arch_fpop_start(thread),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fFPOP_END,
+	(),
+	"fpop_end",
+	"End floating point operation",
+	arch_fpop_end(thread),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fFPSETROUND_NEAREST,
+	(),
+	"round_to_nearest()",
+	"Set rounding mode to Nearest",
+	fesetround(FE_TONEAREST),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fFPSETROUND_CHOP,
+	(),
+	"round_to_zero()",
+	"Set rounding mode to Chop",
+	fesetround(FE_TOWARDZERO),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fFPCANCELFLAGS,
+	(),
+	"cancel_flags()",
+	"Do not update Floating Point Flags",
+	feclearexcept(FE_ALL_EXCEPT),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fISINFPROD,
+	(A,B),
+	"isinf(A*B)",
+	"True if the product of A and B is truly infinite",
+	((isinf(A) && isinf(B)) ||
+		(isinf(A) && isfinite(B) && ((B) != 0.0)) ||
+		(isinf(B) && isfinite(A) && ((A) != 0.0))),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fISZEROPROD,
+	(A,B),
+	"is_true_zero(A*B)",
+	"True if the product of A and B is truly zero",
+	((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A))),
+	/* nothing */
+)
+
+DEF_MACRO(
+	fRAISEFLAGS,
+	(A),
+	"fpflags |= A",
+	"Raise Floating Point Flags",
+	arch_raise_fpflag(A),
+	/* NOTHING */
+)
+
+DEF_MACRO(
+	fDF_MAX,
+	(A,B),
+	"fmax(A,B)",
+	"Floating Point Maximum",
+	(((A)==(B))
+		? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B))
+		: fmax(A,B)),
+	(A_FPOP)
+)
+
+DEF_MACRO(
+	fDF_MIN,
+	(A,B),
+	"fmin(A,B)",
+	"Floating Point Maximum",
+	(((A)==(B))
+		? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B))
+		: fmin(A,B)),
+	(A_FPOP)
+)
+
+DEF_MACRO(
+	fSF_MAX,
+	(A,B),
+	"fmaxf(A,B)",
+	"Floating Point Maximum",
+	(((A)==(B))
+		? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B))
+		: fmaxf(A,B)),
+	(A_FPOP)
+)
+
+DEF_MACRO(
+	fSF_MIN,
+	(A,B),
+	"fmin(A,B)",
+	"Floating Point Maximum",
+	(((A)==(B))
+		? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B))
+		: fminf(A,B)),
+	(A_FPOP)
+)
+
+/*************************************/
+/* Load/Store support                */
+/*************************************/
+
+DEF_MACRO(fMMU,(ADDR),
+	"ADDR",
+	"ADDR",
+	/* mmu xlate */ ADDR,
+	(A_EXCEPTION_TLB,A_EXCEPTION_ACCESS)
+)
+
+DEF_MACRO(fcirc_add,(REG,INCR,IMMED),
+	"REG=circ_add(REG,INCR,IMMED)",
+	"REG=circ_add(REG,INCR,IMMED)",
+	(REG=fcircadd(thread, REG,INCR,IMMED, fREAD_CSREG(MuN))),
+	(A_CIRCADDR,A_IMPLICIT_READS_CS)
+)
+
+DEF_MACRO(fbrev,(REG),
+	"REG.h[1] | brev(REG.h[0])",
+	"REG.h[1] | brev(REG.h[0])",
+	(fbrevaddr(REG)),
+	(A_BREVADDR)
+)
+
+
+DEF_MACRO(fLOAD,(NUM,SIZE,SIGN,EA,DST),
+	"DST = *EA",
+	"Get SIZE bytes from memory at EA and save in DST.",
+	{ DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE(thread,EA,insn); },
+	(A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+DEF_MACRO(fMEMOP,(NUM,SIZE,SIGN,EA,FNTYPE,VALUE),
+	"DST = *EA",
+	"Get SIZE bytes from memory at EA and save in DST.",
+	{ memop##SIZE##_##FNTYPE(thread,EA,VALUE); },
+	(A_LOAD,A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+DEF_MACRO(fGET_FRAMEKEY,(),
+	"FRAMEKEY",
+	"FRAMEKEY",
+	READ_RREG(REG_FRAMEKEY),
+	(A_IMPLICIT_READS_FRAMEKEY)
+)
+
+DEF_MACRO(fFRAME_SCRAMBLE,(VAL),
+	"frame_scramble(VAL)",
+	"frame_scramble(VAL)",
+	((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32)),
+	/* ATTRIBS */
+)
+
+DEF_MACRO(fFRAME_UNSCRAMBLE,(VAL),
+	"frame_unscramble(VAL)",
+	"frame_unscramble(VAL)",
+	fFRAME_SCRAMBLE(VAL),
+	/* ATTRIBS */
+)
+
+DEF_MACRO(fFRAMECHECK,(ADDR,EA),
+	"frame_check_limit(ADDR)",
+	"frame_check_limit(ADDR)",
+	sys_check_framelimit(thread,ADDR,EA),
+	(A_IMPLICIT_READS_FRAMELIMIT)
+)
+
+DEF_MACRO(fLOAD_LOCKED,(NUM,SIZE,SIGN,EA,DST),
+	"DST = *EA; ",
+	"Get SIZE bytes from memory at EA and save in DST.",
+	{     DST = (size##SIZE##SIGN##_t)mem_load_locked(thread,EA,SIZE,insn);
+  },
+	(A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+DEF_MACRO(fLOAD_PHYS,(NUM,SIZE,SIGN,SRC1,SRC2,DST),
+	"DST = *((SRC1&0x7ff) | (SRC2<<11))",
+	"Load from physical address",
+	{     DST = (size##SIZE##SIGN##_t)mem_load_phys(thread,SRC1,SRC2,insn);
+  },
+	(A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+
+DEF_MACRO(fSTORE,(NUM,SIZE,EA,SRC),
+	"*EA = SRC",
+	"Store SIZE bytes from SRC into memory at EA",
+	{ MEM_STORE##SIZE(thread,EA,SRC,insn); },
+	(A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+
+DEF_MACRO(fSTORE_LOCKED,(NUM,SIZE,EA,SRC,PRED),
+	"if (lock_valid) { *EA = SRC; PRED = 0xff; lock_valid = 0; } else { PRED = 0; }",
+	"if the lock is valid, Store SIZE bytes from SRC into memory at EA, and invalidate the lock.  PRED is set to all 1s if the write actually took place.",
+	{ PRED = (mem_store_conditional(thread,EA,SRC,SIZE,insn) ? 0xff : 0); },
+	(A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST)
+)
+
+DEF_MACRO(fVTCM_MEMCPY,(DST,SRC,SIZE),
+	"for (i = 0; i <= SIZE; i++) { *(DST + i) = *(SRC + i); }",
+	"Copy SIZE+1 bytes from memory at SRC to memory at DST",
+	mem_vtcm_memcpy(thread, insn, DST, SRC, SIZE);,
+	/* ATTRIBS */
+)
+
+
+/*************************************/
+/* Permute Handler                   */
+/*************************************/
+
+DEF_MACRO(fPERMUTEH,(SRC0,SRC1,CTRL),
+	"permute(SRC0,SRC1,CTRL)",
+	"Permute SRC0 and SRC1 according to CTRL",
+	fpermuteh((SRC0),(SRC1),CTRL),
+	(A_PERM)
+)
+
+DEF_MACRO(fPERMUTEB,(SRC0,SRC1,CTRL),
+	"permute(SRC0,SRC1,CTRL)",
+	"Permute SRC0 and SRC1 according to CTRL",
+	fpermuteb((SRC0),(SRC1),CTRL),
+	(A_PERM)
+)
+
+/*************************************/
+/* Functions to help with bytes      */
+/*************************************/
+
+DEF_MACRO(fGETBYTE,(N,SRC),
+	"SRC.b[N]",
+	"Byte N from SRC",
+         ((size1s_t)((SRC>>((N)*8))&0xff)),
+	/* nothing */
+)
+
+DEF_MACRO(fGETUBYTE,(N,SRC),
+	"SRC.ub[N]",
+	"Byte N from SRC",
+         ((size1u_t)((SRC>>((N)*8))&0xff)),
+	/* nothing */
+)
+
+DEF_MACRO(fSETBYTE,(N,DST,VAL),
+	"DST.b[N]=VAL",
+	"Byte N from DST = VAL",
+	{
+	DST = (DST & ~(0x0ffLL<<((N)*8))) | (((size8u_t)((VAL) & 0x0ffLL)) << ((N)*8));
+	},
+	/* nothing */
+)
+
+DEF_MACRO(fGETHALF,(N,SRC),
+	"SRC.h[N]",
+	"Halfword N from SRC",
+         ((size2s_t)((SRC>>((N)*16))&0xffff)),
+	/* nothing */
+)
+
+DEF_MACRO(fGETUHALF,(N,SRC),
+	"SRC.uh[N]",
+	"Halfword N from SRC",
+         ((size2u_t)((SRC>>((N)*16))&0xffff)),
+	/* nothing */
+)
+
+DEF_MACRO(fSETHALF,(N,DST,VAL),
+	"DST.h[N]=VAL",
+	"Halfword N from DST = VAL",
+	{
+	DST = (DST & ~(0x0ffffLL<<((N)*16))) | (((size8u_t)((VAL) & 0x0ffff)) << ((N)*16));
+	},
+	/* nothing */
+)
+
+
+
+DEF_MACRO(fGETWORD,(N,SRC),
+	"SRC.w[N]",
+	"Word N from SRC",
+         ((size8s_t)((size4s_t)((SRC>>((N)*32))&0x0ffffffffLL))),
+	/* nothing */
+)
+
+DEF_MACRO(fGETUWORD,(N,SRC),
+	"SRC.uw[N]",
+	"Word N from SRC",
+         ((size8u_t)((size4u_t)((SRC>>((N)*32))&0x0ffffffffLL))),
+	/* nothing */
+)
+
+DEF_MACRO(fSETWORD,(N,DST,VAL),
+	"DST.w[N]=VAL",
+	"Word N from DST = VAL",
+	{
+	DST = (DST & ~(0x0ffffffffLL<<((N)*32))) | (((VAL) & 0x0ffffffffLL) << ((N)*32));
+	},
+	/* nothing */
+)
+
+DEF_MACRO(fACC,(),
+    "",
+    "",
+    ,
+    (A_ACC)
+)
+
+DEF_MACRO(fEXTENSION_AUDIO,(A),
+    "A",
+    "A",
+    A,
+    (A_EXTENSION_AUDIO,A_NOTE_EXTENSION_AUDIO)
+)
+
+DEF_MACRO(fSETBIT,(N,DST,VAL),
+	"DST.N = VAL",
+	"Set bit N in DST to VAL",
+	{
+	DST = (DST & ~(1ULL<<(N))) | (((size8u_t)(VAL))<<(N));
+	},
+	/* nothing */
+)
+
+DEF_MACRO(fGETBIT,(N,SRC),
+	"SRC.N",
+	"Get bit N from SRC",
+	(((SRC)>>N)&1),
+	/* nothing */
+)
+
+
+DEF_MACRO(fSETBITS,(HI,LO,DST,VAL),
+	"DST[HI:LO] = VAL",
+	"Set bits from HI to LO in DST to VAL",
+	do {
+        int j;
+        for (j=LO;j<=HI;j++) {
+          fSETBIT(j,DST,VAL);
+        }
+	} while (0),
+	/* nothing */
+)
+
+DEF_MACRO(fUNDEFINED,(),
+	"UNDEFINED",
+	"UNDEFINED",
+	warn("[UNDEFINED]: architecturally undefined"),
+	/* NOTHING */
+)
+
+/*************************************/
+/* Used for parity, etc........      */
+/*************************************/
+DEF_MACRO(fCOUNTONES_2,(VAL),
+	"count_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_ones_2(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCOUNTONES_4,(VAL),
+	"count_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_ones_4(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCOUNTONES_8,(VAL),
+	"count_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_ones_8(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fBREV_8,(VAL),
+	"reverse_bits(VAL)",
+	"Count the number of bits set in VAL",
+	reverse_bits_8(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fBREV_4,(VAL),
+	"reverse_bits(VAL)",
+	"Count the number of bits set in VAL",
+	reverse_bits_4(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fBREV_2,(VAL),
+	"reverse_bits(VAL)",
+	"Count the number of bits set in VAL",
+	reverse_bits_2(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fBREV_1,(VAL),
+	"reverse_bits(VAL)",
+	"Count the number of bits set in VAL",
+	reverse_bits_1(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCL1_8,(VAL),
+	"count_leading_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_leading_ones_8(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCL1_4,(VAL),
+	"count_leading_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_leading_ones_4(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCL1_2,(VAL),
+	"count_leading_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_leading_ones_2(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fCL1_1,(VAL),
+	"count_leading_ones(VAL)",
+	"Count the number of bits set in VAL",
+	count_leading_ones_1(VAL),
+	/* nothing */
+)
+
+DEF_MACRO(fINTERLEAVE,(ODD,EVEN),
+	"interleave(ODD,EVEN)",
+	"Interleave odd bits from ODD with even bits from EVEN",
+	interleave(ODD,EVEN),
+	/* nothing */
+)
+
+DEF_MACRO(fDEINTERLEAVE,(MIXED),
+	"deinterleave(ODD,EVEN)",
+	"Deinterleave odd bits into high half even bits to low half",
+	deinterleave(MIXED),
+	/* nothing */
+)
+
+DEF_MACRO(fNORM16,(VAL),
+	"get norm of 16bit value(VAL)",
+	"the number of leading sign bits in VAL",
+        ((VAL == 0) ? (31) : (fMAX(fCL1_2( VAL),fCL1_2(~VAL))-1)),
+	/* nothing */
+)
+
+
+
+DEF_MACRO(fHIDE,(A),
+	"",
+	"",
+	A,
+	()
+)
+
+DEF_MACRO(fASM_MAP,(A,B),
+	"Assembler mapped to: B",
+	"Assembler mapped to: B",
+	fatal("ASM_MAP instruction " A "->" B " executed.");,
+	()
+)
+
+DEF_MACRO(fCOND_ASM_MAP,(A,C,X,Y),
+	"if (C) {Assembler mapped to: X;} else {Assembler mapped to: Y;}@",
+	"if (C) {Assembler mapped to: Y;} else {Assembler mapped to: Y;}@",
+	fatal("ASM_MAP instruction " A "->" X "/" Y " executed.");,
+	()
+)
+
+DEF_MACRO(fCONSTLL,(A),
+	"A",
+	"A",
+	A##LL,
+)
+
+DEF_MACRO(fCONSTULL,(A),
+	"A",
+	"A",
+	A##ULL,
+)
+
+/* Do the things in the parens, but don't print the parens. */
+DEF_MACRO(fECHO,(A),
+	"A",
+	"A",
+	(A),
+	/* nothing */
+)
+
+
+/********************************************/
+/* OS interface and stop/wait               */
+/********************************************/
+
+DEF_MACRO(RUNNABLE_THREADS_MAX,,
+	"THREADS_MAX",
+	"THREADS_MAX",
+	(thread->processor_ptr->runnable_threads_max),
+	()
+)
+
+DEF_MACRO(THREAD_IS_ON,(PROC,TNUM),
+	"THREAD IS ENABLE",
+	"Thread is enabled in the revid",
+	((PROC->arch_proc_options->thread_enable_mask>>TNUM) & 0x1),
+	()
+)
+
+DEF_MACRO(THREAD_EN_MASK,(PROC),
+	"THREAD IS ENABLE MASK",
+	"Thread is enabled in the revid",
+	((PROC->arch_proc_options->thread_enable_mask)),
+	()
+)
+
+
+
+DEF_MACRO(READ_IMASK,(TH),
+	"IMASK[TH]",
+	"IMASK[TH]",
+         (((TH) >= (thread->processor_ptr->runnable_threads_max)) ? 0 : (thread->processor_ptr->thread[TH]->Regs[REG_IMASK])),
+	(A_IMPLICIT_READS_IMASK_ANYTHREAD)
+)
+DEF_MACRO(WRITE_IMASK,(TH,VAL),
+	"IMASK[TH]=VAL",
+	"IMASK[TH]=VAL",
+	 if ((TH) < (thread->processor_ptr->runnable_threads_max)) { thread->processor_ptr->thread[TH]->Regs[REG_IMASK]=(VAL & reg_mutability[REG_IMASK] ); },
+	(A_IMPLICIT_WRITES_IMASK_ANYTHREAD)
+)
+
+
+DEF_MACRO(WRITE_PRIO,(TH,VAL),
+	"TID[TH].PRIO=VAL",
+	"TID[TH].PRIO=VAL",
+	{
+		if ((TH) < (thread->processor_ptr->runnable_threads_max)) {
+			size4u_t tid_reg = thread->processor_ptr->thread[TH]->Regs[REG_TID];
+			fINSERT_BITS(tid_reg, reg_field_info[STID_PRIO].width, reg_field_info[STID_PRIO].offset, VAL);
+			LOG_OTHER_THREAD_REG_WRITE(thread,REG_TID,tid_reg,TH);
+		}
+	},
+	(A_IMPLICIT_WRITES_STID_PRIO_ANYTHREAD)
+)
+
+
+DEF_MACRO(DO_IASSIGNW,(REG),
+	"IASSIGNW(REG)",
+	"IASSIGNW(REG)",
+	{
+        int i;
+        int intbitpos = ((REG>>16)&0xF);
+        for (i=0;i<RUNNABLE_THREADS_MAX;i++) {
+			if(( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1)) {
+				fINSERT_BITS(thread->processor_ptr->thread[i]->Regs[REG_IMASK],1, intbitpos, (REG>>i) & 1);
+           }
+		}
+	},
+	(A_IMPLICIT_WRITES_IMASK_ANYTHREAD)
+)
+
+
+
+
+DEF_MACRO(fDO_NMI,(SREG),
+	"Raise NMI on threads",
+	"Raise NMI on threads",
+	{
+		int i;
+		for (i=0;i<RUNNABLE_THREADS_MAX;i++) {
+			if( ( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1) ) {
+				if (SREG & (1<<i)) {
+					register_nmi_interrupt(thread->processor_ptr->thread[i]);
+				}
+			}
+		}
+	},
+)
+
+DEF_MACRO(fDO_TRACE,(SREG),
+	"Send value to ETM trace",
+	"Send value to ETM trace",
+	{
+		fHIDE(CALLBACK(thread->processor_ptr->options->trace_callback,
+			thread->system_ptr,thread->processor_ptr,
+			thread->threadId,SREG);)
+        },
+)
+
+DEF_MACRO(DO_IASSIGNR,(SREG,DREG),
+	"DREG=IASSIGNR(SREG)",
+	"DREG=IASSIGNR(SREG)",
+	{
+		int i;
+		int result=0;
+		int intbitpos = ((SREG>>16)&0xF);
+		for (i=0;i<RUNNABLE_THREADS_MAX;i++) {
+			if(( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1)) {
+				result |= (((thread->processor_ptr->thread[i]->Regs[REG_IMASK]>>intbitpos)&1)<<i);
+			}
+		}
+		DREG=result;
+	},
+	(A_IMPLICIT_READS_IMASK_ANYTHREAD)
+)
+
+#ifdef NEW_INTERRUPTS
+
+DEF_MACRO(DO_SWI,(REG),
+	"IPEND |= REG",
+	"IPEND |= REG",
+        {fHIDE(CALLBACK(thread->processor_ptr->options->swi_callback,
+         thread->system_ptr,thread->processor_ptr,
+         thread->threadId,REG));
+	 fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND)|(REG));
+        },
+	(A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IPEND,A_IMPLICIT_WRITES_IPENDAD_IPEND)
+)
+
+DEF_MACRO(DO_CSWI,(REG),
+	"IPEND &= ~REG",
+	"IPEND &= ~REG",
+	fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND) & ~(REG));,
+	(A_IMPLICIT_READS_IPENDAD_IPEND,A_IMPLICIT_WRITES_IPENDAD_IPEND)
+)
+
+DEF_MACRO(DO_CIAD,(VAL),
+	"IAD &= ~VAL",
+	"IAD &= ~VAL",
+	sys_ciad(thread,VAL);
+	fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD) & ~(VAL));,
+	(A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IAD,A_IMPLICIT_WRITES_IPENDAD_IAD)
+)
+
+DEF_MACRO(DO_SIAD,(VAL),
+	"IAD |= VAL",
+	"IAD |= VAL",
+	sys_siad(thread,VAL);
+	fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD) | (VAL));,
+	(A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IAD,A_IMPLICIT_WRITES_IPENDAD_IAD)
+)
+
+#else
+
+DEF_MACRO(DO_SWI,(REG),
+        "IPEND |= REG",
+        "IPEND |= REG",
+        {fHIDE(CALLBACK(thread->processor_ptr->options->swi_callback,
+         thread->system_ptr,thread->processor_ptr,
+         thread->threadId,REG));
+         LOG_GLOBAL_REG_WRITE(REG_IPEND,(GLOBAL_REG_READ(REG_IPEND) | (REG & GLOBAL_REG_READ(REG_IEL))));
+        },
+        (A_EXCEPTION_SWI)
+)
+
+DEF_MACRO(DO_CSWI,(REG),
+        "IPEND &= ~REG",
+        "IPEND &= ~REG",
+        LOG_GLOBAL_REG_WRITE(REG_IPEND,GLOBAL_REG_READ(REG_IPEND) & ~((REG) & GLOBAL_REG_READ(REG_IEL)));,
+        ()
+)
+
+DEF_MACRO(DO_CIAD,(VAL),
+        "IAD &= ~VAL",
+        "IAD &= ~VAL",
+        sys_ciad(thread,VAL); LOG_GLOBAL_REG_WRITE(REG_IAD,GLOBAL_REG_READ(REG_IAD) & ~(VAL));,
+        (A_EXCEPTION_SWI)
+)
+
+DEF_MACRO(DO_SIAD,(VAL),
+        "IAD |= VAL",
+        "IAD |= VAL",
+        sys_siad(thread,VAL); LOG_GLOBAL_REG_WRITE(REG_IAD,GLOBAL_REG_READ(REG_IAD) | (VAL));,
+        (A_EXCEPTION_SWI)
+)
+
+
+#endif
+
+DEF_MACRO(fBREAK,(),
+	"Enter Debug mode",
+	"Enter Debug mode",
+        {isdb_brkpt_insn(thread->processor_ptr,thread->threadId);},
+	()
+)
+
+DEF_MACRO(fGP_DOCHKPAGECROSS,(BASE,SUM),
+	"",
+	"",
+	if (!(insn->extension_valid)) {
+        fDOCHKPAGECROSS(BASE,SUM);
+    },
+	(A_EA_PAGECROSS)
+)
+
+DEF_MACRO(fDOCHKPAGECROSS,(BASE,SUM),
+	"",
+	"",
+	if (thread->bq_on) {
+		thread->mem_access[insn->slot].check_page_crosses = 1;
+		thread->mem_access[insn->slot].page_cross_base = BASE;
+		thread->mem_access[insn->slot].page_cross_sum = SUM;
+	},
+	(A_EA_PAGECROSS)
+)
+
+DEF_MACRO(fTIMING_AIA,(OLDVA,NEWVA),
+	"",
+	"",
+  if(thread->bq_on){
+	thread->mem_access[insn->slot].post_updated = 1;
+	thread->mem_access[insn->slot].post_updated_va = NEWVA;
+	insn->is_aia = 1;
+	},
+	(A_PM_ANY)
+)
+
+
+DEF_MACRO(fPAUSE,(IMM),
+	"Pause for IMM cycles",
+	"Pause for IMM cycles",
+        {sys_pause(thread, insn->slot, IMM);},
+	()
+)
+
+
+#if 1
+/* The way it should be */
+DEF_MACRO(fTRAP,(TRAPTYPE,IMM),
+	"SSR.CAUSE = IMM; TRAP # TRAPTYPE",
+	"SSR.CAUSE = IMM; TRAP # TRAPTYPE",
+    warn("Trap NPC=%x ",fREAD_NPC());
+	warn("Trap exception, PCYCLE=%lld TYPE=%d NPC=%x IMM=0x%x",thread->processor_ptr->pstats[pcycles],TRAPTYPE,fREAD_NPC(),IMM);
+	register_trap_exception(thread,fREAD_NPC(),TRAPTYPE,IMM);,
+	(A_EXCEPTION_SWI)
+)
+#else
+DEF_MACRO(fTRAP,(TRAPTYPE,IMM),
+        "SSR.CAUSE = IMM; TRAP # TRAPTYPE",
+        "SSR.CAUSE = IMM; TRAP # TRAPTYPE",
+        if ((TRAPTYPE == 0) && (IMM == 0) &&
+              (!thread->sandbox_execution) &&
+              (!thread->processor_ptr->options->disable_angelswi)) {
+                sim_handle_trap(thread->system_ptr,thread->processor_ptr,thread->threadId,0);
+                /*thread->status |= EXEC_STATUS_SWI;*/
+        } else if ((TRAPTYPE == 0) && (IMM == 0xdb) &&
+               (!thread->sandbox_execution) &&
+               (!thread->processor_ptr->options->disable_angelswi)) {
+                sim_handle_debug(thread->system_ptr,thread->processor_ptr,thread->threadId,0xdb);
+        } else {
+          warn("Trap exception, TYPE=%d NPC=%x IMM=0x%x",TRAPTYPE,fREAD_NPC(),IMM);
+          register_trap_exception(thread,fREAD_NPC(),TRAPTYPE,IMM);
+        },
+        (A_EXCEPTION_SWI)
+)
+#endif
+
+DEF_MACRO(fINTERNAL_CLEAR_SAMEPAGE,
+	(),
+	"",
+	"",
+	/* force re-xlate at next fetch, refresh of in_user_mode, etc */
+	/* Permissions change too... */
+	sys_utlb_invalidate(thread->processor_ptr,thread),
+	/* NOTHING */
+)
+
+DEF_MACRO(fCLEAR_RTE_EX,(),
+      "SSR.SSR_EX = 0",
+      "SSR.SSR_EX = 0",
+      {
+        fLOG_REG_FIELD(SSR,SSR_EX,0);
+  	    fINTERNAL_CLEAR_SAMEPAGE();
+      },
+      ()
+)
+
+DEF_MACRO(fTLB_LOCK_AVAILABLE,(),
+	"SYSCFG.TLBLOCK == 0",
+	"SYSCFG.TLBLOCK == 0",
+	(fREAD_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_TLBLOCK) == 0),
+	()
+)
+
+DEF_MACRO(fK0_LOCK_AVAILABLE,(),
+	"SYSCFG.K0LOCK == 0",
+	"SYSCFG.K0LOCK == 0",
+	(fREAD_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_K0LOCK) == 0),
+	()
+)
+
+DEF_MACRO(fSET_TLB_LOCK,(),
+      "if (can_aquire_tlb_lock) {SYSCFG.TLBLOCK = 1;} else {sleep_until_available;}",
+      "if (can_aquire_tlb_lock) {SYSCFG.TLBLOCK = 1;} else {sleep_until_available;}",
+      {
+      if (fTLB_LOCK_AVAILABLE()) {
+        fLOG_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_TLBLOCK,1);
+      } else {
+        sys_waiting_for_tlb_lock(thread);
+      }
+      },
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.7.4

Part of the diff is not shown here. View the raw message.

#18 lore raw

RFC PATCH v2 18/67 Hexagon arch import - instruction encoding

In reply to Taylor Simpson

Imported from the Hexagon architecture library
Instruction encoding bit patterns for every instruction

---
 target/hexagon/imported/encode.def         |  125 ++
 target/hexagon/imported/encode_pp.def      | 2283 ++++++++++++++++++++++++++++
 target/hexagon/imported/encode_subinsn.def |  150 ++
 3 files changed, 2558 insertions(+)
 create mode 100644 target/hexagon/imported/encode.def
 create mode 100644 target/hexagon/imported/encode_pp.def
 create mode 100644 target/hexagon/imported/encode_subinsn.def
target/hexagon/imported/encode.def new file +125 -0
new file mode 100644
index 0000000..ae23301
@@ -0,0 +1,125 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This just includes all encoding files
+ */
+
+#ifndef DEF_FIELD32
+#define __SELF_DEF_FIELD32
+#define DEF_FIELD32(...) /* nothing */
+#endif
+
+#ifndef DEF_CLASS32
+#define __SELF_DEF_CLASS32
+#define DEF_CLASS32(...) /* nothing */
+#endif
+
+#ifndef DEF_ANTICLASS32
+#define __SELF_DEF_ANTICLASS32
+#define DEF_ANTICLASS32(...) /* nothing */
+#endif
+
+#ifndef LEGACY_DEF_ENC32
+#define __SELF_DEF_LEGACY_DEF_ENC32
+#define LEGACY_DEF_ENC32(...) /* nothing */
+#endif
+
+#ifndef DEF_FIELDROW_DESC32
+#define __SELF_DEF_FIELDROW_DESC32
+#define DEF_FIELDROW_DESC32(...) /* nothing */
+#endif
+
+#ifndef DEF_ENC32
+#define __SELF_DEF_ENC32
+#define DEF_ENC32(...) /* nothing */
+#endif
+
+#ifndef DEF_PACKED32
+#define __SELF_DEF_PACKED32
+#define DEF_PACKED32(...) /* nothing */
+#endif
+
+#ifndef DEF_ENC_SUBINSN
+#define __SELF_DEF_ENC_SUBINSN
+#define DEF_ENC_SUBINSN(...) /* nothing */
+#endif
+
+#ifndef DEF_EXT_ENC
+#define __SELF_DEF_EXT_ENC
+#define DEF_EXT_ENC(...) /* nothing */
+#endif
+
+#ifndef DEF_EXT_SPACE
+#define __SELF_DEF_EXT_SPACE
+#define DEF_EXT_SPACE(...) /* nothing */
+#endif
+
+#include "encode_pp.def"
+#include "encode_subinsn.def"
+
+#ifdef __SELF_DEF_FIELD32
+#undef __SELF_DEF_FIELD32
+#undef DEF_FIELD32
+#endif
+
+#ifdef __SELF_DEF_CLASS32
+#undef __SELF_DEF_CLASS32
+#undef DEF_CLASS32
+#endif
+
+#ifdef __SELF_DEF_ANTICLASS32
+#undef __SELF_DEF_ANTICLASS32
+#undef DEF_ANTICLASS32
+#endif
+
+#ifdef __SELF_DEF_LEGACY_DEF_ENC32
+#undef __SELF_DEF_LEGACY_DEF_ENC32
+#undef LEGACY_DEF_ENC32
+#endif
+
+#ifdef __SELF_DEF_FIELDROW_DESC32
+#undef __SELF_DEF_FIELDROW_DESC32
+#undef DEF_FIELDROW_DESC32
+#endif
+
+#ifdef __SELF_DEF_ENC32
+#undef __SELF_DEF_ENC32
+#undef DEF_ENC32
+#endif
+
+#ifdef __SELF_DEF_EXT_SPACE
+#undef __SELF_DEF_EXT_SPACE
+#undef DEF_EXT_SPACE
+#endif
+
+
+#ifdef __SELF_DEF_PACKED32
+#undef __SELF_DEF_PACKED32
+#undef DEF_PACKED32
+#endif
+
+#ifdef __SELF_DEF_ENC_SUBINSN
+#undef __SELF_DEF_ENC_SUBINSN
+#undef DEF_ENC_SUBINSN
+#endif
+
+#ifdef __SELF_DEF_EXT_ENC
+#undef __SELF_DEF_EXT_ENC
+#undef DEF_EXT_ENC
+#endif
+
target/hexagon/imported/encode_pp.def new file +2283 -0

2,283 lines not on this page · raw message

target/hexagon/imported/encode_subinsn.def new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
2.7.4
#19 lore raw

RFC PATCH v2 19/67 Hexagon instruction class definitions

In reply to Taylor Simpson

Imported from the Hexagon architecture library

---
 target/hexagon/imported/iclass.def | 52 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 target/hexagon/imported/iclass.def
target/hexagon/imported/iclass.def new file +52 -0
new file mode 100644
index 0000000..4ef725f
@@ -0,0 +1,52 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* DEF_*(TYPE,SLOTS,UNITS) */
+DEF_PP_ICLASS32(EXTENDER,0123,LDST|SUNIT|MUNIT) /* 0 */
+DEF_PP_ICLASS32(CJ,0123,CTRLFLOW) /* 1 */
+DEF_PP_ICLASS32(NCJ,01,LDST|CTRLFLOW) /* 2 */
+DEF_PP_ICLASS32(V4LDST,01,LDST) /* 3 */
+DEF_PP_ICLASS32(V2LDST,01,LDST) /* 4 */
+DEF_PP_ICLASS32(J,0123,CTRLFLOW)  /* 5 */
+DEF_PP_ICLASS32(CR,3,SUNIT)     /* 6 */
+DEF_PP_ICLASS32(ALU32_2op,0123,LDST|SUNIT|MUNIT) /* 7 */
+DEF_PP_ICLASS32(S_2op,23,SUNIT|MUNIT)               /* 8 */
+DEF_PP_ICLASS32(LD,01,LDST)                    /* 9 */
+DEF_PP_ICLASS32(ST,01,LDST)                        /* 10 */
+DEF_PP_ICLASS32(ALU32_ADDI,0123,LDST|SUNIT|MUNIT) /* 11 */
+DEF_PP_ICLASS32(S_3op,23,SUNIT|MUNIT)               /* 12 */
+DEF_PP_ICLASS32(ALU64,23,SUNIT|MUNIT)             /* 13 */
+DEF_PP_ICLASS32(M,23,SUNIT|MUNIT)                 /* 14 */
+DEF_PP_ICLASS32(ALU32_3op,0123,LDST|SUNIT|MUNIT) /* 15 */
+
+DEF_EE_ICLASS32(EE0,01,INVALID) /* 0 */
+DEF_EE_ICLASS32(EE1,01,INVALID) /* 1 */
+DEF_EE_ICLASS32(EE2,01,INVALID) /* 2 */
+DEF_EE_ICLASS32(EE3,01,INVALID) /* 3 */
+DEF_EE_ICLASS32(EE4,01,INVALID) /* 4 */
+DEF_EE_ICLASS32(EE5,01,INVALID) /* 5 */
+DEF_EE_ICLASS32(EE6,01,INVALID) /* 6 */
+DEF_EE_ICLASS32(EE7,01,INVALID) /* 7 */
+DEF_EE_ICLASS32(EE8,01,INVALID) /* 8 */
+DEF_EE_ICLASS32(EE9,01,INVALID) /* 9 */
+DEF_EE_ICLASS32(EEA,01,INVALID) /* 10 */
+DEF_EE_ICLASS32(EEB,01,INVALID) /* 11 */
+DEF_EE_ICLASS32(EEC,01,INVALID) /* 12 */
+DEF_EE_ICLASS32(EED,01,INVALID) /* 13 */
+DEF_EE_ICLASS32(EEE,01,INVALID) /* 14 */
+DEF_EE_ICLASS32(EEF,01,INVALID) /* 15 */
+
Signature · 1 line
2.7.4
#20 lore raw

RFC PATCH v2 20/67 Hexagon instruction utility functions

In reply to Taylor Simpson

Utility functions called by various instructions

---
 target/hexagon/arch.h     |  62 ++++
 target/hexagon/conv_emu.h |  50 +++
 target/hexagon/fma_emu.h  |  30 ++
 target/hexagon/arch.c     | 663 +++++++++++++++++++++++++++++++++
 target/hexagon/conv_emu.c | 369 +++++++++++++++++++
 target/hexagon/fma_emu.c  | 916 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 2090 insertions(+)
 create mode 100644 target/hexagon/arch.h
 create mode 100644 target/hexagon/conv_emu.h
 create mode 100644 target/hexagon/fma_emu.h
 create mode 100644 target/hexagon/arch.c
 create mode 100644 target/hexagon/conv_emu.c
 create mode 100644 target/hexagon/fma_emu.c
target/hexagon/arch.h new file +62 -0
new file mode 100644
index 0000000..716bbdd
@@ -0,0 +1,62 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_ARCH_H
+#define HEXAGON_ARCH_H
+
+#include "cpu.h"
+#include "hex_arch_types.h"
+
+extern size1u_t rLPS_table_64x4[64][4];
+extern size1u_t AC_next_state_MPS_64[64];
+extern size1u_t AC_next_state_LPS_64[64];
+
+extern size4u_t fbrevaddr(size4u_t pointer);
+extern size4u_t count_ones_2(size2u_t src);
+extern size4u_t count_ones_4(size4u_t src);
+extern size4u_t count_ones_8(size8u_t src);
+extern size4u_t count_leading_ones_8(size8u_t src);
+extern size4u_t count_leading_ones_4(size4u_t src);
+extern size4u_t count_leading_ones_2(size2u_t src);
+extern size4u_t count_leading_ones_1(size1u_t src);
+extern size8u_t reverse_bits_8(size8u_t src);
+extern size4u_t reverse_bits_4(size4u_t src);
+extern size4u_t reverse_bits_2(size2u_t src);
+extern size4u_t reverse_bits_1(size1u_t src);
+extern size8u_t exchange(size8u_t bits, size4u_t cntrl);
+extern size8u_t interleave(size4u_t odd, size4u_t even);
+extern size8u_t deinterleave(size8u_t src);
+extern size4u_t carry_from_add64(size8u_t a, size8u_t b, size4u_t c);
+extern size4s_t conv_round(size4s_t a, int n);
+extern size16s_t cast8s_to_16s(size8s_t a);
+extern size8s_t cast16s_to_8s(size16s_t a);
+extern size4s_t cast16s_to_4s(size16s_t a);
+extern size16s_t add128(size16s_t a, size16s_t b);
+extern size16s_t sub128(size16s_t a, size16s_t b);
+extern size16s_t shiftr128(size16s_t a, size4u_t n);
+extern size16s_t shiftl128(size16s_t a, size4u_t n);
+extern size16s_t and128(size16s_t a, size16s_t b);
+extern void arch_fpop_start(CPUHexagonState *env);
+extern void arch_fpop_end(CPUHexagonState *env);
+extern void arch_raise_fpflag(unsigned int flags);
+extern int arch_sf_recip_common(size4s_t *Rs, size4s_t *Rt, size4s_t *Rd,
+                                int *adjust);
+extern int arch_sf_invsqrt_common(size4s_t *Rs, size4s_t *Rd, int *adjust);
+extern int arch_recip_lookup(int index);
+extern int arch_invsqrt_lookup(int index);
+
+#endif
target/hexagon/conv_emu.h new file +50 -0

50 lines not on this page · raw message

target/hexagon/fma_emu.h new file +30 -0
new file mode 100644
index 0000000..3a54f25
@@ -0,0 +1,30 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_FMA_EMU_H
+#define HEXAGON_FMA_EMU_H
+
+extern float internal_fmafx(float a_in, float b_in, float c_in, int scale);
+extern float internal_fmaf(float a_in, float b_in, float c_in);
+extern double internal_fma(double a_in, double b_in, double c_in);
+extern double internal_fmax(double a_in, double b_in, double c_in, int scale);
+extern float internal_mpyf(float a_in, float b_in);
+extern double internal_mpy(double a_in, double b_in);
+extern double internal_mpyhh(double a_in, double b_in,
+                             unsigned long long int accumulated);
+
+#endif
target/hexagon/arch.c new file +663 -0

663 lines not on this page · raw message

target/hexagon/conv_emu.c new file +369 -0

369 lines not on this page · raw message

target/hexagon/fma_emu.c new file +916 -0

916 lines not on this page · raw message

Signature · 1 line
2.7.4
#21 lore raw

RE: [RFC PATCH v2 20/67] Hexagon instruction utility functions

Quoted 9 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Taylor Simpson
Sent: Friday, February 28, 2020 10:43 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Taylor Simpson <[email protected]>; [email protected]; [email protected]
Subject: [RFC PATCH v2 20/67] Hexagon instruction utility functions

...

Quoted 2 lines
(quoted diff) +2 -0
+int arch_sf_invsqrt_common(size4s_t *Rs, size4s_t *Rd, int *adjust)
+{

...

target/hexagon/arch.c line 598

Quoted 8 lines
target/hexagon/arch.c new file +8 -0
+    } else if (r_class == FP_INFINITE) {
+        /* EJP: or put Inf in num fixup? */
+        RsV = fSFINFVAL(-1);
+        RdV = fSFINFVAL(-1);
+    } else if (r_class == FP_ZERO) {
+        /* EJP: or put zero in num fixup? */
+        RsV = RsV;
+        RdV = fSFONEVAL(0);

...

This "RsV = RsV" looks like a logic error? Presumably it's safe to remove -- unless there's some other field that should get initialized here? PeV maybe?

#22 lore raw

RE: [RFC PATCH v2 20/67] Hexagon instruction utility functions

Quoted 33 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Brian Cain
Sent: Thursday, April 9, 2020 1:53 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC PATCH v2 20/67] Hexagon instruction utility functions

Quoted 3 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Taylor

Simpson

Quoted 6 lines

Sent: Friday, February 28, 2020 10:43 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Taylor Simpson <[email protected]>; [email protected]; [email protected]
Subject: [RFC PATCH v2 20/67] Hexagon instruction utility functions

...

Quoted 2 lines
(quoted diff) +2 -0
+int arch_sf_invsqrt_common(size4s_t *Rs, size4s_t *Rd, int *adjust)
+{

...

target/hexagon/arch.c line 598

Quoted 8 lines
target/hexagon/arch.c new file +8 -0
+    } else if (r_class == FP_INFINITE) {
+        /* EJP: or put Inf in num fixup? */
+        RsV = fSFINFVAL(-1);
+        RdV = fSFINFVAL(-1);
+    } else if (r_class == FP_ZERO) {
+        /* EJP: or put zero in num fixup? */
+        RsV = RsV;
+        RdV = fSFONEVAL(0);
Quoted 4 lines

...

This "RsV = RsV" looks like a logic error? Presumably it's safe to remove -- unless there's some other field that should get initialized here? PeV maybe?

Probably a copy/paste error. I will remove it.

Thanks,
Taylor

#23 lore raw

RFC PATCH v2 21/67 Hexagon generator phase 1 - C preprocessor for semantics

In reply to Taylor Simpson

Run the C preprocessor across the instruction definition files and macro definitoin file to expand macros and prepare the semantics_generated.pyinc file. The resulting file contains one entry with the semantics for each instruction and
one line with the instruction attributes associated with each macro.

---
 target/hexagon/gen_semantics.c | 92 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 target/hexagon/gen_semantics.c
target/hexagon/gen_semantics.c new file +92 -0
new file mode 100644
index 0000000..65d04fa
@@ -0,0 +1,92 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This program generates the semantics file that is processed by
+ * the do_qemu.py script.  We use the C preporcessor to manipulate the
+ * files imported from the Hexagon architecture library.
+ */
+
+#include <stdio.h>
+#define STRINGIZE(X) #X
+
+int main(int argc, char *argv[])
+{
+    FILE *outfile;
+
+    if (argc != 2) {
+        fprintf(stderr, "Usage: gen_semantics ouptputfile\n");
+        return -1;
+    }
+    outfile = fopen(argv[1], "w");
+    if (outfile == NULL) {
+        fprintf(stderr, "Cannot open %s for writing\n", argv[1]);
+        return -1;
+    }
+
+/*
+ * Process the instruction definitions
+ *     Scalar core instructions have the following form
+ *         Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(),
+ *         "Add 32-bit registers",
+ *         { RdV=RsV+RtV;})
+ *     HVX instructions have the following form
+ *         EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)",
+ *         ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE),
+ *         "Insert Word Scalar into Vector",
+ *         VxV.uw[0] = RtV;)
+ */
+#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+    do { \
+        fprintf(outfile, "SEMANTICS(\"%s\",%s,\"\"\"%s\"\"\")\n", \
+                #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \
+        fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \
+                #TAG, STRINGIZE(ATTRIBS)); \
+    } while (0);
+#define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+    do { \
+        fprintf(outfile, "EXT_SEMANTICS(\"%s\",\"%s\",%s,\"\"\"%s\"\"\")\n", \
+                EXTSTR, #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \
+        fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \
+                #TAG, STRINGIZE(ATTRIBS)); \
+    } while (0);
+#include "imported/allidefs.def"
+#undef Q6INSN
+#undef EXTINSN
+
+/*
+ * Process the macro definitions
+ *     Macros definitions have the following form
+ *         DEF_MACRO(
+ *             fLSBNEW0,,
+ *             "P0.new[0]",
+ *             "Least significant bit of new P0",
+ *             predlog_read(thread,0),
+ *             (A_DOTNEW,A_IMPLICIT_READS_P0)
+ *         )
+ * The important part here is the attributes.  Whenever an instruction
+ * invokes a macro, we add the macro's attributes to the instruction.
+ */
+#define DEF_MACRO(MNAME, PARAMS, SDESC, LDESC, BEH, ATTRS) \
+    fprintf(outfile, "MACROATTRIB(\"%s\",\"\"\"%s\"\"\",\"%s\")\n", \
+            #MNAME, STRINGIZE(BEH), STRINGIZE(ATTRS));
+#include "imported/macros.def"
+#undef DEF_MACRO
+
+    fclose(outfile);
+    return 0;
+}
Signature · 1 line
2.7.4
#24 lore raw

RFC PATCH v2 22/67 Hexagon generator phase 2 - qemu_def_generated.h

In reply to Taylor Simpson

For each instruction we create
DEF_HELPER function prototype
TCG code to generate call to helper
Helper definition

---
 target/hexagon/do_qemu.py | 769 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 769 insertions(+)
 create mode 100755 target/hexagon/do_qemu.py
target/hexagon/do_qemu.py new file +769 -0
new file mode 100755
index 0000000..6f0e376
@@ -0,0 +1,769 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+##
+##  This program is free software; you can redistribute it and/or modify
+##  it under the terms of the GNU General Public License as published by
+##  the Free Software Foundation; either version 2 of the License, or
+##  (at your option) any later version.
+##
+##  This program is distributed in the hope that it will be useful,
+##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##  GNU General Public License for more details.
+##
+##  You should have received a copy of the GNU General Public License
+##  along with this program; if not, see <http://www.gnu.org/licenses/>.
+##
+
+import sys
+import re
+import string
+from io import StringIO
+
+
+import operator
+from itertools import chain
+
+
+
+behdict = {}          # tag ->behavior
+semdict = {}          # tag -> semantics
+extdict = {}          # tag -> What extension an instruction belongs to (or "")
+extnames = {}         # ext name -> True
+attribdict = {}       # tag -> attributes
+macros = {}           # macro -> macro information...
+attribinfo = {}       # Register information and misc
+tags = []             # list of all tags
+
+def get_macro(macname,ext=""):
+    mackey = macname + ":" + ext
+    if ext and mackey not in macros:
+        return get_macro(macname,"")
+    return macros[mackey]
+
+# We should do this as a hash for performance,
+# but to keep order let's keep it as a list.
+def uniquify(seq):
+    seen = set()
+    seen_add = seen.add
+    return [x for x in seq if x not in seen and not seen_add(x)]
+
+regre = re.compile(
+    r"((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)")
+immre = re.compile(r"[#]([rRsSuUm])(\d+)(?:[:](\d+))?")
+reg_or_immre = \
+    re.compile(r"(((?<!DUP)[MNRCOPQXSGVZA])([stuvwxyzdefg]+)" + \
+                "([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)")
+relimmre = re.compile(r"[#]([rR])(\d+)(?:[:](\d+))?")
+absimmre = re.compile(r"[#]([sSuUm])(\d+)(?:[:](\d+))?")
+
+finished_macros = set()
+
+def expand_macro_attribs(macro,allmac_re):
+    if macro.key not in finished_macros:
+        # Get a list of all things that might be macros
+        l = allmac_re.findall(macro.beh)
+        for submacro in l:
+            if not submacro: continue
+            if not get_macro(submacro,macro.ext):
+                raise Exception("Couldn't find macro: <%s>" % l)
+            macro.attribs |= expand_macro_attribs(
+                get_macro(submacro,macro.ext), allmac_re)
+            finished_macros.add(macro.key)
+    return macro.attribs
+
+immextre = re.compile(r'f(MUST_)?IMMEXT[(]([UuSsRr])')
+def calculate_attribs():
+    # Recurse down macros, find attributes from sub-macros
+    macroValues = list(macros.values())
+    allmacros_restr = "|".join(set([ m.re.pattern for m in macroValues ]))
+    allmacros_re = re.compile(allmacros_restr)
+    for macro in macroValues:
+        expand_macro_attribs(macro,allmacros_re)
+    # Append attributes to all instructions
+    for tag in tags:
+        for macname in allmacros_re.findall(semdict[tag]):
+            if not macname: continue
+            macro = get_macro(macname,extdict[tag])
+            attribdict[tag] |= set(macro.attribs)
+        m = immextre.search(semdict[tag])
+        if m:
+            if m.group(2).isupper():
+                attrib = 'A_EXT_UPPER_IMMED'
+            elif m.group(2).islower():
+                attrib = 'A_EXT_LOWER_IMMED'
+            else:
+                raise "Not a letter: %s (%s)" % (m.group(1),tag)
+            if not attrib in attribdict[tag]:
+                attribdict[tag].add(attrib)
+
+def SEMANTICS(tag, beh, sem):
+    #print tag,beh,sem
+    extdict[tag] = ""
+    behdict[tag] = beh
+    semdict[tag] = sem
+    attribdict[tag] = set()
+    tags.append(tag)        # dicts have no order, this is for order
+
+def ATTRIBUTES(tag, attribstring):
+    attribstring = \
+        attribstring.replace("ATTRIBS","").replace("(","").replace(")","")
+    if not attribstring:
+        return
+    attribs = attribstring.split(",")
+    for attrib in attribs:
+        attribdict[tag].add(attrib.strip())
+
+class Macro(object):
+    __slots__ = ['key','name', 'beh', 'attribs', 're','ext']
+    def __init__(self,key, name, beh, attribs,ext):
+        self.key = key
+        self.name = name
+        self.beh = beh
+        self.attribs = set(attribs)
+        self.ext = ext
+        self.re = re.compile("\\b" + name + "\\b")
+
+def MACROATTRIB(macname,beh,attribstring,ext=""):
+    attribstring = attribstring.replace("(","").replace(")","")
+    mackey = macname + ":" + ext
+    if attribstring:
+        attribs = attribstring.split(",")
+    else:
+        attribs = []
+    macros[mackey] = Macro(mackey,macname,beh,attribs,ext)
+
+# read in file.  Evaluate each line: each line calls a function above
+
+for line in open(sys.argv[1], 'rt').readlines():
+    if not line.startswith("#"):
+        eval(line.strip())
+
+
+calculate_attribs()
+
+
+attribre = re.compile(r'DEF_ATTRIB\(([A-Za-z0-9_]+), ([^,]*), ' +
+        r'"([A-Za-z0-9_\.]*)", "([A-Za-z0-9_\.]*)"\)')
+for line in open(sys.argv[2], 'rt').readlines():
+    if not attribre.match(line):
+        continue
+    (attrib_base,descr,rreg,wreg) = attribre.findall(line)[0]
+    attrib_base = 'A_' + attrib_base
+    attribinfo[attrib_base] = {'rreg':rreg, 'wreg':wreg, 'descr':descr}
+
+def compute_tag_regs(tag):
+    return uniquify(regre.findall(behdict[tag]))
+
+def compute_tag_immediates(tag):
+    return uniquify(immre.findall(behdict[tag]))
+
+##
+##  tagregs is the main data structure we'll use
+##  tagregs[tag] will contain the registers used by an instruction
+##  Within each entry, we'll use the regtype and regid fields
+##      regtype can be one of the following
+##          C                control register
+##          N                new register value
+##          P                predicate register
+##          R                GPR register
+##          M                modifier register
+##      regid can be one of the following
+##          d, e             destination register
+##          dd               destination register pair
+##          s, t, u, v, w    source register
+##          ss, tt, uu, vv   source register pair
+##          x, y             read-write register
+##          xx, yy           read-write register pair
+##
+tagregs = dict(zip(tags, list(map(compute_tag_regs, tags))))
+
+def is_pair(regid):
+    return len(regid) == 2
+
+def is_single(regid):
+    return len(regid) == 1
+
+def is_written(regid):
+    return regid[0] in "dexy"
+
+def is_writeonly(regid):
+    return regid[0] in "de"
+
+def is_read(regid):
+    return regid[0] in "stuvwxy"
+
+def is_readwrite(regid):
+    return regid[0] in "xy"
+
+def is_scalar_reg(regtype):
+    return regtype in "RPC"
+
+def is_old_val(regtype, regid, tag):
+    return regtype+regid+'V' in semdict[tag]
+
+def is_new_val(regtype, regid, tag):
+    return regtype+regid+'N' in semdict[tag]
+
+tagimms = dict(zip(tags, list(map(compute_tag_immediates, tags))))
+
+def need_slot(tag):
+    if ('A_CONDEXEC' in attribdict[tag] or
+        'A_STORE' in attribdict[tag]):
+        return 1
+    else:
+        return 0
+
+def need_part1(tag):
+    return re.compile(r"fPART1").search(semdict[tag])
+
+def need_ea(tag):
+    return re.compile(r"\bEA\b").search(semdict[tag])
+
+def imm_name(immlett):
+    return "%siV" % immlett
+
+##
+## Helpers for gen_helper_prototype
+##
+def_helper_types = {
+    'N' : 's32',
+    'O' : 's32',
+    'P' : 's32',
+    'M' : 's32',
+    'C' : 's32',
+    'R' : 's32',
+    'V' : 'ptr',
+    'Q' : 'ptr'
+}
+
+def_helper_types_pair = {
+    'R' : 's64',
+    'C' : 's64',
+    'S' : 's64',
+    'G' : 's64',
+    'V' : 'ptr',
+    'Q' : 'ptr'
+}
+
+def gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i):
+    if (is_pair(regid)):
+        f.write(", %s" % (def_helper_types_pair[regtype]))
+    elif (is_single(regid)):
+        f.write(", %s" % (def_helper_types[regtype]))
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+##
+## Generate the DEF_HELPER prototype for an instruction
+##     For A2_add: Rd32=add(Rs32,Rt32)
+##     We produce:
+##         #ifndef fWRAP_A2_add
+##         DEF_HELPER_3(A2_add, s32, env, s32, s32)
+##         #endif
+##
+def gen_helper_prototype(f, tag, regs, imms):
+    f.write('#ifndef fWRAP_%s\n' % tag)
+    numresults = 0
+    numscalarresults = 0
+    numscalarreadwrite = 0
+    for regtype,regid,toss,numregs in regs:
+        if (is_written(regid)):
+            numresults += 1
+            if (is_scalar_reg(regtype)):
+                numscalarresults += 1
+        if (is_readwrite(regid)):
+            if (is_scalar_reg(regtype)):
+                numscalarreadwrite += 1
+
+    if (numscalarresults > 1):
+        ## The helper is bogus when there is more than one result
+        f.write('DEF_HELPER_1(%s, void, env)\n' % tag)
+    else:
+        ## Figure out how many arguments the helper will take
+        if (numscalarresults == 0):
+            def_helper_size = len(regs)+len(imms)+numscalarreadwrite+1
+            if need_part1(tag): def_helper_size += 1
+            if need_slot(tag): def_helper_size += 1
+            f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
+            ## The return type is void
+            f.write(', void' )
+        else:
+            def_helper_size = len(regs)+len(imms)+numscalarreadwrite
+            if need_part1(tag): def_helper_size += 1
+            if need_slot(tag): def_helper_size += 1
+            f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
+
+        ## Generate the qemu DEF_HELPER type for each result
+        i=0
+        for regtype,regid,toss,numregs in regs:
+            if (is_written(regid)):
+                gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
+                i += 1
+
+        ## Put the env between the outputs and inputs
+        f.write(', env' )
+        i += 1
+
+        ## Generate the qemu type for each input operand (regs and immediates)
+        for regtype,regid,toss,numregs in regs:
+            if (is_read(regid)):
+                gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
+                i += 1
+        for immlett,bits,immshift in imms:
+            f.write(", s32")
+
+        ## Add the arguments for the instruction slot and part1 (if needed)
+        if need_slot(tag): f.write(', i32' )
+        if need_part1(tag): f.write(' , i32' )
+        f.write(')\n')
+    f.write('#endif\n')
+
+##
+## Helpers for gen_tcg_func
+##
+def gen_decl_ea_tcg(f):
+    f.write("DECL_EA;\n")
+
+def gen_free_ea_tcg(f):
+    f.write("FREE_EA;\n")
+
+def genptr_decl(f,regtype,regid,regno):
+    regN="%s%sN" % (regtype,regid)
+    macro = "DECL_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sV, %s, %d, 0);\n" % \
+        (macro, regtype, regid, regN, regno))
+
+def genptr_decl_new(f,regtype,regid,regno):
+    regN="%s%sX" % (regtype,regid)
+    macro = "DECL_NEW_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sN, %s, %d, 0);\n" % \
+        (macro, regtype, regid, regN, regno))
+
+def genptr_decl_opn(f, tag, regtype, regid, toss, numregs, i):
+    if (is_pair(regid)):
+        genptr_decl(f,regtype,regid,i)
+    elif (is_single(regid)):
+        if is_old_val(regtype, regid, tag):
+            genptr_decl(f,regtype,regid,i)
+        elif is_new_val(regtype, regid, tag):
+            genptr_decl_new(f,regtype,regid,i)
+        else:
+            print("Bad register parse: ",regtype,regid,toss,numregs)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def genptr_decl_imm(f,immlett):
+    if (immlett.isupper()):
+        i = 1
+    else:
+        i = 0
+    f.write("DECL_IMM(%s,%d);\n" % (imm_name(immlett),i))
+
+def genptr_free(f,regtype,regid,regno):
+    macro = "FREE_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sV);\n" % (macro, regtype, regid))
+
+def genptr_free_new(f,regtype,regid,regno):
+    macro = "FREE_NEW_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sN);\n" % (macro, regtype, regid))
+
+def genptr_free_opn(f,regtype,regid,i):
+    if (is_pair(regid)):
+        genptr_free(f,regtype,regid,i)
+    elif (is_single(regid)):
+        if is_old_val(regtype, regid, tag):
+            genptr_free(f,regtype,regid,i)
+        elif is_new_val(regtype, regid, tag):
+            genptr_free_new(f,regtype,regid,i)
+        else:
+            print("Bad register parse: ",regtype,regid,toss,numregs)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def genptr_free_imm(f,immlett):
+    f.write("FREE_IMM(%s);\n" % (imm_name(immlett)))
+
+def genptr_src_read(f,regtype,regid):
+    macro = "READ_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sV, %s%sN);\n" % \
+        (macro,regtype,regid,regtype,regid))
+
+def genptr_src_read_new(f,regtype,regid):
+    macro = "READ_NEW_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sN, %s%sX);\n" % \
+        (macro,regtype,regid,regtype,regid))
+
+def genptr_src_read_opn(f,regtype,regid):
+    if (is_pair(regid)):
+        genptr_src_read(f,regtype,regid)
+    elif (is_single(regid)):
+        if is_old_val(regtype, regid, tag):
+            genptr_src_read(f,regtype,regid)
+        elif is_new_val(regtype, regid, tag):
+            genptr_src_read_new(f,regtype,regid)
+        else:
+            print("Bad register parse: ",regtype,regid,toss,numregs)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i):
+    if (i > 0): f.write(", ")
+    if (is_pair(regid)):
+        f.write("%s%sV" % (regtype,regid))
+    elif (is_single(regid)):
+        if is_old_val(regtype, regid, tag):
+            f.write("%s%sV" % (regtype,regid))
+        elif is_new_val(regtype, regid, tag):
+            f.write("%s%sN" % (regtype,regid))
+        else:
+            print("Bad register parse: ",regtype,regid,toss,numregs)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def gen_helper_decl_imm(f,immlett):
+    f.write("DECL_TCG_IMM(tcgv_%s, %s);\n" % \
+        (imm_name(immlett), imm_name(immlett)))
+
+def gen_helper_call_imm(f,immlett):
+    f.write(", tcgv_%s" % imm_name(immlett))
+
+def gen_helper_free_imm(f,immlett):
+    f.write("FREE_TCG_IMM(tcgv_%s);\n" % imm_name(immlett))
+
+def genptr_dst_write(f,regtype, regid):
+    macro = "WRITE_%sREG_%s" % (regtype, regid)
+    f.write("%s(%s%sN, %s%sV);\n" % (macro, regtype, regid, regtype, regid))
+
+def genptr_dst_write_opn(f,regtype, regid, tag):
+    if (is_pair(regid)):
+        genptr_dst_write(f, regtype, regid)
+    elif (is_single(regid)):
+        genptr_dst_write(f, regtype, regid)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+##
+## Generate the TCG code to call the helper
+##     For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
+##     We produce:
+##       {
+##       /* A2_add */
+##       DECL_RREG_d(RdV, RdN, 0, 0);
+##       DECL_RREG_s(RsV, RsN, 1, 0);
+##       DECL_RREG_t(RtV, RtN, 2, 0);
+##       READ_RREG_s(RsV, RsN);
+##       READ_RREG_t(RtV, RtN);
+##       fWRAP_A2_add(
+##       do {
+##       gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
+##       while (0),
+##       { RdV=RsV+RtV;});
+##       WRITE_RREG_d(RdN, RdV);
+##       FREE_RREG_d(RdV);
+##       FREE_RREG_s(RsV);
+##       FREE_RREG_t(RtV);
+##       /* A2_add */
+##       }
+##
+def gen_tcg_func(f, tag, regs, imms):
+    f.write('{\n')
+    f.write('/* %s */\n' % tag)
+    if need_ea(tag): gen_decl_ea_tcg(f)
+    i=0
+    ## Declare all the operands (regs and immediates)
+    for regtype,regid,toss,numregs in regs:
+        genptr_decl_opn(f, tag, regtype, regid, toss, numregs, i)
+        i += 1
+    for immlett,bits,immshift in imms:
+        genptr_decl_imm(f,immlett)
+
+    if 'A_PRIV' in attribdict[tag]:
+        f.write('fCHECKFORPRIV();\n')
+    if 'A_GUEST' in attribdict[tag]:
+        f.write('fCHECKFORGUEST();\n')
+    if 'A_FPOP' in attribdict[tag]:
+        f.write('fFPOP_START();\n');
+
+    ## Read all the inputs
+    for regtype,regid,toss,numregs in regs:
+        if (is_read(regid)):
+            genptr_src_read_opn(f,regtype,regid)
+
+    ## Generate the call to the helper
+    f.write("fWRAP_%s(\n" % tag)
+    f.write("do {\n")
+    for immlett,bits,immshift in imms:
+        gen_helper_decl_imm(f,immlett)
+    if need_part1(tag): f.write("PART1_WRAP(")
+    if need_slot(tag): f.write("SLOT_WRAP(")
+    f.write("gen_helper_%s(" % (tag))
+    i=0
+    ## If there is a scalar result, it is the return type
+    for regtype,regid,toss,numregs in regs:
+        if (is_written(regid)):
+            gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i)
+            i += 1
+    if (i > 0): f.write(", ")
+    f.write("cpu_env")
+    i=1
+    for regtype,regid,toss,numregs in regs:
+        if (is_read(regid)):
+            gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i)
+            i += 1
+    for immlett,bits,immshift in imms:
+        gen_helper_call_imm(f,immlett)
+
+    if need_slot(tag): f.write(", slot")
+    if need_part1(tag): f.write(", part1" )
+    f.write(")")
+    if need_slot(tag): f.write(")")
+    if need_part1(tag): f.write(")")
+    f.write(";\n")
+    for immlett,bits,immshift in imms:
+        gen_helper_free_imm(f,immlett)
+    f.write("} while (0)")
+    f.write(",\n%s);\n" % semdict[tag] )
+
+    ## Write all the outputs
+    for regtype,regid,toss,numregs in regs:
+        if (is_written(regid)):
+            genptr_dst_write_opn(f,regtype, regid, tag)
+
+    if 'A_FPOP' in attribdict[tag]:
+        f.write('fFPOP_END();\n');
+
+
+    ## Free all the operands (regs and immediates)
+    if need_ea(tag): gen_free_ea_tcg(f)
+    for regtype,regid,toss,numregs in regs:
+        genptr_free_opn(f,regtype,regid,i)
+        i += 1
+    for immlett,bits,immshift in imms:
+        genptr_free_imm(f,immlett)
+
+    f.write("/* %s */\n" % tag)
+    f.write("}")
+
+##
+## Helpers for gen_helper_definition
+##
+def gen_decl_ea(f):
+    f.write("size4u_t EA;\n")
+
+def gen_helper_return_type(f,regtype,regid,regno):
+    if regno > 1 : f.write(", ")
+    f.write("int32_t")
+
+def gen_helper_return_type_pair(f,regtype,regid,regno):
+    if regno > 1 : f.write(", ")
+    f.write("int64_t")
+
+def gen_helper_arg(f,regtype,regid,regno):
+    if regno > 0 : f.write(", " )
+    f.write("int32_t %s%sV" % (regtype,regid))
+
+def gen_helper_arg_new(f,regtype,regid,regno):
+    if regno >= 0 : f.write(", " )
+    f.write("int32_t %s%sN" % (regtype,regid))
+
+def gen_helper_arg_pair(f,regtype,regid,regno):
+    if regno >= 0 : f.write(", ")
+    f.write("int64_t %s%sV" % (regtype,regid))
+
+def gen_helper_arg_opn(f,regtype,regid,i):
+    if (is_pair(regid)):
+        gen_helper_arg_pair(f,regtype,regid,i)
+    elif (is_single(regid)):
+        if is_old_val(regtype, regid, tag):
+            gen_helper_arg(f,regtype,regid,i)
+        elif is_new_val(regtype, regid, tag):
+            gen_helper_arg_new(f,regtype,regid,i)
+        else:
+            print("Bad register parse: ",regtype,regid,toss,numregs)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def gen_helper_arg_imm(f,immlett):
+    f.write(", int32_t %s" % (imm_name(immlett)))
+
+def gen_helper_dest_decl(f,regtype,regid,regno,subfield=""):
+    f.write("int32_t %s%sV%s = 0;\n" % \
+        (regtype,regid,subfield))
+
+def gen_helper_dest_decl_pair(f,regtype,regid,regno,subfield=""):
+    f.write("int64_t %s%sV%s = 0;\n" % \
+        (regtype,regid,subfield))
+
+def gen_helper_dest_decl_opn(f,regtype,regid,i):
+    if (is_pair(regid)):
+        gen_helper_dest_decl_pair(f,regtype,regid,i)
+    elif (is_single(regid)):
+        gen_helper_dest_decl(f,regtype,regid,i)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+def gen_helper_return(f,regtype,regid,regno):
+    f.write("return %s%sV;\n" % (regtype,regid))
+
+def gen_helper_return_pair(f,regtype,regid,regno):
+    f.write("return %s%sV;\n" % (regtype,regid))
+
+def gen_helper_return_opn(f, regtype, regid, i):
+    if (is_pair(regid)):
+        gen_helper_return_pair(f,regtype,regid,i)
+    elif (is_single(regid)):
+        gen_helper_return(f,regtype,regid,i)
+    else:
+        print("Bad register parse: ",regtype,regid,toss,numregs)
+
+##
+## Generate the TCG code to call the helper
+##     For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
+##     We produce:
+##       #ifndef fWRAP_A2_add
+##       int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV)
+##       {
+##       uint32_t slot = 4; slot = slot;
+##       int32_t RdV = 0;
+##       { RdV=RsV+RtV;}
+##       COUNT_HELPER(A2_add);
+##       return RdV;
+##       }
+##       #endif
+##
+def gen_helper_definition(f, tag, regs, imms):
+    f.write('#ifndef fWRAP_%s\n' % tag)
+    numresults = 0
+    numscalarresults = 0
+    numscalarreadwrite = 0
+    for regtype,regid,toss,numregs in regs:
+        if (is_written(regid)):
+            numresults += 1
+            if (is_scalar_reg(regtype)):
+                numscalarresults += 1
+        if (is_readwrite(regid)):
+            if (is_scalar_reg(regtype)):
+                numscalarreadwrite += 1
+
+    if (numscalarresults > 1):
+        ## The helper is bogus when there is more than one result
+        f.write("void HELPER(%s)(CPUHexagonState *env) { BOGUS_HELPER(%s); }\n"
+                % (tag, tag))
+    else:
+        ## The return type of the function is the type of the destination
+        ## register
+        i=0
+        for regtype,regid,toss,numregs in regs:
+            if (is_written(regid)):
+                if (is_pair(regid)):
+                    gen_helper_return_type_pair(f,regtype,regid,i)
+                elif (is_single(regid)):
+                    gen_helper_return_type(f,regtype,regid,i)
+                else:
+                    print("Bad register parse: ",regtype,regid,toss,numregs)
+            i += 1
+
+        if (numscalarresults == 0):
+            f.write("void")
+        f.write(" HELPER(%s)(CPUHexagonState *env" % tag)
+
+        i = 1
+        ## Arguments to the helper function are the source regs and immediates
+        for regtype,regid,toss,numregs in regs:
+            if (is_read(regid)):
+                gen_helper_arg_opn(f,regtype,regid,i)
+                i += 1
+        for immlett,bits,immshift in imms:
+            gen_helper_arg_imm(f,immlett)
+            i += 1
+        if need_slot(tag):
+            if i > 0: f.write(", ")
+            f.write("uint32_t slot")
+            i += 1
+        if need_part1(tag):
+            if i > 0: f.write(", ")
+            f.write("uint32_t part1")
+        f.write(")\n{\n")
+        if (not need_slot(tag)): f.write("uint32_t slot = 4; slot = slot;\n" )
+        if need_ea(tag): gen_decl_ea(f)
+        ## Declare the return variable
+        i=0
+        for regtype,regid,toss,numregs in regs:
+            if (is_writeonly(regid)):
+                gen_helper_dest_decl_opn(f,regtype,regid,i)
+            i += 1
+
+        if 'A_FPOP' in attribdict[tag]:
+            f.write('fFPOP_START();\n');
+
+        f.write(semdict[tag])
+        f.write("\n")
+        f.write("COUNT_HELPER(%s);\n" % tag )
+
+        if 'A_FPOP' in attribdict[tag]:
+            f.write('fFPOP_END();\n');
+
+        ## Save/return the return variable
+        for regtype,regid,toss,numregs in regs:
+            if (is_written(regid)):
+                gen_helper_return_opn(f, regtype, regid, i)
+        f.write("}\n")
+        ## End of the helper definition
+    f.write('#endif\n')
+
+##
+## Bring it all together in the DEF_QEMU macro
+##
+def gen_qemu(f, tag):
+    regs = tagregs[tag]
+    imms = tagimms[tag]
+
+    f.write('DEF_QEMU(%s,%s,\n' % (tag,semdict[tag]))
+    gen_helper_prototype(f, tag, regs, imms)
+    f.write(",\n" )
+    gen_tcg_func(f, tag, regs, imms)
+    f.write(",\n" )
+    gen_helper_definition(f, tag, regs, imms)
+    f.write(")\n")
+
+##
+## Generate the qemu_def_generated.h file
+##
+f = StringIO()
+
+f.write("#ifndef DEF_QEMU\n")
+f.write("#define DEF_QEMU(TAG,SHORTCODE,HELPER,GENFN,HELPFN)   /* Nothing */\n")
+f.write("#endif\n\n")
+
+
+for tag in tags:
+    ## Skip assembler mapped instructions
+    if "A_MAPPING" in attribdict[tag]:
+        continue
+    ## Skip the fake instructions
+    if ( "A_FAKEINSN" in attribdict[tag] ) :
+        continue
+    ## Skip the priv instructions
+    if ( "A_PRIV" in attribdict[tag] ) :
+        continue
+    ## Skip the guest instructions
+    if ( "A_GUEST" in attribdict[tag] ) :
+        continue
+    ## Skip the diag instructions
+    if ( tag == "Y6_diag" ) :
+        continue
+    if ( tag == "Y6_diag0" ) :
+        continue
+    if ( tag == "Y6_diag1" ) :
+        continue
+
+    gen_qemu(f, tag)
+
+realf = open('qemu_def_generated.h','w')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
Signature · 1 line
2.7.4
#25 lore raw

RFC PATCH v2 23/67 Hexagon generator phase 2 - qemu_wrap_generated.h

In reply to Taylor Simpson

Gives a default definition of fWRAP_<tag> for each instruction

---
 target/hexagon/do_qemu.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
target/hexagon/do_qemu.py +14 -0
index 6f0e376..3f52ef3 100755
@@ -767,3 +767,17 @@ realf.write(f.getvalue())
 realf.close()
 f.close()
 
+##
+## Generate the qemu_wrap_generated.h file
+##     Gives a default definition of fWRAP_<tag> for each instruction
+##
+f = StringIO()
+for tag in tags:
+    f.write( "#ifndef fWRAP_%s\n" % tag )
+    f.write( "#define fWRAP_%s(GENHLPR, SHORTCODE) GENHLPR\n" % tag )
+    f.write( "#endif\n\n" )
+realf = open('qemu_wrap_generated.h', 'wt')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
Signature · 1 line
2.7.4
#26 lore raw

RFC PATCH v2 24/67 Hexagon generator phase 2 - opcodes_def_generated.h

In reply to Taylor Simpson

Gives a list of all the opcodes

---
 target/hexagon/do_qemu.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/hexagon/do_qemu.py +12 -0
index 3f52ef3..107e1e8 100755
@@ -781,3 +781,15 @@ realf.write(f.getvalue())
 realf.close()
 f.close()
 
+##
+## Generate the opcodes_def_generated.h file
+##     Gives a list of all the opcodes
+##
+f = StringIO()
+for tag in tags:
+    f.write ( "OPCODE(%s),\n" % (tag) )
+realf = open('opcodes_def_generated.h', 'wt')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
Signature · 1 line
2.7.4
#27 lore raw

RFC PATCH v2 25/67 Hexagon generator phase 2 - op_attribs_generated.h

In reply to Taylor Simpson

Lists all the attributes associated with each instruction

---
 target/hexagon/do_qemu.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
target/hexagon/do_qemu.py +13 -0
index 107e1e8..499f0e0 100755
@@ -793,3 +793,16 @@ realf.write(f.getvalue())
 realf.close()
 f.close()
 
+##
+## Generate the op_attribs_generated.h file
+##     Lists all the attributes associated with each instruction
+##
+f = StringIO()
+for tag in tags:
+    f.write('OP_ATTRIB(%s,ATTRIBS(%s))\n' % \
+        (tag, ','.join(sorted(attribdict[tag]))))
+realf = open('op_attribs_generated.h', 'wt')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
Signature · 1 line
2.7.4
#28 lore raw

RFC PATCH v2 26/67 Hexagon generator phase 2 - op_regs_generated.h

In reply to Taylor Simpson

Lists the register and immediate operands for each instruction

---
 target/hexagon/do_qemu.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
target/hexagon/do_qemu.py +86 -0
index 499f0e0..0c7643a 100755
@@ -806,3 +806,89 @@ realf.write(f.getvalue())
 realf.close()
 f.close()
 
+##
+## Generate the op_regs_generated.h file
+##     Lists the register and immediate operands for each instruction
+##
+def calculate_regid_reg(tag):
+    def letter_inc(x): return chr(ord(x)+1)
+    ordered_implregs = [ 'SP','FP','LR' ]
+    srcdst_lett = 'X'
+    src_lett = 'S'
+    dst_lett = 'D'
+    retstr = ""
+    mapdict = {}
+    for reg in ordered_implregs:
+        reg_rd = 0
+        reg_wr = 0
+        if ('A_IMPLICIT_READS_'+reg) in attribdict[tag]: reg_rd = 1
+        if ('A_IMPLICIT_WRITES_'+reg) in attribdict[tag]: reg_wr = 1
+        if reg_rd and reg_wr:
+            retstr += srcdst_lett
+            mapdict[srcdst_lett] = reg
+            srcdst_lett = letter_inc(srcdst_lett)
+        elif reg_rd:
+            retstr += src_lett
+            mapdict[src_lett] = reg
+            src_lett = letter_inc(src_lett)
+        elif reg_wr:
+            retstr += dst_lett
+            mapdict[dst_lett] = reg
+            dst_lett = letter_inc(dst_lett)
+    return retstr,mapdict
+
+def calculate_regid_letters(tag):
+    retstr,mapdict = calculate_regid_reg(tag)
+    return retstr
+
+def strip_verif_info_in_regs(x):
+    y=x.replace('UREG.','')
+    y=y.replace('MREG.','')
+    return y.replace('GREG.','')
+
+f = StringIO()
+
+for tag in tags:
+    regs = tagregs[tag]
+    rregs = []
+    wregs = []
+    regids = ""
+    for regtype,regid,toss,numregs in regs:
+        if is_read(regid):
+            if regid[0] not in regids: regids += regid[0]
+            rregs.append(regtype+regid+numregs)
+        if is_written(regid):
+            wregs.append(regtype+regid+numregs)
+            if regid[0] not in regids: regids += regid[0]
+    for attrib in attribdict[tag]:
+        if attribinfo[attrib]['rreg']:
+            rregs.append(strip_verif_info_in_regs(attribinfo[attrib]['rreg']))
+        if attribinfo[attrib]['wreg']:
+            wregs.append(strip_verif_info_in_regs(attribinfo[attrib]['wreg']))
+    regids += calculate_regid_letters(tag)
+    f.write('REGINFO(%s,"%s",\t/*RD:*/\t"%s",\t/*WR:*/\t"%s")\n' % \
+        (tag,regids,",".join(rregs),",".join(wregs)))
+
+for tag in tags:
+    imms = tagimms[tag]
+    f.write( 'IMMINFO(%s' % tag)
+    if not imms:
+        f.write(''','u',0,0,'U',0,0''')
+    for sign,size,shamt in imms:
+        if sign == 'r': sign = 's'
+        if not shamt:
+            shamt = "0"
+        f.write(''','%s',%s,%s''' % (sign,size,shamt))
+    if len(imms) == 1:
+        if sign.isupper():
+            myu = 'u'
+        else:
+            myu = 'U'
+        f.write(''','%s',0,0''' % myu)
+    f.write(')\n')
+
+realf = open('op_regs_generated.h','w')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
Signature · 1 line
2.7.4
#29 lore raw

RFC PATCH v2 27/67 Hexagon generator phase 2 - printinsn-generated.h

In reply to Taylor Simpson

Data for printing (disassembling) each instruction (format string + operands)

---
 target/hexagon/do_qemu.py | 151 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)
target/hexagon/do_qemu.py +151 -0
index 0c7643a..32543c8 100755
@@ -892,3 +892,154 @@ realf.write(f.getvalue())
 realf.close()
 f.close()
 
+##
+## Generate the printinsn_generated.h file
+##     Data for printing each instruction (format string + operands)
+##
+def regprinter(m):
+    str = m.group(1)
+    str += ":".join(["%d"]*len(m.group(2)))
+    str += m.group(3)
+    if ('S' in m.group(1)) and (len(m.group(2)) == 1):
+        str += "/%s"
+    elif ('C' in m.group(1)) and (len(m.group(2)) == 1):
+        str += "/%s"
+    return str
+
+# Regular expression that matches any operator that contains '=' character:
+opswithequal_re = '[-+^&|!<>=]?='
+# Regular expression that matches any assignment operator.
+assignment_re = '[-+^&|]?='
+
+# Out of the operators that contain the = sign, if the operator is also an
+# assignment, spaces will be added around it, unless it's enclosed within
+# parentheses, or spaces are already present.
+
+equals = re.compile(opswithequal_re)
+assign = re.compile(assignment_re)
+
+def spacify(s):
+    slen = len(s)
+    paren_count = {}
+    i = 0
+    pc = 0
+    while i < slen:
+        c = s[i]
+        if c == '(':
+            pc += 1
+        elif c == ')':
+            pc -= 1
+        paren_count[i] = pc
+        i += 1
+
+    # Iterate over all operators that contain the equal sign. If any
+    # match is also an assignment operator, add spaces around it if
+    # the parenthesis count is 0.
+    pos = 0
+    out = []
+    for m in equals.finditer(s):
+        ms = m.start()
+        me = m.end()
+        # t is the string that matched opswithequal_re.
+        t = m.string[ms:me]
+        out += s[pos:ms]
+        pos = me
+        if paren_count[ms] == 0:
+            # Check if the entire string t is an assignment.
+            am = assign.match(t)
+            if am and len(am.group(0)) == me-ms:
+                # Don't add spaces if they are already there.
+                if ms > 0 and s[ms-1] != ' ':
+                    out.append(' ')
+                out += t
+                if me < slen and s[me] != ' ':
+                    out.append(' ')
+                continue
+        # If this is not an assignment, just append it to the output
+        # string.
+        out += t
+
+    # Append the remaining part of the string.
+    out += s[pos:len(s)]
+    return ''.join(out)
+
+immext_casere = re.compile(r'IMMEXT\(([A-Za-z])')
+
+f = StringIO()
+
+for tag in tags:
+    if not behdict[tag]: continue
+    extendable_upper_imm = False
+    extendable_lower_imm = False
+    m = immext_casere.search(semdict[tag])
+    if m:
+        if m.group(1).isupper():
+            extendable_upper_imm = True
+        else:
+            extendable_lower_imm = True
+    beh = behdict[tag]
+    beh = regre.sub(regprinter,beh)
+    beh = absimmre.sub(r"#%s0x%x",beh)
+    beh = relimmre.sub(r"PC+%s%d",beh)
+    beh = spacify(beh)
+    # Print out a literal "%s" at the end, used to match empty string
+    # so C won't complain at us
+    if ("A_VECX" in attribdict[tag]): macname = "DEF_VECX_PRINTINFO"
+    else: macname = "DEF_PRINTINFO"
+    f.write('%s(%s,"%s%%s"' % (macname,tag,beh))
+    regs_or_imms = reg_or_immre.findall(behdict[tag])
+    ri = 0
+    seenregs = {}
+    for allregs,a,b,c,d,allimm,immlett,bits,immshift in regs_or_imms:
+        if a:
+            #register
+            if b in seenregs:
+                regno = seenregs[b]
+            else:
+                regno = ri
+            if len(b) == 1:
+                f.write(',REGNO(%d)' % regno)
+                if 'S' in a:
+                    f.write(',sreg2str(REGNO(%d))' % regno)
+                elif 'C' in a:
+                    f.write(',creg2str(REGNO(%d))' % regno)
+            elif len(b) == 2:
+                f.write(',REGNO(%d)+1,REGNO(%d)' % (regno,regno))
+            elif len(b) == 4:
+                f.write(',REGNO(%d)^3,REGNO(%d)^2,REGNO(%d)^1,REGNO(%d)' % \
+                        (regno,regno,regno,regno))
+            else:
+                print("Put some stuff to handle quads here")
+            if b not in seenregs:
+                seenregs[b] = ri
+                ri += 1
+        else:
+            #immediate
+            if (immlett.isupper()):
+                if extendable_upper_imm:
+                    if immlett in 'rR':
+                        f.write(',insn->extension_valid?"##":""')
+                    else:
+                        f.write(',insn->extension_valid?"#":""')
+                else:
+                    f.write(',""')
+                ii = 1
+            else:
+                if extendable_lower_imm:
+                    if immlett in 'rR':
+                        f.write(',insn->extension_valid?"##":""')
+                    else:
+                        f.write(',insn->extension_valid?"#":""')
+                else:
+                    f.write(',""')
+                ii = 0
+            f.write(',IMMNO(%d)' % ii)
+    # append empty string so there is at least one more arg
+    f.write(',"")\n')
+
+realf = open('printinsn_generated.h','w')
+realf.write(f.getvalue())
+realf.close()
+f.close()
+
+
Signature · 1 line
2.7.4
#30 lore raw

RFC PATCH v2 28/67 Hexagon generator phase 3 - C preprocessor for decode tree

In reply to Taylor Simpson

Run the C preprocessor across the instruction definition and encoding files to expand macros and prepare the iset.py file. The resulting fill contains python data structures used to build the decode tree.

---
 target/hexagon/gen_dectree_import.c | 205 ++++++++++++++++++++++++++++++++++++
 1 file changed, 205 insertions(+)
 create mode 100644 target/hexagon/gen_dectree_import.c
target/hexagon/gen_dectree_import.c new file +205 -0
new file mode 100644
index 0000000..4dfd4d4
@@ -0,0 +1,205 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This program generates the encodings file that is processed by
+ * the dectree.py script to produce the decoding tree.  We use the C
+ * preprocessor to manipulate the files imported from the Hexagon
+ * architecture library.
+ */
+#include <stdio.h>
+#include <string.h>
+#include "opcodes.h"
+
+#define STRINGIZE(X)    #X
+
+const char *opcode_names[] = {
+#define OPCODE(IID) STRINGIZE(IID)
+#include "opcodes_def_generated.h"
+    NULL
+#undef OPCODE
+};
+
+char *opcode_syntax[XX_LAST_OPCODE];
+
+/*
+ * Process the instruction definitions
+ *     Scalar core instructions have the following form
+ *         Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(),
+ *         "Add 32-bit registers",
+ *         { RdV=RsV+RtV;})
+ *     HVX instructions have the following form
+ *         EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)",
+ *         ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE),
+ *         "Insert Word Scalar into Vector",
+ *         VxV.uw[0] = RtV;)
+ */
+void opcode_init()
+{
+#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+   opcode_syntax[TAG] = BEH;
+#define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+   opcode_syntax[TAG] = BEH;
+#include "imported/allidefs.def"
+#undef Q6INSN
+#undef EXTINSN
+}
+
+const char *opcode_rregs[] = {
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
+#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)  /* nothing */
+#include "op_regs_generated.h"
+    NULL
+#undef REGINFO
+#undef IMMINFO
+};
+
+const char *opcode_wregs[] = {
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
+#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)  /* nothing */
+#include "op_regs_generated.h"
+    NULL
+#undef REGINFO
+#undef IMMINFO
+};
+
+opcode_encoding_t opcode_encodings[] = {
+#define DEF_ENC32(TAG, ENCSTR) \
+    [TAG] = { .encoding = ENCSTR },
+#define DEF_ENC_SUBINSN(TAG, CLASS, ENCSTR) \
+    [TAG] = { .encoding = ENCSTR, .enc_class = CLASS },
+#define DEF_EXT_ENC(TAG, CLASS, ENCSTR) \
+    [TAG] = { .encoding = ENCSTR, .enc_class = CLASS },
+#include "imported/encode.def"
+#undef DEF_ENC32
+#undef DEF_ENC_SUBINSN
+#undef DEF_EXT_ENC
+};
+
+static const char * const opcode_enc_class_names[XX_LAST_ENC_CLASS] = {
+    "NORMAL",
+    "16BIT",
+    "SUBINSN_A",
+    "SUBINSN_L1",
+    "SUBINSN_L2",
+    "SUBINSN_S1",
+    "SUBINSN_S2",
+    "EXT_noext",
+    "EXT_mmvec",
+};
+
+static const char *get_opcode_enc(int opcode)
+{
+    const char *tmp = opcode_encodings[opcode].encoding;
+    if (tmp == NULL) {
+        tmp = "MISSING ENCODING";
+    }
+    return tmp;
+}
+
+static const char *get_opcode_enc_class(int opcode)
+{
+    const char *tmp = opcode_encodings[opcode].encoding;
+    if (tmp == NULL) {
+        char *test = "V6_";        /* HVX */
+        char *name = (char *)opcode_names[opcode];
+        if (strncmp(name, test, strlen(test)) == 0) {
+            return "EXT_mmvec";
+        }
+    }
+    return opcode_enc_class_names[opcode_encodings[opcode].enc_class];
+}
+
+static void gen_iset_table(FILE *out)
+{
+    int i;
+
+    fprintf(out, "iset = {\n");
+    for (i = 0; i < XX_LAST_OPCODE; i++) {
+        fprintf(out, "\t\'%s\' : {\n", opcode_names[i]);
+        fprintf(out, "\t\t\'tag\' : \'%s\',\n", opcode_names[i]);
+        fprintf(out, "\t\t\'syntax\' : \'%s\',\n", opcode_syntax[i]);
+        fprintf(out, "\t\t\'rregs\' : \'%s\',\n", opcode_rregs[i]);
+        fprintf(out, "\t\t\'wregs\' : \'%s\',\n", opcode_wregs[i]);
+        fprintf(out, "\t\t\'enc\' : \'%s\',\n", get_opcode_enc(i));
+        fprintf(out, "\t\t\'enc_class\' : \'%s\',\n", get_opcode_enc_class(i));
+        fprintf(out, "\t},\n");
+    }
+    fprintf(out, "};\n\n");
+}
+
+static void gen_tags_list(FILE *out)
+{
+    int i;
+
+    fprintf(out, "tags = [\n");
+    for (i = 0; i < XX_LAST_OPCODE; i++) {
+        fprintf(out, "\t\'%s\',\n", opcode_names[i]);
+    }
+    fprintf(out, "];\n\n");
+}
+
+static void gen_enc_ext_spaces_table(FILE *out)
+{
+    fprintf(out, "enc_ext_spaces = {\n");
+#define DEF_EXT_SPACE(SPACEID, ENCSTR) \
+    fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR);
+#include "imported/encode.def"
+#undef DEF_EXT_SPACE
+    fprintf(out, "};\n\n");
+}
+
+static void gen_subinsn_groupings_table(FILE *out)
+{
+    fprintf(out, "subinsn_groupings = {\n");
+#define DEF_PACKED32(TAG, TYPEA, TYPEB, ENCSTR) \
+    do { \
+        fprintf(out, "\t\'%s\' : {\n", #TAG); \
+        fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \
+        fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \
+        fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \
+        fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \
+        fprintf(out, "\t},\n"); \
+    } while (0);
+#include "imported/encode.def"
+#undef DEF_PACKED32
+    fprintf(out, "};\n\n");
+}
+
+int main(int argc, char *argv[])
+{
+    FILE *outfile;
+
+    if (argc != 2) {
+        fprintf(stderr, "Usage: gen_dectree_import ouptputfile\n");
+        return -1;
+    }
+    outfile = fopen(argv[1], "w");
+    if (outfile == NULL) {
+        fprintf(stderr, "Cannot open %s for writing\n", argv[1]);
+        return -1;
+    }
+
+    opcode_init();
+    gen_iset_table(outfile);
+    gen_tags_list(outfile);
+    gen_enc_ext_spaces_table(outfile);
+    gen_subinsn_groupings_table(outfile);
+
+    fclose(outfile);
+    return 0;
+}
Signature · 1 line
2.7.4
#31 lore raw

RFC PATCH v2 29/67 Hexagon generater phase 4 - Decode tree

In reply to Taylor Simpson

Python script that emits the decode tree in dectree_generated.h.

---
 target/hexagon/dectree.py | 353 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 353 insertions(+)
 create mode 100755 target/hexagon/dectree.py
target/hexagon/dectree.py new file +353 -0
new file mode 100755
index 0000000..2b9c82b
@@ -0,0 +1,353 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+##
+##  This program is free software; you can redistribute it and/or modify
+##  it under the terms of the GNU General Public License as published by
+##  the Free Software Foundation; either version 2 of the License, or
+##  (at your option) any later version.
+##
+##  This program is distributed in the hope that it will be useful,
+##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+##  GNU General Public License for more details.
+##
+##  You should have received a copy of the GNU General Public License
+##  along with this program; if not, see <http://www.gnu.org/licenses/>.
+##
+
+import io
+import re
+
+import sys
+sys.path.insert(0, sys.argv[1])
+import iset
+
+encs = {tag : ''.join(reversed(iset.iset[tag]['enc'].replace(' ', '')))
+    for tag in iset.tags if iset.iset[tag]['enc'] != 'MISSING ENCODING'}
+
+enc_classes = set([iset.iset[tag]['enc_class'] for tag in encs.keys()])
+subinsn_enc_classes = \
+    set([enc_class for enc_class in enc_classes \
+        if enc_class.startswith('SUBINSN_')])
+ext_enc_classes = \
+    set([enc_class for enc_class in enc_classes \
+        if enc_class not in ('NORMAL', '16BIT') and \
+           not enc_class.startswith('SUBINSN_')])
+
+try:
+    subinsn_groupings = iset.subinsn_groupings
+except AttributeError:
+    subinsn_groupings = {}
+
+for (tag, subinsn_grouping) in subinsn_groupings.items():
+    encs[tag] = ''.join(reversed(subinsn_grouping['enc'].replace(' ', '')))
+
+dectree_normal = {'leaves' : set()}
+dectree_16bit = {'leaves' : set()}
+dectree_subinsn_groupings = {'leaves' : set()}
+dectree_subinsns = {name : {'leaves' : set()} for name in subinsn_enc_classes}
+dectree_extensions = {name : {'leaves' : set()} for name in ext_enc_classes}
+
+for tag in encs.keys():
+    if tag in subinsn_groupings:
+        dectree_subinsn_groupings['leaves'].add(tag)
+        continue
+    enc_class = iset.iset[tag]['enc_class']
+    if enc_class.startswith('SUBINSN_'):
+        if len(encs[tag]) != 32:
+            encs[tag] = encs[tag] + '0' * (32 - len(encs[tag]))
+        dectree_subinsns[enc_class]['leaves'].add(tag)
+    elif  enc_class == '16BIT':
+        if len(encs[tag]) != 16:
+            raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' +
+                            'width of 16 bits!'.format(tag, enc_class))
+        dectree_16bit['leaves'].add(tag)
+    else:
+        if len(encs[tag]) != 32:
+            raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' +
+                            'width of 32 bits!'.format(tag, enc_class))
+        if enc_class == 'NORMAL':
+            dectree_normal['leaves'].add(tag)
+        else:
+            dectree_extensions[enc_class]['leaves'].add(tag)
+
+faketags = set()
+for (tag, enc) in iset.enc_ext_spaces.items():
+    faketags.add(tag)
+    encs[tag] = ''.join(reversed(enc.replace(' ', '')))
+    dectree_normal['leaves'].add(tag)
+
+faketags |= set(subinsn_groupings.keys())
+
+def every_bit_counts(bitset):
+    for i in range(1, len(next(iter(bitset)))):
+        if len(set([bits[:i] + bits[i+1:] for bits in bitset])) == len(bitset):
+            return False
+    return True
+
+def auto_separate(node):
+    tags = node['leaves']
+    if len(tags) <= 1:
+        return
+    enc_width = len(encs[next(iter(tags))])
+    opcode_bit_for_all = \
+        [all([encs[tag][i] in '01' \
+            for tag in tags]) for i in range(enc_width)]
+    opcode_bit_is_0_for_all = \
+        [opcode_bit_for_all[i] and all([encs[tag][i] == '0' \
+            for tag in tags]) for i in range(enc_width)]
+    opcode_bit_is_1_for_all = \
+        [opcode_bit_for_all[i] and all([encs[tag][i] == '1' \
+            for tag in tags]) for i in range(enc_width)]
+    differentiator_opcode_bit = \
+        [opcode_bit_for_all[i] and \
+         not (opcode_bit_is_0_for_all[i] or \
+         opcode_bit_is_1_for_all[i]) \
+            for i in range(enc_width)]
+    best_width = 0
+    for width in range(4, 0, -1):
+        for lsb in range(enc_width - width, -1, -1):
+            bitset = set([encs[tag][lsb:lsb+width] for tag in tags])
+            if all(differentiator_opcode_bit[lsb:lsb+width]) and \
+                (len(bitset) == len(tags) or every_bit_counts(bitset)):
+                best_width = width
+                best_lsb = lsb
+                caught_all_tags = len(bitset) == len(tags)
+                break
+        if best_width != 0:
+            break
+    if best_width == 0:
+        raise Exception('Could not find a way to differentiate the encodings ' +
+                         'of the following tags:\n{}'.format('\n'.join(tags)))
+    if caught_all_tags:
+        for width in range(1, best_width):
+            for lsb in range(enc_width - width, -1, -1):
+                bitset = set([encs[tag][lsb:lsb+width] for tag in tags])
+                if all(differentiator_opcode_bit[lsb:lsb+width]) and \
+                    len(bitset) == len(tags):
+                    best_width = width
+                    best_lsb = lsb
+                    break
+            else:
+                continue
+            break
+    node['separator_lsb'] = best_lsb
+    node['separator_width'] = best_width
+    node['children'] = []
+    for value in range(2 ** best_width):
+        child = {}
+        bits = ''.join(reversed('{:0{}b}'.format(value, best_width)))
+        child['leaves'] = \
+            set([tag for tag in tags \
+                if encs[tag][best_lsb:best_lsb+best_width] == bits])
+        node['children'].append(child)
+    for child in node['children']:
+        auto_separate(child)
+
+auto_separate(dectree_normal)
+auto_separate(dectree_16bit)
+if subinsn_groupings:
+    auto_separate(dectree_subinsn_groupings)
+for dectree_subinsn in dectree_subinsns.values():
+    auto_separate(dectree_subinsn)
+for dectree_ext in dectree_extensions.values():
+    auto_separate(dectree_ext)
+
+for tag in faketags:
+    del encs[tag]
+
+def table_name(parents, node):
+    path = parents + [node]
+    root = path[0]
+    tag = next(iter(node['leaves']))
+    if tag in subinsn_groupings:
+        enc_width = len(subinsn_groupings[tag]['enc'].replace(' ', ''))
+    else:
+        tag = next(iter(node['leaves'] - faketags))
+        enc_width = len(encs[tag])
+    determining_bits = ['_'] * enc_width
+    for (parent, child) in zip(path[:-1], path[1:]):
+        lsb = parent['separator_lsb']
+        width = parent['separator_width']
+        value = parent['children'].index(child)
+        determining_bits[lsb:lsb+width] = \
+            list(reversed('{:0{}b}'.format(value, width)))
+    if tag in subinsn_groupings:
+        name = 'DECODE_ROOT_EE'
+    else:
+        enc_class = iset.iset[tag]['enc_class']
+        if enc_class in ext_enc_classes:
+            name = 'DECODE_EXT_{}'.format(enc_class)
+        elif enc_class in subinsn_enc_classes:
+            name = 'DECODE_SUBINSN_{}'.format(enc_class)
+        else:
+            name = 'DECODE_ROOT_{}'.format(enc_width)
+    if node != root:
+        name += '_' + ''.join(reversed(determining_bits))
+    return name
+
+def print_node(f, node, parents):
+    if len(node['leaves']) <= 1:
+        return
+    name = table_name(parents, node)
+    lsb = node['separator_lsb']
+    width = node['separator_width']
+    print('DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\
+        format(name, 2 ** width, lsb, width), file=f)
+    for child in node['children']:
+        if len(child['leaves']) == 0:
+            print('INVALID()', file=f)
+        elif len(child['leaves']) == 1:
+            (tag,) = child['leaves']
+            if tag in subinsn_groupings:
+                class_a = subinsn_groupings[tag]['class_a']
+                class_b = subinsn_groupings[tag]['class_b']
+                enc = subinsn_groupings[tag]['enc'].replace(' ', '')
+                if 'RESERVED' in tag:
+                    print('INVALID()', file=f)
+                else:
+                    print('SUBINSNS({},{},{},"{}")'.\
+                        format(tag, class_a, class_b, enc), file=f)
+            elif tag in iset.enc_ext_spaces:
+                enc = iset.enc_ext_spaces[tag].replace(' ', '')
+                print('EXTSPACE({},"{}")'.format(tag, enc), file=f)
+            else:
+                enc = ''.join(reversed(encs[tag]))
+                print('TERMINAL({},"{}")'.format(tag, enc), file=f)
+        else:
+            print('TABLE_LINK({})'.format(table_name(parents + [node], child)),
+                  file=f)
+    print('DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\
+        format(name, 2 ** width, lsb, width), file=f)
+    print(file=f)
+    parents.append(node)
+    for child in node['children']:
+        print_node(f, child, parents)
+    parents.pop()
+
+def print_tree(f, tree):
+    print_node(f, tree, [])
+
+def print_match_info(f):
+    for tag in sorted(encs.keys(), key=iset.tags.index):
+        enc = ''.join(reversed(encs[tag]))
+        mask = int(re.sub(r'[^1]', r'0', enc.replace('0', '1')), 2)
+        match = int(re.sub(r'[^01]', r'0', enc), 2)
+        suffix = ''
+        print('DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)'.\
+            format(suffix, tag, mask, match), file=f)
+
+regre = re.compile(
+    r'((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)')
+immre = re.compile(r'[#]([rRsSuUm])(\d+)(?:[:](\d+))?')
+
+def ordered_unique(l):
+    return sorted(set(l), key=l.index)
+
+implicit_registers = {
+    'SP' : 29,
+    'FP' : 30,
+    'LR' : 31
+}
+
+num_registers = {
+    'R' : 32,
+    'V' : 32
+}
+
+def print_op_info(f):
+    for tag in sorted(encs.keys(), key=iset.tags.index):
+        enc = encs[tag]
+        print(file=f)
+        print('DECODE_OPINFO({},'.format(tag), file=f)
+        regs = ordered_unique(regre.findall(iset.iset[tag]['syntax']))
+        imms = ordered_unique(immre.findall(iset.iset[tag]['syntax']))
+        regno = 0
+        for reg in regs:
+            reg_type = reg[0]
+            reg_letter = reg[1][0]
+            reg_num_choices = int(reg[3].rstrip('S'))
+            reg_mapping = reg[0] + ''.join(['_' for letter in reg[1]]) + reg[3]
+            reg_enc_fields = re.findall(reg_letter + '+', enc)
+            if len(reg_enc_fields) == 0:
+                raise Exception('Tag "{}" missing register field!'.format(tag))
+            if len(reg_enc_fields) > 1:
+                raise Exception('Tag "{}" has split register field!'.\
+                    format(tag))
+            reg_enc_field = reg_enc_fields[0]
+            if 2 ** len(reg_enc_field) != reg_num_choices:
+                raise Exception('Tag "{}" has incorrect register field width!'.\
+                    format(tag))
+            print('        DECODE_REG({},{},{})'.\
+                format(regno, len(reg_enc_field), enc.index(reg_enc_field)),
+                       file=f)
+            if reg_type in num_registers and \
+                reg_num_choices != num_registers[reg_type]:
+                print('        DECODE_MAPPED_REG({},{})'.\
+                    format(regno, reg_mapping), file=f)
+            regno += 1
+        def implicit_register_key(reg):
+            return implicit_registers[reg]
+        for reg in sorted(
+            set([r for r in (iset.iset[tag]['rregs'].split(',') + \
+                iset.iset[tag]['wregs'].split(',')) \
+                    if r in implicit_registers]), key=implicit_register_key):
+            print('        DECODE_IMPL_REG({},{})'.\
+                format(regno, implicit_registers[reg]), file=f)
+            regno += 1
+        if imms and imms[0][0].isupper():
+            imms = reversed(imms)
+        for imm in imms:
+            if imm[0].isupper():
+                immno = 1
+            else:
+                immno = 0
+            imm_type = imm[0]
+            imm_width = int(imm[1])
+            imm_shift = imm[2]
+            if imm_shift:
+                imm_shift = int(imm_shift)
+            else:
+                imm_shift = 0
+            if imm_type.islower():
+                imm_letter = 'i'
+            else:
+                imm_letter = 'I'
+            remainder = imm_width
+            for m in reversed(list(re.finditer(imm_letter + '+', enc))):
+                remainder -= m.end() - m.start()
+                print('        DECODE_IMM({},{},{},{})'.\
+                    format(immno, m.end() - m.start(), m.start(), remainder),
+                        file=f)
+            if remainder != 0:
+                if imm[2]:
+                    imm[2] = ':' + imm[2]
+                raise Exception('Tag "{}" has an incorrect number of ' + \
+                    'encoding bits for immediate "{}"'.\
+                    format(tag, ''.join(imm)))
+            if imm_type.lower() in 'sr':
+                print('        DECODE_IMM_SXT({},{})'.\
+                    format(immno, imm_width), file=f)
+            if imm_type.lower() == 'n':
+                print('        DECODE_IMM_NEG({},{})'.\
+                    format(immno, imm_width), file=f)
+            if imm_shift:
+                print('        DECODE_IMM_SHIFT({},{})'.\
+                    format(immno, imm_shift), file=f)
+        print(')', file=f)
+
+if __name__ == '__main__':
+    f = io.StringIO()
+    print_tree(f, dectree_normal)
+    print_tree(f, dectree_16bit)
+    if subinsn_groupings:
+        print_tree(f, dectree_subinsn_groupings)
+    for (name, dectree_subinsn) in sorted(dectree_subinsns.items()):
+        print_tree(f, dectree_subinsn)
+    for (name, dectree_ext) in sorted(dectree_extensions.items()):
+        print_tree(f, dectree_ext)
+    print_match_info(f)
+    print_op_info(f)
+    open('dectree_generated.h', 'w').write(f.getvalue())
Signature · 1 line
2.7.4
#32 lore raw

RFC PATCH v2 30/67 Hexagon opcode data structures

In reply to Taylor Simpson
---
 target/hexagon/opcodes.h |  67 +++++++++++++++
 target/hexagon/opcodes.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 284 insertions(+)
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/opcodes.c
target/hexagon/opcodes.h new file +67 -0
new file mode 100644
index 0000000..d29a1a2
@@ -0,0 +1,67 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_OPCODES_H
+#define HEXAGON_OPCODES_H
+
+#include "hex_arch_types.h"
+#include "attribs.h"
+
+typedef enum {
+#define OPCODE(IID) IID
+#include "opcodes_def_generated.h"
+    XX_LAST_OPCODE
+#undef OPCODE
+} opcode_t;
+
+typedef enum {
+    NORMAL,
+    HALF,
+    SUBINSN_A,
+    SUBINSN_L1,
+    SUBINSN_L2,
+    SUBINSN_S1,
+    SUBINSN_S2,
+    EXT_noext,
+    EXT_mmvec,
+    XX_LAST_ENC_CLASS
+} enc_class_t;
+
+extern const char *opcode_names[];
+
+extern const char *opcode_reginfo[];
+extern const char *opcode_rregs[];
+extern const char *opcode_wregs[];
+
+typedef struct {
+    const char * const encoding;
+    size4u_t vals;
+    size4u_t dep_vals;
+    const enc_class_t enc_class;
+    size1u_t is_ee:1;
+} opcode_encoding_t;
+
+extern opcode_encoding_t opcode_encodings[XX_LAST_OPCODE];
+
+extern size4u_t
+    opcode_attribs[XX_LAST_OPCODE][(A_ZZ_LASTATTRIB / ATTRIB_WIDTH) + 1];
+
+extern void opcode_init(void);
+
+extern int opcode_which_immediate_is_extended(opcode_t opcode);
+
+#endif
target/hexagon/opcodes.c new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
2.7.4
#33 lore raw

RFC PATCH v2 31/67 Hexagon macros to interface with the generator

In reply to Taylor Simpson

Various forms of declare, read, write, free

---
 target/hexagon/macros.h | 363 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 363 insertions(+)
 create mode 100644 target/hexagon/macros.h
target/hexagon/macros.h new file +363 -0
new file mode 100644
index 0000000..b8f8d9f
@@ -0,0 +1,363 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_MACROS_H
+#define HEXAGON_MACROS_H
+
+#include "cpu.h"
+#include "hex_regs.h"
+#include "reg_fields.h"
+
+#ifdef QEMU_GENERATE
+#define DECL_REG(NAME, NUM, X, OFF) \
+    TCGv NAME = tcg_temp_local_new(); \
+    int NUM = REGNO(X) + OFF
+
+#define DECL_REG_WRITABLE(NAME, NUM, X, OFF) \
+    TCGv NAME = tcg_temp_local_new(); \
+    int NUM = REGNO(X) + OFF; \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        if (is_predicated && !is_preloaded(ctx, NUM)) { \
+            tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \
+        } \
+    } while (0)
+/*
+ * For read-only temps, avoid allocating and freeing
+ */
+#define DECL_REG_READONLY(NAME, NUM, X, OFF) \
+    TCGv NAME; \
+    int NUM = REGNO(X) + OFF
+
+#define DECL_RREG_d(NAME, NUM, X, OFF) \
+    DECL_REG_WRITABLE(NAME, NUM, X, OFF)
+#define DECL_RREG_e(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+#define DECL_RREG_s(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_RREG_t(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_RREG_u(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_RREG_v(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_RREG_x(NAME, NUM, X, OFF) \
+    DECL_REG_WRITABLE(NAME, NUM, X, OFF)
+#define DECL_RREG_y(NAME, NUM, X, OFF) \
+    DECL_REG_WRITABLE(NAME, NUM, X, OFF)
+
+#define DECL_PREG_d(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+#define DECL_PREG_e(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+#define DECL_PREG_s(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_PREG_t(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_PREG_u(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_PREG_v(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_PREG_x(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+#define DECL_PREG_y(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+
+#define DECL_CREG_d(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+#define DECL_CREG_s(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+
+#define DECL_MREG_u(NAME, NUM, X, OFF) \
+    DECL_REG(NAME, NUM, X, OFF)
+
+#define DECL_NEW_NREG_s(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_NEW_NREG_t(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+
+#define DECL_NEW_PREG_t(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_NEW_PREG_u(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+#define DECL_NEW_PREG_v(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+
+#define DECL_NEW_OREG_s(NAME, NUM, X, OFF) \
+    DECL_REG_READONLY(NAME, NUM, X, OFF)
+
+#define DECL_PAIR(NAME, NUM, X, OFF) \
+    TCGv_i64 NAME = tcg_temp_local_new_i64(); \
+    size1u_t NUM = REGNO(X) + OFF
+
+#define DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) \
+    TCGv_i64 NAME = tcg_temp_local_new_i64(); \
+    size1u_t NUM = REGNO(X) + OFF; \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        if (is_predicated) { \
+            if (!is_preloaded(ctx, NUM)) { \
+                tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \
+            } \
+            if (!is_preloaded(ctx, NUM + 1)) { \
+                tcg_gen_mov_tl(hex_new_value[NUM + 1], hex_gpr[NUM + 1]); \
+            } \
+        } \
+    } while (0)
+
+#define DECL_RREG_dd(NAME, NUM, X, OFF) \
+    DECL_PAIR_WRITABLE(NAME, NUM, X, OFF)
+#define DECL_RREG_ss(NAME, NUM, X, OFF) \
+    DECL_PAIR(NAME, NUM, X, OFF)
+#define DECL_RREG_tt(NAME, NUM, X, OFF) \
+    DECL_PAIR(NAME, NUM, X, OFF)
+#define DECL_RREG_xx(NAME, NUM, X, OFF) \
+    DECL_PAIR_WRITABLE(NAME, NUM, X, OFF)
+#define DECL_RREG_yy(NAME, NUM, X, OFF) \
+    DECL_PAIR_WRITABLE(NAME, NUM, X, OFF)
+
+#define DECL_CREG_dd(NAME, NUM, X, OFF) \
+    DECL_PAIR_WRITABLE(NAME, NUM, X, OFF)
+#define DECL_CREG_ss(NAME, NUM, X, OFF) \
+    DECL_PAIR(NAME, NUM, X, OFF)
+
+#define DECL_IMM(NAME, X) \
+    int NAME = IMMNO(X); \
+    do { \
+        NAME = NAME; \
+    } while (0)
+#define DECL_TCG_IMM(TCG_NAME, VAL) \
+    TCGv TCG_NAME = tcg_const_tl(VAL)
+
+#define DECL_EA \
+    TCGv EA; \
+    do { \
+        if (GET_ATTRIB(insn->opcode, A_CONDEXEC)) { \
+            EA = tcg_temp_local_new(); \
+        } else { \
+            EA = tcg_temp_new(); \
+        } \
+    } while (0)
+
+#define LOG_REG_WRITE(RNUM, VAL)\
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        gen_log_reg_write(RNUM, VAL, insn->slot, is_predicated); \
+        ctx_log_reg_write(ctx, (RNUM)); \
+    } while (0)
+
+#define LOG_PRED_WRITE(PNUM, VAL) \
+    do { \
+        gen_log_pred_write(PNUM, VAL); \
+        ctx_log_pred_write(ctx, (PNUM)); \
+    } while (0)
+
+#define FREE_REG(NAME) \
+    tcg_temp_free(NAME)
+#define FREE_REG_READONLY(NAME) \
+    /* Nothing */
+
+#define FREE_RREG_d(NAME)            FREE_REG(NAME)
+#define FREE_RREG_e(NAME)            FREE_REG(NAME)
+#define FREE_RREG_s(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_RREG_t(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_RREG_u(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_RREG_v(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_RREG_x(NAME)            FREE_REG(NAME)
+#define FREE_RREG_y(NAME)            FREE_REG(NAME)
+
+#define FREE_PREG_d(NAME)            FREE_REG(NAME)
+#define FREE_PREG_e(NAME)            FREE_REG(NAME)
+#define FREE_PREG_s(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_PREG_t(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_PREG_u(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_PREG_v(NAME)            FREE_REG_READONLY(NAME)
+#define FREE_PREG_x(NAME)            FREE_REG(NAME)
+
+#define FREE_CREG_d(NAME)            FREE_REG(NAME)
+#define FREE_CREG_s(NAME)            FREE_REG_READONLY(NAME)
+
+#define FREE_MREG_u(NAME)            FREE_REG_READONLY(NAME)
+
+#define FREE_NEW_NREG_s(NAME)        FREE_REG(NAME)
+#define FREE_NEW_NREG_t(NAME)        FREE_REG(NAME)
+
+#define FREE_NEW_PREG_t(NAME)        FREE_REG_READONLY(NAME)
+#define FREE_NEW_PREG_u(NAME)        FREE_REG_READONLY(NAME)
+#define FREE_NEW_PREG_v(NAME)        FREE_REG_READONLY(NAME)
+
+#define FREE_NEW_OREG_s(NAME)        FREE_REG(NAME)
+
+#define FREE_REG_PAIR(NAME) \
+    tcg_temp_free_i64(NAME)
+
+#define FREE_RREG_dd(NAME)           FREE_REG_PAIR(NAME)
+#define FREE_RREG_ss(NAME)           FREE_REG_PAIR(NAME)
+#define FREE_RREG_tt(NAME)           FREE_REG_PAIR(NAME)
+#define FREE_RREG_xx(NAME)           FREE_REG_PAIR(NAME)
+#define FREE_RREG_yy(NAME)           FREE_REG_PAIR(NAME)
+
+#define FREE_CREG_dd(NAME)           FREE_REG_PAIR(NAME)
+#define FREE_CREG_ss(NAME)           FREE_REG_PAIR(NAME)
+
+#define FREE_IMM(NAME)               /* nothing */
+#define FREE_TCG_IMM(NAME)           tcg_temp_free(NAME)
+
+#define FREE_EA \
+    tcg_temp_free(EA)
+#else
+#define LOG_REG_WRITE(RNUM, VAL)\
+  log_reg_write(env, RNUM, VAL, slot)
+#define LOG_PRED_WRITE(RNUM, VAL)\
+    log_pred_write(env, RNUM, VAL)
+#endif
+
+#define SLOT_WRAP(CODE) \
+    do { \
+        TCGv slot = tcg_const_tl(insn->slot); \
+        CODE; \
+        tcg_temp_free(slot); \
+    } while (0)
+
+#define PART1_WRAP(CODE) \
+    do { \
+        TCGv part1 = tcg_const_tl(insn->part1); \
+        CODE; \
+        tcg_temp_free(part1); \
+    } while (0)
+
+#define MARK_LATE_PRED_WRITE(RNUM) /* Not modelled in qemu */
+
+#define REGNO(NUM) (insn->regno[NUM])
+#define IMMNO(NUM) (insn->immed[NUM])
+
+#ifdef QEMU_GENERATE
+#define READ_REG(dest, NUM) \
+    gen_read_reg(dest, NUM)
+#define READ_REG_READONLY(dest, NUM) \
+    do { dest = hex_gpr[NUM]; } while (0)
+
+#define READ_RREG_s(dest, NUM) \
+    READ_REG_READONLY(dest, NUM)
+#define READ_RREG_t(dest, NUM) \
+    READ_REG_READONLY(dest, NUM)
+#define READ_RREG_u(dest, NUM) \
+    READ_REG_READONLY(dest, NUM)
+#define READ_RREG_x(dest, NUM) \
+    READ_REG(dest, NUM)
+#define READ_RREG_y(dest, NUM) \
+    READ_REG(dest, NUM)
+
+#define READ_OREG_s(dest, NUM) \
+    READ_REG_READONLY(dest, NUM)
+
+#define READ_CREG_s(dest, NUM) \
+    do { \
+        if ((NUM) + HEX_REG_SA0 == HEX_REG_P3_0) { \
+            gen_read_p3_0(dest); \
+        } else { \
+            READ_REG_READONLY(dest, ((NUM) + HEX_REG_SA0)); \
+        } \
+    } while (0)
+
+#define READ_MREG_u(dest, NUM) \
+    do { \
+        READ_REG_READONLY(dest, ((NUM) + HEX_REG_M0)); \
+        dest = dest; \
+    } while (0)
+#else
+#define READ_REG(NUM) \
+    (env->gpr[(NUM)])
+#endif
+
+#ifdef QEMU_GENERATE
+#define READ_REG_PAIR(tmp, NUM) \
+    tcg_gen_concat_i32_i64(tmp, hex_gpr[NUM], hex_gpr[(NUM) + 1])
+#define READ_RREG_ss(tmp, NUM)          READ_REG_PAIR(tmp, NUM)
+#define READ_RREG_tt(tmp, NUM)          READ_REG_PAIR(tmp, NUM)
+#define READ_RREG_xx(tmp, NUM)          READ_REG_PAIR(tmp, NUM)
+#define READ_RREG_yy(tmp, NUM)          READ_REG_PAIR(tmp, NUM)
+
+#define READ_CREG_PAIR(tmp, i) \
+    READ_REG_PAIR(tmp, ((i) + HEX_REG_SA0))
+#define READ_CREG_ss(tmp, i)            READ_CREG_PAIR(tmp, i)
+#endif
+
+#ifdef QEMU_GENERATE
+#define READ_PREG(dest, NUM)             gen_read_preg(dest, (NUM))
+#define READ_PREG_READONLY(dest, NUM)    do { dest = hex_pred[NUM]; } while (0)
+
+#define READ_PREG_s(dest, NUM)           READ_PREG_READONLY(dest, NUM)
+#define READ_PREG_t(dest, NUM)           READ_PREG_READONLY(dest, NUM)
+#define READ_PREG_u(dest, NUM)           READ_PREG_READONLY(dest, NUM)
+#define READ_PREG_v(dest, NUM)           READ_PREG_READONLY(dest, NUM)
+#define READ_PREG_x(dest, NUM)           READ_PREG(dest, NUM)
+
+#define READ_NEW_PREG(pred, PNUM) \
+    do { pred = hex_new_pred_value[PNUM]; } while (0)
+#define READ_NEW_PREG_t(pred, PNUM)      READ_NEW_PREG(pred, PNUM)
+#define READ_NEW_PREG_u(pred, PNUM)      READ_NEW_PREG(pred, PNUM)
+#define READ_NEW_PREG_v(pred, PNUM)      READ_NEW_PREG(pred, PNUM)
+
+#define READ_NEW_REG(tmp, i) \
+    do { tmp = tcg_const_tl(i); } while (0)
+#define READ_NEW_NREG_s(tmp, i)          READ_NEW_REG(tmp, i)
+#define READ_NEW_NREG_t(tmp, i)          READ_NEW_REG(tmp, i)
+#define READ_NEW_OREG_s(tmp, i)          READ_NEW_REG(tmp, i)
+#else
+#define READ_PREG(NUM)                (env->pred[NUM])
+#endif
+
+
+#define WRITE_RREG(NUM, VAL)             LOG_REG_WRITE(NUM, VAL)
+#define WRITE_RREG_d(NUM, VAL)           LOG_REG_WRITE(NUM, VAL)
+#define WRITE_RREG_e(NUM, VAL)           LOG_REG_WRITE(NUM, VAL)
+#define WRITE_RREG_x(NUM, VAL)           LOG_REG_WRITE(NUM, VAL)
+#define WRITE_RREG_y(NUM, VAL)           LOG_REG_WRITE(NUM, VAL)
+
+#define WRITE_PREG(NUM, VAL)             LOG_PRED_WRITE(NUM, VAL)
+#define WRITE_PREG_d(NUM, VAL)           LOG_PRED_WRITE(NUM, VAL)
+#define WRITE_PREG_e(NUM, VAL)           LOG_PRED_WRITE(NUM, VAL)
+#define WRITE_PREG_x(NUM, VAL)           LOG_PRED_WRITE(NUM, VAL)
+
+#ifdef QEMU_GENERATE
+#define WRITE_CREG(i, tmp) \
+    do { \
+        if (i + HEX_REG_SA0 == HEX_REG_P3_0) { \
+            gen_write_p3_0(tmp); \
+        } else { \
+            WRITE_RREG((i) + HEX_REG_SA0, tmp); \
+        } \
+    } while (0)
+#define WRITE_CREG_d(NUM, VAL)           WRITE_CREG(NUM, VAL)
+
+#define WRITE_CREG_PAIR(i, tmp)          WRITE_REG_PAIR((i) + HEX_REG_SA0, tmp)
+#define WRITE_CREG_dd(NUM, VAL)          WRITE_CREG_PAIR(NUM, VAL)
+
+#define WRITE_REG_PAIR(NUM, VAL) \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        gen_log_reg_write_pair(NUM, VAL, insn->slot, is_predicated); \
+        ctx_log_reg_write(ctx, (NUM)); \
+        ctx_log_reg_write(ctx, (NUM) + 1); \
+    } while (0)
+
+#define WRITE_RREG_dd(NUM, VAL)          WRITE_REG_PAIR(NUM, VAL)
+#define WRITE_RREG_xx(NUM, VAL)          WRITE_REG_PAIR(NUM, VAL)
+#define WRITE_RREG_yy(NUM, VAL)          WRITE_REG_PAIR(NUM, VAL)
+#endif
+
Signature · 1 line
2.7.4
#34 lore raw

RFC PATCH v2 32/67 Hexagon macros referenced in instruction semantics

In reply to Taylor Simpson
---
 target/hexagon/macros.h | 1111 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 1111 insertions(+)
target/hexagon/macros.h +1111 -0
index b8f8d9f..2101a01 100644
@@ -361,3 +361,1114 @@
 #define WRITE_RREG_yy(NUM, VAL)          WRITE_REG_PAIR(NUM, VAL)
 #endif
 
+#define PCALIGN 4
+#define PCALIGN_MASK (PCALIGN - 1)
+
+#define GET_FIELD(FIELD, REGIN) \
+    fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \
+                   reg_field_info[FIELD].offset)
+
+#ifdef QEMU_GENERATE
+#define GET_USR_FIELD(FIELD, DST) \
+    tcg_gen_extract_tl(DST, hex_gpr[HEX_REG_USR], \
+                       reg_field_info[FIELD].offset, \
+                       reg_field_info[FIELD].width)
+
+#define SET_USR_FIELD_FUNC(X) \
+    _Generic((X), int : gen_set_usr_fieldi, TCGv : gen_set_usr_field)
+#define SET_USR_FIELD(FIELD, VAL) \
+    SET_USR_FIELD_FUNC(VAL)(FIELD, VAL)
+#else
+#define GET_USR_FIELD(FIELD) \
+    fEXTRACTU_BITS(env->gpr[HEX_REG_USR], reg_field_info[FIELD].width, \
+                   reg_field_info[FIELD].offset)
+
+#define SET_USR_FIELD(FIELD, VAL) \
+    fINSERT_BITS(env->gpr[HEX_REG_USR], reg_field_info[FIELD].width, \
+                 reg_field_info[FIELD].offset, (VAL))
+#endif
+
+#ifdef QEMU_GENERATE
+#define MEM_LOAD1s(DST, VA)       tcg_gen_qemu_ld8s(DST, VA, ctx->mem_idx)
+#define MEM_LOAD1u(DST, VA)       tcg_gen_qemu_ld8u(DST, VA, ctx->mem_idx)
+#define MEM_LOAD2s(DST, VA)       tcg_gen_qemu_ld16s(DST, VA, ctx->mem_idx)
+#define MEM_LOAD2u(DST, VA)       tcg_gen_qemu_ld16u(DST, VA, ctx->mem_idx)
+#define MEM_LOAD4s(DST, VA)       tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx)
+#define MEM_LOAD4u(DST, VA)       tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx)
+#define MEM_LOAD8s(DST, VA)       tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx)
+#define MEM_LOAD8u(DST, VA)       tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx)
+
+#define MEM_STORE1_FUNC(X) \
+    _Generic((X), int : gen_store1i, TCGv_i32 : gen_store1)
+#define MEM_STORE1(VA, DATA, SLOT) \
+    MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+
+#define MEM_STORE2_FUNC(X) \
+    _Generic((X), int : gen_store2i, TCGv_i32 : gen_store2)
+#define MEM_STORE2(VA, DATA, SLOT) \
+    MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+
+#define MEM_STORE4_FUNC(X) \
+    _Generic((X), int : gen_store4i, TCGv_i32 : gen_store4)
+#define MEM_STORE4(VA, DATA, SLOT) \
+    MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+
+#define MEM_STORE8_FUNC(X) \
+    _Generic((X), int64_t : gen_store8i, TCGv_i64 : gen_store8)
+#define MEM_STORE8(VA, DATA, SLOT) \
+    MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT)
+
+#else
+/*
+ * These should never be executed, but they are needed so the helpers will
+ * compile.  All the instructions with loads must be implemented under
+ * QEMU_GENERATE.
+ */
+static inline uint8_t mem_load1(CPUHexagonState *env, target_ulong vaddr)
+{
+    printf("ERROR: mem_load1\n");
+    g_assert_not_reached();
+}
+
+static inline uint16_t mem_load2(CPUHexagonState *env, target_ulong vadd)
+{
+    printf("ERROR: mem_load2\n");
+    g_assert_not_reached();
+}
+
+static inline uint32_t mem_load4(CPUHexagonState *env, target_ulong vaddr)
+{
+    printf("ERROR: mem_load4\n");
+    g_assert_not_reached();
+}
+
+static inline uint64_t mem_load8(CPUHexagonState *env, target_ulong vaddr)
+{
+    printf("ERROR: mem_load8\n");
+    g_assert_not_reached();
+}
+
+static inline
+uint32_t mem_load_locked4(CPUHexagonState *env, target_ulong vaddr)
+{
+    printf("ERROR: load_locked4\n");
+    g_assert_not_reached();
+    return 0;
+}
+
+static inline
+uint64_t mem_load_locked8(CPUHexagonState *env, target_ulong vaddr)
+{
+    printf("ERROR: load_locked8\n");
+    g_assert_not_reached();
+    return 0;
+}
+
+static inline
+uint8_t mem_store_conditional(CPUHexagonState *env,
+                              target_ulong vaddr, uint32_t src, int size)
+{
+    printf("ERROR: store conditional\n");
+    g_assert_not_reached();
+    return 0;
+}
+
+#define MEM_LOAD1s(VA) ((size1s_t)mem_load1(env, VA))
+#define MEM_LOAD1u(VA) ((size1u_t)mem_load1(env, VA))
+#define MEM_LOAD2s(VA) ((size2s_t)mem_load2(env, VA))
+#define MEM_LOAD2u(VA) ((size2u_t)mem_load2(env, VA))
+#define MEM_LOAD4s(VA) ((size4s_t)mem_load4(env, VA))
+#define MEM_LOAD4u(VA) ((size4u_t)mem_load4(env, VA))
+#define MEM_LOAD8s(VA) ((size8s_t)mem_load8(env, VA))
+#define MEM_LOAD8u(VA) ((size8u_t)mem_load8(env, VA))
+
+#define MEM_STORE1(VA, DATA, SLOT) log_store32(env, VA, DATA, 1, SLOT)
+#define MEM_STORE2(VA, DATA, SLOT) log_store32(env, VA, DATA, 2, SLOT)
+#define MEM_STORE4(VA, DATA, SLOT) log_store32(env, VA, DATA, 4, SLOT)
+#define MEM_STORE8(VA, DATA, SLOT) log_store64(env, VA, DATA, 8, SLOT)
+#endif
+
+
+#ifdef QEMU_GENERATE
+static inline void gen_slot_cancelled_check(TCGv check, int slot_num)
+{
+    TCGv mask = tcg_const_tl(1 << slot_num);
+    TCGv one = tcg_const_tl(1);
+    TCGv zero = tcg_const_tl(0);
+
+    tcg_gen_and_tl(mask, hex_slot_cancelled, mask);
+    tcg_gen_movcond_tl(TCG_COND_NE, check, mask, zero, one, zero);
+
+    tcg_temp_free(one);
+    tcg_temp_free(zero);
+    tcg_temp_free(mask);
+}
+
+static inline void gen_cancel(TCGv slot)
+{
+    TCGv one = tcg_const_tl(1);
+    TCGv mask = tcg_temp_new();
+    tcg_gen_shl_tl(mask, one, slot);
+    tcg_gen_or_tl(hex_slot_cancelled, hex_slot_cancelled, mask);
+    tcg_temp_free(one);
+    tcg_temp_free(mask);
+}
+
+#define CANCEL gen_cancel(slot);
+#else
+#define CANCEL cancel_slot(env, slot)
+#endif
+
+#define STORE_ZERO
+#define LOAD_CANCEL(EA) do { CANCEL; } while (0)
+
+#ifdef QEMU_GENERATE
+static inline void gen_pred_cancel(TCGv pred, int slot_num)
+ {
+    TCGv slot_mask = tcg_const_tl(1 << slot_num);
+    TCGv tmp = tcg_temp_new();
+    TCGv zero = tcg_const_tl(0);
+    TCGv one = tcg_const_tl(1);
+    tcg_gen_or_tl(slot_mask, hex_slot_cancelled, slot_mask);
+    tcg_gen_andi_tl(tmp, pred, 1);
+    tcg_gen_movcond_tl(TCG_COND_EQ, hex_slot_cancelled, tmp, zero,
+                       slot_mask, hex_slot_cancelled);
+    tcg_temp_free(slot_mask);
+    tcg_temp_free(tmp);
+    tcg_temp_free(zero);
+    tcg_temp_free(one);
+}
+#define PRED_LOAD_CANCEL(PRED, EA) \
+    gen_pred_cancel(PRED, insn->is_endloop ? 4 : insn->slot)
+
+#define PRED_STORE_CANCEL(PRED, EA) \
+    gen_pred_cancel(PRED, insn->is_endloop ? 4 : insn->slot)
+#else
+#define STORE_CANCEL(EA) { env->slot_cancelled |= (1 << slot); }
+#endif
+
+#define IS_CANCELLED(SLOT)
+#define fMAX(A, B) (((A) > (B)) ? (A) : (B))
+
+#ifdef QEMU_GENERATE
+#define fMIN(DST, A, B) tcg_gen_movcond_i32(TCG_COND_GT, DST, A, B, A, B)
+#else
+#define fMIN(A, B) (((A) < (B)) ? (A) : (B))
+#endif
+
+#define fABS(A) (((A) < 0) ? (-(A)) : (A))
+#define fINSERT_BITS(REG, WIDTH, OFFSET, INVAL) \
+    do { \
+        REG = ((REG) & ~(((fCONSTLL(1) << (WIDTH)) - 1) << (OFFSET))) | \
+           (((INVAL) & ((fCONSTLL(1) << (WIDTH)) - 1)) << (OFFSET)); \
+    } while (0)
+#define fEXTRACTU_BITS(INREG, WIDTH, OFFSET) \
+    (fZXTN(WIDTH, 32, (INREG >> OFFSET)))
+#define fEXTRACTU_BIDIR(INREG, WIDTH, OFFSET) \
+    (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8)))
+#define fEXTRACTU_RANGE(INREG, HIBIT, LOWBIT) \
+    (fZXTN((HIBIT - LOWBIT + 1), 32, (INREG >> LOWBIT)))
+#define fINSERT_RANGE(INREG, HIBIT, LOWBIT, INVAL) \
+    do { \
+        int offset = LOWBIT; \
+        int width = HIBIT - LOWBIT + 1; \
+        INREG &= ~(((fCONSTLL(1) << width) - 1) << offset); \
+        INREG |= ((INVAL & ((fCONSTLL(1) << width) - 1)) << offset); \
+    } while (0)
+
+#ifdef QEMU_GENERATE
+#define f8BITSOF(RES, VAL) gen_8bitsof(RES, VAL)
+#define fLSBOLD(VAL) tcg_gen_andi_tl(LSB, (VAL), 1)
+#else
+#define f8BITSOF(VAL) ((VAL) ? 0xff : 0x00)
+#define fLSBOLD(VAL)  ((VAL) & 1)
+#endif
+
+#ifdef QEMU_GENERATE
+#define fLSBNEW(PVAL)   tcg_gen_mov_tl(LSB, (PVAL))
+#define fLSBNEW0        fLSBNEW(0)
+#define fLSBNEW1        fLSBNEW(1)
+#else
+#define fLSBNEW(PVAL)   (PVAL)
+#define fLSBNEW0        new_pred_value(env, 0)
+#define fLSBNEW1        new_pred_value(env, 1)
+#endif
+
+#ifdef QEMU_GENERATE
+static inline void gen_logical_not(TCGv dest, TCGv src)
+{
+    TCGv one = tcg_const_tl(1);
+    TCGv zero = tcg_const_tl(0);
+
+    tcg_gen_movcond_tl(TCG_COND_NE, dest, src, zero, zero, one);
+
+    tcg_temp_free(one);
+    tcg_temp_free(zero);
+}
+#define fLSBOLDNOT(VAL) \
+    do { \
+        tcg_gen_andi_tl(LSB, (VAL), 1); \
+        tcg_gen_xori_tl(LSB, LSB, 1); \
+    } while (0)
+#define fLSBNEWNOT(PNUM) \
+    gen_logical_not(LSB, (PNUM))
+#define fLSBNEW0NOT \
+    do { \
+        tcg_gen_mov_tl(LSB, hex_new_pred_value[0]); \
+        gen_logical_not(LSB, LSB); \
+    } while (0)
+#define fLSBNEW1NOT \
+    do { \
+        tcg_gen_mov_tl(LSB, hex_new_pred_value[1]); \
+        gen_logical_not(LSB, LSB); \
+    } while (0)
+#else
+#define fLSBNEWNOT(PNUM) (!fLSBNEW(PNUM))
+#define fLSBOLDNOT(VAL) (!fLSBOLD(VAL))
+#define fLSBNEW0NOT (!fLSBNEW0)
+#define fLSBNEW1NOT (!fLSBNEW1)
+#endif
+
+#define fNEWREG(RNUM) HELPER(new_value)(env, RNUM)
+
+#ifdef QEMU_GENERATE
+#define fNEWREG_ST(RNUM) gen_newreg_st(NEWREG_ST, cpu_env, RNUM)
+#else
+#define fNEWREG_ST(RNUM) HELPER(new_value)(env, RNUM)
+#endif
+
+#define fMEMZNEW(RNUM) (RNUM == 0)
+#define fMEMNZNEW(RNUM) (RNUM != 0)
+#define fVSATUVALN(N, VAL) \
+    ({ \
+        (((int)(VAL)) < 0) ? 0 : ((1LL << (N)) - 1); \
+    })
+#define fSATUVALN(N, VAL) \
+    ({ \
+        fSET_OVERFLOW(); \
+        ((VAL) < 0) ? 0 : ((1LL << (N)) - 1); \
+    })
+#define fSATVALN(N, VAL) \
+    ({ \
+        fSET_OVERFLOW(); \
+        ((VAL) < 0) ? (-(1LL << ((N) - 1))) : ((1LL << ((N) - 1)) - 1); \
+    })
+#define fVSATVALN(N, VAL) \
+    ({ \
+        ((VAL) < 0) ? (-(1LL << ((N) - 1))) : ((1LL << ((N) - 1)) - 1); \
+    })
+#define fZXTN(N, M, VAL) ((VAL) & ((1LL << (N)) - 1))
+#define fSXTN(N, M, VAL) \
+    ((fZXTN(N, M, VAL) ^ (1LL << ((N) - 1))) - (1LL << ((N) - 1)))
+#define fSATN(N, VAL) \
+    ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATVALN(N, VAL))
+#define fVSATN(N, VAL) \
+    ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fVSATVALN(N, VAL))
+#define fADDSAT64(DST, A, B) \
+    do { \
+        size8u_t __a = fCAST8u(A); \
+        size8u_t __b = fCAST8u(B); \
+        size8u_t __sum = __a + __b; \
+        size8u_t __xor = __a ^ __b; \
+        const size8u_t __mask = 0x8000000000000000ULL; \
+        if (__xor & __mask) { \
+            DST = __sum; \
+        } \
+        else if ((__a ^ __sum) & __mask) { \
+            if (__sum & __mask) { \
+                DST = 0x7FFFFFFFFFFFFFFFLL; \
+                fSET_OVERFLOW(); \
+            } else { \
+                DST = 0x8000000000000000LL; \
+                fSET_OVERFLOW(); \
+            } \
+        } else { \
+            DST = __sum; \
+        } \
+    } while (0)
+#define fVSATUN(N, VAL) \
+    ((fZXTN(N, 64, VAL) == (VAL)) ? (VAL) : fVSATUVALN(N, VAL))
+#define fSATUN(N, VAL) \
+    ((fZXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATUVALN(N, VAL))
+#define fSATH(VAL) (fSATN(16, VAL))
+#define fSATUH(VAL) (fSATUN(16, VAL))
+#define fVSATH(VAL) (fVSATN(16, VAL))
+#define fVSATUH(VAL) (fVSATUN(16, VAL))
+#define fSATUB(VAL) (fSATUN(8, VAL))
+#define fSATB(VAL) (fSATN(8, VAL))
+#define fVSATUB(VAL) (fVSATUN(8, VAL))
+#define fVSATB(VAL) (fVSATN(8, VAL))
+#define fIMMEXT(IMM) (IMM = IMM)
+#define fMUST_IMMEXT(IMM) fIMMEXT(IMM)
+
+#define fPCALIGN(IMM) IMM = (IMM & ~PCALIGN_MASK)
+
+#define fGET_EXTENSION (insn->extension)
+
+#ifdef QEMU_GENERATE
+static inline TCGv gen_read_ireg(TCGv tmp, TCGv val, int shift)
+{
+    /*
+     *  #define fREAD_IREG(VAL) \
+     *      (fSXTN(11, 64, (((VAL) & 0xf0000000)>>21) | ((VAL >> 17) & 0x7f)))
+     */
+    tcg_gen_sari_tl(tmp, val, 17);
+    tcg_gen_andi_tl(tmp, tmp, 0x7f);
+    tcg_gen_shli_tl(tmp, tmp, shift);
+    return tmp;
+}
+#define fREAD_IREG(VAL, SHIFT) gen_read_ireg(ireg, (VAL), (SHIFT))
+#define fREAD_R0() (READ_REG(tmp, 0))
+#define fREAD_LR() (READ_REG(tmp, HEX_REG_LR))
+#define fREAD_SSR() (READ_REG(tmp, HEX_REG_SSR))
+#else
+#define fREAD_IREG(VAL) \
+    (fSXTN(11, 64, (((VAL) & 0xf0000000) >> 21) | ((VAL >> 17) & 0x7f)))
+#define fREAD_R0() (READ_REG(0))
+#define fREAD_LR() (READ_REG(HEX_REG_LR))
+#define fREAD_SSR() (READ_REG(HEX_REG_SSR))
+#endif
+
+#define fWRITE_R0(A) WRITE_RREG(0, A)
+#define fWRITE_LR(A) WRITE_RREG(HEX_REG_LR, A)
+#define fWRITE_FP(A) WRITE_RREG(HEX_REG_FP, A)
+#define fWRITE_SP(A) WRITE_RREG(HEX_REG_SP, A)
+#define fWRITE_GOSP(A) WRITE_RREG(HEX_REG_GOSP, A)
+#define fWRITE_GP(A) WRITE_RREG(HEX_REG_GP, A)
+
+#ifdef QEMU_GENERATE
+#define fREAD_SP() (READ_REG(tmp, HEX_REG_SP))
+#define fREAD_GOSP() (READ_REG(tmp, HEX_REG_GOSP))
+#define fREAD_GELR() (READ_REG(tmp, HEX_REG_GELR))
+#define fREAD_GEVB() (READ_REG(tmp, HEX_REG_GEVB))
+#define fREAD_CSREG(N) (READ_REG(tmp, HEX_REG_CS0 + N))
+#define fREAD_LC0 (READ_REG(tmp, HEX_REG_LC0))
+#define fREAD_LC1 (READ_REG(tmp, HEX_REG_LC1))
+#define fREAD_SA0 (READ_REG(tmp, HEX_REG_SA0))
+#define fREAD_SA1 (READ_REG(tmp, HEX_REG_SA1))
+#define fREAD_FP() (READ_REG(tmp, HEX_REG_FP))
+#define fREAD_GP() (READ_REG(tmp, HEX_REG_GP))
+#define fREAD_PC() (READ_REG(tmp, HEX_REG_PC))
+#else
+#define fREAD_SP() (READ_REG(HEX_REG_SP))
+#define fREAD_GOSP() (READ_REG(HEX_REG_GOSP))
+#define fREAD_GELR() (READ_REG(HEX_REG_GELR))
+#define fREAD_GEVB() (READ_REG(HEX_REG_GEVB))
+#define fREAD_CSREG(N) (READ_REG(HEX_REG_CS0 + N))
+#define fREAD_LC0 (READ_REG(HEX_REG_LC0))
+#define fREAD_LC1 (READ_REG(HEX_REG_LC1))
+#define fREAD_SA0 (READ_REG(HEX_REG_SA0))
+#define fREAD_SA1 (READ_REG(HEX_REG_SA1))
+#define fREAD_FP() (READ_REG(HEX_REG_FP))
+#define fREAD_GP() (READ_REG(HEX_REG_GP))
+#define fREAD_PC() (READ_REG(HEX_REG_PC))
+#endif
+
+#define fREAD_NPC() (env->next_PC & (0xfffffffe))
+
+#ifdef QEMU_GENERATE
+#define fREAD_P0() (READ_PREG(tmp, 0))
+#define fREAD_P3() (READ_PREG(tmp, 3))
+#define fNOATTRIB_READ_P3() (READ_PREG(tmp, 3))
+#else
+#define fREAD_P0() (READ_PREG(0))
+#define fREAD_P3() (READ_PREG(3))
+#define fNOATTRIB_READ_P3() (READ_PREG(3))
+#endif
+
+#define fCHECK_PCALIGN(A)
+#define fCUREXT() GET_SSR_FIELD(SSR_XA)
+#define fCUREXT_WRAP(EXT_NO)
+
+#ifdef QEMU_GENERATE
+#define fWRITE_NPC(A) gen_write_new_pc(A)
+#else
+#define fWRITE_NPC(A) write_new_pc(env, A)
+#endif
+
+#define fLOOPSTATS(A)
+#define fCOF_CALLBACK(LOC, TYPE)
+#define fBRANCH(LOC, TYPE) \
+    do { \
+        fWRITE_NPC(LOC); \
+        fCOF_CALLBACK(LOC, TYPE); \
+    } while (0)
+#define fJUMPR(REGNO, TARGET, TYPE) fBRANCH(TARGET, COF_TYPE_JUMPR)
+#define fHINTJR(TARGET) { }
+#define fBP_RAS_CALL(A)
+#define fCALL(A) \
+    do { \
+        fWRITE_LR(fREAD_NPC()); \
+        fBRANCH(A, COF_TYPE_CALL); \
+    } while (0)
+#define fCALLR(A) \
+    do { \
+        fWRITE_LR(fREAD_NPC()); \
+        fBRANCH(A, COF_TYPE_CALLR); \
+    } while (0)
+#define fWRITE_LOOP_REGS0(START, COUNT) \
+    do { \
+        WRITE_RREG(HEX_REG_LC0, COUNT);  \
+        WRITE_RREG(HEX_REG_SA0, START); \
+    } while (0)
+#define fWRITE_LOOP_REGS1(START, COUNT) \
+    do { \
+        WRITE_RREG(HEX_REG_LC1, COUNT);  \
+        WRITE_RREG(HEX_REG_SA1, START);\
+    } while (0)
+#define fWRITE_LC0(VAL) WRITE_RREG(HEX_REG_LC0, VAL)
+#define fWRITE_LC1(VAL) WRITE_RREG(HEX_REG_LC1, VAL)
+
+#ifdef QEMU_GENERATE
+#define fCARRY_FROM_ADD(A, B, C) gen_carry_from_add64(tmp_i64, A, B, C)
+#else
+#define fCARRY_FROM_ADD(A, B, C) carry_from_add64(A, B, C)
+#endif
+
+#define fSETCV_ADD(A, B, CARRY) \
+    do { \
+        SET_USR_FIELD(USR_C, gen_carry_add((A), (B), ((A) + (B)))); \
+        SET_USR_FIELD(USR_V, gen_overflow_add((A), (B), ((A) + (B)))); \
+    } while (0)
+#define fSETCV_SUB(A, B, CARRY) \
+    do { \
+        SET_USR_FIELD(USR_C, gen_carry_add((A), (B), ((A) - (B)))); \
+        SET_USR_FIELD(USR_V, gen_overflow_add((A), (B), ((A) - (B)))); \
+    } while (0)
+#define fSET_OVERFLOW() SET_USR_FIELD(USR_OVF, 1)
+#define fSET_LPCFG(VAL) SET_USR_FIELD(USR_LPCFG, (VAL))
+#define fGET_LPCFG (GET_USR_FIELD(USR_LPCFG))
+#define fWRITE_P0(VAL) WRITE_PREG(0, VAL)
+#define fWRITE_P1(VAL) WRITE_PREG(1, VAL)
+#define fWRITE_P2(VAL) WRITE_PREG(2, VAL)
+#define fWRITE_P3(VAL) WRITE_PREG(3, VAL)
+#define fWRITE_P3_LATE(VAL) WRITE_PREG(3, VAL)
+#define fPART1(WORK) if (part1) { WORK; return; }
+#define fCAST4u(A) ((size4u_t)(A))
+#define fCAST4s(A) ((size4s_t)(A))
+#define fCAST8u(A) ((size8u_t)(A))
+#define fCAST8s(A) ((size8s_t)(A))
+#define fCAST2_2s(A) ((size2s_t)(A))
+#define fCAST2_2u(A) ((size2u_t)(A))
+#define fCAST4_4s(A) ((size4s_t)(A))
+#define fCAST4_4u(A) ((size4u_t)(A))
+#define fCAST4_8s(A) ((size8s_t)((size4s_t)(A)))
+#define fCAST4_8u(A) ((size8u_t)((size4u_t)(A)))
+#define fCAST8_8s(A) ((size8s_t)(A))
+#define fCAST8_8u(A) ((size8u_t)(A))
+#define fCAST2_8s(A) ((size8s_t)((size2s_t)(A)))
+#define fCAST2_8u(A) ((size8u_t)((size2u_t)(A)))
+#define fZE8_16(A) ((size2s_t)((size1u_t)(A)))
+#define fSE8_16(A) ((size2s_t)((size1s_t)(A)))
+#define fSE16_32(A) ((size4s_t)((size2s_t)(A)))
+#define fZE16_32(A) ((size4u_t)((size2u_t)(A)))
+#define fSE32_64(A) ((size8s_t)((size4s_t)(A)))
+#define fZE32_64(A) ((size8u_t)((size4u_t)(A)))
+#define fSE8_32(A) ((size4s_t)((size1s_t)(A)))
+#define fZE8_32(A) ((size4s_t)((size1u_t)(A)))
+#define fMPY8UU(A, B) (int)(fZE8_16(A) * fZE8_16(B))
+#define fMPY8US(A, B) (int)(fZE8_16(A) * fSE8_16(B))
+#define fMPY8SU(A, B) (int)(fSE8_16(A) * fZE8_16(B))
+#define fMPY8SS(A, B) (int)((short)(A) * (short)(B))
+#define fMPY16SS(A, B) fSE32_64(fSE16_32(A) * fSE16_32(B))
+#define fMPY16UU(A, B) fZE32_64(fZE16_32(A) * fZE16_32(B))
+#define fMPY16SU(A, B) fSE32_64(fSE16_32(A) * fZE16_32(B))
+#define fMPY16US(A, B) fMPY16SU(B, A)
+#define fMPY32SS(A, B) (fSE32_64(A) * fSE32_64(B))
+#define fMPY32UU(A, B) (fZE32_64(A) * fZE32_64(B))
+#define fMPY32SU(A, B) (fSE32_64(A) * fZE32_64(B))
+#define fMPY3216SS(A, B) (fSE32_64(A) * fSXTN(16, 64, B))
+#define fMPY3216SU(A, B) (fSE32_64(A) * fZXTN(16, 64, B))
+#define fROUND(A) (A + 0x8000)
+#define fCLIP(DST, SRC, U) \
+    do { \
+        size4s_t maxv = (1 << U) - 1; \
+        size4s_t minv = -(1 << U); \
+        DST = fMIN(maxv, fMAX(SRC, minv)); \
+    } while (0)
+#define fCRND(A) ((((A) & 0x3) == 0x3) ? ((A) + 1) : ((A)))
+#define fRNDN(A, N) ((((N) == 0) ? (A) : (((fSE32_64(A)) + (1 << ((N) - 1))))))
+#define fCRNDN(A, N) (conv_round(A, N))
+#define fCRNDN64(A, N) (conv_round64(A, N))
+#define fADD128(A, B) (add128(A, B))
+#define fSUB128(A, B) (sub128(A, B))
+#define fSHIFTR128(A, B) (shiftr128(A, B))
+#define fSHIFTL128(A, B) (shiftl128(A, B))
+#define fAND128(A, B) (and128(A, B))
+#define fCAST8S_16S(A) (cast8s_to_16s(A))
+#define fCAST16S_8S(A) (cast16s_to_8s(A))
+#define fCAST16S_4S(A) (cast16s_to_4s(A))
+
+#ifdef QEMU_GENERATE
+#define fEA_RI(REG, IMM) tcg_gen_addi_tl(EA, REG, IMM)
+#define fEA_RRs(REG, REG2, SCALE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_shli_tl(tmp, REG2, SCALE); \
+        tcg_gen_add_tl(EA, REG, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+#define fEA_IRs(IMM, REG, SCALE) \
+    do { \
+        tcg_gen_shli_tl(EA, REG, SCALE); \
+        tcg_gen_addi_tl(EA, EA, IMM); \
+    } while (0)
+#else
+#define fEA_RI(REG, IMM) \
+    do { \
+        EA = REG + IMM; \
+        fDOCHKPAGECROSS(REG, EA); \
+    } while (0)
+#define fEA_RRs(REG, REG2, SCALE) \
+    do { \
+        EA = REG + (REG2 << SCALE); \
+        fDOCHKPAGECROSS(REG, EA); \
+    } while (0)
+#define fEA_IRs(IMM, REG, SCALE) \
+    do { \
+        EA = IMM + (REG << SCALE); \
+        fDOCHKPAGECROSS(IMM, EA); \
+    } while (0)
+#endif
+
+#ifdef QEMU_GENERATE
+#define fEA_IMM(IMM) tcg_gen_movi_tl(EA, IMM)
+#define fEA_REG(REG) tcg_gen_mov_tl(EA, REG)
+static inline void gen_fbrev(TCGv result, TCGv src)
+{
+    TCGv result_hi = tcg_temp_new();
+    TCGv result_lo = tcg_temp_new();
+    TCGv tmp1 = tcg_temp_new();
+    TCGv tmp2 = tcg_temp_new();
+    int i;
+
+    /*
+     *  Bit reverse the low 16 bits of the address
+     */
+    tcg_gen_andi_tl(result_hi, src, 0xffff0000);
+    tcg_gen_movi_tl(result_lo, 0);
+    tcg_gen_mov_tl(tmp1, src);
+    for (i = 0; i < 16; i++) {
+        /*
+         * result_lo = (result_lo << 1) | (tmp1 & 1);
+         * tmp1 >>= 1;
+         */
+        tcg_gen_shli_tl(result_lo, result_lo, 1);
+        tcg_gen_andi_tl(tmp2, tmp1, 1);
+        tcg_gen_or_tl(result_lo, result_lo, tmp2);
+        tcg_gen_sari_tl(tmp1, tmp1, 1);
+    }
+    tcg_gen_or_tl(result, result_hi, result_lo);
+
+    tcg_temp_free(result_hi);
+    tcg_temp_free(result_lo);
+    tcg_temp_free(tmp1);
+    tcg_temp_free(tmp2);
+}
+static inline void gen_fcircadd(TCGv reg, TCGv incr, TCGv M, TCGv start_addr)
+{
+    TCGv length = tcg_temp_new();
+    TCGv new_ptr = tcg_temp_new();
+    TCGv end_addr = tcg_temp_new();
+    TCGv tmp = tcg_temp_new();
+
+    tcg_gen_andi_tl(length, M, 0x1ffff);
+    tcg_gen_add_tl(new_ptr, reg, incr);
+    tcg_gen_add_tl(end_addr, start_addr, length);
+
+    tcg_gen_sub_tl(tmp, new_ptr, length);
+    tcg_gen_movcond_tl(TCG_COND_GE, new_ptr, new_ptr, end_addr, tmp, new_ptr);
+    tcg_gen_add_tl(tmp, new_ptr, length);
+    tcg_gen_movcond_tl(TCG_COND_LT, new_ptr, new_ptr, start_addr, tmp, new_ptr);
+
+    tcg_gen_mov_tl(reg, new_ptr);
+
+    tcg_temp_free(length);
+    tcg_temp_free(new_ptr);
+    tcg_temp_free(end_addr);
+    tcg_temp_free(tmp);
+}
+
+#define fEA_BREVR(REG)      gen_fbrev(EA, REG)
+#define fEA_GPI(IMM)        tcg_gen_addi_tl(EA, fREAD_GP(), IMM)
+#define fPM_I(REG, IMM)     tcg_gen_addi_tl(REG, REG, IMM)
+#define fPM_M(REG, MVAL)    tcg_gen_add_tl(REG, REG, MVAL)
+#else
+#define fEA_IMM(IMM) EA = IMM
+#define fEA_REG(REG) EA = REG
+#define fEA_GPI(IMM) \
+    do { \
+        EA = fREAD_GP() + IMM; \
+        fGP_DOCHKPAGECROSS(fREAD_GP(), EA); \
+    } while (0)
+#define fPM_I(REG, IMM) \
+    do { \
+        REG = REG + IMM; \
+    } while (0)
+#define fPM_M(REG, MVAL) \
+    do { \
+        REG = REG + MVAL; \
+    } while (0)
+#define fEA_BREVR(REG) \
+    do { \
+        EA = fbrev(REG); \
+    } while (0)
+#endif
+#define fPM_CIRI(REG, IMM, MVAL) \
+    do { \
+        TCGv tcgv_siV = tcg_const_tl(siV); \
+        fcirc_add(REG, tcgv_siV, MuV); \
+        tcg_temp_free(tcgv_siV); \
+    } while (0)
+#define fPM_CIRR(REG, VAL, MVAL) \
+    do { \
+        fcirc_add(REG, VAL, MuV); \
+    } while (0)
+#define fMODCIRCU(N, P) ((N) & ((1 << (P)) - 1))
+#define fSCALE(N, A) (((size8s_t)(A)) << N)
+#define fVSATW(A) fVSATN(32, ((long long)A))
+#define fSATW(A) fSATN(32, ((long long)A))
+#define fVSAT(A) fVSATN(32, (A))
+#define fSAT(A) fSATN(32, (A))
+#define fSAT_ORIG_SHL(A, ORIG_REG) \
+    ((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) \
+        ? fSATVALN(32, ((size4s_t)(ORIG_REG))) \
+        : ((((ORIG_REG) > 0) && ((A) == 0)) ? fSATVALN(32, (ORIG_REG)) \
+                                            : fSAT(A)))
+#define fPASS(A) A
+#define fRND(A) (((A) + 1) >> 1)
+#define fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT)) - 1)) >> 1) \
+                   : (fCAST##REGSTYPE(SRC) << (SHAMT)))
+#define fBIDIR_ASHIFTL(SRC, SHAMT, REGSTYPE) \
+    fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##s)
+#define fBIDIR_LSHIFTL(SRC, SHAMT, REGSTYPE) \
+    fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##u)
+#define fBIDIR_ASHIFTL_SAT(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT)) - 1)) >> 1) \
+                   : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT), (SRC)))
+#define fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT)) - 1)) << 1) \
+                   : (fCAST##REGSTYPE(SRC) >> (SHAMT)))
+#define fBIDIR_ASHIFTR(SRC, SHAMT, REGSTYPE) \
+    fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##s)
+#define fBIDIR_LSHIFTR(SRC, SHAMT, REGSTYPE) \
+    fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##u)
+#define fBIDIR_ASHIFTR_SAT(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) \
+                        << ((-(SHAMT)) - 1)) << 1, (SRC)) \
+                   : (fCAST##REGSTYPE##s(SRC) >> (SHAMT)))
+#ifdef QEMU_GENERATE
+#define fASHIFTR(DST, SRC, SHAMT, REGSTYPE) \
+    gen_ashiftr_##REGSTYPE##s(DST, SRC, SHAMT)
+#define fLSHIFTR(DST, SRC, SHAMT, REGSTYPE) \
+    gen_lshiftr_##REGSTYPE##u(DST, SRC, SHAMT)
+#else
+#define fASHIFTR(SRC, SHAMT, REGSTYPE) (fCAST##REGSTYPE##s(SRC) >> (SHAMT))
+#define fLSHIFTR(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##u(SRC) >> (SHAMT)))
+#endif
+#define fROTL(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) == 0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) << (SHAMT)) | \
+                              ((fCAST##REGSTYPE##u(SRC) >> \
+                                 ((sizeof(SRC) * 8) - (SHAMT))))))
+#define fROTR(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) == 0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) >> (SHAMT)) | \
+                              ((fCAST##REGSTYPE##u(SRC) << \
+                                 ((sizeof(SRC) * 8) - (SHAMT))))))
+#ifdef QEMU_GENERATE
+#define fASHIFTL(DST, SRC, SHAMT, REGSTYPE) \
+    gen_ashiftl_##REGSTYPE##s(DST, SRC, SHAMT)
+#else
+#define fASHIFTL(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##s(SRC) << (SHAMT)))
+#endif
+#define fFLOAT(A) \
+    ({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; })
+#define fUNFLOAT(A) \
+    ({ union { float f; size4u_t i; } _fipun; \
+     _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; })
+#define fSFNANVAL() 0xffffffff
+#define fSFINFVAL(A) (((A) & 0x80000000) | 0x7f800000)
+#define fSFONEVAL(A) (((A) & 0x80000000) | fUNFLOAT(1.0))
+#define fCHECKSFNAN(DST, A) \
+    do { \
+        if (isnan(fFLOAT(A))) { \
+            if ((fGETBIT(22, A)) == 0) { \
+                fRAISEFLAGS(FE_INVALID); \
+            } \
+            DST = fSFNANVAL(); \
+        } \
+    } while (0)
+#define fCHECKSFNAN3(DST, A, B, C) \
+    do { \
+        fCHECKSFNAN(DST, A); \
+        fCHECKSFNAN(DST, B); \
+        fCHECKSFNAN(DST, C); \
+    } while (0)
+#define fSF_BIAS() 127
+#define fSF_MANTBITS() 23
+#define fSF_RECIP_LOOKUP(IDX) arch_recip_lookup(IDX)
+#define fSF_INVSQRT_LOOKUP(IDX) arch_invsqrt_lookup(IDX)
+#define fSF_MUL_POW2(A, B) \
+    (fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS())))
+#define fSF_GETEXP(A) (((A) >> fSF_MANTBITS()) & 0xff)
+#define fSF_MAXEXP() (254)
+#define fSF_RECIP_COMMON(N, D, O, A) arch_sf_recip_common(&N, &D, &O, &A)
+#define fSF_INVSQRT_COMMON(N, O, A) arch_sf_invsqrt_common(&N, &O, &A)
+#define fFMAFX(A, B, C, ADJ) internal_fmafx(A, B, C, fSXTN(8, 64, ADJ))
+#define fFMAF(A, B, C) internal_fmafx(A, B, C, 0)
+#define fSFMPY(A, B) internal_mpyf(A, B)
+#define fMAKESF(SIGN, EXP, MANT) \
+    ((((SIGN) & 1) << 31) | \
+     (((EXP) & 0xff) << fSF_MANTBITS()) | \
+     ((MANT) & ((1 << fSF_MANTBITS()) - 1)))
+#define fDOUBLE(A) \
+    ({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; })
+#define fUNDOUBLE(A) \
+    ({ union { double f; size8u_t i; } _fipun; \
+     _fipun.f = (A); \
+     isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; })
+#define fDFNANVAL() 0xffffffffffffffffULL
+#define fDFINFVAL(A) (((A) & 0x8000000000000000ULL) | 0x7ff0000000000000ULL)
+#define fDFONEVAL(A) (((A) & 0x8000000000000000ULL) | fUNDOUBLE(1.0))
+#define fCHECKDFNAN(DST, A) \
+    do { \
+        if (isnan(fDOUBLE(A))) { \
+            if ((fGETBIT(51, A)) == 0) { \
+                fRAISEFLAGS(FE_INVALID); \
+            } \
+            DST = fDFNANVAL(); \
+        } \
+    } while (0)
+#define fCHECKDFNAN3(DST, A, B, C) \
+    do { \
+        fCHECKDFNAN(DST, A); \
+        fCHECKDFNAN(DST, B); \
+        fCHECKDFNAN(DST, C); \
+    } while (0)
+#define fDF_BIAS() 1023
+#define fDF_ISNORMAL(X) (fpclassify(fDOUBLE(X)) == FP_NORMAL)
+#define fDF_ISDENORM(X) (fpclassify(fDOUBLE(X)) == FP_SUBNORMAL)
+#define fDF_ISBIG(X) (fDF_GETEXP(X) >= 512)
+#define fDF_MANTBITS() 52
+#define fDF_RECIP_LOOKUP(IDX) (size8u_t)(arch_recip_lookup(IDX))
+#define fDF_INVSQRT_LOOKUP(IDX) (size8u_t)(arch_invsqrt_lookup(IDX))
+#define fDF_MUL_POW2(A, B) \
+    (fUNDOUBLE(fDOUBLE(A) * fDOUBLE((0ULL + fDF_BIAS() + (B)) << \
+     fDF_MANTBITS())))
+#define fDF_GETEXP(A) (((A) >> fDF_MANTBITS()) & 0x7ff)
+#define fDF_MAXEXP() (2046)
+#define fDF_RECIP_COMMON(N, D, O, A) arch_df_recip_common(&N, &D, &O, &A)
+#define fDF_INVSQRT_COMMON(N, O, A) arch_df_invsqrt_common(&N, &O, &A)
+#define fFMA(A, B, C) internal_fma(A, B, C)
+#define fDFMPY(A, B) internal_mpy(A, B)
+#define fDF_MPY_HH(A, B, ACC) internal_mpyhh(A, B, ACC)
+#define fFMAX(A, B, C, ADJ) internal_fmax(A, B, C, fSXTN(8, 64, ADJ) * 2)
+#define fMAKEDF(SIGN, EXP, MANT) \
+    ((((SIGN) & 1ULL) << 63) | \
+     (((EXP) & 0x7ffULL) << fDF_MANTBITS()) | \
+     ((MANT) & ((1ULL << fDF_MANTBITS()) - 1)))
+
+#ifdef QEMU_GENERATE
+/* These will be needed if we write any FP instructions with TCG */
+#define fFPOP_START()      /* nothing */
+#define fFPOP_END()        /* nothing */
+#else
+#define fFPOP_START() arch_fpop_start(env)
+#define fFPOP_END() arch_fpop_end(env)
+#endif
+
+#define fFPSETROUND_NEAREST() fesetround(FE_TONEAREST)
+#define fFPSETROUND_CHOP() fesetround(FE_TOWARDZERO)
+#define fFPCANCELFLAGS() feclearexcept(FE_ALL_EXCEPT)
+#define fISINFPROD(A, B) \
+    ((isinf(A) && isinf(B)) || \
+     (isinf(A) && isfinite(B) && ((B) != 0.0)) || \
+     (isinf(B) && isfinite(A) && ((A) != 0.0)))
+#define fISZEROPROD(A, B) \
+    ((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A)))
+#define fRAISEFLAGS(A) arch_raise_fpflag(A)
+#define fDF_MAX(A, B) \
+    (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B)) : fmax(A, B))
+#define fDF_MIN(A, B) \
+    (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B)) : fmin(A, B))
+#define fSF_MAX(A, B) \
+    (((A) == (B)) ? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B)) : fmaxf(A, B))
+#define fSF_MIN(A, B) \
+    (((A) == (B)) ? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B)) : fminf(A, B))
+#define fMMU(ADDR) ADDR
+
+#ifdef QEMU_GENERATE
+#define fcirc_add(REG, INCR, MV) \
+    gen_fcircadd(REG, INCR, MV, fREAD_CSREG(MuN))
+#else
+#define fcirc_add(REG, INCR, IMMED)  /* Not possible in helpers */
+#endif
+
+#define fbrev(REG) (fbrevaddr(REG))
+
+#ifdef QEMU_GENERATE
+#define fLOAD(NUM, SIZE, SIGN, EA, DST) MEM_LOAD##SIZE##SIGN(DST, EA)
+#else
+#define fLOAD(NUM, SIZE, SIGN, EA, DST) \
+    DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE##SIGN(EA)
+#endif
+
+#define fMEMOP(NUM, SIZE, SIGN, EA, FNTYPE, VALUE)
+
+#ifdef QEMU_GENERATE
+#define fGET_FRAMEKEY() READ_REG(tmp, HEX_REG_FRAMEKEY)
+static inline TCGv_i64 gen_frame_scramble(TCGv_i64 result)
+{
+    /* ((LR << 32) | FP) ^ (FRAMEKEY << 32)) */
+    TCGv_i64 LR_i64 = tcg_temp_new_i64();
+    TCGv_i64 FP_i64 = tcg_temp_new_i64();
+    TCGv_i64 FRAMEKEY_i64 = tcg_temp_new_i64();
+
+    tcg_gen_extu_i32_i64(LR_i64, hex_gpr[HEX_REG_LR]);
+    tcg_gen_extu_i32_i64(FP_i64, hex_gpr[HEX_REG_FP]);
+    tcg_gen_extu_i32_i64(FRAMEKEY_i64, hex_gpr[HEX_REG_FRAMEKEY]);
+
+    tcg_gen_shli_i64(LR_i64, LR_i64, 32);
+    tcg_gen_shli_i64(FRAMEKEY_i64, FRAMEKEY_i64, 32);
+    tcg_gen_or_i64(result, LR_i64, FP_i64);
+    tcg_gen_xor_i64(result, result, FRAMEKEY_i64);
+
+    tcg_temp_free_i64(LR_i64);
+    tcg_temp_free_i64(FP_i64);
+    tcg_temp_free_i64(FRAMEKEY_i64);
+    return result;
+}
+#define fFRAME_SCRAMBLE(VAL) gen_frame_scramble(scramble_tmp)
+static inline TCGv_i64 gen_frame_unscramble(TCGv_i64 frame)
+{
+    TCGv_i64 FRAMEKEY_i64 = tcg_temp_new_i64();
+    tcg_gen_extu_i32_i64(FRAMEKEY_i64, hex_gpr[HEX_REG_FRAMEKEY]);
+    tcg_gen_shli_i64(FRAMEKEY_i64, FRAMEKEY_i64, 32);
+    tcg_gen_xor_i64(frame, frame, FRAMEKEY_i64);
+    tcg_temp_free_i64(FRAMEKEY_i64);
+    return frame;
+}
+
+#define fFRAME_UNSCRAMBLE(VAL) gen_frame_unscramble(VAL)
+#else
+#define fGET_FRAMEKEY() READ_REG(HEX_REG_FRAMEKEY)
+#define fFRAME_SCRAMBLE(VAL) ((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32))
+#define fFRAME_UNSCRAMBLE(VAL) fFRAME_SCRAMBLE(VAL)
+#endif
+
+#ifdef CONFIG_USER_ONLY
+#define fFRAMECHECK(ADDR, EA) do { } while (0) /* Not modelled in linux-user */
+#else
+/* System mode not implemented yet */
+#define fFRAMECHECK(ADDR, EA)  g_assert_not_reached();
+#endif
+
+#ifdef QEMU_GENERATE
+#define fLOAD_LOCKED(NUM, SIZE, SIGN, EA, DST) \
+    gen_load_locked##SIZE##SIGN(DST, EA, ctx->mem_idx);
+#else
+#define fLOAD_LOCKED(NUM, SIZE, SIGN, EA, DST) \
+    DST = (size##SIZE##SIGN##_t)mem_load_locked##SIZE(env, EA);
+#endif
+
+#define fLOAD_PHYS(NUM, SIZE, SIGN, SRC1, SRC2, DST)
+
+#ifdef QEMU_GENERATE
+#define fSTORE(NUM, SIZE, EA, SRC) MEM_STORE##SIZE(EA, SRC, insn->slot)
+#else
+#define fSTORE(NUM, SIZE, EA, SRC) MEM_STORE##SIZE(EA, SRC, slot)
+#endif
+
+#ifdef QEMU_GENERATE
+#define fSTORE_LOCKED(NUM, SIZE, EA, SRC, PRED) \
+    gen_store_conditional##SIZE(env, ctx, PdN, PRED, EA, SRC);
+#else
+#define fSTORE_LOCKED(NUM, SIZE, EA, SRC, PRED) \
+    PRED = (mem_store_conditional(env, EA, SRC, SIZE) ? 0xff : 0);
+#endif
+
+#define fVTCM_MEMCPY(DST, SRC, SIZE)
+#define fPERMUTEH(SRC0, SRC1, CTRL) fpermuteh((SRC0), (SRC1), CTRL)
+#define fPERMUTEB(SRC0, SRC1, CTRL) fpermuteb((SRC0), (SRC1), CTRL)
+
+#ifdef QEMU_GENERATE
+#define GETBYTE_FUNC(X) \
+    _Generic((X), TCGv_i32 : gen_get_byte, TCGv_i64 : gen_get_byte_i64)
+#define fGETBYTE(N, SRC) GETBYTE_FUNC(SRC)(BYTE, N, SRC, true)
+#define fGETUBYTE(N, SRC) GETBYTE_FUNC(SRC)(BYTE, N, SRC, false)
+#else
+#define fGETBYTE(N, SRC) ((size1s_t)((SRC >> ((N) * 8)) & 0xff))
+#define fGETUBYTE(N, SRC) ((size1u_t)((SRC >> ((N) * 8)) & 0xff))
+#endif
+
+#ifdef QEMU_GENERATE
+#define SETBYTE_FUNC(X) \
+    _Generic((X), TCGv_i32 : gen_set_byte, TCGv_i64 : gen_set_byte_i64)
+#define fSETBYTE(N, DST, VAL) SETBYTE_FUNC(DST)(N, DST, VAL)
+
+#define fGETHALF(N, SRC)  gen_get_half(HALF, N, SRC, true)
+#define fGETUHALF(N, SRC) gen_get_half(HALF, N, SRC, false)
+
+#define SETHALF_FUNC(X) \
+    _Generic((X), TCGv_i32 : gen_set_half, TCGv_i64 : gen_set_half_i64)
+#define fSETHALF(N, DST, VAL) SETHALF_FUNC(DST)(N, DST, VAL)
+#define fSETHALFw(N, DST, VAL) gen_set_half(N, DST, VAL)
+#define fSETHALFd(N, DST, VAL) gen_set_half_i64(N, DST, VAL)
+#else
+#define fSETBYTE(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffLL << ((N) * 8))) | \
+        (((size8u_t)((VAL) & 0x0ffLL)) << ((N) * 8)); \
+    } while (0)
+#define fGETHALF(N, SRC) ((size2s_t)((SRC >> ((N) * 16)) & 0xffff))
+#define fGETUHALF(N, SRC) ((size2u_t)((SRC >> ((N) * 16)) & 0xffff))
+#define fSETHALF(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffffLL << ((N) * 16))) | \
+        (((size8u_t)((VAL) & 0x0ffff)) << ((N) * 16)); \
+    } while (0)
+#define fSETHALFw fSETHALF
+#define fSETHALFd fSETHALF
+#endif
+
+#ifdef QEMU_GENERATE
+#define GETWORD_FUNC(X) \
+    _Generic((X), TCGv_i32 : gen_get_word, TCGv_i64 : gen_get_word_i64)
+#define fGETWORD(N, SRC)  GETWORD_FUNC(WORD)(WORD, N, SRC, true)
+#define fGETUWORD(N, SRC) GETWORD_FUNC(WORD)(WORD, N, SRC, false)
+#else
+#define fGETWORD(N, SRC) \
+    ((size8s_t)((size4s_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL)))
+#define fGETUWORD(N, SRC) \
+    ((size8u_t)((size4u_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL)))
+#endif
+
+#define fSETWORD(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffffffffLL << ((N) * 32))) | \
+              (((VAL) & 0x0ffffffffLL) << ((N) * 32)); \
+    } while (0)
+#define fACC()
+#define fEXTENSION_AUDIO(A) A
+
+#ifdef QEMU_GENERATE
+#define fSETBIT(N, DST, VAL) gen_set_bit((N), (DST), (VAL));
+#else
+#define fSETBIT(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(1ULL << (N))) | (((size8u_t)(VAL)) << (N)); \
+    } while (0)
+#endif
+
+#define fGETBIT(N, SRC) (((SRC) >> N) & 1)
+#define fSETBITS(HI, LO, DST, VAL) \
+    do { \
+        int j; \
+        for (j = LO; j <= HI; j++) { \
+            fSETBIT(j, DST, VAL); \
+        } \
+    } while (0)
+#define fCOUNTONES_2(VAL) count_ones_2(VAL)
+#define fCOUNTONES_4(VAL) count_ones_4(VAL)
+#define fCOUNTONES_8(VAL) count_ones_8(VAL)
+#define fBREV_8(VAL) reverse_bits_8(VAL)
+#define fBREV_4(VAL) reverse_bits_4(VAL)
+#define fBREV_2(VAL) reverse_bits_2(VAL)
+#define fBREV_1(VAL) reverse_bits_1(VAL)
+#define fCL1_8(VAL) count_leading_ones_8(VAL)
+#define fCL1_4(VAL) count_leading_ones_4(VAL)
+#define fCL1_2(VAL) count_leading_ones_2(VAL)
+#define fCL1_1(VAL) count_leading_ones_1(VAL)
+#define fINTERLEAVE(ODD, EVEN) interleave(ODD, EVEN)
+#define fDEINTERLEAVE(MIXED) deinterleave(MIXED)
+#define fNORM16(VAL) \
+    ((VAL == 0) ? (31) : (fMAX(fCL1_2(VAL), fCL1_2(~VAL)) - 1))
+#define fHIDE(A) A
+#define fCONSTLL(A) A##LL
+#define fCONSTULL(A) A##ULL
+#define fECHO(A) (A)
+
+#define fDO_TRACE(SREG)
+#define fBREAK()
+#define fGP_DOCHKPAGECROSS(BASE, SUM)
+#define fDOCHKPAGECROSS(BASE, SUM)
+#define fPAUSE(IMM)
+#define fTRAP(TRAPTYPE, IMM) helper_raise_exception(env, HEX_EXCP_TRAP0)
+
+#define fALIGN_REG_FIELD_VALUE(FIELD, VAL) \
+    ((VAL) << reg_field_info[FIELD].offset)
+#define fGET_REG_FIELD_MASK(FIELD) \
+    (((1 << reg_field_info[FIELD].width) - 1) << reg_field_info[FIELD].offset)
+#define fLOG_REG_FIELD(REG, FIELD, VAL)
+#define fWRITE_GLOBAL_REG_FIELD(REG, FIELD, VAL)
+#define fLOG_GLOBAL_REG_FIELD(REG, FIELD, VAL)
+#define fREAD_REG_FIELD(REG, FIELD) \
+    fEXTRACTU_BITS(env->gpr[HEX_REG_##REG], \
+                   reg_field_info[FIELD].width, \
+                   reg_field_info[FIELD].offset)
+#define fREAD_GLOBAL_REG_FIELD(REG, FIELD)
+#define fGET_FIELD(VAL, FIELD)
+#define fSET_FIELD(VAL, FIELD, NEWVAL)
+#define fPOW2_HELP_ROUNDUP(VAL) \
+    ((VAL) | \
+     ((VAL) >> 1) | \
+     ((VAL) >> 2) | \
+     ((VAL) >> 4) | \
+     ((VAL) >> 8) | \
+     ((VAL) >> 16))
+#define fPOW2_ROUNDUP(VAL) (fPOW2_HELP_ROUNDUP((VAL) - 1) + 1)
+#define fBARRIER()
+#define fSYNCH()
+#define fISYNC()
+#define fICFETCH(REG)
+#define fDCFETCH(REG) do { REG = REG; } while (0) /* Nothing to do in qemu */
+#define fICINVIDX(REG)
+#define fICINVA(REG) do { REG = REG; } while (0) /* Nothing to do in qemu */
+#define fICKILL()
+#define fDCKILL()
+#define fL2KILL()
+#define fL2UNLOCK()
+#define fL2CLEAN()
+#define fL2CLEANINV()
+#define fL2CLEANPA(REG)
+#define fL2CLEANINVPA(REG)
+#define fL2CLEANINVIDX(REG)
+#define fL2CLEANIDX(REG)
+#define fL2INVIDX(REG)
+#define fL2FETCH(ADDR, HEIGHT, WIDTH, STRIDE, FLAGS)
+#define fL2TAGR(INDEX, DST, DSTREG)
+#define fL2LOCKA(VA, DST, PREGDST)
+#define fL2UNLOCKA(VA)
+#define fL2TAGW(INDEX, PART2)
+#define fDCCLEANIDX(REG)
+#define fDCCLEANA(REG) do { REG = REG; } while (0) /* Nothing to do in qemu */
+#define fDCCLEANINVIDX(REG)
+#define fDCCLEANINVA(REG) \
+    do { REG = REG; } while (0) /* Nothing to do in qemu */
+
+#ifdef QEMU_GENERATE
+#define fDCZEROA(REG) tcg_gen_mov_tl(hex_dczero_addr, (REG))
+#else
+#define fDCZEROA(REG) do { REG = REG; g_assert_not_reached(); } while (0)
+#endif
+
+#define fDCINVIDX(REG)
+#define fDCINVA(REG) do { REG = REG; } while (0) /* Nothing to do in qemu */
+#define fBRANCH_SPECULATED_RIGHT(JC, SD, DOTNEWVAL) \
+    (((JC) ^ (SD) ^ (DOTNEWVAL & 1)) & 0x1)
+#define fBRANCH_SPECULATE_STALL(DOTNEWVAL, JUMP_COND, SPEC_DIR, HINTBITNUM, \
+                                STRBITNUM) /* Nothing */
+
+#define IV1DEAD()
+#define fVIRTINSN_SPSWAP(IMM, REG)
+#define fVIRTINSN_GETIE(IMM, REG) { REG = 0xdeafbeef; }
+#define fVIRTINSN_SETIE(IMM, REG)
+#define fVIRTINSN_RTE(IMM, REG)
+#define fTRAP1_VIRTINSN(IMM) \
+    (((IMM) == 1) || ((IMM) == 3) || ((IMM) == 4) || ((IMM) == 6))
+#define fNOP_EXECUTED
+#define fPREDUSE_TIMING()
+
+#endif
Signature · 1 line
2.7.4
#35 lore raw

RFC PATCH v2 33/67 Hexagon instruction classes

In reply to Taylor Simpson

Used to determine legal VLIW slots for each instruction

---
 target/hexagon/iclass.h |  46 +++++++++++++++++++++
 target/hexagon/iclass.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+)
 create mode 100644 target/hexagon/iclass.h
 create mode 100644 target/hexagon/iclass.c
target/hexagon/iclass.h new file +46 -0
new file mode 100644
index 0000000..89288ac
@@ -0,0 +1,46 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_ICLASS_H
+#define HEXAGON_ICLASS_H
+
+#include "opcodes.h"
+
+#define ICLASS_FROM_TYPE(TYPE) ICLASS_##TYPE
+
+typedef enum {
+
+#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS)    ICLASS_FROM_TYPE(TYPE),
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS)    /* nothing */
+#include "imported/iclass.def"
+#undef DEF_PP_ICLASS32
+#undef DEF_EE_ICLASS32
+
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS)    ICLASS_FROM_TYPE(TYPE),
+#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS)    /* nothing */
+#include "imported/iclass.def"
+#undef DEF_PP_ICLASS32
+#undef DEF_EE_ICLASS32
+
+    ICLASS_FROM_TYPE(COPROC_VX),
+    ICLASS_FROM_TYPE(COPROC_VMEM),
+    NUM_ICLASSES
+} iclass_t;
+
+extern const char *find_iclass_slots(opcode_t opcode, int itype);
+
+#endif
target/hexagon/iclass.c new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.7.4
#36 lore raw

RFC PATCH v2 34/67 Hexagon TCG generation helpers - step 1

In reply to Taylor Simpson

Helpers for reading and writing registers
Helpers for getting and setting parts of values (e.g., set bit)

---
 target/hexagon/genptr_helpers.h | 337 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 337 insertions(+)
 create mode 100644 target/hexagon/genptr_helpers.h
target/hexagon/genptr_helpers.h new file +337 -0
new file mode 100644
index 0000000..d8d5d95
@@ -0,0 +1,337 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_GENPTR_HELPERS_H
+#define HEXAGON_GENPTR_HELPERS_H
+
+#include "tcg/tcg.h"
+
+static inline TCGv gen_read_reg(TCGv result, int num)
+{
+    tcg_gen_mov_tl(result, hex_gpr[num]);
+    return result;
+}
+
+static inline TCGv gen_read_preg(TCGv pred, uint8_t num)
+{
+    tcg_gen_mov_tl(pred, hex_pred[num]);
+    return pred;
+}
+
+static inline TCGv gen_newreg_st(TCGv result, TCGv_env cpu_env, TCGv rnum)
+{
+    gen_helper_new_value(result, cpu_env, rnum);
+    return result;
+}
+
+static inline bool is_preloaded(DisasContext *ctx, int num)
+{
+    int i;
+    for (i = 0; i < ctx->ctx_reg_log_idx; i++) {
+        if (ctx->ctx_reg_log[i] == num) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static inline void gen_log_reg_write(int rnum, TCGv val, int slot,
+                                     int is_predicated)
+{
+    if (is_predicated) {
+        TCGv one = tcg_const_tl(1);
+        TCGv zero = tcg_const_tl(0);
+        TCGv slot_mask = tcg_temp_new();
+
+        tcg_gen_andi_tl(slot_mask, hex_slot_cancelled, 1 << slot);
+        tcg_gen_movcond_tl(TCG_COND_EQ, hex_new_value[rnum], slot_mask, zero,
+                           val, hex_new_value[rnum]);
+#if HEX_DEBUG
+        /* Do this so HELPER(debug_commit_end) will know */
+        tcg_gen_movcond_tl(TCG_COND_EQ, hex_reg_written[rnum], slot_mask, zero,
+                           one, hex_reg_written[rnum]);
+#endif
+
+        tcg_temp_free(one);
+        tcg_temp_free(zero);
+        tcg_temp_free(slot_mask);
+    } else {
+        tcg_gen_mov_tl(hex_new_value[rnum], val);
+#if HEX_DEBUG
+        /* Do this so HELPER(debug_commit_end) will know */
+        tcg_gen_movi_tl(hex_reg_written[rnum], 1);
+#endif
+    }
+}
+
+static inline void gen_log_reg_write_pair(int rnum, TCGv_i64 val, int slot,
+                                          int is_predicated)
+{
+    TCGv val32 = tcg_temp_new();
+
+    if (is_predicated) {
+        TCGv one = tcg_const_tl(1);
+        TCGv zero = tcg_const_tl(0);
+        TCGv slot_mask = tcg_temp_new();
+
+        tcg_gen_andi_tl(slot_mask, hex_slot_cancelled, 1 << slot);
+        /* Low word */
+        tcg_gen_extrl_i64_i32(val32, val);
+        tcg_gen_movcond_tl(TCG_COND_EQ, hex_new_value[rnum], slot_mask, zero,
+                           val32, hex_new_value[rnum]);
+        /* High word */
+        tcg_gen_extrh_i64_i32(val32, val);
+        tcg_gen_movcond_tl(TCG_COND_EQ, hex_new_value[rnum + 1],
+                           slot_mask, zero,
+                           val32, hex_new_value[rnum + 1]);
+
+        tcg_temp_free(one);
+        tcg_temp_free(zero);
+        tcg_temp_free(slot_mask);
+    } else {
+        /* Low word */
+        tcg_gen_extrl_i64_i32(val32, val);
+        tcg_gen_mov_tl(hex_new_value[rnum], val32);
+        /* High word */
+        tcg_gen_extrh_i64_i32(val32, val);
+        tcg_gen_mov_tl(hex_new_value[rnum + 1], val32);
+    }
+
+    tcg_temp_free(val32);
+}
+
+static inline void gen_log_pred_write(int pnum, TCGv val)
+{
+    TCGv zero = tcg_const_tl(0);
+    TCGv base_val = tcg_temp_new();
+    TCGv and_val = tcg_temp_new();
+    TCGv pred_written = tcg_temp_new();
+
+    /* Multiple writes to the same preg are and'ed together */
+    tcg_gen_andi_tl(base_val, val, 0xff);
+    tcg_gen_and_tl(and_val, base_val, hex_new_pred_value[pnum]);
+    tcg_gen_andi_tl(pred_written, hex_pred_written, 1 << pnum);
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_new_pred_value[pnum],
+                       pred_written, zero,
+                       and_val, base_val);
+    tcg_gen_ori_tl(hex_pred_written, hex_pred_written, 1 << pnum);
+
+    tcg_temp_free(zero);
+    tcg_temp_free(base_val);
+    tcg_temp_free(and_val);
+    tcg_temp_free(pred_written);
+}
+
+static inline void gen_read_p3_0(TCGv control_reg)
+{
+    TCGv pval = tcg_temp_new();
+    int i;
+    tcg_gen_movi_tl(control_reg, 0);
+    for (i = NUM_PREGS - 1; i >= 0; i--) {
+        tcg_gen_shli_tl(control_reg, control_reg, 8);
+        tcg_gen_andi_tl(pval, hex_pred[i], 0xff);
+        tcg_gen_or_tl(control_reg, control_reg, pval);
+    }
+    tcg_temp_free(pval);
+}
+
+static inline void gen_write_p3_0(TCGv tmp)
+{
+    TCGv control_reg = tcg_temp_new();
+    TCGv pred_val = tcg_temp_new();
+    int i;
+
+    tcg_gen_mov_tl(control_reg, tmp);
+    for (i = 0; i < NUM_PREGS; i++) {
+        tcg_gen_andi_tl(pred_val, control_reg, 0xff);
+        tcg_gen_mov_tl(hex_pred[i], pred_val);
+        tcg_gen_shri_tl(control_reg, control_reg, 8);
+    }
+    tcg_temp_free(control_reg);
+    tcg_temp_free(pred_val);
+}
+
+static inline TCGv gen_get_byte(TCGv result, int N, TCGv src, bool sign)
+{
+    TCGv shift = tcg_const_tl(8 * N);
+    TCGv mask = tcg_const_tl(0xff);
+
+    tcg_gen_shr_tl(result, src, shift);
+    tcg_gen_and_tl(result, result, mask);
+    if (sign) {
+        tcg_gen_ext8s_tl(result, result);
+    } else {
+        tcg_gen_ext8u_tl(result, result);
+    }
+    tcg_temp_free(mask);
+    tcg_temp_free(shift);
+
+    return result;
+}
+
+static inline TCGv gen_get_byte_i64(TCGv result, int N, TCGv_i64 src, bool sign)
+{
+    TCGv_i64 result_i64 = tcg_temp_new_i64();
+    TCGv_i64 shift = tcg_const_i64(8 * N);
+    TCGv_i64 mask = tcg_const_i64(0xff);
+    tcg_gen_shr_i64(result_i64, src, shift);
+    tcg_gen_and_i64(result_i64, result_i64, mask);
+    tcg_gen_extrl_i64_i32(result, result_i64);
+    if (sign) {
+        tcg_gen_ext8s_tl(result, result);
+    } else {
+        tcg_gen_ext8u_tl(result, result);
+    }
+    tcg_temp_free_i64(result_i64);
+    tcg_temp_free_i64(shift);
+    tcg_temp_free_i64(mask);
+
+    return result;
+
+}
+static inline TCGv gen_get_half(TCGv result, int N, TCGv src, bool sign)
+{
+    TCGv shift = tcg_const_tl(16 * N);
+    TCGv mask = tcg_const_tl(0xffff);
+
+    tcg_gen_shr_tl(result, src, shift);
+    tcg_gen_and_tl(result, result, mask);
+    if (sign) {
+        tcg_gen_ext16s_tl(result, result);
+    } else {
+        tcg_gen_ext16u_tl(result, result);
+    }
+    tcg_temp_free(mask);
+    tcg_temp_free(shift);
+
+    return result;
+}
+
+static inline void gen_set_half(int N, TCGv result, TCGv src)
+{
+    TCGv mask1 = tcg_const_tl(~(0xffff << (N * 16)));
+    TCGv mask2 = tcg_const_tl(0xffff);
+    TCGv shift = tcg_const_tl(N * 16);
+    TCGv tmp = tcg_temp_new();
+
+    tcg_gen_and_tl(result, result, mask1);
+    tcg_gen_and_tl(tmp, src, mask2);
+    tcg_gen_shli_tl(tmp, tmp, N * 16);
+    tcg_gen_or_tl(result, result, tmp);
+
+    tcg_temp_free(mask1);
+    tcg_temp_free(mask2);
+    tcg_temp_free(shift);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_set_half_i64(int N, TCGv_i64 result, TCGv src)
+{
+    TCGv_i64 mask1 = tcg_const_i64(~(0xffffLL << (N * 16)));
+    TCGv_i64 mask2 = tcg_const_i64(0xffffLL);
+    TCGv_i64 shift = tcg_const_i64(N * 16);
+    TCGv_i64 tmp = tcg_temp_new_i64();
+
+    tcg_gen_and_i64(result, result, mask1);
+    tcg_gen_concat_i32_i64(tmp, src, src);
+    tcg_gen_and_i64(tmp, tmp, mask2);
+    tcg_gen_shli_i64(tmp, tmp, N * 16);
+    tcg_gen_or_i64(result, result, tmp);
+
+    tcg_temp_free_i64(mask1);
+    tcg_temp_free_i64(mask2);
+    tcg_temp_free_i64(shift);
+    tcg_temp_free_i64(tmp);
+}
+
+static inline void gen_set_byte(int N, TCGv result, TCGv src)
+{
+    TCGv mask1 = tcg_const_tl(~(0xff << (N * 8)));
+    TCGv mask2 = tcg_const_tl(0xff);
+    TCGv shift = tcg_const_tl(N * 8);
+    TCGv tmp = tcg_temp_new();
+
+    tcg_gen_and_tl(result, result, mask1);
+    tcg_gen_and_tl(tmp, src, mask2);
+    tcg_gen_shli_tl(tmp, tmp, N * 8);
+    tcg_gen_or_tl(result, result, tmp);
+
+    tcg_temp_free(mask1);
+    tcg_temp_free(mask2);
+    tcg_temp_free(shift);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)
+{
+    TCGv_i64 mask1 = tcg_const_i64(~(0xffLL << (N * 8)));
+    TCGv_i64 mask2 = tcg_const_i64(0xffLL);
+    TCGv_i64 shift = tcg_const_i64(N * 8);
+    TCGv_i64 tmp = tcg_temp_new_i64();
+
+    tcg_gen_and_i64(result, result, mask1);
+    tcg_gen_concat_i32_i64(tmp, src, src);
+    tcg_gen_and_i64(tmp, tmp, mask2);
+    tcg_gen_shli_i64(tmp, tmp, N * 8);
+    tcg_gen_or_i64(result, result, tmp);
+
+    tcg_temp_free_i64(mask1);
+    tcg_temp_free_i64(mask2);
+    tcg_temp_free_i64(shift);
+    tcg_temp_free_i64(tmp);
+}
+
+static inline TCGv gen_get_word(TCGv result, int N, TCGv_i64 src, bool sign)
+{
+    if (N == 0) {
+        tcg_gen_extrl_i64_i32(result, src);
+    } else if (N == 1) {
+        tcg_gen_extrh_i64_i32(result, src);
+    } else {
+      g_assert_not_reached();
+    }
+    return result;
+}
+
+static inline TCGv_i64 gen_get_word_i64(TCGv_i64 result, int N, TCGv_i64 src,
+                                        bool sign)
+{
+    TCGv word = tcg_temp_new();
+    gen_get_word(word, N, src, sign);
+    if (sign) {
+        tcg_gen_ext_i32_i64(result, word);
+    } else {
+        tcg_gen_extu_i32_i64(result, word);
+    }
+    tcg_temp_free(word);
+    return result;
+}
+
+static inline TCGv gen_set_bit(int i, TCGv result, TCGv src)
+{
+    TCGv mask = tcg_const_tl(~(1 << i));
+    TCGv bit = tcg_temp_new();
+    tcg_gen_shli_tl(bit, src, i);
+    tcg_gen_and_tl(result, result, mask);
+    tcg_gen_or_tl(result, result, bit);
+    tcg_temp_free(mask);
+    tcg_temp_free(bit);
+
+    return result;
+}
+
+#endif
Signature · 1 line
2.7.4
#37 lore raw

RFC PATCH v2 35/67 Hexagon TCG generation helpers - step 2

In reply to Taylor Simpson

Helpers for load-locked/store-conditional

---
 target/hexagon/genptr_helpers.h | 52 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
target/hexagon/genptr_helpers.h +52 -0
index d8d5d95..c0e4c39 100644
@@ -334,4 +334,56 @@ static inline TCGv gen_set_bit(int i, TCGv result, TCGv src)
     return result;
 }
 
+static inline void gen_load_locked4u(TCGv dest, TCGv vaddr, int mem_index)
+{
+    tcg_gen_qemu_ld32u(dest, vaddr, mem_index);
+    tcg_gen_mov_tl(llsc_addr, vaddr);
+    tcg_gen_mov_tl(llsc_val, dest);
+}
+
+static inline void gen_load_locked8u(TCGv_i64 dest, TCGv vaddr, int mem_index)
+{
+    tcg_gen_qemu_ld64(dest, vaddr, mem_index);
+    tcg_gen_mov_tl(llsc_addr, vaddr);
+    tcg_gen_mov_i64(llsc_val_i64, dest);
+}
+
+static inline void gen_store_conditional4(CPUHexagonState *env,
+                                          DisasContext *ctx, int prednum,
+                                          TCGv pred, TCGv vaddr, TCGv src)
+{
+    TCGv tmp = tcg_temp_new();
+    TCGLabel *fail = gen_new_label();
+
+    tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPUHexagonState, llsc_addr));
+    tcg_gen_brcond_tl(TCG_COND_NE, vaddr, tmp, fail);
+    tcg_gen_movi_tl(tmp, prednum);
+    tcg_gen_st_tl(tmp, cpu_env, offsetof(CPUHexagonState, llsc_reg));
+    tcg_gen_st_tl(src, cpu_env, offsetof(CPUHexagonState, llsc_newval));
+    gen_exception(HEX_EXCP_SC4);
+
+    gen_set_label(fail);
+    tcg_gen_movi_tl(pred, 0);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_store_conditional8(CPUHexagonState *env,
+                                          DisasContext *ctx, int prednum,
+                                          TCGv pred, TCGv vaddr, TCGv_i64 src)
+{
+    TCGv tmp = tcg_temp_new();
+    TCGLabel *fail = gen_new_label();
+
+    tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPUHexagonState, llsc_addr));
+    tcg_gen_brcond_tl(TCG_COND_NE, vaddr, tmp, fail);
+    tcg_gen_movi_tl(tmp, prednum);
+    tcg_gen_st_tl(tmp, cpu_env, offsetof(CPUHexagonState, llsc_reg));
+    tcg_gen_st_i64(src, cpu_env, offsetof(CPUHexagonState, llsc_newval_i64));
+    gen_exception(HEX_EXCP_SC8);
+
+    gen_set_label(fail);
+    tcg_gen_movi_tl(pred, 0);
+    tcg_temp_free(tmp);
+}
+
 #endif
Signature · 1 line
2.7.4
#38 lore raw

RFC PATCH v2 36/67 Hexagon TCG generation helpers - step 3

In reply to Taylor Simpson

Helpers for store instructions

---
 target/hexagon/genptr_helpers.h | 77 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
target/hexagon/genptr_helpers.h +77 -0
index c0e4c39..0e2d7b9 100644
@@ -386,4 +386,81 @@ static inline void gen_store_conditional8(CPUHexagonState *env,
     tcg_temp_free(tmp);
 }
 
+static inline void gen_store32(TCGv vaddr, TCGv src, int width, int slot)
+{
+    tcg_gen_mov_tl(hex_store_addr[slot], vaddr);
+    tcg_gen_movi_tl(hex_store_width[slot], width);
+    tcg_gen_mov_tl(hex_store_val32[slot], src);
+}
+
+static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src,
+                              DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(slot);
+    gen_store32(vaddr, src, 1, slot);
+    tcg_temp_free(tmp);
+    ctx->ctx_store_width[slot] = 1;
+}
+
+static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
+                               DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(src);
+    gen_store1(cpu_env, vaddr, tmp, ctx, slot);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src,
+                              DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(slot);
+    gen_store32(vaddr, src, 2, slot);
+    tcg_temp_free(tmp);
+    ctx->ctx_store_width[slot] = 2;
+}
+
+static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
+                               DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(src);
+    gen_store2(cpu_env, vaddr, tmp, ctx, slot);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src,
+                              DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(slot);
+    gen_store32(vaddr, src, 4, slot);
+    tcg_temp_free(tmp);
+    ctx->ctx_store_width[slot] = 4;
+}
+
+static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
+                               DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(src);
+    gen_store4(cpu_env, vaddr, tmp, ctx, slot);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src,
+                              DisasContext *ctx, int slot)
+{
+    TCGv tmp = tcg_const_tl(slot);
+    tcg_gen_mov_tl(hex_store_addr[slot], vaddr);
+    tcg_gen_movi_tl(hex_store_width[slot], 8);
+    tcg_gen_mov_i64(hex_store_val64[slot], src);
+    tcg_temp_free(tmp);
+    ctx->ctx_store_width[slot] = 8;
+}
+
+static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src,
+                               DisasContext *ctx, int slot)
+{
+    TCGv_i64 tmp = tcg_const_i64(src);
+    gen_store8(cpu_env, vaddr, tmp, ctx, slot);
+    tcg_temp_free_i64(tmp);
+}
+
 #endif
Signature · 1 line
2.7.4
#39 lore raw

RFC PATCH v2 37/67 Hexagon TCG generation helpers - step 4

In reply to Taylor Simpson

Helpers referenced in macros.h

---
 target/hexagon/genptr_helpers.h | 67 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
target/hexagon/genptr_helpers.h +67 -0
index 0e2d7b9..9917d72 100644
@@ -463,4 +463,71 @@ static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src,
     tcg_temp_free_i64(tmp);
 }
 
+static inline TCGv_i64 gen_carry_from_add64(TCGv_i64 result, TCGv_i64 a,
+                                            TCGv_i64 b, TCGv_i64 c)
+{
+    TCGv_i64 WORD = tcg_temp_new_i64();
+    TCGv_i64 tmpa = tcg_temp_new_i64();
+    TCGv_i64 tmpb = tcg_temp_new_i64();
+    TCGv_i64 tmpc = tcg_temp_new_i64();
+
+    tcg_gen_mov_i64(tmpa, fGETUWORD(0, a));
+    tcg_gen_mov_i64(tmpb, fGETUWORD(0, b));
+    tcg_gen_add_i64(tmpc, tmpa, tmpb);
+    tcg_gen_add_i64(tmpc, tmpc, c);
+    tcg_gen_mov_i64(tmpa, fGETUWORD(1, a));
+    tcg_gen_mov_i64(tmpb, fGETUWORD(1, b));
+    tcg_gen_add_i64(tmpc, tmpa, tmpb);
+    tcg_gen_add_i64(tmpc, tmpc, fGETUWORD(1, tmpc));
+    tcg_gen_mov_i64(result, fGETUWORD(1, tmpc));
+
+    tcg_temp_free_i64(WORD);
+    tcg_temp_free_i64(tmpa);
+    tcg_temp_free_i64(tmpb);
+    tcg_temp_free_i64(tmpc);
+    return result;
+}
+
+static inline TCGv gen_8bitsof(TCGv result, TCGv value)
+{
+    TCGv zero = tcg_const_tl(0);
+    TCGv ones = tcg_const_tl(0xff);
+    tcg_gen_movcond_tl(TCG_COND_NE, result, value, zero, ones, zero);
+    tcg_temp_free(zero);
+    tcg_temp_free(ones);
+
+    return result;
+}
+
+static inline void gen_write_new_pc(TCGv addr)
+{
+    /* If there are multiple branches in a packet, ignore the second one */
+    TCGv zero = tcg_const_tl(0);
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_next_PC, hex_branch_taken, zero,
+                       hex_next_PC, addr);
+    tcg_gen_movi_tl(hex_branch_taken, 1);
+    tcg_temp_free(zero);
+}
+
+static inline void gen_set_usr_field(int field, TCGv val)
+{
+    tcg_gen_deposit_tl(hex_gpr[HEX_REG_USR], hex_gpr[HEX_REG_USR], val,
+                       reg_field_info[field].offset,
+                       reg_field_info[field].width);
+}
+
+static inline void gen_set_usr_fieldi(int field, int x)
+{
+    TCGv val = tcg_const_tl(x);
+    gen_set_usr_field(field, val);
+    tcg_temp_free(val);
+}
+
+static inline void gen_cond_return(TCGv pred, TCGv addr)
+{
+    TCGv zero = tcg_const_tl(0);
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_next_PC, pred, zero, addr, hex_next_PC);
+    tcg_temp_free(zero);
+}
+
 #endif
Signature · 1 line
2.7.4
#40 lore raw

RFC PATCH v2 38/67 Hexagon TCG generation helpers - step 5

In reply to Taylor Simpson

Helpers for instructions overriden for optimization

---
 target/hexagon/genptr_helpers.h | 314 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 314 insertions(+)
target/hexagon/genptr_helpers.h +314 -0
index 9917d72..e342f29 100644
@@ -530,4 +530,318 @@ static inline void gen_cond_return(TCGv pred, TCGv addr)
     tcg_temp_free(zero);
 }
 
+static inline void gen_loop0r(TCGv RsV, int riV, insn_t *insn)
+{
+    TCGv tmp = tcg_temp_new();
+    fIMMEXT(riV);
+    fPCALIGN(riV);
+    /* fWRITE_LOOP_REGS0( fREAD_PC()+riV, RsV); */
+    tcg_gen_addi_tl(tmp, hex_gpr[HEX_REG_PC], riV);
+    gen_log_reg_write(HEX_REG_LC0, RsV, insn->slot, 0);
+    gen_log_reg_write(HEX_REG_SA0, tmp, insn->slot, 0);
+    fSET_LPCFG(0);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_loop1r(TCGv RsV, int riV, insn_t *insn)
+{
+    TCGv tmp = tcg_temp_new();
+    fIMMEXT(riV);
+    fPCALIGN(riV);
+    /* fWRITE_LOOP_REGS1( fREAD_PC()+riV, RsV); */
+    tcg_gen_addi_tl(tmp, hex_gpr[HEX_REG_PC], riV);
+    gen_log_reg_write(HEX_REG_LC1, RsV, insn->slot, 0);
+    gen_log_reg_write(HEX_REG_SA1, tmp, insn->slot, 0);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_compare(TCGCond cond, TCGv res, TCGv arg1, TCGv arg2)
+{
+    TCGv one = tcg_const_tl(0xff);
+    TCGv zero = tcg_const_tl(0);
+
+    tcg_gen_movcond_tl(cond, res, arg1, arg2, one, zero);
+
+    tcg_temp_free(one);
+    tcg_temp_free(zero);
+}
+
+static inline void gen_comparei(TCGCond cond, TCGv res, TCGv arg1, int arg2)
+{
+    TCGv tmp = tcg_const_tl(arg2);
+    gen_compare(cond, res, arg1, tmp);
+    tcg_temp_free(tmp);
+}
+
+static inline void gen_compare_i64(TCGCond cond, TCGv res,
+                                   TCGv_i64 arg1, TCGv_i64 arg2)
+{
+    TCGv_i64 one = tcg_const_i64(0xff);
+    TCGv_i64 zero = tcg_const_i64(0);
+    TCGv_i64 temp = tcg_temp_new_i64();
+
+    tcg_gen_movcond_i64(cond, temp, arg1, arg2, one, zero);
+    tcg_gen_extrl_i64_i32(res, temp);
+    tcg_gen_andi_tl(res, res, 0xff);
+
+    tcg_temp_free_i64(one);
+    tcg_temp_free_i64(zero);
+    tcg_temp_free_i64(temp);
+}
+
+static inline void gen_cmpnd_cmp_jmp(int pnum, TCGCond cond, bool sense,
+                                     TCGv arg1, TCGv arg2, int pc_off)
+{
+    TCGv new_pc = tcg_temp_new();
+    TCGv pred = tcg_temp_new();
+    TCGv zero = tcg_const_tl(0);
+    TCGv one = tcg_const_tl(1);
+
+    tcg_gen_addi_tl(new_pc, hex_gpr[HEX_REG_PC], pc_off);
+    gen_compare(cond, pred, arg1, arg2);
+    gen_log_pred_write(pnum, pred);
+    if (!sense) {
+        tcg_gen_xori_tl(pred, pred, 0xff);
+    }
+
+    /* If there are multiple branches in a packet, ignore the second one */
+    tcg_gen_movcond_tl(TCG_COND_NE, pred, hex_branch_taken, zero, zero, pred);
+
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_next_PC, pred, zero,
+                       new_pc, hex_next_PC);
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_branch_taken, pred, zero,
+                       one, hex_branch_taken);
+
+    tcg_temp_free(new_pc);
+    tcg_temp_free(pred);
+    tcg_temp_free(zero);
+    tcg_temp_free(one);
+}
+
+static inline void gen_cmpnd_cmpi_jmp(int pnum, TCGCond cond, bool sense,
+                                      TCGv arg1, int arg2, int pc_off)
+{
+    TCGv tmp = tcg_const_tl(arg2);
+    gen_cmpnd_cmp_jmp(pnum, cond, sense, arg1, tmp, pc_off);
+    tcg_temp_free(tmp);
+
+}
+
+static inline void gen_cmpnd_cmp_n1_jmp(int pnum, TCGCond cond, bool sense,
+                                        TCGv arg, int pc_off)
+{
+    gen_cmpnd_cmpi_jmp(pnum, cond, sense, arg, -1, pc_off);
+}
+
+
+static inline void gen_jump(int pc_off)
+{
+    TCGv new_pc = tcg_temp_new();
+    tcg_gen_addi_tl(new_pc, hex_gpr[HEX_REG_PC], pc_off);
+    gen_write_new_pc(new_pc);
+    tcg_temp_free(new_pc);
+}
+
+static inline void gen_cond_jumpr(TCGv pred, TCGv dst_pc)
+{
+    TCGv zero = tcg_const_tl(0);
+    TCGv one = tcg_const_tl(1);
+    TCGv new_pc = tcg_temp_new();
+
+    tcg_gen_movcond_tl(TCG_COND_EQ, new_pc, pred, zero, hex_next_PC, dst_pc);
+
+    /* If there are multiple jumps in a packet, only the first one is taken */
+    tcg_gen_movcond_tl(TCG_COND_NE, hex_next_PC, hex_branch_taken, zero,
+                       hex_next_PC, new_pc);
+    tcg_gen_movcond_tl(TCG_COND_EQ, hex_branch_taken, pred, zero,
+                       hex_branch_taken, one);
+
+    tcg_temp_free(zero);
+    tcg_temp_free(one);
+    tcg_temp_free(new_pc);
+}
+
+static inline void gen_cond_jump(TCGv pred, int pc_off)
+{
+    TCGv new_pc = tcg_temp_new();
+
+    tcg_gen_addi_tl(new_pc, hex_gpr[HEX_REG_PC], pc_off);
+    gen_cond_jumpr(pred, new_pc);
+
+    tcg_temp_free(new_pc);
+}
+
+static inline void gen_call(int pc_off)
+{
+    gen_log_reg_write(HEX_REG_LR, hex_next_PC, 4, false);
+    gen_jump(pc_off);
+}
+
+static inline void gen_callr(TCGv new_pc)
+{
+    gen_log_reg_write(HEX_REG_LR, hex_next_PC, 4, false);
+    gen_write_new_pc(new_pc);
+}
+
+static inline void gen_endloop0(void)
+{
+    TCGv lpcfg = tcg_temp_local_new();
+
+    GET_USR_FIELD(USR_LPCFG, lpcfg);
+
+    /*
+     *    if (lpcfg == 1) {
+     *        hex_new_pred_value[3] = 0xff;
+     *        hex_pred_written |= 1 << 3;
+     *    }
+     */
+    TCGLabel *label1 = gen_new_label();
+    tcg_gen_brcondi_tl(TCG_COND_NE, lpcfg, 1, label1);
+    {
+        tcg_gen_movi_tl(hex_new_pred_value[3], 0xff);
+        tcg_gen_ori_tl(hex_pred_written, hex_pred_written, 1 << 3);
+    }
+    gen_set_label(label1);
+
+    /*
+     *    if (lpcfg) {
+     *        SET_USR_FIELD(USR_LPCFG, lpcfg - 1);
+     *    }
+     */
+    TCGLabel *label2 = gen_new_label();
+    tcg_gen_brcondi_tl(TCG_COND_EQ, lpcfg, 0, label2);
+    {
+        tcg_gen_subi_tl(lpcfg, lpcfg, 1);
+        SET_USR_FIELD(USR_LPCFG, lpcfg);
+    }
+    gen_set_label(label2);
+
+    /*
+     *    if (hex_gpr[HEX_REG_LC0] > 1) {
+     *        hex_next_PC = hex_gpr[HEX_REG_SA0];
+     *        hex_branch_taken = 1;
+     *        hex_gpr[HEX_REG_LC0] = hex_gpr[HEX_REG_LC0] - 1;
+     *    }
+     */
+    TCGLabel *label3 = gen_new_label();
+    tcg_gen_brcondi_tl(TCG_COND_LEU, hex_gpr[HEX_REG_LC0], 1, label3);
+    {
+        tcg_gen_mov_tl(hex_next_PC, hex_gpr[HEX_REG_SA0]);
+        tcg_gen_movi_tl(hex_branch_taken, 1);
+        TCGv lc0 = tcg_temp_local_new();
+        tcg_gen_mov_tl(lc0, hex_gpr[HEX_REG_LC0]);
+        tcg_gen_subi_tl(lc0, lc0, 1);
+        tcg_gen_mov_tl(hex_new_value[HEX_REG_LC0], lc0);
+        tcg_temp_free(lc0);
+    }
+    gen_set_label(label3);
+
+    tcg_temp_free(lpcfg);
+}
+
+static inline void gen_endloop1(void)
+{
+    /*
+     *    if (hex_gpr[HEX_REG_LC1] > 1) {
+     *        hex_next_PC = hex_gpr[HEX_REG_SA1];
+     *        hex_branch_taken = 1;
+     *        hex_gpr[HEX_REG_LC1] = hex_gpr[HEX_REG_LC1] - 1;
+     *    }
+     */
+    TCGLabel *label = gen_new_label();
+    tcg_gen_brcondi_tl(TCG_COND_LEU, hex_gpr[HEX_REG_LC1], 1, label);
+    {
+        tcg_gen_mov_tl(hex_next_PC, hex_gpr[HEX_REG_SA1]);
+        tcg_gen_movi_tl(hex_branch_taken, 1);
+        TCGv lc1 = tcg_temp_local_new();
+        tcg_gen_mov_tl(lc1, hex_gpr[HEX_REG_LC1]);
+        tcg_gen_subi_tl(lc1, lc1, 1);
+        tcg_gen_mov_tl(hex_new_value[HEX_REG_LC1], lc1);
+        tcg_temp_free(lc1);
+    }
+    gen_set_label(label);
+}
+
+static inline void gen_ashiftr_4_4s(TCGv dst, TCGv src, int32_t shift_amt)
+{
+    tcg_gen_sari_tl(dst, src, shift_amt);
+}
+
+static inline void gen_ashiftl_4_4s(TCGv dst, TCGv src, int32_t shift_amt)
+{
+    if (shift_amt >= 64) {
+        tcg_gen_movi_tl(dst, 0);
+    } else {
+        tcg_gen_shli_tl(dst, src, shift_amt);
+    }
+}
+
+static inline void gen_cmp_jumpnv(TCGCond cond, int rnum, TCGv src, int pc_off)
+{
+    TCGv pred = tcg_temp_new();
+    tcg_gen_setcond_tl(cond, pred, hex_new_value[rnum], src);
+    gen_cond_jump(pred, pc_off);
+    tcg_temp_free(pred);
+}
+
+static inline void gen_cmpi_jumpnv(TCGCond cond, int rnum, int src, int pc_off)
+{
+    TCGv pred = tcg_temp_new();
+    tcg_gen_setcondi_tl(cond, pred, hex_new_value[rnum], src);
+    gen_cond_jump(pred, pc_off);
+    tcg_temp_free(pred);
+}
+
+static inline void gen_asl_r_r_or(TCGv RxV, TCGv RsV, TCGv RtV)
+{
+    TCGv zero = tcg_const_tl(0);
+    TCGv shift_amt = tcg_temp_new();
+    TCGv_i64 shift_amt_i64 = tcg_temp_new_i64();
+    TCGv_i64 shift_left_val_i64 = tcg_temp_new_i64();
+    TCGv shift_left_val = tcg_temp_new();
+    TCGv_i64 shift_right_val_i64 = tcg_temp_new_i64();
+    TCGv shift_right_val = tcg_temp_new();
+    TCGv or_val = tcg_temp_new();
+
+    /* Sign extend 7->32 bits */
+    tcg_gen_shli_tl(shift_amt, RtV, 32 - 7);
+    tcg_gen_sari_tl(shift_amt, shift_amt, 32 - 7);
+    tcg_gen_ext_i32_i64(shift_amt_i64, shift_amt);
+
+    tcg_gen_ext_i32_i64(shift_left_val_i64, RsV);
+    tcg_gen_shl_i64(shift_left_val_i64, shift_left_val_i64, shift_amt_i64);
+    tcg_gen_extrl_i64_i32(shift_left_val, shift_left_val_i64);
+
+    /* ((-(SHAMT)) - 1) */
+    tcg_gen_neg_i64(shift_amt_i64, shift_amt_i64);
+    tcg_gen_subi_i64(shift_amt_i64, shift_amt_i64, 1);
+
+    tcg_gen_ext_i32_i64(shift_right_val_i64, RsV);
+    tcg_gen_sar_i64(shift_right_val_i64, shift_right_val_i64, shift_amt_i64);
+    tcg_gen_sari_i64(shift_right_val_i64, shift_right_val_i64, 1);
+    tcg_gen_extrl_i64_i32(shift_right_val, shift_right_val_i64);
+
+    tcg_gen_movcond_tl(TCG_COND_GE, or_val, shift_amt, zero,
+                       shift_left_val, shift_right_val);
+    tcg_gen_or_tl(RxV, RxV, or_val);
+
+    tcg_temp_free(zero);
+    tcg_temp_free(shift_amt);
+    tcg_temp_free_i64(shift_amt_i64);
+    tcg_temp_free_i64(shift_left_val_i64);
+    tcg_temp_free(shift_left_val);
+    tcg_temp_free_i64(shift_right_val_i64);
+    tcg_temp_free(shift_right_val);
+    tcg_temp_free(or_val);
+}
+
+static inline void gen_lshiftr_4_4u(TCGv dst, TCGv src, int32_t shift_amt)
+{
+    if (shift_amt >= 64) {
+        tcg_gen_movi_tl(dst, 0);
+    } else {
+        tcg_gen_shri_tl(dst, src, shift_amt);
+    }
+}
+
 #endif
Signature · 1 line
2.7.4
#41 lore raw

RFC PATCH v2 39/67 Hexagon TCG generation - step 01

In reply to Taylor Simpson

Include the generated files and set up the data structures

---
 target/hexagon/genptr.h | 25 +++++++++++++++++++++
 target/hexagon/genptr.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/genptr.c
target/hexagon/genptr.h new file +25 -0
new file mode 100644
index 0000000..a3a3db1
@@ -0,0 +1,25 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_GENPTR_H
+#define HEXAGON_GENPTR_H
+
+#include "insn.h"
+
+extern semantic_insn_t opcode_genptr[];
+
+#endif
target/hexagon/genptr.c new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.7.4
#42 lore raw

RFC PATCH v2 40/67 Hexagon TCG generation - step 02

In reply to Taylor Simpson

Override load instructions

---
 target/hexagon/helper_overrides.h | 404 ++++++++++++++++++++++++++++++++++++++
 target/hexagon/genptr.c           |   1 +
 2 files changed, 405 insertions(+)
 create mode 100644 target/hexagon/helper_overrides.h
target/hexagon/helper_overrides.h new file +404 -0
new file mode 100644
index 0000000..6a69fc6
@@ -0,0 +1,404 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_HELPER_OVERRIDES_H
+#define HEXAGON_HELPER_OVERRIDES_H
+
+/*
+ * Here is a primer to understand the tag names for load/store instructions
+ *
+ * Data types
+ *      b        signed byte                       r0 = memb(r2+#0)
+ *     ub        unsigned byte                     r0 = memub(r2+#0)
+ *      h        signed half word (16 bits)        r0 = memh(r2+#0)
+ *     uh        unsigned half word                r0 = memuh(r2+#0)
+ *      i        integer (32 bits)                 r0 = memw(r2+#0)
+ *      d        double word (64 bits)             r1:0 = memd(r2+#0)
+ *
+ * Addressing modes
+ *     _io       indirect with offset              r0 = memw(r1+#4)
+ *     _ur       absolute with register offset     r0 = memw(r1<<#4+##variable)
+ *     _rr       indirect with register offset     r0 = memw(r1+r4<<#2)
+ *     gp        global pointer relative           r0 = memw(gp+#200)
+ *     _sp       stack pointer relative            r0 = memw(r29+#12)
+ *     _ap       absolute set                      r0 = memw(r1=##variable)
+ *     _pr       post increment register           r0 = memw(r1++m1)
+ *     _pbr      post increment bit reverse        r0 = memw(r1++m1:brev)
+ *     _pi       post increment immediate          r0 = memb(r1++#1)
+ *     _pci      post increment circular immediate r0 = memw(r1++#4:circ(m0))
+ *     _pcr      post increment circular register  r0 = memw(r1++I:circ(m0))
+ */
+
+/* Macros for complex addressing modes */
+#define GET_EA_ap \
+    do { \
+        fEA_IMM(UiV); \
+        tcg_gen_movi_tl(ReV, UiV); \
+    } while (0)
+#define GET_EA_pr \
+    do { \
+        fEA_REG(RxV); \
+        fPM_M(RxV, MuV); \
+    } while (0)
+#define GET_EA_pbr \
+    do { \
+        fEA_BREVR(RxV); \
+        fPM_M(RxV, MuV); \
+    } while (0)
+#define GET_EA_pi \
+    do { \
+        fEA_REG(RxV); \
+        fPM_I(RxV, siV); \
+    } while (0)
+#define GET_EA_pci \
+    do { \
+        fEA_REG(RxV); \
+        fPM_CIRI(RxV, siV, MuV); \
+    } while (0)
+#define GET_EA_pcr(SHIFT) \
+    do { \
+        fEA_REG(RxV); \
+        fPM_CIRR(RxV, fREAD_IREG(MuV, (SHIFT)), MuV); \
+    } while (0)
+
+/*
+ * Many instructions will work with just macro redefinitions
+ * with the caveat that they need a tmp variable to carry a
+ * value between them.
+ */
+#define fWRAP_tmp(SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        SHORTCODE; \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* Byte load instructions */
+#define fWRAP_L2_loadrub_io(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrb_io(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadrub_ur(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L4_loadrb_ur(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadrub_rr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L4_loadrb_rr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrubgp(GENHLPR, SHORTCODE)       fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadrbgp(GENHLPR, SHORTCODE)        fWRAP_tmp(SHORTCODE)
+#define fWRAP_SL1_loadrub_io(GENHLPR, SHORTCODE)     SHORTCODE
+#define fWRAP_SL2_loadrb_io(GENHLPR, SHORTCODE)      SHORTCODE
+
+/* Half word load instruction */
+#define fWRAP_L2_loadruh_io(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrh_io(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadruh_ur(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L4_loadrh_ur(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadruh_rr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L4_loadrh_rr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadruhgp(GENHLPR, SHORTCODE)       fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadrhgp(GENHLPR, SHORTCODE)        fWRAP_tmp(SHORTCODE)
+#define fWRAP_SL2_loadruh_io(GENHLPR, SHORTCODE)     SHORTCODE
+#define fWRAP_SL2_loadrh_io(GENHLPR, SHORTCODE)      SHORTCODE
+
+/* Word load instructions */
+#define fWRAP_L2_loadri_io(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadri_ur(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadri_rr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrigp(GENHLPR, SHORTCODE)        fWRAP_tmp(SHORTCODE)
+#define fWRAP_SL1_loadri_io(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_SL2_loadri_sp(GENHLPR, SHORTCODE)      fWRAP_tmp(SHORTCODE)
+
+/* Double word load instructions */
+#define fWRAP_L2_loadrd_io(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadrd_ur(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L4_loadrd_rr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrdgp(GENHLPR, SHORTCODE)        fWRAP_tmp(SHORTCODE)
+#define fWRAP_SL2_loadrd_sp(GENHLPR, SHORTCODE)      fWRAP_tmp(SHORTCODE)
+
+/* Instructions with multiple definitions */
+#define fWRAP_LOAD_AP(RES, SIZE, SIGN) \
+    do { \
+        fMUST_IMMEXT(UiV); \
+        fEA_IMM(UiV); \
+        fLOAD(1, SIZE, SIGN, EA, RES); \
+        tcg_gen_movi_tl(ReV, UiV); \
+    } while (0)
+
+#define fWRAP_L4_loadrub_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RdV, 1, u)
+#define fWRAP_L4_loadrb_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RdV, 1, s)
+#define fWRAP_L4_loadruh_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RdV, 2, u)
+#define fWRAP_L4_loadrh_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RdV, 2, s)
+#define fWRAP_L4_loadri_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RdV, 4, u)
+#define fWRAP_L4_loadrd_ap(GENHLPR, SHORTCODE) \
+    fWRAP_LOAD_AP(RddV, 8, u)
+
+#define fWRAP_L2_loadrub_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadrb_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadruh_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadrh_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadri_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+#define fWRAP_L2_loadrd_pci(GENHLPR, SHORTCODE) \
+      fWRAP_tmp(SHORTCODE)
+
+#define fWRAP_PCR(SHIFT, LOAD) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        fEA_REG(RxV); \
+        fREAD_IREG(MuV, SHIFT); \
+        gen_fcircadd(RxV, ireg, MuV, fREAD_CSREG(MuN)); \
+        LOAD; \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(ireg); \
+    } while (0)
+
+#define fWRAP_L2_loadrub_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(0, fLOAD(1, 1, u, EA, RdV))
+#define fWRAP_L2_loadrb_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(0, fLOAD(1, 1, s, EA, RdV))
+#define fWRAP_L2_loadruh_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(1, fLOAD(1, 2, u, EA, RdV))
+#define fWRAP_L2_loadrh_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(1, fLOAD(1, 2, s, EA, RdV))
+#define fWRAP_L2_loadri_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(2, fLOAD(1, 4, u, EA, RdV))
+#define fWRAP_L2_loadrd_pcr(GENHLPR, SHORTCODE) \
+      fWRAP_PCR(3, fLOAD(1, 8, u, EA, RddV))
+
+#define fWRAP_L2_loadrub_pr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrub_pbr(GENHLPR, SHORTCODE)     SHORTCODE
+#define fWRAP_L2_loadrub_pi(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrb_pr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrb_pbr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrb_pi(GENHLPR, SHORTCODE)       SHORTCODE;
+#define fWRAP_L2_loadruh_pr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadruh_pbr(GENHLPR, SHORTCODE)     SHORTCODE
+#define fWRAP_L2_loadruh_pi(GENHLPR, SHORTCODE)      SHORTCODE;
+#define fWRAP_L2_loadrh_pr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrh_pbr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrh_pi(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadri_pr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadri_pbr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadri_pi(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrd_pr(GENHLPR, SHORTCODE)       SHORTCODE
+#define fWRAP_L2_loadrd_pbr(GENHLPR, SHORTCODE)      SHORTCODE
+#define fWRAP_L2_loadrd_pi(GENHLPR, SHORTCODE)       SHORTCODE
+
+/*
+ * These instructions load 2 bytes and places them in
+ * two halves of the destination register.
+ * The GET_EA macro determines the addressing mode.
+ * The fGB macro determines whether to zero-extend or
+ * sign-extend.
+ */
+#define fWRAP_loadbXw2(GET_EA, fGB) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv tmpV = tcg_temp_new(); \
+        TCGv BYTE = tcg_temp_new(); \
+        int i; \
+        GET_EA; \
+        fLOAD(1, 2, u, EA, tmpV); \
+        tcg_gen_movi_tl(RdV, 0); \
+        for (i = 0; i < 2; i++) { \
+            fSETHALF(i, RdV, fGB(i, tmpV)); \
+        } \
+        tcg_temp_free(ireg); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(tmpV); \
+        tcg_temp_free(BYTE); \
+    } while (0)
+
+#define fWRAP_L2_loadbzw2_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(fEA_RI(RsV, siV), fGETUBYTE)
+#define fWRAP_L4_loadbzw2_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(fEA_IRs(UiV, RtV, uiV), fGETUBYTE)
+#define fWRAP_L2_loadbsw2_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(fEA_RI(RsV, siV), fGETBYTE)
+#define fWRAP_L4_loadbsw2_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(fEA_IRs(UiV, RtV, uiV), fGETBYTE)
+#define fWRAP_L4_loadbzw2_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_ap, fGETUBYTE)
+#define fWRAP_L2_loadbzw2_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pr, fGETUBYTE)
+#define fWRAP_L2_loadbzw2_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pbr, fGETUBYTE)
+#define fWRAP_L2_loadbzw2_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pi, fGETUBYTE)
+#define fWRAP_L4_loadbsw2_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_ap, fGETBYTE)
+#define fWRAP_L2_loadbsw2_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pr, fGETBYTE)
+#define fWRAP_L2_loadbsw2_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pbr, fGETBYTE)
+#define fWRAP_L2_loadbsw2_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pi, fGETBYTE)
+#define fWRAP_L2_loadbzw2_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pci, fGETUBYTE)
+#define fWRAP_L2_loadbsw2_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pci, fGETBYTE)
+#define fWRAP_L2_loadbzw2_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pcr(1), fGETUBYTE)
+#define fWRAP_L2_loadbsw2_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw2(GET_EA_pcr(1), fGETBYTE)
+
+/*
+ * These instructions load 4 bytes and places them in
+ * four halves of the destination register pair.
+ * The GET_EA macro determines the addressing mode.
+ * The fGB macro determines whether to zero-extend or
+ * sign-extend.
+ */
+#define fWRAP_loadbXw4(GET_EA, fGB) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv tmpV = tcg_temp_new(); \
+        TCGv BYTE = tcg_temp_new(); \
+        int i; \
+        GET_EA; \
+        fLOAD(1, 4, u, EA, tmpV);  \
+        tcg_gen_movi_i64(RddV, 0); \
+        for (i = 0; i < 4; i++) { \
+            fSETHALF(i, RddV, fGB(i, tmpV));  \
+        }  \
+        tcg_temp_free(ireg); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(tmpV); \
+        tcg_temp_free(BYTE); \
+    } while (0)
+
+#define fWRAP_L2_loadbzw4_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(fEA_RI(RsV, siV), fGETUBYTE)
+#define fWRAP_L4_loadbzw4_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(fEA_IRs(UiV, RtV, uiV), fGETUBYTE)
+#define fWRAP_L2_loadbsw4_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(fEA_RI(RsV, siV), fGETBYTE)
+#define fWRAP_L4_loadbsw4_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(fEA_IRs(UiV, RtV, uiV), fGETBYTE)
+#define fWRAP_L2_loadbzw4_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pci, fGETUBYTE)
+#define fWRAP_L2_loadbsw4_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pci, fGETBYTE)
+#define fWRAP_L2_loadbzw4_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pcr(2), fGETUBYTE)
+#define fWRAP_L2_loadbsw4_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pcr(2), fGETBYTE)
+#define fWRAP_L4_loadbzw4_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_ap, fGETUBYTE)
+#define fWRAP_L2_loadbzw4_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pr, fGETUBYTE)
+#define fWRAP_L2_loadbzw4_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pbr, fGETUBYTE)
+#define fWRAP_L2_loadbzw4_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pi, fGETUBYTE)
+#define fWRAP_L4_loadbsw4_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_ap, fGETBYTE)
+#define fWRAP_L2_loadbsw4_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pr, fGETBYTE)
+#define fWRAP_L2_loadbsw4_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pbr, fGETBYTE)
+#define fWRAP_L2_loadbsw4_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadbXw4(GET_EA_pi, fGETBYTE)
+
+/*
+ * These instructions load a half word, shift the destination right by 16 bits
+ * and place the loaded value in the high half word of the destination pair.
+ * The GET_EA macro determines the addressing mode.
+ */
+#define fWRAP_loadalignh(GET_EA) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv tmpV = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        READ_REG_PAIR(RyyV, RyyN); \
+        GET_EA;  \
+        fLOAD(1, 2, u, EA, tmpV);  \
+        tcg_gen_extu_i32_i64(tmp_i64, tmpV); \
+        tcg_gen_shli_i64(tmp_i64, tmp_i64, 48); \
+        tcg_gen_shri_i64(RyyV, RyyV, 16); \
+        tcg_gen_or_i64(RyyV, RyyV, tmp_i64); \
+        tcg_temp_free(ireg); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(tmpV); \
+        tcg_temp_free_i64(tmp_i64); \
+    } while (0)
+
+#define fWRAP_L4_loadalignh_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(fEA_IRs(UiV, RtV, uiV))
+#define fWRAP_L2_loadalignh_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(fEA_RI(RsV, siV))
+#define fWRAP_L2_loadalignh_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_pci)
+#define fWRAP_L2_loadalignh_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_pcr(1))
+#define fWRAP_L4_loadalignh_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_ap)
+#define fWRAP_L2_loadalignh_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_pr)
+#define fWRAP_L2_loadalignh_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_pbr)
+#define fWRAP_L2_loadalignh_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignh(GET_EA_pi)
+
+/* Same as above, but loads a byte instead of half word */
+#define fWRAP_loadalignb(GET_EA) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv tmpV = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        READ_REG_PAIR(RyyV, RyyN); \
+        GET_EA;  \
+        fLOAD(1, 1, u, EA, tmpV);  \
+        tcg_gen_extu_i32_i64(tmp_i64, tmpV); \
+        tcg_gen_shli_i64(tmp_i64, tmp_i64, 56); \
+        tcg_gen_shri_i64(RyyV, RyyV, 8); \
+        tcg_gen_or_i64(RyyV, RyyV, tmp_i64); \
+        tcg_temp_free(ireg); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(tmpV); \
+        tcg_temp_free_i64(tmp_i64); \
+    } while (0)
+
+#define fWRAP_L2_loadalignb_io(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(fEA_RI(RsV, siV))
+#define fWRAP_L4_loadalignb_ur(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(fEA_IRs(UiV, RtV, uiV))
+#define fWRAP_L2_loadalignb_pci(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_pci)
+#define fWRAP_L2_loadalignb_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_pcr(0))
+#define fWRAP_L4_loadalignb_ap(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_ap)
+#define fWRAP_L2_loadalignb_pr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_pr)
+#define fWRAP_L2_loadalignb_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_pbr)
+#define fWRAP_L2_loadalignb_pi(GENHLPR, SHORTCODE) \
+    fWRAP_loadalignb(GET_EA_pi)
+
+#endif
target/hexagon/genptr.c +1 -0
index 5a602bd..6b9cc0d 100644
@@ -26,6 +26,7 @@
 #include "translate.h"
 #include "macros.h"
 #include "genptr_helpers.h"
+#include "helper_overrides.h"
 
 #include "qemu_wrap_generated.h"
 
Signature · 1 line
2.7.4
#43 lore raw

RFC PATCH v2 41/67 Hexagon TCG generation - step 03

In reply to Taylor Simpson

Override predicated load instructions

---
 target/hexagon/helper_overrides.h | 235 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 235 insertions(+)
target/hexagon/helper_overrides.h +235 -0
index 6a69fc6..20d8584 100644
@@ -401,4 +401,239 @@
 #define fWRAP_L2_loadalignb_pi(GENHLPR, SHORTCODE) \
     fWRAP_loadalignb(GET_EA_pi)
 
+/*
+ * Predicated loads
+ * Here is a primer to understand the tag names
+ *
+ * Predicate used
+ *      t        true "old" value                  if (p0) r0 = memb(r2+#0)
+ *      f        false "old" value                 if (!p0) r0 = memb(r2+#0)
+ *      tnew     true "new" value                  if (p0.new) r0 = memb(r2+#0)
+ *      fnew     false "new" value                 if (!p0.new) r0 = memb(r2+#0)
+ */
+#define fWRAP_PRED_LOAD(GET_EA, PRED, SIZE, SIGN) \
+    do { \
+        TCGv LSB = tcg_temp_local_new(); \
+        TCGLabel *label = gen_new_label(); \
+        GET_EA; \
+        PRED;  \
+        PRED_LOAD_CANCEL(LSB, EA); \
+        tcg_gen_movi_tl(RdV, 0); \
+        tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \
+            fLOAD(1, SIZE, SIGN, EA, RdV); \
+        gen_set_label(label); \
+        tcg_temp_free(LSB); \
+    } while (0)
+
+#define fWRAP_L2_ploadrubt_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLD(PtV), 1, u)
+#define fWRAP_L2_ploadrubt_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 1, u)
+#define fWRAP_L2_ploadrubf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV), 1, u)
+#define fWRAP_L2_ploadrubf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 1, u)
+#define fWRAP_L2_ploadrubtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEW(PtN), 1, u)
+#define fWRAP_L2_ploadrubfnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN), 1, u)
+#define fWRAP_L4_ploadrubt_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV), 1, u)
+#define fWRAP_L4_ploadrubf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV), 1, u)
+#define fWRAP_L4_ploadrubtnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN), 1, u)
+#define fWRAP_L4_ploadrubfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN), 1, u)
+#define fWRAP_L2_ploadrubtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 1, u)
+#define fWRAP_L2_ploadrubfnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 1, u)
+#define fWRAP_L4_ploadrubt_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLD(PtV), 1, u)
+#define fWRAP_L4_ploadrubf_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLDNOT(PtV), 1, u)
+#define fWRAP_L4_ploadrubtnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEW(PtN), 1, u)
+#define fWRAP_L4_ploadrubfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEWNOT(PtN), 1, u)
+#define fWRAP_L2_ploadrbt_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLD(PtV), 1, s)
+#define fWRAP_L2_ploadrbt_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 1, s)
+#define fWRAP_L2_ploadrbf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV), 1, s)
+#define fWRAP_L2_ploadrbf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 1, s)
+#define fWRAP_L2_ploadrbtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEW(PtN), 1, s)
+#define fWRAP_L2_ploadrbfnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN), 1, s)
+#define fWRAP_L4_ploadrbt_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV), 1, s)
+#define fWRAP_L4_ploadrbf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV), 1, s)
+#define fWRAP_L4_ploadrbtnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN), 1, s)
+#define fWRAP_L4_ploadrbfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN), 1, s)
+#define fWRAP_L2_ploadrbtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 1, s)
+#define fWRAP_L2_ploadrbfnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD({ fEA_REG(RxV); fPM_I(RxV, siV); }, fLSBNEWNOT(PtN), 1, s)
+#define fWRAP_L4_ploadrbt_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLD(PtV), 1, s)
+#define fWRAP_L4_ploadrbf_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLDNOT(PtV), 1, s)
+#define fWRAP_L4_ploadrbtnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEW(PtN), 1, s)
+#define fWRAP_L4_ploadrbfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEWNOT(PtN), 1, s)
+
+#define fWRAP_L2_ploadruht_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLD(PtV), 2, u)
+#define fWRAP_L2_ploadruht_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 2, u)
+#define fWRAP_L2_ploadruhf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV), 2, u)
+#define fWRAP_L2_ploadruhf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 2, u)
+#define fWRAP_L2_ploadruhtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEW(PtN), 2, u)
+#define fWRAP_L2_ploadruhfnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN), 2, u)
+#define fWRAP_L4_ploadruht_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV), 2, u)
+#define fWRAP_L4_ploadruhf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV), 2, u)
+#define fWRAP_L4_ploadruhtnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN), 2, u)
+#define fWRAP_L4_ploadruhfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN), 2, u)
+#define fWRAP_L2_ploadruhtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 2, u)
+#define fWRAP_L2_ploadruhfnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 2, u)
+#define fWRAP_L4_ploadruht_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLD(PtV), 2, u)
+#define fWRAP_L4_ploadruhf_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLDNOT(PtV), 2, u)
+#define fWRAP_L4_ploadruhtnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEW(PtN), 2, u)
+#define fWRAP_L4_ploadruhfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEWNOT(PtN), 2, u)
+#define fWRAP_L2_ploadrht_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLD(PtV), 2, s)
+#define fWRAP_L2_ploadrht_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 2, s)
+#define fWRAP_L2_ploadrhf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV), 2, s)
+#define fWRAP_L2_ploadrhf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 2, s)
+#define fWRAP_L2_ploadrhtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEW(PtN), 2, s)
+#define fWRAP_L2_ploadrhfnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN), 2, s)
+#define fWRAP_L4_ploadrht_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV), 2, s)
+#define fWRAP_L4_ploadrhf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV), 2, s)
+#define fWRAP_L4_ploadrhtnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN), 2, s)
+#define fWRAP_L4_ploadrhfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN), 2, s)
+#define fWRAP_L2_ploadrhtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 2, s)
+#define fWRAP_L2_ploadrhfnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 2, s)
+#define fWRAP_L4_ploadrht_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLD(PtV), 2, s)
+#define fWRAP_L4_ploadrhf_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLDNOT(PtV), 2, s)
+#define fWRAP_L4_ploadrhtnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEW(PtN), 2, s)
+#define fWRAP_L4_ploadrhfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEWNOT(PtN), 2, s)
+
+#define fWRAP_L2_ploadrit_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLD(PtV), 4, u)
+#define fWRAP_L2_ploadrit_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 4, u)
+#define fWRAP_L2_ploadrif_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV), 4, u)
+#define fWRAP_L2_ploadrif_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 4, u)
+#define fWRAP_L2_ploadritnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEW(PtN), 4, u)
+#define fWRAP_L2_ploadrifnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN), 4, u)
+#define fWRAP_L4_ploadrit_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV), 4, u)
+#define fWRAP_L4_ploadrif_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV), 4, u)
+#define fWRAP_L4_ploadritnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN), 4, u)
+#define fWRAP_L4_ploadrifnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN), 4, u)
+#define fWRAP_L2_ploadritnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 4, u)
+#define fWRAP_L2_ploadrifnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 4, u)
+#define fWRAP_L4_ploadrit_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLD(PtV), 4, u)
+#define fWRAP_L4_ploadrif_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBOLDNOT(PtV), 4, u)
+#define fWRAP_L4_ploadritnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEW(PtN), 4, u)
+#define fWRAP_L4_ploadrifnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD(fEA_IMM(uiV), fLSBNEWNOT(PtN), 4, u)
+
+/* Predicated loads into a register pair */
+#define fWRAP_PRED_LOAD_PAIR(GET_EA, PRED) \
+    do { \
+        TCGv LSB = tcg_temp_local_new(); \
+        TCGLabel *label = gen_new_label(); \
+        GET_EA; \
+        PRED;  \
+        PRED_LOAD_CANCEL(LSB, EA); \
+        tcg_gen_movi_i64(RddV, 0); \
+        tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \
+            fLOAD(1, 8, u, EA, RddV); \
+        gen_set_label(label); \
+        tcg_temp_free(LSB); \
+    } while (0)
+
+#define fWRAP_L2_ploadrdt_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RI(RsV, uiV), fLSBOLD(PtV))
+#define fWRAP_L2_ploadrdt_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(GET_EA_pi, fLSBOLD(PtV))
+#define fWRAP_L2_ploadrdf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RI(RsV, uiV), fLSBOLDNOT(PtV))
+#define fWRAP_L2_ploadrdf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(GET_EA_pi, fLSBOLDNOT(PtV))
+#define fWRAP_L2_ploadrdtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RI(RsV, uiV), fLSBNEW(PtN))
+#define fWRAP_L2_ploadrdfnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RI(RsV, uiV), fLSBNEWNOT(PtN))
+#define fWRAP_L4_ploadrdt_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RRs(RsV, RtV, uiV), fLSBOLD(PvV))
+#define fWRAP_L4_ploadrdf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RRs(RsV, RtV, uiV), fLSBOLDNOT(PvV))
+#define fWRAP_L4_ploadrdtnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RRs(RsV, RtV, uiV), fLSBNEW(PvN))
+#define fWRAP_L4_ploadrdfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_RRs(RsV, RtV, uiV), fLSBNEWNOT(PvN))
+#define fWRAP_L2_ploadrdtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(GET_EA_pi, fLSBNEW(PtN))
+#define fWRAP_L2_ploadrdfnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(GET_EA_pi, fLSBNEWNOT(PtN))
+#define fWRAP_L4_ploadrdt_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_IMM(uiV), fLSBOLD(PtV))
+#define fWRAP_L4_ploadrdf_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_IMM(uiV), fLSBOLDNOT(PtV))
+#define fWRAP_L4_ploadrdtnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_IMM(uiV), fLSBNEW(PtN))
+#define fWRAP_L4_ploadrdfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_LOAD_PAIR(fEA_IMM(uiV), fLSBNEWNOT(PtN))
+
 #endif
Signature · 1 line
2.7.4
#44 lore raw

RFC PATCH v2 42/67 Hexagon TCG generation - step 04

In reply to Taylor Simpson

Override store instructions

---
 target/hexagon/helper_overrides.h | 241 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 241 insertions(+)
target/hexagon/helper_overrides.h +241 -0
index 20d8584..fdcc517 100644
@@ -636,4 +636,245 @@
 #define fWRAP_L4_ploadrdfnew_abs(GENHLPR, SHORTCODE) \
     fWRAP_PRED_LOAD_PAIR(fEA_IMM(uiV), fLSBNEWNOT(PtN))
 
+/* load-locked and store-locked */
+#define fWRAP_L2_loadw_locked(GENHLPR, SHORTCODE) \
+    SHORTCODE
+#define fWRAP_L4_loadd_locked(GENHLPR, SHORTCODE) \
+    SHORTCODE
+#define fWRAP_S2_storew_locked(GENHLPR, SHORTCODE) \
+    do { SHORTCODE; READ_PREG(PdV, PdN); } while (0)
+#define fWRAP_S4_stored_locked(GENHLPR, SHORTCODE) \
+    do { SHORTCODE; READ_PREG(PdV, PdN); } while (0)
+
+#define fWRAP_STORE(SHORTCODE) \
+    do { \
+        TCGv HALF = tcg_temp_new(); \
+        TCGv BYTE = tcg_temp_new(); \
+        TCGv NEWREG_ST = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        SHORTCODE; \
+        tcg_temp_free(HALF); \
+        tcg_temp_free(BYTE); \
+        tcg_temp_free(NEWREG_ST); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_STORE_ap(STORE) \
+    do { \
+        TCGv HALF = tcg_temp_new(); \
+        TCGv BYTE = tcg_temp_new(); \
+        TCGv NEWREG_ST = tcg_temp_new(); \
+        { \
+            fEA_IMM(UiV); \
+            STORE; \
+            tcg_gen_movi_tl(ReV, UiV); \
+        } \
+        tcg_temp_free(HALF); \
+        tcg_temp_free(BYTE); \
+        tcg_temp_free(NEWREG_ST); \
+    } while (0)
+
+#define fWRAP_STORE_pcr(SHIFT, STORE) \
+    do { \
+        TCGv ireg = tcg_temp_new(); \
+        TCGv HALF = tcg_temp_new(); \
+        TCGv BYTE = tcg_temp_new(); \
+        TCGv NEWREG_ST = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        fEA_REG(RxV); \
+        fPM_CIRR(RxV, fREAD_IREG(MuV, SHIFT), MuV); \
+        STORE; \
+        tcg_temp_free(ireg); \
+        tcg_temp_free(HALF); \
+        tcg_temp_free(BYTE); \
+        tcg_temp_free(NEWREG_ST); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_S2_storerb_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerb_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerb_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 1, EA, fGETBYTE(0, RtV)))
+#define fWRAP_S2_storerb_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerb_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerb_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerb_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerb_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(0, fSTORE(1, 1, EA, fGETBYTE(0, RtV)))
+#define fWRAP_S4_storerb_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerbnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storeirb_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerbgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS1_storeb_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS2_storebi0(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerh_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerh_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerh_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 2, EA, fGETHALF(0, RtV)))
+#define fWRAP_S2_storerh_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerh_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerh_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerh_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerh_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(1, fSTORE(1, 2, EA, fGETHALF(0, RtV)))
+#define fWRAP_S4_storerh_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storeirh_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerhgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS2_storeh_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerf_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerf_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerf_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 2, EA, fGETHALF(1, RtV)))
+#define fWRAP_S2_storerf_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerf_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerf_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerf_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerf_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(1, fSTORE(1, 2, EA, fGETHALF(1, RtV)))
+#define fWRAP_S4_storerf_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerfgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storeri_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storeri_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storeri_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 4, EA, RtV))
+#define fWRAP_S2_storeri_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storeri_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storeri_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storeri_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storeri_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(2, fSTORE(1, 4, EA, RtV))
+#define fWRAP_S4_storeri_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerinew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storeiri_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerigp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS1_storew_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS2_storew_sp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS2_storewi0(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerd_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerd_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerd_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 8, EA, RttV))
+#define fWRAP_S2_storerd_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerd_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerd_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerd_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerd_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(3, fSTORE(1, 8, EA, RttV))
+#define fWRAP_S4_storerd_rr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerdgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_SS2_stored_sp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerbnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerbnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerbnew_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 1, EA, fGETBYTE(0, fNEWREG_ST(NtN))))
+#define fWRAP_S2_storerbnew_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerbnew_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerbnew_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerbnew_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerbnew_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(0, fSTORE(1, 1, EA, fGETBYTE(0, fNEWREG_ST(NtN))))
+#define fWRAP_S2_storerbnewgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerhnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerhnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerhnew_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 2, EA, fGETHALF(0, fNEWREG_ST(NtN))))
+#define fWRAP_S2_storerhnew_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerhnew_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerhnew_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerhnew_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerhnew_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(1, fSTORE(1, 2, EA, fGETHALF(0, fNEWREG_ST(NtN))))
+#define fWRAP_S2_storerhnewgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
+#define fWRAP_S2_storerinew_io(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerinew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerinew_ap(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_ap(fSTORE(1, 4, EA, fNEWREG_ST(NtN)))
+#define fWRAP_S2_storerinew_pr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S4_storerinew_ur(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerinew_pbr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerinew_pci(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+#define fWRAP_S2_storerinew_pcr(GENHLPR, SHORTCODE) \
+    fWRAP_STORE_pcr(2, fSTORE(1, 4, EA, fNEWREG_ST(NtN)))
+#define fWRAP_S2_storerinewgp(GENHLPR, SHORTCODE) \
+    fWRAP_STORE(SHORTCODE)
+
 #endif
Signature · 1 line
2.7.4
#45 lore raw

RFC PATCH v2 43/67 Hexagon TCG generation - step 05

In reply to Taylor Simpson

Override predicated store instructions

---
 target/hexagon/helper_overrides.h | 54 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
target/hexagon/helper_overrides.h +54 -0
index fdcc517..a6cbce0 100644
@@ -877,4 +877,58 @@
 #define fWRAP_S2_storerinewgp(GENHLPR, SHORTCODE) \
     fWRAP_STORE(SHORTCODE)
 
+/* Predicated stores */
+#define fWRAP_PRED_STORE(GET_EA, PRED, SRC, SIZE, INC) \
+    do { \
+        TCGv LSB = tcg_temp_local_new(); \
+        TCGv NEWREG_ST = tcg_temp_local_new(); \
+        TCGv BYTE = tcg_temp_local_new(); \
+        TCGv HALF = tcg_temp_local_new(); \
+        TCGLabel *label = gen_new_label(); \
+        GET_EA; \
+        PRED;  \
+        PRED_STORE_CANCEL(LSB, EA); \
+        tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \
+            INC; \
+            fSTORE(1, SIZE, EA, SRC); \
+        gen_set_label(label); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free(NEWREG_ST); \
+        tcg_temp_free(BYTE); \
+        tcg_temp_free(HALF); \
+    } while (0)
+
+#define NOINC    do {} while (0)
+
+#define fWRAP_S4_pstorerinewfnew_rr(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_RRs(RsV, RuV, uiV), fLSBNEWNOT(PvN), \
+                     hex_new_value[NtX], 4, NOINC)
+#define fWRAP_S2_pstorerdtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_REG(RxV), fLSBNEW(PvN), \
+                     RttV, 8, tcg_gen_addi_tl(RxV, RxV, IMMNO(0)))
+#define fWRAP_S4_pstorerdtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_RI(RsV, uiV), fLSBNEW(PvN), \
+                     RttV, 8, NOINC)
+#define fWRAP_S4_pstorerbtnew_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_RI(RsV, uiV), fLSBNEW(PvN), \
+                     fGETBYTE(0, RtV), 1, NOINC)
+#define fWRAP_S2_pstorerhtnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_REG(RxV), fLSBNEW(PvN), \
+                     fGETHALF(0, RtV), 2, tcg_gen_addi_tl(RxV, RxV, IMMNO(0)))
+#define fWRAP_S2_pstoreritnew_pi(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_REG(RxV), fLSBNEW(PvN), \
+                     RtV, 4, tcg_gen_addi_tl(RxV, RxV, IMMNO(0)))
+#define fWRAP_S2_pstorerif_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_RI(RsV, uiV), fLSBOLDNOT(PvV), \
+                     RtV, 4, NOINC)
+#define fWRAP_S4_pstorerit_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_IMM(uiV), fLSBOLD(PvV), \
+                     RtV, 4, NOINC)
+#define fWRAP_S2_pstorerinewf_io(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_RI(RsV, uiV), fLSBOLDNOT(PvV), \
+                     hex_new_value[NtX], 4, NOINC)
+#define fWRAP_S4_pstorerbnewfnew_abs(GENHLPR, SHORTCODE) \
+    fWRAP_PRED_STORE(fEA_IMM(uiV), fLSBNEWNOT(PvN), \
+                     fGETBYTE(0, hex_new_value[NtX]), 1, NOINC)
+
 #endif
Signature · 1 line
2.7.4
#46 lore raw

RFC PATCH v2 44/67 Hexagon TCG generation - step 06

In reply to Taylor Simpson

Override memop instructions

---
 target/hexagon/helper_overrides.h | 60 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
target/hexagon/helper_overrides.h +60 -0
index a6cbce0..00647cb 100644
@@ -931,4 +931,64 @@
     fWRAP_PRED_STORE(fEA_IMM(uiV), fLSBNEWNOT(PvN), \
                      fGETBYTE(0, hex_new_value[NtX]), 1, NOINC)
 
+/* We have to brute force memops because they have C math in the semantics */
+#define fWRAP_MEMOP(GENHLPR, SHORTCODE, SIZE, OP) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        fEA_RI(RsV, uiV); \
+        fLOAD(1, SIZE, s, EA, tmp); \
+        OP; \
+        fSTORE(1, SIZE, EA, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_L4_add_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_add_tl(tmp, tmp, RtV))
+#define fWRAP_L4_add_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_add_tl(tmp, tmp, RtV))
+#define fWRAP_L4_add_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_add_tl(tmp, tmp, RtV))
+#define fWRAP_L4_sub_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_sub_tl(tmp, tmp, RtV))
+#define fWRAP_L4_sub_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_sub_tl(tmp, tmp, RtV))
+#define fWRAP_L4_sub_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_sub_tl(tmp, tmp, RtV))
+#define fWRAP_L4_and_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_and_tl(tmp, tmp, RtV))
+#define fWRAP_L4_and_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_and_tl(tmp, tmp, RtV))
+#define fWRAP_L4_and_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_and_tl(tmp, tmp, RtV))
+#define fWRAP_L4_or_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_or_tl(tmp, tmp, RtV))
+#define fWRAP_L4_or_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_or_tl(tmp, tmp, RtV))
+#define fWRAP_L4_or_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_or_tl(tmp, tmp, RtV))
+#define fWRAP_L4_iadd_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_addi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_iadd_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_addi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_iadd_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_addi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_isub_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_subi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_isub_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_subi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_isub_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_subi_tl(tmp, tmp, UiV))
+#define fWRAP_L4_iand_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_andi_tl(tmp, tmp, ~(1 << UiV)))
+#define fWRAP_L4_iand_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_andi_tl(tmp, tmp, ~(1 << UiV)))
+#define fWRAP_L4_iand_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_andi_tl(tmp, tmp, ~(1 << UiV)))
+#define fWRAP_L4_ior_memopw_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 4, tcg_gen_ori_tl(tmp, tmp, 1 << UiV))
+#define fWRAP_L4_ior_memopb_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 1, tcg_gen_ori_tl(tmp, tmp, 1 << UiV))
+#define fWRAP_L4_ior_memoph_io(GENHLPR, SHORTCODE) \
+    fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_ori_tl(tmp, tmp, 1 << UiV))
+
 #endif
Signature · 1 line
2.7.4
#47 lore raw

RFC PATCH v2 45/67 Hexagon TCG generation - step 07

In reply to Taylor Simpson

Override dczeroa, allocframe, and return instructions

---
 target/hexagon/helper_overrides.h | 209 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 209 insertions(+)
target/hexagon/helper_overrides.h +209 -0
index 00647cb..1ac363e 100644
@@ -991,4 +991,213 @@
 #define fWRAP_L4_ior_memoph_io(GENHLPR, SHORTCODE) \
     fWRAP_MEMOP(GENHLPR, SHORTCODE, 2, tcg_gen_ori_tl(tmp, tmp, 1 << UiV))
 
+/* dczeroa clears the 32 byte cache line at the address given */
+#define fWRAP_Y2_dczeroa(GENHLPR, SHORTCODE) SHORTCODE
+
+/* We have to brute force allocframe because it has C math in the semantics */
+#define fWRAP_S2_allocframe(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv_i64 scramble_tmp = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        { fEA_RI(RxV, -8); \
+          fSTORE(1, 8, EA, fFRAME_SCRAMBLE((fCAST8_8u(fREAD_LR()) << 32) | \
+                                           fCAST4_4u(fREAD_FP()))); \
+          fWRITE_FP(EA); \
+          fFRAMECHECK(EA - uiV, EA); \
+          tcg_gen_subi_tl(RxV, EA, uiV); \
+        } \
+        tcg_temp_free_i64(scramble_tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_SS2_allocframe(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv_i64 scramble_tmp = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        { fEA_RI(fREAD_SP(), -8); \
+          fSTORE(1, 8, EA, fFRAME_SCRAMBLE((fCAST8_8u(fREAD_LR()) << 32) | \
+                                           fCAST4_4u(fREAD_FP()))); \
+          fWRITE_FP(EA); \
+          fFRAMECHECK(EA - uiV, EA); \
+          tcg_gen_subi_tl(tmp, EA, uiV); \
+          fWRITE_SP(tmp); \
+        } \
+        tcg_temp_free_i64(scramble_tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* Also have to brute force the deallocframe variants */
+#define fWRAP_L2_deallocframe(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        { \
+          fEA_REG(RsV); \
+          fLOAD(1, 8, u, EA, tmp_i64); \
+          tcg_gen_mov_i64(RddV, fFRAME_UNSCRAMBLE(tmp_i64)); \
+          tcg_gen_addi_tl(tmp, EA, 8); \
+          fWRITE_SP(tmp); \
+        } \
+        tcg_temp_free(tmp); \
+        tcg_temp_free_i64(tmp_i64); \
+    } while (0)
+
+#define fWRAP_SL2_deallocframe(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv WORD = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        { \
+          fEA_REG(fREAD_FP()); \
+          fLOAD(1, 8, u, EA, tmp_i64); \
+          fFRAME_UNSCRAMBLE(tmp_i64); \
+          fWRITE_LR(fGETWORD(1, tmp_i64)); \
+          fWRITE_FP(fGETWORD(0, tmp_i64)); \
+          tcg_gen_addi_tl(tmp, EA, 8); \
+          fWRITE_SP(tmp); \
+        } \
+        tcg_temp_free(WORD); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free_i64(tmp_i64); \
+    } while (0)
+
+#define fWRAP_L4_return(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv WORD = tcg_temp_new(); \
+        { \
+          fEA_REG(RsV); \
+          fLOAD(1, 8, u, EA, tmp_i64); \
+          tcg_gen_mov_i64(RddV, fFRAME_UNSCRAMBLE(tmp_i64)); \
+          tcg_gen_addi_tl(tmp, EA, 8); \
+          fWRITE_SP(tmp); \
+          fJUMPR(REG_LR, fGETWORD(1, RddV), COF_TYPE_JUMPR);\
+        } \
+        tcg_temp_free(tmp); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(WORD); \
+    } while (0)
+
+#define fWRAP_SL2_return(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv WORD = tcg_temp_new(); \
+        { \
+          fEA_REG(fREAD_FP()); \
+          fLOAD(1, 8, u, EA, tmp_i64); \
+          fFRAME_UNSCRAMBLE(tmp_i64); \
+          fWRITE_LR(fGETWORD(1, tmp_i64)); \
+          fWRITE_FP(fGETWORD(0, tmp_i64)); \
+          tcg_gen_addi_tl(tmp, EA, 8); \
+          fWRITE_SP(tmp); \
+          fJUMPR(REG_LR, fGETWORD(1, tmp_i64), COF_TYPE_JUMPR);\
+        } \
+        tcg_temp_free(tmp); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(WORD); \
+    } while (0)
+
+/*
+ * Conditional returns follow the same predicate naming convention as
+ * predicated loads above
+ */
+#define fWRAP_COND_RETURN(PRED) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv_i64 LSB_i64 = tcg_temp_new_i64(); \
+        TCGv zero = tcg_const_tl(0); \
+        TCGv_i64 zero_i64 = tcg_const_i64(0); \
+        TCGv_i64 unscramble = tcg_temp_new_i64(); \
+        TCGv WORD = tcg_temp_new(); \
+        TCGv SP = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        fEA_REG(RsV); \
+        PRED; \
+        tcg_gen_extu_i32_i64(LSB_i64, LSB); \
+        fLOAD(1, 8, u, EA, tmp_i64); \
+        tcg_gen_mov_i64(unscramble, fFRAME_UNSCRAMBLE(tmp_i64)); \
+        READ_REG_PAIR(RddV, HEX_REG_FP); \
+        tcg_gen_movcond_i64(TCG_COND_NE, RddV, LSB_i64, zero_i64, \
+                            unscramble, RddV); \
+        tcg_gen_mov_tl(SP, hex_gpr[HEX_REG_SP]); \
+        tcg_gen_addi_tl(tmp, EA, 8); \
+        tcg_gen_movcond_tl(TCG_COND_NE, SP, LSB, zero, tmp, SP); \
+        fWRITE_SP(SP); \
+        gen_cond_return(LSB, fGETWORD(1, RddV)); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free_i64(LSB_i64); \
+        tcg_temp_free(zero); \
+        tcg_temp_free_i64(zero_i64); \
+        tcg_temp_free_i64(unscramble); \
+        tcg_temp_free(WORD); \
+        tcg_temp_free(SP); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_L4_return_t(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBOLD(PvV))
+#define fWRAP_L4_return_f(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBOLDNOT(PvV))
+#define fWRAP_L4_return_tnew_pt(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBNEW(PvN))
+#define fWRAP_L4_return_fnew_pt(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBNEWNOT(PvN))
+#define fWRAP_L4_return_tnew_pnt(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBNEW(PvN))
+#define fWRAP_L4_return_tnew_pnt(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBNEW(PvN))
+#define fWRAP_L4_return_fnew_pnt(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN(fLSBNEWNOT(PvN))
+
+#define fWRAP_COND_RETURN_SUBINSN(PRED) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv_i64 LSB_i64 = tcg_temp_new_i64(); \
+        TCGv zero = tcg_const_tl(0); \
+        TCGv_i64 zero_i64 = tcg_const_i64(0); \
+        TCGv_i64 unscramble = tcg_temp_new_i64(); \
+        TCGv_i64 RddV = tcg_temp_new_i64(); \
+        TCGv WORD = tcg_temp_new(); \
+        TCGv SP = tcg_temp_new(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        fEA_REG(fREAD_FP()); \
+        PRED; \
+        tcg_gen_extu_i32_i64(LSB_i64, LSB); \
+        fLOAD(1, 8, u, EA, tmp_i64); \
+        tcg_gen_mov_i64(unscramble, fFRAME_UNSCRAMBLE(tmp_i64)); \
+        READ_REG_PAIR(RddV, HEX_REG_FP); \
+        tcg_gen_movcond_i64(TCG_COND_NE, RddV, LSB_i64, zero_i64, \
+                            unscramble, RddV); \
+        tcg_gen_mov_tl(SP, hex_gpr[HEX_REG_SP]); \
+        tcg_gen_addi_tl(tmp, EA, 8); \
+        tcg_gen_movcond_tl(TCG_COND_NE, SP, LSB, zero, tmp, SP); \
+        fWRITE_SP(SP); \
+        WRITE_REG_PAIR(HEX_REG_FP, RddV); \
+        gen_cond_return(LSB, fGETWORD(1, RddV)); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free_i64(LSB_i64); \
+        tcg_temp_free(zero); \
+        tcg_temp_free_i64(zero_i64); \
+        tcg_temp_free_i64(unscramble); \
+        tcg_temp_free_i64(RddV); \
+        tcg_temp_free(WORD); \
+        tcg_temp_free(SP); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_SL2_return_t(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN_SUBINSN(fLSBOLD(fREAD_P0()))
+#define fWRAP_SL2_return_f(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN_SUBINSN(fLSBOLDNOT(fREAD_P0()))
+#define fWRAP_SL2_return_tnew(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN_SUBINSN(fLSBNEW0)
+#define fWRAP_SL2_return_fnew(GENHLPR, SHORTCODE) \
+    fWRAP_COND_RETURN_SUBINSN(fLSBNEW0NOT)
+
 #endif
Signature · 1 line
2.7.4
#48 lore raw

RFC PATCH v2 46/67 Hexagon TCG generation - step 08

In reply to Taylor Simpson

Override mathematical operations with more than one definition

---
 target/hexagon/helper_overrides.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
target/hexagon/helper_overrides.h +30 -0
index 1ac363e..d18aea4 100644
@@ -1200,4 +1200,34 @@
 #define fWRAP_SL2_return_fnew(GENHLPR, SHORTCODE) \
     fWRAP_COND_RETURN_SUBINSN(fLSBNEW0NOT)
 
+/*
+ * Mathematical operations with more than one definition require
+ * special handling
+ */
+/*
+ * Approximate reciprocal
+ * r3,p1 = sfrecipa(r0, r1)
+ */
+#define fWRAP_F2_sfrecipa(GENHLPR, SHORTCODE) \
+    do { \
+        gen_helper_sfrecipa_val(RdV, cpu_env, RsV, RtV);  \
+        gen_helper_sfrecipa_pred(PeV, cpu_env, RsV, RtV);  \
+    } while (0)
+
+/*
+ * Approximation of the reciprocal square root
+ * r1,p0 = sfinvsqrta(r0)
+ */
+#define fWRAP_F2_sfinvsqrta(GENHLPR, SHORTCODE) \
+    do { \
+        gen_helper_sfinvsqrta_val(RdV, cpu_env, RsV); \
+        gen_helper_sfinvsqrta_pred(PeV, cpu_env, RsV); \
+    } while (0)
+
+#define fWRAP_A5_ACS(GENHLPR, SHORTCODE) \
+    do { \
+        gen_helper_vacsh_val(RxxV, cpu_env, RxxV, RssV, RttV); \
+        gen_helper_vacsh_pred(PeV, cpu_env, RxxV, RssV, RttV); \
+    } while (0)
+
 #endif
Signature · 1 line
2.7.4
#49 lore raw

RFC PATCH v2 47/67 Hexagon TCG generation - step 09

In reply to Taylor Simpson

Override instructions to speed up qemu

---
 target/hexagon/helper_overrides.h | 97 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
target/hexagon/helper_overrides.h +97 -0
index d18aea4..5443a94e 100644
@@ -1230,4 +1230,101 @@
         gen_helper_vacsh_pred(PeV, cpu_env, RxxV, RssV, RttV); \
     } while (0)
 
+/*
+ * The following fWRAP macros are to speed up qemu
+ * We can add more over time
+ */
+
+/*
+ * Add or subtract with carry.
+ * Predicate register is used as an extra input and output.
+ * r5:4 = add(r1:0, r3:2, p1):carry
+ */
+#define fWRAP_A4_addp_c(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv_i64 LSB_i64 = tcg_temp_new_i64(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_add_i64(RddV, RssV, RttV); \
+        fLSBOLD(PxV); \
+        tcg_gen_extu_i32_i64(LSB_i64, LSB); \
+        tcg_gen_add_i64(RddV, RddV, LSB_i64); \
+        fCARRY_FROM_ADD(RssV, RttV, LSB_i64); \
+        tcg_gen_extrl_i64_i32(tmp, RssV); \
+        f8BITSOF(PxV, tmp); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free_i64(LSB_i64); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r5:4 = sub(r1:0, r3:2, p1):carry */
+#define fWRAP_A4_subp_c(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv_i64 LSB_i64 = tcg_temp_new_i64(); \
+        TCGv_i64 tmp_i64 = tcg_temp_new_i64(); \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_not_i64(tmp_i64, RttV); \
+        tcg_gen_add_i64(RddV, RssV, tmp_i64); \
+        fLSBOLD(PxV); \
+        tcg_gen_extu_i32_i64(LSB_i64, LSB); \
+        tcg_gen_add_i64(RddV, RddV, LSB_i64); \
+        fCARRY_FROM_ADD(RssV, tmp_i64, LSB_i64); \
+        tcg_gen_extrl_i64_i32(tmp, RssV); \
+        f8BITSOF(PxV, tmp); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free_i64(LSB_i64); \
+        tcg_temp_free_i64(tmp_i64); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/*
+ * Compare each of the 8 unsigned bytes
+ * The minimum is places in each byte of the destination.
+ * Each bit of the predicate is set true if the bit from the first operand
+ * is greater than the bit from the second operand.
+ * r5:4,p1 = vminub(r1:0, r3:2)
+ */
+#define fWRAP_A6_vminub_RdP(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv BYTE = tcg_temp_new(); \
+        TCGv left = tcg_temp_new(); \
+        TCGv right = tcg_temp_new(); \
+        TCGv tmp = tcg_temp_new(); \
+        int i; \
+        tcg_gen_movi_tl(PeV, 0); \
+        tcg_gen_movi_i64(RddV, 0); \
+        for (i = 0; i < 8; i++) { \
+            fGETUBYTE(i, RttV); \
+            tcg_gen_mov_tl(left, BYTE); \
+            fGETUBYTE(i, RssV); \
+            tcg_gen_mov_tl(right, BYTE); \
+            tcg_gen_setcond_tl(TCG_COND_GT, tmp, left, right); \
+            fSETBIT(i, PeV, tmp); \
+            fMIN(tmp, left, right); \
+            fSETBYTE(i, RddV, tmp); \
+        } \
+        tcg_temp_free(BYTE); \
+        tcg_temp_free(left); \
+        tcg_temp_free(right); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_J2_call(GENHLPR, SHORTCODE) \
+    gen_call(riV)
+#define fWRAP_J2_callr(GENHLPR, SHORTCODE) \
+    gen_callr(RsV)
+
+#define fWRAP_J2_loop0r(GENHLPR, SHORTCODE) \
+    gen_loop0r(RsV, riV, insn)
+#define fWRAP_J2_loop1r(GENHLPR, SHORTCODE) \
+    gen_loop1r(RsV, riV, insn)
+
+#define fWRAP_J2_endloop0(GENHLPR, SHORTCODE) \
+    gen_endloop0()
+#define fWRAP_J2_endloop1(GENHLPR, SHORTCODE) \
+    gen_endloop1()
+
 #endif
Signature · 1 line
2.7.4
#50 lore raw

RFC PATCH v2 48/67 Hexagon TCG generation - step 10

In reply to Taylor Simpson

Override compound compare and jump instructions

---
 target/hexagon/helper_overrides.h | 105 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
target/hexagon/helper_overrides.h +105 -0
index 5443a94e..d3311be 100644
@@ -1327,4 +1327,109 @@
 #define fWRAP_J2_endloop1(GENHLPR, SHORTCODE) \
     gen_endloop1()
 
+/*
+ * Compound compare and jump instructions
+ * Here is a primer to understand the tag names
+ *
+ * Comparison
+ *      cmpeqi   compare equal to an immediate
+ *      cmpgti   compare greater than an immediate
+ *      cmpgtiu  compare greater than an unsigned immediate
+ *      cmpeqn1  compare equal to negative 1
+ *      cmpgtn1  compare greater than negative 1
+ *      cmpeq    compare equal (two registers)
+ *
+ * Condition
+ *      tp0      p0 is true     p0 = cmp.eq(r0,#5); if (p0.new) jump:nt address
+ *      fp0      p0 is false    p0 = cmp.eq(r0,#5); if (!p0.new) jump:nt address
+ *      tp1      p1 is true     p1 = cmp.eq(r0,#5); if (p1.new) jump:nt address
+ *      fp1      p1 is false    p1 = cmp.eq(r0,#5); if (!p1.new) jump:nt address
+ *
+ * Prediction (not modelled in qemu)
+ *      _nt      not taken
+ *      _t       taken
+ */
+#define fWRAP_J4_cmpeqi_tp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_EQ, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_fp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_EQ, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_EQ, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_fp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_EQ, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_tp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_EQ, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_fp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_EQ, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_tp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_EQ, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqi_fp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_EQ, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_tp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GT, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_fp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GT, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GT, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_fp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GT, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_tp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GT, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_fp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GT, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_tp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GT, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgti_fp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GT, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_tp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GTU, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_fp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GTU, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GTU, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_fp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(0, TCG_COND_GTU, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_tp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GTU, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_fp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GTU, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_tp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GTU, true, RsV, UiV, riV)
+#define fWRAP_J4_cmpgtui_fp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmpi_jmp(1, TCG_COND_GTU, false, RsV, UiV, riV)
+#define fWRAP_J4_cmpeqn1_tp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_EQ, true, RsV, riV)
+#define fWRAP_J4_cmpeqn1_fp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_EQ, false, RsV, riV)
+#define fWRAP_J4_cmpeqn1_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_EQ, true, RsV, riV)
+#define fWRAP_J4_cmpeqn1_fp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_EQ, false, RsV, riV)
+#define fWRAP_J4_cmpeqn1_tp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_EQ, true, RsV, riV)
+#define fWRAP_J4_cmpeqn1_fp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_EQ, false, RsV, riV)
+#define fWRAP_J4_cmpeqn1_tp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_EQ, true, RsV, riV)
+#define fWRAP_J4_cmpeqn1_fp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_EQ, false, RsV, riV)
+#define fWRAP_J4_cmpgtn1_tp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_GT, true, RsV, riV)
+#define fWRAP_J4_cmpgtn1_fp0_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_GT, false, RsV, riV)
+#define fWRAP_J4_cmpgtn1_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_GT, true, RsV, riV)
+#define fWRAP_J4_cmpgtn1_fp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(0, TCG_COND_GT, false, RsV, riV)
+#define fWRAP_J4_cmpgtn1_tp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_GT, true, RsV, riV)
+#define fWRAP_J4_cmpgtn1_fp1_jump_nt(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_GT, false, RsV, riV)
+#define fWRAP_J4_cmpgtn1_tp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_GT, true, RsV, riV)
+#define fWRAP_J4_cmpgtn1_fp1_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_n1_jmp(1, TCG_COND_GT, false, RsV, riV)
+#define fWRAP_J4_cmpeq_tp0_jump_t(GENHLPR, SHORTCODE) \
+    gen_cmpnd_cmp_jmp(0, TCG_COND_EQ, true, RsV, RtV, riV)
+
 #endif
Signature · 1 line
2.7.4
#51 lore raw

RFC PATCH v2 49/67 Hexagon TCG generation - step 11

In reply to Taylor Simpson

Override compare, transfer, conditional jump instructions

---
 target/hexagon/helper_overrides.h | 119 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
target/hexagon/helper_overrides.h +119 -0
index d3311be..ad9a88c 100644
@@ -1432,4 +1432,123 @@
 #define fWRAP_J4_cmpeq_tp0_jump_t(GENHLPR, SHORTCODE) \
     gen_cmpnd_cmp_jmp(0, TCG_COND_EQ, true, RsV, RtV, riV)
 
+/* p0 = cmp.eq(r0, #7) */
+#define fWRAP_SA1_cmpeqi(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        gen_comparei(TCG_COND_EQ, tmp, RsV, uiV); \
+        gen_log_pred_write(0, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 = add(r29,#8) */
+#define fWRAP_SA1_addsp(GENHLPR, SHORTCODE) \
+    tcg_gen_addi_tl(RdV, hex_gpr[HEX_REG_SP], IMMNO(0))
+
+/* r0 = add(r0, r1) */
+#define fWRAP_SA1_addrx(GENHLPR, SHORTCODE) \
+    tcg_gen_add_tl(RxV, RxV, RsV)
+
+#define fWRAP_A2_add(GENHLPR, SHORTCODE) \
+    tcg_gen_add_tl(RdV, RsV, RtV)
+
+#define fWRAP_A2_sub(GENHLPR, SHORTCODE) \
+    tcg_gen_sub_tl(RdV, RtV, RsV)
+
+/* r0 = sub(#10, r1) */
+#define fWRAP_A2_subri(GENHLPR, SHORTCODE) \
+    tcg_gen_subfi_tl(RdV, siV, RsV)
+
+#define fWRAP_A2_addi(GENHLPR, SHORTCODE) \
+    tcg_gen_addi_tl(RdV, RsV, siV)
+
+#define fWRAP_A2_and(GENHLPR, SHORTCODE) \
+    tcg_gen_and_tl(RdV, RsV, RtV)
+
+#define fWRAP_A2_andir(GENHLPR, SHORTCODE) \
+    tcg_gen_andi_tl(RdV, RsV, siV)
+
+#define fWRAP_A2_xor(GENHLPR, SHORTCODE) \
+    tcg_gen_xor_tl(RdV, RsV, RtV)
+
+/* Transfer instructions */
+#define fWRAP_A2_tfr(GENHLPR, SHORTCODE) \
+    tcg_gen_mov_tl(RdV, RsV)
+#define fWRAP_SA1_tfr(GENHLPR, SHORTCODE) \
+    tcg_gen_mov_tl(RdV, RsV)
+#define fWRAP_A2_tfrsi(GENHLPR, SHORTCODE) \
+    tcg_gen_movi_tl(RdV, siV)
+#define fWRAP_A2_tfrcrr(GENHLPR, SHORTCODE) \
+    tcg_gen_mov_tl(RdV, CsV)
+#define fWRAP_A2_tfrrcr(GENHLPR, SHORTCODE) \
+    tcg_gen_mov_tl(CdV, RsV)
+
+#define fWRAP_A2_nop(GENHLPR, SHORTCODE) \
+    do { } while (0)
+
+/* Compare instructions */
+#define fWRAP_C2_cmpeq(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_EQ, PdV, RsV, RtV)
+#define fWRAP_C4_cmpneq(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_NE, PdV, RsV, RtV)
+#define fWRAP_C2_cmpgt(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_GT, PdV, RsV, RtV)
+#define fWRAP_C2_cmpgtu(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_GTU, PdV, RsV, RtV)
+#define fWRAP_C4_cmplte(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_LE, PdV, RsV, RtV)
+#define fWRAP_C4_cmplteu(GENHLPR, SHORTCODE) \
+    gen_compare(TCG_COND_LEU, PdV, RsV, RtV)
+#define fWRAP_C2_cmpeqp(GENHLPR, SHORTCODE) \
+    gen_compare_i64(TCG_COND_EQ, PdV, RssV, RttV)
+#define fWRAP_C2_cmpgtp(GENHLPR, SHORTCODE) \
+    gen_compare_i64(TCG_COND_GT, PdV, RssV, RttV)
+#define fWRAP_C2_cmpgtup(GENHLPR, SHORTCODE) \
+    gen_compare_i64(TCG_COND_GTU, PdV, RssV, RttV)
+#define fWRAP_C2_cmpeqi(GENHLPR, SHORTCODE) \
+    gen_comparei(TCG_COND_EQ, PdV, RsV, siV)
+#define fWRAP_C2_cmpgti(GENHLPR, SHORTCODE) \
+    gen_comparei(TCG_COND_GT, PdV, RsV, siV)
+#define fWRAP_C2_cmpgtui(GENHLPR, SHORTCODE) \
+    gen_comparei(TCG_COND_GTU, PdV, RsV, uiV)
+
+#define fWRAP_SA1_zxtb(GENHLPR, SHORTCODE) \
+    tcg_gen_ext8u_tl(RdV, RsV)
+
+#define fWRAP_J2_jump(GENHLPR, SHORTCODE) \
+    gen_jump(riV)
+#define fWRAP_J2_jumpr(GENHLPR, SHORTCODE) \
+    gen_write_new_pc(RsV)
+
+#define fWRAP_cond_jump(COND) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        COND; \
+        gen_cond_jump(LSB, riV); \
+        tcg_temp_free(LSB); \
+    } while (0)
+
+#define fWRAP_J2_jumpt(GENHLPR, SHORTCODE) \
+    fWRAP_cond_jump(fLSBOLD(PuV))
+#define fWRAP_J2_jumpf(GENHLPR, SHORTCODE) \
+    fWRAP_cond_jump(fLSBOLDNOT(PuV))
+#define fWRAP_J2_jumpfnewpt(GENHLPR, SHORTCODE) \
+    fWRAP_cond_jump(fLSBNEWNOT(PuN))
+#define fWRAP_J2_jumpfnew(GENHLPR, SHORTCODE) \
+    fWRAP_cond_jump(fLSBNEWNOT(PuN))
+
+#define fWRAP_J2_jumprfnew(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        tcg_gen_andi_tl(LSB, PuN, 1); \
+        tcg_gen_xori_tl(LSB, LSB, 1); \
+        gen_cond_jumpr(LSB, RsV); \
+        tcg_temp_free(LSB); \
+    } while (0)
+
+#define fWRAP_J2_jumptnew(GENHLPR, SHORTCODE) \
+    gen_cond_jump(PuN, riV)
+#define fWRAP_J2_jumptnewpt(GENHLPR, SHORTCODE) \
+    gen_cond_jump(PuN, riV)
+
 #endif
Signature · 1 line
2.7.4
#52 lore raw

RFC PATCH v2 50/67 Hexagon TCG generation - step 12

In reply to Taylor Simpson

Override miscellaneous instructions identified during profiling

---
 target/hexagon/helper_overrides.h | 296 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 296 insertions(+)
target/hexagon/helper_overrides.h +296 -0
index ad9a88c..b796ced 100644
@@ -1551,4 +1551,300 @@
 #define fWRAP_J2_jumptnewpt(GENHLPR, SHORTCODE) \
     gen_cond_jump(PuN, riV)
 
+/*
+ * New value compare & jump instructions
+ * if ([!]COND(r0.new, r1) jump:t address
+ * if ([!]COND(r0.new, #7) jump:t address
+ */
+#define fWRAP_J4_cmpgt_f_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_LE, NsX, RtV, riV)
+#define fWRAP_J4_cmpeq_f_jumpnv_nt(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_NE, NsX, RtV, riV)
+#define fWRAP_J4_cmpgt_t_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_GT, NsX, RtV, riV)
+#define fWRAP_J4_cmpeqi_t_jumpnv_nt(GENHLPR, SHORTCODE) \
+    gen_cmpi_jumpnv(TCG_COND_EQ, NsX, UiV, riV)
+#define fWRAP_J4_cmpltu_f_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_GEU, NsX, RtV, riV)
+#define fWRAP_J4_cmpgtui_t_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmpi_jumpnv(TCG_COND_GTU, NsX, UiV, riV)
+#define fWRAP_J4_cmpeq_f_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_NE, NsX, RtV, riV)
+#define fWRAP_J4_cmpeqi_f_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmpi_jumpnv(TCG_COND_NE, NsX, UiV, riV)
+#define fWRAP_J4_cmpgtu_t_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_GTU, NsX, RtV, riV)
+#define fWRAP_J4_cmpgtu_f_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_LEU, NsX, RtV, riV)
+#define fWRAP_J4_cmplt_t_jumpnv_t(GENHLPR, SHORTCODE) \
+    gen_cmp_jumpnv(TCG_COND_LT, NsX, RtV, riV)
+
+/* r0 = r1 ; jump address */
+#define fWRAP_J4_jumpsetr(GENHLPR, SHORTCODE) \
+    do { \
+        tcg_gen_mov_tl(RdV, RsV); \
+        gen_jump(riV); \
+    } while (0)
+
+/* r0 = lsr(r1, #5) */
+#define fWRAP_S2_lsr_i_r(GENHLPR, SHORTCODE) \
+    fLSHIFTR(RdV, RsV, IMMNO(0), 4_4)
+
+/* r0 += lsr(r1, #5) */
+#define fWRAP_S2_lsr_i_r_acc(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        fLSHIFTR(tmp, RsV, IMMNO(0), 4_4); \
+        tcg_gen_add_tl(RxV, RxV, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 ^= lsr(r1, #5) */
+#define fWRAP_S2_lsr_i_r_xacc(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        fLSHIFTR(tmp, RsV, IMMNO(0), 4_4); \
+        tcg_gen_xor_tl(RxV, RxV, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 = asr(r1, #5) */
+#define fWRAP_S2_asr_i_r(GENHLPR, SHORTCODE) \
+    fASHIFTR(RdV, RsV, IMMNO(0), 4_4)
+
+/* r0 = addasl(r1, r2, #3) */
+#define fWRAP_S2_addasl_rrri(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        fASHIFTL(tmp, RsV, IMMNO(0), 4_4); \
+        tcg_gen_add_tl(RdV, RtV, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 |= asl(r1, r2) */
+#define fWRAP_S2_asl_r_r_or(GENHLPR, SHORTCODE) \
+    gen_asl_r_r_or(RxV, RsV, RtV)
+
+/* r0 = asl(r1, #5) */
+#define fWRAP_S2_asl_i_r(GENHLPR, SHORTCODE) \
+    fASHIFTL(RdV, RsV, IMMNO(0), 4_4)
+
+/* r0 |= asl(r1, #5) */
+#define fWRAP_S2_asl_i_r_or(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        fASHIFTL(tmp, RsV, IMMNO(0), 4_4); \
+        tcg_gen_or_tl(RxV, RxV, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 = vsplatb(r1) */
+#define fWRAP_S2_vsplatrb(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        int i; \
+        tcg_gen_movi_tl(RdV, 0); \
+        tcg_gen_andi_tl(tmp, RsV, 0xff); \
+        for (i = 0; i < 4; i++) { \
+            tcg_gen_shli_tl(RdV, RdV, 8); \
+            tcg_gen_or_tl(RdV, RdV, tmp); \
+        } \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+#define fWRAP_SA1_seti(GENHLPR, SHORTCODE) \
+    tcg_gen_movi_tl(RdV, IMMNO(0))
+
+#define fWRAP_S2_insert(GENHLPR, SHORTCODE) \
+    tcg_gen_deposit_i32(RxV, RxV, RsV, IMMNO(1), IMMNO(0))
+
+#define fWRAP_S2_extractu(GENHLPR, SHORTCODE) \
+    tcg_gen_extract_i32(RdV, RsV, IMMNO(1), IMMNO(0))
+
+#define fWRAP_A2_combinew(GENHLPR, SHORTCODE) \
+    tcg_gen_concat_i32_i64(RddV, RtV, RsV)
+#define fWRAP_A2_combineii(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp_lo = tcg_const_tl(SiV); \
+        TCGv tmp_hi = tcg_const_tl(siV); \
+        tcg_gen_concat_i32_i64(RddV, tmp_lo, tmp_hi); \
+        tcg_temp_free(tmp_lo); \
+        tcg_temp_free(tmp_hi); \
+    } while (0)
+#define fWRAP_A4_combineri(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp_lo = tcg_const_tl(siV); \
+        tcg_gen_concat_i32_i64(RddV, tmp_lo, RsV); \
+        tcg_temp_free(tmp_lo); \
+    } while (0)
+#define fWRAP_A4_combineir(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp_hi = tcg_const_tl(siV); \
+        tcg_gen_concat_i32_i64(RddV, RsV, tmp_hi); \
+        tcg_temp_free(tmp_hi); \
+    } while (0)
+#define fWRAP_A4_combineii(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp_lo = tcg_const_tl(UiV); \
+        TCGv tmp_hi = tcg_const_tl(siV); \
+        tcg_gen_concat_i32_i64(RddV, tmp_lo, tmp_hi); \
+        tcg_temp_free(tmp_lo); \
+        tcg_temp_free(tmp_hi); \
+    } while (0)
+
+#define fWRAP_SA1_combine0i(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp_lo = tcg_const_tl(uiV); \
+        TCGv zero = tcg_const_tl(0); \
+        tcg_gen_concat_i32_i64(RddV, tmp_lo, zero); \
+        tcg_temp_free(tmp_lo); \
+        tcg_temp_free(zero); \
+    } while (0)
+
+/* r0 = or(#8, asl(r1, #5)) */
+#define fWRAP_S4_ori_asl_ri(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_shli_tl(tmp, RxV, IMMNO(1)); \
+        tcg_gen_ori_tl(RxV, tmp, IMMNO(0)); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 = add(r1, sub(#6, r2)) */
+#define fWRAP_S4_subaddi(GENHLPR, SHORTCODE) \
+    do { \
+        tcg_gen_sub_tl(RdV, RsV, RuV); \
+        tcg_gen_addi_tl(RdV, RdV, IMMNO(0)); \
+    } while (0)
+
+#define fWRAP_SA1_inc(GENHLPR, SHORTCODE) \
+    tcg_gen_addi_tl(RdV, RsV, 1)
+
+#define fWRAP_SA1_dec(GENHLPR, SHORTCODE) \
+    tcg_gen_subi_tl(RdV, RsV, 1)
+
+/* if (p0.new) r0 = #0 */
+#define fWRAP_SA1_clrtnew(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv mask = tcg_temp_new(); \
+        TCGv zero = tcg_const_tl(0); \
+        tcg_gen_movi_tl(RdV, 0); \
+        tcg_gen_movi_tl(mask, 1 << insn->slot); \
+        tcg_gen_or_tl(mask, hex_slot_cancelled, mask); \
+        tcg_gen_movcond_tl(TCG_COND_EQ, hex_slot_cancelled, \
+                           hex_new_pred_value[0], zero, \
+                           mask, hex_slot_cancelled); \
+        tcg_temp_free(mask); \
+        tcg_temp_free(zero); \
+    } while (0)
+
+/* r0 = add(r1 , mpyi(#6, r2)) */
+#define fWRAP_M4_mpyri_addr_u2(GENHLPR, SHORTCODE) \
+    do { \
+        tcg_gen_muli_tl(RdV, RsV, IMMNO(0)); \
+        tcg_gen_add_tl(RdV, RuV, RdV); \
+    } while (0)
+
+/* Predicated add instructions */
+#define WRAP_padd(PRED, ADD) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv mask = tcg_temp_new(); \
+        TCGv zero = tcg_const_tl(0); \
+        PRED; \
+        ADD; \
+        tcg_gen_movi_tl(mask, 1 << insn->slot); \
+        tcg_gen_or_tl(mask, hex_slot_cancelled, mask); \
+        tcg_gen_movcond_tl(TCG_COND_NE, hex_slot_cancelled, LSB, zero, \
+                           hex_slot_cancelled, mask); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free(mask); \
+        tcg_temp_free(zero); \
+    } while (0)
+
+#define fWRAP_A2_paddt(GENHLPR, SHORTCODE) \
+    WRAP_padd(fLSBOLD(PuV), tcg_gen_add_tl(RdV, RsV, RtV))
+#define fWRAP_A2_paddf(GENHLPR, SHORTCODE) \
+    WRAP_padd(fLSBOLDNOT(PuV), tcg_gen_add_tl(RdV, RsV, RtV))
+#define fWRAP_A2_paddit(GENHLPR, SHORTCODE) \
+    WRAP_padd(fLSBOLD(PuV), tcg_gen_addi_tl(RdV, RsV, IMMNO(0)))
+#define fWRAP_A2_paddif(GENHLPR, SHORTCODE) \
+    WRAP_padd(fLSBOLDNOT(PuV), tcg_gen_addi_tl(RdV, RsV, IMMNO(0)))
+#define fWRAP_A2_padditnew(GENHLPR, SHORTCODE) \
+    WRAP_padd(fLSBNEW(PuN), tcg_gen_addi_tl(RdV, RsV, IMMNO(0)))
+
+/* Conditional move instructions */
+#define fWRAP_COND_MOVE(VAL, COND) \
+    do { \
+        TCGv LSB = tcg_temp_new(); \
+        TCGv zero = tcg_const_tl(0); \
+        TCGv mask = tcg_temp_new(); \
+        TCGv value = tcg_const_tl(siV); \
+        VAL; \
+        tcg_gen_movcond_tl(COND, RdV, LSB, zero, value, zero); \
+        tcg_gen_movi_tl(mask, 1 << insn->slot); \
+        tcg_gen_movcond_tl(TCG_COND_EQ, mask, LSB, zero, mask, zero); \
+        tcg_gen_or_tl(hex_slot_cancelled, hex_slot_cancelled, mask); \
+        tcg_temp_free(LSB); \
+        tcg_temp_free(zero); \
+        tcg_temp_free(mask); \
+        tcg_temp_free(value); \
+    } while (0)
+
+#define fWRAP_C2_cmoveit(GENHLPR, SHORTCODE) \
+    fWRAP_COND_MOVE(fLSBOLD(PuV), TCG_COND_NE)
+#define fWRAP_C2_cmovenewit(GENHLPR, SHORTCODE) \
+    fWRAP_COND_MOVE(fLSBNEW(PuN), TCG_COND_NE)
+#define fWRAP_C2_cmovenewif(GENHLPR, SHORTCODE) \
+    fWRAP_COND_MOVE(fLSBNEWNOT(PuN), TCG_COND_NE)
+
+/* p0 = tstbit(r0, #5) */
+#define fWRAP_S2_tstbit_i(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_andi_tl(tmp, RsV, (1 << IMMNO(0))); \
+        gen_8bitsof(PdV, tmp); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* p0 = !tstbit(r0, #5) */
+#define fWRAP_S4_ntstbit_i(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_andi_tl(tmp, RsV, (1 << IMMNO(0))); \
+        gen_8bitsof(PdV, tmp); \
+        tcg_gen_xori_tl(PdV, PdV, 0xff); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* r0 = setbit(r1, #5) */
+#define fWRAP_S2_setbit_i(GENHLPR, SHORTCODE) \
+    tcg_gen_ori_tl(RdV, RsV, 1 << IMMNO(0))
+
+/* r0 += add(r1, #8) */
+#define fWRAP_M2_accii(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        tcg_gen_add_tl(tmp, RxV, RsV); \
+        tcg_gen_addi_tl(RxV, tmp, IMMNO(0)); \
+        tcg_temp_free(tmp); \
+    } while (0)
+
+/* p0 = bitsclr(r1, #6) */
+#define fWRAP_C2_bitsclri(GENHLPR, SHORTCODE) \
+    do { \
+        TCGv tmp = tcg_temp_new(); \
+        TCGv zero = tcg_const_tl(0); \
+        tcg_gen_andi_tl(tmp, RsV, IMMNO(0)); \
+        gen_compare(TCG_COND_EQ, PdV, tmp, zero); \
+        tcg_temp_free(tmp); \
+        tcg_temp_free(zero); \
+    } while (0)
+
+#define fWRAP_SL2_jumpr31(GENHLPR, SHORTCODE) \
+    gen_write_new_pc(hex_gpr[HEX_REG_LR])
+
+#define fWRAP_SL2_jumpr31_tnew(GENHLPR, SHORTCODE) \
+    gen_cond_jumpr(hex_new_pred_value[0], hex_gpr[HEX_REG_LR])
+
 #endif
Signature · 1 line
2.7.4
#53 lore raw

RFC PATCH v2 51/67 Hexagon translation

In reply to Taylor Simpson

Read the instruction memory
Create a packet data structure
Generate TCG code for the start of the packet
Invoke the generate function for each instruction
Generate TCG code for the end of the packet

---
 target/hexagon/translate.h |  82 +++++
 target/hexagon/translate.c | 728 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 810 insertions(+)
 create mode 100644 target/hexagon/translate.h
 create mode 100644 target/hexagon/translate.c
target/hexagon/translate.h new file +82 -0
new file mode 100644
index 0000000..65b721e
@@ -0,0 +1,82 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_TRANSLATE_H
+#define HEXAGON_TRANSLATE_H
+
+#include "cpu.h"
+#include "exec/translator.h"
+#include "exec/helper-proto.h"
+#include "exec/helper-gen.h"
+#include "internal.h"
+
+typedef struct DisasContext {
+    DisasContextBase base;
+    uint32_t mem_idx;
+    int ctx_reg_log[REG_WRITES_MAX];
+    int ctx_reg_log_idx;
+    int ctx_preg_log[PRED_WRITES_MAX];
+    int ctx_preg_log_idx;
+    uint8_t ctx_store_width[STORES_MAX];
+} DisasContext;
+
+static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)
+{
+#if HEX_DEBUG
+    int i;
+    for (i = 0; i < ctx->ctx_reg_log_idx; i++) {
+        if (ctx->ctx_reg_log[i] == rnum) {
+            HEX_DEBUG_LOG("WARNING: Multiple writes to r%d\n", rnum);
+        }
+    }
+#endif
+    ctx->ctx_reg_log[ctx->ctx_reg_log_idx] = rnum;
+    ctx->ctx_reg_log_idx++;
+}
+
+static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
+{
+    ctx->ctx_preg_log[ctx->ctx_preg_log_idx] = pnum;
+    ctx->ctx_preg_log_idx++;
+}
+
+extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
+extern TCGv hex_pred[NUM_PREGS];
+extern TCGv hex_next_PC;
+extern TCGv hex_this_PC;
+extern TCGv hex_slot_cancelled;
+extern TCGv hex_branch_taken;
+extern TCGv hex_new_value[TOTAL_PER_THREAD_REGS];
+extern TCGv hex_reg_written[TOTAL_PER_THREAD_REGS];
+extern TCGv hex_new_pred_value[NUM_PREGS];
+extern TCGv hex_pred_written;
+extern TCGv hex_store_addr[STORES_MAX];
+extern TCGv hex_store_width[STORES_MAX];
+extern TCGv hex_store_val32[STORES_MAX];
+extern TCGv_i64 hex_store_val64[STORES_MAX];
+extern TCGv hex_dczero_addr;
+extern TCGv llsc_addr;
+extern TCGv llsc_val;
+extern TCGv_i64 llsc_val_i64;
+extern TCGv hex_is_gather_store_insn;
+extern TCGv hex_gather_issued;
+
+void hexagon_translate_init(void);
+extern void gen_exception(int excp);
+extern void gen_exception_debug(void);
+
+#endif
target/hexagon/translate.c new file +728 -0

728 lines not on this page · raw message

Signature · 1 line
2.7.4
#54 lore raw

RFC PATCH v2 52/67 Hexagon Linux user emulation

In reply to Taylor Simpson

Implementation of Linux user emulation for RISC-V
Some common files modified in addition to new files in linux-user/hexagon

---
 linux-user/hexagon/sockbits.h       |  18 ++
 linux-user/hexagon/syscall_nr.h     | 346 ++++++++++++++++++++++++++++++++++++
 linux-user/hexagon/target_cpu.h     |  44 +++++
 linux-user/hexagon/target_elf.h     |  38 ++++
 linux-user/hexagon/target_fcntl.h   |  18 ++
 linux-user/hexagon/target_signal.h  |  34 ++++
 linux-user/hexagon/target_structs.h |  46 +++++
 linux-user/hexagon/target_syscall.h |  32 ++++
 linux-user/hexagon/termbits.h       |  18 ++
 linux-user/syscall_defs.h           |  33 ++++
 linux-user/elfload.c                |  16 ++
 linux-user/hexagon/cpu_loop.c       | 173 ++++++++++++++++++
 linux-user/hexagon/signal.c         | 276 ++++++++++++++++++++++++++++
 linux-user/syscall.c                |   2 +
 14 files changed, 1094 insertions(+)
 create mode 100644 linux-user/hexagon/sockbits.h
 create mode 100644 linux-user/hexagon/syscall_nr.h
 create mode 100644 linux-user/hexagon/target_cpu.h
 create mode 100644 linux-user/hexagon/target_elf.h
 create mode 100644 linux-user/hexagon/target_fcntl.h
 create mode 100644 linux-user/hexagon/target_signal.h
 create mode 100644 linux-user/hexagon/target_structs.h
 create mode 100644 linux-user/hexagon/target_syscall.h
 create mode 100644 linux-user/hexagon/termbits.h
 create mode 100644 linux-user/hexagon/cpu_loop.c
 create mode 100644 linux-user/hexagon/signal.c
linux-user/hexagon/sockbits.h new file +18 -0
new file mode 100644
index 0000000..a6e8966
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "../generic/sockbits.h"
linux-user/hexagon/syscall_nr.h new file +346 -0

346 lines not on this page · raw message

linux-user/hexagon/target_cpu.h new file +44 -0

44 lines not on this page · raw message

linux-user/hexagon/target_elf.h new file +38 -0
new file mode 100644
index 0000000..6aea113
@@ -0,0 +1,38 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_TARGET_ELF_H
+#define HEXAGON_TARGET_ELF_H
+
+static inline const char *cpu_get_model(uint32_t eflags)
+{
+    /* For now, treat anything newer than v5 as a v67 */
+    /* FIXME - Disable instructions that are newer than the specified arch */
+    if (eflags == 0x04 ||    /* v5  */
+        eflags == 0x05 ||    /* v55 */
+        eflags == 0x60 ||    /* v60 */
+        eflags == 0x61 ||    /* v61 */
+        eflags == 0x62 ||    /* v62 */
+        eflags == 0x65 ||    /* v65 */
+        eflags == 0x66 ||    /* v66 */
+        eflags == 0x67) {    /* v67 */
+        return "v67";
+    }
+    return "unknown";
+}
+
+#endif
linux-user/hexagon/target_fcntl.h new file +18 -0
new file mode 100644
index 0000000..08162e6
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "../generic/fcntl.h"
linux-user/hexagon/target_signal.h new file +34 -0
new file mode 100644
index 0000000..12a6187
@@ -0,0 +1,34 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_TARGET_SIGNAL_H
+#define HEXAGON_TARGET_SIGNAL_H
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    abi_int ss_flags;
+    abi_ulong ss_size;
+} target_stack_t;
+
+#define TARGET_SS_ONSTACK 1
+#define TARGET_SS_DISABLE 2
+
+#define TARGET_MINSIGSTKSZ 2048
+
+#include "../generic/signal.h"
+
+#endif /* TARGET_SIGNAL_H */
linux-user/hexagon/target_structs.h new file +46 -0

46 lines not on this page · raw message

linux-user/hexagon/target_syscall.h new file +32 -0
new file mode 100644
index 0000000..a3bd307
@@ -0,0 +1,32 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_TARGET_SYSCALL_H
+#define HEXAGON_TARGET_SYSCALL_H
+
+struct target_pt_regs {
+    abi_long sepc;
+    abi_long sp;
+};
+
+#define UNAME_MACHINE "hexagon"
+#define UNAME_MINIMUM_RELEASE "4.15.0"
+
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
+
+#endif
linux-user/hexagon/termbits.h new file +18 -0
new file mode 100644
index 0000000..c5f92f1
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "../i386/termbits.h"
linux-user/syscall_defs.h +33 -0
index 152ec63..049379d 100644
@@ -102,6 +102,14 @@
 #define TARGET_IOC_WRITE  2U
 #define TARGET_IOC_READ   1U
 
+#elif defined(TARGET_HEXAGON)
+
+#define TARGET_IOC_SIZEBITS     14
+
+#define TARGET_IOC_NONE   0U
+#define TARGET_IOC_WRITE  1U
+#define TARGET_IOC_READ          2U
+
 #else
 #error unsupported CPU
 #endif
@@ -2133,6 +2141,31 @@ struct target_stat64 {
     uint64_t   st_ino;
 };
 
+#elif defined(TARGET_HEXAGON)
+
+struct target_stat {
+    unsigned long long st_dev;
+    unsigned long long st_ino;
+    unsigned int st_mode;
+    unsigned int st_nlink;
+    unsigned int st_uid;
+    unsigned int st_gid;
+    unsigned long long st_rdev;
+    target_ulong __pad1;
+    long long st_size;
+    target_long st_blksize;
+    int __pad2;
+    long long st_blocks;
+
+    target_long target_st_atime;
+    target_long target_st_atime_nsec;
+    target_long target_st_mtime;
+    target_long target_st_mtime_nsec;
+    target_long target_st_ctime;
+    target_long target_st_ctime_nsec;
+    int __unused[2];
+};
+
 #else
 #error unsupported CPU
 #endif
linux-user/elfload.c +16 -0
index b1a895f..cafbeb2 100644
@@ -1507,6 +1507,22 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #endif /* TARGET_XTENSA */
 
+#ifdef TARGET_HEXAGON
+
+#define ELF_START_MMAP 0x20000000
+
+#define ELF_CLASS       ELFCLASS32
+#define ELF_ARCH        EM_HEXAGON
+
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
+{
+    regs->sepc = infop->entry;
+    regs->sp = infop->start_stack;
+}
+
+#endif /* TARGET_HEXAGON */
+
 #ifndef ELF_PLATFORM
 #define ELF_PLATFORM (NULL)
 #endif
linux-user/hexagon/cpu_loop.c new file +173 -0

173 lines not on this page · raw message

linux-user/hexagon/signal.c new file +276 -0

276 lines not on this page · raw message

linux-user/syscall.c +2 -0
index 8d27d10..26cbedc 100644
@@ -516,6 +516,8 @@ static inline int regpairs_aligned(void *cpu_env, int num)
 }
 #elif defined(TARGET_XTENSA)
 static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+#elif defined(TARGET_HEXAGON)
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
 #else
 static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
 #endif
Signature · 1 line
2.7.4
#55 lore raw

RFC PATCH v2 53/67 Hexagon build infrastructure

In reply to Taylor Simpson

Add file to default-configs
Change configure
Add target/hexagon/Makefile.objs
Change scripts/qemu-binfmt-conf.sh
Modify tests/tcg/configure.sh
Add reference files to tests/tcg/hexagon

At this point in the patch series, you can build a hexagon-linux-user target and run programs on the Hexagon scalar core. With hexagon-linux-clang installed, "make check-tcg TIMEOUT=60" will pass.

---
 configure                              |   9 +
 default-configs/hexagon-linux-user.mak |   1 +
 scripts/qemu-binfmt-conf.sh            |   6 +-
 target/hexagon/Makefile.objs           | 121 ++++++
 tests/tcg/configure.sh                 |   4 +-
 tests/tcg/hexagon/float_convs.ref      | 748 ++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/float_madds.ref      | 768 +++++++++++++++++++++++++++++++++
 7 files changed, 1655 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/hexagon-linux-user.mak
 create mode 100644 target/hexagon/Makefile.objs
 create mode 100644 tests/tcg/hexagon/float_convs.ref
 create mode 100644 tests/tcg/hexagon/float_madds.ref
configure +9 -0
index 48d6f89..a10885f 100755
@@ -7862,6 +7862,12 @@ case "$target_name" in
     bflt="yes"
     mttcg="yes"
   ;;
+  hexagon)
+    TARGET_BASE_ARCH=hexagon
+    TARGET_ABI_DIR=hexagon
+    mttcg=yes
+    target_compiler=$cross_cc_hexagon
+  ;;
   *)
     error_exit "Unsupported target CPU"
   ;;
@@ -8025,6 +8031,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
   xtensa*)
     disas_config "XTENSA"
   ;;
+  hexagon)
+    disas_config "HEXAGON"
+  ;;
   esac
 done
 if test "$tcg_interpreter" = "yes" ; then
default-configs/hexagon-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..ad55af0
@@ -0,0 +1 @@
+# Default configuration for hexagon-linux-user
scripts/qemu-binfmt-conf.sh +5 -1
index 9f1580a..7b5d54b 100755
@@ -4,7 +4,7 @@
 qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \
 ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \
 sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \
-microblaze microblazeel or1k x86_64"
+microblaze microblazeel or1k x86_64 hexagon"
 
 i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
 i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
@@ -136,6 +136,10 @@ or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\
 or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
 or1k_family=or1k
 
+hexagon_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xa4\x00'
+hexagon_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+hexagon_family=hexagon
+
 qemu_get_family() {
     cpu=${HOST_ARCH:-$(uname -m)}
     case "$cpu" in
target/hexagon/Makefile.objs new file +121 -0

121 lines not on this page · raw message

tests/tcg/configure.sh +3 -1
index 9eb6ba3..31f156c 100755
@@ -60,6 +60,8 @@ fi
 : ${cross_cc_cflags_s390x="-m64"}
 : ${cross_cc_cflags_sparc="-m32 -mv8plus -mcpu=ultrasparc"}
 : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
+: ${cross_cc_hexagon="hexagon-linux-clang"}
+: ${cross_cc_cflags_hexagon="-mv67"}
 
 for target in $target_list; do
   arch=${target%%-*}
@@ -85,7 +87,7 @@ for target in $target_list; do
     xtensa|xtensaeb)
       arches=xtensa
       ;;
-    alpha|cris|hppa|i386|lm32|m68k|openrisc|riscv64|s390x|sh4|sparc64)
+    alpha|cris|hppa|i386|lm32|m68k|openrisc|riscv64|s390x|sh4|sparc64|hexagon)
       arches=$target
       ;;
     *)
tests/tcg/hexagon/float_convs.ref new file +748 -0

748 lines not on this page · raw message

tests/tcg/hexagon/float_madds.ref new file +768 -0

768 lines not on this page · raw message

Signature · 1 line
2.7.4
#56 lore raw

RFC PATCH v2 54/67 Hexagon - Add Hexagon Vector eXtensions (HVX) to core definition

In reply to Taylor Simpson

HVX is a set of wide vector instructions. Machine state includes
vector registers (VRegs)
vector predicate registers (QRegs)
temporary registers for packet semantics
store buffer (masked stores and scatter/gather)

---
 target/hexagon/cpu.h         | 42 +++++++++++++++++++++
 target/hexagon/insn.h        | 16 ++++++++
 target/hexagon/internal.h    |  2 +
 target/hexagon/mmvec/mmvec.h | 87 ++++++++++++++++++++++++++++++++++++++++++++
 target/hexagon/cpu.c         | 51 +++++++++++++++++++++++++-
 5 files changed, 197 insertions(+), 1 deletion(-)
 create mode 100644 target/hexagon/mmvec/mmvec.h
target/hexagon/cpu.h +42 -0
index 6146561..6215f91 100644
@@ -30,6 +30,7 @@ typedef struct CPUHexagonState CPUHexagonState;
 #include "qemu-common.h"
 #include "exec/cpu-defs.h"
 #include "hex_regs.h"
+#include "mmvec/mmvec.h"
 
 #define NUM_PREGS 4
 #ifdef CONFIG_USER_ONLY
@@ -42,6 +43,7 @@ typedef struct CPUHexagonState CPUHexagonState;
 #define STORES_MAX 2
 #define REG_WRITES_MAX 32
 #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
+#define VSTORES_MAX 2
 
 #define TYPE_HEXAGON_CPU "hexagon-cpu"
 
@@ -60,6 +62,19 @@ struct MemLog {
     uint64_t data64;
 };
 
+typedef struct {
+    target_ulong va;
+    int size;
+    mmvector_t mask;
+    mmvector_t data;
+} vstorelog_t;
+
+typedef struct {
+    unsigned char cdata[256];
+    uint32_t range;
+    uint8_t format;
+} mem_access_info_t;
+
 #define EXEC_STATUS_OK          0x0000
 #define EXEC_STATUS_STOP        0x0002
 #define EXEC_STATUS_REPLAY      0x0010
@@ -72,6 +87,9 @@ struct MemLog {
 #define CLEAR_EXCEPTION         (env->status &= (~EXEC_STATUS_EXCEPTION))
 #define SET_EXCEPTION           (env->status |= EXEC_STATUS_EXCEPTION)
 
+/* This needs to be large enough for all the reads and writes in a packet */
+#define TEMP_VECTORS_MAX        25
+
 struct CPUHexagonState {
     target_ulong gpr[TOTAL_PER_THREAD_REGS];
     target_ulong pred[NUM_PREGS];
@@ -110,6 +128,30 @@ struct CPUHexagonState {
 
     target_ulong is_gather_store_insn;
     target_ulong gather_issued;
+
+    mmvector_t VRegs[NUM_VREGS];
+    mmvector_t future_VRegs[NUM_VREGS];
+    mmvector_t tmp_VRegs[NUM_VREGS];
+
+    VRegMask VRegs_updated_tmp;
+    VRegMask VRegs_updated;
+    VRegMask VRegs_select;
+
+    mmqreg_t QRegs[NUM_QREGS];
+    mmqreg_t future_QRegs[NUM_QREGS];
+    QRegMask QRegs_updated;
+
+    vstorelog_t vstore[VSTORES_MAX];
+    uint8_t store_pending[VSTORES_MAX];
+    uint8_t vstore_pending[VSTORES_MAX];
+    uint8_t vtcm_pending;
+    vtcm_storelog_t vtcm_log;
+    mem_access_info_t mem_access[SLOTS_MAX];
+
+    int status;
+
+    mmvector_t temp_vregs[TEMP_VECTORS_MAX];
+    mmqreg_t temp_qregs[TEMP_VECTORS_MAX];
 };
 
 #define HEXAGON_CPU_CLASS(klass) \
target/hexagon/insn.h +16 -0
index a80bcb9..16d298d 100644
@@ -49,12 +49,16 @@ struct Instruction {
     size4u_t is_dcfetch:1;   /* Has an A_DCFETCH attribute */
     size4u_t is_load:1;      /* Has A_LOAD attribute */
     size4u_t is_store:1;     /* Has A_STORE attribute */
+    size4u_t is_vmem_ld:1;   /* Has an A_LOAD and an A_VMEM attribute */
+    size4u_t is_vmem_st:1;   /* Has an A_STORE and an A_VMEM attribute */
+    size4u_t is_scatgath:1;  /* Has an A_CVI_GATHER or A_CVI_SCATTER attr */
     size4u_t is_memop:1;     /* Has A_MEMOP attribute */
     size4u_t is_dealloc:1;   /* Is a dealloc return or dealloc frame */
     size4u_t is_aia:1;       /* Is a post increment */
     size4u_t is_endloop:1;   /* This is an end of loop */
     size4u_t is_2nd_jump:1;  /* This is the second jump of a dual-jump packet */
     size4u_t new_value_producer_slot:4;
+    size4u_t hvx_resource:8;
     size4s_t immed[IMMEDS_MAX];    /* immediate field */
 };
 
@@ -121,10 +125,22 @@ struct Packet {
 
     /* Misc */
     size8u_t num_rops:4;            /* Num risc ops in the packet */
+    size8u_t pkt_has_vtcm_access:1; /* Is a vmem access going to VTCM */
     size8u_t pkt_access_count:2;    /* Is a vmem access going to VTCM */
     size8u_t pkt_ldaccess_l2:2;     /* vmem ld access to l2 */
     size8u_t pkt_ldaccess_vtcm:2;   /* vmem ld access to vtcm */
 
+    /* Count the types of HVX instructions */
+    size8u_t pkt_hvx_va:4;
+    size8u_t pkt_hvx_vx:4;
+    size8u_t pkt_hvx_vp:4;
+    size8u_t pkt_hvx_vs:4;
+    size8u_t pkt_hvx_all:4;
+    size8u_t pkt_hvx_none:4;
+
+    size8u_t pkt_has_hvx:1;
+    size8u_t pkt_has_extension:1;
+
     insn_t insn[INSTRUCTIONS_MAX];
 };
 
target/hexagon/internal.h +2 -0
index 092dedc..4ff7020 100644
@@ -39,6 +39,8 @@
 extern int hexagon_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
 extern int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 
+extern void hexagon_debug_vreg(CPUHexagonState *env, int regnum);
+extern void hexagon_debug_qreg(CPUHexagonState *env, int regnum);
 extern void hexagon_debug(CPUHexagonState *env);
 
 #if COUNT_HEX_HELPERS
target/hexagon/mmvec/mmvec.h new file +87 -0

87 lines not on this page · raw message

target/hexagon/cpu.c +50 -1

69 lines not on this page · raw message

Signature · 1 line
2.7.4
#57 lore raw

RFC PATCH v2 55/67 Hexagon HVX support in gdbstub

In reply to Taylor Simpson
---
 target/hexagon/gdbstub.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
target/hexagon/gdbstub.c +62 -0
index e678aea..79a4f33 100644
@@ -21,6 +21,28 @@
 #include "cpu.h"
 #include "internal.h"
 
+static int gdb_get_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
+{
+    int total = 0;
+    int i;
+    for (i = 0; i < MAX_VEC_SIZE_BYTES / 4; i++) {
+        total += gdb_get_regl(mem_buf, env->VRegs[n].uw[i]);
+        mem_buf += 4;
+    }
+    return total;
+}
+
+static int gdb_get_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
+{
+    int total = 0;
+    int i;
+    for (i = 0; i < MAX_VEC_SIZE_BYTES / 4 / 8; i++) {
+        total += gdb_get_regl(mem_buf, env->QRegs[n].uw[i]);
+        mem_buf += 4;
+    }
+    return total;
+}
+
 int hexagon_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     HexagonCPU *cpu = HEXAGON_CPU(cs);
@@ -29,11 +51,41 @@ int hexagon_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
     if (n < TOTAL_PER_THREAD_REGS) {
         return gdb_get_regl(mem_buf, env->gpr[n]);
     }
+    n -= TOTAL_PER_THREAD_REGS;
+
+    if (n < NUM_VREGS) {
+        return gdb_get_vreg(env, mem_buf, n);
+    }
+    n -= NUM_VREGS;
+
+    if (n < NUM_QREGS) {
+        return gdb_get_qreg(env, mem_buf, n);
+    }
 
     g_assert_not_reached();
     return 0;
 }
 
+static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
+{
+    int i;
+    for (i = 0; i < MAX_VEC_SIZE_BYTES / 4; i++) {
+        env->VRegs[n].uw[i] = ldtul_p(mem_buf);
+        mem_buf += 4;
+    }
+    return MAX_VEC_SIZE_BYTES;
+}
+
+static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
+{
+    int i;
+    for (i = 0; i < MAX_VEC_SIZE_BYTES / 4 / 8; i++) {
+        env->QRegs[n].uw[i] = ldtul_p(mem_buf);
+        mem_buf += 4;
+    }
+    return MAX_VEC_SIZE_BYTES / 8;
+}
+
 int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     HexagonCPU *cpu = HEXAGON_CPU(cs);
@@ -43,6 +95,16 @@ int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
         env->gpr[n] = ldtul_p(mem_buf);
         return sizeof(target_ulong);
     }
+    n -= TOTAL_PER_THREAD_REGS;
+
+    if (n < NUM_VREGS) {
+        return gdb_put_vreg(env, mem_buf, n);
+    }
+    n -= NUM_VREGS;
+
+    if (n < NUM_QREGS) {
+        return gdb_put_qreg(env, mem_buf, n);
+    }
 
     g_assert_not_reached();
     return 0;
Signature · 1 line
2.7.4
#58 lore raw

RFC PATCH v2 56/67 Hexagon HVX import instruction encodings

In reply to Taylor Simpson
---
 target/hexagon/imported/allextenc.def        |  20 +
 target/hexagon/imported/encode.def           |   1 +
 target/hexagon/imported/mmvec/encode_ext.def | 830 +++++++++++++++++++++++++++
 3 files changed, 851 insertions(+)
 create mode 100644 target/hexagon/imported/allextenc.def
 create mode 100644 target/hexagon/imported/mmvec/encode_ext.def
target/hexagon/imported/allextenc.def new file +20 -0
new file mode 100644
index 0000000..9af9412
@@ -0,0 +1,20 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define EXTNAME mmvec
+#include "mmvec/encode_ext.def"
+#undef EXTNAME
target/hexagon/imported/encode.def +1 -0
index ae23301..7eb40be 100644
@@ -71,6 +71,7 @@
 
 #include "encode_pp.def"
 #include "encode_subinsn.def"
+#include "allextenc.def"
 
 #ifdef __SELF_DEF_FIELD32
 #undef __SELF_DEF_FIELD32
target/hexagon/imported/mmvec/encode_ext.def new file +830 -0

830 lines not on this page · raw message

Signature · 1 line
2.7.4
#59 lore raw

RFC PATCH v2 57/67 Hexagon HVX import semantics

In reply to Taylor Simpson

Imported from the Hexagon architecture library
imported/allext.idef Top level file for all extensions
imported/mmvec/ext.idef HVX instruction definitions

---
 target/hexagon/imported/allext.idef    |   25 +
 target/hexagon/imported/allidefs.def   |    1 +
 target/hexagon/imported/mmvec/ext.idef | 2780 ++++++++++++++++++++++++++++++++
 3 files changed, 2806 insertions(+)
 create mode 100644 target/hexagon/imported/allext.idef
 create mode 100644 target/hexagon/imported/mmvec/ext.idef
target/hexagon/imported/allext.idef new file +25 -0
new file mode 100644
index 0000000..26db774
@@ -0,0 +1,25 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Top level file for all instruction set extensions
+ */
+#define EXTNAME mmvec
+#define EXTSTR "mmvec"
+#include "mmvec/ext.idef"
+#undef EXTNAME
+#undef EXTSTR
target/hexagon/imported/allidefs.def +1 -0
index d2f13a2..03f3f1b 100644
@@ -89,3 +89,4 @@
 #include "shift.idef"
 #include "system.idef"
 #include "subinsns.idef"
+#include "allext.idef"
target/hexagon/imported/mmvec/ext.idef new file +2780 -0

2,780 lines not on this page · raw message

Signature · 1 line
2.7.4
#60 lore raw

RFC PATCH v2 58/67 Hexagon HVX import macro definitions

In reply to Taylor Simpson

Imported from the Hexagon architecture library
imported/allext_macros.def Top level macro include for all extensions
imported/mmvec/macros.def HVX macro definitions
The macro definition files specify instruction attributes that are applied to each instruction that reverences the macro.

---
 target/hexagon/imported/allext_macros.def |   25 +
 target/hexagon/imported/mmvec/macros.def  | 1110 +++++++++++++++++++++++++++++
 2 files changed, 1135 insertions(+)
 create mode 100644 target/hexagon/imported/allext_macros.def
 create mode 100755 target/hexagon/imported/mmvec/macros.def
target/hexagon/imported/allext_macros.def new file +25 -0
new file mode 100644
index 0000000..e1f16eb
@@ -0,0 +1,25 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Top level file for all instruction set extensions
+ */
+#define EXTNAME mmvec
+#define EXTSTR "mmvec"
+#include "mmvec/macros.def"
+#undef EXTNAME
+#undef EXTSTR
target/hexagon/imported/mmvec/macros.def new file +1110 -0

1,110 lines not on this page · raw message

Signature · 1 line
2.7.4
#61 lore raw

RFC PATCH v2 59/67 Hexagon HVX semantics generator

In reply to Taylor Simpson

Add HVX support to the semantics generator

---
 target/hexagon/gen_semantics.c |   9 +++
 target/hexagon/do_qemu.py      | 175 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 171 insertions(+), 13 deletions(-)
target/hexagon/gen_semantics.c +9 -0
index 65d04fa..f5ee3ae 100644
@@ -87,6 +87,15 @@ int main(int argc, char *argv[])
 #include "imported/macros.def"
 #undef DEF_MACRO
 
+/*
+ * Process the macros for HVX
+ */
+#define DEF_MACRO(MNAME, PARAMS, SDESC, LDESC, BEH, ATTRS) \
+    fprintf(outfile, "MACROATTRIB(\"%s\",\"\"\"%s\"\"\",\"%s\",\"%s\")\n", \
+            #MNAME, STRINGIZE(BEH), STRINGIZE(ATTRS), EXTSTR);
+#include "imported/allext_macros.def"
+#undef DEF_MACRO
+
     fclose(outfile);
     return 0;
 }
target/hexagon/do_qemu.py +162 -13

297 lines not on this page · raw message

Signature · 1 line
2.7.4
#62 lore raw

RFC PATCH v2 60/67 Hexagon HVX instruction decoding

In reply to Taylor Simpson
---
 target/hexagon/mmvec/decode_ext_mmvec.h |  24 ++
 target/hexagon/decode.c                 |  23 +-
 target/hexagon/mmvec/decode_ext_mmvec.c | 670 ++++++++++++++++++++++++++++++++
 target/hexagon/q6v_decode.c             |  14 +
 4 files changed, 729 insertions(+), 2 deletions(-)
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.h
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.c
target/hexagon/mmvec/decode_ext_mmvec.h new file +24 -0
new file mode 100644
index 0000000..67d3ead
@@ -0,0 +1,24 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_DECODE_EXT_MMVEC_H
+#define HEXAGON_DECODE_EXT_MMVEC_H
+
+extern int mmvec_ext_decode_checks(packet_t *pkt);
+extern const char *mmvec_ext_decode_find_iclass_slots(int opcode);
+
+#endif
target/hexagon/decode.c +21 -2
index 2201c23..fcf5e75 100644
@@ -24,6 +24,8 @@
 #include "insn.h"
 #include "macros.h"
 #include "printinsn.h"
+#include "mmvec/mmvec.h"
+#include "mmvec/decode_ext_mmvec.h"
 
 enum {
     EXT_IDX_noext = 0,
@@ -148,6 +150,9 @@ static void decode_ext_init(void)
     for (i = EXT_IDX_noext; i < EXT_IDX_noext_AFTER; i++) {
         ext_trees[i] = &dectree_table_DECODE_EXT_EXT_noext;
     }
+    for (i = EXT_IDX_mmvec; i < EXT_IDX_mmvec_AFTER; i++) {
+        ext_trees[i] = &dectree_table_DECODE_EXT_EXT_mmvec;
+    }
 }
 
 typedef struct {
@@ -445,6 +450,9 @@ static int decode_set_insn_attr_fields(packet_t *pkt)
 
         if (GET_ATTRIB(opcode, A_STORE)) {
             pkt->insn[i].is_store = 1;
+            if (GET_ATTRIB(opcode, A_VMEM)) {
+                pkt->insn[i].is_vmem_st = 1;
+            }
 
             if (pkt->insn[i].slot == 0) {
                 pkt->pkt_has_store_s0 = 1;
@@ -457,6 +465,9 @@ static int decode_set_insn_attr_fields(packet_t *pkt)
         }
         if (GET_ATTRIB(opcode, A_LOAD)) {
             pkt->insn[i].is_load = 1;
+            if (GET_ATTRIB(opcode, A_VMEM))  {
+                pkt->insn[i].is_vmem_ld = 1;
+            }
 
             if (pkt->insn[i].slot == 0) {
                 pkt->pkt_has_load_s0 = 1;
@@ -464,6 +475,10 @@ static int decode_set_insn_attr_fields(packet_t *pkt)
                 pkt->pkt_has_load_s1 = 1;
             }
         }
+        if (GET_ATTRIB(opcode, A_CVI_GATHER) ||
+            GET_ATTRIB(opcode, A_CVI_SCATTER)) {
+            pkt->insn[i].is_scatgath = 1;
+        }
         if (GET_ATTRIB(opcode, A_MEMOP)) {
             pkt->insn[i].is_memop = 1;
         }
@@ -737,8 +752,12 @@ static int decode_remove_extenders(packet_t *packet)
 static const char *
 get_valid_slot_str(const packet_t *pkt, unsigned int slot)
 {
-    return find_iclass_slots(pkt->insn[slot].opcode,
-                             pkt->insn[slot].iclass);
+    if (GET_ATTRIB(pkt->insn[slot].opcode, A_EXTENSION)) {
+        return mmvec_ext_decode_find_iclass_slots(pkt->insn[slot].opcode);
+    } else {
+        return find_iclass_slots(pkt->insn[slot].opcode,
+                                 pkt->insn[slot].iclass);
+    }
 }
 
 #include "q6v_decode.c"
target/hexagon/mmvec/decode_ext_mmvec.c new file +670 -0

670 lines not on this page · raw message

target/hexagon/q6v_decode.c +14 -0
index f2b1548..2d253db 100644
@@ -161,6 +161,13 @@ decode_insns_tablewalk(insn_t *insn, dectree_table_t *table, size4u_t encoding)
         }
         decode_op(insn, opc, encoding);
         return 1;
+    } else if (table->table[i].type == DECTREE_EXTSPACE) {
+        size4u_t active_ext;
+        /*
+         * For now, HVX will be the only coproc
+         */
+        active_ext = 4;
+        return decode_insns_tablewalk(insn, ext_trees[active_ext], encoding);
     } else {
         return 0;
     }
@@ -356,10 +363,13 @@ static int do_decode_packet(int max_words, const size4u_t *words, packet_t *pkt)
             pkt->pkt_has_payload = 1;
         }
     }
+    pkt->pkt_has_extension = 0;
     pkt->pkt_has_initloop = 0;
     pkt->pkt_has_initloop0 = 0;
     pkt->pkt_has_initloop1 = 0;
     for (i = 0; i < num_insns; i++) {
+        pkt->pkt_has_extension |=
+            GET_ATTRIB(pkt->insn[i].opcode, A_EXTENSION);
         pkt->pkt_has_initloop0 |=
             GET_ATTRIB(pkt->insn[i].opcode, A_HWLOOP0_SETUP);
         pkt->pkt_has_initloop1 |=
@@ -391,6 +401,10 @@ static int do_decode_packet(int max_words, const size4u_t *words, packet_t *pkt)
     errors += decode_set_slot_number(pkt);
     errors += decode_fill_newvalue_regno(pkt);
 
+    if (pkt->pkt_has_extension) {
+        errors += mmvec_ext_decode_checks(pkt);
+    }
+
     errors += decode_shuffle_for_execution(pkt);
     errors += decode_split_cmpjump(pkt);
     errors += decode_set_insn_attr_fields(pkt);
Signature · 1 line
2.7.4
#63 lore raw

RFC PATCH v2 61/67 Hexagon HVX instruction utility functions

In reply to Taylor Simpson

Functions to support scatter/gather

---
 target/hexagon/mmvec/system_ext_mmvec.h |  38 +++++
 target/hexagon/mmvec/system_ext_mmvec.c | 263 ++++++++++++++++++++++++++++++++
 2 files changed, 301 insertions(+)
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.h
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.c
target/hexagon/mmvec/system_ext_mmvec.h new file +38 -0
new file mode 100644
index 0000000..4f35966
@@ -0,0 +1,38 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_SYSTEM_EXT_MMVEC_H
+#define HEXAGON_SYSTEM_EXT_MMVEC_H
+
+extern void mem_load_vector_oddva(CPUHexagonState *env, vaddr_t vaddr,
+                           vaddr_t lookup_vaddr, int slot, int size,
+                           size1u_t *data, int use_full_va);
+extern void mem_store_vector_oddva(CPUHexagonState *env, vaddr_t vaddr,
+                            vaddr_t lookup_vaddr, int slot, int size,
+                            size1u_t *data, size1u_t* mask, unsigned invert,
+                            int use_full_va);
+extern void mem_vector_scatter_init(CPUHexagonState *env, int slot,
+                                    vaddr_t base_vaddr, int length,
+                                    int element_size);
+extern void mem_vector_scatter_finish(CPUHexagonState *env, int slot, int op);
+extern void mem_vector_gather_finish(CPUHexagonState *env, int slot);
+extern void mem_vector_gather_init(CPUHexagonState *env, int slot,
+                                   vaddr_t base_vaddr, int length,
+                                   int element_size);
+
+
+#endif
target/hexagon/mmvec/system_ext_mmvec.c new file +263 -0

263 lines not on this page · raw message

Signature · 1 line
2.7.4
#64 lore raw

RFC PATCH v2 62/67 Hexagon HVX macros to interface with the generator

In reply to Taylor Simpson

Various forms of declare, read, write, free for HVX operands

---
 target/hexagon/mmvec/macros.h | 262 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 262 insertions(+)
 create mode 100644 target/hexagon/mmvec/macros.h
target/hexagon/mmvec/macros.h new file +262 -0
new file mode 100644
index 0000000..be80bbd
@@ -0,0 +1,262 @@
+/*
+ *  Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HEXAGON_MMVEC_MACROS_H
+#define HEXAGON_MMVEC_MACROS_H
+
+#include "mmvec/system_ext_mmvec.h"
+
+#ifdef QEMU_GENERATE
+#else
+#define VdV      (*(mmvector_t *)(VdV_void))
+#define VsV      (*(mmvector_t *)(VsV_void))
+#define VuV      (*(mmvector_t *)(VuV_void))
+#define VvV      (*(mmvector_t *)(VvV_void))
+#define VwV      (*(mmvector_t *)(VwV_void))
+#define VxV      (*(mmvector_t *)(VxV_void))
+#define VyV      (*(mmvector_t *)(VyV_void))
+
+#define VddV     (*(mmvector_pair_t *)(VddV_void))
+#define VuuV     (*(mmvector_pair_t *)(VuuV_void))
+#define VvvV     (*(mmvector_pair_t *)(VvvV_void))
+#define VxxV     (*(mmvector_pair_t *)(VxxV_void))
+
+#define QeV      (*(mmqreg_t *)(QeV_void))
+#define QdV      (*(mmqreg_t *)(QdV_void))
+#define QsV      (*(mmqreg_t *)(QsV_void))
+#define QtV      (*(mmqreg_t *)(QtV_void))
+#define QuV      (*(mmqreg_t *)(QuV_void))
+#define QvV      (*(mmqreg_t *)(QvV_void))
+#define QxV      (*(mmqreg_t *)(QxV_void))
+#endif
+
+#ifdef QEMU_GENERATE
+#define DECL_VREG(VAR, NUM, X, OFF) \
+    TCGv_ptr VAR = tcg_temp_local_new_ptr(); \
+    size1u_t NUM = REGNO(X) + OFF; \
+    do { \
+        uint32_t offset = new_temp_vreg_offset(ctx, 1); \
+        tcg_gen_addi_ptr(VAR, cpu_env, offset); \
+    } while (0)
+
+/*
+ * Certain instructions appear to have readonly operands, but
+ * in reality they do not.
+ *     vdelta instructions overwrite their VuV operand
+ */
+static bool readonly_ok(insn_t *insn)
+{
+    uint32_t opcode = insn->opcode;
+    if (opcode == V6_vdelta ||
+        opcode == V6_vrdelta) {
+        return false;
+    }
+    return true;
+}
+
+#define DECL_VREG_READONLY(VAR, NUM, X, OFF) \
+    TCGv_ptr VAR = tcg_temp_local_new_ptr(); \
+    size1u_t NUM = REGNO(X) + OFF; \
+    if (!readonly_ok(insn)) { \
+        uint32_t offset = new_temp_vreg_offset(ctx, 1); \
+        tcg_gen_addi_ptr(VAR, cpu_env, offset); \
+    }
+
+#define DECL_VREG_d(VAR, NUM, X, OFF) \
+    DECL_VREG(VAR, NUM, X, OFF)
+#define DECL_VREG_s(VAR, NUM, X, OFF) \
+    DECL_VREG_READONLY(VAR, NUM, X, OFF)
+#define DECL_VREG_u(VAR, NUM, X, OFF) \
+    DECL_VREG_READONLY(VAR, NUM, X, OFF)
+#define DECL_VREG_v(VAR, NUM, X, OFF) \
+    DECL_VREG_READONLY(VAR, NUM, X, OFF)
+#define DECL_VREG_w(VAR, NUM, X, OFF) \
+    DECL_VREG_READONLY(VAR, NUM, X, OFF)
+#define DECL_VREG_x(VAR, NUM, X, OFF) \
+    DECL_VREG(VAR, NUM, X, OFF)
+#define DECL_VREG_y(VAR, NUM, X, OFF) \
+    DECL_VREG(VAR, NUM, X, OFF)
+
+#define DECL_VREG_PAIR(VAR, NUM, X, OFF) \
+    TCGv_ptr VAR = tcg_temp_local_new_ptr(); \
+    size1u_t NUM = REGNO(X) + OFF; \
+    do { \
+        uint32_t offset = new_temp_vreg_offset(ctx, 2); \
+        tcg_gen_addi_ptr(VAR, cpu_env, offset); \
+    } while (0)
+
+#define DECL_VREG_dd(VAR, NUM, X, OFF) \
+    DECL_VREG_PAIR(VAR, NUM, X, OFF)
+#define DECL_VREG_uu(VAR, NUM, X, OFF) \
+    DECL_VREG_PAIR(VAR, NUM, X, OFF)
+#define DECL_VREG_vv(VAR, NUM, X, OFF) \
+    DECL_VREG_PAIR(VAR, NUM, X, OFF)
+#define DECL_VREG_xx(VAR, NUM, X, OFF) \
+    DECL_VREG_PAIR(VAR, NUM, X, OFF)
+
+#define DECL_QREG(VAR, NUM, X, OFF) \
+    TCGv_ptr VAR = tcg_temp_local_new_ptr(); \
+    size1u_t NUM = REGNO(X) + OFF; \
+    do { \
+        uint32_t __offset = new_temp_qreg_offset(ctx); \
+        tcg_gen_addi_ptr(VAR, cpu_env, __offset); \
+    } while (0)
+
+#define DECL_QREG_d(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_e(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_s(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_t(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_u(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_v(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+#define DECL_QREG_x(VAR, NUM, X, OFF) \
+    DECL_QREG(VAR, NUM, X, OFF)
+
+#define FREE_VREG(VAR)          tcg_temp_free_ptr(VAR)
+#define FREE_VREG_d(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_s(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_u(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_v(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_w(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_x(VAR)        FREE_VREG(VAR)
+#define FREE_VREG_y(VAR)        FREE_VREG(VAR)
+
+#define FREE_VREG_PAIR(VAR)     tcg_temp_free_ptr(VAR)
+#define FREE_VREG_dd(VAR)       FREE_VREG_PAIR(VAR)
+#define FREE_VREG_uu(VAR)       FREE_VREG_PAIR(VAR)
+#define FREE_VREG_vv(VAR)       FREE_VREG_PAIR(VAR)
+#define FREE_VREG_xx(VAR)       FREE_VREG_PAIR(VAR)
+
+#define FREE_QREG(VAR)          tcg_temp_free_ptr(VAR)
+#define FREE_QREG_d(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_e(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_s(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_t(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_u(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_v(VAR)        FREE_QREG(VAR)
+#define FREE_QREG_x(VAR)        FREE_QREG(VAR)
+
+#define READ_VREG(VAR, NUM) \
+    gen_read_vreg(VAR, NUM, 0)
+#define READ_VREG_READONLY(VAR, NUM) \
+    do { \
+        if (readonly_ok(insn)) { \
+            gen_read_vreg_readonly(VAR, NUM, 0); \
+        } else { \
+            gen_read_vreg(VAR, NUM, 0); \
+        } \
+    } while (0)
+
+#define READ_VREG_s(VAR, NUM)    READ_VREG_READONLY(VAR, NUM)
+#define READ_VREG_u(VAR, NUM)    READ_VREG_READONLY(VAR, NUM)
+#define READ_VREG_v(VAR, NUM)    READ_VREG_READONLY(VAR, NUM)
+#define READ_VREG_w(VAR, NUM)    READ_VREG_READONLY(VAR, NUM)
+#define READ_VREG_x(VAR, NUM)    READ_VREG(VAR, NUM)
+#define READ_VREG_y(VAR, NUM)    READ_VREG(VAR, NUM)
+
+#define READ_VREG_PAIR(VAR, NUM) \
+    gen_read_vreg_pair(VAR, NUM, 0)
+#define READ_VREG_uu(VAR, NUM)   READ_VREG_PAIR(VAR, NUM)
+#define READ_VREG_vv(VAR, NUM)   READ_VREG_PAIR(VAR, NUM)
+#define READ_VREG_xx(VAR, NUM)   READ_VREG_PAIR(VAR, NUM)
+
+#define READ_QREG(VAR, NUM) \
+    gen_read_qreg(VAR, NUM, 0)
+#define READ_QREG_s(VAR, NUM)     READ_QREG(VAR, NUM)
+#define READ_QREG_t(VAR, NUM)     READ_QREG(VAR, NUM)
+#define READ_QREG_u(VAR, NUM)     READ_QREG(VAR, NUM)
+#define READ_QREG_v(VAR, NUM)     READ_QREG(VAR, NUM)
+#define READ_QREG_x(VAR, NUM)     READ_QREG(VAR, NUM)
+
+#define DECL_NEW_OREG(TYPE, NAME, NUM, X, OFF) \
+    TYPE NAME; \
+    int NUM = REGNO(X) + OFF
+
+#define READ_NEW_OREG(tmp, i) (tmp = tcg_const_tl(i))
+
+#define FREE_NEW_OREG(NAME) \
+    tcg_temp_free(NAME)
+
+#define LOG_VREG_WRITE(NUM, VAR, VNEW) \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        gen_log_vreg_write(VAR, NUM, VNEW, insn->slot); \
+        ctx_log_vreg_write(ctx, (NUM), is_predicated); \
+    } while (0)
+
+#define LOG_VREG_WRITE_PAIR(NUM, VAR, VNEW) \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        gen_log_vreg_write_pair(VAR, NUM, VNEW, insn->slot); \
+        ctx_log_vreg_write(ctx, (NUM) ^ 0, is_predicated); \
+        ctx_log_vreg_write(ctx, (NUM) ^ 1, is_predicated); \
+    } while (0)
+
+#define LOG_QREG_WRITE(NUM, VAR, VNEW) \
+    do { \
+        int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \
+        gen_log_qreg_write(VAR, NUM, VNEW, insn->slot); \
+        ctx_log_qreg_write(ctx, (NUM), is_predicated); \
+    } while (0)
+#else
+#define NEW_WRITTEN(NUM) ((env->VRegs_select >> (NUM)) & 1)
+#define TMP_WRITTEN(NUM) ((env->VRegs_updated_tmp >> (NUM)) & 1)
+
+#define LOG_VREG_WRITE_FUNC(X) \
+    _Generic((X), void * : log_vreg_write, mmvector_t : log_mmvector_write)
+#define LOG_VREG_WRITE(NUM, VAR, VNEW) \
+    LOG_VREG_WRITE_FUNC(VAR)(env, NUM, VAR, VNEW, slot)
+
+#define READ_EXT_VREG(NUM, VAR, VTMP) \
+    do { \
+        VAR = ((NEW_WRITTEN(NUM)) ? env->future_VRegs[NUM] \
+                                  : env->VRegs[NUM]); \
+        VAR = ((TMP_WRITTEN(NUM)) ? env->tmp_VRegs[NUM] : VAR); \
+        if (VTMP == EXT_TMP) { \
+            if (env->VRegs_updated & ((VRegMask)1) << (NUM)) { \
+                VAR = env->future_VRegs[NUM]; \
+                env->VRegs_updated ^= ((VRegMask)1) << (NUM); \
+            } \
+        } \
+    } while (0)
+
+#define READ_EXT_VREG_PAIR(NUM, VAR, VTMP) \
+    do { \
+        READ_EXT_VREG((NUM) ^ 0, VAR.v[0], VTMP); \
+        READ_EXT_VREG((NUM) ^ 1, VAR.v[1], VTMP) \
+    } while (0)
+#endif
+
+#define WRITE_EXT_VREG(NUM, VAR, VNEW)   LOG_VREG_WRITE(NUM, VAR, VNEW)
+#define WRITE_VREG_d(NUM, VAR, VNEW)     LOG_VREG_WRITE(NUM, VAR, VNEW)
+#define WRITE_VREG_x(NUM, VAR, VNEW)     LOG_VREG_WRITE(NUM, VAR, VNEW)
+#define WRITE_VREG_y(NUM, VAR, VNEW)     LOG_VREG_WRITE(NUM, VAR, VNEW)
+
+#define WRITE_VREG_dd(NUM, VAR, VNEW)    LOG_VREG_WRITE_PAIR(NUM, VAR, VNEW)
+#define WRITE_VREG_xx(NUM, VAR, VNEW)    LOG_VREG_WRITE_PAIR(NUM, VAR, VNEW)
+#define WRITE_VREG_yy(NUM, VAR, VNEW)    LOG_VREG_WRITE_PAIR(NUM, VAR, VNEW)
+
+#define WRITE_QREG_d(NUM, VAR, VNEW)     LOG_QREG_WRITE(NUM, VAR, VNEW)
+#define WRITE_QREG_e(NUM, VAR, VNEW)     LOG_QREG_WRITE(NUM, VAR, VNEW)
+#define WRITE_QREG_x(NUM, VAR, VNEW)     LOG_QREG_WRITE(NUM, VAR, VNEW)
+
+#endif
Signature · 1 line
2.7.4
#65 lore raw

RFC PATCH v2 63/67 Hexagon HVX macros referenced in instruction semantics

In reply to Taylor Simpson
---
 target/hexagon/mmvec/macros.h | 436 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 436 insertions(+)
target/hexagon/mmvec/macros.h +436 -0
index be80bbd..c63a00a 100644
@@ -259,4 +259,440 @@ static bool readonly_ok(insn_t *insn)
 #define WRITE_QREG_e(NUM, VAR, VNEW)     LOG_QREG_WRITE(NUM, VAR, VNEW)
 #define WRITE_QREG_x(NUM, VAR, VNEW)     LOG_QREG_WRITE(NUM, VAR, VNEW)
 
+#define LOG_VTCM_BYTE(VA, MASK, VAL, IDX) \
+    do { \
+        env->vtcm_log.data.ub[IDX] = (VAL); \
+        env->vtcm_log.mask.ub[IDX] = (MASK); \
+        env->vtcm_log.va[IDX] = (VA); \
+    } while (0)
+
+/* VTCM Banks */
+#define LOG_VTCM_BANK(VAL, MASK, IDX) \
+    do { \
+        env->vtcm_log.offsets.uh[IDX]  = (VAL & 0xFFF); \
+        env->vtcm_log.offsets.uh[IDX] |= ((MASK & 0xF) << 12) ; \
+    } while (0)
+
+#define fUSE_LOOKUP_ADDRESS_BY_REV(PROC) true
+#define fUSE_LOOKUP_ADDRESS() 1
+#define fRT8NOTE()
+#define fNOTQ(VAL) \
+    ({ \
+        mmqreg_t _ret;  \
+        int _i_;  \
+        for (_i_ = 0; _i_ < fVECSIZE() / 64; _i_++) { \
+            _ret.ud[_i_] = ~VAL.ud[_i_]; \
+        } \
+        _ret;\
+     })
+#define fGETQBITS(REG, WIDTH, MASK, BITNO) \
+    ((MASK) & (REG.w[(BITNO) >> 5] >> ((BITNO) & 0x1f)))
+#define fGETQBIT(REG, BITNO) fGETQBITS(REG, 1, 1, BITNO)
+#define fGENMASKW(QREG, IDX) \
+    (((fGETQBIT(QREG, (IDX * 4 + 0)) ? 0xFF : 0x0) << 0)  | \
+     ((fGETQBIT(QREG, (IDX * 4 + 1)) ? 0xFF : 0x0) << 8)  | \
+     ((fGETQBIT(QREG, (IDX * 4 + 2)) ? 0xFF : 0x0) << 16) | \
+     ((fGETQBIT(QREG, (IDX * 4 + 3)) ? 0xFF : 0x0) << 24))
+#define fGETNIBBLE(IDX, SRC) (fSXTN(4, 8, (SRC >> (4 * IDX)) & 0xF))
+#define fGETCRUMB(IDX, SRC) (fSXTN(2, 8, (SRC >> (2 * IDX)) & 0x3))
+#define fGETCRUMB_SYMMETRIC(IDX, SRC) \
+    ((fGETCRUMB(IDX, SRC) >= 0 ? (2 - fGETCRUMB(IDX, SRC)) \
+                               : fGETCRUMB(IDX, SRC)))
+#define fGENMASKH(QREG, IDX) \
+    (((fGETQBIT(QREG, (IDX * 2 + 0)) ? 0xFF : 0x0) << 0) | \
+     ((fGETQBIT(QREG, (IDX * 2 + 1)) ? 0xFF : 0x0) << 8))
+#define fGETMASKW(VREG, QREG, IDX) (VREG.w[IDX] & fGENMASKW((QREG), IDX))
+#define fGETMASKH(VREG, QREG, IDX) (VREG.h[IDX] & fGENMASKH((QREG), IDX))
+#define fCONDMASK8(QREG, IDX, YESVAL, NOVAL) \
+    (fGETQBIT(QREG, IDX) ? (YESVAL) : (NOVAL))
+#define fCONDMASK16(QREG, IDX, YESVAL, NOVAL) \
+    ((fGENMASKH(QREG, IDX) & (YESVAL)) | \
+     (fGENMASKH(fNOTQ(QREG), IDX) & (NOVAL)))
+#define fCONDMASK32(QREG, IDX, YESVAL, NOVAL) \
+    ((fGENMASKW(QREG, IDX) & (YESVAL)) | \
+     (fGENMASKW(fNOTQ(QREG), IDX) & (NOVAL)))
+#define fSETQBITS(REG, WIDTH, MASK, BITNO, VAL) \
+    do { \
+        size4u_t __TMP = (VAL); \
+        REG.w[(BITNO) >> 5] &= ~((MASK) << ((BITNO) & 0x1f)); \
+        REG.w[(BITNO) >> 5] |= (((__TMP) & (MASK)) << ((BITNO) & 0x1f)); \
+    } while (0)
+#define fSETQBIT(REG, BITNO, VAL) fSETQBITS(REG, 1, 1, BITNO, VAL)
+#define fVBYTES() (fVECSIZE())
+#define fVALIGN(ADDR, LOG2_ALIGNMENT) (ADDR = ADDR & ~(LOG2_ALIGNMENT - 1))
+#define fVLASTBYTE(ADDR, LOG2_ALIGNMENT) (ADDR = ADDR | (LOG2_ALIGNMENT - 1))
+#define fVELEM(WIDTH) ((fVECSIZE() * 8) / WIDTH)
+#define fVECLOGSIZE() (7)
+#define fVECSIZE() (1 << fVECLOGSIZE())
+#define fSWAPB(A, B) do { size1u_t tmp = A; A = B; B = tmp; } while (0)
+static inline mmvector_t mmvec_zero_vector(void)
+{
+    mmvector_t ret;
+    memset(&ret, 0, sizeof(ret));
+    return ret;
+}
+#define fVZERO() mmvec_zero_vector()
+#define fNEWVREG(VNUM) \
+    ((env->VRegs_updated & (((VRegMask)1) << VNUM)) ? env->future_VRegs[VNUM] \
+                                                    : mmvec_zero_vector())
+#define fV_AL_CHECK(EA, MASK) \
+    if ((EA) & (MASK)) { \
+        warn("aligning misaligned vector. EA=%08x", (EA)); \
+    }
+#define fSCATTER_INIT(REGION_START, LENGTH, ELEMENT_SIZE) \
+    do { \
+        mem_vector_scatter_init(env, slot, REGION_START, LENGTH, ELEMENT_SIZE);\
+        if (EXCEPTION_DETECTED) { \
+            return; \
+        } \
+    } while (0)
+#define fGATHER_INIT(REGION_START, LENGTH, ELEMENT_SIZE) \
+    do { \
+        mem_vector_gather_init(env, slot, REGION_START, LENGTH, ELEMENT_SIZE); \
+        if (EXCEPTION_DETECTED) { \
+            return; \
+        } \
+    } while (0)
+#define fSCATTER_FINISH(OP) \
+    do { \
+        if (EXCEPTION_DETECTED) { \
+            return; \
+        } \
+        mem_vector_scatter_finish(env, slot, OP); \
+    } while (0);
+#define fGATHER_FINISH() \
+    do { \
+        if (EXCEPTION_DETECTED) { \
+            return; \
+        } \
+        mem_vector_gather_finish(env, slot); \
+    } while (0);
+#define fLOG_SCATTER_OP(SIZE) \
+    do { \
+        env->vtcm_log.op = 1; \
+        env->vtcm_log.op_size = SIZE; \
+    } while (0)
+#define fVLOG_VTCM_WORD_INCREMENT(EA, OFFSET, INC, IDX, ALIGNMENT, LEN) \
+    do { \
+        int log_byte = 0; \
+        vaddr_t va = EA; \
+        vaddr_t va_high = EA + LEN; \
+        for (int i0 = 0; i0 < 4; i0++) { \
+            log_byte = (va + i0) <= va_high; \
+            LOG_VTCM_BYTE(va + i0, log_byte, INC. ub[4 * IDX + i0], \
+                          4 * IDX + i0); \
+        } \
+    } while (0)
+#define fVLOG_VTCM_HALFWORD_INCREMENT(EA, OFFSET, INC, IDX, ALIGNMENT, LEN) \
+    do { \
+        int log_byte = 0; \
+        vaddr_t va = EA; \
+        vaddr_t va_high = EA + LEN; \
+        for (int i0 = 0; i0 < 2; i0++) { \
+            log_byte = (va + i0) <= va_high; \
+            LOG_VTCM_BYTE(va + i0, log_byte, INC.ub[2 * IDX + i0], \
+                          2 * IDX + i0); \
+        } \
+    } while (0)
+
+#define fVLOG_VTCM_HALFWORD_INCREMENT_DV(EA, OFFSET, INC, IDX, IDX2, IDX_H, \
+                                         ALIGNMENT, LEN) \
+    do { \
+        int log_byte = 0; \
+        vaddr_t va = EA; \
+        vaddr_t va_high = EA + LEN; \
+        for (int i0 = 0; i0 < 2; i0++) { \
+            log_byte = (va + i0) <= va_high; \
+            LOG_VTCM_BYTE(va + i0, log_byte, INC.ub[2 * IDX + i0], \
+                          2 * IDX + i0); \
+        } \
+    } while (0)
+
+/* NOTE - Will this always be tmp_VRegs[0]; */
+#define GATHER_FUNCTION(EA, OFFSET, IDX, LEN, ELEMENT_SIZE, BANK_IDX, QVAL) \
+    do { \
+        int i0; \
+        vaddr_t va = EA; \
+        vaddr_t va_high = EA + LEN; \
+        int log_bank = 0; \
+        int log_byte = 0; \
+        for (i0 = 0; i0 < ELEMENT_SIZE; i0++) { \
+            log_byte = ((va + i0) <= va_high) && QVAL; \
+            log_bank |= (log_byte << i0); \
+            size1u_t B; \
+            get_user_u8(B, EA + i0); \
+            env->tmp_VRegs[0].ub[ELEMENT_SIZE * IDX + i0] = B; \
+            LOG_VTCM_BYTE(va + i0, log_byte, B, ELEMENT_SIZE * IDX + i0); \
+        } \
+        LOG_VTCM_BANK(va, log_bank, BANK_IDX); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_WORD(EA, OFFSET, IDX, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 4, IDX, 1); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_HALFWORD(EA, OFFSET, IDX, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 2, IDX, 1); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_HALFWORD_DV(EA, OFFSET, IDX, IDX2, IDX_H, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 2, (2 * IDX2 + IDX_H), 1); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_WORDQ(EA, OFFSET, IDX, Q, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 4, IDX, \
+                        fGETQBIT(QsV, 4 * IDX + i0)); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_HALFWORDQ(EA, OFFSET, IDX, Q, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 2, IDX, \
+                        fGETQBIT(QsV, 2 * IDX + i0)); \
+    } while (0)
+#define fVLOG_VTCM_GATHER_HALFWORDQ_DV(EA, OFFSET, IDX, IDX2, IDX_H, Q, LEN) \
+    do { \
+        GATHER_FUNCTION(EA, OFFSET, IDX, LEN, 2, (2 * IDX2 + IDX_H), \
+                        fGETQBIT(QsV, 2 * IDX + i0)); \
+    } while (0)
+#define SCATTER_OP_WRITE_TO_MEM(TYPE) \
+    do { \
+        for (int i = 0; i < env->vtcm_log.size; i += sizeof(TYPE)) { \
+            if (env->vtcm_log.mask.ub[i] != 0) { \
+                TYPE dst = 0; \
+                TYPE inc = 0; \
+                for (int j = 0; j < sizeof(TYPE); j++) { \
+                    size1u_t val; \
+                    get_user_u8(val, env->vtcm_log.va[i + j]); \
+                    dst |= val << (8 * j); \
+                    inc |= env->vtcm_log.data.ub[j + i] << (8 * j); \
+                    env->vtcm_log.mask.ub[j + i] = 0; \
+                    env->vtcm_log.data.ub[j + i] = 0; \
+                    env->vtcm_log.offsets.ub[j + i] = 0; \
+                } \
+                dst += inc; \
+                for (int j = 0; j < sizeof(TYPE); j++) { \
+                    put_user_u8((dst >> (8 * j)) & 0xFF, \
+                        env->vtcm_log.va[i + j]);  \
+                } \
+            } \
+        } \
+    } while (0)
+#define SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, ELEM_SIZE, BANK_IDX, QVAL, IN) \
+    do { \
+        int i0; \
+        target_ulong va = EA; \
+        target_ulong va_high = EA + LEN; \
+        int log_bank = 0; \
+        int log_byte = 0; \
+        for (i0 = 0; i0 < ELEM_SIZE; i0++) { \
+            log_byte = ((va + i0) <= va_high) && QVAL; \
+            log_bank |= (log_byte << i0); \
+            LOG_VTCM_BYTE(va + i0, log_byte, IN.ub[ELEM_SIZE * IDX + i0], \
+                          ELEM_SIZE * IDX + i0); \
+        } \
+        LOG_VTCM_BANK(va, log_bank, BANK_IDX); \
+    } while (0)
+#define fVLOG_VTCM_HALFWORD(EA, OFFSET, IN, IDX, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 2, IDX, 1, IN); \
+    } while (0)
+#define fVLOG_VTCM_WORD(EA, OFFSET, IN, IDX, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 4, IDX, 1, IN); \
+    } while (0)
+#define fVLOG_VTCM_HALFWORDQ(EA, OFFSET, IN, IDX, Q, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 2, IDX, \
+                         fGETQBIT(QsV, 2 * IDX + i0), IN); \
+    } while (0)
+#define fVLOG_VTCM_WORDQ(EA, OFFSET, IN, IDX, Q, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 4, IDX, \
+                         fGETQBIT(QsV, 4 * IDX + i0), IN); \
+    } while (0)
+#define fVLOG_VTCM_HALFWORD_DV(EA, OFFSET, IN, IDX, IDX2, IDX_H, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 2, \
+                         (2 * IDX2 + IDX_H), 1, IN); \
+    } while (0)
+#define fVLOG_VTCM_HALFWORDQ_DV(EA, OFFSET, IN, IDX, Q, IDX2, IDX_H, LEN) \
+    do { \
+        SCATTER_FUNCTION(EA, OFFSET, IDX, LEN, 2, (2 * IDX2 + IDX_H), \
+                         fGETQBIT(QsV, 2 * IDX + i0), IN); \
+    } while (0)
+#define fSTORERELEASE(EA, TYPE) \
+    do { \
+        fV_AL_CHECK(EA, fVECSIZE() - 1); \
+    } while (0)
+#define fLOADMMV_AL(EA, ALIGNMENT, LEN, DST) \
+    do { \
+        fV_AL_CHECK(EA, ALIGNMENT - 1); \
+        mem_load_vector_oddva(env, EA & ~(ALIGNMENT - 1), EA, slot, LEN, \
+                              &DST.ub[0], fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fLOADMMV(EA, DST) fLOADMMV_AL(EA, fVECSIZE(), fVECSIZE(), DST)
+#define fLOADMMVU_AL(EA, ALIGNMENT, LEN, DST) \
+    do { \
+        size4u_t size2 = (EA) & (ALIGNMENT - 1); \
+        size4u_t size1 = LEN - size2; \
+        mem_load_vector_oddva(env, EA + size1, EA + fVECSIZE(), 1, size2, \
+                              &DST.ub[size1], fUSE_LOOKUP_ADDRESS()); \
+        mem_load_vector_oddva(env, EA, EA, 0, size1, &DST.ub[0], \
+                              fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fLOADMMVU(EA, DST) \
+    do { \
+        if ((EA & (fVECSIZE() - 1)) == 0) { \
+            fLOADMMV_AL(EA, fVECSIZE(), fVECSIZE(), DST); \
+        } else { \
+            fLOADMMVU_AL(EA, fVECSIZE(), fVECSIZE(), DST); \
+        } \
+    } while (0)
+#define fSTOREMMV_AL(EA, ALIGNMENT, LEN, SRC) \
+    do  { \
+        fV_AL_CHECK(EA, ALIGNMENT - 1); \
+        mem_store_vector_oddva(env, EA & ~(ALIGNMENT - 1), EA, slot, LEN, \
+                               &SRC.ub[0], 0, 0, \
+                               fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fSTOREMMV(EA, SRC) fSTOREMMV_AL(EA, fVECSIZE(), fVECSIZE(), SRC)
+#define fSTOREMMVQ_AL(EA, ALIGNMENT, LEN, SRC, MASK) \
+    do { \
+        mmvector_t maskvec; \
+        int i; \
+        for (i = 0; i < fVECSIZE(); i++) { \
+            maskvec.ub[i] = fGETQBIT(MASK, i); \
+        } \
+        mem_store_vector_oddva(env, EA & ~(ALIGNMENT - 1), EA, slot, LEN, \
+                               &SRC.ub[0], &maskvec.ub[0], 0, \
+                               fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fSTOREMMVQ(EA, SRC, MASK) \
+    fSTOREMMVQ_AL(EA, fVECSIZE(), fVECSIZE(), SRC, MASK)
+#define fSTOREMMVNQ_AL(EA, ALIGNMENT, LEN, SRC, MASK) \
+    do { \
+        mmvector_t maskvec; \
+        int i; \
+        for (i = 0; i < fVECSIZE(); i++) { \
+            maskvec.ub[i] = fGETQBIT(MASK, i); \
+        } \
+        fV_AL_CHECK(EA, ALIGNMENT - 1); \
+        mem_store_vector_oddva(env, EA & ~(ALIGNMENT - 1), EA, slot, LEN, \
+                               &SRC.ub[0], &maskvec.ub[0], 1, \
+                               fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fSTOREMMVNQ(EA, SRC, MASK) \
+    fSTOREMMVNQ_AL(EA, fVECSIZE(), fVECSIZE(), SRC, MASK)
+#define fSTOREMMVU_AL(EA, ALIGNMENT, LEN, SRC) \
+    do { \
+        size4u_t size1 = ALIGNMENT - ((EA) & (ALIGNMENT - 1)); \
+        size4u_t size2; \
+        if (size1 > LEN) { \
+            size1 = LEN; \
+        } \
+        size2 = LEN - size1; \
+        mem_store_vector_oddva(env, EA + size1, EA + fVECSIZE(), 1, size2, \
+                               &SRC.ub[size1], 0, 0, \
+                               fUSE_LOOKUP_ADDRESS()); \
+        mem_store_vector_oddva(env, EA, EA, 0, size1, &SRC.ub[0], 0, 0, \
+                               fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fSTOREMMVU(EA, SRC) \
+    do { \
+        if ((EA & (fVECSIZE() - 1)) == 0) { \
+            fSTOREMMV_AL(EA, fVECSIZE(), fVECSIZE(), SRC); \
+        } else { \
+            fSTOREMMVU_AL(EA, fVECSIZE(), fVECSIZE(), SRC); \
+        } \
+    } while (0)
+#define fSTOREMMVQU_AL(EA, ALIGNMENT, LEN, SRC, MASK) \
+    do { \
+        size4u_t size1 = ALIGNMENT - ((EA) & (ALIGNMENT - 1)); \
+        size4u_t size2; \
+        mmvector_t maskvec; \
+        int i; \
+        for (i = 0; i < fVECSIZE(); i++) { \
+            maskvec.ub[i] = fGETQBIT(MASK, i); \
+        } \
+        if (size1 > LEN) { \
+            size1 = LEN; \
+        } \
+        size2 = LEN - size1; \
+        mem_store_vector_oddva(env, EA + size1, EA + fVECSIZE(), 1, size2, \
+                               &SRC.ub[size1], &maskvec.ub[size1], 0, \
+                               fUSE_LOOKUP_ADDRESS()); \
+        mem_store_vector_oddva(env, EA, 0, size1, &SRC.ub[0], &maskvec.ub[0], \
+                               0, fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fSTOREMMVNQU_AL(EA, ALIGNMENT, LEN, SRC, MASK) \
+    do { \
+        size4u_t size1 = ALIGNMENT - ((EA) & (ALIGNMENT - 1)); \
+        size4u_t size2; \
+        mmvector_t maskvec; \
+        int i; \
+        for (i = 0; i < fVECSIZE(); i++) { \
+            maskvec.ub[i] = fGETQBIT(MASK, i); \
+        } \
+        if (size1 > LEN) { \
+            size1 = LEN; \
+        } \
+        size2 = LEN - size1; \
+        mem_store_vector_oddva(env, EA + size1, EA + fVECSIZE(), 1, size2, \
+                               &SRC.ub[size1], &maskvec.ub[size1], 1, \
+                               fUSE_LOOKUP_ADDRESS()); \
+        mem_store_vector_oddva(env, EA, EA, 0, size1, &SRC.ub[0], \
+                               &maskvec.ub[0], 1, \
+                               fUSE_LOOKUP_ADDRESS_BY_REV()); \
+    } while (0)
+#define fVFOREACH(WIDTH, VAR) for (VAR = 0; VAR < fVELEM(WIDTH); VAR++)
+#define fVARRAY_ELEMENT_ACCESS(ARRAY, TYPE, INDEX) \
+    ARRAY.v[(INDEX) / (fVECSIZE() / (sizeof(ARRAY.TYPE[0])))].TYPE[(INDEX) % \
+    (fVECSIZE() / (sizeof(ARRAY.TYPE[0])))]
+/* Grabs the .tmp data, wherever it is, and clears the .tmp status */
+/* Used for vhist */
+static inline mmvector_t mmvec_vtmp_data(void)
+{
+    mmvector_t ret;
+    g_assert_not_reached();
+    return ret;
+}
+#define fTMPVDATA() mmvec_vtmp_data()
+#define fVSATDW(U, V) fVSATW(((((long long)U) << 32) | fZXTN(32, 64, V)))
+#define fVASL_SATHI(U, V) fVSATW(((U) << 1) | ((V) >> 31))
+#define fVUADDSAT(WIDTH, U, V) \
+    fVSATUN(WIDTH, fZXTN(WIDTH, 2 * WIDTH, U) + fZXTN(WIDTH, 2 * WIDTH, V))
+#define fVSADDSAT(WIDTH, U, V) \
+    fVSATN(WIDTH, fSXTN(WIDTH, 2 * WIDTH, U) + fSXTN(WIDTH, 2 * WIDTH, V))
+#define fVUSUBSAT(WIDTH, U, V) \
+    fVSATUN(WIDTH, fZXTN(WIDTH, 2 * WIDTH, U) - fZXTN(WIDTH, 2 * WIDTH, V))
+#define fVSSUBSAT(WIDTH, U, V) \
+    fVSATN(WIDTH, fSXTN(WIDTH, 2 * WIDTH, U) - fSXTN(WIDTH, 2 * WIDTH, V))
+#define fVAVGU(WIDTH, U, V) \
+    ((fZXTN(WIDTH, 2 * WIDTH, U) + fZXTN(WIDTH, 2 * WIDTH, V)) >> 1)
+#define fVAVGURND(WIDTH, U, V) \
+    ((fZXTN(WIDTH, 2 * WIDTH, U) + fZXTN(WIDTH, 2 * WIDTH, V) + 1) >> 1)
+#define fVNAVGU(WIDTH, U, V) \
+    ((fZXTN(WIDTH, 2 * WIDTH, U) - fZXTN(WIDTH, 2 * WIDTH, V)) >> 1)
+#define fVNAVGURNDSAT(WIDTH, U, V) \
+    fVSATUN(WIDTH, ((fZXTN(WIDTH, 2 * WIDTH, U) - \
+                     fZXTN(WIDTH, 2 * WIDTH, V) + 1) >> 1))
+#define fVAVGS(WIDTH, U, V) \
+    ((fSXTN(WIDTH, 2 * WIDTH, U) + fSXTN(WIDTH, 2 * WIDTH, V)) >> 1)
+#define fVAVGSRND(WIDTH, U, V) \
+    ((fSXTN(WIDTH, 2 * WIDTH, U) + fSXTN(WIDTH, 2 * WIDTH, V) + 1) >> 1)
+#define fVNAVGS(WIDTH, U, V) \
+    ((fSXTN(WIDTH, 2 * WIDTH, U) - fSXTN(WIDTH, 2 * WIDTH, V)) >> 1)
+#define fVNAVGSRND(WIDTH, U, V) \
+    ((fSXTN(WIDTH, 2 * WIDTH, U) - fSXTN(WIDTH, 2 * WIDTH, V) + 1) >> 1)
+#define fVNAVGSRNDSAT(WIDTH, U, V) \
+    fVSATN(WIDTH, ((fSXTN(WIDTH, 2 * WIDTH, U) - \
+                    fSXTN(WIDTH, 2 * WIDTH, V) + 1) >> 1))
+#define fVNOROUND(VAL, SHAMT) VAL
+#define fVNOSAT(VAL) VAL
+#define fVROUND(VAL, SHAMT) \
+    ((VAL) + (((SHAMT) > 0) ? (1LL << ((SHAMT) - 1)) : 0))
+#define fCARRY_FROM_ADD32(A, B, C) \
+    (((fZXTN(32, 64, A) + fZXTN(32, 64, B) + C) >> 32) & 1)
+#define fUARCH_NOTE_PUMP_4X()
+#define fUARCH_NOTE_PUMP_2X()
+
 #endif
Signature · 1 line
2.7.4
#66 lore raw

RFC PATCH v2 64/67 Hexagon HVX helper to commit vector stores (masked and scatter/gather)

In reply to Taylor Simpson
---
 target/hexagon/helper.h    |  1 +
 target/hexagon/op_helper.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
target/hexagon/helper.h +1 -0
index 8558da8..64e798b 100644
@@ -21,6 +21,7 @@ DEF_HELPER_2(raise_exception, noreturn, env, i32)
 DEF_HELPER_1(debug_start_packet, void, env)
 DEF_HELPER_2(new_value, s32, env, int)
 DEF_HELPER_3(debug_check_store_width, void, env, int, int)
+DEF_HELPER_1(commit_hvx_stores, void, env)
 DEF_HELPER_3(debug_commit_end, void, env, int, int)
 DEF_HELPER_3(sfrecipa_val, s32, env, s32, s32)
 DEF_HELPER_3(sfrecipa_pred, s32, env, s32, s32)
target/hexagon/op_helper.c +75 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
#67 lore raw

RFC PATCH v2 65/67 Hexagon HVX TCG generation

In reply to Taylor Simpson
---
 target/hexagon/genptr_helpers.h | 202 ++++++++++++++++++++++++++++++++++++++++
 target/hexagon/genptr.c         |   1 +
 2 files changed, 203 insertions(+)
target/hexagon/genptr_helpers.h +202 -0
index e342f29..84479f8 100644
@@ -844,4 +844,206 @@ static inline void gen_lshiftr_4_4u(TCGv dst, TCGv src, int32_t shift_amt)
     }
 }
 
+static inline uint32_t new_temp_vreg_offset(DisasContext *ctx, int num)
+{
+    uint32_t offset =
+        offsetof(CPUHexagonState, temp_vregs[ctx->ctx_temp_vregs_idx]);
+
+    HEX_DEBUG_LOG("new_temp_vreg_offset: %d\n", ctx->ctx_temp_vregs_idx);
+    g_assert(ctx->ctx_temp_vregs_idx + num - 1 < TEMP_VECTORS_MAX);
+    ctx->ctx_temp_vregs_idx += num;
+    return offset;
+}
+
+static inline uint32_t new_temp_qreg_offset(DisasContext *ctx)
+{
+    uint32_t offset =
+        offsetof(CPUHexagonState, temp_qregs[ctx->ctx_temp_qregs_idx]);
+
+    HEX_DEBUG_LOG("new_temp_qreg_offset: %d\n", ctx->ctx_temp_qregs_idx);
+    g_assert(ctx->ctx_temp_qregs_idx < TEMP_VECTORS_MAX);
+    ctx->ctx_temp_qregs_idx++;
+    return offset;
+}
+
+static inline void gen_read_qreg(TCGv_ptr var, int num, int vtmp)
+{
+    uint32_t offset = offsetof(CPUHexagonState, QRegs[(num)]);
+    TCGv_ptr src = tcg_temp_new_ptr();
+    tcg_gen_addi_ptr(src, cpu_env, offset);
+    gen_memcpy(var, src, sizeof(mmqreg_t));
+    tcg_temp_free_ptr(src);
+}
+
+static inline void gen_read_vreg_ptr_src(TCGv_ptr ptr_src, int num, int vtmp)
+{
+    TCGv zero = tcg_const_tl(0);
+    TCGv offset_future =
+        tcg_const_tl(offsetof(CPUHexagonState, future_VRegs[num]));
+    TCGv offset_vregs =
+        tcg_const_tl(offsetof(CPUHexagonState, VRegs[num]));
+    TCGv offset_tmp_vregs =
+        tcg_const_tl(offsetof(CPUHexagonState, tmp_VRegs[num]));
+    TCGv offset = tcg_temp_new();
+    TCGv_ptr offset_ptr = tcg_temp_new_ptr();
+    TCGv new_written = tcg_temp_new();
+    TCGv tmp_written = tcg_temp_new();
+
+    /*
+     *  new_written = (hex_VRegs_select >> num) & 1;
+     *  offset = new_written ? offset_future, offset_vregs;
+     */
+    tcg_gen_shri_tl(new_written, hex_VRegs_select, num);
+    tcg_gen_andi_tl(new_written, new_written, 1);
+    tcg_gen_movcond_tl(TCG_COND_NE, offset, new_written, zero,
+                       offset_future, offset_vregs);
+
+    /*
+     * tmp_written = (hex_VRegs_updated_tmp >> num) & 1;
+     * if (tmp_written) offset = offset_tmp_vregs;
+     */
+    tcg_gen_shri_tl(tmp_written, hex_VRegs_updated_tmp, num);
+    tcg_gen_andi_tl(tmp_written, tmp_written, 1);
+    tcg_gen_movcond_tl(TCG_COND_NE, offset, tmp_written, zero,
+                       offset_tmp_vregs, offset);
+
+    if (vtmp == EXT_TMP) {
+        TCGv vregs_updated = tcg_temp_new();
+        TCGv temp = tcg_temp_new();
+
+        /*
+         * vregs_updated = hex_VRegs_updates & (1 << num);
+         * if (vregs_updated) {
+         *     offset = offset_future;
+         *     hex_VRegs_updated ^= (1 << num);
+         * }
+         */
+        tcg_gen_andi_tl(vregs_updated, hex_VRegs_updated, 1 << num);
+        tcg_gen_movcond_tl(TCG_COND_NE, offset, vregs_updated, zero,
+                           offset_future, offset);
+        tcg_gen_xori_tl(temp, hex_VRegs_updated, 1 << num);
+        tcg_gen_movcond_tl(TCG_COND_NE, hex_VRegs_updated, vregs_updated, zero,
+                           temp, hex_VRegs_updated);
+
+        tcg_temp_free(vregs_updated);
+        tcg_temp_free(temp);
+    }
+
+    tcg_gen_ext_i32_ptr(offset_ptr, offset);
+    tcg_gen_add_ptr(ptr_src, cpu_env, offset_ptr);
+
+    tcg_temp_free(zero);
+    tcg_temp_free(offset_future);
+    tcg_temp_free(offset_vregs);
+    tcg_temp_free(offset_tmp_vregs);
+    tcg_temp_free(offset);
+    tcg_temp_free_ptr(offset_ptr);
+    tcg_temp_free(new_written);
+    tcg_temp_free(tmp_written);
+}
+
+static inline void gen_read_vreg_readonly(TCGv_ptr var, int num, int vtmp)
+{
+    TCGv_ptr ptr_src = tcg_temp_new_ptr();
+    gen_read_vreg_ptr_src(ptr_src, num, vtmp);
+    tcg_gen_addi_ptr(var, ptr_src, 0);
+    tcg_temp_free_ptr(ptr_src);
+}
+
+static inline void gen_read_vreg(TCGv_ptr var, int num, int vtmp)
+{
+    TCGv_ptr ptr_src = tcg_temp_new_ptr();
+    gen_read_vreg_ptr_src(ptr_src, num, vtmp);
+    gen_memcpy(var, ptr_src, sizeof(mmvector_t));
+    tcg_temp_free_ptr(ptr_src);
+}
+
+static inline void gen_read_vreg_pair(TCGv_ptr var, int num, int vtmp)
+{
+    TCGv_ptr v0 = tcg_temp_new_ptr();
+    TCGv_ptr v1 = tcg_temp_new_ptr();
+    tcg_gen_addi_ptr(v0, var, offsetof(mmvector_pair_t, v[0]));
+    gen_read_vreg(v0, num ^ 0, vtmp);
+    tcg_gen_addi_ptr(v1, var, offsetof(mmvector_pair_t, v[1]));
+    gen_read_vreg(v1, num ^ 1, vtmp);
+    tcg_temp_free_ptr(v0);
+    tcg_temp_free_ptr(v1);
+}
+
+static inline void gen_log_vreg_write(TCGv_ptr var, int num, int vnew,
+                                      int slot_num)
+{
+    TCGv cancelled = tcg_temp_local_new();
+    TCGLabel *label_end = gen_new_label();
+
+    /* Don't do anything if the slot was cancelled */
+    gen_slot_cancelled_check(cancelled, slot_num);
+    tcg_gen_brcondi_tl(TCG_COND_NE, cancelled, 0, label_end);
+    {
+        TCGv mask = tcg_const_tl(1 << num);
+        TCGv_ptr dst = tcg_temp_new_ptr();
+        if (vnew != EXT_TMP) {
+            tcg_gen_or_tl(hex_VRegs_updated, hex_VRegs_updated, mask);
+        }
+        if (vnew == EXT_NEW) {
+            tcg_gen_or_tl(hex_VRegs_select, hex_VRegs_select, mask);
+        }
+        if (vnew == EXT_TMP) {
+            tcg_gen_or_tl(hex_VRegs_updated_tmp, hex_VRegs_updated_tmp, mask);
+        }
+        tcg_gen_addi_ptr(dst, cpu_env,
+                         offsetof(CPUHexagonState, future_VRegs[num]));
+        gen_memcpy(dst, var, sizeof(mmvector_t));
+        if (vnew == EXT_TMP) {
+            TCGv_ptr src = tcg_temp_new_ptr();
+            tcg_gen_addi_ptr(dst, cpu_env,
+                             offsetof(CPUHexagonState, tmp_VRegs[num]));
+            tcg_gen_addi_ptr(src, cpu_env,
+                             offsetof(CPUHexagonState, future_VRegs[num]));
+            gen_memcpy(dst, src, sizeof(mmvector_t));
+            tcg_temp_free_ptr(src);
+        }
+        tcg_temp_free(mask);
+        tcg_temp_free_ptr(dst);
+    }
+    gen_set_label(label_end);
+
+    tcg_temp_free(cancelled);
+}
+
+static inline void gen_log_vreg_write_pair(TCGv_ptr var, int num, int vnew,
+                                           int slot_num)
+{
+    TCGv_ptr v0 = tcg_temp_local_new_ptr();
+    TCGv_ptr v1 = tcg_temp_local_new_ptr();
+    tcg_gen_addi_ptr(v0, var, offsetof(mmvector_pair_t, v[0]));
+    gen_log_vreg_write(v0, num ^ 0, vnew, slot_num);
+    tcg_gen_addi_ptr(v1, var, offsetof(mmvector_pair_t, v[1]));
+    gen_log_vreg_write(v1, num ^ 1, vnew, slot_num);
+    tcg_temp_free_ptr(v0);
+    tcg_temp_free_ptr(v1);
+}
+
+static inline void gen_log_qreg_write(TCGv_ptr var, int num, int vnew,
+                                          int slot_num)
+{
+    TCGv cancelled = tcg_temp_local_new();
+    TCGLabel *label_end = gen_new_label();
+
+    /* Don't do anything if the slot was cancelled */
+    gen_slot_cancelled_check(cancelled, slot_num);
+    tcg_gen_brcondi_tl(TCG_COND_NE, cancelled, 0, label_end);
+    {
+        TCGv_ptr dst = tcg_temp_new_ptr();
+        tcg_gen_addi_ptr(dst, cpu_env,
+                         offsetof(CPUHexagonState, future_QRegs[num]));
+        gen_memcpy(dst, var, sizeof(mmqreg_t));
+        tcg_gen_ori_tl(hex_QRegs_updated, hex_QRegs_updated, 1 << num);
+        tcg_temp_free_ptr(dst);
+    }
+    gen_set_label(label_end);
+
+    tcg_temp_free(cancelled);
+}
+
 #endif
target/hexagon/genptr.c +1 -0
index 6b9cc0d..588360d 100644
@@ -25,6 +25,7 @@
 #include "opcodes.h"
 #include "translate.h"
 #include "macros.h"
+#include "mmvec/macros.h"
 #include "genptr_helpers.h"
 #include "helper_overrides.h"
 
Signature · 1 line
2.7.4
#68 lore raw

RFC PATCH v2 66/67 Hexagon HVX translation

In reply to Taylor Simpson

Changes to packet semantics to support HVX

---
 target/hexagon/translate.h |  30 ++++++++
 target/hexagon/translate.c | 188 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 218 insertions(+)
target/hexagon/translate.h +30 -0
index 65b721e..481dbbd 100644
@@ -32,6 +32,14 @@ typedef struct DisasContext {
     int ctx_preg_log[PRED_WRITES_MAX];
     int ctx_preg_log_idx;
     uint8_t ctx_store_width[STORES_MAX];
+    int ctx_temp_vregs_idx;
+    int ctx_temp_qregs_idx;
+    int ctx_vreg_log[NUM_VREGS];
+    int ctx_vreg_is_predicated[NUM_VREGS];
+    int ctx_vreg_log_idx;
+    int ctx_qreg_log[NUM_QREGS];
+    int ctx_qreg_is_predicated[NUM_QREGS];
+    int ctx_qreg_log_idx;
 } DisasContext;
 
 static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)
@@ -54,6 +62,22 @@ static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
     ctx->ctx_preg_log_idx++;
 }
 
+static inline void ctx_log_vreg_write(DisasContext *ctx,
+                                      int rnum, int is_predicated)
+{
+    ctx->ctx_vreg_log[ctx->ctx_vreg_log_idx] = rnum;
+    ctx->ctx_vreg_is_predicated[ctx->ctx_vreg_log_idx] = is_predicated;
+    ctx->ctx_vreg_log_idx++;
+}
+
+static inline void ctx_log_qreg_write(DisasContext *ctx,
+                                      int rnum, int is_predicated)
+{
+    ctx->ctx_qreg_log[ctx->ctx_qreg_log_idx] = rnum;
+    ctx->ctx_qreg_is_predicated[ctx->ctx_qreg_log_idx] = is_predicated;
+    ctx->ctx_qreg_log_idx++;
+}
+
 extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
 extern TCGv hex_pred[NUM_PREGS];
 extern TCGv hex_next_PC;
@@ -74,9 +98,15 @@ extern TCGv llsc_val;
 extern TCGv_i64 llsc_val_i64;
 extern TCGv hex_is_gather_store_insn;
 extern TCGv hex_gather_issued;
+extern TCGv hex_VRegs_updated_tmp;
+extern TCGv hex_VRegs_updated;
+extern TCGv hex_VRegs_select;
+extern TCGv hex_QRegs_updated;
 
 void hexagon_translate_init(void);
 extern void gen_exception(int excp);
 extern void gen_exception_debug(void);
 
+extern void gen_memcpy(TCGv_ptr dest, TCGv_ptr src, size_t n);
+
 #endif
target/hexagon/translate.c +188 -0

240 lines not on this page · raw message

Signature · 1 line
2.7.4
#69 lore raw

RFC PATCH v2 67/67 Hexagon HVX build infrastructure

In reply to Taylor Simpson
---
 target/hexagon/Makefile.objs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
target/hexagon/Makefile.objs +9 -3
index be0d08f..d18b41f 100644
@@ -28,7 +28,9 @@ obj-y += \
     printinsn.o \
     arch.o \
     fma_emu.o \
-    conv_emu.o
+    conv_emu.o \
+    mmvec/decode_ext_mmvec.o \
+    mmvec/system_ext_mmvec.o
 
 #
 #  Step 1
@@ -47,10 +49,14 @@ IDEF_FILES = \
     $(SRC_PATH)/target/hexagon/imported/mpy.idef \
     $(SRC_PATH)/target/hexagon/imported/shift.idef \
     $(SRC_PATH)/target/hexagon/imported/subinsns.idef \
-    $(SRC_PATH)/target/hexagon/imported/system.idef
+    $(SRC_PATH)/target/hexagon/imported/system.idef \
+    $(SRC_PATH)/target/hexagon/imported/allext.idef \
+    $(SRC_PATH)/target/hexagon/imported/mmvec/ext.idef
 DEF_FILES = \
     $(SRC_PATH)/target/hexagon/imported/allidefs.def \
-    $(SRC_PATH)/target/hexagon/imported/macros.def
+    $(SRC_PATH)/target/hexagon/imported/macros.def \
+    $(SRC_PATH)/target/hexagon/imported/allext_macros.def \
+    $(SRC_PATH)/target/hexagon/imported/mmvec/macros.def
 
 $(GEN_SEMANTICS): $(GEN_SEMANTICS_SRC) $(IDEF_FILES) $(DEF_FILES)
 	$(CC) $(CFLAGS) $(GEN_SEMANTICS_SRC) -o $(GEN_SEMANTICS)
Signature · 1 line
2.7.4
#70 lore raw
In reply to Taylor Simpson

I know everyone is heads-down working on the 5.0 release, and I realize this is a lot of code. However, I would really appreciate some feedback on it. Is there anything I can do to make it easier to review?

Thanks,
Taylor

Quoted 336 lines

-----Original Message-----
From: Taylor Simpson <[email protected]>
Sent: Friday, February 28, 2020 10:43 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Taylor Simpson <[email protected]>
Subject: [RFC PATCH v2 00/67] Hexagon patch series

This series adds support for the Hexagon processor with Linux user support

See patch 02/67 Hexagon README for detailed information.

The patches up to and including "Hexagon build infractructure" implement the
base Hexagon core and the remainder add HVX. Once the build infrastructure
patch is applied, you can build and qemu will execute non-HVX Hexagon programs.

We have a parallel effort to make the Hexagon Linux toolchain publically available.

*** Testing ***

The port passes the following tests
Directed unit tests will contributed when the Hexagon toolchain is available MUSL libc test suite (good coverage of Linux system calls)
https://git.musl-libc.org/cgit/libc-testsuite/
Internal compiler intrinsics test suite (good coverage of instructions) Hexagon machine learning library unit tests
TODO - pull these from the CAF repo
make check-tcg TIMEOUT=60

*** Known checkpatch issues ***

The following are known checkpatch errors in the series
include/disas/dis-asm.h space prohibited
(Follow convention of other targets on prior lines)
target/hexagon/reg_fields.h Complex macro
target/hexagon/attribs.h Complex macro
target/hexagon/decode.c Complex macro
target/hexagon/q6v_decode.c Macro needs do - while
target/hexagon/printinsn.c Macro needs do - while
target/hexagon/gen_semantics.c Suspicious ; after while (0)
target/hexagon/gen_dectree_import.c Complex macro target/hexagon/gen_dectree_import.c Suspicious ; after while (0)
target/hexagon/opcodes.c Complex macro
target/hexagon/iclass.h Complex macro
scripts/qemu-binfmt-conf.sh Line over 90 characters
target/hexagon/mmvec/macros.h Suspicious ; after while (0)

The following are known checkpatch warnings in the series
target/hexagon/fma_emu.c Comments inside macro definition
scripts/qemu-binfmt-conf.sh Line over 80 characters

*** Changes in v2 ***
- Use scripts/git.orderfile
- Create a README with the code overview in patch 0001
- Change #define's in hex_regs.h to an enum
- Replace hard coded disassembly buffer length (1028) with #define
- Move Hexagon architecture types patch earlier in series
- Replace #include standard header files with #include "qemu/osdep.h"
- Prefix all header file #ifndef's with HEXAGON_
- Update python version to python3
- #include "tcg/tcg.h" in genptr_helpers.h
- Change target/hexagon/Makefile.objs to support out-of-tree build
- Updated copyright to include year 2020
- Bug fixes
Fix some problems with HEX_DEBUG output
Fix bug in circular addressing
- Optimizations to reduce the amount of TCG code generated Change pred_written from an array to a bit mask Optimize readonly vector registers
Conditionally call gen_helper_commit_hvx_stores

Taylor Simpson (67):
Hexagon Maintainers
Hexagon README
Hexagon ELF Machine Definition
Hexagon CPU Scalar Core Definition
Hexagon register names
Hexagon Disassembler
Hexagon CPU Scalar Core Helpers
Hexagon GDB Stub
Hexagon architecture types
Hexagon instruction and packet types
Hexagon register fields
Hexagon instruction attributes
Hexagon register map
Hexagon instruction/packet decode
Hexagon instruction printing
Hexagon arch import - instruction semantics definitions Hexagon arch import - macro definitions
Hexagon arch import - instruction encoding
Hexagon instruction class definitions
Hexagon instruction utility functions
Hexagon generator phase 1 - C preprocessor for semantics Hexagon generator phase 2 - qemu_def_generated.h
Hexagon generator phase 2 - qemu_wrap_generated.h
Hexagon generator phase 2 - opcodes_def_generated.h Hexagon generator phase 2 - op_attribs_generated.h
Hexagon generator phase 2 - op_regs_generated.h
Hexagon generator phase 2 - printinsn-generated.h
Hexagon generator phase 3 - C preprocessor for decode tree Hexagon generater phase 4 - Decode tree
Hexagon opcode data structures
Hexagon macros to interface with the generator
Hexagon macros referenced in instruction semantics
Hexagon instruction classes
Hexagon TCG generation helpers - step 1
Hexagon TCG generation helpers - step 2
Hexagon TCG generation helpers - step 3
Hexagon TCG generation helpers - step 4
Hexagon TCG generation helpers - step 5
Hexagon TCG generation - step 01
Hexagon TCG generation - step 02
Hexagon TCG generation - step 03
Hexagon TCG generation - step 04
Hexagon TCG generation - step 05
Hexagon TCG generation - step 06
Hexagon TCG generation - step 07
Hexagon TCG generation - step 08
Hexagon TCG generation - step 09
Hexagon TCG generation - step 10
Hexagon TCG generation - step 11
Hexagon TCG generation - step 12
Hexagon translation
Hexagon Linux user emulation
Hexagon build infrastructure
Hexagon - Add Hexagon Vector eXtensions (HVX) to core definition Hexagon HVX support in gdbstub
Hexagon HVX import instruction encodings
Hexagon HVX import semantics
Hexagon HVX import macro definitions
Hexagon HVX semantics generator
Hexagon HVX instruction decoding
Hexagon HVX instruction utility functions
Hexagon HVX macros to interface with the generator
Hexagon HVX macros referenced in instruction semantics Hexagon HVX helper to commit vector stores (masked and scatter/gather) Hexagon HVX TCG generation
Hexagon HVX translation
Hexagon HVX build infrastructure

 configure                                    |    9 +
 default-configs/hexagon-linux-user.mak       |    1 +
 include/disas/dis-asm.h                      |    1 +
 include/elf.h                                |    2 +
 linux-user/hexagon/sockbits.h                |   18 +
 linux-user/hexagon/syscall_nr.h              |  346 +++
 linux-user/hexagon/target_cpu.h              |   44 +
 linux-user/hexagon/target_elf.h              |   38 +
 linux-user/hexagon/target_fcntl.h            |   18 +
 linux-user/hexagon/target_signal.h           |   34 +
 linux-user/hexagon/target_structs.h          |   46 +
 linux-user/hexagon/target_syscall.h          |   32 +
 linux-user/hexagon/termbits.h                |   18 +
 linux-user/syscall_defs.h                    |   33 +
 target/hexagon/arch.h                        |   62 +
 target/hexagon/attribs.h                     |   32 +
 target/hexagon/attribs_def.h                 |  404 +++
 target/hexagon/conv_emu.h                    |   50 +
 target/hexagon/cpu-param.h                   |   26 +
 target/hexagon/cpu.h                         |  207 ++
 target/hexagon/cpu_bits.h                    |   37 +
 target/hexagon/decode.h                      |   39 +
 target/hexagon/fma_emu.h                     |   30 +
 target/hexagon/genptr.h                      |   25 +
 target/hexagon/genptr_helpers.h              | 1049 +++++++
 target/hexagon/helper.h                      |   38 +
 target/hexagon/helper_overrides.h            | 1850 ++++++++++++
 target/hexagon/hex_arch_types.h              |   42 +
 target/hexagon/hex_regs.h                    |   99 +
 target/hexagon/iclass.h                      |   46 +
 target/hexagon/insn.h                        |  149 +
 target/hexagon/internal.h                    |   54 +
 target/hexagon/macros.h                      | 1474 ++++++++++
 target/hexagon/mmvec/decode_ext_mmvec.h      |   24 +
 target/hexagon/mmvec/macros.h                |  698 +++++
 target/hexagon/mmvec/mmvec.h                 |   87 +
 target/hexagon/mmvec/system_ext_mmvec.h      |   38 +
 target/hexagon/opcodes.h                     |   67 +
 target/hexagon/printinsn.h                   |   26 +
 target/hexagon/reg_fields.h                  |   40 +
 target/hexagon/reg_fields_def.h              |  109 +
 target/hexagon/regmap.h                      |   38 +
 target/hexagon/translate.h                   |  112 +
 disas/hexagon.c                              |   62 +
 linux-user/elfload.c                         |   16 +
 linux-user/hexagon/cpu_loop.c                |  173 ++
 linux-user/hexagon/signal.c                  |  276 ++
 linux-user/syscall.c                         |    2 +
 target/hexagon/arch.c                        |  663 +++++
 target/hexagon/conv_emu.c                    |  369 +++
 target/hexagon/cpu.c                         |  374 +++
 target/hexagon/decode.c                      |  788 +++++
 target/hexagon/fma_emu.c                     |  916 ++++++
 target/hexagon/gdbstub.c                     |  111 +
 target/hexagon/gen_dectree_import.c          |  205 ++
 target/hexagon/gen_semantics.c               |  101 +
 target/hexagon/genptr.c                      |   61 +
 target/hexagon/iclass.c                      |  107 +
 target/hexagon/mmvec/decode_ext_mmvec.c      |  670 +++++
 target/hexagon/mmvec/system_ext_mmvec.c      |  263 ++
 target/hexagon/op_helper.c                   |  509 ++++
 target/hexagon/opcodes.c                     |  217 ++
 target/hexagon/printinsn.c                   |   91 +
 target/hexagon/q6v_decode.c                  |  416 +++
 target/hexagon/reg_fields.c                  |   28 +
 target/hexagon/translate.c                   |  916 ++++++
 MAINTAINERS                                  |    8 +
 disas/Makefile.objs                          |    1 +
 scripts/qemu-binfmt-conf.sh                  |    6 +-
 target/hexagon/Makefile.objs                 |  127 +
 target/hexagon/README                        |  296 ++
 target/hexagon/dectree.py                    |  353 +++
 target/hexagon/do_qemu.py                    | 1194 ++++++++
 target/hexagon/imported/allext.idef          |   25 +
 target/hexagon/imported/allext_macros.def    |   25 +
 target/hexagon/imported/allextenc.def        |   20 +
 target/hexagon/imported/allidefs.def         |   92 +
 target/hexagon/imported/alu.idef             | 1335 +++++++++
 target/hexagon/imported/branch.idef          |  344 +++
 target/hexagon/imported/compare.idef         |  639 +++++
 target/hexagon/imported/encode.def           |  126 +
 target/hexagon/imported/encode_pp.def        | 2283 +++++++++++++++
 target/hexagon/imported/encode_subinsn.def   |  150 +
 target/hexagon/imported/float.idef           |  498 ++++
 target/hexagon/imported/iclass.def           |   52 +
 target/hexagon/imported/ldst.idef            |  421 +++
 target/hexagon/imported/macros.def           | 3970
++++++++++++++++++++++++++
 target/hexagon/imported/mmvec/encode_ext.def |  830 ++++++
 target/hexagon/imported/mmvec/ext.idef       | 2780
++++++++++++++++++
 target/hexagon/imported/mmvec/macros.def     | 1110 +++++++
 target/hexagon/imported/mpy.idef             | 1269 ++++++++
 target/hexagon/imported/shift.idef           | 1211 ++++++++
 target/hexagon/imported/subinsns.idef        |  152 +
 target/hexagon/imported/system.idef          |  302 ++
 tests/tcg/configure.sh                       |    4 +-
 tests/tcg/hexagon/float_convs.ref            |  748 +++++
 tests/tcg/hexagon/float_madds.ref            |  768 +++++
 97 files changed, 36063 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/hexagon-linux-user.mak
 create mode 100644 linux-user/hexagon/sockbits.h
 create mode 100644 linux-user/hexagon/syscall_nr.h
 create mode 100644 linux-user/hexagon/target_cpu.h
 create mode 100644 linux-user/hexagon/target_elf.h
 create mode 100644 linux-user/hexagon/target_fcntl.h
 create mode 100644 linux-user/hexagon/target_signal.h
 create mode 100644 linux-user/hexagon/target_structs.h
 create mode 100644 linux-user/hexagon/target_syscall.h
 create mode 100644 linux-user/hexagon/termbits.h
 create mode 100644 target/hexagon/arch.h
 create mode 100644 target/hexagon/attribs.h
 create mode 100644 target/hexagon/attribs_def.h
 create mode 100644 target/hexagon/conv_emu.h
 create mode 100644 target/hexagon/cpu-param.h
 create mode 100644 target/hexagon/cpu.h
 create mode 100644 target/hexagon/cpu_bits.h
 create mode 100644 target/hexagon/decode.h
 create mode 100644 target/hexagon/fma_emu.h
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/genptr_helpers.h
 create mode 100644 target/hexagon/helper.h
 create mode 100644 target/hexagon/helper_overrides.h
 create mode 100644 target/hexagon/hex_arch_types.h
 create mode 100644 target/hexagon/hex_regs.h
 create mode 100644 target/hexagon/iclass.h
 create mode 100644 target/hexagon/insn.h
 create mode 100644 target/hexagon/internal.h
 create mode 100644 target/hexagon/macros.h
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.h
 create mode 100644 target/hexagon/mmvec/macros.h
 create mode 100644 target/hexagon/mmvec/mmvec.h
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.h
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/reg_fields.h
 create mode 100644 target/hexagon/reg_fields_def.h
 create mode 100644 target/hexagon/regmap.h
 create mode 100644 target/hexagon/translate.h
 create mode 100644 disas/hexagon.c
 create mode 100644 linux-user/hexagon/cpu_loop.c
 create mode 100644 linux-user/hexagon/signal.c
 create mode 100644 target/hexagon/arch.c
 create mode 100644 target/hexagon/conv_emu.c
 create mode 100644 target/hexagon/cpu.c
 create mode 100644 target/hexagon/decode.c
 create mode 100644 target/hexagon/fma_emu.c
 create mode 100644 target/hexagon/gdbstub.c
 create mode 100644 target/hexagon/gen_dectree_import.c
 create mode 100644 target/hexagon/gen_semantics.c
 create mode 100644 target/hexagon/genptr.c
 create mode 100644 target/hexagon/iclass.c
 create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.c
 create mode 100644 target/hexagon/mmvec/system_ext_mmvec.c
 create mode 100644 target/hexagon/op_helper.c
 create mode 100644 target/hexagon/opcodes.c
 create mode 100644 target/hexagon/printinsn.c
 create mode 100644 target/hexagon/q6v_decode.c
 create mode 100644 target/hexagon/reg_fields.c
 create mode 100644 target/hexagon/translate.c
 create mode 100644 target/hexagon/Makefile.objs
 create mode 100644 target/hexagon/README
 create mode 100755 target/hexagon/dectree.py
 create mode 100755 target/hexagon/do_qemu.py
 create mode 100644 target/hexagon/imported/allext.idef
 create mode 100644 target/hexagon/imported/allext_macros.def
 create mode 100644 target/hexagon/imported/allextenc.def
 create mode 100644 target/hexagon/imported/allidefs.def
 create mode 100644 target/hexagon/imported/alu.idef
 create mode 100644 target/hexagon/imported/branch.idef
 create mode 100644 target/hexagon/imported/compare.idef
 create mode 100644 target/hexagon/imported/encode.def
 create mode 100644 target/hexagon/imported/encode_pp.def
 create mode 100644 target/hexagon/imported/encode_subinsn.def
 create mode 100644 target/hexagon/imported/float.idef
 create mode 100644 target/hexagon/imported/iclass.def
 create mode 100644 target/hexagon/imported/ldst.idef
 create mode 100755 target/hexagon/imported/macros.def
 create mode 100644 target/hexagon/imported/mmvec/encode_ext.def
 create mode 100644 target/hexagon/imported/mmvec/ext.idef
 create mode 100755 target/hexagon/imported/mmvec/macros.def
 create mode 100644 target/hexagon/imported/mpy.idef
 create mode 100644 target/hexagon/imported/shift.idef
 create mode 100644 target/hexagon/imported/subinsns.idef
 create mode 100644 target/hexagon/imported/system.idef
 create mode 100644 tests/tcg/hexagon/float_convs.ref
 create mode 100644 tests/tcg/hexagon/float_madds.ref

--
2.7.4