Skip to contentSkip to conversation

Hexagon patch series

PATCH In review Taylor Simpson 8 participants 101 messages Feb 8, 2021 – Apr 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v8 cover Hexagon patch series

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

See patch 02 Hexagon README for detailed information.

This series assumes int128_or() is implemented.
https://lists.nongnu.org/archive/html/qemu-devel/2020-10/msg06004.html

The series is also available at https://github.com/quic/qemu on branch small_series_v8.

Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.

The final patch in the series add docker support. Thanks to Alessandro Di Federico <[email protected]> and Brian Cain <[email protected]> for making this happen. The default container (debian-hexagon-cross) uses a toolchain built by rev.ng. Alternatively, there is a container that will build the toolchain locally (debian-hexagon-cross-build-local).

Here are the commands to verify the code:

    mkdir build
    cd build
    ../configure --target-list=hexagon-linux-user
    make
    make check-tcg

*** Known checkpatch issues ***

The following are known checkpatch errors in the series

    target/hexagon/reg_fields.h         Complex macro
    target/hexagon/attribs.h            Complex macro
    target/hexagon/decode.c             Complex macro
    target/hexagon/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
configure.sh Line over 90 characters
tests/tcg/configure.sh Line over 90 characters
scripts/qemu-binfmt-conf.sh Line over 90 characters

The following are known checkpatch warnings in the series

    target/hexagon/fma_emu.c            Comments inside macro definition
    target/hexagon/gen_tcg_funcs.py     Line over 80 characters
    scripts/qemu-binfmt-conf.sh         Line over 80 characters

*** Changes in v8 ***
Address feedback from Philippe Mathieu-Daud� <[email protected]>
Make RAISE_FP_EXCEPTION conditional on CONFIG_USER_ONLY Enable build in 32-bit mode
Remove extern from function prototypes in header files Fixed issues running under gitlab-ci
Use qemu .inc file naming convention

Address feedback from Richard Henderson <<[email protected]>
Don't set PC at the beginning of every packet
Don't set slot_cancelled at the beginning of every packet Don't set pred_written at the beginning of every packet Only update execution counters at the end of TB

Reduce the amount of code that gets compiled when HEX_DEBUG is off

Fix bug uncovered in sanitizers-enabled build
Fix bug uncovered in clang build

*** Changes in v7 ***
Address feedback from Philippe Mathieu-Daud� <[email protected]>
Update copyright to 2021
Use GString instead of <string.h> for disassembly
Remove mixed declarations (interleaving statements and declarations) Change 4 to sizeof(uint32_t)

Address feedback from Alex Benn�e <[email protected]>
Break TCG tests patch into multiple patches
Remove pthread_cancel test (submitted as a standalone patch)

*** Changes in v6 ***
Correct QEMU_GENERATE implementations for fLSBNEW0/fLSBNEW1 Change Python file handling to use with statement
Change import hex_common to be explicit
Generator cleanup
Change N?N (new value) to value instead of register number for consistency Fixed bud in reading control register pair
Add ctx_log_reg_write_pair
Clean up control reg offset from HEX_REG_SA0
Fix errors in FP instructions uncovered by musl libc-tests
Added unit tests

*** Changes in v5 ***
Bug fixes
Properly implement circular addressing
memw(r1++I:circ(m0)) = r2
Make gen_cmpnd_cmp_jmp execute in 2 parts

Address remaining blocker items from Richard Henderson's review.
Use qemu softfloat
Use const where appropriate
Break tcg_funcs_generated.h into two files - functions and table Change struct and enum type names to CamelCase
Include packet in raw bytes in assembly
Use DEF_HELPER_FLAGS where possible
Fix merge_bytes endianness and overlap test by doing the store before load Use bitmask instead of string in decoding
Add comments to decoder
Use qemu/int128.h
Use qemu/bitops.h for instruction attributes
Add bitmask for ctx->reg_log
Note we still have the array/idx for iteration during gen_commit_packet
Change opcode_syntax to be created at compile time in gen_dectree_import.c Remove unused tmp variables
Isolate hex_arch_types to imported files
Fix git am whitespace warnings

Address items from Philippe Mathieu-Daud�'s review
Split utility functions patch into 3 digestable patches Fixed type "definition"
Change all exit codes to be either 0 or 1 Validated build with gcc 4.8, 5.5, and ***** Removed qemu/osdep.h and qemu/host-utils.h from macros.h

Address items from Laurent Vivier's review
Don't filter out __NR_syscalls
Remove syscall_nr_generators from linux-user/hexagon/meson.build Remove subdir('hexagon') from linux-user/meson.build Generate syscall_nr.h from 5.5 Linux kernel

*** Changes in v4 ***
Convert target/hexagon/Makefile.objs to meson.build

Address portions of feedback from Richard Henderson. Here is the table of items from Richard's review.

Patch   Item                                                 Blocker Status
        Use qemu softfloat                                   Yes
        Use qemu decodetree.py                               No
Several Use const when appropriate                           Yes
Several Remove anything after g_assert_not_reached           Yes     DONE
Several Fix log_store32/64 add/remove/add in patch series    Yes     DONE
Several Follow naming guidelines for structs and enums       Yes
4       Move decls to cpu-param.h                            Yes     DONE
4       Remove CONFIG_USER_ONLY ifdef's                      Yes     DONE
4       Remove DEBUG_HEXAGON                                 Yes     Partially
4       Remove stack pointer modification hack               Yes     DONE
4       Add property x-lldb-compat to control output         Yes     DONE
6       Include instruction and raw bytes in disassembly     Yes
7       Use DEF_HELPER_FLAGS                                 No
07, 26  Endianness of merge_bytes                            Yes
7       Fix overlap test                                     Yes
7       Remove HELPER(debug_value)/HELPER(debug_value_i64)   Yes     DONE
9       Include "qemu/osdep.h" instead of <stdint.h>         Yes     DONE
Several Stick with stdint.h types except in imported files   Yes     DONE
11      Remove description from reg field definitions        Yes     DONE
13      Move regmap.h into decode.c                          Yes     DONE
14, 27  Use bit mask instead of strings in decoding          No
14      Add comments to decoder                              Yes
16      Use qemu/int128.h                                    No
17      Squash patches dealing with imported files           Yes     DONE
24      Use qemu/bitops.h for instruction attributes         No
24      Fix initialization of opcode_short_semantics         Yes     DONE
24      Change if (p == NULL) { g_assert_not_reached(); }
        to assert(p != NULL)                                 No      DONE
25      Expand DECL/READ/WRITE/FREE macros in generator      Yes     DONE
26      Rewrite fINSERT*, fEXTRACT*, f?XTN macros            Yes     DONE
26      Investigate fRND macro                               No      DONE
26      Change REG = REG to (VOID)REG to suppress warning    Yes     DONE
27      Remove multiple includes of imported/iclass.def      Yes     DONE
28      Move genptr_helpers.h into genptr.c                  Yes     DONE
28      Remove unneeded temps                                No      DONE
28      Use tcg_gen_deposit_tl and tcg_gen_extract_tl
        when dealing with p3_0                               No      DONE
29      Size opcode_genptr[] properly and initialize
        with [TAG] = generate_##TAG                          Yes     DONE
30      Don't generate helpers for overridden instructions   Yes     DONE
        Don't include "gen_tcg.h" in helper.h                Yes     DONE
31      Use bitmask for ctx->reg_log instead of an array     Yes

31 Use tcg_gen_extract_i32 for gen_slot_cancelled_check Yes DONE
31 Properly deal with reading instructions across
a page boundary and too many instructions before
finding end-of-packet Yes DONE

31      Don't set PC at the beginning of every packet        No
31      Don't set slot_cancelled unless needed               No
31      Don't set hex_pred_written unless needed             No
31      Change cancelled variable to not local               Yes     DONE
31      Remove unnecessary temp                              Yes     DONE
31      Let tcg_gen_addi_tl check for zero                   Yes     DONE
31      Move gen_exec_counters to end of TB                  No
31      Move end of TB handling to hexagon_tr_tb_stop        Yes     DONE

Generate two lists for TCG functions instead of
the DEF_TCG_FUNC macro Yes DONE

*** Changes in v3 ***
Remove substantial portions of the code to facilitate review
- Plan to submit subsequent patches
- Hexagon Vector eXtensions (HVX)
- Circular and bit-reverse addressiong
- Add/sub-with-carry
- Unused insn_t and pkt_t fields
- Unused instruction attributes
- All TCG overrides except instructions with multiple definitions
- Unused macros
- Unused reg fields
- COUNT_HEX_HELPERS
Use Laurent's gensyscall.sh script to generate linux-user/hexagon/syscall_nr.h Handle mem_noshuf
Remove "RsV = RsV" per review feedback
Simplify include file structure
Add directed tests in <qemu>/tests/tcg/hexagon
Change fWRAP_* macros to fGEN_TCG_*

*** 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

Alessandro Di Federico (1):
Add Dockerfile for hexagon

Taylor Simpson (34):
Hexagon Update MAINTAINERS file
Hexagon (target/hexagon) README
Hexagon (include/elf.h) ELF machine definition
Hexagon (target/hexagon) scalar core definition
Hexagon (disas) disassembler
Hexagon (target/hexagon) register names
Hexagon (target/hexagon) scalar core helpers
Hexagon (target/hexagon) GDB Stub
Hexagon (target/hexagon) architecture types
Hexagon (target/hexagon) instruction and packet types Hexagon (target/hexagon) register fields
Hexagon (target/hexagon) instruction attributes
Hexagon (target/hexagon) instruction/packet decode
Hexagon (target/hexagon) instruction printing
Hexagon (target/hexagon/arch.[ch]) utility functions Hexagon (target/hexagon/conv_emu.[ch]) utility functions Hexagon (target/hexagon/fma_emu.[ch]) utility functions Hexagon (target/hexagon/imported) arch import
Hexagon (target/hexagon) generator phase 1 - C preprocessor for
semantics
Hexagon (target/hexagon) generator phase 2 - generate header files Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode
tree
Hexagon (target/hexagon) generater phase 4 - decode tree Hexagon (target/hexagon) opcode data structures
Hexagon (target/hexagon) macros
Hexagon (target/hexagon) instruction classes
Hexagon (target/hexagon) TCG generation
Hexagon (target/hexagon) TCG for instructions with multiple
definitions
Hexagon (target/hexagon) TCG for floating point instructions Hexagon (target/hexagon) translation
Hexagon (linux-user/hexagon) Linux user emulation
Hexagon (tests/tcg/hexagon) TCG tests - multiarch
Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc Hexagon (tests/tcg/hexagon) TCG tests - floating point Hexagon build infrastructure

 default-configs/targets/hexagon-linux-user.mak     |    1 +
 meson.build                                        |    1 +
 include/disas/dis-asm.h                            |    1 +
 include/elf.h                                      |    1 +
 linux-user/hexagon/sockbits.h                      |   18 +
 linux-user/hexagon/syscall_nr.h                    |  322 +++
 linux-user/hexagon/target_cpu.h                    |   44 +
 linux-user/hexagon/target_elf.h                    |   40 +
 linux-user/hexagon/target_fcntl.h                  |   18 +
 linux-user/hexagon/target_signal.h                 |   34 +
 linux-user/hexagon/target_structs.h                |   54 +
 linux-user/hexagon/target_syscall.h                |   36 +
 linux-user/hexagon/termbits.h                      |   18 +
 linux-user/qemu.h                                  |    2 +
 linux-user/syscall_defs.h                          |   33 +
 target/hexagon/arch.h                              |   34 +
 target/hexagon/attribs.h                           |   35 +
 target/hexagon/conv_emu.h                          |   31 +
 target/hexagon/cpu-param.h                         |   29 +
 target/hexagon/cpu.h                               |  159 ++
 target/hexagon/cpu_bits.h                          |   58 +
 target/hexagon/decode.h                            |   32 +
 target/hexagon/fma_emu.h                           |   36 +
 target/hexagon/gen_tcg.h                           |  319 +++
 target/hexagon/genptr.h                            |   25 +
 target/hexagon/helper.h                            |   88 +
 target/hexagon/hex_arch_types.h                    |   38 +
 target/hexagon/hex_regs.h                          |   83 +
 target/hexagon/iclass.h                            |   50 +
 target/hexagon/insn.h                              |   74 +
 target/hexagon/internal.h                          |   37 +
 target/hexagon/macros.h                            |  592 ++++++
 target/hexagon/opcodes.h                           |   58 +
 target/hexagon/printinsn.h                         |   27 +
 target/hexagon/reg_fields.h                        |   36 +
 target/hexagon/translate.h                         |   93 +
 target/hexagon/attribs_def.h.inc                   |   97 +
 target/hexagon/reg_fields_def.h.inc                |   41 +
 disas/hexagon.c                                    |   65 +
 linux-user/elfload.c                               |   16 +
 linux-user/hexagon/cpu_loop.c                      |  100 +
 linux-user/hexagon/signal.c                        |  276 +++
 target/hexagon/arch.c                              |  300 +++
 target/hexagon/conv_emu.c                          |  177 ++
 target/hexagon/cpu.c                               |  318 +++
 target/hexagon/decode.c                            |  957 +++++++++
 target/hexagon/fma_emu.c                           |  702 +++++++
 target/hexagon/gdbstub.c                           |   47 +
 target/hexagon/gen_dectree_import.c                |  188 ++
 target/hexagon/gen_semantics.c                     |   88 +
 target/hexagon/genptr.c                            |  331 +++
 target/hexagon/iclass.c                            |   73 +
 target/hexagon/op_helper.c                         | 1064 ++++++++++
 target/hexagon/opcodes.c                           |  142 ++
 target/hexagon/printinsn.c                         |  146 ++
 target/hexagon/reg_fields.c                        |   27 +
 target/hexagon/translate.c                         |  748 +++++++
 tests/tcg/hexagon/atomics.c                        |  139 ++
 tests/tcg/hexagon/dual_stores.c                    |   60 +
 tests/tcg/hexagon/fpstuff.c                        |  370 ++++
 tests/tcg/hexagon/mem_noshuf.c                     |  328 +++
 tests/tcg/hexagon/misc.c                           |  380 ++++
 tests/tcg/hexagon/preg_alias.c                     |  169 ++
 MAINTAINERS                                        |    9 +
 disas/meson.build                                  |    1 +
 scripts/gensyscalls.sh                             |    1 +
 scripts/qemu-binfmt-conf.sh                        |    6 +-
 target/hexagon/README                              |  235 +++
 target/hexagon/dectree.py                          |  351 ++++
 target/hexagon/gen_helper_funcs.py                 |  220 ++
 target/hexagon/gen_helper_protos.py                |  150 ++
 target/hexagon/gen_op_attribs.py                   |   39 +
 target/hexagon/gen_op_regs.py                      |  110 +
 target/hexagon/gen_opcodes_def.py                  |   36 +
 target/hexagon/gen_printinsn.py                    |  173 ++
 target/hexagon/gen_shortcode.py                    |   60 +
 target/hexagon/gen_tcg_func_table.py               |   58 +
 target/hexagon/gen_tcg_funcs.py                    |  485 +++++
 target/hexagon/hex_common.py                       |  234 +++
 target/hexagon/imported/allidefs.def               |   30 +
 target/hexagon/imported/alu.idef                   | 1258 ++++++++++++
 target/hexagon/imported/branch.idef                |  326 +++
 target/hexagon/imported/compare.idef               |  619 ++++++
 target/hexagon/imported/encode.def                 |  124 ++
 target/hexagon/imported/encode_pp.def              | 2110 ++++++++++++++++++++
 target/hexagon/imported/encode_subinsn.def         |  149 ++
 target/hexagon/imported/float.idef                 |  312 +++
 target/hexagon/imported/iclass.def                 |   51 +
 target/hexagon/imported/ldst.idef                  |  286 +++
 target/hexagon/imported/macros.def                 | 1531 ++++++++++++++
 target/hexagon/imported/mpy.idef                   | 1208 +++++++++++
 target/hexagon/imported/shift.idef                 | 1066 ++++++++++
 target/hexagon/imported/subinsns.idef              |  149 ++
 target/hexagon/imported/system.idef                |   68 +
 target/hexagon/meson.build                         |  193 ++
 target/meson.build                                 |    1 +
 .../debian-hexagon-cross-build-local.docker        |   18 +
 .../debian-hexagon-cross.build-toolchain.sh        |  141 ++
 .../docker/dockerfiles/debian-hexagon-cross.docker |    1 +
 tests/tcg/configure.sh                             |    8 +-
 tests/tcg/hexagon/Makefile.target                  |   46 +
 tests/tcg/hexagon/first.S                          |   56 +
 tests/tcg/hexagon/float_convs.ref                  |  748 +++++++
 tests/tcg/hexagon/float_madds.ref                  |  768 +++++++
 104 files changed, 23339 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/targets/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/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/gen_tcg.h
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/helper.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/opcodes.h
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/reg_fields.h
 create mode 100644 target/hexagon/translate.h
 create mode 100644 target/hexagon/attribs_def.h.inc
 create mode 100644 target/hexagon/reg_fields_def.h.inc
 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/op_helper.c
 create mode 100644 target/hexagon/opcodes.c
 create mode 100644 target/hexagon/printinsn.c
 create mode 100644 target/hexagon/reg_fields.c
 create mode 100644 target/hexagon/translate.c
 create mode 100644 tests/tcg/hexagon/atomics.c
 create mode 100644 tests/tcg/hexagon/dual_stores.c
 create mode 100644 tests/tcg/hexagon/fpstuff.c
 create mode 100644 tests/tcg/hexagon/mem_noshuf.c
 create mode 100644 tests/tcg/hexagon/misc.c
 create mode 100644 tests/tcg/hexagon/preg_alias.c
 create mode 100644 target/hexagon/README
 create mode 100755 target/hexagon/dectree.py
 create mode 100755 target/hexagon/gen_helper_funcs.py
 create mode 100755 target/hexagon/gen_helper_protos.py
 create mode 100755 target/hexagon/gen_op_attribs.py
 create mode 100755 target/hexagon/gen_op_regs.py
 create mode 100755 target/hexagon/gen_opcodes_def.py
 create mode 100755 target/hexagon/gen_printinsn.py
 create mode 100755 target/hexagon/gen_shortcode.py
 create mode 100755 target/hexagon/gen_tcg_func_table.py
 create mode 100755 target/hexagon/gen_tcg_funcs.py
 create mode 100755 target/hexagon/hex_common.py
 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/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 target/hexagon/meson.build
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker
 create mode 100755 tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross.docker
 create mode 100644 tests/tcg/hexagon/Makefile.target
 create mode 100644 tests/tcg/hexagon/first.S
 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

PATCH v8 1/35 Hexagon Update MAINTAINERS file

Add Taylor Simpson as the Hexagon target maintainer

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index 8d8b0bf..4130008 100644
@@ -188,6 +188,15 @@ 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: tests/tcg/hexagon/
+F: disas/hexagon.c
+F: default-configs/targets/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

PATCH v8 2/35 Hexagon (target/hexagon) README

In reply to Taylor Simpson

Gives an introduction and overview to the Hexagon target

---
 target/hexagon/README | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 235 insertions(+)
 create mode 100644 target/hexagon/README
target/hexagon/README new file +235 -0
new file mode 100644
index 0000000..b0b2435
@@ -0,0 +1,235 @@
+Hexagon is Qualcomm's very long instruction word (VLIW) digital signal
+processor(DSP).
+
+The following versions of the Hexagon core are supported
+    Scalar core: v67
+    https://developer.qualcomm.com/downloads/qualcomm-hexagon-v67-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 scripts that generate a bunch of include files.  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/gen_semantics.c.  This step produces
+    <BUILD_DIR>/target/hexagon/semantics_generated.pyinc.
+That file is consumed by the following python scripts to produce the indicated
+header files in <BUILD_DIR>/target/hexagon
+        gen_opcodes_def.py              -> opcodes_def_generated.h.inc
+        gen_op_regs.py                  -> op_regs_generated.h.inc
+        gen_printinsn.py                -> printinsn_generated.h.inc
+        gen_op_attribs.py               -> op_attribs_generated.h.inc
+        gen_helper_protos.py            -> helper_protos_generated.h.inc
+        gen_shortcode.py                -> shortcode_generated.h.inc
+        gen_tcg_funcs.py                -> tcg_funcs_generated.c.inc
+        gen_tcg_func_table.py           -> tcg_func_table_generated.c.inc
+        gen_helper_funcs.py             -> helper_funcs_generated.c.inc
+
+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
+
+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
+hex_common.py) to determine the signature of the helper function.  Here are the
+results for A2_add
+
+helper_protos_generated.h.inc
+    DEF_HELPER_3(A2_add, s32, env, s32, s32)
+
+tcg_funcs_generated.c.inc
+    static void generate_A2_add(
+                    CPUHexagonState *env,
+                    DisasContext *ctx,
+                    Insn *insn,
+                    Packet *pkt)
+    {
+        TCGv RdV = tcg_temp_local_new();
+        const int RdN = insn->regno[0];
+        TCGv RsV = hex_gpr[insn->regno[1]];
+        TCGv RtV = hex_gpr[insn->regno[2]];
+        gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
+        gen_log_reg_write(RdN, RdV);
+        ctx_log_reg_write(ctx, RdN);
+        tcg_temp_free(RdV);
+    }
+
+helper_funcs_generated.c.inc
+    int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV)
+    {
+        uint32_t slot __attribute__((unused)) = 4;
+        int32_t RdV = 0;
+        { RdV=RsV+RtV;}
+        return RdV;
+    }
+
+Note that generate_A2_add updates the disassembly context to be processed
+when the packet commits (see "Packet Semantics" below).
+
+The generator checks for fGEN_TCG_<tag> macro.  This allows us to generate
+TCG code instead of a call to the helper.  If defined, the macro takes 1
+argument.
+    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 gen_tcg.h file has any overrides. For example, we could write
+    #define fGEN_TCG_A2_add(GENHLPR, SHORTCODE) \
+        tcg_gen_add_tl(RdV, RsV, RtV)
+
+The instruction semantics C code relies 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 L2_loadw_locked:
+    Instruction tag        L2_loadw_locked
+    Assembly syntax        "Rd32=memw_locked(Rs32)"
+    Instruction semantics  "{ fEA_REG(RsV); fLOAD_LOCKED(1,4,u,EA,RdV) }"
+
+In gen_tcg.h, we use the shortcode
+#define fGEN_TCG_L2_loadw_locked(SHORTCODE) \
+    SHORTCODE
+
+There are also cases where we brute force the TCG code generation.
+Instructions with multiple definitions are examples.  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>/target/hexagon/iset.py
+This file is imported by target/hexagon/dectree.py to produce
+    <BUILD_DIR>/target/hexagon/dectree_generated.h.inc
+
+*** 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
+
+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_and_translate_packet - disassemble a packet and generate code
+
+genptr.c
+gen_tcg.h
+
+These files create a function for each instruction.  It is mostly composed of
+fGEN_TCG_<tag> definitions followed by including tcg_funcs_generated.c.inc.
+
+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
+helper_funcs_generated.c.inc.  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
+
+    reg_log            list of registers written
+    reg_log_idx        index into ctx_reg_log
+    pred_log           list of predicates written
+    pred_log_idx       index into ctx_pred_log
+    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)
+
+*** 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_A2_add
+    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

PATCH v8 3/35 Hexagon (include/elf.h) ELF machine definition

In reply to Taylor Simpson

Define EM_HEXAGON 164

---
 include/elf.h | 1 +
 1 file changed, 1 insertion(+)
include/elf.h +1 -0
index 7a418ee..f4fa3c1 100644
@@ -176,6 +176,7 @@ typedef struct mips_elf_abiflags_v0 {
 
 #define EM_UNICORE32    110     /* UniCore32 */
 
+#define EM_HEXAGON      164     /* Qualcomm Hexagon */
 #define EM_RX           173     /* Renesas RX family */
 
 #define EM_RISCV        243     /* RISC-V */
Signature · 1 line
2.7.4
#4 lore raw

PATCH v8 4/35 Hexagon (target/hexagon) scalar core definition

In reply to Taylor Simpson

Add target state header, target definitions and initialization routines

---
 target/hexagon/cpu-param.h |  29 +++++
 target/hexagon/cpu.h       | 159 +++++++++++++++++++++++
 target/hexagon/cpu_bits.h  |  58 +++++++++
 target/hexagon/internal.h  |  35 +++++
 target/hexagon/cpu.c       | 318 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 599 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 +29 -0
new file mode 100644
index 0000000..e8ed546
@@ -0,0 +1,29 @@
+/*
+ *  Copyright(c) 2019-2021 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_PAGE_BITS 16     /* 64K pages */
+#define TARGET_LONG_BITS 32
+
+#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 +159 -0

159 lines not on this page · raw message

target/hexagon/cpu_bits.h new file +58 -0

58 lines not on this page · raw message

target/hexagon/internal.h new file +35 -0
new file mode 100644
index 0000000..c839796
@@ -0,0 +1,35 @@
+/*
+ *  Copyright(c) 2019-2021 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_INTERNAL_H
+#define HEXAGON_INTERNAL_H
+
+/*
+ * Change HEX_DEBUG to 1 to turn on debugging output
+ */
+#define HEX_DEBUG 0
+#if HEX_DEBUG
+#define HEX_DEBUG_LOG(...) qemu_log(__VA_ARGS__)
+#else
+#define HEX_DEBUG_LOG(...) do { } while (0)
+#endif
+
+void hexagon_debug(CPUHexagonState *env);
+
+extern const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS];
+
+#endif
target/hexagon/cpu.c new file +318 -0

318 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH v8 5/35 Hexagon (disas) disassembler

In reply to Taylor Simpson

Add hexagon to disas/meson.build
Add disas/hexagon.c
Add hexagon to include/disas/dis-asm.h

---
 include/disas/dis-asm.h |  1 +
 disas/hexagon.c         | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 disas/meson.build       |  1 +
 3 files changed, 67 insertions(+)
 create mode 100644 disas/hexagon.c
include/disas/dis-asm.h +1 -0
index d1133a4..13fa1ed 100644
@@ -459,6 +459,7 @@ 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_rx(bfd_vma, disassemble_info *);
+int print_insn_hexagon(bfd_vma, disassemble_info *);
 
 #ifdef CONFIG_CAPSTONE
 bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size);
disas/hexagon.c new file +65 -0

65 lines not on this page · raw message

disas/meson.build +1 -0
index da341a5..4c8da01 100644
@@ -6,6 +6,7 @@ common_ss.add(when: 'CONFIG_ARM_A64_DIS', if_true: files('arm-a64.cc'))
 common_ss.add_all(when: 'CONFIG_ARM_A64_DIS', if_true: libvixl_ss)
 common_ss.add(when: 'CONFIG_ARM_DIS', if_true: files('arm.c'))
 common_ss.add(when: 'CONFIG_CRIS_DIS', if_true: files('cris.c'))
+common_ss.add(when: 'CONFIG_HEXAGON_DIS', if_true: files('hexagon.c'))
 common_ss.add(when: 'CONFIG_HPPA_DIS', if_true: files('hppa.c'))
 common_ss.add(when: 'CONFIG_I386_DIS', if_true: files('i386.c'))
 common_ss.add(when: 'CONFIG_LM32_DIS', if_true: files('lm32.c'))
Signature · 1 line
2.7.4
#6 lore raw

PATCH v8 6/35 Hexagon (target/hexagon) register names

In reply to Taylor Simpson
---
 target/hexagon/hex_regs.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 target/hexagon/hex_regs.h
target/hexagon/hex_regs.h new file +83 -0
new file mode 100644
index 0000000..f291911
@@ -0,0 +1,83 @@
+/*
+ *  Copyright(c) 2019-2021 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_UTIMERLO          = 62,
+    HEX_REG_UTIMERHI          = 63,
+};
+
+#endif
Signature · 1 line
2.7.4
#7 lore raw

PATCH v8 7/35 Hexagon (target/hexagon) 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    |   88 ++++
 target/hexagon/op_helper.c | 1064 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1152 insertions(+)
 create mode 100644 target/hexagon/helper.h
 create mode 100644 target/hexagon/op_helper.c
target/hexagon/helper.h new file +88 -0
new file mode 100644
index 0000000..a5f340c
@@ -0,0 +1,88 @@
+/*
+ *  Copyright(c) 2019-2021 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 "internal.h"
+#include "helper_protos_generated.h.inc"
+
+DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32)
+#if HEX_DEBUG
+DEF_HELPER_1(debug_start_packet, void, env)
+DEF_HELPER_FLAGS_3(debug_check_store_width, TCG_CALL_NO_WG, void, env, int, int)
+DEF_HELPER_FLAGS_3(debug_commit_end, TCG_CALL_NO_WG, void, env, int, int)
+#endif
+DEF_HELPER_2(commit_store, void, env, int)
+DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32)
+
+/* Floating point */
+DEF_HELPER_2(conv_sf2df, f64, env, f32)
+DEF_HELPER_2(conv_df2sf, f32, env, f64)
+DEF_HELPER_2(conv_uw2sf, f32, env, s32)
+DEF_HELPER_2(conv_uw2df, f64, env, s32)
+DEF_HELPER_2(conv_w2sf, f32, env, s32)
+DEF_HELPER_2(conv_w2df, f64, env, s32)
+DEF_HELPER_2(conv_ud2sf, f32, env, s64)
+DEF_HELPER_2(conv_ud2df, f64, env, s64)
+DEF_HELPER_2(conv_d2sf, f32, env, s64)
+DEF_HELPER_2(conv_d2df, f64, env, s64)
+DEF_HELPER_2(conv_sf2uw, s32, env, f32)
+DEF_HELPER_2(conv_sf2w, s32, env, f32)
+DEF_HELPER_2(conv_sf2ud, s64, env, f32)
+DEF_HELPER_2(conv_sf2d, s64, env, f32)
+DEF_HELPER_2(conv_df2uw, s32, env, f64)
+DEF_HELPER_2(conv_df2w, s32, env, f64)
+DEF_HELPER_2(conv_df2ud, s64, env, f64)
+DEF_HELPER_2(conv_df2d, s64, env, f64)
+DEF_HELPER_2(conv_sf2uw_chop, s32, env, f32)
+DEF_HELPER_2(conv_sf2w_chop, s32, env, f32)
+DEF_HELPER_2(conv_sf2ud_chop, s64, env, f32)
+DEF_HELPER_2(conv_sf2d_chop, s64, env, f32)
+DEF_HELPER_2(conv_df2uw_chop, s32, env, f64)
+DEF_HELPER_2(conv_df2w_chop, s32, env, f64)
+DEF_HELPER_2(conv_df2ud_chop, s64, env, f64)
+DEF_HELPER_2(conv_df2d_chop, s64, env, f64)
+DEF_HELPER_3(sfadd, f32, env, f32, f32)
+DEF_HELPER_3(sfsub, f32, env, f32, f32)
+DEF_HELPER_3(sfcmpeq, s32, env, f32, f32)
+DEF_HELPER_3(sfcmpgt, s32, env, f32, f32)
+DEF_HELPER_3(sfcmpge, s32, env, f32, f32)
+DEF_HELPER_3(sfcmpuo, s32, env, f32, f32)
+DEF_HELPER_3(sfmax, f32, env, f32, f32)
+DEF_HELPER_3(sfmin, f32, env, f32, f32)
+DEF_HELPER_3(sfclass, s32, env, f32, s32)
+DEF_HELPER_3(sffixupn, f32, env, f32, f32)
+DEF_HELPER_3(sffixupd, f32, env, f32, f32)
+DEF_HELPER_2(sffixupr, f32, env, f32)
+
+DEF_HELPER_3(dfadd, f64, env, f64, f64)
+DEF_HELPER_3(dfsub, f64, env, f64, f64)
+DEF_HELPER_3(dfmax, f64, env, f64, f64)
+DEF_HELPER_3(dfmin, f64, env, f64, f64)
+DEF_HELPER_3(dfcmpeq, s32, env, f64, f64)
+DEF_HELPER_3(dfcmpgt, s32, env, f64, f64)
+DEF_HELPER_3(dfcmpge, s32, env, f64, f64)
+DEF_HELPER_3(dfcmpuo, s32, env, f64, f64)
+DEF_HELPER_3(dfclass, s32, env, f64, s32)
+
+DEF_HELPER_3(sfmpy, f32, env, f32, f32)
+DEF_HELPER_4(sffma, f32, env, f32, f32, f32)
+DEF_HELPER_5(sffma_sc, f32, env, f32, f32, f32, f32)
+DEF_HELPER_4(sffms, f32, env, f32, f32, f32)
+DEF_HELPER_4(sffma_lib, f32, env, f32, f32, f32)
+DEF_HELPER_4(sffms_lib, f32, env, f32, f32, f32)
+
+DEF_HELPER_3(dfmpyfix, f64, env, f64, f64)
+DEF_HELPER_4(dfmpyhh, f64, env, f64, f64, f64)
target/hexagon/op_helper.c new file +1064 -0

1,064 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v8 8/35 Hexagon (target/hexagon) GDB Stub

In reply to Taylor Simpson

GDB register read and write routines

---
 target/hexagon/internal.h |  2 ++
 target/hexagon/gdbstub.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 target/hexagon/gdbstub.c
target/hexagon/internal.h +2 -0
index c839796..2da85c8 100644
@@ -28,6 +28,8 @@
 #define HEX_DEBUG_LOG(...) do { } while (0)
 #endif
 
+int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
+int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 void hexagon_debug(CPUHexagonState *env);
 
 extern const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS];
target/hexagon/gdbstub.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

PATCH v8 9/35 Hexagon (target/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 | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 target/hexagon/hex_arch_types.h
target/hexagon/hex_arch_types.h new file +38 -0
new file mode 100644
index 0000000..d721e1f
@@ -0,0 +1,38 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+#include "qemu/osdep.h"
+#include "qemu/int128.h"
+
+/*
+ * These types are used by the code imported from the Hexagon
+ * architecture library.
+ */
+typedef uint8_t     size1u_t;
+typedef int8_t      size1s_t;
+typedef uint16_t    size2u_t;
+typedef int16_t     size2s_t;
+typedef uint32_t    size4u_t;
+typedef int32_t     size4s_t;
+typedef uint64_t    size8u_t;
+typedef int64_t     size8s_t;
+typedef Int128      size16s_t;
+
+#endif
Signature · 1 line
2.7.4
Reviewed-by on v8 9/35
#10 lore raw

Re: [PATCH v8 09/35] Hexagon (target/hexagon) architecture types

Quoted 7 lines · Taylor Simpson

Define types used in files imported from the Hexagon architecture library

---
 target/hexagon/hex_arch_types.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 target/hexagon/hex_arch_types.h
Reviewed-by on v8 9/35
#11 lore raw

Re: [PATCH v8 09/35] Hexagon (target/hexagon) architecture types

In reply to Taylor Simpson
Quoted 7 lines · Taylor Simpson

Define types used in files imported from the Hexagon architecture library

---
 target/hexagon/hex_arch_types.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 target/hexagon/hex_arch_types.h

r~

#12 lore raw

PATCH v8 10/35 Hexagon (target/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 | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 target/hexagon/insn.h
target/hexagon/insn.h new file +74 -0
new file mode 100644
index 0000000..5756a1d
@@ -0,0 +1,74 @@
+/*
+ *  Copyright(c) 2019-2021 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"
+
+#define INSTRUCTIONS_MAX 7    /* 2 pairs + loopend */
+#define REG_OPERANDS_MAX 5
+#define IMMEDS_MAX 2
+
+struct Instruction;
+struct Packet;
+struct DisasContext;
+
+typedef void (*SemanticInsn)(CPUHexagonState *env,
+                             struct DisasContext *ctx,
+                             struct Instruction *insn,
+                             struct Packet *pkt);
+
+struct Instruction {
+    SemanticInsn generate;            /* pointer to genptr routine */
+    uint8_t regno[REG_OPERANDS_MAX];    /* reg operands including predicates */
+    uint16_t opcode;
+
+    uint32_t iclass:6;
+    uint32_t slot:3;
+    uint32_t part1:1;        /*
+                              * cmp-jumps are split into two insns.
+                              * set for the compare and clear for the jump
+                              */
+    uint32_t extension_valid:1;   /* Has a constant extender attached */
+    uint32_t which_extended:1;    /* If has an extender, which immediate */
+    uint32_t is_endloop:1;   /* This is an end of loop */
+    uint32_t new_value_producer_slot:4;
+    int32_t immed[IMMEDS_MAX];    /* immediate field */
+};
+
+typedef struct Instruction Insn;
+
+struct Packet {
+    uint16_t num_insns;
+    uint16_t encod_pkt_size_in_bytes;
+
+    /* Pre-decodes about COF */
+    uint32_t pkt_has_cof:1;          /* Has any change-of-flow */
+    uint32_t pkt_has_endloop:1;
+
+    uint32_t pkt_has_dczeroa:1;
+
+    uint32_t pkt_has_store_s0:1;
+    uint32_t pkt_has_store_s1:1;
+
+    Insn insn[INSTRUCTIONS_MAX];
+};
+
+typedef struct Packet Packet;
+
+#endif
Signature · 1 line
2.7.4
Reviewed-by on v8 10/35
#13 lore raw

Re: [PATCH v8 10/35] Hexagon (target/hexagon) instruction and packet types

Quoted 3 lines · Taylor Simpson
target/hexagon/insn.h new file +3 -0
+    uint32_t extension_valid:1;   /* Has a constant extender attached */
+    uint32_t which_extended:1;    /* If has an extender, which immediate */
+    uint32_t is_endloop:1;   /* This is an end of loop */

...

target/hexagon/insn.h line 67

Quoted 7 lines
target/hexagon/insn.h new file +7 -0
+    uint32_t pkt_has_cof:1;          /* Has any change-of-flow */
+    uint32_t pkt_has_endloop:1;
+
+    uint32_t pkt_has_dczeroa:1;
+
+    uint32_t pkt_has_store_s0:1;
+    uint32_t pkt_has_store_s1:1;

Any reason not to use bool?

Otherwise,

r~

#14 lore raw

PATCH v8 11/35 Hexagon (target/hexagon) register fields

In reply to Taylor Simpson

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

---
 target/hexagon/reg_fields.h         | 36 ++++++++++++++++++++++++++++++++
 target/hexagon/reg_fields_def.h.inc | 41 +++++++++++++++++++++++++++++++++++++
 target/hexagon/reg_fields.c         | 27 ++++++++++++++++++++++++
 3 files changed, 104 insertions(+)
 create mode 100644 target/hexagon/reg_fields.h
 create mode 100644 target/hexagon/reg_fields_def.h.inc
 create mode 100644 target/hexagon/reg_fields.c
target/hexagon/reg_fields.h new file +36 -0
new file mode 100644
index 0000000..d3c86c9
@@ -0,0 +1,36 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+typedef struct {
+    int offset;
+    int width;
+} RegField;
+
+extern const RegField reg_field_info[];
+
+enum {
+#define DEF_REG_FIELD(TAG, START, WIDTH) \
+    TAG,
+#include "reg_fields_def.h.inc"
+    NUM_REG_FIELDS
+#undef DEF_REG_FIELD
+};
+
+#endif
target/hexagon/reg_fields_def.h.inc new file +41 -0

41 lines not on this page · raw message

target/hexagon/reg_fields.c new file +27 -0
new file mode 100644
index 0000000..bdcab79
@@ -0,0 +1,27 @@
+/*
+ *  Copyright(c) 2019-2021 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"
+
+const RegField reg_field_info[] = {
+#define DEF_REG_FIELD(TAG, START, WIDTH)    \
+      { START, WIDTH },
+#include "reg_fields_def.h.inc"
+      { 0, 0 }
+#undef DEF_REG_FIELD
+};
Signature · 1 line
2.7.4
Reviewed-by on v8 11/35
#15 lore raw

Re: [PATCH v8 11/35] Hexagon (target/hexagon) register fields

target/hexagon/reg_fields.c line 27

Quoted 7 lines · Taylor Simpson
target/hexagon/reg_fields.c new file +7 -0
+const RegField reg_field_info[] = {
+#define DEF_REG_FIELD(TAG, START, WIDTH)    \
+      { START, WIDTH },
+#include "reg_fields_def.h.inc"
+      { 0, 0 }
+#undef DEF_REG_FIELD
+};

What is the purpose of the 0,0 entry? Surely you don't actually reference reg_field_info[NUM_REG_FIELDS]?

You could also annotate the declaration and definition of reg_field_info with the array size:

extern const RegField reg_field_info[NUM_REG_FIELDS];

Otherwise,

r~

#16 lore raw

PATCH v8 12/35 Hexagon (target/hexagon) instruction attributes

In reply to Taylor Simpson
---
 target/hexagon/attribs.h         | 35 +++++++++++++++
 target/hexagon/attribs_def.h.inc | 97 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 target/hexagon/attribs.h
 create mode 100644 target/hexagon/attribs_def.h.inc
target/hexagon/attribs.h new file +35 -0
new file mode 100644
index 0000000..54576f4
@@ -0,0 +1,35 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+#include "qemu/bitmap.h"
+#include "opcodes.h"
+
+enum {
+#define DEF_ATTRIB(NAME, ...) A_##NAME,
+#include "attribs_def.h.inc"
+#undef DEF_ATTRIB
+};
+
+extern DECLARE_BITMAP(opcode_attribs[XX_LAST_OPCODE], A_ZZ_LASTATTRIB);
+
+#define GET_ATTRIB(opcode, attrib) \
+    test_bit(attrib, opcode_attribs[opcode])
+
+#endif /* ATTRIBS_H */
target/hexagon/attribs_def.h.inc new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 12/35
#17 lore raw

Re: [PATCH v8 12/35] Hexagon (target/hexagon) instruction attributes

Quoted 8 lines · Taylor Simpson
---
 target/hexagon/attribs.h         | 35 +++++++++++++++
 target/hexagon/attribs_def.h.inc | 97 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 target/hexagon/attribs.h
 create mode 100644 target/hexagon/attribs_def.h.inc

r~

#18 lore raw

PATCH v8 13/35 Hexagon (target/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 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 |  32 ++
 target/hexagon/decode.c | 957 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 989 insertions(+)
 create mode 100644 target/hexagon/decode.h
 create mode 100644 target/hexagon/decode.c
target/hexagon/decode.h new file +32 -0
new file mode 100644
index 0000000..c66f5ea
@@ -0,0 +1,32 @@
+/*
+ *  Copyright(c) 2019-2021 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 "insn.h"
+
+void decode_init(void);
+
+void decode_send_insn_to(Packet *packet, int start, int newloc);
+
+int decode_packet(int max_words, const uint32_t *words, Packet *pkt,
+                  bool disas_only);
+
+#endif
target/hexagon/decode.c new file +957 -0

957 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 13/35
#19 lore raw

Re: [PATCH v8 13/35] Hexagon (target/hexagon) instruction/packet decode

target/hexagon/decode.c line 52

Quoted 2 lines · Taylor Simpson
target/hexagon/decode.c new file +2 -0
+#define DECODE_MAPPED_REG(REGNO, NAME) \
+    insn->regno[REGNO] = DECODE_REGISTER_##NAME[insn->regno[REGNO]];

The macro argument is not a regno, but an operand number.

Quoted 11 lines
target/hexagon/decode.c new file +11 -0
+static inline int decode_opcode_can_jump(int opcode)
+{
+    if ((GET_ATTRIB(opcode, A_JUMP)) ||
+        (GET_ATTRIB(opcode, A_CALL)) ||
+        (opcode == J2_trap0) ||
+        (opcode == J2_pause)) {
+        /* Exception to A_JUMP attribute */
+        if (opcode == J4_hintjumpr) {
+            return 0;
+        }
+        return 1;

target/hexagon/decode.c line 377

Quoted 10 lines
target/hexagon/decode.c new file +10 -0
+    }
+
+    return 0;
+}
+
+static inline int decode_opcode_ends_loop(int opcode)
+{
+    return GET_ATTRIB(opcode, A_HWLOOP0_END) ||
+           GET_ATTRIB(opcode, A_HWLOOP1_END);
+}

You can drop the inline markers.
You should use bool for booleans.

target/hexagon/decode.c line 427

Quoted 10 lines
target/hexagon/decode.c new file +10 -0
+/*
+ * Shuffle for execution
+ * Move stores to end (in same order as encoding)
+ * Move compares to beginning (for use by .new insns)
+ */
+static void decode_shuffle_for_execution(Packet *packet)
+{
+    int changed = 0;
+    int i;
+    int flag;    /* flag means we've seen a non-memory instruction */

Both changed and flag should be bool. Please have another look through and use bool as reasonable.

Otherwise,

r~

#20 lore raw

RE: [PATCH v8 13/35] Hexagon (target/hexagon) instruction/packet decode

Quoted 11 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 12:32 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 13/35] Hexagon (target/hexagon) instruction/packet decode

Quoted 6 lines
Quoted 3 lines · Taylor Simpson
(quoted diff) +2 -0
+#define DECODE_MAPPED_REG(REGNO, NAME) \
+    insn->regno[REGNO] = DECODE_REGISTER_##NAME[insn-

regno[REGNO]];

The macro argument is not a regno, but an operand number.

OK

Quoted 1 line

Please have another look through and use bool as reasonable.

OK

#21 lore raw

PATCH v8 14/35 Hexagon (target/hexagon) instruction printing

In reply to Taylor Simpson
---
 target/hexagon/printinsn.h |  27 +++++++++
 target/hexagon/printinsn.c | 146 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 173 insertions(+)
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/printinsn.c
target/hexagon/printinsn.h new file +27 -0
new file mode 100644
index 0000000..2ecd173
@@ -0,0 +1,27 @@
+/*
+ *  Copyright(c) 2019-2021 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 "insn.h"
+
+void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words,
+                         target_ulong pc);
+void snprint_a_pkt_debug(GString *buf, Packet *pkt);
+
+#endif
target/hexagon/printinsn.c new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 14/35
#22 lore raw

Re: [PATCH v8 14/35] Hexagon (target/hexagon) instruction printing

Quoted 8 lines · Taylor Simpson
---
 target/hexagon/printinsn.h |  27 +++++++++
 target/hexagon/printinsn.c | 146 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 173 insertions(+)
 create mode 100644 target/hexagon/printinsn.h
 create mode 100644 target/hexagon/printinsn.c

r~

#23 lore raw

PATCH v8 15/35 Hexagon (target/hexagon/arch.[ch]) utility functions

In reply to Taylor Simpson
---
 target/hexagon/arch.h |  34 ++++++
 target/hexagon/arch.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 334 insertions(+)
 create mode 100644 target/hexagon/arch.h
 create mode 100644 target/hexagon/arch.c
target/hexagon/arch.h new file +34 -0
new file mode 100644
index 0000000..1f7f036
@@ -0,0 +1,34 @@
+/*
+ *  Copyright(c) 2019-2021 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 "qemu/int128.h"
+
+uint64_t interleave(uint32_t odd, uint32_t even);
+uint64_t deinterleave(uint64_t src);
+uint32_t carry_from_add64(uint64_t a, uint64_t b, uint32_t c);
+int32_t conv_round(int32_t a, int n);
+void arch_fpop_start(CPUHexagonState *env);
+void arch_fpop_end(CPUHexagonState *env);
+int arch_sf_recip_common(float32 *Rs, float32 *Rt, float32 *Rd,
+                         int *adjust, float_status *fp_status);
+int arch_sf_invsqrt_common(float32 *Rs, float32 *Rd, int *adjust,
+                          float_status *fp_status);
+
+#endif
target/hexagon/arch.c new file +300 -0

300 lines not on this page · raw message

Signature · 1 line
2.7.4
#24 lore raw

Re: [PATCH v8 15/35] Hexagon (target/hexagon/arch.[ch]) utility functions

target/hexagon/arch.c line 90

Quoted 12 lines · Taylor Simpson
target/hexagon/arch.c new file +12 -0
+uint32_t carry_from_add64(uint64_t a, uint64_t b, uint32_t c)
+{
+    uint64_t tmpa, tmpb, tmpc;
+    tmpa = fGETUWORD(0, a);
+    tmpb = fGETUWORD(0, b);
+    tmpc = tmpa + tmpb + c;
+    tmpa = fGETUWORD(1, a);
+    tmpb = fGETUWORD(1, b);
+    tmpc = tmpa + tmpb + fGETUWORD(1, tmpc);
+    tmpc = fGETUWORD(1, tmpc);
+    return tmpc;
+}

I presume this is intended to compute carry-out from 64-bit addition with carry-in?

    uint64_t r = a + b;
    return c ? r <= a : r < a;
Quoted 1 line

+static const int softfloat_roundingmodes[] = {

FloatRoundMode

target/hexagon/arch.c line 163

Quoted 5 lines
target/hexagon/arch.c new file +5 -0
+static float32 float32_mul_pow2(float32 a, uint32_t p, float_status *fp_status)
+{
+    float32 b = make_float32((SF_BIAS + p) << SF_MANTBITS);
+    return float32_mul(a, b, fp_status);
+}

This is float32_scalbn.

r~

#25 lore raw

RE: [PATCH v8 15/35] Hexagon (target/hexagon/arch.[ch]) utility functions

Quoted 28 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 2:13 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 15/35] Hexagon (target/hexagon/arch.[ch]) utility functions

target/hexagon/arch.c line 90

Quoted 12 lines · Taylor Simpson
target/hexagon/arch.c new file +12 -0
+uint32_t carry_from_add64(uint64_t a, uint64_t b, uint32_t c)
+{
+    uint64_t tmpa, tmpb, tmpc;
+    tmpa = fGETUWORD(0, a);
+    tmpb = fGETUWORD(0, b);
+    tmpc = tmpa + tmpb + c;
+    tmpa = fGETUWORD(1, a);
+    tmpb = fGETUWORD(1, b);
+    tmpc = tmpa + tmpb + fGETUWORD(1, tmpc);
+    tmpc = fGETUWORD(1, tmpc);
+    return tmpc;
+}

I presume this is intended to compute carry-out from 64-bit addition with carry-in?

Quoted 2 lines
    uint64_t r = a + b;
    return c ? r <= a : r < a;

Actually, I can remove this because the instructions that use it have TCG overrides (i.e., there isn't a helper that references it).

Quoted 4 lines
Quoted 2 lines

+static const int softfloat_roundingmodes[] = {

FloatRoundMode

OK

Quoted 8 lines
Quoted 1 line

+static float32 float32_mul_pow2(float32 a, uint32_t p, float_status

*fp_status)

target/hexagon/arch.c line 163

Quoted 4 lines
target/hexagon/arch.c new file +4 -0
+{
+    float32 b = make_float32((SF_BIAS + p) << SF_MANTBITS);
+    return float32_mul(a, b, fp_status);
+}

This is float32_scalbn.

OK

Thanks,
Taylor

#26 lore raw

PATCH v8 16/35 Hexagon (target/hexagon/conv_emu.[ch]) utility functions

In reply to Taylor Simpson
---
 target/hexagon/conv_emu.h |  31 ++++++++
 target/hexagon/conv_emu.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 208 insertions(+)
 create mode 100644 target/hexagon/conv_emu.h
 create mode 100644 target/hexagon/conv_emu.c
target/hexagon/conv_emu.h new file +31 -0
new file mode 100644
index 0000000..cade9de
@@ -0,0 +1,31 @@
+/*
+ *  Copyright(c) 2019-2021 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_CONV_EMU_H
+#define HEXAGON_CONV_EMU_H
+
+uint64_t conv_sf_to_8u(float32 in, float_status *fp_status);
+uint32_t conv_sf_to_4u(float32 in, float_status *fp_status);
+int64_t conv_sf_to_8s(float32 in, float_status *fp_status);
+int32_t conv_sf_to_4s(float32 in, float_status *fp_status);
+
+uint64_t conv_df_to_8u(float64 in, float_status *fp_status);
+uint32_t conv_df_to_4u(float64 in, float_status *fp_status);
+int64_t conv_df_to_8s(float64 in, float_status *fp_status);
+int32_t conv_df_to_4s(float64 in, float_status *fp_status);
+
+#endif
target/hexagon/conv_emu.c new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

target/hexagon/conv_emu.h line 29

Quoted 9 lines · Taylor Simpson
target/hexagon/conv_emu.h new file +9 -0
+uint64_t conv_sf_to_8u(float32 in, float_status *fp_status);
+uint32_t conv_sf_to_4u(float32 in, float_status *fp_status);
+int64_t conv_sf_to_8s(float32 in, float_status *fp_status);
+int32_t conv_sf_to_4s(float32 in, float_status *fp_status);
+
+uint64_t conv_df_to_8u(float64 in, float_status *fp_status);
+uint32_t conv_df_to_4u(float64 in, float_status *fp_status);
+int64_t conv_df_to_8s(float64 in, float_status *fp_status);
+int32_t conv_df_to_4s(float64 in, float_status *fp_status);

You need to either use the normal float conversion routines, or document what the differences are.

target/hexagon/conv_emu.c line 34

Quoted 8 lines
target/hexagon/conv_emu.c new file +8 -0
+static uint64_t conv_f64_to_8u_n(float64 in, int will_negate,
+                                 float_status *fp_status)
+{
+    uint8_t sign = float64_is_neg(in);
+    if (float64_is_infinity(in)) {
+        float_raise(float_flag_invalid, fp_status);
+        if (float64_is_neg(in)) {
+            return 0ULL;

This isn't right for will_negate.

r~

#28 lore raw

RE: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 12 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 2:57 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

On 2/7/21 9:46 PM, Taylor Simpson wrote:

Quoted 12 lines

target/hexagon/conv_emu.h line 29

Quoted 9 lines
target/hexagon/conv_emu.h new file +9 -0
+uint64_t conv_sf_to_8u(float32 in, float_status *fp_status);
+uint32_t conv_sf_to_4u(float32 in, float_status *fp_status);
+int64_t conv_sf_to_8s(float32 in, float_status *fp_status);
+int32_t conv_sf_to_4s(float32 in, float_status *fp_status);
+
+uint64_t conv_df_to_8u(float64 in, float_status *fp_status);
+uint32_t conv_df_to_4u(float64 in, float_status *fp_status);
+int64_t conv_df_to_8s(float64 in, float_status *fp_status);
+int32_t conv_df_to_4s(float64 in, float_status *fp_status);

You need to either use the normal float conversion routines, or document what the differences are.

There are some differences in floating point flags raised, so I could write something like this:

    if (float32_is_infinity(RsV)) {
        float_raise(float_flag_invalid, &env->fp_status);
        if (float32_is_neg(RsV)) {
            RddV = 0ULL;
        } else {
            RddV = ~0ULL;
        }
    } else if (float32_is_any_nan(RsV)) {
        float_raise(float_flag_invalid, &env->fp_status);
        RddV = ~0ULL;
    } else if (float32_is_zero(RsV)) {
        RddV = 0;
    } else if (float32_is_neg(RsV)) {
        float_raise(float_flag_invalid, &env->fp_status);
        RddV = 0;
    } else {
        RddV = float32_to_uint64_round_to_zero(RsV, &env->fp_status);
    }

Does that work?

Thanks,
Taylor

#29 lore raw

Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 25 lines · Taylor Simpson
Quoted 12 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 2:57 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

On 2/7/21 9:46 PM, Taylor Simpson wrote:

Quoted 12 lines

target/hexagon/conv_emu.h line 29

Quoted 9 lines
target/hexagon/conv_emu.h new file +9 -0
+uint64_t conv_sf_to_8u(float32 in, float_status *fp_status);
+uint32_t conv_sf_to_4u(float32 in, float_status *fp_status);
+int64_t conv_sf_to_8s(float32 in, float_status *fp_status);
+int32_t conv_sf_to_4s(float32 in, float_status *fp_status);
+
+uint64_t conv_df_to_8u(float64 in, float_status *fp_status);
+uint32_t conv_df_to_4u(float64 in, float_status *fp_status);
+int64_t conv_df_to_8s(float64 in, float_status *fp_status);
+int32_t conv_df_to_4s(float64 in, float_status *fp_status);

You need to either use the normal float conversion routines, or document what the differences are.

Quoted 8 lines

There are some differences in floating point flags raised, so I could write something like this:

     if (float32_is_infinity(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         if (float32_is_neg(RsV)) {
             RddV = 0ULL;
         } else {
             RddV = ~0ULL;
         }

This isn't different from softfloat.c.

Quoted 3 lines
     } else if (float32_is_any_nan(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         RddV = ~0ULL;

Nor is this.

Quoted 2 lines
     } else if (float32_is_zero(RsV)) {
         RddV = 0;

Not exactly a special case.

Quoted 3 lines
     } else if (float32_is_neg(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         RddV = 0;

Not different.

Quoted 5 lines
     } else {
         RddV = float32_to_uint64_round_to_zero(RsV, &env->fp_status);
     }

Does that work?

This is 100% identical with round_to_uint_and_pack as used by float32_to_uint64_round_to_zero. It's all straight IEEE 754.

r~

#30 lore raw

RE: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 47 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, March 18, 2021 8:30 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 25 lines · Taylor Simpson
Quoted 12 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 2:57 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

On 2/7/21 9:46 PM, Taylor Simpson wrote:

Quoted 12 lines

target/hexagon/conv_emu.h line 29

Quoted 9 lines
target/hexagon/conv_emu.h new file +9 -0
+uint64_t conv_sf_to_8u(float32 in, float_status *fp_status);
+uint32_t conv_sf_to_4u(float32 in, float_status *fp_status);
+int64_t conv_sf_to_8s(float32 in, float_status *fp_status);
+int32_t conv_sf_to_4s(float32 in, float_status *fp_status);
+
+uint64_t conv_df_to_8u(float64 in, float_status *fp_status);
+uint32_t conv_df_to_4u(float64 in, float_status *fp_status);
+int64_t conv_df_to_8s(float64 in, float_status *fp_status);
+int32_t conv_df_to_4s(float64 in, float_status *fp_status);

You need to either use the normal float conversion routines, or document what the differences are.

Quoted 1 line

There are some differences in floating point flags raised, so I could write

something like this:

Quoted 7 lines
     if (float32_is_infinity(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         if (float32_is_neg(RsV)) {
             RddV = 0ULL;
         } else {
             RddV = ~0ULL;
         }
Quoted 7 lines

This isn't different from softfloat.c.

Quoted 3 lines
     } else if (float32_is_any_nan(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         RddV = ~0ULL;

Nor is this.

Actually, softfloat raises inexact instead of invalid. Is there a way to override?

Thanks,
Taylor

#31 lore raw

Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 1 line · Taylor Simpson

Actually, softfloat raises inexact instead of invalid. Is there a way to override?

Not true:

    switch (p.cls) {
    case float_class_snan:
    case float_class_qnan:
        s->float_exception_flags = orig_flags | float_flag_invalid;
        return max;

r~

#32 lore raw

RE: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 15 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, March 18, 2021 10:36 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 1 line · Taylor Simpson

Actually, softfloat raises inexact instead of invalid. Is there a way to

override?

Quoted 7 lines

Not true:

     switch (p.cls) {
     case float_class_snan:
     case float_class_qnan:
         s->float_exception_flags = orig_flags | float_flag_invalid;
         return max;

Sorry, I was mistaken. The difference is in the negative case.

    } else if (float32_is_neg(RsV)) {
        float_raise(float_flag_invalid, &env->fp_status);
        RddV = 0;

For many cases, this is what softfloat does. The difference comes when value is both negative and near zero (exponent is negative). Softfloat checks the exponent before checking the sign. round_to_int does this first

        if (a.exp < 0) {
            bool one;
            /* all fractional */
            s->float_exception_flags |= float_flag_inexact;
Then it sets
     a.cls = float_class_zero;
So round_to_uint_and_pack does this
    case float_class_zero:
        return 0;

Here's an example from float_convs

    from single: f32(-0x1.31f75000000000000000p-40:0xab98fba8)

Softfloat:to uint64: 0 (INEXACT )
Hexagon:to uint64: 0 (INVALID)

So, just looking at the float_convs tests the Hexagon version of f32->uint64 would be

    if (float32_is_neg(RsV) && !float32_is_any_nan(RsV)) {
        float_raise(float_flag_invalid, &env->fp_status);
        RddV = 0;
    } else {
        RddV = float32_to_uint64_round_to_zero(RsV, &env->fp_status);
    }

Thanks,
Taylor

#33 lore raw

Re: [PATCH v8 16/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions

Quoted 4 lines · Taylor Simpson

Here's an example from float_convs

     from single: f32(-0x1.31f75000000000000000p-40:0xab98fba8)

Softfloat:to uint64: 0 (INEXACT )
Hexagon:to uint64: 0 (INVALID)

Ahh, so an ieee conformance issue in hexagon -- failure to defer the sign check til after rounding.

Quoted 7 lines

So, just looking at the float_convs tests the Hexagon version of f32->uint64 would be

     if (float32_is_neg(RsV) && !float32_is_any_nan(RsV)) {
         float_raise(float_flag_invalid, &env->fp_status);
         RddV = 0;
     } else {
         RddV = float32_to_uint64_round_to_zero(RsV, &env->fp_status);
     }

Looks good. Just add a comment too.

r~

#34 lore raw

PATCH v8 17/35 Hexagon (target/hexagon/fma_emu.[ch]) utility functions

In reply to Taylor Simpson
---
 target/hexagon/fma_emu.h |  36 +++
 target/hexagon/fma_emu.c | 702 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 738 insertions(+)
 create mode 100644 target/hexagon/fma_emu.h
 create mode 100644 target/hexagon/fma_emu.c
target/hexagon/fma_emu.h new file +36 -0
new file mode 100644
index 0000000..e3b99a8
@@ -0,0 +1,36 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+static inline bool is_finite(float64 x)
+{
+    return !float64_is_any_nan(x) && !float64_is_infinity(x);
+}
+
+int32_t float64_getexp(float64 f64);
+int32_t float32_getexp(float32 f32);
+float32 infinite_float32(uint8_t sign);
+float32 internal_fmafx(float32 a, float32 b, float32 c,
+                       int scale, float_status *fp_status);
+float32 internal_mpyf(float32 a, float32 b, float_status *fp_status);
+float64 internal_mpyhh(float64 a, float64 b,
+                       unsigned long long int accumulated,
+                       float_status *fp_status);
+
+#endif
target/hexagon/fma_emu.c new file +702 -0

702 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 17/35
#35 lore raw

Re: [PATCH v8 17/35] Hexagon (target/hexagon/fma_emu.[ch]) utility functions

Quoted 7 lines · Taylor Simpson
---
 target/hexagon/fma_emu.h |  36 +++
 target/hexagon/fma_emu.c | 702 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 738 insertions(+)
 create mode 100644 target/hexagon/fma_emu.h
 create mode 100644 target/hexagon/fma_emu.c

I'm not a floating point specialist (Alex, Laurent, feel free to review on top), however this patch LGTM:

#36 lore raw

Re: [PATCH v8 17/35] Hexagon (target/hexagon/fma_emu.[ch]) utility functions

In reply to Taylor Simpson
Quoted 5 lines · Taylor Simpson
target/hexagon/fma_emu.c new file +5 -0
+#define DF_NAN         0xffffffffffffffffULL
+#define DF_INF         0x7ff0000000000000ULL
+#define DF_MINUS_INF   0xfff0000000000000ULL
+#define DF_MAXF        0x7fefffffffffffffULL
+#define DF_MINUS_MAXF  0xffefffffffffffffULL

...

target/hexagon/fma_emu.c line 40

Quoted 4 lines
target/hexagon/fma_emu.c new file +4 -0
+#define SF_INF         0x7f800000
+#define SF_MINUS_INF   0xff800000
+#define SF_MAXF        0x7f7fffff
+#define SF_MINUS_MAXF  0xff7fffff

Redundant with softfloat. Is the default nan really -1? I suppose then that hexagon does not distinguish QNaN from SNaN?

You'll want to patch fpu/softfloat-specialize.c.inc for both of these choices:
no_signaling_nans and parts_default_nan.

target/hexagon/fma_emu.c line 55

Quoted 9 lines
target/hexagon/fma_emu.c new file +9 -0
+typedef union {
+    double f;
+    uint64_t i;
+    struct {
+        uint64_t mant:52;
+        uint64_t exp:11;
+        uint64_t sign:1;
+    };
+} Double;

You cannot use a union with bitfields portably. This will fail on a big-endian host. Anyway, extracting these bits of a float are already present via softfloat.

Quoted 13 lines
target/hexagon/fma_emu.c new file +13 -0
+static inline Int128 int128_mul_6464(uint64_t ai, uint64_t bi)
+{
+    Int128 a, b;
+    uint64_t pp0, pp1a, pp1b, pp1s, pp2;
+
+    a = int128_make64(ai);
+    b = int128_make64(bi);
+    pp0 = (uint64_t)int128_getw0(a) * (uint64_t)int128_getw0(b);
+    pp1a = (uint64_t)int128_getw1(a) * (uint64_t)int128_getw0(b);
+    pp1b = (uint64_t)int128_getw1(b) * (uint64_t)int128_getw0(a);
+    pp2 = (uint64_t)int128_getw1(a) * (uint64_t)int128_getw1(b);
+
+    pp1s = pp1a + pp1b;

target/hexagon/fma_emu.c line 153

Quoted 10 lines
target/hexagon/fma_emu.c new file +10 -0
+    if ((pp1s < pp1a) || (pp1s < pp1b)) {
+        pp2 += (1ULL << 32);
+    }
+    uint64_t ret_low = pp0 + (pp1s << 32);
+    if ((ret_low < pp0) || (ret_low < (pp1s << 32))) {
+        pp2 += 1;
+    }
+
+    return int128_make128(ret_low, pp2 + (pp1s >> 32));
+}

This is duplicating code from include/fpu/softfloat-macros.h, except for the wrapping to Int128. That said, I don't think you should actually need this, or, frankly, the vast majority of the rest of your fp code.

target/hexagon/fma_emu.c line 171

Quoted 8 lines
target/hexagon/fma_emu.c new file +8 -0
+typedef struct {
+    Int128 mant;
+    int32_t exp;
+    uint8_t sign;
+    uint8_t guard;
+    uint8_t round;
+    uint8_t sticky;
+} Accum;

Um.. what? Why in the world would you split the 3 guard bits away from the rest of mant?

target/hexagon/fma_emu.c line 339

Quoted 9 lines
target/hexagon/fma_emu.c new file +9 -0
+/* Return an infinity with requested sign */
+static inline float64 infinite_float64(uint8_t sign)
+{
+    if (sign) {
+        return make_float64(DF_MINUS_INF);
+    } else {
+        return make_float64(DF_INF);
+    }
+}

Surely just float64_set_sign(float64_infinity, sign).

target/hexagon/fma_emu.c line 525

Quoted 4 lines
target/hexagon/fma_emu.c new file +4 -0
+static bool is_inf_prod(float64 a, float64 b)
+{
+    return ((float64_is_infinity(a) && float64_is_infinity(b)) ||
+            (float64_is_infinity(a) && is_finite(b) && (!float64_is_zero(b))) ||

This is always false, because is_finite excludes infinity.

target/hexagon/fma_emu.c line 601

Quoted 3 lines
target/hexagon/fma_emu.c new file +3 -0
+float32 internal_fmafx(float32 a, float32 b, float32 c, int scale,
+                       float_status *fp_status)
+{

Right. So, best I can figure, all of this support code that's re-implementing softfloat stuff is just so you can add "int scale" to floatXX_muladd.

Currently, we have a single bit to affect scaling of muladd (2**-1), for Arm. It would be easy to adjust the softfloat implementation to handle arbitrary scaling.

I would vastly prefer to do that than do this.

target/hexagon/fma_emu.c line 668

Quoted 3 lines
target/hexagon/fma_emu.c new file +3 -0
+float64 internal_mpyhh(float64 a, float64 b,
+                      unsigned long long int accumulated,
+                      float_status *fp_status)

I really don't understand what this is doing. Sadly, the hexagon manual doesn't bother to define some of its pseudocode functions, and this (dfmpyhh) is one of them.

r~

#37 lore raw

RE: [PATCH v8 17/35] Hexagon (target/hexagon/fma_emu.[ch]) utility functions

Quoted 11 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 5:15 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 17/35] Hexagon (target/hexagon/fma_emu.[ch]) utility functions

Quoted 7 lines

On 2/7/21 9:46 PM, Taylor Simpson wrote:

Redundant with softfloat. Is the default nan really -1? I suppose then that hexagon does not distinguish QNaN from SNaN?

You'll want to patch fpu/softfloat-specialize.c.inc for both of these choices:
no_signaling_nans and parts_default_nan.

Yes, the default is really -1. We do distinguish SNaN - when a SNaN is fed to an arithmetic operation, it raises the invalid flag and a QNaN is returned.

So, it looks like I'll need to patch parts_default_nan and parts_silence_nan as well as set default_nan_mode to 1.

Quoted 3 lines

This is duplicating code from include/fpu/softfloat-macros.h, except for the wrapping to Int128. That said, I don't think you should actually need this, or, frankly, the vast majority of the rest of your fp code.

OK, I will look into this.

Thanks,
Taylor

#38 lore raw

PATCH v8 18/35 Hexagon (target/hexagon/imported) arch import

In reply to Taylor Simpson

Imported from the Hexagon architecture library
imported/macros.def
The macro definitions specify instruction attributes that are applied to each instruction that references the macro. The generator will recursively apply attributes to each instruction that used the macro.
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 to generate various header files.
imported/encode*.def
Instruction encoding bit patterns for every instruction

---
 target/hexagon/imported/allidefs.def       |   30 +
 target/hexagon/imported/alu.idef           | 1258 +++++++++++++++++
 target/hexagon/imported/branch.idef        |  326 +++++
 target/hexagon/imported/compare.idef       |  619 ++++++++
 target/hexagon/imported/encode.def         |  124 ++
 target/hexagon/imported/encode_pp.def      | 2110 ++++++++++++++++++++++++++++
 target/hexagon/imported/encode_subinsn.def |  149 ++
 target/hexagon/imported/float.idef         |  312 ++++
 target/hexagon/imported/ldst.idef          |  286 ++++
 target/hexagon/imported/macros.def         | 1531 ++++++++++++++++++++
 target/hexagon/imported/mpy.idef           | 1208 ++++++++++++++++
 target/hexagon/imported/shift.idef         | 1066 ++++++++++++++
 target/hexagon/imported/subinsns.idef      |  149 ++
 target/hexagon/imported/system.idef        |   68 +
 14 files changed, 9236 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/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/ldst.idef
 create mode 100755 target/hexagon/imported/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
target/hexagon/imported/allidefs.def new file +30 -0
new file mode 100644
index 0000000..2aace29
@@ -0,0 +1,30 @@
+/*
+ *  Copyright(c) 2019-2021 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
+ */
+
+#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 +1258 -0

1,258 lines not on this page · raw message

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

326 lines not on this page · raw message

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

619 lines not on this page · raw message

target/hexagon/imported/encode.def new file +124 -0

124 lines not on this page · raw message

target/hexagon/imported/encode_pp.def new file +2110 -0

643 lines not on this page · raw message

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

149 lines not on this page · raw message

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

312 lines not on this page · raw message

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

286 lines not on this page · raw message

target/hexagon/imported/macros.def new file +1531 -0

1,531 lines not on this page · raw message

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

1,208 lines not on this page · raw message

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

1,066 lines not on this page · raw message

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

149 lines not on this page · raw message

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

68 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.

#39 lore raw

PATCH v8 19/35 Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics

In reply to Taylor Simpson

Run the C preprocessor across the instruction definition files and macro definition 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 | 88 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 target/hexagon/gen_semantics.c
target/hexagon/gen_semantics.c new file +88 -0
new file mode 100644
index 0000000..c5fccec
@@ -0,0 +1,88 @@
+/*
+ *  Copyright(c) 2019-2021 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;})
+ */
+#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+    do { \
+        fprintf(outfile, "SEMANTICS( \\\n" \
+                         "    \"%s\", \\\n" \
+                         "    %s, \\\n" \
+                         "    \"\"\"%s\"\"\" \\\n" \
+                         ")\n", \
+                #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \
+        fprintf(outfile, "ATTRIBUTES( \\\n" \
+                         "    \"%s\", \\\n" \
+                         "    \"%s\" \\\n" \
+                         ")\n", \
+                #TAG, STRINGIZE(ATTRIBS)); \
+    } while (0);
+#include "imported/allidefs.def"
+#undef Q6INSN
+
+/*
+ * Process the macro definitions
+ *     Macros definitions have the following form
+ *         DEF_MACRO(
+ *             fLSBNEW0,
+ *             predlog_read(thread,0),
+ *             ()
+ *         )
+ * 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, BEH, ATTRS) \
+    fprintf(outfile, "MACROATTRIB( \\\n" \
+                     "    \"%s\", \\\n" \
+                     "    \"\"\"%s\"\"\", \\\n" \
+                     "    \"%s\" \\\n" \
+                     ")\n", \
+            #MNAME, STRINGIZE(BEH), STRINGIZE(ATTRS));
+#include "imported/macros.def"
+#undef DEF_MACRO
+
+    fclose(outfile);
+    return 0;
+}
Signature · 1 line
2.7.4
Reviewed-by on v8 19/35
#40 lore raw

Re: [PATCH v8 19/35] Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics

Quoted 6 lines · Taylor Simpson

Run the C preprocessor across the instruction definition files and macro definition 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.

Quoted 6 lines
---
 target/hexagon/gen_semantics.c | 88 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 target/hexagon/gen_semantics.c

r~

#41 lore raw

PATCH v8 20/35 Hexagon (target/hexagon) generator phase 2 - generate header files

In reply to Taylor Simpson

Python scripts generate the following files
helper_protos_generated.h.inc
For each instruction we create DEF_HELPER function prototype
helper_funcs_generated.c.inc
For each instruction we create the helper function definition
tcg_funcs_generated.c.inc
For each instruction we create TCG code to generate call to helper
tcg_func_table_generated.c.inc
Table of function pointers indexed by opcode
shortcode_generated.h.inc
Generate a table of instruction "shortcode" semantics
opcodes_def_generated.h.inc
Gives a list of all the opcodes
op_attribs_generated.h.inc
Lists all the attributes associated with each instruction
op_regs_generated.h.inc
Lists the register and immediate operands for each instruction
printinsn_generated.h.inc
Data for printing (disassembling) each instruction (format string + operands)

---
 target/hexagon/gen_helper_funcs.py   | 220 ++++++++++++++++
 target/hexagon/gen_helper_protos.py  | 150 +++++++++++
 target/hexagon/gen_op_attribs.py     |  39 +++
 target/hexagon/gen_op_regs.py        | 110 ++++++++
 target/hexagon/gen_opcodes_def.py    |  36 +++
 target/hexagon/gen_printinsn.py      | 173 +++++++++++++
 target/hexagon/gen_shortcode.py      |  60 +++++
 target/hexagon/gen_tcg_func_table.py |  58 +++++
 target/hexagon/gen_tcg_funcs.py      | 485 +++++++++++++++++++++++++++++++++++
 target/hexagon/hex_common.py         | 234 +++++++++++++++++
 10 files changed, 1565 insertions(+)
 create mode 100755 target/hexagon/gen_helper_funcs.py
 create mode 100755 target/hexagon/gen_helper_protos.py
 create mode 100755 target/hexagon/gen_op_attribs.py
 create mode 100755 target/hexagon/gen_op_regs.py
 create mode 100755 target/hexagon/gen_opcodes_def.py
 create mode 100755 target/hexagon/gen_printinsn.py
 create mode 100755 target/hexagon/gen_shortcode.py
 create mode 100755 target/hexagon/gen_tcg_func_table.py
 create mode 100755 target/hexagon/gen_tcg_funcs.py
 create mode 100755 target/hexagon/hex_common.py
target/hexagon/gen_helper_funcs.py new file +220 -0
new file mode 100755
index 0000000..2b1c5d8
@@ -0,0 +1,220 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2021 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
+import hex_common
+
+##
+## Helpers for gen_helper_function
+##
+def gen_decl_ea(f):
+    f.write("    uint32_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,tag):
+    if (hex_common.is_pair(regid)):
+        gen_helper_arg_pair(f,regtype,regid,i)
+    elif (hex_common.is_single(regid)):
+        if hex_common.is_old_val(regtype, regid, tag):
+            gen_helper_arg(f,regtype,regid,i)
+        elif hex_common.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" % (hex_common.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 (hex_common.is_pair(regid)):
+        gen_helper_dest_decl_pair(f,regtype,regid,i)
+    elif (hex_common.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 (hex_common.is_pair(regid)):
+        gen_helper_return_pair(f,regtype,regid,i)
+    elif (hex_common.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:
+##       int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV)
+##       {
+##           uint32_t slot __attribute__(unused)) = 4;
+##           int32_t RdV = 0;
+##           { RdV=RsV+RtV;}
+##           COUNT_HELPER(A2_add);
+##           return RdV;
+##       }
+##
+def gen_helper_function(f, tag, tagregs, tagimms):
+    regs = tagregs[tag]
+    imms = tagimms[tag]
+
+    numresults = 0
+    numscalarresults = 0
+    numscalarreadwrite = 0
+    for regtype,regid,toss,numregs in regs:
+        if (hex_common.is_written(regid)):
+            numresults += 1
+            if (hex_common.is_scalar_reg(regtype)):
+                numscalarresults += 1
+        if (hex_common.is_readwrite(regid)):
+            if (hex_common.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 (hex_common.is_written(regid)):
+                if (hex_common.is_pair(regid)):
+                    gen_helper_return_type_pair(f,regtype,regid,i)
+                elif (hex_common.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 (hex_common.is_read(regid)):
+                gen_helper_arg_opn(f,regtype,regid,i,tag)
+                i += 1
+        for immlett,bits,immshift in imms:
+            gen_helper_arg_imm(f,immlett)
+            i += 1
+        if hex_common.need_slot(tag):
+            if i > 0: f.write(", ")
+            f.write("uint32_t slot")
+            i += 1
+        if hex_common.need_part1(tag):
+            if i > 0: f.write(", ")
+            f.write("uint32_t part1")
+        f.write(")\n{\n")
+        if (not hex_common.need_slot(tag)):
+            f.write("    uint32_t slot __attribute__((unused)) = 4;\n" )
+        if hex_common.need_ea(tag): gen_decl_ea(f)
+        ## Declare the return variable
+        i=0
+        for regtype,regid,toss,numregs in regs:
+            if (hex_common.is_writeonly(regid)):
+                gen_helper_dest_decl_opn(f,regtype,regid,i)
+            i += 1
+
+        if 'A_FPOP' in hex_common.attribdict[tag]:
+            f.write('    arch_fpop_start(env);\n');
+
+        f.write("    %s\n" % hex_common.semdict[tag])
+
+        if 'A_FPOP' in hex_common.attribdict[tag]:
+            f.write('    arch_fpop_end(env);\n');
+
+        ## Save/return the return variable
+        for regtype,regid,toss,numregs in regs:
+            if (hex_common.is_written(regid)):
+                gen_helper_return_opn(f, regtype, regid, i)
+        f.write("}\n\n")
+        ## End of the helper definition
+
+def main():
+    hex_common.read_semantics_file(sys.argv[1])
+    hex_common.read_attribs_file(sys.argv[2])
+    hex_common.read_overrides_file(sys.argv[3])
+    hex_common.calculate_attribs()
+    tagregs = hex_common.get_tagregs()
+    tagimms = hex_common.get_tagimms()
+
+    with open(sys.argv[4], 'w') as f:
+        for tag in hex_common.tags:
+            ## Skip the priv instructions
+            if ( "A_PRIV" in hex_common.attribdict[tag] ) :
+                continue
+            ## Skip the guest instructions
+            if ( "A_GUEST" in hex_common.attribdict[tag] ) :
+                continue
+            ## Skip the diag instructions
+            if ( tag == "Y6_diag" ) :
+                continue
+            if ( tag == "Y6_diag0" ) :
+                continue
+            if ( tag == "Y6_diag1" ) :
+                continue
+            if ( hex_common.skip_qemu_helper(tag) ):
+                continue
+
+            gen_helper_function(f, tag, tagregs, tagimms)
+
+if __name__ == "__main__":
+    main()
target/hexagon/gen_helper_protos.py new file +150 -0

150 lines not on this page · raw message

target/hexagon/gen_op_attribs.py new file +39 -0
new file mode 100755
index 0000000..6a1a1ca
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2021 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
+import hex_common
+
+def main():
+    hex_common.read_semantics_file(sys.argv[1])
+    hex_common.read_attribs_file(sys.argv[2])
+    hex_common.calculate_attribs()
+
+    ##
+    ##     Generate all the attributes associated with each instruction
+    ##
+    with open(sys.argv[3], 'w') as f:
+        for tag in hex_common.tags:
+            f.write('OP_ATTRIB(%s,ATTRIBS(%s))\n' % \
+                (tag, ','.join(sorted(hex_common.attribdict[tag]))))
+
+if __name__ == "__main__":
+    main()
target/hexagon/gen_op_regs.py new file +110 -0

110 lines not on this page · raw message

target/hexagon/gen_opcodes_def.py new file +36 -0
new file mode 100755
index 0000000..fa604a8
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2021 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
+import hex_common
+
+def main():
+    hex_common.read_semantics_file(sys.argv[1])
+
+    ##
+    ##     Generate a list of all the opcodes
+    ##
+    with open(sys.argv[3], 'w') as f:
+        for tag in hex_common.tags:
+            f.write ( "OPCODE(%s),\n" % (tag) )
+
+if __name__ == "__main__":
+    main()
target/hexagon/gen_printinsn.py new file +173 -0

173 lines not on this page · raw message

target/hexagon/gen_shortcode.py new file +60 -0

60 lines not on this page · raw message

target/hexagon/gen_tcg_func_table.py new file +58 -0

58 lines not on this page · raw message

target/hexagon/gen_tcg_funcs.py new file +485 -0

485 lines not on this page · raw message

target/hexagon/hex_common.py new file +234 -0

234 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 20/35
#42 lore raw

Re: [PATCH v8 20/35] Hexagon (target/hexagon) generator phase 2 - generate header files

Quoted 21 lines · Taylor Simpson

Python scripts generate the following files
helper_protos_generated.h.inc
For each instruction we create DEF_HELPER function prototype
helper_funcs_generated.c.inc
For each instruction we create the helper function definition
tcg_funcs_generated.c.inc
For each instruction we create TCG code to generate call to helper
tcg_func_table_generated.c.inc
Table of function pointers indexed by opcode
shortcode_generated.h.inc
Generate a table of instruction "shortcode" semantics
opcodes_def_generated.h.inc
Gives a list of all the opcodes
op_attribs_generated.h.inc
Lists all the attributes associated with each instruction
op_regs_generated.h.inc
Lists the register and immediate operands for each instruction
printinsn_generated.h.inc
Data for printing (disassembling) each instruction (format string + operands)

Quoted 2 lines

---

r~

#43 lore raw

PATCH v8 21/35 Hexagon (target/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 | 188 ++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)
 create mode 100644 target/hexagon/gen_dectree_import.c
target/hexagon/gen_dectree_import.c new file +188 -0
new file mode 100644
index 0000000..5b7ecfc
@@ -0,0 +1,188 @@
+/*
+ *  Copyright(c) 2019-2021 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 * const opcode_names[] = {
+#define OPCODE(IID) STRINGIZE(IID)
+#include "opcodes_def_generated.h.inc"
+    NULL
+#undef 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;})
+ */
+const char * const opcode_syntax[XX_LAST_OPCODE] = {
+#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+   [TAG] = BEH,
+#define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+   [TAG] = BEH,
+#include "imported/allidefs.def"
+#undef Q6INSN
+#undef EXTINSN
+};
+
+const char * const opcode_rregs[] = {
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
+#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)  /* nothing */
+#include "op_regs_generated.h.inc"
+    NULL
+#undef REGINFO
+#undef IMMINFO
+};
+
+const char * const opcode_wregs[] = {
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
+#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)  /* nothing */
+#include "op_regs_generated.h.inc"
+    NULL
+#undef REGINFO
+#undef IMMINFO
+};
+
+const OpcodeEncoding 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)
+{
+    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;
+    }
+
+    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
Reviewed-by on v8 21/35
#44 lore raw

Re: [PATCH v8 21/35] Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree

Quoted 10 lines · 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 | 188 ++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)
 create mode 100644 target/hexagon/gen_dectree_import.c

r~

#45 lore raw

PATCH v8 22/35 Hexagon (target/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 | 351 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 351 insertions(+)
 create mode 100755 target/hexagon/dectree.py
target/hexagon/dectree.py new file +351 -0
new file mode 100755
index 0000000..29467ec
@@ -0,0 +1,351 @@
+#!/usr/bin/env python3
+
+##
+##  Copyright(c) 2019-2021 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
+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__':
+    with open(sys.argv[1], 'w') as f:
+        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)
Signature · 1 line
2.7.4
Reviewed-by on v8 22/35
#46 lore raw

Re: [PATCH v8 22/35] Hexagon (target/hexagon) generater phase 4 - decode tree

Quoted 7 lines · Taylor Simpson

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

---
 target/hexagon/dectree.py | 351 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 351 insertions(+)
 create mode 100755 target/hexagon/dectree.py

r~

#47 lore raw

PATCH v8 23/35 Hexagon (target/hexagon) opcode data structures

In reply to Taylor Simpson
---
 target/hexagon/opcodes.h |  58 +++++++++++++++++++
 target/hexagon/opcodes.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 200 insertions(+)
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/opcodes.c
target/hexagon/opcodes.h new file +58 -0
new file mode 100644
index 0000000..6e90e00
@@ -0,0 +1,58 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+typedef enum {
+#define OPCODE(IID) IID
+#include "opcodes_def_generated.h.inc"
+    XX_LAST_OPCODE
+#undef OPCODE
+} Opcode;
+
+typedef enum {
+    NORMAL,
+    HALF,
+    SUBINSN_A,
+    SUBINSN_L1,
+    SUBINSN_L2,
+    SUBINSN_S1,
+    SUBINSN_S2,
+    EXT_noext,
+    EXT_mmvec,
+    XX_LAST_ENC_CLASS
+} EncClass;
+
+extern const char * const opcode_names[];
+
+extern const char * const opcode_reginfo[];
+extern const char * const opcode_rregs[];
+extern const char * const opcode_wregs[];
+
+typedef struct {
+    const char * const encoding;
+    const EncClass enc_class;
+} OpcodeEncoding;
+
+extern const OpcodeEncoding opcode_encodings[XX_LAST_OPCODE];
+
+void opcode_init(void);
+
+int opcode_which_immediate_is_extended(Opcode opcode);
+
+#endif
target/hexagon/opcodes.c new file +142 -0

142 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 23/35
#48 lore raw

Re: [PATCH v8 23/35] Hexagon (target/hexagon) opcode data structures

Quoted 7 lines · Taylor Simpson
---
 target/hexagon/opcodes.h |  58 +++++++++++++++++++
 target/hexagon/opcodes.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 200 insertions(+)
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/opcodes.c
Reviewed-by on v8 23/35
#49 lore raw

Re: [PATCH v8 23/35] Hexagon (target/hexagon) opcode data structures

In reply to Taylor Simpson
Quoted 7 lines · Taylor Simpson
---
 target/hexagon/opcodes.h |  58 +++++++++++++++++++
 target/hexagon/opcodes.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 200 insertions(+)
 create mode 100644 target/hexagon/opcodes.h
 create mode 100644 target/hexagon/opcodes.c

r~

#50 lore raw

PATCH v8 24/35 Hexagon (target/hexagon) macros

In reply to Taylor Simpson

macros to interface with the generator
macros referenced in instruction semantics

---
 target/hexagon/macros.h | 592 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 592 insertions(+)
 create mode 100644 target/hexagon/macros.h
target/hexagon/macros.h new file +592 -0
new file mode 100644
index 0000000..78c4efb
@@ -0,0 +1,592 @@
+/*
+ *  Copyright(c) 2019-2021 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 READ_REG(dest, NUM)              gen_read_reg(dest, NUM)
+#define READ_PREG(dest, NUM)             gen_read_preg(dest, (NUM))
+#else
+#define READ_REG(NUM)                    (env->gpr[(NUM)])
+#define READ_PREG(NUM)                   (env->pred[NUM])
+
+#define WRITE_RREG(NUM, VAL)             log_reg_write(env, NUM, VAL, slot)
+#define WRITE_PREG(NUM, VAL)             log_pred_write(env, 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 TYPE_INT(X)          __builtin_types_compatible_p(typeof(X), int)
+#define TYPE_TCGV(X)         __builtin_types_compatible_p(typeof(X), TCGv)
+#define TYPE_TCGV_I64(X)     __builtin_types_compatible_p(typeof(X), TCGv_i64)
+
+#define SET_USR_FIELD_FUNC(X) \
+    __builtin_choose_expr(TYPE_INT(X), \
+        gen_set_usr_fieldi, \
+        __builtin_choose_expr(TYPE_TCGV(X), \
+            gen_set_usr_field, (void)0))
+#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
+/*
+ * Section 5.5 of the Hexagon V67 Programmer's Reference Manual
+ *
+ * Slot 1 store with slot 0 load
+ * A slot 1 store operation with a slot 0 load operation can appear in a packet.
+ * The packet attribute :mem_noshuf inhibits the instruction reordering that
+ * would otherwise be done by the assembler. For example:
+ *     {
+ *         memw(R5) = R2 // slot 1 store
+ *         R3 = memh(R6) // slot 0 load
+ *     }:mem_noshuf
+ * Unlike most packetized operations, these memory operations are not executed
+ * in parallel (Section 3.3.1). Instead, the store instruction in Slot 1
+ * effectively executes first, followed by the load instruction in Slot 0. If
+ * the addresses of the two operations are overlapping, the load will receive
+ * the newly stored data. This feature is supported in processor versions
+ * V65 or greater.
+ *
+ *
+ * For qemu, we look for a load in slot 0 when there is  a store in slot 1
+ * in the same packet.  When we see this, we call a helper that merges the
+ * bytes from the store buffer with the value loaded from memory.
+ */
+#define CHECK_NOSHUF \
+    do { \
+        if (insn->slot == 0 && pkt->pkt_has_store_s1) { \
+            process_store(ctx, pkt, 1); \
+        } \
+    } while (0)
+
+#define MEM_LOAD1s(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld8s(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD1u(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld8u(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD2s(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld16s(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD2u(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld16u(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD4s(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD4u(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \
+    } while (0)
+#define MEM_LOAD8u(DST, VA) \
+    do { \
+        CHECK_NOSHUF; \
+        tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx); \
+    } while (0)
+#else
+#define MEM_LOAD1s(VA) ((int8_t)mem_load1(env, slot, VA))
+#define MEM_LOAD1u(VA) ((uint8_t)mem_load1(env, slot, VA))
+#define MEM_LOAD2s(VA) ((int16_t)mem_load2(env, slot, VA))
+#define MEM_LOAD2u(VA) ((uint16_t)mem_load2(env, slot, VA))
+#define MEM_LOAD4s(VA) ((int32_t)mem_load4(env, slot, VA))
+#define MEM_LOAD4u(VA) ((uint32_t)mem_load4(env, slot, VA))
+#define MEM_LOAD8s(VA) ((int64_t)mem_load8(env, slot, VA))
+#define MEM_LOAD8u(VA) ((uint64_t)mem_load8(env, slot, 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
+
+#define CANCEL cancel_slot(env, slot)
+
+#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)
+#endif
+
+#define STORE_CANCEL(EA) { env->slot_cancelled |= (1 << slot); }
+
+#define fMAX(A, B) (((A) > (B)) ? (A) : (B))
+
+#define fMIN(A, B) (((A) < (B)) ? (A) : (B))
+
+#define fABS(A) (((A) < 0) ? (-(A)) : (A))
+#define fINSERT_BITS(REG, WIDTH, OFFSET, INVAL) \
+    REG = ((WIDTH) ? deposit64(REG, (OFFSET), (WIDTH), (INVAL)) : REG)
+#define fEXTRACTU_BITS(INREG, WIDTH, OFFSET) \
+    ((WIDTH) ? extract64((INREG), (OFFSET), (WIDTH)) : 0LL)
+#define fEXTRACTU_BIDIR(INREG, WIDTH, OFFSET) \
+    (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8)))
+#define fEXTRACTU_RANGE(INREG, HIBIT, LOWBIT) \
+    (((HIBIT) - (LOWBIT) + 1) ? \
+        extract64((INREG), (LOWBIT), ((HIBIT) - (LOWBIT) + 1)) : \
+        0LL)
+
+#define f8BITSOF(VAL) ((VAL) ? 0xff : 0x00)
+
+#ifdef QEMU_GENERATE
+#define fLSBOLD(VAL) tcg_gen_andi_tl(LSB, (VAL), 1)
+#else
+#define fLSBOLD(VAL)  ((VAL) & 1)
+#endif
+
+#ifdef QEMU_GENERATE
+#define fLSBNEW(PVAL)   tcg_gen_mov_tl(LSB, (PVAL))
+#define fLSBNEW0        tcg_gen_mov_tl(LSB, hex_new_pred_value[0])
+#define fLSBNEW1        tcg_gen_mov_tl(LSB, hex_new_pred_value[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))
+#else
+#define fLSBNEWNOT(PNUM) (!fLSBNEW(PNUM))
+#define fLSBOLDNOT(VAL) (!fLSBOLD(VAL))
+#define fLSBNEW0NOT (!fLSBNEW0)
+#define fLSBNEW1NOT (!fLSBNEW1)
+#endif
+
+#define fNEWREG(VAL) ((int32_t)(VAL))
+
+#define fNEWREG_ST(VAL) (VAL)
+
+#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 fZXTN(N, M, VAL) (((N) != 0) ? extract64((VAL), 0, (N)) : 0LL)
+#define fSXTN(N, M, VAL) (((N) != 0) ? sextract64((VAL), 0, (N)) : 0LL)
+#define fSATN(N, VAL) \
+    ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATVALN(N, VAL))
+#define fADDSAT64(DST, A, B) \
+    do { \
+        uint64_t __a = fCAST8u(A); \
+        uint64_t __b = fCAST8u(B); \
+        uint64_t __sum = __a + __b; \
+        uint64_t __xor = __a ^ __b; \
+        const uint64_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 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 fSATUB(VAL) (fSATUN(8, VAL))
+#define fSATB(VAL) (fSATN(8, VAL))
+#define fIMMEXT(IMM) (IMM = IMM)
+#define fMUST_IMMEXT(IMM) fIMMEXT(IMM)
+
+#define fPCALIGN(IMM) IMM = (IMM & ~PCALIGN_MASK)
+
+#define fREAD_LR() (READ_REG(HEX_REG_LR))
+
+#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 fREAD_SP() (READ_REG(HEX_REG_SP))
+#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))
+#ifdef FIXME
+/* Figure out how to get insn->extension_valid to helper */
+#define fREAD_GP() \
+    (insn->extension_valid ? 0 : READ_REG(HEX_REG_GP))
+#else
+#define fREAD_GP() READ_REG(HEX_REG_GP)
+#endif
+#define fREAD_PC() (READ_REG(HEX_REG_PC))
+
+#define fREAD_NPC() (env->next_PC & (0xfffffffe))
+
+#define fREAD_P0() (READ_PREG(0))
+#define fREAD_P3() (READ_PREG(3))
+
+#define fCHECK_PCALIGN(A)
+
+#define fWRITE_NPC(A) write_new_pc(env, A)
+
+#define fBRANCH(LOC, TYPE)          fWRITE_NPC(LOC)
+#define fJUMPR(REGNO, TARGET, TYPE) fBRANCH(TARGET, COF_TYPE_JUMPR)
+#define fHINTJR(TARGET) { /* Not modelled in qemu */}
+#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)
+
+#define fCARRY_FROM_ADD(A, B, C) carry_from_add64(A, B, C)
+
+#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 fPART1(WORK) if (part1) { WORK; return; }
+#define fCAST4u(A) ((uint32_t)(A))
+#define fCAST4s(A) ((int32_t)(A))
+#define fCAST8u(A) ((uint64_t)(A))
+#define fCAST8s(A) ((int64_t)(A))
+#define fCAST4_4s(A) ((int32_t)(A))
+#define fCAST4_4u(A) ((uint32_t)(A))
+#define fCAST4_8s(A) ((int64_t)((int32_t)(A)))
+#define fCAST4_8u(A) ((uint64_t)((uint32_t)(A)))
+#define fCAST8_8s(A) ((int64_t)(A))
+#define fCAST8_8u(A) ((uint64_t)(A))
+#define fCAST2_8s(A) ((int64_t)((int16_t)(A)))
+#define fCAST2_8u(A) ((uint64_t)((uint16_t)(A)))
+#define fZE8_16(A) ((int16_t)((uint8_t)(A)))
+#define fSE8_16(A) ((int16_t)((int8_t)(A)))
+#define fSE16_32(A) ((int32_t)((int16_t)(A)))
+#define fZE16_32(A) ((uint32_t)((uint16_t)(A)))
+#define fSE32_64(A) ((int64_t)((int32_t)(A)))
+#define fZE32_64(A) ((uint64_t)((uint32_t)(A)))
+#define fSE8_32(A) ((int32_t)((int8_t)(A)))
+#define fZE8_32(A) ((int32_t)((uint8_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 { \
+        int32_t maxv = (1 << U) - 1; \
+        int32_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 fADD128(A, B) (int128_add(A, B))
+#define fSUB128(A, B) (int128_sub(A, B))
+#define fSHIFTR128(A, B) (int128_rshift(A, B))
+#define fSHIFTL128(A, B) (int128_lshift(A, B))
+#define fAND128(A, B) (int128_and(A, B))
+#define fCAST8S_16S(A) (int128_exts64(A))
+#define fCAST16S_8S(A) (int128_getlo(A))
+
+#define fEA_RI(REG, IMM) \
+    do { \
+        EA = REG + IMM; \
+    } while (0)
+#define fEA_RRs(REG, REG2, SCALE) \
+    do { \
+        EA = REG + (REG2 << SCALE); \
+    } while (0)
+#define fEA_IRs(IMM, REG, SCALE) \
+    do { \
+        EA = IMM + (REG << SCALE); \
+    } while (0)
+
+#ifdef QEMU_GENERATE
+#define fEA_IMM(IMM) tcg_gen_movi_tl(EA, IMM)
+#define fEA_REG(REG) tcg_gen_mov_tl(EA, REG)
+#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)        do { EA = (IMM); } while (0)
+#define fEA_REG(REG)        do { EA = (REG); } while (0)
+#define fEA_GPI(IMM)        do { EA = (fREAD_GP() + (IMM)); } while (0)
+#define fPM_I(REG, IMM)     do { REG = REG + (IMM); } while (0)
+#define fPM_M(REG, MVAL)    do { REG = REG + (MVAL); } while (0)
+#endif
+#define fSCALE(N, A) (((int64_t)(A)) << N)
+#define fSATW(A) fSATN(32, ((long long)A))
+#define fSAT(A) fSATN(32, (A))
+#define fSAT_ORIG_SHL(A, ORIG_REG) \
+    ((((int32_t)((fSAT(A)) ^ ((int32_t)(ORIG_REG)))) < 0) \
+        ? fSATVALN(32, ((int32_t)(ORIG_REG))) \
+        : ((((ORIG_REG) > 0) && ((A) == 0)) ? fSATVALN(32, (ORIG_REG)) \
+                                            : fSAT(A)))
+#define fPASS(A) A
+#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)))
+#define fASHIFTR(SRC, SHAMT, REGSTYPE) (fCAST##REGSTYPE##s(SRC) >> (SHAMT))
+#define fLSHIFTR(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##u(SRC) >> (SHAMT)))
+#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))))))
+#define fASHIFTL(SRC, SHAMT, REGSTYPE) \
+    (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##s(SRC) << (SHAMT)))
+
+#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)
+
+#define fGET_FRAMEKEY() READ_REG(HEX_REG_FRAMEKEY)
+#define fFRAME_SCRAMBLE(VAL) ((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32))
+#define fFRAME_UNSCRAMBLE(VAL) fFRAME_SCRAMBLE(VAL)
+
+#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);
+#endif
+
+#define fSTORE(NUM, SIZE, EA, SRC) MEM_STORE##SIZE(EA, SRC, slot)
+
+#ifdef QEMU_GENERATE
+#define fSTORE_LOCKED(NUM, SIZE, EA, SRC, PRED) \
+    gen_store_conditional##SIZE(env, ctx, PdN, PRED, EA, SRC);
+#endif
+
+#define fGETBYTE(N, SRC) ((int8_t)((SRC >> ((N) * 8)) & 0xff))
+#define fGETUBYTE(N, SRC) ((uint8_t)((SRC >> ((N) * 8)) & 0xff))
+
+#define fSETBYTE(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffLL << ((N) * 8))) | \
+        (((uint64_t)((VAL) & 0x0ffLL)) << ((N) * 8)); \
+    } while (0)
+#define fGETHALF(N, SRC) ((int16_t)((SRC >> ((N) * 16)) & 0xffff))
+#define fGETUHALF(N, SRC) ((uint16_t)((SRC >> ((N) * 16)) & 0xffff))
+#define fSETHALF(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffffLL << ((N) * 16))) | \
+        (((uint64_t)((VAL) & 0x0ffff)) << ((N) * 16)); \
+    } while (0)
+#define fSETHALFw fSETHALF
+#define fSETHALFd fSETHALF
+
+#define fGETWORD(N, SRC) \
+    ((int64_t)((int32_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL)))
+#define fGETUWORD(N, SRC) \
+    ((uint64_t)((uint32_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL)))
+
+#define fSETWORD(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(0x0ffffffffLL << ((N) * 32))) | \
+              (((VAL) & 0x0ffffffffLL) << ((N) * 32)); \
+    } while (0)
+
+#define fSETBIT(N, DST, VAL) \
+    do { \
+        DST = (DST & ~(1ULL << (N))) | (((uint64_t)(VAL)) << (N)); \
+    } while (0)
+
+#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_4(VAL) ctpop32(VAL)
+#define fCOUNTONES_8(VAL) ctpop64(VAL)
+#define fBREV_8(VAL) revbit64(VAL)
+#define fBREV_4(VAL) revbit32(VAL)
+#define fCL1_8(VAL) clo64(VAL)
+#define fCL1_4(VAL) clo32(VAL)
+#define fINTERLEAVE(ODD, EVEN) interleave(ODD, EVEN)
+#define fDEINTERLEAVE(MIXED) deinterleave(MIXED)
+#define fHIDE(A) A
+#define fCONSTLL(A) A##LL
+#define fECHO(A) (A)
+
+#define fTRAP(TRAPTYPE, IMM) helper_raise_exception(env, HEX_EXCP_TRAP0)
+#define fPAUSE(IMM)
+
+#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 fREAD_REG_FIELD(REG, FIELD) \
+    fEXTRACTU_BITS(env->gpr[HEX_REG_##REG], \
+                   reg_field_info[FIELD].width, \
+                   reg_field_info[FIELD].offset)
+#define fGET_FIELD(VAL, FIELD)
+#define fSET_FIELD(VAL, FIELD, NEWVAL)
+#define fBARRIER()
+#define fSYNCH()
+#define fISYNC()
+#define fDCFETCH(REG) \
+    do { (void)REG; } while (0) /* Nothing to do in qemu */
+#define fICINVA(REG) \
+    do { (void)REG; } while (0) /* Nothing to do in qemu */
+#define fL2FETCH(ADDR, HEIGHT, WIDTH, STRIDE, FLAGS)
+#define fDCCLEANA(REG) \
+    do { (void)REG; } while (0) /* Nothing to do in qemu */
+#define fDCCLEANINVA(REG) \
+    do { (void)REG; } while (0) /* Nothing to do in qemu */
+
+#define fDCZEROA(REG) do { env->dczero_addr = (REG); } while (0)
+
+#define fBRANCH_SPECULATE_STALL(DOTNEWVAL, JUMP_COND, SPEC_DIR, HINTBITNUM, \
+                                STRBITNUM) /* Nothing */
+
+
+#endif
Signature · 1 line
2.7.4
Reviewed-by on v8 24/35
#51 lore raw

Re: [PATCH v8 24/35] Hexagon (target/hexagon) macros

Quoted 8 lines · Taylor Simpson

macros to interface with the generator
macros referenced in instruction semantics

---
 target/hexagon/macros.h | 592 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 592 insertions(+)
 create mode 100644 target/hexagon/macros.h

r~

#52 lore raw

PATCH v8 25/35 Hexagon (target/hexagon) instruction classes

In reply to Taylor Simpson

Determine legal VLIW slots for each instruction

---
 target/hexagon/iclass.h            | 50 ++++++++++++++++++++++++++
 target/hexagon/iclass.c            | 73 ++++++++++++++++++++++++++++++++++++++
 target/hexagon/imported/iclass.def | 51 ++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 target/hexagon/iclass.h
 create mode 100644 target/hexagon/iclass.c
 create mode 100644 target/hexagon/imported/iclass.def
target/hexagon/iclass.h new file +50 -0
new file mode 100644
index 0000000..78d3726
@@ -0,0 +1,50 @@
+/*
+ *  Copyright(c) 2019-2021 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 "attribs.h"
+
+#define ICLASS_FROM_TYPE(TYPE) ICLASS_##TYPE
+
+enum {
+
+#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS)    ICLASS_FROM_TYPE(TYPE),
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS)    ICLASS_FROM_TYPE(TYPE),
+#include "imported/iclass.def"
+#undef DEF_PP_ICLASS32
+#undef DEF_EE_ICLASS32
+
+    ICLASS_FROM_TYPE(COPROC_VX),
+    ICLASS_FROM_TYPE(COPROC_VMEM),
+    NUM_ICLASSES
+};
+
+typedef enum {
+    SLOTS_0          = (1 << 0),
+    SLOTS_1          = (1 << 1),
+    SLOTS_2          = (1 << 2),
+    SLOTS_3          = (1 << 3),
+    SLOTS_01         = SLOTS_0 | SLOTS_1,
+    SLOTS_23         = SLOTS_2 | SLOTS_3,
+    SLOTS_0123       = SLOTS_0 | SLOTS_1 | SLOTS_2 | SLOTS_3,
+} SlotMask;
+
+SlotMask find_iclass_slots(Opcode opcode, int itype);
+
+#endif
target/hexagon/iclass.c new file +73 -0

73 lines not on this page · raw message

target/hexagon/imported/iclass.def new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v8 25/35
#53 lore raw

Re: [PATCH v8 25/35] Hexagon (target/hexagon) instruction classes

target/hexagon/iclass.c line 59

Quoted 4 lines · Taylor Simpson
target/hexagon/iclass.c new file +4 -0
+    } else if ((itype == ICLASS_V2LDST) && (GET_ATTRIB(opcode, A_STORE))) {
+        return SLOTS_01;
+    } else if ((itype == ICLASS_V2LDST) && (!GET_ATTRIB(opcode, A_STORE))) {
+        return SLOTS_01;

What's the point of this? Between the two all ICLASS_V2LDST use SLOTS_01. Why can't it be done in

Quoted 1 line

+ return iclass_info[itype];

here?

Otherwise,

r~

#54 lore raw

RE: [PATCH v8 25/35] Hexagon (target/hexagon) instruction classes

Quoted 13 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 5:41 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 25/35] Hexagon (target/hexagon) instruction classes

Quoted 1 line · Taylor Simpson

+ } else if ((itype == ICLASS_V2LDST) && (GET_ATTRIB(opcode,

A_STORE))) {

Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+        return SLOTS_01;
+    } else if ((itype == ICLASS_V2LDST) && (!GET_ATTRIB(opcode,

A_STORE))) {

Quoted 1 line

+ return SLOTS_01;

What's the point of this? Between the two all ICLASS_V2LDST use SLOTS_01. Why
can't it be done in

Quoted 1 line

+ return iclass_info[itype];

Good catch - I'll eliminate the unnecessary checks.

#55 lore raw

PATCH v8 26/35 Hexagon (target/hexagon) TCG generation

In reply to Taylor Simpson

Include the generated files and set up the data structures

---
 target/hexagon/genptr.h |  25 ++++
 target/hexagon/genptr.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 356 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..c158005
@@ -0,0 +1,25 @@
+/*
+ *  Copyright(c) 2019-2021 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 const SemanticInsn opcode_genptr[];
+
+#endif
target/hexagon/genptr.c new file +331 -0

331 lines not on this page · raw message

Signature · 1 line
2.7.4
#56 lore raw

Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Hi Taylor,

Quoted 55 lines · Taylor Simpson

Include the generated files and set up the data structures

---
 target/hexagon/genptr.h |  25 ++++
 target/hexagon/genptr.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 356 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..c158005
@@ -0,0 +1,25 @@
+/*
+ *  Copyright(c) 2019-2021 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 const SemanticInsn opcode_genptr[];
+
+#endif
target/hexagon/genptr.c new file +8 -0
new file mode 100644
index 0000000..7481f4c
@@ -0,0 +1,331 @@
+/*
+ *  Copyright(c) 2019-2021 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.
+ *

target/hexagon/genptr.c line 18

Quoted 10 lines
target/hexagon/genptr.c new file +10 -0
+ *  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 QEMU_GENERATE

Maybe move this ...

target/hexagon/genptr.c line 26

Quoted 8 lines
target/hexagon/genptr.c new file +8 -0
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "cpu.h"
+#include "internal.h"
+#include "tcg/tcg-op.h"
+#include "insn.h"
+#include "opcodes.h"
+#include "translate.h"

... here with a comment:

#define QEMU_GENERATE /* Used internally by macros.h */

target/hexagon/genptr.c line 27

Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+#include "macros.h"

and undef?

#undef QEMU_GENERATE

Quoted 8 lines
target/hexagon/genptr.c new file +8 -0
+#include "gen_tcg.h"
+
+static inline TCGv gen_read_preg(TCGv pred, uint8_t num)
+{
+    tcg_gen_mov_tl(pred, hex_pred[num]);
+    return pred;
+}
+

target/hexagon/genptr.c line 45

Quoted 10 lines
target/hexagon/genptr.c new file +10 -0
+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int slot)
+{
+    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

Can you declare an 'bool hexagon_debug_enabled(void);' eventually inlined, so we can get this code compiled (to avoid bitroting) using

  if (hexagon_debug_enabled()) {

target/hexagon/genptr.c line 48

Quoted 3 lines
target/hexagon/genptr.c new file +3 -0
+    /* 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]);
  }

target/hexagon/genptr.c line 54

Quoted 6 lines
target/hexagon/genptr.c new file +6 -0
+#endif
+
+    tcg_temp_free(one);
+    tcg_temp_free(zero);
+    tcg_temp_free(slot_mask);
+}

Otherwise looks good.

Regards,

Phil.

#57 lore raw

RE: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 47 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Thursday, February 11, 2021 6:23 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Hi Taylor,

Quoted 6 lines · Taylor Simpson

Include the generated files and set up the data structures

---
 target/hexagon/genptr.h |  25 ++++
 target/hexagon/genptr.c | 331

++++++++++++++++++++++++++++++++++++++++++++++++

target/hexagon/genptr.c line 2

Quoted 12 lines
 2 files changed, 356 insertions(+)
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/genptr.c
target/hexagon/genptr.c new file +2 -0
new file mode 100644
index 0000000..7481f4c
@@ -0,0 +1,331 @@
+
+#define QEMU_GENERATE

Maybe move this ...

target/hexagon/genptr.c line 26

Quoted 8 lines
target/hexagon/genptr.c new file +8 -0
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "cpu.h"
+#include "internal.h"
+#include "tcg/tcg-op.h"
+#include "insn.h"
+#include "opcodes.h"
+#include "translate.h"

... here with a comment:

Quoted 7 lines

#define QEMU_GENERATE /* Used internally by macros.h */

target/hexagon/genptr.c line 27

Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+#include "macros.h"

and undef?

#undef QEMU_GENERATE

OK

Quoted 24 lines

target/hexagon/genptr.c

Quoted 9 lines
target/hexagon/genptr.c new file +9 -0
+#include "gen_tcg.h"
+
+static inline TCGv gen_read_preg(TCGv pred, uint8_t num)
+{
+    tcg_gen_mov_tl(pred, hex_pred[num]);
+    return pred;
+}
+
+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int

slot)

target/hexagon/genptr.c

Quoted 7 lines
target/hexagon/genptr.c new file +7 -0
+{
+    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,

target/hexagon/genptr.c line 29

Quoted 2 lines
target/hexagon/genptr.c new file +2 -0
+                           val, hex_new_value[rnum]);
+#if HEX_DEBUG

Can you declare an 'bool hexagon_debug_enabled(void);' eventually inlined, so we can get this code compiled (to avoid bitroting) using

Quoted 10 lines
  if (hexagon_debug_enabled()) {

target/hexagon/genptr.c line 31

Quoted 2 lines
target/hexagon/genptr.c new file +2 -0
+    /* Do this so HELPER(debug_commit_end) will know */
+    tcg_gen_movcond_tl(TCG_COND_EQ, hex_reg_written[rnum],

slot_mask, zero,

target/hexagon/genptr.c line 32

Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+                       one, hex_reg_written[rnum]);
  }
Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+#endif

Do we really need a function? Why not change

#if HEX_DEBUG
    ...

#endif

to

if (HEX_DEBUG) {
    ...
}

Thanks,
Taylor

#58 lore raw

Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 94 lines · Taylor Simpson
Quoted 45 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Thursday, February 11, 2021 6:23 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Hi Taylor,

Quoted 6 lines · Taylor Simpson

Include the generated files and set up the data structures

---
 target/hexagon/genptr.h |  25 ++++
 target/hexagon/genptr.c | 331

++++++++++++++++++++++++++++++++++++++++++++++++

target/hexagon/genptr.c line 2

Quoted 12 lines
 2 files changed, 356 insertions(+)
 create mode 100644 target/hexagon/genptr.h
 create mode 100644 target/hexagon/genptr.c
target/hexagon/genptr.c new file +2 -0
new file mode 100644
index 0000000..7481f4c
@@ -0,0 +1,331 @@
+
+#define QEMU_GENERATE

Maybe move this ...

target/hexagon/genptr.c line 26

Quoted 8 lines
target/hexagon/genptr.c new file +8 -0
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "cpu.h"
+#include "internal.h"
+#include "tcg/tcg-op.h"
+#include "insn.h"
+#include "opcodes.h"
+#include "translate.h"

... here with a comment:

Quoted 7 lines

#define QEMU_GENERATE /* Used internally by macros.h */

target/hexagon/genptr.c line 27

Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+#include "macros.h"

and undef?

#undef QEMU_GENERATE

OK

Quoted 24 lines

target/hexagon/genptr.c

Quoted 9 lines
target/hexagon/genptr.c new file +9 -0
+#include "gen_tcg.h"
+
+static inline TCGv gen_read_preg(TCGv pred, uint8_t num)
+{
+    tcg_gen_mov_tl(pred, hex_pred[num]);
+    return pred;
+}
+
+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int

slot)

target/hexagon/genptr.c

Quoted 7 lines
target/hexagon/genptr.c new file +7 -0
+{
+    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,

target/hexagon/genptr.c line 29

Quoted 2 lines
target/hexagon/genptr.c new file +2 -0
+                           val, hex_new_value[rnum]);
+#if HEX_DEBUG

Can you declare an 'bool hexagon_debug_enabled(void);' eventually inlined, so we can get this code compiled (to avoid bitroting) using

Quoted 10 lines
  if (hexagon_debug_enabled()) {

target/hexagon/genptr.c line 31

Quoted 2 lines
target/hexagon/genptr.c new file +2 -0
+    /* Do this so HELPER(debug_commit_end) will know */
+    tcg_gen_movcond_tl(TCG_COND_EQ, hex_reg_written[rnum],

slot_mask, zero,

target/hexagon/genptr.c line 32

Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+                       one, hex_reg_written[rnum]);
  }
Quoted 1 line
target/hexagon/genptr.c new file +1 -0
+#endif

Do we really need a function? Why not change

#if HEX_DEBUG
    ...
Quoted 7 lines

#endif

to

if (HEX_DEBUG) {
    ...
}

You can go the whole hog and wrap everything up to minimise the chance of functional changes in your debug legs in the main code, e.g.:

  #define tlb_debug(fmt, ...) do { \
      if (DEBUG_TLB_LOG_GATE) { \
          qemu_log_mask(CPU_LOG_MMU, "%s: " fmt, __func__, \
                        ## __VA_ARGS__); \
      } else if (DEBUG_TLB_GATE) { \
          fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \
      } \
  } while (0)

Then a statement like:

  tlb_debug("mmu_idx:0x%04" PRIx16 "\n", asked);

is unambiguously:

- obviously a debug statement
- always compiled, hence no bit rot
- optimises away when gates are 0
- doesn't accidentally include changes in behaviour

Quoted 4 lines

Thanks,
Taylor

Signature · 1 line
Alex Bennée
#59 lore raw

RE: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 78 lines

-----Original Message-----
From: Alex Bennée <[email protected]>
Sent: Tuesday, April 6, 2021 4:20 AM
To: Taylor Simpson <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 43 lines · Taylor Simpson
Quoted 29 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Thursday, February 11, 2021 6:23 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 6 lines
target/hexagon/genptr.c new file +6 -0
+static inline TCGv gen_read_preg(TCGv pred, uint8_t num)
+{
+    tcg_gen_mov_tl(pred, hex_pred[num]);
+    return pred;
+}
+

target/hexagon/genptr.c line 45

Quoted 10 lines
target/hexagon/genptr.c new file +10 -0
+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int slot)
+{
+    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

Can you declare an 'bool hexagon_debug_enabled(void);' eventually inlined, so we can get this code compiled (to avoid bitroting) using

Quoted 9 lines
  if (hexagon_debug_enabled()) {

target/hexagon/genptr.c line 48

Quoted 3 lines
target/hexagon/genptr.c new file +3 -0
+    /* 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]);
  }
Quoted 1 line

+#endif

Do we really need a function? Why not change

#if HEX_DEBUG
    ...
Quoted 7 lines

#endif

to

if (HEX_DEBUG) {
    ...
}

You can go the whole hog and wrap everything up to minimise the chance of functional changes in your debug legs in the main code, e.g.:

  #define tlb_debug(fmt, ...) do { \
      if (DEBUG_TLB_LOG_GATE) { \
          qemu_log_mask(CPU_LOG_MMU, "%s: " fmt, __func__, \
                        ## __VA_ARGS__); \
      } else if (DEBUG_TLB_GATE) { \
          fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \
      } \
  } while (0)

Then a statement like:

Quoted 8 lines
  tlb_debug("mmu_idx:0x%04" PRIx16 "\n", asked);

is unambiguously:

- obviously a debug statement
- always compiled, hence no bit rot
- optimises away when gates are 0
- doesn't accidentally include changes in behaviour

That approach works fine for code that prints things out. In fact, we have HEX_DEBUG_LOG for that purpose. I can rewrite it as you suggest so the args always get compiled.

In addition, there are a dozen or so places where we emit additional TCG code when HEX_DEBUG is set. We print the results in HELPER(debug_commit_end). In the example above, we would end up with

#define debug_predicated_reg_write(rnum, slot_mask, zero, one) \
    do { \
        if (HEX_DEBUG) { \
            tcg_gen_movcond_tl(TCG_COND_EQ, hex_reg_written[rnum], slot_mask, zero, \
                                                   one, hex_reg_written[rnum]); \
        } \
    } while (0)

IMO, the invocation

    debug_predicated_reg_write(rnum, slot_mask, zero, one);

would be harder to read because you have to look at two places to see what is going on. There would be only one invocation, so it would be better to put the if (HEX_DEBUG) in place.

Taylor

#60 lore raw

Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

In reply to Taylor Simpson
Quoted 1 line · Taylor Simpson

+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int slot)

Drop all the inline markup. Let the compiler decide. It also means we get more consistent warnings for unused functions between gcc and clang (clang will warn for unused inlines outside a header file, gcc will not).

Also, quite a few of these function are really way too big to want to inline.

target/hexagon/genptr.c line 48

Quoted 12 lines
target/hexagon/genptr.c new file +12 -0
+{
+    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]);

This is a very complicated OR.

If you really want hex_reg_written = {0,1}, then change to

    tcg_gen_extract_tl(slot_mask, hex_slot_canceled, slot, 1);

otherwise, just let hex_reg_written be zero/non-zero, and or in the slot.

target/hexagon/genptr.c line 127

Quoted 9 lines
target/hexagon/genptr.c new file +9 -0
+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);

Why is this here, rather than asserting that we never generate an out-of-range value?

target/hexagon/genptr.c line 133

Quoted 6 lines
target/hexagon/genptr.c new file +6 -0
+    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);

Except for HEX_DEBUG, why would we not know whether or not a predicate has been written twice? It seems like we shouldn't need hex_pred_written for the non-debug case.

r~

#61 lore raw

RE: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 36 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 6:07 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 1 line · Taylor Simpson

+static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int

slot)

Drop all the inline markup. Let the compiler decide. It also means we get more consistent warnings for unused functions between gcc and clang (clang will
warn for unused inlines outside a header file, gcc will not).

Also, quite a few of these function are really way too big to want to inline.

target/hexagon/genptr.c

Quoted 7 lines
target/hexagon/genptr.c new file +7 -0
+{
+    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,

target/hexagon/genptr.c line 79

Quoted 4 lines
target/hexagon/genptr.c new file +4 -0
+                           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,

Quoted 1 line

+ one, hex_reg_written[rnum]);

Quoted 7 lines

This is a very complicated OR.

If you really want hex_reg_written = {0,1}, then change to

    tcg_gen_extract_tl(slot_mask, hex_slot_canceled, slot, 1);

otherwise, just let hex_reg_written be zero/non-zero, and or in the slot.

Note that slot_mask indicates that the value is not written (i.e., slot was cancelled). So, the code will be

    tcg_gen_xori_tl(slot_mask, slot_mask, 1 << slot);
    tcg_gen_or_tl(hex_reg_written[rnum], hex_reg_written[rnum], slot_mask);
Quoted 5 lines
Quoted 5 lines
target/hexagon/genptr.c new file +5 -0
+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();
Quoted 8 lines

target/hexagon/genptr.c line 127

Quoted 4 lines
target/hexagon/genptr.c new file +4 -0
+    TCGv pred_written = tcg_temp_new();
+
+    /* Multiple writes to the same preg are and'ed together */
+    tcg_gen_andi_tl(base_val, val, 0xff);

Why is this here, rather than asserting that we never generate an out-of- range
value?

The instruction semantics assume the values will be truncated to 8 bits when written. Here's an example:

    Q6INSN(C2_not,"Pd4=not(Ps4)",ATTRIBS(A_CRSLOT23),
    "Logical NOT Predicate",
    {PdV=~PsV;})

BTW, how can I generate an assert via TCG?

Quoted 11 lines

target/hexagon/genptr.c line 133

Quoted 6 lines
target/hexagon/genptr.c new file +6 -0
+    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);

Except for HEX_DEBUG, why would we not know whether or not a predicate has been
written twice? It seems like we shouldn't need hex_pred_written for the non-debug case.

It's legal to write to a predicate more than once in the same packet. In this case, we and the results together. This is described in Section 6.1.3 of the reference manual. I'll beef up the comment to make it more clear.

Thanks,
Taylor

#62 lore raw

Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 1 line · Taylor Simpson

BTW, how can I generate an assert via TCG?

You can't, as such. You can call a helper function, which can do whatever.

Quoted 6 lines
Quoted 4 lines

Except for HEX_DEBUG, why would we not know whether or not a predicate has been
written twice? It seems like we shouldn't need hex_pred_written for the non-debug case.

It's legal to write to a predicate more than once in the same packet.

I repeat -- why would you not know that? You should be able to examine the packet and see whether it does or does not write to a predicate register more than once.

Simply always generating code that assumes it has is lazy.

r~

#63 lore raw

RE: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 16 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Saturday, March 13, 2021 7:40 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 26/35] Hexagon (target/hexagon) TCG generation

Quoted 1 line
Quoted 1 line

Except for HEX_DEBUG, why would we not know whether or not a

predicate

Quoted 4 lines
Quoted 3 lines

has been
written twice? It seems like we shouldn't need hex_pred_written for the non-debug case.

Quoted 8 lines
Quoted 1 line

It's legal to write to a predicate more than once in the same packet.

I repeat -- why would you not know that? You should be able to examine the packet and see whether it does or does not write to a predicate register more
than once.

Simply always generating code that assumes it has is lazy.

Sorry misunderstood the question - yes, it should be possible at TCG generation time (rather than TCG execution time) to determine if the predicate has already been written. I will code this up.

Thanks,
Taylor

#64 lore raw

PATCH v8 27/35 Hexagon (target/hexagon) TCG for instructions with multiple definitions

In reply to Taylor Simpson

Helpers won't work if there are multiple definitions, so we override these instructions using #define fGEN_TCG_<tag>.

---
 target/hexagon/gen_tcg.h | 198 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 198 insertions(+)
 create mode 100644 target/hexagon/gen_tcg.h
target/hexagon/gen_tcg.h new file +198 -0
new file mode 100644
index 0000000..a8d9321
@@ -0,0 +1,198 @@
+/*
+ *  Copyright(c) 2019-2021 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_GEN_TCG_H
+#define HEXAGON_GEN_TCG_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)
+ *     _pi       post increment immediate          r0 = memb(r1++#1)
+ */
+
+/* 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_pi \
+    do { \
+        fEA_REG(RxV); \
+        fPM_I(RxV, siV); \
+    } while (0)
+
+
+/* Instructions with multiple definitions */
+#define fGEN_TCG_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 fGEN_TCG_L4_loadrub_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RdV, 1, u)
+#define fGEN_TCG_L4_loadrb_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RdV, 1, s)
+#define fGEN_TCG_L4_loadruh_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RdV, 2, u)
+#define fGEN_TCG_L4_loadrh_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RdV, 2, s)
+#define fGEN_TCG_L4_loadri_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RdV, 4, u)
+#define fGEN_TCG_L4_loadrd_ap(SHORTCODE) \
+    fGEN_TCG_LOAD_AP(RddV, 8, u)
+
+#define fGEN_TCG_L2_loadrub_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrub_pi(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrb_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrb_pi(SHORTCODE)       SHORTCODE;
+#define fGEN_TCG_L2_loadruh_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadruh_pi(SHORTCODE)      SHORTCODE;
+#define fGEN_TCG_L2_loadrh_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrh_pi(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadri_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadri_pi(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrd_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrd_pi(SHORTCODE)       SHORTCODE
+
+/*
+ * 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 fGEN_TCG_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 fGEN_TCG_L2_ploadrubt_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 1, u)
+#define fGEN_TCG_L2_ploadrubf_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 1, u)
+#define fGEN_TCG_L2_ploadrubtnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 1, u)
+#define fGEN_TCG_L2_ploadrubfnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 1, u)
+#define fGEN_TCG_L2_ploadrbt_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 1, s)
+#define fGEN_TCG_L2_ploadrbf_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 1, s)
+#define fGEN_TCG_L2_ploadrbtnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 1, s)
+#define fGEN_TCG_L2_ploadrbfnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD({ fEA_REG(RxV); fPM_I(RxV, siV); }, \
+                       fLSBNEWNOT(PtN), 1, s)
+
+#define fGEN_TCG_L2_ploadruht_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 2, u)
+#define fGEN_TCG_L2_ploadruhf_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 2, u)
+#define fGEN_TCG_L2_ploadruhtnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 2, u)
+#define fGEN_TCG_L2_ploadruhfnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 2, u)
+#define fGEN_TCG_L2_ploadrht_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 2, s)
+#define fGEN_TCG_L2_ploadrhf_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 2, s)
+#define fGEN_TCG_L2_ploadrhtnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 2, s)
+#define fGEN_TCG_L2_ploadrhfnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 2, s)
+
+#define fGEN_TCG_L2_ploadrit_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLD(PtV), 4, u)
+#define fGEN_TCG_L2_ploadrif_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBOLDNOT(PtV), 4, u)
+#define fGEN_TCG_L2_ploadritnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEW(PtN), 4, u)
+#define fGEN_TCG_L2_ploadrifnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD(GET_EA_pi, fLSBNEWNOT(PtN), 4, u)
+
+/* Predicated loads into a register pair */
+#define fGEN_TCG_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 fGEN_TCG_L2_ploadrdt_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD_PAIR(GET_EA_pi, fLSBOLD(PtV))
+#define fGEN_TCG_L2_ploadrdf_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD_PAIR(GET_EA_pi, fLSBOLDNOT(PtV))
+#define fGEN_TCG_L2_ploadrdtnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD_PAIR(GET_EA_pi, fLSBNEW(PtN))
+#define fGEN_TCG_L2_ploadrdfnew_pi(SHORTCODE) \
+    fGEN_TCG_PRED_LOAD_PAIR(GET_EA_pi, fLSBNEWNOT(PtN))
+
+/* load-locked and store-locked */
+#define fGEN_TCG_L2_loadw_locked(SHORTCODE) \
+    SHORTCODE
+#define fGEN_TCG_L4_loadd_locked(SHORTCODE) \
+    SHORTCODE
+#define fGEN_TCG_S2_storew_locked(SHORTCODE) \
+    do { SHORTCODE; READ_PREG(PdV, PdN); } while (0)
+#define fGEN_TCG_S4_stored_locked(SHORTCODE) \
+    do { SHORTCODE; READ_PREG(PdV, PdN); } while (0)
+
+#endif
Signature · 1 line
2.7.4
#65 lore raw

Re: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

target/hexagon/gen_tcg.h line 88

Quoted 6 lines · Taylor Simpson
target/hexagon/gen_tcg.h new file +6 -0
+#define fGEN_TCG_L2_loadrub_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrub_pi(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrb_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrb_pi(SHORTCODE)       SHORTCODE;
+#define fGEN_TCG_L2_loadruh_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadruh_pi(SHORTCODE)      SHORTCODE;

Why have some of these ; but not all?

r~

#66 lore raw

RE: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

Quoted 12 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 6:34 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

On 2/7/21 9:46 PM, Taylor Simpson wrote:

Quoted 8 lines

target/hexagon/gen_tcg.h line 88

Quoted 6 lines
target/hexagon/gen_tcg.h new file +6 -0
+#define fGEN_TCG_L2_loadrub_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrub_pi(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrb_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrb_pi(SHORTCODE)       SHORTCODE;
+#define fGEN_TCG_L2_loadruh_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadruh_pi(SHORTCODE)      SHORTCODE;

Why have some of these ; but not all?

The initial series only has overrides that are required for correct execution. I did that to minimize the amount of code to review. For most loads, the helper version works correctly. These need to be overridden because they define two results (the value loaded and the updated pointer). I have written the overrides for all and will upstream them in the future.

Here is my roadmap for Hexagon patches
- Address your feedback on the v8 series
- Add the remaining scalar core instructions
- Add the Hexagon Vector eXtensions (HVX) instructions
- Additional overrides, including these

Thanks,
Taylor

#67 lore raw

Re: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

Quoted 10 lines · Taylor Simpson
Quoted 8 lines

target/hexagon/gen_tcg.h line 88

Quoted 6 lines
target/hexagon/gen_tcg.h new file +6 -0
+#define fGEN_TCG_L2_loadrub_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrub_pi(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrb_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrb_pi(SHORTCODE)       SHORTCODE;
+#define fGEN_TCG_L2_loadruh_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadruh_pi(SHORTCODE)      SHORTCODE;

Why have some of these ; but not all?

The initial series only has overrides that are required for correct execution.

This does not answer the question re the semicolon inconsistency.

r~

#68 lore raw

RE: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

Quoted 21 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, March 14, 2021 1:02 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 27/35] Hexagon (target/hexagon) TCG for instructions with multiple definitions

Quoted 9 lines · Taylor Simpson
Quoted 8 lines

target/hexagon/gen_tcg.h line 88

Quoted 6 lines
target/hexagon/gen_tcg.h new file +6 -0
+#define fGEN_TCG_L2_loadrub_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrub_pi(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadrb_pr(SHORTCODE)       SHORTCODE
+#define fGEN_TCG_L2_loadrb_pi(SHORTCODE)       SHORTCODE;
+#define fGEN_TCG_L2_loadruh_pr(SHORTCODE)      SHORTCODE
+#define fGEN_TCG_L2_loadruh_pi(SHORTCODE)      SHORTCODE;

Why have some of these ; but not all?

Quoted 3 lines
Quoted 1 line

The initial series only has overrides that are required for correct execution.

This does not answer the question re the semicolon inconsistency.

Sorry, misunderstood the question. The semi's must've been needed at some point, but they're not needed now. I'll remove them.

Taylor

#69 lore raw

PATCH v8 28/35 Hexagon (target/hexagon) TCG for floating point instructions

In reply to Taylor Simpson

The imported code uses host floating point. We override them to use qemu softfloat

---
 target/hexagon/gen_tcg.h | 121 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
target/hexagon/gen_tcg.h +121 -0
index a8d9321..e044dea 100644
@@ -195,4 +195,125 @@
 #define fGEN_TCG_S4_stored_locked(SHORTCODE) \
     do { SHORTCODE; READ_PREG(PdV, PdN); } while (0)
 
+/* Floating point */
+#define fGEN_TCG_F2_conv_sf2df(SHORTCODE) \
+    gen_helper_conv_sf2df(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_df2sf(SHORTCODE) \
+    gen_helper_conv_df2sf(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_uw2sf(SHORTCODE) \
+    gen_helper_conv_uw2sf(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_uw2df(SHORTCODE) \
+    gen_helper_conv_uw2df(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_w2sf(SHORTCODE) \
+    gen_helper_conv_w2sf(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_w2df(SHORTCODE) \
+    gen_helper_conv_w2df(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_ud2sf(SHORTCODE) \
+    gen_helper_conv_ud2sf(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_ud2df(SHORTCODE) \
+    gen_helper_conv_ud2df(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_d2sf(SHORTCODE) \
+    gen_helper_conv_d2sf(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_d2df(SHORTCODE) \
+    gen_helper_conv_d2df(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_sf2uw(SHORTCODE) \
+    gen_helper_conv_sf2uw(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2w(SHORTCODE) \
+    gen_helper_conv_sf2w(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2ud(SHORTCODE) \
+    gen_helper_conv_sf2ud(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2d(SHORTCODE) \
+    gen_helper_conv_sf2d(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_df2uw(SHORTCODE) \
+    gen_helper_conv_df2uw(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2w(SHORTCODE) \
+    gen_helper_conv_df2w(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2ud(SHORTCODE) \
+    gen_helper_conv_df2ud(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2d(SHORTCODE) \
+    gen_helper_conv_df2d(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_sf2uw_chop(SHORTCODE) \
+    gen_helper_conv_sf2uw_chop(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2w_chop(SHORTCODE) \
+    gen_helper_conv_sf2w_chop(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2ud_chop(SHORTCODE) \
+    gen_helper_conv_sf2ud_chop(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_sf2d_chop(SHORTCODE) \
+    gen_helper_conv_sf2d_chop(RddV, cpu_env, RsV)
+#define fGEN_TCG_F2_conv_df2uw_chop(SHORTCODE) \
+    gen_helper_conv_df2uw_chop(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2w_chop(SHORTCODE) \
+    gen_helper_conv_df2w_chop(RdV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2ud_chop(SHORTCODE) \
+    gen_helper_conv_df2ud_chop(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_conv_df2d_chop(SHORTCODE) \
+    gen_helper_conv_df2d_chop(RddV, cpu_env, RssV)
+#define fGEN_TCG_F2_sfadd(SHORTCODE) \
+    gen_helper_sfadd(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfsub(SHORTCODE) \
+    gen_helper_sfsub(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfcmpeq(SHORTCODE) \
+    gen_helper_sfcmpeq(PdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfcmpgt(SHORTCODE) \
+    gen_helper_sfcmpgt(PdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfcmpge(SHORTCODE) \
+    gen_helper_sfcmpge(PdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfcmpuo(SHORTCODE) \
+    gen_helper_sfcmpuo(PdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfmax(SHORTCODE) \
+    gen_helper_sfmax(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfmin(SHORTCODE) \
+    gen_helper_sfmin(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sfclass(SHORTCODE) \
+    do { \
+        TCGv imm = tcg_const_tl(uiV); \
+        gen_helper_sfclass(PdV, cpu_env, RsV, imm); \
+        tcg_temp_free(imm); \
+    } while (0)
+#define fGEN_TCG_F2_sffixupn(SHORTCODE) \
+    gen_helper_sffixupn(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sffixupd(SHORTCODE) \
+    gen_helper_sffixupd(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sffixupr(SHORTCODE) \
+    gen_helper_sffixupr(RdV, cpu_env, RsV)
+#define fGEN_TCG_F2_dfadd(SHORTCODE) \
+    gen_helper_dfadd(RddV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfsub(SHORTCODE) \
+    gen_helper_dfsub(RddV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfmax(SHORTCODE) \
+    gen_helper_dfmax(RddV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfmin(SHORTCODE) \
+    gen_helper_dfmin(RddV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfcmpeq(SHORTCODE) \
+    gen_helper_dfcmpeq(PdV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfcmpgt(SHORTCODE) \
+    gen_helper_dfcmpgt(PdV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfcmpge(SHORTCODE) \
+    gen_helper_dfcmpge(PdV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfcmpuo(SHORTCODE) \
+    gen_helper_dfcmpuo(PdV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfclass(SHORTCODE) \
+    do { \
+        TCGv imm = tcg_const_tl(uiV); \
+        gen_helper_dfclass(PdV, cpu_env, RssV, imm); \
+        tcg_temp_free(imm); \
+    } while (0)
+#define fGEN_TCG_F2_sfmpy(SHORTCODE) \
+    gen_helper_sfmpy(RdV, cpu_env, RsV, RtV)
+#define fGEN_TCG_F2_sffma(SHORTCODE) \
+    gen_helper_sffma(RxV, cpu_env, RxV, RsV, RtV)
+#define fGEN_TCG_F2_sffma_sc(SHORTCODE) \
+    gen_helper_sffma_sc(RxV, cpu_env, RxV, RsV, RtV, PuV)
+#define fGEN_TCG_F2_sffms(SHORTCODE) \
+    gen_helper_sffms(RxV, cpu_env, RxV, RsV, RtV)
+#define fGEN_TCG_F2_sffma_lib(SHORTCODE) \
+    gen_helper_sffma_lib(RxV, cpu_env, RxV, RsV, RtV)
+#define fGEN_TCG_F2_sffms_lib(SHORTCODE) \
+    gen_helper_sffms_lib(RxV, cpu_env, RxV, RsV, RtV)
+
+#define fGEN_TCG_F2_dfmpyfix(SHORTCODE) \
+    gen_helper_dfmpyfix(RddV, cpu_env, RssV, RttV)
+#define fGEN_TCG_F2_dfmpyhh(SHORTCODE) \
+    gen_helper_dfmpyhh(RxxV, cpu_env, RxxV, RssV, RttV)
+
 #endif
Signature · 1 line
2.7.4
#71 lore raw

PATCH v8 29/35 Hexagon (target/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 |  93 ++++++
 target/hexagon/translate.c | 748 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 841 insertions(+)
 create mode 100644 target/hexagon/translate.h
 create mode 100644 target/hexagon/translate.c
target/hexagon/translate.h new file +93 -0
new file mode 100644
index 0000000..938f7fb
@@ -0,0 +1,93 @@
+/*
+ *  Copyright(c) 2019-2021 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 "qemu/bitmap.h"
+#include "cpu.h"
+#include "exec/translator.h"
+#include "tcg/tcg-op.h"
+#include "internal.h"
+
+typedef struct DisasContext {
+    DisasContextBase base;
+    uint32_t mem_idx;
+    uint32_t num_packets;
+    uint32_t num_insns;
+    int reg_log[REG_WRITES_MAX];
+    int reg_log_idx;
+    DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS);
+    int preg_log[PRED_WRITES_MAX];
+    int preg_log_idx;
+    uint8_t store_width[STORES_MAX];
+    uint8_t s1_store_processed;
+} DisasContext;
+
+static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)
+{
+#if HEX_DEBUG
+    if (test_bit(rnum, ctx->regs_written)) {
+        HEX_DEBUG_LOG("WARNING: Multiple writes to r%d\n", rnum);
+    }
+#endif
+    ctx->reg_log[ctx->reg_log_idx] = rnum;
+    ctx->reg_log_idx++;
+    set_bit(rnum, ctx->regs_written);
+}
+
+static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum)
+{
+    ctx_log_reg_write(ctx, rnum);
+    ctx_log_reg_write(ctx, rnum + 1);
+}
+
+static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
+{
+    ctx->preg_log[ctx->preg_log_idx] = pnum;
+    ctx->preg_log_idx++;
+}
+
+static inline bool is_preloaded(DisasContext *ctx, int num)
+{
+    return test_bit(num, ctx->regs_written);
+}
+
+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 hex_llsc_addr;
+extern TCGv hex_llsc_val;
+extern TCGv_i64 hex_llsc_val_i64;
+
+void gen_exception(int excp);
+void gen_exception_debug(void);
+
+void process_store(DisasContext *ctx, Packet *pkt, int slot_num);
+#endif
target/hexagon/translate.c new file +748 -0

748 lines not on this page · raw message

Signature · 1 line
2.7.4
#72 lore raw

Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 1 line · Taylor Simpson

+static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)

Drop the inline markup throughout.

target/hexagon/translate.c line 92

Quoted 10 lines
target/hexagon/translate.c new file +10 -0
+static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
+                             uint32_t words[])
+{
+    bool found_end = false;
+    int nwords, max_words;
+
+    memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
+    for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
+        words[nwords] = cpu_ldl_code(env,
+                                ctx->base.pc_next + nwords * sizeof(uint32_t));

translate_ldl, so that a plugin has access to the packet data. (Note that pkt_crosses_page is fine, because that's read-ahead, not reads for the current packet.)

Quoted 4 lines
target/hexagon/translate.c new file +4 -0
+#if HEX_DEBUG
+static inline void gen_check_store_width(DisasContext *ctx, int slot_num)
+{
+    TCGv slot = tcg_const_tl(slot_num);

target/hexagon/translate.c line 308

Quoted 10 lines
target/hexagon/translate.c new file +10 -0
+    TCGv check = tcg_const_tl(ctx->store_width[slot_num]);
+    gen_helper_debug_check_store_width(cpu_env, slot, check);
+    tcg_temp_free(slot);
+    tcg_temp_free(check);
+}
+#define HEX_DEBUG_GEN_CHECK_STORE_WIDTH(ctx, slot_num) \
+    gen_check_store_width(ctx, slot_num)
+#else
+#define HEX_DEBUG_GEN_CHECK_STORE_WIDTH(ctx, slot_num)  /* nothing */
+#endif

Fold this to a simple function call:

static void gen_check_store_width(...)

{
    if (HEX_DEBUG) {
       ....
    }
}

target/hexagon/translate.c line 599

Quoted 4 lines
target/hexagon/translate.c new file +4 -0
+#if HEX_DEBUG
+        /* When debugging, only put one packet per TB */
+        ctx->base.is_jmp = DISAS_TOO_MANY;
+#endif

Why? You can always add -singlestep to the command-line.

target/hexagon/translate.c line 624

Quoted 8 lines
target/hexagon/translate.c new file +8 -0
+    case DISAS_NORETURN:
+        gen_exec_counters(ctx);
+        tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
+        if (ctx->base.singlestep_enabled) {
+            gen_exception_debug();
+        } else {
+            tcg_gen_exit_tb(NULL, 0);
+        }

DISAS_NORETURN says that we have *already* exited the TB. None of the code you emit here will be reachable.

r~

#73 lore raw

RE: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 10 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 7:04 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 4 lines
Quoted 1 line · Taylor Simpson

+static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)

Drop the inline markup throughout.

I can go through the code and remove unnecessary inline's. However, these particular inline's are needed because this is a header file. If we remove the inline and the header gets included in a .c file that doesn't use the function, we get a "defined but not used" error. Also, we need to keep the inline's in genptr.c to avoid the same error when we switch an instruction between the fGEN_TCG and helper implementations (and the idef-parser in the future). Also, there is one function that needs to be inline for performance reasons. I'll add a comment for that one.

Quoted 7 lines

target/hexagon/translate.c line 92

Quoted 2 lines
target/hexagon/translate.c new file +2 -0
+        words[nwords] = cpu_ldl_code(env,
+                                ctx->base.pc_next + nwords * sizeof(uint32_t));

translate_ldl, so that a plugin has access to the packet data. (Note that pkt_crosses_page is fine, because that's read-ahead, not reads for the current
packet.)

OK

Quoted 9 lines

Fold this to a simple function call:

static void gen_check_store_width(...)

{
    if (HEX_DEBUG) {
       ....
    }
}

OK

Quoted 6 lines

target/hexagon/translate.c line 599

Quoted 4 lines
target/hexagon/translate.c new file +4 -0
+#if HEX_DEBUG
+        /* When debugging, only put one packet per TB */
+        ctx->base.is_jmp = DISAS_TOO_MANY;
+#endif

Why? You can always add -singlestep to the command-line.

OK

Quoted 9 lines

target/hexagon/translate.c line 624

Quoted 8 lines
target/hexagon/translate.c new file +8 -0
+    case DISAS_NORETURN:
+        gen_exec_counters(ctx);
+        tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
+        if (ctx->base.singlestep_enabled) {
+            gen_exception_debug();
+        } else {
+            tcg_gen_exit_tb(NULL, 0);
+        }
Quoted 3 lines

DISAS_NORETURN says that we have *already* exited the TB. None of the code you
emit here will be reachable.

Isn't this called before the TB ends? Here's the code in translator.c

    /* Emit code to exit the TB, as indicated by db->is_jmp.  */
    ops->tb_stop(db, cpu);
    gen_tb_end(db->tb, db->num_insns - bp_insn);

Thanks,
Taylor

#74 lore raw

Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 57 lines · Taylor Simpson
Quoted 10 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 7:04 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 4 lines
Quoted 1 line · Taylor Simpson

+static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)

Drop the inline markup throughout.

I can go through the code and remove unnecessary inline's. However, these particular inline's are needed because this is a header file. If we remove the inline and the header gets included in a .c file that doesn't use the function, we get a "defined but not used" error. Also, we need to keep the inline's in genptr.c to avoid the same error when we switch an instruction between the fGEN_TCG and helper implementations (and the idef-parser in the future). Also, there is one function that needs to be inline for performance reasons. I'll add a comment for that one.

Quoted 7 lines

target/hexagon/translate.c line 92

Quoted 2 lines
target/hexagon/translate.c new file +2 -0
+        words[nwords] = cpu_ldl_code(env,
+                                ctx->base.pc_next + nwords * sizeof(uint32_t));

translate_ldl, so that a plugin has access to the packet data. (Note that pkt_crosses_page is fine, because that's read-ahead, not reads for the current
packet.)

OK

Quoted 9 lines

Fold this to a simple function call:

static void gen_check_store_width(...)

{
     if (HEX_DEBUG) {
        ....
     }
}

OK

Quoted 6 lines

target/hexagon/translate.c line 599

Quoted 4 lines
target/hexagon/translate.c new file +4 -0
+#if HEX_DEBUG
+        /* When debugging, only put one packet per TB */
+        ctx->base.is_jmp = DISAS_TOO_MANY;
+#endif

Why? You can always add -singlestep to the command-line.

OK

Quoted 9 lines
Quoted 8 lines
target/hexagon/translate.c new file +8 -0
+    case DISAS_NORETURN:
+        gen_exec_counters(ctx);
+        tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
+        if (ctx->base.singlestep_enabled) {
+            gen_exception_debug();
+        } else {
+            tcg_gen_exit_tb(NULL, 0);
+        }
Quoted 5 lines
Quoted 3 lines

DISAS_NORETURN says that we have *already* exited the TB. None of the code you
emit here will be reachable.

Isn't this called before the TB ends?

Yes, but DISAS_NORETURN still means we've already exited.

Just like calling abort() in C means that we won't reach any following return statement.

r~

#75 lore raw

RE: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 27 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Saturday, March 13, 2021 7:44 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 18 lines
Quoted 18 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 7:04 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 8 lines · Taylor Simpson
target/hexagon/translate.c new file +8 -0
+    case DISAS_NORETURN:
+        gen_exec_counters(ctx);
+        tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
+        if (ctx->base.singlestep_enabled) {
+            gen_exception_debug();
+        } else {
+            tcg_gen_exit_tb(NULL, 0);
+        }
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

DISAS_NORETURN says that we have *already* exited the TB. None of the code you emit here will be reachable.

Isn't this called before the TB ends?

Yes, but DISAS_NORETURN still means we've already exited.

Just like calling abort() in C means that we won't reach any following return statement.

Then I'm missing something because the code emitted here does get executed. I thought the tb_stop function is a place for the target to add code. Should I push this up to all the places where we set ctx->base.is_jmp to DISAS_NORETURN?

Taylor

#76 lore raw

Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 5 lines · Taylor Simpson
Quoted 3 lines

Yes, but DISAS_NORETURN still means we've already exited.

Just like calling abort() in C means that we won't reach any following return statement.

Then I'm missing something because the code emitted here does get executed.

You really are missing the point.

The code emitted here, for the NORETURN case, gets executed? How do you know?
And if so, then *something* is returning when it shouldn't.

The stop hook is for the use of all of the *other* DISAS_* codes, for which we have not yet exited.

There should be *nothing* to be done for NORETURN. We have longjmp'ed away to the main loop already. Anything that needed to be done must have been done before that point.

r~

#77 lore raw

RE: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 12 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, March 15, 2021 8:32 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v8 29/35] Hexagon (target/hexagon) translation

Quoted 2 lines · Taylor Simpson
Quoted 2 lines

Yes, but DISAS_NORETURN still means we've already exited.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Just like calling abort() in C means that we won't reach any following return statement.

Then I'm missing something because the code emitted here does get executed.

You really are missing the point.

The code emitted here, for the NORETURN case, gets executed? How do you know?

I can see the side effects. For example, there is a call to gen_exec_counters(ctx), and I can see the counters being updated.

Quoted 7 lines

And if so, then *something* is returning when it shouldn't.

The stop hook is for the use of all of the *other* DISAS_* codes, for which we have not yet exited.

There should be *nothing* to be done for NORETURN. We have longjmp'ed away to the main loop already. Anything that needed to be done must have been done before that point.

OK - I'll make sure everything is done during the packet generation and nothing is done during tb_stop.

Thanks,
Taylor

#78 lore raw

PATCH v8 30/35 Hexagon (linux-user/hexagon) Linux user emulation

In reply to Taylor Simpson

Implementation of Linux user emulation for Hexagon
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     | 322 ++++++++++++++++++++++++++++++++++++
 linux-user/hexagon/target_cpu.h     |  44 +++++
 linux-user/hexagon/target_elf.h     |  40 +++++
 linux-user/hexagon/target_fcntl.h   |  18 ++
 linux-user/hexagon/target_signal.h  |  34 ++++
 linux-user/hexagon/target_structs.h |  54 ++++++
 linux-user/hexagon/target_syscall.h |  36 ++++
 linux-user/hexagon/termbits.h       |  18 ++
 linux-user/qemu.h                   |   2 +
 linux-user/syscall_defs.h           |  33 ++++
 linux-user/elfload.c                |  16 ++
 linux-user/hexagon/cpu_loop.c       | 100 +++++++++++
 linux-user/hexagon/signal.c         | 276 +++++++++++++++++++++++++++++++
 scripts/gensyscalls.sh              |   1 +
 15 files changed, 1012 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..b7ad5dc
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2021 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 +322 -0

322 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 +40 -0
new file mode 100644
index 0000000..b4e9f40
@@ -0,0 +1,40 @@
+/*
+ *  Copyright(c) 2019-2021 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 */
+        eflags == 0x8067     /* v67t */
+       ) {
+        return "v67";
+    }
+    return "unknown";
+}
+
+#endif
linux-user/hexagon/target_fcntl.h new file +18 -0
new file mode 100644
index 0000000..2892db8
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2021 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..345cf1c
@@ -0,0 +1,34 @@
+/*
+ *  Copyright(c) 2019-2021 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 +54 -0

54 lines not on this page · raw message

linux-user/hexagon/target_syscall.h new file +36 -0
new file mode 100644
index 0000000..7f91a4a
@@ -0,0 +1,36 @@
+/*
+ *  Copyright(c) 2019-2021 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
+
+#define TARGET_MCL_CURRENT  1
+#define TARGET_MCL_FUTURE   2
+#define TARGET_MCL_ONFAULT  4
+
+#endif
linux-user/hexagon/termbits.h new file +18 -0
new file mode 100644
index 0000000..8abf992
@@ -0,0 +1,18 @@
+/*
+ *  Copyright(c) 2019-2021 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/qemu.h +2 -0
index 17aa992..ac99d7d 100644
@@ -744,6 +744,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
linux-user/syscall_defs.h +33 -0
index f98c1c1..bf55ed5 100644
@@ -104,6 +104,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
@@ -2252,6 +2260,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 a640507..84ca7b0 100644
@@ -1514,6 +1514,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 +100 -0

100 lines not on this page · raw message

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

276 lines not on this page · raw message

scripts/gensyscalls.sh +1 -0
index bba9fb0..8fb450e 100755
@@ -98,4 +98,5 @@ generate_syscall_nr openrisc 32 "$output/linux-user/openrisc/syscall_nr.h"
 
 generate_syscall_nr riscv 32 "$output/linux-user/riscv/syscall32_nr.h"
 generate_syscall_nr riscv 64 "$output/linux-user/riscv/syscall64_nr.h"
+generate_syscall_nr hexagon 32 "$output/linux-user/hexagon/syscall_nr.h"
 rm -fr "$TMP"
Signature · 1 line
2.7.4
#79 lore raw

PATCH v8 31/35 Hexagon (tests/tcg/hexagon) TCG tests - multiarch

In reply to Taylor Simpson

Enable multiarch tests for Hexagon
Modify tests/tcg/configure.sh
Add reference files to tests/tcg/hexagon

---
 tests/tcg/configure.sh            |   4 +-
 tests/tcg/hexagon/Makefile.target |  30 ++
 tests/tcg/hexagon/float_convs.ref | 748 +++++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/float_madds.ref | 768 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 1549 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/Makefile.target
 create mode 100644 tests/tcg/hexagon/float_convs.ref
 create mode 100644 tests/tcg/hexagon/float_madds.ref
tests/tcg/configure.sh +3 -1
index e1b70e2..35f1a77 100755
@@ -49,6 +49,8 @@ fi
 : $(cross_cc_alpha="alpha-linux-gnu-gcc")
 : ${cross_cc_arm="arm-linux-gnueabihf-gcc"}
 : ${cross_cc_cflags_armeb="-mbig-endian"}
+: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
+: ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
 : ${cross_cc_hppa="hppa-linux-gnu-gcc"}
 : ${cross_cc_i386="i386-pc-linux-gnu-gcc"}
 : ${cross_cc_cflags_i386="-m32"}
@@ -94,7 +96,7 @@ for target in $target_list; do
     xtensa|xtensaeb)
       arches=xtensa
       ;;
-    alpha|cris|hppa|i386|lm32|microblaze|microblazeel|m68k|openrisc|riscv64|s390x|sh4|sparc64)
+    alpha|cris|hexagon|hppa|i386|lm32|microblaze|microblazeel|m68k|openrisc|riscv64|s390x|sh4|sparc64)
       arches=$target
       ;;
     *)
tests/tcg/hexagon/Makefile.target new file +30 -0
new file mode 100644
index 0000000..10b7c84
@@ -0,0 +1,30 @@
+##
+##  Copyright(c) 2019-2021 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/>.
+##
+
+# Hexagon doesn't support gdb, so skip the EXTRA_RUNS
+EXTRA_RUNS =
+
+# Hexagon has 64K pages, so increase the timeout to keep
+# test-mmap from timing out
+ifeq ($(CONFIG_DEBUG_TCG),y)
+TIMEOUT=800
+else
+TIMEOUT=500
+endif
+
+
+CFLAGS += -Wno-incompatible-pointer-types -Wno-undefined-internal
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
Reviewed-by on v8 31/35
#80 lore raw

Re: [PATCH v8 31/35] Hexagon (tests/tcg/hexagon) TCG tests - multiarch

Quoted 5 lines · Taylor Simpson

Enable multiarch tests for Hexagon
Modify tests/tcg/configure.sh
Add reference files to tests/tcg/hexagon

Quoted 9 lines
---
 tests/tcg/configure.sh            |   4 +-
 tests/tcg/hexagon/Makefile.target |  30 ++
 tests/tcg/hexagon/float_convs.ref | 748 +++++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/float_madds.ref | 768 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 1549 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/Makefile.target
 create mode 100644 tests/tcg/hexagon/float_convs.ref
 create mode 100644 tests/tcg/hexagon/float_madds.ref
#82 lore raw

PATCH v8 32/35 Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc

In reply to Taylor Simpson
---
 tests/tcg/hexagon/atomics.c       | 139 ++++++++++++++
 tests/tcg/hexagon/dual_stores.c   |  60 ++++++
 tests/tcg/hexagon/mem_noshuf.c    | 328 ++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/misc.c          | 380 ++++++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/preg_alias.c    | 169 +++++++++++++++++
 tests/tcg/hexagon/Makefile.target |  15 ++
 tests/tcg/hexagon/first.S         |  56 ++++++
 7 files changed, 1147 insertions(+)
 create mode 100644 tests/tcg/hexagon/atomics.c
 create mode 100644 tests/tcg/hexagon/dual_stores.c
 create mode 100644 tests/tcg/hexagon/mem_noshuf.c
 create mode 100644 tests/tcg/hexagon/misc.c
 create mode 100644 tests/tcg/hexagon/preg_alias.c
 create mode 100644 tests/tcg/hexagon/first.S
tests/tcg/hexagon/atomics.c new file +139 -0
new file mode 100644
index 0000000..ff1ceee
@@ -0,0 +1,139 @@
+/*
+ *  Copyright(c) 2019-2021 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <pthread.h>
+
+/* Using volatile because we are testing atomics */
+static inline int atomic_inc32(volatile int *x)
+{
+    int old, dummy;
+    __asm__ __volatile__(
+        "1: %0 = memw_locked(%2)\n\t"
+        "   %1 = add(%0, #1)\n\t"
+        "   memw_locked(%2, p0) = %1\n\t"
+        "   if (!p0) jump 1b\n\t"
+        : "=&r"(old), "=&r"(dummy)
+        : "r"(x)
+        : "p0", "memory");
+    return old;
+}
+
+/* Using volatile because we are testing atomics */
+static inline long long atomic_inc64(volatile long long *x)
+{
+    long long old, dummy;
+    __asm__ __volatile__(
+        "1: %0 = memd_locked(%2)\n\t"
+        "   %1 = #1\n\t"
+        "   %1 = add(%0, %1)\n\t"
+        "   memd_locked(%2, p0) = %1\n\t"
+        "   if (!p0) jump 1b\n\t"
+        : "=&r"(old), "=&r"(dummy)
+        : "r"(x)
+        : "p0", "memory");
+    return old;
+}
+
+/* Using volatile because we are testing atomics */
+static inline int atomic_dec32(volatile int *x)
+{
+    int old, dummy;
+    __asm__ __volatile__(
+        "1: %0 = memw_locked(%2)\n\t"
+        "   %1 = add(%0, #-1)\n\t"
+        "   memw_locked(%2, p0) = %1\n\t"
+        "   if (!p0) jump 1b\n\t"
+        : "=&r"(old), "=&r"(dummy)
+        : "r"(x)
+        : "p0", "memory");
+    return old;
+}
+
+/* Using volatile because we are testing atomics */
+static inline long long atomic_dec64(volatile long long *x)
+{
+    long long old, dummy;
+    __asm__ __volatile__(
+        "1: %0 = memd_locked(%2)\n\t"
+        "   %1 = #-1\n\t"
+        "   %1 = add(%0, %1)\n\t"
+        "   memd_locked(%2, p0) = %1\n\t"
+        "   if (!p0) jump 1b\n\t"
+        : "=&r"(old), "=&r"(dummy)
+        : "r"(x)
+        : "p0", "memory");
+    return old;
+}
+
+#define LOOP_CNT 1000
+/* Using volatile because we are testing atomics */
+volatile int tick32 = 1;
+/* Using volatile because we are testing atomics */
+volatile long long tick64 = 1;
+int err;
+
+void *thread1_func(void *arg)
+{
+    int i;
+
+    for (i = 0; i < LOOP_CNT; i++) {
+        atomic_inc32(&tick32);
+        atomic_dec64(&tick64);
+    }
+    return NULL;
+}
+
+void *thread2_func(void *arg)
+{
+    int i;
+    for (i = 0; i < LOOP_CNT; i++) {
+        atomic_dec32(&tick32);
+        atomic_inc64(&tick64);
+    }
+    return NULL;
+}
+
+void test_pthread(void)
+{
+    pthread_t tid1, tid2;
+
+    pthread_create(&tid1, NULL, thread1_func, "hello1");
+    pthread_create(&tid2, NULL, thread2_func, "hello2");
+    pthread_join(tid1, NULL);
+    pthread_join(tid2, NULL);
+
+    if (tick32 != 1) {
+        printf("ERROR: tick32 %d != 1\n", tick32);
+        err++;
+    }
+    if (tick64 != 1) {
+        printf("ERROR: tick64 %lld != 1\n", tick64);
+        err++;
+    }
+}
+
+int main(int argc, char **argv)
+{
+    test_pthread();
+    puts(err ? "FAIL" : "PASS");
+    return err;
+}
tests/tcg/hexagon/dual_stores.c new file +60 -0

60 lines not on this page · raw message

tests/tcg/hexagon/mem_noshuf.c new file +328 -0

328 lines not on this page · raw message

tests/tcg/hexagon/misc.c new file +380 -0

380 lines not on this page · raw message

tests/tcg/hexagon/preg_alias.c new file +169 -0

169 lines not on this page · raw message

tests/tcg/hexagon/Makefile.target +15 -0
index 10b7c84..a54e3c7 100644
@@ -28,3 +28,18 @@ endif
 
 
 CFLAGS += -Wno-incompatible-pointer-types -Wno-undefined-internal
+
+HEX_SRC=$(SRC_PATH)/tests/tcg/hexagon
+VPATH += $(HEX_SRC)
+
+first: $(HEX_SRC)/first.S
+	$(CC) -static -mv67 -nostdlib $^ -o $@
+
+HEX_TESTS = first
+HEX_TESTS += misc
+HEX_TESTS += preg_alias
+HEX_TESTS += dual_stores
+HEX_TESTS += mem_noshuf
+HEX_TESTS += atomics
+
+TESTS += $(HEX_TESTS)
tests/tcg/hexagon/first.S new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.7.4
#83 lore raw

Re: [PATCH v8 32/35] Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc

Quoted 4 lines · Taylor Simpson
tests/tcg/hexagon/atomics.c new file +4 -0
+/* Using volatile because we are testing atomics */
+static inline int atomic_inc32(volatile int *x)
+{
+    int old, dummy;

tests/tcg/hexagon/atomics.c line 38

Quoted 10 lines
tests/tcg/hexagon/atomics.c new file +10 -0
+    __asm__ __volatile__(
+        "1: %0 = memw_locked(%2)\n\t"
+        "   %1 = add(%0, #1)\n\t"
+        "   memw_locked(%2, p0) = %1\n\t"
+        "   if (!p0) jump 1b\n\t"
+        : "=&r"(old), "=&r"(dummy)
+        : "r"(x)
+        : "p0", "memory");
+    return old;
+}

While I can hardly deny a cpu testcase using inline asm, I'm a bit curious why you didn't use the compiler builtins.

r~

#84 lore raw

PATCH v8 33/35 Hexagon (tests/tcg/hexagon) TCG tests - floating point

In reply to Taylor Simpson
---
 tests/tcg/hexagon/fpstuff.c       | 370 ++++++++++++++++++++++++++++++++++++++
 tests/tcg/hexagon/Makefile.target |   1 +
 2 files changed, 371 insertions(+)
 create mode 100644 tests/tcg/hexagon/fpstuff.c
tests/tcg/hexagon/fpstuff.c new file +370 -0
new file mode 100644
index 0000000..e4f1a0e
@@ -0,0 +1,370 @@
+/*
+ *  Copyright(c) 2020-2021 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 test checks various FP operations performed on Hexagon
+ */
+
+#include <stdio.h>
+
+const int FPINVF_BIT = 1;                 /* Invalid */
+const int FPINVF = 1 << FPINVF_BIT;
+const int FPDBZF_BIT = 2;                 /* Divide by zero */
+const int FPDBZF = 1 << FPDBZF_BIT;
+const int FPOVFF_BIT = 3;                 /* Overflow */
+const int FPOVFF = 1 << FPOVFF_BIT;
+const int FPUNFF_BIT = 4;                 /* Underflow */
+const int FPUNFF = 1 << FPUNFF_BIT;
+const int FPINPF_BIT = 5;                 /* Inexact */
+const int FPINPF = 1 << FPINPF_BIT;
+
+const int SF_ZERO =                       0x00000000;
+const int SF_NaN =                        0x7fc00000;
+const int SF_NaN_special =                0x7f800001;
+const int SF_ANY =                        0x3f800000;
+const int SF_HEX_NAN =                    0xffffffff;
+
+const long long DF_NaN =                  0x7ff8000000000000ULL;
+const long long DF_ANY =                  0x3f80000000000000ULL;
+const long long DF_HEX_NAN =              0xffffffffffffffffULL;
+
+int err;
+
+#define CLEAR_FPSTATUS \
+    "r2 = usr\n\t" \
+    "r2 = clrbit(r2, #1)\n\t" \
+    "r2 = clrbit(r2, #2)\n\t" \
+    "r2 = clrbit(r2, #3)\n\t" \
+    "r2 = clrbit(r2, #4)\n\t" \
+    "r2 = clrbit(r2, #5)\n\t" \
+    "usr = r2\n\t"
+
+static void check_fpstatus_bit(int usr, int expect, int flag, const char *n)
+{
+    int bit = 1 << flag;
+    if ((usr & bit) != (expect & bit)) {
+        printf("ERROR %s: usr = %d, expect = %d\n", n,
+               (usr >> flag) & 1, (expect >> flag) & 1);
+        err++;
+    }
+}
+
+static void check_fpstatus(int usr, int expect)
+{
+    check_fpstatus_bit(usr, expect, FPINVF_BIT, "Invalid");
+    check_fpstatus_bit(usr, expect, FPDBZF_BIT, "Div by zero");
+    check_fpstatus_bit(usr, expect, FPOVFF_BIT, "Overflow");
+    check_fpstatus_bit(usr, expect, FPUNFF_BIT, "Underflow");
+    check_fpstatus_bit(usr, expect, FPINPF_BIT, "Inexact");
+}
+
+static void check32(int val, int expect)
+{
+    if (val != expect) {
+        printf("ERROR: 0x%x != 0x%x\n", val, expect);
+        err++;
+    }
+}
+static void check64(unsigned long long val, unsigned long long expect)
+{
+    if (val != expect) {
+        printf("ERROR: 0x%llx != 0x%llx\n", val, expect);
+        err++;
+    }
+}
+
+static void check_compare_exception(void)
+{
+    int cmp;
+    int usr;
+
+    /* Check that FP compares are quiet (don't raise any execptions) */
+    asm (CLEAR_FPSTATUS
+         "p0 = sfcmp.eq(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "p0 = sfcmp.gt(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "p0 = sfcmp.ge(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "p0 = dfcmp.eq(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "p0 = dfcmp.gt(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "p0 = dfcmp.ge(%2, %3)\n\t"
+         "%0 = p0\n\t"
+         "%1 = usr\n\t"
+         : "=r"(cmp), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+         : "r2", "p0", "usr");
+    check32(cmp, 0);
+    check_fpstatus(usr, 0);
+}
+
+static void check_sfminmax(void)
+{
+    int minmax;
+    int usr;
+
+    /*
+     * Execute sfmin/sfmax instructions with one operand as NaN
+     * Check that
+     *     Result is the other operand
+     *     Invalid bit in USR is not set
+     */
+     asm (CLEAR_FPSTATUS
+         "%0 = sfmin(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+         : "r2", "usr");
+    check64(minmax, SF_ANY);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "%0 = sfmax(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+         : "r2", "usr");
+    check64(minmax, SF_ANY);
+    check_fpstatus(usr, 0);
+
+    /*
+     * Execute sfmin/sfmax instructions with both operands NaN
+     * Check that
+     *     Result is SF_HEX_NAN
+     *     Invalid bit in USR is set
+     */
+    asm (CLEAR_FPSTATUS
+         "%0 = sfmin(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(SF_NaN), "r"(SF_NaN)
+         : "r2", "usr");
+    check64(minmax, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm (CLEAR_FPSTATUS
+         "%0 = sfmax(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(SF_NaN), "r"(SF_NaN)
+         : "r2", "usr");
+    check64(minmax, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+}
+
+static void check_dfminmax(void)
+{
+    unsigned long long minmax;
+    int usr;
+
+    /*
+     * Execute dfmin/dfmax instructions with one operand as NaN
+     * Check that
+     *     Result is the other operand
+     *     Invalid bit in USR is set
+     */
+     asm (CLEAR_FPSTATUS
+         "%0 = dfmin(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+         : "r2", "usr");
+    check64(minmax, DF_ANY);
+    check_fpstatus(usr, FPINVF);
+
+    asm (CLEAR_FPSTATUS
+         "%0 = dfmax(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+         : "r2", "usr");
+    check64(minmax, DF_ANY);
+    check_fpstatus(usr, FPINVF);
+
+    /*
+     * Execute dfmin/dfmax instructions with both operands NaN
+     * Check that
+     *     Result is DF_HEX_NAN
+     *     Invalid bit in USR is set
+     */
+    asm (CLEAR_FPSTATUS
+         "%0 = dfmin(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(DF_NaN), "r"(DF_NaN)
+         : "r2", "usr");
+    check64(minmax, DF_HEX_NAN);
+    check_fpstatus(usr, FPINVF);
+
+    asm (CLEAR_FPSTATUS
+         "%0 = dfmax(%2, %3)\n\t"
+         "%1 = usr\n\t"
+         : "=r"(minmax), "=r"(usr) : "r"(DF_NaN), "r"(DF_NaN)
+         : "r2", "usr");
+    check64(minmax, DF_HEX_NAN);
+    check_fpstatus(usr, FPINVF);
+}
+
+static void check_canonical_NaN(void)
+{
+    int sf_result;
+    unsigned long long df_result;
+    int usr;
+
+    /* Check that each FP instruction properly returns SF_HEX_NAN/DF_HEX_NAN */
+    asm(CLEAR_FPSTATUS
+        "%0 = sfadd(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = sfsub(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = sfmpy(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    sf_result = SF_ZERO;
+    asm(CLEAR_FPSTATUS
+        "%0 += sfmpy(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "+r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    sf_result = SF_ZERO;
+    asm(CLEAR_FPSTATUS
+        "p0 = !cmp.eq(r0, r0)\n\t"
+        "%0 += sfmpy(%2, %3, p0):scale\n\t"
+        "%1 = usr\n\t"
+        : "+r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr", "p0");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    sf_result = SF_ZERO;
+    asm(CLEAR_FPSTATUS
+        "%0 -= sfmpy(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "+r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    sf_result = SF_ZERO;
+    asm(CLEAR_FPSTATUS
+        "%0 += sfmpy(%2, %3):lib\n\t"
+        "%1 = usr\n\t"
+        : "+r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    sf_result = SF_ZERO;
+    asm(CLEAR_FPSTATUS
+        "%0 -= sfmpy(%2, %3):lib\n\t"
+        "%1 = usr\n\t"
+        : "+r"(sf_result), "=r"(usr) : "r"(SF_NaN), "r"(SF_ANY)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = convert_df2sf(%2)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(sf_result), "=r"(usr) : "r"(DF_NaN)
+        : "r2", "usr");
+    check32(sf_result, SF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = dfadd(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(df_result), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+        : "r2", "usr");
+    check64(df_result, DF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = dfsub(%2, %3)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(df_result), "=r"(usr) : "r"(DF_NaN), "r"(DF_ANY)
+        : "r2", "usr");
+    check64(df_result, DF_HEX_NAN);
+    check_fpstatus(usr, 0);
+
+    asm(CLEAR_FPSTATUS
+        "%0 = convert_sf2df(%2)\n\t"
+        "%1 = usr\n\t"
+        : "=r"(df_result), "=r"(usr) : "r"(SF_NaN)
+        : "r2", "usr");
+    check64(df_result, DF_HEX_NAN);
+    check_fpstatus(usr, 0);
+}
+
+int main()
+{
+    check_compare_exception();
+    check_sfminmax();
+    check_dfminmax();
+    check_canonical_NaN();
+
+    puts(err ? "FAIL" : "PASS");
+    return err ? 1 : 0;
+}
tests/tcg/hexagon/Makefile.target +1 -0
index a54e3c7..616af69 100644
@@ -41,5 +41,6 @@ HEX_TESTS += preg_alias
 HEX_TESTS += dual_stores
 HEX_TESTS += mem_noshuf
 HEX_TESTS += atomics
+HEX_TESTS += fpstuff
 
 TESTS += $(HEX_TESTS)
Signature · 1 line
2.7.4
#86 lore raw

PATCH v8 34/35 Hexagon build infrastructure

In reply to Taylor Simpson

Add file to default-configs
Add hexagon to meson.build
Add hexagon to target/meson.build
Add target/hexagon/meson.build
Change scripts/qemu-binfmt-conf.sh

We can build a hexagon-linux-user target and run programs on the Hexagon scalar core. With hexagon-linux-clang installed, "make check-tcg" will pass.

---
 default-configs/targets/hexagon-linux-user.mak |   1 +
 meson.build                                    |   1 +
 scripts/qemu-binfmt-conf.sh                    |   6 +-
 target/hexagon/meson.build                     | 193 +++++++++++++++++++++++++
 target/meson.build                             |   1 +
 5 files changed, 201 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/targets/hexagon-linux-user.mak
 create mode 100644 target/hexagon/meson.build
default-configs/targets/hexagon-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..003ed0a
@@ -0,0 +1 @@
+TARGET_ARCH=hexagon
meson.build +1 -0
index 2d8b433..4b1ebe9 100644
@@ -1172,6 +1172,7 @@ disassemblers = {
   'arm' : ['CONFIG_ARM_DIS'],
   'avr' : ['CONFIG_AVR_DIS'],
   'cris' : ['CONFIG_CRIS_DIS'],
+  'hexagon' : ['CONFIG_HEXAGON_DIS'],
   'hppa' : ['CONFIG_HPPA_DIS'],
   'i386' : ['CONFIG_I386_DIS'],
   'x86_64' : ['CONFIG_I386_DIS'],
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/meson.build new file +193 -0

193 lines not on this page · raw message

target/meson.build +1 -0
index 9f0ae93..c35c1e9 100644
@@ -2,6 +2,7 @@ subdir('alpha')
 subdir('arm')
 subdir('avr')
 subdir('cris')
+subdir('hexagon')
 subdir('hppa')
 subdir('i386')
 subdir('lm32')
Signature · 1 line
2.7.4
Reviewed-by on v8 34/35
#87 lore raw

Re: [PATCH v8 34/35] Hexagon build infrastructure

Quoted 6 lines · Taylor Simpson

Add file to default-configs
Add hexagon to meson.build
Add hexagon to target/meson.build
Add target/hexagon/meson.build
Change scripts/qemu-binfmt-conf.sh

Quoted 6 lines

We can build a hexagon-linux-user target and run programs on the Hexagon scalar core. With hexagon-linux-clang installed, "make check-tcg" will pass.

---

r~

#88 lore raw

PATCH v8 35/35 Add Dockerfile for hexagon

In reply to Taylor Simpson

From: Alessandro Di Federico <[email protected]>

---
 .../debian-hexagon-cross-build-local.docker        |  18 +++
 .../debian-hexagon-cross.build-toolchain.sh        | 141 +++++++++++++++++++++
 .../docker/dockerfiles/debian-hexagon-cross.docker |   1 +
 tests/tcg/configure.sh                             |   4 +
 4 files changed, 164 insertions(+)
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker
 create mode 100755 tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross.docker
tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker new file +18 -0
new file mode 100644
index 0000000..355adbf
@@ -0,0 +1,18 @@
+FROM debian:10
+
+RUN apt update && \
+    DEBIAN_FRONTEND=noninteractive \
+    apt install -y --no-install-recommends \
+        ca-certificates build-essential cmake clang lld ninja-build \
+	flex bison pkg-config wget python3 rsync
+
+ENV TOOLCHAIN_INSTALL /usr
+ENV ROOTFS /usr
+
+ENV LLVM_URL https://github.com/llvm/llvm-project/archive/3d8149c2a1228609fd7d7c91a04681304a2f0ca9.tar.gz
+ENV MUSL_URL https://github.com/quic/musl/archive/aff74b395fbf59cd7e93b3691905aa1af6c0778c.tar.gz
+ENV LINUX_URL https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.6.18.tar.xz
+
+COPY debian-hexagon-cross.build-toolchain.sh /root/hexagon-toolchain/
+
+RUN cd /root/hexagon-toolchain/ && ./debian-hexagon-cross.build-toolchain.sh && cd / && rm -rf /root/hexagon-toolchain/
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh new file +141 -0

141 lines not on this page · raw message

tests/docker/dockerfiles/debian-hexagon-cross.docker new file +1 -0
new file mode 100644
index 0000000..92c586e
@@ -0,0 +1 @@
+FROM revng/qemu:debian-hexagon-cross
tests/tcg/configure.sh +4 -0
index 35f1a77..4efb3f7 100755
@@ -124,6 +124,10 @@ for target in $target_list; do
       container_image=fedora-cris-cross
       container_cross_cc=cris-linux-gnu-gcc
       ;;
+    hexagon-*)
+      container_image=debian-hexagon-cross
+      container_cross_cc=hexagon-unknown-linux-musl-clang
+      ;;
     hppa-*)
       container_image=debian-hppa-cross
       container_cross_cc=hppa-linux-gnu-gcc
Signature · 1 line
2.7.4
Tested-by on v8 35/35
#89 lore raw

Re: [PATCH v8 35/35] Add Dockerfile for hexagon

Hi Alessandro!

Quoted 26 lines · Taylor Simpson

From: Alessandro Di Federico <[email protected]>

---
 .../debian-hexagon-cross-build-local.docker        |  18 +++
 .../debian-hexagon-cross.build-toolchain.sh        | 141 +++++++++++++++++++++
 .../docker/dockerfiles/debian-hexagon-cross.docker |   1 +
 tests/tcg/configure.sh                             |   4 +
 4 files changed, 164 insertions(+)
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker
 create mode 100755 tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross.docker
tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker new file +6 -0
new file mode 100644
index 0000000..355adbf
@@ -0,0 +1,18 @@
+FROM debian:10
+
+RUN apt update && \
+    DEBIAN_FRONTEND=noninteractive \
+    apt install -y --no-install-recommends \
+        ca-certificates build-essential cmake clang lld ninja-build \

tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker line 16

Quoted 10 lines
tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker new file +10 -0
+	flex bison pkg-config wget python3 rsync
+
+ENV TOOLCHAIN_INSTALL /usr
+ENV ROOTFS /usr
+
+ENV LLVM_URL https://github.com/llvm/llvm-project/archive/3d8149c2a1228609fd7d7c91a04681304a2f0ca9.tar.gz
+ENV MUSL_URL https://github.com/quic/musl/archive/aff74b395fbf59cd7e93b3691905aa1af6c0778c.tar.gz
+ENV LINUX_URL https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.6.18.tar.xz
+
+COPY debian-hexagon-cross.build-toolchain.sh /root/hexagon-toolchain/

I had to add this to build your image with QEMU build system:

-- >8 --

tests/docker/Makefile.include +2 -0
index 93b29ad823e..ba73fb4b1f0 100644
@@ -146,6 +146,8 @@ docker-image-debian-riscv64-cross: docker-image-debian10
 docker-image-debian-s390x-cross: docker-image-debian10
 docker-image-debian-sh4-cross: docker-image-debian10
 docker-image-debian-sparc64-cross: docker-image-debian10
+docker-image-debian-hexagon-cross-build-local: \
+

EXTRA_FILES:=$(SRC_PATH)/tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh

docker-image-travis: NOUSER=1

---

tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker line 1

Quoted 3 lines
tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker new file +2 -0
+++ b/tests/docker/dockerfiles/debian-hexagon-cross.docker
@@ -0,0 +1 @@
+FROM revng/qemu:debian-hexagon-cross

Once this patch gets merged, the image will be available on qemu/qemu:debian-hexagon-cross.

I suppose for the final merge patch we want:
- rm debian-hexagon-cross.docker
- mv debian-hexagon-cross-build-local.docker debian-hexagon-cross.docker

Is that correct? If so, can you amend that detail after the '---' separator of the commit description so we don't merge this patch as it?

Also, can you add a job to build your image in .gitlab-ci.d/containers.yml?

Meanwhile:

Regards,

Phil.

#90 lore raw

Re: [PATCH v8 35/35] Add Dockerfile for hexagon

Quoted 1 line · On Sun, 14 Feb 2021 19:50:41 +0100 Philippe Mathieu-Daudé <[email protected]>…

Hi Alessandro!

Hi Philippe!

Quoted 18 lines

I had to add this to build your image with QEMU build system:

-- >8 --

(quoted diff) +0 -0

b/tests/docker/Makefile.include index 93b29ad823e..ba73fb4b1f0 100644

tests/docker/Makefile.include +0 -0
@@ -146,6 +146,8 @@ docker-image-debian-riscv64-cross:

docker-image-debian10 docker-image-debian-s390x-cross:
docker-image-debian10 docker-image-debian-sh4-cross:
docker-image-debian10 docker-image-debian-sparc64-cross:
docker-image-debian10
+docker-image-debian-hexagon-cross-build-local:
\
+ EXTRA_FILES:=$(SRC_PATH)/tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh

Quoted 3 lines

docker-image-travis: NOUSER=1

---

OK, I'll drop -local (see below).

Quoted 7 lines

Review line 1

Quoted 3 lines

+++ b/tests/docker/dockerfiles/debian-hexagon-cross.docker

(quoted diff) +1 -0
@@ -0,0 +1 @@
+FROM revng/qemu:debian-hexagon-cross  

Once this patch gets merged, the image will be available on qemu/qemu:debian-hexagon-cross.

Quoted 6 lines

I suppose for the final merge patch we want:
- rm debian-hexagon-cross.docker
- mv debian-hexagon-cross-build-local.docker
debian-hexagon-cross.docker

Is that correct?

The revng/qemu:debian-hexagon-cross image was there only to let people quickly try out a toolchain without building it from source.

If building from source is OK with you, that works for us. In any case, people will be able to use qemu/qemu:debian-hexagon-cross, right?

Quoted 3 lines

If so, can you amend that detail after the '---' separator of the commit description so we don't merge this patch as it?

I'm a bit confused, do you want me to send a patch corrected by hand here?
I'll send a new patch tomorrow.

Quoted 2 lines

Also, can you add a job to build your image in
.gitlab-ci.d/containers.yml?

OK, is there a quick way for me to test changes I make to that file?

Signature · 2 lines
Alessandro Di Federico
rev.ng Srls, CEO
#91 lore raw

Re: [PATCH v8 35/35] Add Dockerfile for hexagon

Quoted 43 lines · Alessandro Di Federico via
Quoted 1 line · On Sun, 14 Feb 2021 19:50:41 +0100 Philippe Mathieu-Daudé <[email protected]>…

Hi Alessandro!

Hi Philippe!

Quoted 18 lines

I had to add this to build your image with QEMU build system:

-- >8 --

(quoted diff) +0 -0

b/tests/docker/Makefile.include index 93b29ad823e..ba73fb4b1f0 100644

tests/docker/Makefile.include +0 -0
@@ -146,6 +146,8 @@ docker-image-debian-riscv64-cross:

docker-image-debian10 docker-image-debian-s390x-cross:
docker-image-debian10 docker-image-debian-sh4-cross:
docker-image-debian10 docker-image-debian-sparc64-cross:
docker-image-debian10
+docker-image-debian-hexagon-cross-build-local:
\
+ EXTRA_FILES:=$(SRC_PATH)/tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh

Quoted 3 lines

docker-image-travis: NOUSER=1

---

OK, I'll drop -local (see below).

Quoted 12 lines

Review line 1

Quoted 3 lines

+++ b/tests/docker/dockerfiles/debian-hexagon-cross.docker

(quoted diff) +1 -0
@@ -0,0 +1 @@
+FROM revng/qemu:debian-hexagon-cross  

Once this patch gets merged, the image will be available on qemu/qemu:debian-hexagon-cross.

I suppose for the final merge patch we want:
- rm debian-hexagon-cross.docker
- mv debian-hexagon-cross-build-local.docker
debian-hexagon-cross.docker

Quoted 4 lines
Quoted 1 line

Is that correct?

The revng/qemu:debian-hexagon-cross image was there only to let people quickly try out a toolchain without building it from source.

OK, not obvious from the commit description ;)

Quoted 3 lines

If building from source is OK with you, that works for us. In any case, people will be able to use qemu/qemu:debian-hexagon-cross, right?

If you add a job to build it (see .gitlab-ci.d/containers.yml) it will then be pushed to the Gitlab QEMU namespace. So Yes.

When we need a Docker image to build things, we first try to pull from QEMU namespace, then build locally if not available (see tests/docker/Makefile.include).

Quoted 7 lines
Quoted 3 lines

If so, can you amend that detail after the '---' separator of the commit description so we don't merge this patch as it?

I'm a bit confused, do you want me to send a patch corrected by hand here?
I'll send a new patch tomorrow.

I basically meant, "If this is the case and you want to keep it as it, please describe this better, so this patch doesn't get merged".

Quoted 4 lines
Quoted 2 lines

Also, can you add a job to build your image in
.gitlab-ci.d/containers.yml?

OK, is there a quick way for me to test changes I make to that file?

Open a Gitlab account, clone QEMU, push your change :)

https://wiki.qemu.org/Testing/CI/GitLabCI

Regards,

Phil.

#92 lore raw

Re: [PATCH v8 35/35] Add Dockerfile for hexagon

In reply to Taylor Simpson
Quoted 13 lines · Taylor Simpson

From: Alessandro Di Federico <[email protected]>

---
 .../debian-hexagon-cross-build-local.docker        |  18 +++
 .../debian-hexagon-cross.build-toolchain.sh        | 141 +++++++++++++++++++++
 .../docker/dockerfiles/debian-hexagon-cross.docker |   1 +
 tests/tcg/configure.sh                             |   4 +
 4 files changed, 164 insertions(+)
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker
 create mode 100755 tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh
 create mode 100644 tests/docker/dockerfiles/debian-hexagon-cross.docker

...

tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh line 39

Quoted 9 lines
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh new file +9 -0
+build_llvm_clang() {
+  fetch "$BASE/llvm-project" "$LLVM_URL"
+  cdp "$BASE/build-llvm"
+
+  cmake -G Ninja \
+    -DCMAKE_BUILD_TYPE=Release \
+    -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_INSTALL} \
+    -DLLVM_ENABLE_LLD=ON \
+    -DLLVM_TARGETS_TO_BUILD="X86;Hexagon" \

Is the X86 target really required?

Quoted 17 lines
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh new file +17 -0
+    -DLLVM_ENABLE_PROJECTS="clang;lld" \
+    "$BASE/llvm-project/llvm"
+  ninja all install
+  cd ${TOOLCHAIN_BIN}
+  ln -sf clang hexagon-unknown-linux-musl-clang
+  ln -sf clang++ hexagon-unknown-linux-musl-clang++
+  ln -sf llvm-ar hexagon-unknown-linux-musl-ar
+  ln -sf llvm-objdump hexagon-unknown-linux-musl-objdump
+  ln -sf llvm-objcopy hexagon-unknown-linux-musl-objcopy
+  ln -sf llvm-readelf hexagon-unknown-linux-musl-readelf
+  ln -sf llvm-ranlib hexagon-unknown-linux-musl-ranlib
+
+  # workaround for now:
+  cat <<EOF > hexagon-unknown-linux-musl.cfg
+-G0 --sysroot=${HEX_SYSROOT}
+EOF
+}
#93 lore raw

RE: [PATCH v8 35/35] Add Dockerfile for hexagon

Quoted 30 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Saturday, February 27, 2021 8:10 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Fam Zheng <[email protected]>
Subject: [EXT] Re: [PATCH v8 35/35] Add Dockerfile for hexagon

Quoted 7 lines · Taylor Simpson

From: Alessandro Di Federico <[email protected]>

---
 .../debian-hexagon-cross-build-local.docker        |  18 +++
 .../debian-hexagon-cross.build-toolchain.sh        | 141

+++++++++++++++++++++

Quoted 9 lines
 .../docker/dockerfiles/debian-hexagon-cross.docker |   1 +
 tests/tcg/configure.sh                             |   4 +
 4 files changed, 164 insertions(+)
 create mode 100644
tests/docker/dockerfiles/debian-hexagon-cross-build-local.docker
 create mode 100755
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh
 create mode 100644

tests/docker/dockerfiles/debian-hexagon-cross.docker

...

Quoted 11 lines

tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh line 39

Quoted 9 lines
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh new file +9 -0
+build_llvm_clang() {
+  fetch "$BASE/llvm-project" "$LLVM_URL"
+  cdp "$BASE/build-llvm"
+
+  cmake -G Ninja \
+    -DCMAKE_BUILD_TYPE=Release \
+    -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_INSTALL} \
+    -DLLVM_ENABLE_LLD=ON \
+    -DLLVM_TARGETS_TO_BUILD="X86;Hexagon" \

Is the X86 target really required?

No, it isn't. When I was developing this recipe it was useful to have as another backend to compare against. Also many of the tests of target-independent functionality require the x86 backend, so it was useful during experimentation to check for regressions.

Quoted 17 lines
Quoted 17 lines
tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh new file +17 -0
+    -DLLVM_ENABLE_PROJECTS="clang;lld" \
+    "$BASE/llvm-project/llvm"
+  ninja all install
+  cd ${TOOLCHAIN_BIN}
+  ln -sf clang hexagon-unknown-linux-musl-clang  ln -sf clang++
+ hexagon-unknown-linux-musl-clang++
+  ln -sf llvm-ar hexagon-unknown-linux-musl-ar  ln -sf llvm-objdump
+ hexagon-unknown-linux-musl-objdump
+  ln -sf llvm-objcopy hexagon-unknown-linux-musl-objcopy
+  ln -sf llvm-readelf hexagon-unknown-linux-musl-readelf
+  ln -sf llvm-ranlib hexagon-unknown-linux-musl-ranlib
+
+  # workaround for now:
+  cat <<EOF > hexagon-unknown-linux-musl.cfg
+-G0 --sysroot=${HEX_SYSROOT}
+EOF
+}
#94 lore raw
In reply to Taylor Simpson
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH v8 00/35] Hexagon patch series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
e71959e Add Dockerfile for hexagon
b7e8432 Hexagon build infrastructure
1fd178a Hexagon (tests/tcg/hexagon) TCG tests - floating point
89d3999 Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc a9c3ca4 Hexagon (tests/tcg/hexagon) TCG tests - multiarch
2c9a909 Hexagon (linux-user/hexagon) Linux user emulation
ab1632c Hexagon (target/hexagon) translation
eb45c4f Hexagon (target/hexagon) TCG for floating point instructions 184b3ac Hexagon (target/hexagon) TCG for instructions with multiple definitions d896de8 Hexagon (target/hexagon) TCG generation
5feb00b Hexagon (target/hexagon) instruction classes
9f9870a Hexagon (target/hexagon) macros
188798c Hexagon (target/hexagon) opcode data structures
ebb5188 Hexagon (target/hexagon) generater phase 4 - decode tree a4398ec Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree 94f0367 Hexagon (target/hexagon) generator phase 2 - generate header files a873166 Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics 4fa249a Hexagon (target/hexagon/imported) arch import
269dad9 Hexagon (target/hexagon/fma_emu.[ch]) utility functions a705db0 Hexagon (target/hexagon/conv_emu.[ch]) utility functions d30061a Hexagon (target/hexagon/arch.[ch]) utility functions
1024159 Hexagon (target/hexagon) instruction printing
dd519a9 Hexagon (target/hexagon) instruction/packet decode
3bb8d3d Hexagon (target/hexagon) instruction attributes
3f802d0 Hexagon (target/hexagon) register fields
e6475ae Hexagon (target/hexagon) instruction and packet types
f810506 Hexagon (target/hexagon) architecture types
0da2919 Hexagon (target/hexagon) GDB Stub
6f8acae Hexagon (target/hexagon) scalar core helpers
9266519 Hexagon (target/hexagon) register names
f5f4022 Hexagon (disas) disassembler
a0c1b3d Hexagon (target/hexagon) scalar core definition
a13b56a Hexagon (include/elf.h) ELF machine definition
fdbf072 Hexagon (target/hexagon) README
e088d0c Hexagon Update MAINTAINERS file

=== OUTPUT BEGIN ===
1/35 Checking commit e088d0c1088a (Hexagon Update MAINTAINERS file) 2/35 Checking commit fdbf072e162e (Hexagon (target/hexagon) README)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

total: 0 errors, 1 warnings, 235 lines checked

Patch 2/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/35 Checking commit a13b56a21bd4 (Hexagon (include/elf.h) ELF machine definition) 4/35 Checking commit a0c1b3d3d63d (Hexagon (target/hexagon) scalar core definition)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #20:
new file mode 100644

total: 0 errors, 1 warnings, 599 lines checked

Patch 4/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/35 Checking commit f5f4022b1301 (Hexagon (disas) disassembler)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #22:
new file mode 100644

total: 0 errors, 1 warnings, 79 lines checked

Patch 5/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/35 Checking commit 92665197bcd8 (Hexagon (target/hexagon) register names)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

total: 0 errors, 1 warnings, 83 lines checked

Patch 6/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
7/35 Checking commit 6f8acae0a07b (Hexagon (target/hexagon) scalar core helpers)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100644

total: 0 errors, 1 warnings, 1152 lines checked

Patch 7/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/35 Checking commit 0da2919872fa (Hexagon (target/hexagon) GDB Stub)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #19:
new file mode 100644

total: 0 errors, 1 warnings, 55 lines checked

Patch 8/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
9/35 Checking commit f81050687616 (Hexagon (target/hexagon) architecture types)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

total: 0 errors, 1 warnings, 38 lines checked

Patch 9/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
10/35 Checking commit e6475ae026f9 (Hexagon (target/hexagon) instruction and packet types)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #17:
new file mode 100644

total: 0 errors, 1 warnings, 74 lines checked

Patch 10/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/35 Checking commit 3f802d0701f4 (Hexagon (target/hexagon) register fields)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #84: FILE: target/hexagon/reg_fields.h:29:
+#define DEF_REG_FIELD(TAG, START, WIDTH) \
+ TAG,

total: 1 errors, 1 warnings, 104 lines checked

Patch 11/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

12/35 Checking commit 3bb8d3d83bc5 (Hexagon (target/hexagon) instruction attributes)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #45: FILE: target/hexagon/attribs.h:25:
+#define DEF_ATTRIB(NAME, ...) A_##NAME,

total: 1 errors, 1 warnings, 132 lines checked

Patch 12/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

13/35 Checking commit dd519a99ef6f (Hexagon (target/hexagon) instruction/packet decode)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #26:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #131: FILE: target/hexagon/decode.c:101:
+#define DECODE_SEPARATOR_BITS(START, WIDTH) NULL, START, WIDTH

ERROR: Macros with multiple statements should be enclosed in a do - while loop #637: FILE: target/hexagon/decode.c:607:
+#define DECODE_OPINFO(TAG, BEH) \
+ case TAG: \
+ { BEH } \
+ break; \
+

total: 2 errors, 1 warnings, 989 lines checked

Patch 13/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

14/35 Checking commit 102415937a11 (Hexagon (target/hexagon) instruction printing)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

ERROR: Macros with multiple statements should be enclosed in a do - while loop #63: FILE: target/hexagon/printinsn.c:43:
+#define DEF_PRINTINFO(TAG, FMT, ...) \
+ case TAG: \
+ g_string_append_printf(buf, FMT, __VA_ARGS__); \
+ break;

total: 1 errors, 1 warnings, 173 lines checked

Patch 14/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

15/35 Checking commit d30061ac1775 (Hexagon (target/hexagon/arch.[ch]) utility functions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644

total: 0 errors, 1 warnings, 334 lines checked

Patch 15/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
16/35 Checking commit a705db08f1e8 (Hexagon (target/hexagon/conv_emu.[ch]) utility functions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#15:
new file mode 100644

total: 0 errors, 1 warnings, 208 lines checked

Patch 16/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
17/35 Checking commit 269dad92975c (Hexagon (target/hexagon/fma_emu.[ch]) utility functions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644

ERROR: "foo * bar" should be "foo *bar"
#411: FILE: target/hexagon/fma_emu.c:392:
+static inline SUFFIX accum_round_##SUFFIX(Accum a, float_status * fp_status) \

WARNING: Block comments use a leading /* on a separate line #415: FILE: target/hexagon/fma_emu.c:396:
+ /* result zero */ \

WARNING: Block comments use a leading /* on a separate line #423: FILE: target/hexagon/fma_emu.c:404:
+ /* Normalize right */ \

WARNING: Block comments use a leading /* on a separate line #424: FILE: target/hexagon/fma_emu.c:405:
+ /* We want MANTBITS bits of mantissa plus the leading one. */ \

WARNING: Block comments use a leading /* on a separate line #425: FILE: target/hexagon/fma_emu.c:406:
+ /* That means that we want MANTBITS+1 bits, or 0x000000000000FF_FFFF */ \

WARNING: Block comments use a leading /* on a separate line #426: FILE: target/hexagon/fma_emu.c:407:
+ /* So we need to normalize right while the high word is non-zero and \

WARNING: Block comments should align the * on each line #427: FILE: target/hexagon/fma_emu.c:408:
+ /* So we need to normalize right while the high word is non-zero and \
+ * while the low word is nonzero when masked with 0xffe0_0000_0000_0000 */ \

WARNING: Block comments use a leading /* on a separate line #432: FILE: target/hexagon/fma_emu.c:413:
+ /* \

WARNING: Block comments use a leading /* on a separate line #442: FILE: target/hexagon/fma_emu.c:423:
+ /* \

WARNING: Block comments use a leading /* on a separate line #449: FILE: target/hexagon/fma_emu.c:430:
+ /* \

WARNING: Block comments use a leading /* on a separate line #458: FILE: target/hexagon/fma_emu.c:439:
+ /* OK, we're relatively canonical... now we need to round */ \

WARNING: Block comments use a leading /* on a separate line #463: FILE: target/hexagon/fma_emu.c:444:
+ /* Chop and we're done */ \

WARNING: Block comments use a leading /* on a separate line #477: FILE: target/hexagon/fma_emu.c:458:
+ /* round up if guard is 1, down if guard is zero */ \

WARNING: Block comments use a leading /* on a separate line #480: FILE: target/hexagon/fma_emu.c:461:
+ /* exactly .5, round up if odd */ \

WARNING: Block comments use a leading /* on a separate line #486: FILE: target/hexagon/fma_emu.c:467:
+ /* \

WARNING: Block comments use a leading /* on a separate line #495: FILE: target/hexagon/fma_emu.c:476:
+ /* Overflow? */ \

WARNING: Block comments use a leading /* on a separate line #497: FILE: target/hexagon/fma_emu.c:478:
+ /* Yep, inf result */ \

WARNING: Block comments use a leading /* on a separate line #519: FILE: target/hexagon/fma_emu.c:500:
+ /* Underflow? */ \

WARNING: Block comments use a leading /* on a separate line #521: FILE: target/hexagon/fma_emu.c:502:
+ /* Leading one means: No, we're normal. So, we should be done... */ \

total: 1 errors, 19 warnings, 738 lines checked

Patch 17/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

18/35 Checking commit 4fa249aec3d1 (Hexagon (target/hexagon/imported) arch import)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #44:
new file mode 100644

total: 0 errors, 1 warnings, 9236 lines checked

Patch 18/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
19/35 Checking commit a8731661ffe1 (Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#21:
new file mode 100644

ERROR: suspicious ; after while (0)
#86: FILE: target/hexagon/gen_semantics.c:61:
+ } while (0);

total: 1 errors, 1 warnings, 88 lines checked

Patch 19/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

20/35 Checking commit 94f03677e802 (Hexagon (target/hexagon) generator phase 2 - generate header files)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#44:
new file mode 100755

WARNING: line over 80 characters
#995: FILE: target/hexagon/gen_tcg_funcs.py:53:
+ f.write(" tcg_gen_mov_tl(hex_new_value[%s + 1], hex_gpr[%s + 1]);\n" % \

WARNING: line over 80 characters
#1076: FILE: target/hexagon/gen_tcg_funcs.py:134:
+ f.write(" TCGv %s%sN = hex_new_pred_value[insn->regno[%d]];\n" % \

WARNING: line over 80 characters
#1158: FILE: target/hexagon/gen_tcg_funcs.py:216:
+ f.write(" hex_gpr[%s%sN + 1]);\n" % \

WARNING: line over 80 characters
#1235: FILE: target/hexagon/gen_tcg_funcs.py:293:
+ f.write(" gen_log_predicated_reg_write_pair(%s%sN, %s%sV, insn->slot);\n" % \

total: 0 errors, 5 warnings, 1565 lines checked

Patch 20/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
21/35 Checking commit a4398ec594ee (Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#19:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #68: FILE: target/hexagon/gen_dectree_import.c:45:
+#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+ [TAG] = BEH,

ERROR: Macros with complex values should be enclosed in parenthesis #70: FILE: target/hexagon/gen_dectree_import.c:47:
+#define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
+ [TAG] = BEH,

ERROR: Macros with complex values should be enclosed in parenthesis #78: FILE: target/hexagon/gen_dectree_import.c:55:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,

ERROR: Macros with complex values should be enclosed in parenthesis #87: FILE: target/hexagon/gen_dectree_import.c:64:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,

ERROR: suspicious ; after while (0)
#184: FILE: target/hexagon/gen_dectree_import.c:161:
+ } while (0);

total: 5 errors, 1 warnings, 188 lines checked

Patch 21/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

22/35 Checking commit ebb5188d1866 (Hexagon (target/hexagon) generater phase 4 - decode tree)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#16:
new file mode 100755

total: 0 errors, 1 warnings, 351 lines checked

Patch 22/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
23/35 Checking commit 188798c0543e (Hexagon (target/hexagon) opcode data structures)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #60: FILE: target/hexagon/opcodes.c:41:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) REGINFO,

ERROR: Macros with complex values should be enclosed in parenthesis #70: FILE: target/hexagon/opcodes.c:51:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,

ERROR: Macros with complex values should be enclosed in parenthesis #80: FILE: target/hexagon/opcodes.c:61:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,

ERROR: Macros with complex values should be enclosed in parenthesis #88: FILE: target/hexagon/opcodes.c:69:
+#define DEF_SHORTCODE(TAG, SHORTCODE) [TAG] = #SHORTCODE,

ERROR: Macros with complex values should be enclosed in parenthesis #127: FILE: target/hexagon/opcodes.c:108:
+#define ATTRIBS(...) , ## __VA_ARGS__, 0

total: 5 errors, 1 warnings, 200 lines checked

Patch 23/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

24/35 Checking commit 9f9870a235a6 (Hexagon (target/hexagon) macros)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #17:
new file mode 100644

total: 0 errors, 1 warnings, 592 lines checked

Patch 24/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
25/35 Checking commit 5feb00be6a48 (Hexagon (target/hexagon) instruction classes)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100644

ERROR: Macros with complex values should be enclosed in parenthesis #45: FILE: target/hexagon/iclass.c:23:
+#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) \
+ [ICLASS_FROM_TYPE(TYPE)] = SLOTS_##SLOTS,

ERROR: Macros with complex values should be enclosed in parenthesis #47: FILE: target/hexagon/iclass.c:25:
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) \
+ [ICLASS_FROM_TYPE(TYPE)] = SLOTS_##SLOTS,

ERROR: Macros with complex values should be enclosed in parenthesis #128: FILE: target/hexagon/iclass.h:27:
+#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) ICLASS_FROM_TYPE(TYPE),

ERROR: Macros with complex values should be enclosed in parenthesis #129: FILE: target/hexagon/iclass.h:28:
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) ICLASS_FROM_TYPE(TYPE),

total: 4 errors, 1 warnings, 174 lines checked

Patch 25/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

26/35 Checking commit d896de82dff6 (Hexagon (target/hexagon) TCG generation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #17:
new file mode 100644

total: 0 errors, 1 warnings, 356 lines checked

Patch 26/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
27/35 Checking commit 184b3ac19881 (Hexagon (target/hexagon) TCG for instructions with multiple definitions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#17:
new file mode 100644

total: 0 errors, 1 warnings, 198 lines checked

Patch 27/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
28/35 Checking commit eb45c4f8ec61 (Hexagon (target/hexagon) TCG for floating point instructions) 29/35 Checking commit ab1632cff2fb (Hexagon (target/hexagon) translation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#21:
new file mode 100644

total: 0 errors, 1 warnings, 841 lines checked

Patch 29/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
30/35 Checking commit 2c9a909e8e24 (Hexagon (linux-user/hexagon) Linux user emulation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #59:
new file mode 100644

ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #139: FILE: linux-user/hexagon/cpu_loop.c:76:
+ EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",

total: 1 errors, 1 warnings, 1040 lines checked

Patch 30/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

31/35 Checking commit a9c3ca4cce6f (Hexagon (tests/tcg/hexagon) TCG tests - multiarch)
ERROR: line over 90 characters
#38: FILE: tests/tcg/configure.sh:99:
+ alpha|cris|hexagon|hppa|i386|lm32|microblaze|microblazeel|m68k|openrisc|riscv64|s390x|sh4|sparc64)

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #43:
new file mode 100644

total: 1 errors, 1 warnings, 1562 lines checked

Patch 31/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

32/35 Checking commit 89d39998fc4d (Hexagon (tests/tcg/hexagon) TCG tests - atomics/load/store/misc)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#43:
new file mode 100644

total: 0 errors, 1 warnings, 1150 lines checked

Patch 32/35 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
33/35 Checking commit 1fd178ab9634 (Hexagon (tests/tcg/hexagon) TCG tests - floating point)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #26:
new file mode 100644

total: 0 errors, 1 warnings, 376 lines checked

Patch 33/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
34/35 Checking commit b7e8432b75a4 (Hexagon build infrastructure)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #28:
new file mode 100644

WARNING: line over 80 characters
#63: FILE: scripts/qemu-binfmt-conf.sh:139:
+hexagon_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xa4\x00'

ERROR: line over 90 characters
#64: FILE: scripts/qemu-binfmt-conf.sh:140:
+hexagon_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'

total: 1 errors, 2 warnings, 226 lines checked

Patch 34/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

35/35 Checking commit e71959ea0fe8 (Add Dockerfile for hexagon)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100644

WARNING: line over 80 characters
#109: FILE: tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh:63:
+ -DCMAKE_ASM_FLAGS="-G0 -mlong-calls -fno-pic --target=hexagon-unknown-linux-musl " \

ERROR: line over 90 characters
#136: FILE: tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh:90:
+ CROSS_CFLAGS="-G0 -O0 -mv65 -fno-builtin -fno-rounding-math --target=hexagon-unknown-linux-musl" \

ERROR: line over 90 characters
#173: FILE: tests/docker/dockerfiles/debian-hexagon-cross.build-toolchain.sh:127:
+ CFLAGS="-G0 -O0 -mv65 -fno-builtin -fno-rounding-math --target=hexagon-unknown-linux-musl" \

total: 2 errors, 2 warnings, 170 lines checked

Patch 35/35 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#95 lore raw
In reply to Taylor Simpson
Quoted 11 lines · Taylor Simpson

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

See patch 02 Hexagon README for detailed information.

This series assumes int128_or() is implemented.
https://lists.nongnu.org/archive/html/qemu-devel/2020-10/msg06004.html

The series is also available at https://github.com/quic/qemu on branch small_series_v8.

Quoted 8 lines

Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.

The final patch in the series add docker support. Thanks to Alessandro Di Federico <[email protected]> and Brian Cain <[email protected]> for making this happen. The default container (debian-hexagon-cross) uses a toolchain built by rev.ng. Alternatively, there is a container that will build the toolchain locally (debian-hexagon-cross-build-local).

Right. This is in really good shape.

I've completed review of this round, and there are some nits. But they're minor enough that I wouldn't even mind them being addressed via the normal development process. I.e. I'd be keen to not look through that diffstat again.
;-)

Any objections from anyone else on that?

I don't suppose you and Peter Maydell signed gpg keys when we all met in Lyon?

r~

#96 lore raw
Quoted 11 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, February 14, 2021 7:23 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Peter Maydell <[email protected]>
Subject: Re: [PATCH v8 00/35] Hexagon patch series

Quoted 8 lines
Quoted 7 lines · Taylor Simpson

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

See patch 02 Hexagon README for detailed information.

This series assumes int128_or() is implemented.
https://lists.nongnu.org/archive/html/qemu-devel/2020-10/msg06004.html

What's the status of this patch? Could you go ahead and merge it ahead of the rest of the series that it's in?

Quoted 12 lines
Quoted 6 lines

Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.

The final patch in the series add docker support. Thanks to Alessandro Di Federico <[email protected]> and Brian Cain <[email protected]> for making

this

Quoted 1 line

happen. The default container (debian-hexagon-cross) uses a toolchain

built

Quoted 2 lines

by rev.ng. Alternatively, there is a container that will build the toolchain locally (debian-hexagon-cross-build-local).

Quoted 7 lines

Right. This is in really good shape.

I've completed review of this round, and there are some nits. But they're minor enough that I wouldn't even mind them being addressed via the normal
development process. I.e. I'd be keen to not look through that diffstat again.
;-)

Thanks Richard!! We're having unprecedented winter weather in Austin, so I'll address your latest feedback once our datacenter recovers from a power outage.

Quoted 5 lines

Any objections from anyone else on that?

I don't suppose you and Peter Maydell signed gpg keys when we all met in Lyon?

Nope. Peter, please advise

#97 lore raw
Quoted 8 lines · Taylor Simpson
Quoted 7 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
I've completed review of this round, and there are some nits. But they're minor enough that I wouldn't even mind them being addressed via the normal
development process. I.e. I'd be keen to not look through that diffstat again.
;-)

Quoted 6 lines
Quoted 4 lines

Any objections from anyone else on that?

I don't suppose you and Peter Maydell signed gpg keys when we all met in Lyon?

Nope. Peter, please advise

We effectively are operating a TOFU policy for gpg keys, ie put them on a public keyserver, to the extent that you can arrange to get them signed by other people who also have gpg keys please do, and at some point we may be able to meet up and get a shorter trust path.

For this patchset, I would prefer it if Richard collected the patches and sent me a pullrequest. First pullrequests from new submaintainers are higher-effort for me, because I need to look them through carefully to be sure that they're the right format and so on; so I'd rather not do that with an enormous patchset. It's easier for me if that work is postponed and done with something smaller later.

thanks
-- PMM

#98 lore raw
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Taylor Simpson
Quoted 9 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
I've completed review of this round, and there are some nits. But they're minor enough that I wouldn't even mind them being addressed via the normal
development process. I.e. I'd be keen to not look through that diffstat again.
;-)

Any objections from anyone else on that?

I'm very pleased with how this series evolved over the time, and Taylor interaction with the community during the long review process.

Patches 1-34 are OK but I don't think patch 35 (Dockerfile hexagon) should enter mainstream that way. It probably makes sense to add it along with the CI testing job (missing so far).

Patch 30 (Linux user emulation) could have an Acked-by from Laurent.

Also, while having TCG unit tests is great, it doesn't replace integration tests using real world binaries. So personally I'd like to be able to test an Hexagon BusyBox, ideally one coming from the official Hexagon distribution (extracted from the SDK). We talked about this and Brian will probably share it.

Whole series tested it on x86, so:

(I still plan to test it on big-endian host)

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I don't suppose you and Peter Maydell signed gpg keys when we all met in Lyon?

Nope. Peter, please advise

We effectively are operating a TOFU policy for gpg keys, ie put them on a public keyserver, to the extent that you can arrange to get them signed by other people who also have gpg keys please do, and at some point we may be able to meet up and get a shorter trust path.

Quoted 6 lines

For this patchset, I would prefer it if Richard collected the patches and sent me a pullrequest. First pullrequests from new submaintainers are higher-effort for me, because I need to look them through carefully to be sure that they're the right format and so on; so I'd rather not do that with an enormous patchset. It's easier for me if that work is postponed and done with something smaller later.

Ahah I just suggested to Taylor to look at your previous explanation before reading the same explanation here :)
https://www.mail-archive.com/[email protected]/msg765788.html

Regards,

Phil.

#99 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé

I'm very pleased with how this series evolved over the time, and Taylor interaction with the community during the long review process.

Patches 1-34 are OK but I don't think patch 35 (Dockerfile hexagon) should enter mainstream that way. It probably makes sense to add it along with the CI testing job (missing so far).

Ok, I'll drop 35 from the initial pull,

Quoted 1 line

Patch 30 (Linux user emulation) could have an Acked-by from Laurent.

and wait a couple of days more for this. But without, I'll send the PR on the weekend.

Quoted 3 lines

Whole series tested it on x86, so:

(I still plan to test it on big-endian host)

Thanks.

r~

#100 lore raw
In reply to Taylor Simpson
Quoted 5 lines · Taylor Simpson
Quoted 3 lines
Quoted 3 lines

This series assumes int128_or() is implemented.
https://lists.nongnu.org/archive/html/qemu-devel/2020-10/msg06004.html

What's the status of this patch? Could you go ahead and merge it ahead of the rest of the series that it's in?

The fp patch set that created this patch has been rewritten and no longer uses it. I'll queue this to the branch that will include this pull.

r~