Hexagon patch series
v3 cover Hexagon patch series
This series adds support for the Hexagon processor with Linux user support
See patch 02/34 Hexagon README for detailed information.
Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.
We have a parallel effort to make the Hexagon Linux toolchain inside a docker container publically available.
*** Future items under consideration ***
Use qemu softfloat
Use qemu decodetree
*** 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/q6v_decode.c Macro needs do - while
target/hexagon/printinsn.c Macro needs do - while
target/hexagon/gen_semantics.c Suspicious ; after while (0) target/hexagon/gen_dectree_import.c Complex macro target/hexagon/gen_dectree_import.c Suspicious ; after while (0)
target/hexagon/opcodes.c Complex macro
target/hexagon/iclass.h Complex macro
scripts/qemu-binfmt-conf.sh Line over 90 characters
The following are known checkpatch warnings in the series
target/hexagon/fma_emu.c Comments inside macro definition
scripts/qemu-binfmt-conf.sh Line over 80 characters
*** Changes in 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
Rework the python scripts to generate one header file at a time Change fWRAP_* macros to fGEN_TCG_*
*** Changes in v2 ***
- Use scripts/git.orderfile
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 (target/hexagon) register names
Hexagon (disas) disassembler
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) register map
Hexagon (target/hexagon) instruction/packet decode
Hexagon (target/hexagon) instruction printing
Hexagon (target/hexagon) utility functions
Hexagon (target/hexagon/imported) arch import - macro definitions Hexagon (target/hexagon/imported) arch import - instruction semantics Hexagon (target/hexagon/imported) arch import - instruction encoding 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 to interface with the generator Hexagon (target/hexagon) macros referenced in instruction semantics Hexagon (target/hexagon) instruction classes
Hexagon (target/hexagon) TCG generation helpers
Hexagon (target/hexagon) TCG generation
Hexagon (target/hexagon) TCG for instructions with multiple
definitions
Hexagon (target/hexagon) translation
Hexagon (linux-user/hexagon) Linux user emulation
Hexagon (tests/tcg/hexagon) TCG tests
Hexagon build infrastructure
configure | 9 + default-configs/hexagon-linux-user.mak | 1 + include/disas/dis-asm.h | 1 + include/elf.h | 2 + linux-user/hexagon/sockbits.h | 18 + linux-user/hexagon/syscall_nr.h | 343 +++++ 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 | 46 + linux-user/hexagon/target_syscall.h | 32 + linux-user/hexagon/termbits.h | 18 + linux-user/syscall_defs.h | 33 + target/hexagon/arch.h | 42 + target/hexagon/attribs.h | 32 + target/hexagon/attribs_def.h | 98 ++ target/hexagon/conv_emu.h | 50 + target/hexagon/cpu-param.h | 26 + target/hexagon/cpu.h | 164 +++ target/hexagon/cpu_bits.h | 34 + target/hexagon/decode.h | 39 + target/hexagon/fma_emu.h | 27 + target/hexagon/gen_tcg.h | 198 +++ target/hexagon/genptr.h | 25 + target/hexagon/genptr_helpers.h | 244 ++++ target/hexagon/helper.h | 35 + target/hexagon/hex_arch_types.h | 43 + target/hexagon/hex_regs.h | 83 ++ target/hexagon/iclass.h | 46 + target/hexagon/insn.h | 75 + target/hexagon/internal.h | 42 + target/hexagon/macros.h | 982 +++++++++++++ target/hexagon/opcodes.h | 66 + target/hexagon/printinsn.h | 26 + target/hexagon/reg_fields.h | 40 + target/hexagon/reg_fields_def.h | 78 + target/hexagon/regmap.h | 38 + target/hexagon/translate.h | 103 ++ disas/hexagon.c | 62 + linux-user/elfload.c | 16 + linux-user/hexagon/cpu_loop.c | 99 ++ linux-user/hexagon/signal.c | 276 ++++ linux-user/syscall.c | 2 + target/hexagon/arch.c | 354 +++++ target/hexagon/conv_emu.c | 369 +++++ target/hexagon/cpu.c | 318 +++++ target/hexagon/decode.c | 593 ++++++++ target/hexagon/fma_emu.c | 781 ++++++++++ target/hexagon/gdbstub.c | 49 + target/hexagon/gen_dectree_import.c | 191 +++ target/hexagon/gen_semantics.c | 88 ++ target/hexagon/genptr.c | 56 + target/hexagon/iclass.c | 88 ++ target/hexagon/op_helper.c | 365 +++++ target/hexagon/opcodes.c | 211 +++ target/hexagon/printinsn.c | 94 ++ target/hexagon/q6v_decode.c | 373 +++++ target/hexagon/reg_fields.c | 28 + target/hexagon/translate.c | 730 ++++++++++ tests/tcg/hexagon/atomics.c | 122 ++ tests/tcg/hexagon/clrtnew.c | 56 + tests/tcg/hexagon/dual_stores.c | 60 + tests/tcg/hexagon/exec_counters.c | 57 + tests/tcg/hexagon/mem_noshuf.c | 291 ++++ tests/tcg/hexagon/misc.c | 293 ++++ tests/tcg/hexagon/preg_alias.c | 106 ++ tests/tcg/hexagon/pthread_cancel.c | 43 + tests/tcg/hexagon/sfminmax.c | 62 + MAINTAINERS | 8 + disas/Makefile.objs | 1 + scripts/gensyscalls.sh | 3 +- scripts/qemu-binfmt-conf.sh | 6 +- target/hexagon/Makefile.objs | 203 +++ target/hexagon/README | 254 ++++ target/hexagon/dectree.py | 352 +++++ target/hexagon/gen_helper_funcs.py | 230 +++ target/hexagon/gen_helper_protos.py | 158 +++ target/hexagon/gen_op_attribs.py | 46 + target/hexagon/gen_op_regs.py | 119 ++ target/hexagon/gen_opcodes_def.py | 43 + target/hexagon/gen_printinsn.py | 182 +++ target/hexagon/gen_shortcode.py | 71 + target/hexagon/gen_tcg_funcs.py | 301 ++++ target/hexagon/hex_common.py | 204 +++ target/hexagon/imported/allidefs.def | 30 + target/hexagon/imported/alu.idef | 1259 +++++++++++++++++ target/hexagon/imported/branch.idef | 328 +++++ target/hexagon/imported/compare.idef | 621 ++++++++ target/hexagon/imported/encode.def | 125 ++ target/hexagon/imported/encode_pp.def | 2110 ++++++++++++++++++++++++++++ target/hexagon/imported/encode_subinsn.def | 150 ++ target/hexagon/imported/float.idef | 313 +++++ target/hexagon/imported/iclass.def | 52 + target/hexagon/imported/ldst.idef | 286 ++++ target/hexagon/imported/macros.def | 1529 ++++++++++++++++++++ target/hexagon/imported/mpy.idef | 1212 ++++++++++++++++ target/hexagon/imported/shift.idef | 1067 ++++++++++++++ target/hexagon/imported/subinsns.idef | 152 ++ target/hexagon/imported/system.idef | 69 + tests/tcg/configure.sh | 4 +- tests/tcg/hexagon/Makefile.target | 49 + tests/tcg/hexagon/first.S | 57 + tests/tcg/hexagon/float_convs.ref | 748 ++++++++++ tests/tcg/hexagon/float_madds.ref | 768 ++++++++++ 105 files changed, 22615 insertions(+), 3 deletions(-) create mode 100644 default-configs/hexagon-linux-user.mak create mode 100644 linux-user/hexagon/sockbits.h create mode 100644 linux-user/hexagon/syscall_nr.h create mode 100644 linux-user/hexagon/target_cpu.h create mode 100644 linux-user/hexagon/target_elf.h create mode 100644 linux-user/hexagon/target_fcntl.h create mode 100644 linux-user/hexagon/target_signal.h create mode 100644 linux-user/hexagon/target_structs.h create mode 100644 linux-user/hexagon/target_syscall.h create mode 100644 linux-user/hexagon/termbits.h create mode 100644 target/hexagon/arch.h create mode 100644 target/hexagon/attribs.h create mode 100644 target/hexagon/attribs_def.h create mode 100644 target/hexagon/conv_emu.h create mode 100644 target/hexagon/cpu-param.h create mode 100644 target/hexagon/cpu.h create mode 100644 target/hexagon/cpu_bits.h create mode 100644 target/hexagon/decode.h create mode 100644 target/hexagon/fma_emu.h create mode 100644 target/hexagon/gen_tcg.h create mode 100644 target/hexagon/genptr.h create mode 100644 target/hexagon/genptr_helpers.h create mode 100644 target/hexagon/helper.h create mode 100644 target/hexagon/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/reg_fields_def.h create mode 100644 target/hexagon/regmap.h create mode 100644 target/hexagon/translate.h create mode 100644 disas/hexagon.c create mode 100644 linux-user/hexagon/cpu_loop.c create mode 100644 linux-user/hexagon/signal.c create mode 100644 target/hexagon/arch.c create mode 100644 target/hexagon/conv_emu.c create mode 100644 target/hexagon/cpu.c create mode 100644 target/hexagon/decode.c create mode 100644 target/hexagon/fma_emu.c create mode 100644 target/hexagon/gdbstub.c create mode 100644 target/hexagon/gen_dectree_import.c create mode 100644 target/hexagon/gen_semantics.c create mode 100644 target/hexagon/genptr.c create mode 100644 target/hexagon/iclass.c create mode 100644 target/hexagon/op_helper.c create mode 100644 target/hexagon/opcodes.c create mode 100644 target/hexagon/printinsn.c create mode 100644 target/hexagon/q6v_decode.c create mode 100644 target/hexagon/reg_fields.c create mode 100644 target/hexagon/translate.c create mode 100644 tests/tcg/hexagon/atomics.c create mode 100644 tests/tcg/hexagon/clrtnew.c create mode 100644 tests/tcg/hexagon/dual_stores.c create mode 100644 tests/tcg/hexagon/exec_counters.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/pthread_cancel.c create mode 100644 tests/tcg/hexagon/sfminmax.c create mode 100644 target/hexagon/Makefile.objs create mode 100644 target/hexagon/README create mode 100755 target/hexagon/dectree.py create mode 100755 target/hexagon/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_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 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
RFC PATCH v3 1/34 Hexagon Update MAINTAINERS file
Add Taylor Simpson as the Hexagon target maintainer
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -184,6 +184,14 @@ F: include/hw/cris/ F: tests/tcg/cris/ F: disas/cris.c +Hexagon TCG CPUs +M: Taylor Simpson <[email protected]> +S: Supported +F: target/hexagon/ +F: linux-user/hexagon/ +F: disas/hexagon.c +F: default-configs/hexagon-linux-user.mak + HPPA (PA-RISC) TCG CPUs M: Richard Henderson <[email protected]> S: Maintained
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 01/34] Hexagon Update MAINTAINERS file
Quoted 6 lines · Taylor Simpson
Add Taylor Simpson as the Hexagon target maintainer
Signed-off-by Taylor Simpson <[email protected]>--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
r~
RFC PATCH v3 2/34 Hexagon (target/hexagon) README
In reply to Taylor SimpsonGives an introduction and overview to the Hexagon target
--- target/hexagon/README | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 target/hexagon/README
target/hexagon/README new file +254 -0
@@ -0,0 +1,254 @@ +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>/hexagon-linux-user/semantics_generated.pyinc. +That file is consumed by the following python scripts to produce the indicated +header files in <BUILD_DIR>/hexagon-linux-user + gen_shortcode.py -> shortcode_generated.h + gen_helper_protos.py -> helper_protos_generated.h + gen_tcg_funcs.py -> tcg_funcs_generated.h + gen_helper_funcs.py -> helper_funcs_generated.h + +Qemu helper functions have 3 parts + DEF_HELPER declaration indicates the signature of the helper + gen_helper_<NAME> will generate a TCG call to the helper function + The helper implementation + +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 + #ifndef fGEN_TCG_A2_add + DEF_HELPER_3(A2_add, s32, env, s32, s32) + #endif + +tcg_funcs_generated.h + DEF_TCG_FUNC(A2_add, /* { RdV=RsV+RtV;} */ + { + /* A2_add */ + DECL_RREG_d(RdV, RdN, 0, 0); + DECL_RREG_s(RsV, RsN, 1, 0); + DECL_RREG_t(RtV, RtN, 2, 0); + READ_RREG_s(RsV, RsN); + READ_RREG_t(RtV, RtN); + #ifdef fGEN_TCG_A2_add + fGEN_TCG_A2_add({ RdV=RsV+RtV;}); + #else + do { + gen_helper_A2_add(RdV, cpu_env, RsV, RtV); + } while (0); + #endif + WRITE_RREG_d(RdN, RdV); + FREE_RREG_d(RdV); + FREE_RREG_s(RsV); + FREE_RREG_t(RtV); + /* A2_add */ + }) + +helper_funcs_generated.h + #ifndef fGEN_TCG_A2_add + 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; + } + #endif + +For each operand, there are macros for DECL, FREE, READ, WRITE. These are +defined in macros.h. Note that we append the operand type to the macro name, +which allows us to specialize the TCG code tenerated. For read-only operands, +DECL simply declares the TCGv variable (no need for tcg_temp_local_new()), +and READ will assign from the TCGv corresponding to the GPR, and FREE doesn't +have to do anything. Also, note that the WRITE macros update the disassembly +context to be processed when the packet commits (see "Packet Semantics" below). + +Note the fGEN_TCG_A2_add macro. This macro 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, + #define fGEN_TCG_A2_add(GENHLPR, SHORTCODE) \ + tcg_gen_add_tl(RdV, RsV, RtV) + +The gen_tcg.h file is included twice +1) In genptr.c, it overrides the semantics from tcg_funcs_generated.h +2) In helper.h, it prevents the generation of helpers for overridden + instructions. Notice the #ifndef fGEN_TCG_A2_add above in both + helper_protos_generated.h and helper_functions.h + +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>/hexagon-linux-user/iset.py +This file is imported by target/hexagon/dectree.py to produce + <BUILD_DIR>/hexagon-linux-user/dectree_generated.h + +*** Key Files *** + +cpu.h + +This file contains the definition of the CPUHexagonState struct. It is the +runtime information for each thread and contains stuff like the GPR and +predicate registers. + +macros.h + +The Hexagon arch lib relies heavily on macros for the instruction semantics. +This is a great advantage for qemu because we can override them for different +purposes. You will also notice there are sometimes two definitions of a macro. +The QEMU_GENERATE variable determines whether we want the macro to generate TCG +code. If QEMU_GENERATE is not defined, we want the macro to generate vanilla +C code that will work in the helper implementation. + +translate.c + +The functions in this file generate TCG code for a translation block. Some +important functions in this file are + + gen_start_packet - initialize the data structures for packet semantics + gen_commit_packet - commit the register writes, stores, etc for a packet + decode_packet - disassemble a packet and generate code + +genptr.c +genptr_helpers.h +gen_tcg.h + +These files create a function for each instruction. It is mostly composed of +fGEN_TCG_<tag> definitions followed by including qemu_def_generated.h. The +genptr_helpers.h file contains helper functions that are invoked by the macros +in gen_tcg.h and macros.h + +op_helper.c + +This file contains the implementations of all the helpers. There are a few +general purpose helpers, but most of them are generated by including +qemu_def_generated.h. There are also several helpers used for debugging. + + +*** Packet Semantics *** + +VLIW packet semantics differ from serial semantics in that all input operands +are read, then the operations are performed, then all the results are written. +For exmaple, this packet performs a swap of registers r0 and r1 + { r0 = r1; r1 = r0 } +Note that the result is different if the instructions are executed serially. + +Packet semantics dictate that we defer any changes of state until the entire +packet is committed. We record the results of each instruction in a side data +structure, and update the visible processor state when we commit the packet. + +The data structures are divided between the runtime state and the translation +context. + +During the TCG generation (see translate.[ch]), we use the DisasContext to +track what needs to be done during packet commit. Here are the relevant +fields + + 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
Re: [RFC PATCH v3 02/34] Hexagon (target/hexagon) README
target/hexagon/README line 79
Quoted 6 lines · Taylor Simpson
target/hexagon/README new file +6
-0+ #ifdef fGEN_TCG_A2_add + fGEN_TCG_A2_add({ RdV=RsV+RtV;}); + #else + do { + gen_helper_A2_add(RdV, cpu_env, RsV, RtV); + } while (0);
I don't understand the benefit of passing the SHORTCODE to fGEN_TCG_*. Is this file included for helper generation?
It seems to contradict what you have a few lines lower
target/hexagon/README line 118
Quoted 3 lines
target/hexagon/README new file +3
-0+The gen_tcg.h file has any overrides. For example, + #define fGEN_TCG_A2_add(GENHLPR, SHORTCODE) \ + tcg_gen_add_tl(RdV, RsV, RtV)
which has two arguments not one.
Is this README out of date?
r~
RFC PATCH v3 3/34 Hexagon (include/elf.h) ELF machine definition
In reply to Taylor SimpsonDefine EM_HEXAGON 164
--- include/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/elf.h +2 -0
@@ -172,6 +172,8 @@ typedef struct mips_elf_abiflags_v0 {#define EM_UNICORE32 110/* UniCore32 */ +#define EM_HEXAGON 164/* Qualcomm Hexagon */ +#define EM_RISCV 243/* RISC-V */ #define EM_NANOMIPS 249/* Wave Computing nanoMIPS */
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 03/34] Hexagon (include/elf.h) ELF machine definition
Quoted 8 lines · Taylor Simpson
Define
EM_HEXAGON164Signed-off-by Taylor Simpson <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- include/elf.h | 2 ++ 1 file changed, 2 insertions(+)
r~
RFC PATCH v3 4/34 Hexagon (target/hexagon) scalar core definition
In reply to Taylor SimpsonAdd target state header, target definitions and initialization routines
--- target/hexagon/cpu-param.h | 26 ++++ target/hexagon/cpu.h | 164 +++++++++++++++++++++++ target/hexagon/cpu_bits.h | 34 +++++ target/hexagon/internal.h | 40 ++++++ target/hexagon/cpu.c | 316 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 580 insertions(+) create mode 100644 target/hexagon/cpu-param.h create mode 100644 target/hexagon/cpu.h create mode 100644 target/hexagon/cpu_bits.h create mode 100644 target/hexagon/internal.h create mode 100644 target/hexagon/cpu.c
target/hexagon/cpu-param.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_CPU_PARAM_H +#define HEXAGON_CPU_PARAM_H + +#define TARGET_PHYS_ADDR_SPACE_BITS 36 +#define TARGET_VIRT_ADDR_SPACE_BITS 32 + +#define NB_MMU_MODES 1 + +#endif
target/hexagon/cpu.h new file +164 -0
164 lines not on this page · raw message
target/hexagon/cpu_bits.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_CPU_BITS_H +#define HEXAGON_CPU_BITS_H + +#define HEX_EXCP_FETCH_NO_UPAGE 0x012 +#define HEX_EXCP_INVALID_PACKET 0x015 +#define HEX_EXCP_INVALID_OPCODE 0x015 +#define HEX_EXCP_PRIV_NO_UREAD 0x024 +#define HEX_EXCP_PRIV_NO_UWRITE 0x025 + +#define HEX_EXCP_TRAP0 0x172 + +#define PACKET_WORDS_MAX 4 + +extern int disassemble_hexagon (uint32_t *words,int nwords, +char *buf,int bufsize); + +#endif
target/hexagon/internal.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_INTERNAL_H +#define HEXAGON_INTERNAL_H + +/* +* Change HEX_DEBUG to 1 to turn on debugging output +*/ +#define HEX_DEBUG 0 +#define HEX_DEBUG_LOG (...) \ + do { \ + if (HEX_DEBUG) { \ + rcu_read_lock(); \ + fprintf(stderr, __VA_ARGS__); \ + rcu_read_unlock(); \ + } \ + } while (0) + +extern void hexagon_debug (CPUHexagonState *env); + +extern const char *const hexagon_regnames[TOTAL_PER_THREAD_REGS ]; + +extern void init_genptr (void ); + +#endif
target/hexagon/cpu.c new file +316 -0
316 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 04/34] Hexagon (target/hexagon) scalar core definition
Quoted 1 line · Taylor Simpson
+#include <
fenv.h>
This should not be in cpu.h. What's up?
target/hexagon/cpu.h line 27
Quoted 2 lines
target/hexagon/cpu.h new file +2
-0+#define TARGET_PAGE_BITS 16/* 64K pages */ +#define TARGET_LONG_BITS 32
Belongs in cpu-param.h
Quoted 3 lines
target/hexagon/cpu.h new file +3
-0+#ifdef CONFIG_USER_ONLY +#define TOTAL_PER_THREAD_REGS 64 +#else
...
Quoted 1 line
+
target_ulonggpr[TOTAL_PER_THREAD_REGS];
Do I not understand hexagon enough to know why the number of general registers would vary with system mode? Why is the define conditional on user-only?
target/hexagon/internal.h line 33
Quoted 13 lines
target/hexagon/internal.h new file +13
-0+/* +* Change HEX_DEBUG to 1 to turn on debugging output +*/ +#define HEX_DEBUG 0 +#define HEX_DEBUG_LOG (...) \ + do { \ + if (HEX_DEBUG) { \ + rcu_read_lock(); \ + fprintf(stderr, __VA_ARGS__); \ + rcu_read_unlock(); \ + } \ + } while (0) +
No. There are plenty of bad examples of this in qemu, let's not add another.
First, the lock doesn't do what you think.
Second, stderr is never right.
Third, just about any time you want this, there's a tracepoint that you could add that would be better, correct, and toggleable from the command-line.
Quoted 28 lines
target/hexagon/cpu.c new file +28
-0+/* +* One of the main debugging techniques is to use "-d cpu" and compare against +* LLDB output when single stepping. However, the target and qemu put the +* stacks at different locations. This is used to compensate so the diff is +* cleaner. +*/ +static inline target_ulong hack_stack_ptrs (CPUHexagonState *env, +target_ulong addr) +{ +static bool first = true; +if (first) { + first = false; + env->stack_start = env->gpr[HEX_REG_SP ]; + env->gpr[HEX_REG_USR ] =0x56000 ; + +#define ADJUST_STACK 0 +#if ADJUST_STACK +/* +* Change the two numbers below to +* 1 qemu stack location +* 2 hardware stack location +* Or set to zero for normal mode (no stack adjustment) +*/ + env->stack_adjust =0xfffeeb80 -0xbf89f980 ; +#else + env->stack_adjust =0 ; +#endif + }
target/hexagon/cpu.c line 97
Quoted 10 lines
target/hexagon/cpu.c new file +10
-0+ +target_ulong stack_start = env->stack_start; +target_ulong stack_size =0x10000 ; +target_ulong stack_adjust = env->stack_adjust; + +if (stack_start +0x1000 >= addr && addr >= (stack_start - stack_size)) { +return addr - stack_adjust; + } +return addr; +}
I understand your desire for this sort of comparison. What I don't understand is the method. Surely it would be preferable to actually change the stack location in qemu, rather than constantly adjust for it.
Add a per-target hook to linux-user/hexagon/target_elf.h that controls the allocation of the stack in elfload.c, setup_arg_pages().
target/hexagon/cpu.c line 137
Quoted 12 lines
target/hexagon/cpu.c new file +12
-0+static void hexagon_dump (CPUHexagonState *env,FILE *f) +{ +static target_ulong last_pc; +int i; + +/* +* When comparing with LLDB, it doesn't step through single-cycle +* hardware loops the same way. So, we just skip them here +*/ +if (env->gpr[HEX_REG_PC ] == last_pc) { +return ; + }
Multi-threaded data race. Might as well move last_pc to env->dump_last_pc or something.
But I'd also suggest that all of this lldb compatibility stuff be optional, switchable from the command-line with a cpu property. Because there are going to be real cases where *not* single-stepping will result in dumps from the same PC, and you've just squashed all of those.
Call the property x-lldb-compat, or something, and default it to off. You then turn it on with "-cpu v67,x-lldb-compat=on".
r~
RE: [RFC PATCH v3 04/34] Hexagon (target/hexagon) scalar core definition
Thanks for the feedback, Richard!!
Quoted 9 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 7:36 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 04/34] Hexagon (target/hexagon) scalar core definition
Quoted 4 lines
Quoted 1 line · Taylor Simpson
+#include <
fenv.h>This should not be in
cpu.h. What's up?
We're not using qemu softfloat (it's on the TODO list), so there's a fenv_t field in CPUHexagonState.
Quoted 4 lines
target/hexagon/cpu.h line 27
Quoted 2 lines
target/hexagon/cpu.h new file +2
-0+#define TARGET_PAGE_BITS 16/* 64K pages */ +#define TARGET_LONG_BITS 32Belongs in
cpu-param.h
OK
Quoted 9 lines
Quoted 3 lines
target/hexagon/cpu.h new file +3
-0+#ifdef CONFIG_USER_ONLY +#define TOTAL_PER_THREAD_REGS 64 +#else ...
Quoted 1 line
+
target_ulonggpr[TOTAL_PER_THREAD_REGS];Do I not understand hexagon enough to know why the number of general registers
would vary with system mode? Why is the define conditional on user-only?
Yes, there are some registers that are only available in system mode. Since this series is only for linux-user mode, I'll remove the ifdef for now.
We're working on system mode. When that series is ready, we can put the ifdef back in. At that time, you'll also see the extra registers in hex_regs.h.
Quoted 6 lines
No. There are plenty of bad examples of this in qemu, let's not add another.
First, the lock doesn't do what you think.
Second, stderr is never right.
Third, just about any time you want this, there's a tracepoint that you could add that would be better, correct, and toggleable from the command-line.
OK
Quoted 7 lines
I understand your desire for this sort of comparison. What I don't understand
is the method. Surely it would be preferable to actually change the stack location in qemu, rather than constantly adjust for it.Add a per-target hook to
linux-user/hexagon/target_elf.hthat controls the allocation of the stack inelfload.c,setup_arg_pages().
OK, will look into this. Thanks for the advice, I wasn't aware this was possible.
Quoted 25 lines
target/hexagon/cpu.c line 137
Quoted 13 lines
target/hexagon/cpu.c new file +12
-0+static void hexagon_dump (CPUHexagonState *env,FILE *f) +{ +static target_ulong last_pc; +int i; + +/* +* When comparing with LLDB, it doesn't step through single-cycle +* hardware loops the same way. So, we just skip them here +*/ +if (env->gpr[HEX_REG_PC ] == last_pc) { +return ; + }Multi-threaded data race. Might as well move
last_pctoenv->dump_last_pcor
something.But I'd also suggest that all of this lldb compatibility stuff be optional, switchable from the command-line with a cpu property. Because there are going
to be real cases where *not* single-stepping will result in dumps from the same
PC, and you've just squashed all of those.
Quoted 2 lines
Call the property x-lldb-compat, or something, and default it to off. You then turn it on with "-cpu v67,x-lldb-compat=on".
OK
RFC PATCH v3 5/34 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
@@ -0,0 +1,83 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_REGS_H +#define HEXAGON_REGS_H + +enum { +HEX_REG_R00 =0 , +HEX_REG_R01 =1 , +HEX_REG_R02 =2 , +HEX_REG_R03 =3 , +HEX_REG_R04 =4 , +HEX_REG_R05 =5 , +HEX_REG_R06 =6 , +HEX_REG_R07 =7 , +HEX_REG_R08 =8 , +HEX_REG_R09 =9 , +HEX_REG_R10 =10 , +HEX_REG_R11 =11 , +HEX_REG_R12 =12 , +HEX_REG_R13 =13 , +HEX_REG_R14 =14 , +HEX_REG_R15 =15 , +HEX_REG_R16 =16 , +HEX_REG_R17 =17 , +HEX_REG_R18 =18 , +HEX_REG_R19 =19 , +HEX_REG_R20 =20 , +HEX_REG_R21 =21 , +HEX_REG_R22 =22 , +HEX_REG_R23 =23 , +HEX_REG_R24 =24 , +HEX_REG_R25 =25 , +HEX_REG_R26 =26 , +HEX_REG_R27 =27 , +HEX_REG_R28 =28 , +HEX_REG_R29 =29 , +HEX_REG_SP =29 , +HEX_REG_FP =30 , +HEX_REG_R30 =30 , +HEX_REG_LR =31 , +HEX_REG_R31 =31 , +HEX_REG_SA0 =32 , +HEX_REG_LC0 =33 , +HEX_REG_SA1 =34 , +HEX_REG_LC1 =35 , +HEX_REG_P3_0 =36 , +HEX_REG_M0 =38 , +HEX_REG_M1 =39 , +HEX_REG_USR =40 , +HEX_REG_PC =41 , +HEX_REG_UGP =42 , +HEX_REG_GP =43 , +HEX_REG_CS0 =44 , +HEX_REG_CS1 =45 , +HEX_REG_UPCYCLELO =46 , +HEX_REG_UPCYCLEHI =47 , +HEX_REG_FRAMELIMIT =48 , +HEX_REG_FRAMEKEY =49 , +HEX_REG_PKTCNTLO =50 , +HEX_REG_PKTCNTHI =51 , +/* Use reserved control registers for qemu execution counts */ +HEX_REG_QEMU_PKT_CNT =52 , +HEX_REG_QEMU_INSN_CNT =53 , +HEX_REG_UTIMERLO =62 , +HEX_REG_UTIMERHI =63 , +}; + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 05/34] Hexagon (target/hexagon) register names
Quoted 5 lines · Taylor Simpson
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/hex_regs.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 target/hexagon/hex_regs.h
Noting for the record that this apparent out-of-order patch hasn't broken bisecting because the build is not enabled until the final patch.
RFC PATCH v3 6/34 Hexagon (disas) disassembler
In reply to Taylor SimpsonThe Hexagon disassembler calls disassemble_hexagon to decode a packet and format it for printing
--- include/disas/dis-asm.h | 1 + disas/hexagon.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ disas/Makefile.objs | 1 + 3 files changed, 64 insertions(+) create mode 100644 disas/hexagon.c
include/disas/dis-asm.h +1 -0
@@ -460,6 +460,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 *);#if 0 /* Fetch the disassembler for a given BFD, if that support is available. */
disas/hexagon.c new file +62 -0
62 lines not on this page · raw message
disas/Makefile.objs +1 -0
@@ -24,6 +24,7 @@ common-obj-$(CONFIG_SH4_DIS) += sh4.o common-obj-$(CONFIG_SPARC_DIS) += sparc.o common-obj-$(CONFIG_LM32_DIS) += lm32.o common-obj-$(CONFIG_XTENSA_DIS) += xtensa.o +common-obj-$(CONFIG_HEXAGON_DIS) += hexagon.o # TODO: As long as the TCG interpreter and its generated code depend # on the QEMU target, we cannot compile the disassembler here.
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 06/34] Hexagon (disas) disassembler
disas/hexagon.c line 58
Quoted 6 lines · Taylor Simpson
disas/hexagon.c new file +6
-0+ len =disassemble_hexagon (words, i, buf,PACKET_BUFFER_LEN ); + slen =strlen (buf); +if (buf[slen -1 ] =='\n' ) { + buf[slen -1 ] ='\0' ; + } + (*info->fprintf_func)(info->stream,"%s" , buf);
Normally our disassemblers print the instruction address; sometimes the raw bytes (or word) of the instruction.
Looking forward to patch 14 where disassemble_hexagon is defined, I see none of that. Indeed, if disassembly fails, we get...
Review
Quoted 7 lines
(quoted diff) +7
-0+ if (decode_this(nwords, words, &pkt)) { + snprint_a_pkt(buf, bufsize, &pkt); + return pkt.encod_pkt_size_in_bytes; + } else { + snprintf(buf, bufsize, "<invalid>"); + return 0; + }
... no indication at all what happened or where, just "<invalid>". That's not going to make it easy to find problems.
r~
RE: [RFC PATCH v3 06/34] Hexagon (disas) disassembler
Quoted 10 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 7:52 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 06/34] Hexagon (disas) disassembler
Quoted 2 lines
Normally our disassemblers print the instruction address; sometimes the raw bytes (or word) of the instruction.
OK
RFC PATCH v3 7/34 Hexagon (target/hexagon) scalar core helpers
In reply to Taylor SimpsonThe majority of helpers are generated. Define the helper functions needed then include the generated file
--- target/hexagon/helper.h | 33 ++++ target/hexagon/op_helper.c | 368 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100644 target/hexagon/helper.h create mode 100644 target/hexagon/op_helper.c
target/hexagon/helper.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +DEF_HELPER_2(raise_exception, noreturn, env, i32) +DEF_HELPER_1(debug_start_packet, void, env) +DEF_HELPER_3(debug_check_store_width, void, env, int, int) +DEF_HELPER_3(debug_commit_end, void, env, int, int) +DEF_HELPER_3(merge_inflight_store1s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store1u, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store2s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store2u, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store4s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store4u, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store8u, s64, env, s32, s64) + +#include "helper_protos_generated.h" + +DEF_HELPER_2(debug_value, void, env, s32) +DEF_HELPER_2 (debug_value_i64, void, env, s64)
target/hexagon/op_helper.c new file +368 -0
368 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 07/34] Hexagon (target/hexagon) scalar core helpers
Quoted 35 lines · Taylor Simpson
The majority of helpers are generated. Define the helper functions needed then include the generated file
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/helper.h | 33 ++++ target/hexagon/op_helper.c | 368 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100644 target/hexagon/helper.h create mode 100644 target/hexagon/op_helper.ctarget/hexagon/helper.h new file +18
-0@@ -0,0 +1,33 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +DEF_HELPER_2 (raise_exception, noreturn, env, i32)
target/hexagon/helper.h line 28
Quoted 10 lines
target/hexagon/helper.h new file +10
-0+DEF_HELPER_1(debug_start_packet, void, env) +DEF_HELPER_3(debug_check_store_width, void, env, int, int) +DEF_HELPER_3(debug_commit_end, void, env, int, int) +DEF_HELPER_3(merge_inflight_store1s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store1u, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store2s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store2u, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store4s, s32, env, s32, s32) +DEF_HELPER_3(merge_inflight_store4u, s32, env, s32, s32) +DEF_HELPER_3 (merge_inflight_store8u, s64, env, s32, s64)
Please use DEF_HELPER_FLAGS_N when possible.
You should be able to know when
(1) No exceptions are possible, and nothing is touched except the inputs. In this case use TCG_CALL_NO_RWG_SE.
(2) No exceptions are possible, and nothing in env is touched for which you have created a tcg variable in hexagon_translate_init(). In this case use TCG_CALL_NO_RWG.
(3) Exceptions are possible, and no tcg variables are touched on the non-exceptional path. In this case use TCG_CALL_NO_WG.
target/hexagon/helper.h line 30
Quoted 2 lines
target/hexagon/helper.h new file +2
-0+static inline void log_pred_write (CPUHexagonState *env,int pnum, +target_ulong val)
You might be better off letting the compiler decide about inlining.
Quoted 14 lines
target/hexagon/helper.h new file +14
-0+/* +* Handle mem_noshuf +* +* This occurs when there is a load that might need data forwarded +* from an inflight store in slot 1. Note that the load and store +* might have different sizes, so we can't simply compare the +* addresses. We merge only the bytes that overlap (if any). +*/ +static int64_t merge_bytes (CPUHexagonState *env,target_ulong load_addr, +int64_t load_data,uint32_t load_width) +{ +/* Don't do anything if slot 1 was cancelled */ +const int store_slot =1 ; +if (env->slot_cancelled & (1 << store_slot)) {
target/hexagon/helper.h
Quoted 10 lines
target/hexagon/helper.h new file +10
-0+return load_data; + } + +int store_width = env->mem_log_stores[store_slot].width; +target_ulong store_addr = env->mem_log_stores[store_slot].va; +union { +uint8_t bytes[8 ]; +uint32_t data32; +uint64_t data64; + } retdata, storedata;
Red flag here. This is assuming that the host and the target are both little-endian.
target/hexagon/helper.h
Quoted 2 lines
target/hexagon/helper.h new file +2
-0+int bigmask = ((-load_width) & (-store_width)); +if ((load_addr & bigmask) != (store_addr & bigmask)) {
Huh? This doesn't detect overlap. Counter example:
load_addr = 0, load_width = 4,
store_addr = 1, store_width = 1.
bigmask = -4 & -1 -> -4.
(0 & -4) != (1 & -4) -> 0 != 1
target/hexagon/helper.h
Quoted 6 lines
target/hexagon/helper.h new file +6
-0+while ((i < load_width) && (j < store_width)) { + retdata.bytes[i] = storedata.bytes[j]; + i++; + j++; + } +return retdata.data64;
This most definitely requires host-endian adjustment.
target/hexagon/helper.h
Quoted 10 lines
target/hexagon/helper.h new file +10
-0+/* Helpful for printing intermediate values within instructions */ +void HELPER (debug_value )(CPUHexagonState *env,int32_t value) +{ +HEX_DEBUG_LOG ("value = 0x%x\n" , value); +} + +void HELPER (debug_value_i64 )(CPUHexagonState *env,int64_t value) +{ +HEX_DEBUG_LOG ("value_i64 = 0x%lx\n" , value); +}
I think we need to lose all of this.
There are other ways to debug TCG.
r~
RE: [RFC PATCH v3 07/34] Hexagon (target/hexagon) scalar core helpers
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 8:17 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 07/34] Hexagon (target/hexagon) scalar core helpers
Quoted 3 lines
Quoted 1 line
+DEF_HELPER_3(merge_inflight_store8u, s64, env, s32, s64)
Please use
DEF_HELPER_FLAGS_Nwhen possible.
OK
Quoted 4 lines
target/hexagon/op_helper.c line 76
Quoted 2 lines
target/hexagon/op_helper.c new file +2
-0+static inline void log_pred_write (CPUHexagonState *env,int pnum, +target_ulong val)You might be better off letting the compiler decide about inlining.
Isn't "inline" just a hint to the compiler?
Quoted 8 lines
target/hexagon/op_helper.c line 260
Quoted 5 lines
target/hexagon/op_helper.c new file +5
-0+union { +uint8_t bytes[8 ]; +uint32_t data32; +uint64_t data64; + } retdata, storedata;Red flag here. This is assuming that the host and the target are both little-endian.
OK
Quoted 11 lines
target/hexagon/op_helper.c line 262
Quoted 2 lines
target/hexagon/op_helper.c new file +2
-0+int bigmask = ((-load_width) & (-store_width)); +if ((load_addr & bigmask) != (store_addr & bigmask)) {Huh? This doesn't detect overlap. Counter example:
load_addr= 0,load_width= 4,
store_addr= 1,store_width= 1.bigmask = -4 & -1 -> -4.
(0 & -4) != (1 & -4) -> 0 != 1
OK
Quoted 8 lines
target/hexagon/op_helper.c line 283
Quoted 6 lines
target/hexagon/op_helper.c new file +6
-0+while ((i < load_width) && (j < store_width)) { + retdata.bytes[i] = storedata.bytes[j]; + i++; + j++; + } +return retdata.data64;This most definitely requires host-endian adjustment.
OK
Quoted 5 lines
Quoted 5 lines
target/hexagon/op_helper.c new file +5
-0+/* Helpful for printing intermediate values within instructions */ +void HELPER (debug_value )(CPUHexagonState *env,int32_t value) +{ +HEX_DEBUG_LOG ("value = 0x%x\n" , value); +}
Quoted 8 lines
target/hexagon/op_helper.c line 352
Quoted 5 lines
target/hexagon/op_helper.c new file +5
-0+ +void HELPER (debug_value_i64 )(CPUHexagonState *env,int64_t value) +{ +HEX_DEBUG_LOG ("value_i64 = 0x%lx\n" , value); +}I think we need to lose all of this.
There are other ways to debug TCG.
OK
RFC PATCH v3 8/34 Hexagon (target/hexagon) GDB Stub
In reply to Taylor SimpsonGDB register read and write routines
--- target/hexagon/internal.h | 2 ++ target/hexagon/cpu.c | 2 ++ target/hexagon/gdbstub.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 target/hexagon/gdbstub.c
target/hexagon/internal.h +2 -0
@@ -37,4 +37,6 @@ extern const char * const hexagon_regnames[TOTAL_PER_THREAD_REGS];extern void init_genptr (void ); +extern int hexagon_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +extern int hexagon_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);#endif
target/hexagon/cpu.c +2 -0
@@ -284,6 +284,8 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data) cc->dump_state = hexagon_dump_state; cc->set_pc = hexagon_cpu_set_pc; cc->synchronize_from_tb = hexagon_cpu_synchronize_from_tb; + cc->gdb_read_register = hexagon_gdb_read_register; + cc->gdb_write_register = hexagon_gdb_write_register; cc->gdb_num_core_regs =TOTAL_PER_THREAD_REGS ; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = hexagon_cpu_disas_set_info;
target/hexagon/gdbstub.c new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 08/34] Hexagon (target/hexagon) GDB Stub
Quoted 9 lines · Taylor Simpson
GDB register read and write routines
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/internal.h | 2 ++ target/hexagon/cpu.c | 2 ++ target/hexagon/gdbstub.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 target/hexagon/gdbstub.c
r~
RFC PATCH v3 9/34 Hexagon (target/hexagon) architecture types
In reply to Taylor SimpsonDefine types used in files imported from the Hexagon architecture library
--- target/hexagon/hex_arch_types.h | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 target/hexagon/hex_arch_types.h
target/hexagon/hex_arch_types.h new file +43 -0
@@ -0,0 +1,43 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_ARCH_TYPES_H +#define HEXAGON_ARCH_TYPES_H + +#include <stdint.h> + +/* +* These types are used by the code generated 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 uint64_t paddr_t ; +typedef uint32_t vaddr_t ; + +typedef struct size16s { +size8s_t hi; +size8u_t lo; +}size16s_t ; + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 09/34] Hexagon (target/hexagon) architecture types
target/hexagon/hex_arch_types.h line 21
Quoted 4 lines · Taylor Simpson
target/hexagon/hex_arch_types.h new file +4
-0+#ifndef HEXAGON_ARCH_TYPES_H +#define HEXAGON_ARCH_TYPES_H + +#include <stdint.h>
Do you really need to re-include this?
This was done in "qemu/osdep.h".
In general, osdep.h must be included first, and it takes care of all of the basic system includes.
r~
RE: [RFC PATCH v3 09/34] Hexagon (target/hexagon) architecture types
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 8:19 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 09/34] Hexagon (target/hexagon) architecture types
Quoted 7 lines
Quoted 1 line
+#include <
stdint.h>Do you really need to re-include this?
This was done in "qemu/osdep.h".In general,
osdep.hmust be included first, and it takes care of all of the basic system includes.
OK
RFC PATCH v3 10/34 Hexagon (target/hexagon) instruction and packet types
In reply to Taylor SimpsonThe insn_t and packet_t are the interface between instruction decoding and TCG code generation
--- target/hexagon/insn.h | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 target/hexagon/insn.h
target/hexagon/insn.h new file +75 -0
@@ -0,0 +1,75 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_INSN_H +#define HEXAGON_INSN_H + +#include "cpu.h" +#include "hex_arch_types.h" + +#define INSTRUCTIONS_MAX 7/* 2 pairs + loopend */ +#define REG_OPERANDS_MAX 5 +#define IMMEDS_MAX 2 + +struct Instruction ; +struct Packet ; +struct DisasContext ; + +typedef void (*semantic_insn_t )(CPUHexagonState *env, +struct DisasContext *ctx, +struct Instruction *insn, +struct Packet *pkt); + +struct Instruction { +semantic_insn_t generate;/* pointer to genptr routine */ +size1u_t regno[REG_OPERANDS_MAX ];/* reg operands including predicates */ +size2u_t opcode; + +size4u_t iclass:6 ; +size4u_t slot:3 ; +size4u_t part1:1 ;/* +* cmp-jumps are split into two insns. +* set for the compare and clear for the jump +*/ +size4u_t extension_valid:1 ;/* Has a constant extender attached */ +size4u_t which_extended:1 ;/* If has an extender, which immediate */ +size4u_t is_endloop:1 ;/* This is an end of loop */ +size4u_t new_value_producer_slot:4 ; +size4s_t immed[IMMEDS_MAX ];/* immediate field */ +}; + +typedef struct Instruction insn_t ; + +struct Packet { +size2u_t num_insns; +size2u_t encod_pkt_size_in_bytes; + +/* Pre-decodes about COF */ +size8u_t pkt_has_cof:1 ;/* Has any change-of-flow */ +size8u_t pkt_has_endloop:1 ; + +size8u_t pkt_has_dczeroa:1 ; + +size8u_t pkt_has_store_s0:1 ; +size8u_t pkt_has_store_s1:1 ; + +insn_t insn[INSTRUCTIONS_MAX ]; +}; + +typedef struct Packet packet_t ; + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 10/34] Hexagon (target/hexagon) instruction and packet types
Quoted 7 lines · Taylor Simpson
target/hexagon/insn.h new file +7
-0+struct Instruction { +semantic_insn_t generate;/* pointer to genptr routine */ +size1u_t regno[REG_OPERANDS_MAX ];/* reg operands including predicates */ +size2u_t opcode; + +size4u_t iclass:6 ; +size4u_t slot:3 ;
target/hexagon/insn.h line 53
Quoted 10 lines
target/hexagon/insn.h new file +10
-0+ size4u_t part1:1; /* +* cmp-jumps are split into two insns. +* set for the compare and clear for the jump +*/ + size4u_t extension_valid:1; /* Has a constant extender attached */ + size4u_t which_extended:1; /* If has an extender, which immediate */ + size4u_t is_endloop:1; /* This is an end of loop */ + size4u_t new_value_producer_slot:4; +size4s_t immed[IMMEDS_MAX ];/* immediate field */ +};
Is this an imported file or not?
If it is not imported, I'd very much prefer that we stick to the stdint.h type names.
r~
RE: [RFC PATCH v3 10/34] Hexagon (target/hexagon) instruction and packet types
Quoted 32 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 8:22 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 10/34] Hexagon (target/hexagon) instruction and packet typestarget/hexagon/insn.h
Quoted 3 lines · Taylor Simpson
target/hexagon/insn.h new file +3
-0+struct Instruction { +semantic_insn_t generate;/* pointer to genptr routine */ +size1u_t regno[REG_OPERANDS_MAX ];/* reg operands including predicates */
target/hexagon/insn.h
Quoted 10 lines
target/hexagon/insn.h new file +10
-0+size2u_t opcode; + + size4u_t iclass:6; + size4u_t slot:3; + size4u_t part1:1; /* +* cmp-jumps are split into two insns. +* set for the compare and clear for the jump +*/ + size4u_t extension_valid:1; /* Has a constant extender attached */ + size4u_t which_extended:1; /* If has an extender, which immediate*/
target/hexagon/insn.h line 53
Quoted 4 lines
target/hexagon/insn.h new file +4
-0+ size4u_t is_endloop:1; /* This is an end of loop */ + size4u_t new_value_producer_slot:4; +size4s_t immed[IMMEDS_MAX ];/* immediate field */ +};
Quoted 4 lines
Is this an imported file or not?
If it is not imported, I'd very much prefer that we stick to the
stdint.htype names.
Agreed. My goal is to stick with stdint.h types outside the imported directory. I'll change this.
RFC PATCH v3 11/34 Hexagon (target/hexagon) register fields
In reply to Taylor SimpsonDeclare bitfields within registers such as user status register (USR)
--- target/hexagon/reg_fields.h | 40 +++++++++++++++++++++ target/hexagon/reg_fields_def.h | 78 +++++++++++++++++++++++++++++++++++++++++ target/hexagon/reg_fields.c | 28 +++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 target/hexagon/reg_fields.h create mode 100644 target/hexagon/reg_fields_def.h create mode 100644 target/hexagon/reg_fields.c
target/hexagon/reg_fields.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_REG_FIELDS_H +#define HEXAGON_REG_FIELDS_H + +#define NUM_GEN_REGS 32 + +typedef struct { +const char *name; +int offset; +int width; +const char *description; +}reg_field_t ; + +extern reg_field_t reg_field_info[]; + +enum reg_fields_enum { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + TAG, +#include "reg_fields_def.h" + NUM_REG_FIELDS +#undef DEF_REG_FIELD +}; + +#endif
target/hexagon/reg_fields_def.h new file +78 -0
78 lines not on this page · raw message
target/hexagon/reg_fields.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "reg_fields.h" + +reg_field_t reg_field_info[] = { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + {NAME, START, WIDTH, DESCRIPTION}, +#include "reg_fields_def.h" + {NULL, 0, 0} +#undef DEF_REG_FIELD +}; +
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 11/34] Hexagon (target/hexagon) register fields
Quoted 29 lines · Taylor Simpson
Declare bitfields within registers such as user status register (USR)
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/reg_fields.h | 40 +++++++++++++++++++++ target/hexagon/reg_fields_def.h | 78 +++++++++++++++++++++++++++++++++++++++++ target/hexagon/reg_fields.c | 28 +++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 target/hexagon/reg_fields.h create mode 100644 target/hexagon/reg_fields_def.h create mode 100644 target/hexagon/reg_fields.ctarget/hexagon/reg_fields.h new file +11
-0@@ -0,0 +1,40 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
target/hexagon/reg_fields.h line 21
Quoted 10 lines
target/hexagon/reg_fields.h new file +10
-0+* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_REG_FIELDS_H +#define HEXAGON_REG_FIELDS_H + +#define NUM_GEN_REGS 32
What's this? It doesn't appear to be field related.
target/hexagon/reg_fields.h line 30
Quoted 1 line
target/hexagon/reg_fields.h new file +1
-0+extern reg_field_t reg_field_info[];
const.
target/hexagon/reg_fields.h line 32
Quoted 1 line
target/hexagon/reg_fields.h new file +1
-0+enum reg_fields_enum {
Doesn't follow naming guidelines. But you don't actually use the name at all, so better to just drop the name entirely?
target/hexagon/reg_fields.h line 30
Quoted 7 lines
target/hexagon/reg_fields.h new file +7
-0+/* USR fields */ +DEF_REG_FIELD (USR_OVF , +"ovf" ,0 ,1 , +"Sticky Saturation Overflow - " +"Set when saturation occurs while executing instruction that specifies " +"optional saturation, remains set until explicitly cleared by a USR=Rs " +"instruction." )
Is the description as a string really useful, or even used?
A comment would seem to do just as well, not consume space in the final binary, and even then seems redundant with the actual architecture manual.
r~
RE: [RFC PATCH v3 11/34] Hexagon (target/hexagon) register fields
Quoted 10 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 8:30 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 11/34] Hexagon (target/hexagon) register fields
Quoted 3 lines
Quoted 1 line
+#define
NUM_GEN_REGS32What's this? It doesn't appear to be field related.
Not needed, will remove it.
Quoted 3 lines
Quoted 1 line
+extern
reg_field_treg_field_info[];const.
OK
Quoted 4 lines
Quoted 1 line
+enum
reg_fields_enum{Doesn't follow naming guidelines. But you don't actually use the name at all, so better to just drop the name entirely?
OK
Quoted 4 lines
Quoted 4 lines
target/hexagon/reg_fields_def.h new file +4
-0+/* USR fields */ +DEF_REG_FIELD (USR_OVF , +"ovf" ,0 ,1 , + "Sticky Saturation Overflow - "
Quoted 8 lines
target/hexagon/reg_fields_def.h line 33
Quoted 3 lines
target/hexagon/reg_fields_def.h new file +3
-0+"Set when saturation occurs while executing instruction that specifies " +"optional saturation, remains set until explicitly cleared by a USR=Rs " + "instruction.")Is the description as a string really useful, or even used? A comment would seem to do just as well, not consume space in the final binary,
and even then seems redundant with the actual architecture manual.
I thought they help make the code more readable. You are right that they shouldn't take space in the binary.
I can either change so they don't go into the binary or remove them altogether - guess I'll remove them altogether.
RFC PATCH v3 12/34 Hexagon (target/hexagon) instruction attributes
In reply to Taylor Simpson--- target/hexagon/attribs.h | 32 +++++++++++++++ target/hexagon/attribs_def.h | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 target/hexagon/attribs.h create mode 100644 target/hexagon/attribs_def.h
target/hexagon/attribs.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_ATTRIBS_H +#define HEXAGON_ATTRIBS_H + +enum { +#define DEF_ATTRIB(NAME, ...) A_##NAME, +#include "attribs_def.h" +#undef DEF_ATTRIB +}; + +#define ATTRIB_WIDTH 32 +#define GET_ATTRIB (opcode, attrib) \ + (((opcode_attribs[opcode][attrib / ATTRIB_WIDTH])\ + >> (attrib % ATTRIB_WIDTH)) & 0x1) + +#endif /* ATTRIBS_H */
target/hexagon/attribs_def.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 12/34] Hexagon (target/hexagon) instruction attributes
target/hexagon/attribs.h line 30
Quoted 4 lines · Taylor Simpson
target/hexagon/attribs.h new file +4
-0+#define ATTRIB_WIDTH 32 +#define GET_ATTRIB (opcode, attrib) \ + (((opcode_attribs[opcode][attrib / ATTRIB_WIDTH])\ + >> (attrib % ATTRIB_WIDTH)) & 0x1)
Can you define GET_ATTRIB in terms of qemu/bitops.h?
I'm leery of ATTRIB_WIDTH being separate from the actual definition of opcode_attribs, over in opcodes.h.
Why does attribs.h need to live separately? They're clearly closely related, and cannot in fact be used separately.
r~
RFC PATCH v3 13/34 Hexagon (target/hexagon) register map
In reply to Taylor SimpsonCertain operand types represent a non-contiguous set of values. For example, the compound compare-and-jump instruction can only access registers R0-R7 and R16-23.
This table represents the mapping from the encoding to the actual values.
--- target/hexagon/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 target/hexagon/regmap.h
target/hexagon/regmap.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* Certain operand types represent a non-contiguous set of values. +* For example, the compound compare-and-jump instruction can only access +* registers R0-R7 and R16-23. +* This table represents the mapping from the encoding to the actual values. +*/ + +#ifndef HEXAGON_REGMAP_H +#define HEXAGON_REGMAP_H + +/* Name Num Table */ +DEF_REGMAP(R_16, 16, 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23) +DEF_REGMAP(R__8, 8, 0, 2, 4, 6, 16, 18, 20, 22) +DEF_REGMAP(R__4, 4, 0, 2, 4, 6) +DEF_REGMAP(R_4, 4, 0, 1, 2, 3) +DEF_REGMAP(R_8S, 8, 0, 1, 2, 3, 16, 17, 18, 19) +DEF_REGMAP(R_8, 8, 0, 1, 2, 3, 4, 5, 6, 7) +DEF_REGMAP(V__8, 8, 0, 4, 8, 12, 16, 20, 24, 28) +DEF_REGMAP(V__16, 16, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30) + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 13/34] Hexagon (target/hexagon) register map
target/hexagon/regmap.h line 36
Quoted 12 lines · Taylor Simpson
target/hexagon/regmap.h new file +12
-0+#ifndef HEXAGON_REGMAP_H +#define HEXAGON_REGMAP_H + +/* Name Num Table */ +DEF_REGMAP(R_16, 16, 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23) +DEF_REGMAP(R__8, 8, 0, 2, 4, 6, 16, 18, 20, 22) +DEF_REGMAP(R__4, 4, 0, 2, 4, 6) +DEF_REGMAP(R_4, 4, 0, 1, 2, 3) +DEF_REGMAP(R_8S, 8, 0, 1, 2, 3, 16, 17, 18, 19) +DEF_REGMAP(R_8, 8, 0, 1, 2, 3, 4, 5, 6, 7) +DEF_REGMAP(V__8, 8, 0, 4, 8, 12, 16, 20, 24, 28) +DEF_REGMAP (V__16 ,16 ,0 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,18 ,20 ,22 ,24 ,26 ,28 ,30 )
Given that DEF_REGMAP itself is defined in decode.c, and not even in another header file, why do these not live in decode.c as well?
r~
RE: [RFC PATCH v3 13/34] Hexagon (target/hexagon) register map
Quoted 10 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 8:36 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 13/34] Hexagon (target/hexagon) register map
Quoted 6 lines
Quoted 1 line
+DEF_REGMAP(V__16, 16, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
30)
Given that
DEF_REGMAPitself is defined indecode.c, and not even in another
header file, why do these not live indecode.cas well?
I'll move them to decode.c.
RFC PATCH v3 14/34 Hexagon (target/hexagon) instruction/packet decode
In reply to Taylor SimpsonTake 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 | 39 +++ target/hexagon/decode.c | 593 ++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/q6v_decode.c | 373 ++++++++++++++++++++++++++++ 3 files changed, 1005 insertions(+) create mode 100644 target/hexagon/decode.h create mode 100644 target/hexagon/decode.c create mode 100644 target/hexagon/q6v_decode.c
target/hexagon/decode.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_DECODE_H +#define HEXAGON_DECODE_H + +#include "cpu.h" +#include "opcodes.h" +#include "hex_arch_types.h" +#include "insn.h" + +extern void decode_init (void ); + +static inline int is_packet_end (uint32_t word) +{ +uint32_t bits = (word >>14 ) &0x3 ; +return ((bits ==0x3 ) || (bits ==0x0 )); +} + +extern void decode_send_insn_to (packet_t *packet,int start,int newloc); + +extern packet_t *decode_this (int max_words,size4u_t *words, +packet_t *decode_pkt); + +#endif
target/hexagon/decode.c new file +593 -0
593 lines not on this page · raw message
target/hexagon/q6v_decode.c new file +373 -0
373 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 14/34] Hexagon (target/hexagon) instruction/packet decode
target/hexagon/decode.c line 67
Quoted 2 lines · Taylor Simpson
target/hexagon/decode.c new file +2
-0+#define DECODE_NEW_TABLE (TAG ,SIZE ,WHATNOT ) \ + static struct _dectree_table_struct dectree_table_##TAG;
All of these little structures should be const.
target/hexagon/decode.c line 56
Quoted 12 lines
target/hexagon/decode.c new file +12
-0+typedef struct { +struct _dectree_table_struct *table_link; +struct _dectree_table_struct *table_link_b; +opcode_t opcode; +enum { +DECTREE_ENTRY_INVALID , +DECTREE_TABLE_LINK , +DECTREE_SUBINSNS , +DECTREE_EXTSPACE , +DECTREE_TERMINAL + } type; +}dectree_entry_t ;
Which probably requires these links to be const, and a few uses within the functions that use them.
That should move 78K worth of tables into .data.rel.ro, where they can't be modified after relocation.
Quoted 14 lines
target/hexagon/decode.c new file +14
-0+/* previous insn is the producer */ + def_opcode = packet->insn[def_idx].opcode; + dststr =strstr (opcode_wregs[def_opcode],"Rd" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'d' ); + }else { + dststr =strstr (opcode_wregs[def_opcode],"Rx" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'x' ); + }else { + dststr =strstr (opcode_wregs[def_opcode],"Re" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'e' ); + }else {
target/hexagon/decode.c line 293
Quoted 10 lines
target/hexagon/decode.c new file +10
-0+ dststr =strstr (opcode_wregs[def_opcode],"Ry" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'y' ); + }else { +g_assert_not_reached (); +return 1 ; + } + } + } + }
I can't help but thinking that all of this string manipulation is not the most ideal way to implement a decoder. Surely all this can be pre-processed into code, or flags, or an enumeration or something.
Oh, and g_assert_not_reached() will never return. You don't have to keep putting return statements after it. Please remove all of those, everywhere.
I'm going to ignore the rest of the decoder, as it's somewhat bewildering. Even in the final patches-applied form. It could really use some more commentary.
r~
RE: [RFC PATCH v3 14/34] Hexagon (target/hexagon) instruction/packet decode
Quoted 15 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 9:07 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 14/34] Hexagon (target/hexagon) instruction/packet decodetarget/hexagon/decode.c line 67
Quoted 2 lines · Taylor Simpson
target/hexagon/decode.c new file +2
-0+#define DECODE_NEW_TABLE (TAG ,SIZE ,WHATNOT ) \ + static struct _dectree_table_struct dectree_table_##TAG;
Quoted 7 lines
All of these little structures should be const.
Which probably requires these links to be const, and a few uses within the functions that use them.
That should move 78K worth of tables into .data.rel.ro, where they can't be modified after relocation.
OK
Quoted 3 lines
I can't help but thinking that all of this string manipulation is not the most ideal way to implement a decoder. Surely all this can be pre-processed into code, or flags, or an enumeration or something.
I'll have to think about this one.
Quoted 3 lines
Oh, and
g_assert_not_reached()will never return. You don't have to keep putting return statements after it. Please remove all of those, everywhere.
OK
Quoted 3 lines
I'm going to ignore the rest of the decoder, as it's somewhat bewildering. Even in the final patches-applied form. It could really use some more commentary.
OK
RFC PATCH v3 15/34 Hexagon (target/hexagon) instruction printing
In reply to Taylor Simpson--- target/hexagon/printinsn.h | 26 +++++++++++++ target/hexagon/printinsn.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 target/hexagon/printinsn.h create mode 100644 target/hexagon/printinsn.c
target/hexagon/printinsn.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_PRINTINSN_H +#define HEXAGON_PRINTINSN_H + +#include "qemu/osdep.h" +#include "insn.h" + +extern void snprint_a_pkt (char *buf,int n,packet_t *pkt); + +#endif
target/hexagon/printinsn.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 15/34] Hexagon (target/hexagon) instruction printing
Quoted 1 line · Taylor Simpson
+extern void
snprint_a_pkt(char *buf, int n, packet_t *pkt);
Is there a good reason you're using a fixed size buffer and not returning a GString?
r~
RFC PATCH v3 16/34 Hexagon (target/hexagon) utility functions
In reply to Taylor SimpsonUtility functions called by various instructions
--- target/hexagon/arch.h | 42 +++ target/hexagon/conv_emu.h | 50 +++ target/hexagon/fma_emu.h | 27 ++ target/hexagon/arch.c | 354 +++++++++++++++++++++ target/hexagon/conv_emu.c | 369 ++++++++++++++++++++++ target/hexagon/fma_emu.c | 781 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1623 insertions(+) create mode 100644 target/hexagon/arch.h create mode 100644 target/hexagon/conv_emu.h create mode 100644 target/hexagon/fma_emu.h create mode 100644 target/hexagon/arch.c create mode 100644 target/hexagon/conv_emu.c create mode 100644 target/hexagon/fma_emu.c
target/hexagon/arch.h new file +42 -0
@@ -0,0 +1,42 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_ARCH_H +#define HEXAGON_ARCH_H + +#include "cpu.h" +#include "hex_arch_types.h" + +extern size8u_t interleave (size4u_t odd,size4u_t even); +extern size8u_t deinterleave (size8u_t src); +extern size4u_t carry_from_add64 (size8u_t a,size8u_t b,size4u_t c); +extern size4s_t conv_round (size4s_t a,int n); +extern size16s_t cast8s_to_16s (size8s_t a); +extern size8s_t cast16s_to_8s (size16s_t a); +extern size16s_t add128 (size16s_t a,size16s_t b); +extern size16s_t sub128 (size16s_t a,size16s_t b); +extern size16s_t shiftr128 (size16s_t a,size4u_t n); +extern size16s_t shiftl128 (size16s_t a,size4u_t n); +extern size16s_t and128 (size16s_t a,size16s_t b); +extern void arch_fpop_start (CPUHexagonState *env); +extern void arch_fpop_end (CPUHexagonState *env); +extern void arch_raise_fpflag (unsigned int flags); +extern int arch_sf_recip_common (size4s_t *Rs,size4s_t *Rt,size4s_t *Rd, +int *adjust); +extern int arch_sf_invsqrt_common (size4s_t *Rs,size4s_t *Rd,int *adjust); + +#endif
target/hexagon/conv_emu.h new file +50 -0
50 lines not on this page · raw message
target/hexagon/fma_emu.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_FMA_EMU_H +#define HEXAGON_FMA_EMU_H + +extern float internal_fmafx (float a_in,float b_in,float c_in,int scale); +extern float internal_fmaf (float a_in,float b_in,float c_in); +extern float internal_mpyf (float a_in,float b_in); +extern double internal_mpyhh (double a_in,double b_in, +unsigned long long int accumulated); + +#endif
target/hexagon/arch.c new file +354 -0
354 lines not on this page · raw message
target/hexagon/conv_emu.c new file +369 -0
369 lines not on this page · raw message
target/hexagon/fma_emu.c new file +781 -0
781 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 16/34] Hexagon (target/hexagon) utility functions
target/hexagon/arch.h line 34
Quoted 7 lines · Taylor Simpson
target/hexagon/arch.h new file +7
-0+extern size16s_t cast8s_to_16s (size8s_t a); +extern size8s_t cast16s_to_8s (size16s_t a); +extern size16s_t add128 (size16s_t a,size16s_t b); +extern size16s_t sub128 (size16s_t a,size16s_t b); +extern size16s_t shiftr128 (size16s_t a,size4u_t n); +extern size16s_t shiftl128 (size16s_t a,size4u_t n); +extern size16s_t and128 (size16s_t a,size16s_t b);
Did you really need to reinvent qemu/int128.h?
r~
RE: [RFC PATCH v3 16/34] Hexagon (target/hexagon) utility functions
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 9:11 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 16/34] Hexagon (target/hexagon) utility functionsDid you really need to reinvent
qemu/int128.h?
I remember looking at qemu/int128.h briefly but can't remember why I ended up not using it. I'll take another look.
RFC PATCH v3 17/34 Hexagon (target/hexagon/imported) arch import - macro definitions
In reply to Taylor SimpsonThe 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.
--- target/hexagon/imported/macros.def | 1529 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1529 insertions(+) create mode 100755 target/hexagon/imported/macros.def
target/hexagon/imported/macros.def new file +1529 -0
@@ -0,0 +1,1529 @@ +/* + * Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +DEF_MACRO( + LIKELY, /* NAME */ + __builtin_expect((X),1), /* BEH */ + () /* attribs */ +) + +DEF_MACRO( + UNLIKELY, /* NAME */ + __builtin_expect((X),0), /* BEH */ + () /* attribs */ +) + +DEF_MACRO( + CANCEL, /* macro name */ + {if (thread->last_pkt) thread->last_pkt->slot_cancelled |= (1<<insn->slot); return;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + LOAD_CANCEL, /* macro name */ + {mem_general_load_cancelled(thread,EA,insn);CANCEL;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + STORE_CANCEL, /* macro name */ + {mem_general_store_cancelled(thread,EA,insn);CANCEL;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + fMAX, /* macro name */ + (((A) > (B)) ? (A) : (B)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fMIN, /* macro name */ + (((A) < (B)) ? (A) : (B)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fABS, /* macro name */ + (((A)<0)?(-(A)):(A)), /* behavior */ + /* optional attributes */ +) + + +/* Bit insert */ +DEF_MACRO( + fINSERT_BITS, + { + REG = ((REG) & ~(((fCONSTLL(1)<<(WIDTH))-1)<<(OFFSET))) | (((INVAL) & ((fCONSTLL(1)<<(WIDTH))-1)) << (OFFSET)); + }, + /* attribs */ +) + +/* Bit extract */ +DEF_MACRO( + fEXTRACTU_BITS, + (fZXTN(WIDTH,32,(INREG >> OFFSET))), + /* attribs */ +) + +DEF_MACRO( + fEXTRACTU_BIDIR, + (fZXTN(WIDTH,32,fBIDIR_LSHIFTR((INREG),(OFFSET),4_8))), + /* attribs */ +) + +DEF_MACRO( + fEXTRACTU_RANGE, + (fZXTN((HIBIT-LOWBIT+1),32,(INREG >> LOWBIT))), + /* attribs */ +) + +DEF_MACRO( + f8BITSOF, + ( (VAL) ? 0xff : 0x00), + /* attribs */ +) + +DEF_MACRO( + fLSBOLD, + ((VAL) & 1), + () +) + +DEF_MACRO( + fLSBNEW, + predlog_read(thread,PNUM), + () +) + +DEF_MACRO( + fLSBNEW0, + predlog_read(thread,0), + () +) + +DEF_MACRO( + fLSBNEW1, + predlog_read(thread,1), + () +) + +DEF_MACRO( + fLSBOLDNOT, + (!fLSBOLD(VAL)), + () +) + +DEF_MACRO( + fLSBNEWNOT, + (!fLSBNEW(PNUM)), + () +) + +DEF_MACRO( + fLSBNEW0NOT, + (!fLSBNEW0), + () +) + +DEF_MACRO( + fLSBNEW1NOT, + (!fLSBNEW1), + () +) + +DEF_MACRO( + fNEWREG, + ({if (newvalue_missing(thread,RNUM) || + IS_CANCELLED(insn->new_value_producer_slot)) CANCEL; reglog_read(thread,RNUM);}), + (A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY) +) +// Store new with a missing newvalue or cancelled goes out as a zero byte store in V65 +// take advantage of the fact that reglog_read returns zero for not valid rnum +DEF_MACRO( + fNEWREG_ST, + ({if (newvalue_missing(thread,RNUM) || + IS_CANCELLED(insn->new_value_producer_slot)) { STORE_ZERO; RNUM = -1; }; reglog_read(thread,RNUM);}), + (A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY) +) + +DEF_MACRO( + fSATUVALN, + ({fSET_OVERFLOW(); ((VAL) < 0) ? 0 : ((1LL<<(N))-1);}), + () +) + +DEF_MACRO( + fSATVALN, + ({fSET_OVERFLOW(); ((VAL) < 0) ? (-(1LL<<((N)-1))) : ((1LL<<((N)-1))-1);}), + () +) + +DEF_MACRO( + fZXTN, /* macro name */ + ((VAL) & ((1LL<<(N))-1)), + /* attribs */ +) + +DEF_MACRO( + fSXTN, /* macro name */ + ((fZXTN(N,M,VAL) ^ (1LL<<((N)-1))) - (1LL<<((N)-1))), + /* attribs */ +) + +DEF_MACRO( + fSATN, + ((fSXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATVALN(N,VAL)), + () +) + +DEF_MACRO( + fADDSAT64, + { + size8u_t __a = fCAST8u(A); + size8u_t __b = fCAST8u(B); + size8u_t __sum = __a + __b; + size8u_t __xor = __a ^ __b; + const size8u_t __mask = 0x8000000000000000ULL; + if (__xor & __mask) { + /* Opposite signs, OK */ + DST = __sum; + } else if ((__a ^ __sum) & __mask) { + /* Signs mismatch */ + if (__sum & __mask) { + /* overflowed to negative, make max pos */ + DST=0x7FFFFFFFFFFFFFFFLL; fSET_OVERFLOW(); + } else { + /* overflowed to positive, make max neg */ + DST=0x8000000000000000LL; fSET_OVERFLOW(); + } + } else { + /* signs did not mismatch, OK */ + DST = __sum; + } + }, + () +) + +DEF_MACRO( + fSATUN, + ((fZXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATUVALN(N,VAL)), + () +) + +DEF_MACRO( + fSATH, + (fSATN(16,VAL)), + () +) + + +DEF_MACRO( + fSATUH, + (fSATUN(16,VAL)), + () +) + +DEF_MACRO( + fSATUB, + (fSATUN(8,VAL)), + () +) +DEF_MACRO( + fSATB, + (fSATN(8,VAL)), + () +) + + +/*************************************/ +/* immediate extension */ +/*************************************/ + +DEF_MACRO( + fIMMEXT, + (IMM = IMM), + (A_EXTENDABLE) +) + +DEF_MACRO( + fMUST_IMMEXT, + fIMMEXT(IMM), + (A_EXTENDABLE) +) + +DEF_MACRO( + fPCALIGN, + IMM=(IMM & ~PCALIGN_MASK), + (A_EXTENDABLE) +) + +/*************************************/ +/* Read and Write Implicit Regs */ +/*************************************/ + +DEF_MACRO( + fREAD_LR, /* read link register */ + (READ_RREG(REG_LR)), /* behavior */ + () +) + +DEF_MACRO( + fWRITE_LR, /* write lr */ + WRITE_RREG(REG_LR,A), /* behavior */ + (A_IMPLICIT_WRITES_LR) +) + +DEF_MACRO( + fWRITE_FP, /* write sp */ + WRITE_RREG(REG_FP,A), /* behavior */ + (A_IMPLICIT_WRITES_FP) +) + +DEF_MACRO( + fWRITE_SP, /* write sp */ + WRITE_RREG(REG_SP,A), /* behavior */ + (A_IMPLICIT_WRITES_SP) +) + +DEF_MACRO( + fREAD_SP, /* read stack pointer */ + (READ_RREG(REG_SP)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_LC0, /* read loop count */ + (READ_RREG(REG_LC0)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_LC1, /* read loop count */ + (READ_RREG(REG_LC1)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_SA0, /* read start addr */ + (READ_RREG(REG_SA0)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_SA1, /* read start addr */ + (READ_RREG(REG_SA1)), /* behavior */ + () +) + + +DEF_MACRO( + fREAD_FP, /* read frame pointer */ + (READ_RREG(REG_FP)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_GP, /* read global pointer */ + (insn->extension_valid ? 0 : READ_RREG(REG_GP)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_PC, /* read PC */ + (READ_RREG(REG_PC)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_NPC, /* read next PC */ + (thread->next_PC & (0xfffffffe)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_P0, /* read Predicate 0 */ + (READ_PREG(0)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_P3, /* read Predicate 3 */ + (READ_PREG(3)), /* behavior */ + () +) + +DEF_MACRO( + fCHECK_PCALIGN, + if (((A) & PCALIGN_MASK)) { + register_error_exception(thread,PRECISE_CAUSE_PC_NOT_ALIGNED,thread->Regs[REG_BADVA0],thread->Regs[REG_BADVA1],GET_SSR_FIELD(SSR_BVS),GET_SSR_FIELD(SSR_V0),GET_SSR_FIELD(SSR_V1),0); + }, + () +) + +DEF_MACRO( + fWRITE_NPC, /* write next PC */ + if (!thread->branch_taken) { + if (A != thread->next_PC) { + thread->next_pkt_guess=thread->last_pkt->taken_ptr; + } + fCHECK_PCALIGN(A); + thread->branched = 1; thread->branch_taken = 1; thread->next_PC = A; \ + thread->branch_offset = insn->encoding_offset; thread->branch_opcode = insn->opcode; + } + , /* behavior */ + (A_COF) +) + +DEF_MACRO( + fBRANCH, + fWRITE_NPC(LOC); fCOF_CALLBACK(LOC,TYPE), + () +) + +DEF_MACRO( + fJUMPR, /* A jumpr has executed */ + {fBRANCH(TARGET,COF_TYPE_JUMPR);}, + (A_INDIRECT) +) + +DEF_MACRO( + fHINTJR, /* A hintjr instruction has executed */ + { }, +) + +DEF_MACRO( + fCALL, /* Do a call */ + if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALL);}, + (A_COF,A_IMPLICIT_WRITES_LR,A_CALL) +) + +DEF_MACRO( + fCALLR, /* Do a call Register */ + if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALLR);}, + (A_COF,A_IMPLICIT_WRITES_LR,A_CALL) +) + +DEF_MACRO( + fWRITE_LOOP_REGS0, /* write ln,sa,ea,lc */ + {WRITE_RREG(REG_LC0,COUNT); + WRITE_RREG(REG_SA0,START);}, + (A_IMPLICIT_WRITES_LC0,A_IMPLICIT_WRITES_SA0) +) + +DEF_MACRO( + fWRITE_LOOP_REGS1, /* write ln,sa,ea,lc */ + {WRITE_RREG(REG_LC1,COUNT); + WRITE_RREG(REG_SA1,START);}, + (A_IMPLICIT_WRITES_LC1,A_IMPLICIT_WRITES_SA1) +) + +DEF_MACRO( + fWRITE_LC0, + WRITE_RREG(REG_LC0,VAL), + (A_IMPLICIT_WRITES_LC0) +) + +DEF_MACRO( + fWRITE_LC1, + WRITE_RREG(REG_LC1,VAL), + (A_IMPLICIT_WRITES_LC1) +) + +DEF_MACRO( + fCARRY_FROM_ADD, + carry_from_add64(A,B,C), + /* NOTHING */ +) + +DEF_MACRO( + fSET_OVERFLOW, + SET_USR_FIELD(USR_OVF,1), + () +) + +DEF_MACRO( + fSET_LPCFG, + SET_USR_FIELD(USR_LPCFG,(VAL)), + () +) + + +DEF_MACRO( + fGET_LPCFG, + (GET_USR_FIELD(USR_LPCFG)), + () +) + + + +DEF_MACRO( + fWRITE_P0, /* write Predicate 0 */ + WRITE_PREG(0,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P0) +) + +DEF_MACRO( + fWRITE_P1, /* write Predicate 0 */ + WRITE_PREG(1,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P1) +) + +DEF_MACRO( + fWRITE_P2, /* write Predicate 0 */ + WRITE_PREG(2,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P2) +) + +DEF_MACRO( + fWRITE_P3, /* write Predicate 0 */ + WRITE_PREG(3,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P3) +) + +DEF_MACRO( + fPART1, /* write Predicate 0 */ + if (insn->part1) { WORK; return; }, /* behavior */ + /* optional attributes */ +) + + +/*************************************/ +/* Casting, Sign-Zero extension, etc */ +/*************************************/ + +DEF_MACRO( + fCAST4u, /* macro name */ + ((size4u_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST4s, /* macro name */ + ((size4s_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST8u, /* macro name */ + ((size8u_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST8s, /* macro name */ + ((size8s_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_4s, /* macro name */ + ((size4s_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_4u, /* macro name */ + ((size4u_t)(A)), + /* optional attributes */ +) + + +DEF_MACRO( + fCAST4_8s, /* macro name */ + ((size8s_t)((size4s_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_8u, /* macro name */ + ((size8u_t)((size4u_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8_8s, /* macro name */ + ((size8s_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8_8u, /* macro name */ + ((size8u_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST2_8s, /* macro name */ + ((size8s_t)((size2s_t)(A))), + /* optional attributes */ +) +DEF_MACRO( + fCAST2_8u, /* macro name */ + ((size8u_t)((size2u_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fZE8_16, /* zero-extend 8 to 16 */ + ((size2s_t)((size1u_t)(A))), + /* optional attributes */ +) +DEF_MACRO( + fSE8_16, /* sign-extend 8 to 16 */ + ((size2s_t)((size1s_t)(A))), + /* optional attributes */ +) + + +DEF_MACRO( + fSE16_32, /* sign-extend 16 to 32 */ + ((size4s_t)((size2s_t)(A))), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fZE16_32, /* zero-extend 16 to 32 */ + ((size4u_t)((size2u_t)(A))), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fSE32_64, + ( (size8s_t)((size4s_t)(A)) ), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fZE32_64, + ( (size8u_t)((size4u_t)(A)) ), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fSE8_32, /* sign-extend 8 to 32 */ + ((size4s_t)((size1s_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fZE8_32, /* zero-extend 8 to 32 */ + ((size4s_t)((size1u_t)(A))), + /* optional attributes */ +) + +/*************************************/ +/* DSP arithmetic support */ +/************************************/ +DEF_MACRO( + fMPY8UU, /* multiply half integer */ + (int)(fZE8_16(A)*fZE8_16(B)), /* behavior */ + () +) +DEF_MACRO( + fMPY8US, /* multiply half integer */ + (int)(fZE8_16(A)*fSE8_16(B)), /* behavior */ + () +) +DEF_MACRO( + fMPY8SU, /* multiply half integer */ + (int)(fSE8_16(A)*fZE8_16(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY8SS, /* multiply half integer */ + (int)((short)(A)*(short)(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY16SS, /* multiply half integer */ + fSE32_64(fSE16_32(A)*fSE16_32(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY16UU, /* multiply unsigned half integer */ + fZE32_64(fZE16_32(A)*fZE16_32(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY16SU, /* multiply half integer */ + fSE32_64(fSE16_32(A)*fZE16_32(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY16US, /* multiply half integer */ + fMPY16SU(B,A), + () +) + +DEF_MACRO( + fMPY32SS, /* multiply half integer */ + (fSE32_64(A)*fSE32_64(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY32UU, /* multiply half integer */ + (fZE32_64(A)*fZE32_64(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY32SU, /* multiply half integer */ + (fSE32_64(A)*fZE32_64(B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY3216SS, /* multiply mixed precision */ + (fSE32_64(A)*fSXTN(16,64,B)), /* behavior */ + () +) + +DEF_MACRO( + fMPY3216SU, /* multiply mixed precision */ + (fSE32_64(A)*fZXTN(16,64,B)), /* behavior */ + () +) + +DEF_MACRO( + fROUND, /* optional rounding */ + (A+0x8000), + /* optional attributes */ +) + +DEF_MACRO( + fCLIP, /* optional rounding */ + { size4s_t maxv = (1<<U)-1; + size4s_t minv = -(1<<U); + DST = fMIN(maxv,fMAX(SRC,minv)); + }, + /* optional attributes */ +) + +DEF_MACRO( + fCRND, /* optional rounding */ + ((((A)&0x3)==0x3)?((A)+1):((A))), + /* optional attributes */ +) + +DEF_MACRO( + fRNDN, /* Rounding to a boundary */ + ((((N)==0)?(A):(((fSE32_64(A))+(1<<((N)-1)))))), + /* optional attributes */ +) + +DEF_MACRO( + fCRNDN, /* Rounding to a boundary */ + (conv_round(A,N)), + /* optional attributes */ +) + +DEF_MACRO( + fADD128, /* Rounding to a boundary */ + (add128(A, B)), + /* optional attributes */ +) +DEF_MACRO( + fSUB128, /* Rounding to a boundary */ + (sub128(A, B)), + /* optional attributes */ +) +DEF_MACRO( + fSHIFTR128, /* Rounding to a boundary */ + (shiftr128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fSHIFTL128, /* Rounding to a boundary */ + (shiftl128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fAND128, /* Rounding to a boundary */ + (and128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8S_16S, /* Rounding to a boundary */ + (cast8s_to_16s(A)), + /* optional attributes */ +) +DEF_MACRO( + fCAST16S_8S, /* Rounding to a boundary */ + (cast16s_to_8s(A)), + /* optional attributes */ +) + +DEF_MACRO( + fEA_RI, /* Calculate EA with Register + Immediate Offset */ + do { EA=REG+IMM; fDOCHKPAGECROSS(REG,EA); } while (0), + () +) + +DEF_MACRO( + fEA_RRs, /* Calculate EA with Register + Registers scaled Offset */ + do { EA=REG+(REG2<<SCALE); fDOCHKPAGECROSS(REG,EA); } while (0), + () +) + +DEF_MACRO( + fEA_IRs, /* Calculate EA with Immediate + Registers scaled Offset */ + do { EA=IMM+(REG<<SCALE); fDOCHKPAGECROSS(IMM,EA); } while (0), + () +) + +DEF_MACRO( + fEA_IMM, /* Calculate EA with Immediate */ + EA=IMM, + () +) + +DEF_MACRO( + fEA_REG, /* Calculate EA with REGISTER */ + EA=REG, + () +) + +DEF_MACRO( + fEA_GPI, /* Calculate EA with Global Poitner + Immediate */ + do { EA=fREAD_GP()+IMM; fGP_DOCHKPAGECROSS(fREAD_GP(),EA); } while (0), + () +) + +DEF_MACRO( + fPM_I, /* Post Modify Register by Immediate*/ + do { REG = REG + IMM; } while (0), + () +) + +DEF_MACRO( + fPM_M, /* Post Modify Register by M register */ + do { REG = REG + MVAL; } while (0), + () +) + +DEF_MACRO( + fSCALE, /* scale by N */ + (((size8s_t)(A))<<N), + /* optional attributes */ +) + +DEF_MACRO( + fSATW, /* saturating to 32-bits*/ + fSATN(32,((long long)A)), + () +) + +DEF_MACRO( + fSAT, /* saturating to 32-bits*/ + fSATN(32,(A)), + () +) + +DEF_MACRO( + fSAT_ORIG_SHL, /* Saturating to 32-bits, with original value, for shift left */ + ((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) ? + fSATVALN(32,((size4s_t)(ORIG_REG))) : + ((((ORIG_REG) > 0) && ((A) == 0)) ? + fSATVALN(32,(ORIG_REG)) : + fSAT(A))), + () +) + +DEF_MACRO( + fPASS, + A, +) + +DEF_MACRO( + fRND, /* saturating to 32-bits*/ + (((A)+1)>>1), +) + + +DEF_MACRO( + fBIDIR_SHIFTL, + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT))-1)) >>1) : (fCAST##REGSTYPE(SRC) << (SHAMT))), + () +) + +DEF_MACRO( + fBIDIR_ASHIFTL, + fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##s), + () +) + +DEF_MACRO( + fBIDIR_LSHIFTL, + fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##u), + () +) + +DEF_MACRO( + fBIDIR_ASHIFTL_SAT, + (((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT))-1)) >>1) : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT),(SRC))), + () +) + + +DEF_MACRO( + fBIDIR_SHIFTR, + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT))-1)) << 1) : (fCAST##REGSTYPE(SRC) >> (SHAMT))), + () +) + +DEF_MACRO( + fBIDIR_ASHIFTR, + fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##s), + () +) + +DEF_MACRO( + fBIDIR_LSHIFTR, + fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##u), + () +) + +DEF_MACRO( + fBIDIR_ASHIFTR_SAT, + (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) << ((-(SHAMT))-1)) << 1,(SRC)) : (fCAST##REGSTYPE##s(SRC) >> (SHAMT))), + () +) + +DEF_MACRO( + fASHIFTR, + (fCAST##REGSTYPE##s(SRC) >> (SHAMT)), + /* */ +) + +DEF_MACRO( + fLSHIFTR, + (((SHAMT) >= 64)?0:(fCAST##REGSTYPE##u(SRC) >> (SHAMT))), + /* */ +) + +DEF_MACRO( + fROTL, + (((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) << (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) >> ((sizeof(SRC)*8)-(SHAMT)))))), + /* */ +) + +DEF_MACRO( + fROTR, + (((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) >> (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) << ((sizeof(SRC)*8)-(SHAMT)))))), + /* */ +) + +DEF_MACRO( + fASHIFTL, + (((SHAMT) >= 64)?0:(fCAST##REGSTYPE##s(SRC) << (SHAMT))), + /* */ +) + +/*************************************/ +/* Floating-Point Support */ +/************************************/ + +DEF_MACRO( + fFLOAT, /* name */ + ({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; }), /* behavior */ + (A_FPOP) +) + +DEF_MACRO( + fUNFLOAT, /* multiply half integer */ + ({ union { float f; size4u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; }), /* behavior */ + (A_FPOP) +) + +DEF_MACRO( + fSFNANVAL, + 0xffffffff, + () +) + +DEF_MACRO( + fSFINFVAL, + (((A) & 0x80000000) | 0x7f800000), + () +) + +DEF_MACRO( + fSFONEVAL, + (((A) & 0x80000000) | fUNFLOAT(1.0)), + () +) + +DEF_MACRO( + fCHECKSFNAN, + do { + if (isnan(fFLOAT(A))) { + if ((fGETBIT(22,A)) == 0) fRAISEFLAGS(FE_INVALID); + DST = fSFNANVAL(); + } + } while (0), + () +) + +DEF_MACRO( + fCHECKSFNAN3, + do { + fCHECKSFNAN(DST,A); + fCHECKSFNAN(DST,B); + fCHECKSFNAN(DST,C); + } while (0), + () +) + +DEF_MACRO( + fSF_BIAS, + 127, + () +) + +DEF_MACRO( + fSF_MANTBITS, + 23, + () +) + +DEF_MACRO( + fSF_MUL_POW2, + (fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS()))), + () +) + +DEF_MACRO( + fSF_GETEXP, + (((A) >> fSF_MANTBITS()) & 0xff), + () +) + +DEF_MACRO( + fSF_MAXEXP, + (254), + () +) + +DEF_MACRO( + fSF_RECIP_COMMON, + arch_sf_recip_common(&N,&D,&O,&A), + (A_FPOP) +) + +DEF_MACRO( + fSF_INVSQRT_COMMON, + arch_sf_invsqrt_common(&N,&O,&A), + (A_FPOP) +) + +DEF_MACRO( + fFMAFX, + internal_fmafx(A,B,C,fSXTN(8,64,ADJ)), + () +) + +DEF_MACRO( + fFMAF, + internal_fmafx(A,B,C,0), + () +) + +DEF_MACRO( + fSFMPY, + internal_mpyf(A,B), + () +) + +DEF_MACRO( + fMAKESF, + ((((SIGN) & 1) << 31) | (((EXP) & 0xff) << fSF_MANTBITS()) | + ((MANT) & ((1<<fSF_MANTBITS())-1))), + () +) + + +DEF_MACRO( + fDOUBLE, /* multiply half integer */ + ({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; }), /* behavior */ + (A_FPOP) +) + +DEF_MACRO( + fUNDOUBLE, /* multiply half integer */ + ({ union { double f; size8u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; }), /* behavior */ + (A_FPOP) +) + +DEF_MACRO( + fDFNANVAL, + 0xffffffffffffffffULL, + () +) + +DEF_MACRO( + fDF_ISNORMAL, + (fpclassify(fDOUBLE(X)) == FP_NORMAL), + () +) + +DEF_MACRO( + fDF_ISDENORM, + (fpclassify(fDOUBLE(X)) == FP_SUBNORMAL), + () +) + +DEF_MACRO( + fDF_ISBIG, + (fDF_GETEXP(X) >= 512), + () +) + +DEF_MACRO( + fDF_MANTBITS, + 52, + () +) + +DEF_MACRO( + fDF_GETEXP, + (((A) >> fDF_MANTBITS()) & 0x7ff), + () +) + +DEF_MACRO( + fFMA, + internal_fma(A,B,C), + /* nothing */ +) + +DEF_MACRO( + fDF_MPY_HH, + internal_mpyhh(A,B,ACC), + /* nothing */ +) + +DEF_MACRO( + fFPOP_START, + arch_fpop_start(thread), + /* nothing */ +) + +DEF_MACRO( + fFPOP_END, + arch_fpop_end(thread), + /* nothing */ +) + +DEF_MACRO( + fFPSETROUND_NEAREST, + fesetround(FE_TONEAREST), + /* nothing */ +) + +DEF_MACRO( + fFPSETROUND_CHOP, + fesetround(FE_TOWARDZERO), + /* nothing */ +) + +DEF_MACRO( + fFPCANCELFLAGS, + feclearexcept(FE_ALL_EXCEPT), + /* nothing */ +) + +DEF_MACRO( + fISINFPROD, + ((isinf(A) && isinf(B)) || + (isinf(A) && isfinite(B) && ((B) != 0.0)) || + (isinf(B) && isfinite(A) && ((A) != 0.0))), + /* nothing */ +) + +DEF_MACRO( + fISZEROPROD, + ((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A))), + /* nothing */ +) + +DEF_MACRO( + fRAISEFLAGS, + arch_raise_fpflag(A), + /* NOTHING */ +) + +DEF_MACRO( + fDF_MAX, + (((A)==(B)) + ? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B)) + : fmax(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fDF_MIN, + (((A)==(B)) + ? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B)) + : fmin(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fSF_MAX, + (((A)==(B)) + ? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B)) + : fmaxf(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fSF_MIN, + (((A)==(B)) + ? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B)) + : fminf(A,B)), + (A_FPOP) +) + +/*************************************/ +/* Load/Store support */ +/*************************************/ + +DEF_MACRO(fLOAD, + { DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE(thread,EA,insn); }, + (A_LOAD,A_MEMLIKE) +) + +DEF_MACRO(fMEMOP, + { memop##SIZE##_##FNTYPE(thread,EA,VALUE); }, + (A_LOAD,A_STORE,A_MEMLIKE) +) + +DEF_MACRO(fGET_FRAMEKEY, + READ_RREG(REG_FRAMEKEY), + () +) + +DEF_MACRO(fFRAME_SCRAMBLE, + ((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32)), + /* ATTRIBS */ +) + +DEF_MACRO(fFRAME_UNSCRAMBLE, + fFRAME_SCRAMBLE(VAL), + /* ATTRIBS */ +) + +DEF_MACRO(fFRAMECHECK, + sys_check_framelimit(thread,ADDR,EA), + () +) + +DEF_MACRO(fLOAD_LOCKED, + { DST = (size##SIZE##SIGN##_t)mem_load_locked(thread,EA,SIZE,insn); + }, + (A_LOAD,A_MEMLIKE) +) + +DEF_MACRO(fSTORE, + { MEM_STORE##SIZE(thread,EA,SRC,insn); }, + (A_STORE,A_MEMLIKE) +) + + +DEF_MACRO(fSTORE_LOCKED, + { PRED = (mem_store_conditional(thread,EA,SRC,SIZE,insn) ? 0xff : 0); }, + (A_STORE,A_MEMLIKE) +) + +/*************************************/ +/* Functions to help with bytes */ +/*************************************/ + +DEF_MACRO(fGETBYTE, + ((size1s_t)((SRC>>((N)*8))&0xff)), + /* nothing */ +) + +DEF_MACRO(fGETUBYTE, + ((size1u_t)((SRC>>((N)*8))&0xff)), + /* nothing */ +) + +DEF_MACRO(fSETBYTE, + { + DST = (DST & ~(0x0ffLL<<((N)*8))) | (((size8u_t)((VAL) & 0x0ffLL)) << ((N)*8)); + }, + /* nothing */ +) + +DEF_MACRO(fGETHALF, + ((size2s_t)((SRC>>((N)*16))&0xffff)), + /* nothing */ +) + +DEF_MACRO(fGETUHALF, + ((size2u_t)((SRC>>((N)*16))&0xffff)), + /* nothing */ +) + +DEF_MACRO(fSETHALF, + { + DST = (DST & ~(0x0ffffLL<<((N)*16))) | (((size8u_t)((VAL) & 0x0ffff)) << ((N)*16)); + }, + /* nothing */ +) + + + +DEF_MACRO(fGETWORD, + ((size8s_t)((size4s_t)((SRC>>((N)*32))&0x0ffffffffLL))), + /* nothing */ +) + +DEF_MACRO(fGETUWORD, + ((size8u_t)((size4u_t)((SRC>>((N)*32))&0x0ffffffffLL))), + /* nothing */ +) + +DEF_MACRO(fSETWORD, + { + DST = (DST & ~(0x0ffffffffLL<<((N)*32))) | (((VAL) & 0x0ffffffffLL) << ((N)*32)); + }, + /* nothing */ +) + +DEF_MACRO(fSETBIT, + { + DST = (DST & ~(1ULL<<(N))) | (((size8u_t)(VAL))<<(N)); + }, + /* nothing */ +) + +DEF_MACRO(fGETBIT, + (((SRC)>>N)&1), + /* nothing */ +) + + +DEF_MACRO(fSETBITS, + do { + int j; + for (j=LO;j<=HI;j++) { + fSETBIT(j,DST,VAL); + } + } while (0), + /* nothing */ +) + +/*************************************/ +/* Used for parity, etc........ */ +/*************************************/ +DEF_MACRO(fCOUNTONES_4, + count_ones_4(VAL), + /* nothing */ +) + +DEF_MACRO(fCOUNTONES_8, + count_ones_8(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_8, + reverse_bits_8(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_4, + reverse_bits_4(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_8, + count_leading_ones_8(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_4, + count_leading_ones_4(VAL), + /* nothing */ +) + +DEF_MACRO(fINTERLEAVE, + interleave(ODD,EVEN), + /* nothing */ +) + +DEF_MACRO(fDEINTERLEAVE, + deinterleave(MIXED), + /* nothing */ +) + +DEF_MACRO(fHIDE, + A, + () +) + +DEF_MACRO(fCONSTLL, + A##LL, +) + +/* Do the things in the parens, but don't print the parens. */ +DEF_MACRO(fECHO, + (A), + /* nothing */ +) + + +/********************************************/ +/* OS interface and stop/wait */ +/********************************************/ + +DEF_MACRO(fTRAP, + warn("Trap NPC=%x ",fREAD_NPC()); + warn("Trap exception, PCYCLE=%lld TYPE=%d NPC=%x IMM=0x%x",thread->processor_ptr->pstats[pcycles],TRAPTYPE,fREAD_NPC(),IMM); + register_trap_exception(thread,fREAD_NPC(),TRAPTYPE,IMM);, + () +) + +DEF_MACRO(fALIGN_REG_FIELD_VALUE, + ((VAL)<<reg_field_info[FIELD].offset), + /* */ +) + +DEF_MACRO(fGET_REG_FIELD_MASK, + (((1<<reg_field_info[FIELD].width)-1)<<reg_field_info[FIELD].offset), + /* */ +) + +DEF_MACRO(fREAD_REG_FIELD, + fEXTRACTU_BITS(thread->Regs[REG_##REG], + reg_field_info[FIELD].width, + reg_field_info[FIELD].offset), + /* ATTRIBS */ +) + +DEF_MACRO(fGET_FIELD, + fEXTRACTU_BITS(VAL, + reg_field_info[FIELD].width, + reg_field_info[FIELD].offset), + /* ATTRIBS */ +) + +DEF_MACRO(fSET_FIELD, + fINSERT_BITS(VAL, + reg_field_info[FIELD].width, + reg_field_info[FIELD].offset, + (NEWVAL)), + /* ATTRIBS */ +) + +/********************************************/ +/* Cache Management */ +/********************************************/ + +DEF_MACRO(fBARRIER, + { + sys_barrier(thread, insn->slot); + }, + () +) + +DEF_MACRO(fSYNCH, + { + sys_sync(thread, insn->slot); + }, + () +) + +DEF_MACRO(fISYNC, + { + sys_isync(thread, insn->slot); + }, + () +) + + +DEF_MACRO(fDCFETCH, + sys_dcfetch(thread, (REG), insn->slot), + (A_MEMLIKE) +) + +DEF_MACRO(fICINVA, + { + arch_internal_flush(thread->processor_ptr, 0, 0xffffffff); + sys_icinva(thread, (REG),insn->slot); + }, + (A_ICINVA) +) + +DEF_MACRO(fL2FETCH, + sys_l2fetch(thread, ADDR,HEIGHT,WIDTH,STRIDE,FLAGS, insn->slot), + (A_MEMLIKE,A_L2FETCH) +) + +DEF_MACRO(fDCCLEANA, + sys_dccleana(thread, (REG)), + (A_MEMLIKE) +) + +DEF_MACRO(fDCCLEANINVA, + sys_dccleaninva(thread, (REG), insn->slot), + (A_MEMLIKE,A_DCCLEANINVA) +) + +DEF_MACRO(fDCZEROA, + sys_dczeroa(thread, (REG)), + (A_MEMLIKE) +) + +DEF_MACRO(fCHECKFORPRIV, + {sys_check_privs(thread); if (EXCEPTION_DETECTED) return; }, + () +) + +DEF_MACRO(fCHECKFORGUEST, + {sys_check_guest(thread); if (EXCEPTION_DETECTED) return; }, + () +) + +DEF_MACRO(fBRANCH_SPECULATE_STALL, + { +sys_speculate_branch_stall(thread, insn->slot, JUMP_COND(JUMP_PRED_SET), + SPEC_DIR, + DOTNEWVAL, + HINTBITNUM, + STRBITNUM, + 0, + thread->last_pkt->pkt_has_dual_jump, + insn->is_2nd_jump, + (thread->fetch_access.vaddr + insn->encoding_offset*4)); + }, + () +) +
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 17/34] Hexagon (target/hexagon/imported) arch import - macro definitions
Quoted 9 lines · Taylor Simpson
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.
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/imported/macros.def | 1529 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1529 insertions(+) create mode 100755 target/hexagon/imported/macros.def
You might as well squash all of the patches dealing with imported files, because they're beyond review. They are what they are: another project's files.
Give that squashed patch my
r~
PS: I notice that the README mentions archlib, but does not give a pointer to it.
RE: [RFC PATCH v3 17/34] Hexagon (target/hexagon/imported) arch import - macro definitions
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 9:17 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 17/34] Hexagon (target/hexagon/imported) arch import - macro definitions
Quoted 7 lines
You might as well squash all of the patches dealing with imported files, because they're beyond review. They are what they are: another project's files.
Give that squashed patch my
OK
Quoted 2 lines
PS: I notice that the README mentions archlib, but does not give a pointer to it.
Other than what we import here, it's not open source.
RFC PATCH v3 18/34 Hexagon (target/hexagon/imported) arch import - instruction semantics
In reply to Taylor SimpsonImported from the Hexagon architecture library
imported/allidefs.def Top level instruction definition file
imported/*.idef Instruction definition files
These files are input to the first phase of the generator (gen_semantics.c) to create a python include file with the instruction semantics and attributes. The python include file is fed to the second phase to generate various header files.
--- target/hexagon/imported/allidefs.def | 30 + target/hexagon/imported/alu.idef | 1259 +++++++++++++++++++++++++++++++++ target/hexagon/imported/branch.idef | 328 +++++++++ target/hexagon/imported/compare.idef | 621 ++++++++++++++++ target/hexagon/imported/float.idef | 313 ++++++++ target/hexagon/imported/ldst.idef | 286 ++++++++ target/hexagon/imported/mpy.idef | 1212 +++++++++++++++++++++++++++++++ target/hexagon/imported/shift.idef | 1067 ++++++++++++++++++++++++++++ target/hexagon/imported/subinsns.idef | 152 ++++ target/hexagon/imported/system.idef | 69 ++ 10 files changed, 5337 insertions(+) create mode 100644 target/hexagon/imported/allidefs.def create mode 100644 target/hexagon/imported/alu.idef create mode 100644 target/hexagon/imported/branch.idef create mode 100644 target/hexagon/imported/compare.idef create mode 100644 target/hexagon/imported/float.idef create mode 100644 target/hexagon/imported/ldst.idef create mode 100644 target/hexagon/imported/mpy.idef create mode 100644 target/hexagon/imported/shift.idef create mode 100644 target/hexagon/imported/subinsns.idef create mode 100644 target/hexagon/imported/system.idef
target/hexagon/imported/allidefs.def new file +30 -0
@@ -0,0 +1,30 @@ +/* + * Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +/* + * 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 +1259 -0
1,259 lines not on this page · raw message
target/hexagon/imported/branch.idef new file +328 -0
328 lines not on this page · raw message
target/hexagon/imported/compare.idef new file +621 -0
621 lines not on this page · raw message
target/hexagon/imported/float.idef new file +313 -0
313 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/mpy.idef new file +1212 -0
163 lines not on this page · raw message
target/hexagon/imported/shift.idef new file +1067 -0
1,067 lines not on this page · raw message
target/hexagon/imported/subinsns.idef new file +152 -0
152 lines not on this page · raw message
target/hexagon/imported/system.idef new file +69 -0
69 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.
RFC PATCH v3 19/34 Hexagon (target/hexagon/imported) arch import - instruction encoding
In reply to Taylor SimpsonImported from the Hexagon architecture library
Instruction encoding bit patterns for every instruction
--- target/hexagon/imported/encode.def | 125 ++ target/hexagon/imported/encode_pp.def | 2110 ++++++++++++++++++++++++++++ target/hexagon/imported/encode_subinsn.def | 150 ++ 3 files changed, 2385 insertions(+) create mode 100644 target/hexagon/imported/encode.def create mode 100644 target/hexagon/imported/encode_pp.def create mode 100644 target/hexagon/imported/encode_subinsn.def
target/hexagon/imported/encode.def new file +125 -0
@@ -0,0 +1,125 @@ +/* + * Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +/* + * This just includes all encoding files + */ + +#ifndef DEF_FIELD32 +#define __SELF_DEF_FIELD32 +#define DEF_FIELD32(...) /* nothing */ +#endif + +#ifndef DEF_CLASS32 +#define __SELF_DEF_CLASS32 +#define DEF_CLASS32(...) /* nothing */ +#endif + +#ifndef DEF_ANTICLASS32 +#define __SELF_DEF_ANTICLASS32 +#define DEF_ANTICLASS32(...) /* nothing */ +#endif + +#ifndef LEGACY_DEF_ENC32 +#define __SELF_DEF_LEGACY_DEF_ENC32 +#define LEGACY_DEF_ENC32(...) /* nothing */ +#endif + +#ifndef DEF_FIELDROW_DESC32 +#define __SELF_DEF_FIELDROW_DESC32 +#define DEF_FIELDROW_DESC32(...) /* nothing */ +#endif + +#ifndef DEF_ENC32 +#define __SELF_DEF_ENC32 +#define DEF_ENC32(...) /* nothing */ +#endif + +#ifndef DEF_PACKED32 +#define __SELF_DEF_PACKED32 +#define DEF_PACKED32(...) /* nothing */ +#endif + +#ifndef DEF_ENC_SUBINSN +#define __SELF_DEF_ENC_SUBINSN +#define DEF_ENC_SUBINSN(...) /* nothing */ +#endif + +#ifndef DEF_EXT_ENC +#define __SELF_DEF_EXT_ENC +#define DEF_EXT_ENC(...) /* nothing */ +#endif + +#ifndef DEF_EXT_SPACE +#define __SELF_DEF_EXT_SPACE +#define DEF_EXT_SPACE(...) /* nothing */ +#endif + +#include "encode_pp.def" +#include "encode_subinsn.def" + +#ifdef __SELF_DEF_FIELD32 +#undef __SELF_DEF_FIELD32 +#undef DEF_FIELD32 +#endif + +#ifdef __SELF_DEF_CLASS32 +#undef __SELF_DEF_CLASS32 +#undef DEF_CLASS32 +#endif + +#ifdef __SELF_DEF_ANTICLASS32 +#undef __SELF_DEF_ANTICLASS32 +#undef DEF_ANTICLASS32 +#endif + +#ifdef __SELF_DEF_LEGACY_DEF_ENC32 +#undef __SELF_DEF_LEGACY_DEF_ENC32 +#undef LEGACY_DEF_ENC32 +#endif + +#ifdef __SELF_DEF_FIELDROW_DESC32 +#undef __SELF_DEF_FIELDROW_DESC32 +#undef DEF_FIELDROW_DESC32 +#endif + +#ifdef __SELF_DEF_ENC32 +#undef __SELF_DEF_ENC32 +#undef DEF_ENC32 +#endif + +#ifdef __SELF_DEF_EXT_SPACE +#undef __SELF_DEF_EXT_SPACE +#undef DEF_EXT_SPACE +#endif + + +#ifdef __SELF_DEF_PACKED32 +#undef __SELF_DEF_PACKED32 +#undef DEF_PACKED32 +#endif + +#ifdef __SELF_DEF_ENC_SUBINSN +#undef __SELF_DEF_ENC_SUBINSN +#undef DEF_ENC_SUBINSN +#endif + +#ifdef __SELF_DEF_EXT_ENC +#undef __SELF_DEF_EXT_ENC +#undef DEF_EXT_ENC +#endif +
target/hexagon/imported/encode_pp.def new file +2110 -0
2,110 lines not on this page · raw message
target/hexagon/imported/encode_subinsn.def new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v3 20/34 Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics
In reply to Taylor SimpsonRun the C preprocessor across the instruction definition files and macro definitoin file to expand macros and prepare the semantics_generated.pyinc file. The resulting file contains one entry with the semantics for each instruction and one line with the instruction attributes associated with each macro.
--- target/hexagon/gen_semantics.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 target/hexagon/gen_semantics.c
target/hexagon/gen_semantics.c new file +88 -0
@@ -0,0 +1,88 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* This program generates the semantics file that is processed by +* the do_qemu.py script. We use the C preporcessor to manipulate the +* files imported from the Hexagon architecture library. +*/ + +#include <stdio.h> +#define STRINGIZE (X ) #X + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_semantics ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + } + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +*/ +#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
RFC PATCH v3 21/34 Hexagon (target/hexagon) generator phase 2 - generate header files
In reply to Taylor SimpsonPython scripts generate the following files
helper_protos_generated.h
For each instruction we create DEF_HELPER function prototype
helper_funcs_generated.h
For each instruction we create the helper function definition
tcg_funcs_generated.h
For each instruction we create TCG code to generate call to helper
shortcode_generated.h
Generate a table of instruction "shortcode" semantics
opcodes_def_generated.h
Gives a list of all the opcodes
op_attribs_generated.h
Lists all the attributes associated with each instruction
op_regs_generated.h
Lists the register and immediate operands for each instruction
printinsn_generated.h
Data for printing (disassembling) each instruction (format string + operands)
--- target/hexagon/gen_helper_funcs.py | 230 +++++++++++++++++++++++++++ target/hexagon/gen_helper_protos.py | 158 +++++++++++++++++++ target/hexagon/gen_op_attribs.py | 46 ++++++ target/hexagon/gen_op_regs.py | 119 ++++++++++++++ target/hexagon/gen_opcodes_def.py | 43 ++++++ target/hexagon/gen_printinsn.py | 182 ++++++++++++++++++++++ target/hexagon/gen_shortcode.py | 71 +++++++++ target/hexagon/gen_tcg_funcs.py | 301 ++++++++++++++++++++++++++++++++++++ target/hexagon/hex_common.py | 204 ++++++++++++++++++++++++ 9 files changed, 1354 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_funcs.py create mode 100755 target/hexagon/hex_common.py
target/hexagon/gen_helper_funcs.py new file +230 -0
@@ -0,0 +1,230 @@ +#!/usr/bin/env python3 + +## +## Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## + +import sys +import re +import string +from io import StringIO + +from hex_common import * + +## +## Helpers for gen_helper_function +## +def gen_decl_ea(f): + f.write("size4u_t EA;\n") + +def gen_helper_return_type(f,regtype,regid,regno): + if regno > 1 : f.write(", ") + f.write("int32_t") + +def gen_helper_return_type_pair(f,regtype,regid,regno): + if regno > 1 : f.write(", ") + f.write("int64_t") + +def gen_helper_arg(f,regtype,regid,regno): + if regno > 0 : f.write(", " ) + f.write("int32_t %s%sV" % (regtype,regid)) + +def gen_helper_arg_new(f,regtype,regid,regno): + if regno >= 0 : f.write(", " ) + f.write("int32_t %s%sN" % (regtype,regid)) + +def gen_helper_arg_pair(f,regtype,regid,regno): + if regno >= 0 : f.write(", ") + f.write("int64_t %s%sV" % (regtype,regid)) + +def gen_helper_arg_opn(f,regtype,regid,i,tag): + if (is_pair(regid)): + gen_helper_arg_pair(f,regtype,regid,i) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + gen_helper_arg(f,regtype,regid,i) + elif is_new_val(regtype, regid, tag): + gen_helper_arg_new(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_arg_imm(f,immlett): + f.write(", int32_t %s" % (imm_name(immlett))) + +def gen_helper_dest_decl(f,regtype,regid,regno,subfield=""): + f.write("int32_t %s%sV%s = 0;\n" % \ + (regtype,regid,subfield)) + +def gen_helper_dest_decl_pair(f,regtype,regid,regno,subfield=""): + f.write("int64_t %s%sV%s = 0;\n" % \ + (regtype,regid,subfield)) + +def gen_helper_dest_decl_opn(f,regtype,regid,i): + if (is_pair(regid)): + gen_helper_dest_decl_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_dest_decl(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_return(f,regtype,regid,regno): + f.write("return %s%sV;\n" % (regtype,regid)) + +def gen_helper_return_pair(f,regtype,regid,regno): + f.write("return %s%sV;\n" % (regtype,regid)) + +def gen_helper_return_opn(f, regtype, regid, i): + if (is_pair(regid)): + gen_helper_return_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_return(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +## +## Generate the TCG code to call the helper +## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} +## We produce: +## #ifndef fGEN_TCG_A2_add +## 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; +## } +## #endif +## +def gen_helper_function(f, tag, tagregs, tagimms): + regs = tagregs[tag] + imms = tagimms[tag] + + f.write('#ifndef fGEN_TCG_%s\n' % tag) + numresults = 0 + numscalarresults = 0 + numscalarreadwrite = 0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + numresults += 1 + if (is_scalar_reg(regtype)): + numscalarresults += 1 + if (is_readwrite(regid)): + if (is_scalar_reg(regtype)): + numscalarreadwrite += 1 + + if (numscalarresults > 1): + ## The helper is bogus when there is more than one result + f.write("void HELPER(%s)(CPUHexagonState *env) { BOGUS_HELPER(%s); }\n" + % (tag, tag)) + else: + ## The return type of the function is the type of the destination + ## register + i=0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + if (is_pair(regid)): + gen_helper_return_type_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_return_type(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + i += 1 + + if (numscalarresults == 0): + f.write("void") + f.write(" HELPER(%s)(CPUHexagonState *env" % tag) + + i = 1 + + ## Arguments to the helper function are the source regs and immediates + for regtype,regid,toss,numregs in regs: + if (is_read(regid)): + gen_helper_arg_opn(f,regtype,regid,i,tag) + i += 1 + for immlett,bits,immshift in imms: + gen_helper_arg_imm(f,immlett) + i += 1 + if need_slot(tag): + if i > 0: f.write(", ") + f.write("uint32_t slot") + i += 1 + if need_part1(tag): + if i > 0: f.write(", ") + f.write("uint32_t part1") + f.write(")\n{\n") + if (not need_slot(tag)): + f.write("uint32_t slot __attribute__((unused)) = 4;\n" ) + if need_ea(tag): gen_decl_ea(f) + ## Declare the return variable + i=0 + for regtype,regid,toss,numregs in regs: + if (is_writeonly(regid)): + gen_helper_dest_decl_opn(f,regtype,regid,i) + i += 1 + + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_START();\n'); + + f.write(semdict[tag]) + f.write("\n") + + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_END();\n'); + + ## Save/return the return variable + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + gen_helper_return_opn(f, regtype, regid, i) + f.write("}\n") + ## End of the helper definition + f.write('#endif\n') + +def main(): + read_semantics_file(sys.argv[1]) + read_attribs_file(sys.argv[2]) + calculate_attribs() + tagregs = get_tagregs() + tagimms = get_tagimms() + + f = StringIO() + + for tag in tags: + ## Skip the priv instructions + if ( "A_PRIV" in attribdict[tag] ) : + continue + ## Skip the guest instructions + if ( "A_GUEST" in attribdict[tag] ) : + continue + ## Skip the diag instructions + if ( tag == "Y6_diag" ) : + continue + if ( tag == "Y6_diag0" ) : + continue + if ( tag == "Y6_diag1" ) : + continue + + gen_helper_function(f, tag, tagregs, tagimms) + + + realf = open('helper_funcs_generated.h','w') + realf.write(f.getvalue()) + realf.close() + f.close() + +if __name__ == "__main__": + main()
target/hexagon/gen_helper_protos.py new file +158 -0
158 lines not on this page · raw message
target/hexagon/gen_op_attribs.py new file +46 -0
46 lines not on this page · raw message
target/hexagon/gen_op_regs.py new file +119 -0
119 lines not on this page · raw message
target/hexagon/gen_opcodes_def.py new file +43 -0
43 lines not on this page · raw message
target/hexagon/gen_printinsn.py new file +182 -0
182 lines not on this page · raw message
target/hexagon/gen_shortcode.py new file +71 -0
71 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py new file +301 -0
301 lines not on this page · raw message
target/hexagon/hex_common.py new file +204 -0
204 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v3 22/34 Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree
In reply to Taylor SimpsonRun 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 | 191 ++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 target/hexagon/gen_dectree_import.c
target/hexagon/gen_dectree_import.c new file +191 -0
@@ -0,0 +1,191 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* This program generates the encodings file that is processed by +* the dectree.py script to produce the decoding tree. We use the C +* preprocessor to manipulate the files imported from the Hexagon +* architecture library. +*/ +#include "qemu/osdep.h" +#include "opcodes.h" + +#define STRINGIZE (X ) #X + +const char *opcode_names[] = { +#define OPCODE(IID) STRINGIZE(IID) +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +const char *opcode_syntax[XX_LAST_OPCODE ]; + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +*/ +void opcode_init (void ) +{ +#define Q6INSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#define EXTINSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#include "imported/allidefs.def" +#undef Q6INSN +#undef EXTINSN +} + +const char *opcode_rregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +const char *opcode_wregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +opcode_encoding_t opcode_encodings[] = { +#define DEF_ENC32(TAG, ENCSTR) \ + [TAG] = { .encoding = ENCSTR }, +#define DEF_ENC_SUBINSN(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#define DEF_EXT_ENC(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#include "imported/encode.def" +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC +}; + +static const char *const opcode_enc_class_names[XX_LAST_ENC_CLASS ] = { +"NORMAL" , +"16BIT" , +"SUBINSN_A" , +"SUBINSN_L1" , +"SUBINSN_L2" , +"SUBINSN_S1" , +"SUBINSN_S2" , +"EXT_noext" , +"EXT_mmvec" , +}; + +static const char *get_opcode_enc (int opcode) +{ +const char *tmp = opcode_encodings[opcode].encoding; +if (tmp ==NULL ) { + tmp ="MISSING ENCODING" ; + } +return tmp; +} + +static const char *get_opcode_enc_class (int opcode) +{ +return opcode_enc_class_names[opcode_encodings[opcode].enc_class]; +} + +static void gen_iset_table (FILE *out) +{ +int i; + +fprintf (out,"iset = {\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\' : {\n" , opcode_names[i]); +fprintf (out,"\t\t\'tag\' : \'%s\',\n" , opcode_names[i]); +fprintf (out,"\t\t\'syntax\' : \'%s\',\n" , opcode_syntax[i]); +fprintf (out,"\t\t\'rregs\' : \'%s\',\n" , opcode_rregs[i]); +fprintf (out,"\t\t\'wregs\' : \'%s\',\n" , opcode_wregs[i]); +fprintf (out,"\t\t\'enc\' : \'%s\',\n" ,get_opcode_enc (i)); +fprintf (out,"\t\t\'enc_class\' : \'%s\',\n" ,get_opcode_enc_class (i)); +fprintf (out,"\t},\n" ); + } +fprintf (out,"};\n\n" ); +} + +static void gen_tags_list (FILE *out) +{ +int i; + +fprintf (out,"tags = [\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\',\n" , opcode_names[i]); + } +fprintf (out,"];\n\n" ); +} + +static void gen_enc_ext_spaces_table (FILE *out) +{ +fprintf (out,"enc_ext_spaces = {\n" ); +#define DEF_EXT_SPACE (SPACEID ,ENCSTR ) \ + fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR); +#include "imported/encode.def" +#undef DEF_EXT_SPACE +fprintf (out,"};\n\n" ); +} + +static void gen_subinsn_groupings_table (FILE *out) +{ +fprintf (out,"subinsn_groupings = {\n" ); +#define DEF_PACKED32 (TAG ,TYPEA ,TYPEB ,ENCSTR ) \ + do { \ + fprintf(out, "\t\'%s\' : {\n", #TAG); \ + fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \ + fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \ + fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \ + fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \ + fprintf(out, "\t},\n"); \ + } while (0); +#include "imported/encode.def" +#undef DEF_PACKED32 +fprintf (out,"};\n\n" ); +} + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_dectree_import ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + } + +opcode_init (); +gen_iset_table (outfile); +gen_tags_list (outfile); +gen_enc_ext_spaces_table (outfile); +gen_subinsn_groupings_table (outfile); + +fclose (outfile); +return 0 ; +}
Signature · 1 line
2.7.4
RFC PATCH v3 23/34 Hexagon (target/hexagon) generater phase 4 - decode tree
In reply to Taylor SimpsonPython script that emits the decode tree in dectree_generated.h.
--- target/hexagon/dectree.py | 352 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 352 insertions(+) create mode 100755 target/hexagon/dectree.py
target/hexagon/dectree.py new file +352 -0
@@ -0,0 +1,352 @@ +#!/usr/bin/env python3 + +## +## Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## + +import io +import re + +import sys +import iset + +encs = {tag : ''.join(reversed(iset.iset[tag]['enc'].replace(' ', ''))) + for tag in iset.tags if iset.iset[tag]['enc'] != 'MISSING ENCODING'} + +enc_classes = set([iset.iset[tag]['enc_class'] for tag in encs.keys()]) +subinsn_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class.startswith('SUBINSN_')]) +ext_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class not in ('NORMAL', '16BIT') and \ + not enc_class.startswith('SUBINSN_')]) + +try: + subinsn_groupings = iset.subinsn_groupings +except AttributeError: + subinsn_groupings = {} + +for (tag, subinsn_grouping) in subinsn_groupings.items(): + encs[tag] = ''.join(reversed(subinsn_grouping['enc'].replace(' ', ''))) + +dectree_normal = {'leaves' : set()} +dectree_16bit = {'leaves' : set()} +dectree_subinsn_groupings = {'leaves' : set()} +dectree_subinsns = {name : {'leaves' : set()} for name in subinsn_enc_classes} +dectree_extensions = {name : {'leaves' : set()} for name in ext_enc_classes} + +for tag in encs.keys(): + if tag in subinsn_groupings: + dectree_subinsn_groupings['leaves'].add(tag) + continue + enc_class = iset.iset[tag]['enc_class'] + if enc_class.startswith('SUBINSN_'): + if len(encs[tag]) != 32: + encs[tag] = encs[tag] + '0' * (32 - len(encs[tag])) + dectree_subinsns[enc_class]['leaves'].add(tag) + elif enc_class == '16BIT': + if len(encs[tag]) != 16: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 16 bits!'.format(tag, enc_class)) + dectree_16bit['leaves'].add(tag) + else: + if len(encs[tag]) != 32: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 32 bits!'.format(tag, enc_class)) + if enc_class == 'NORMAL': + dectree_normal['leaves'].add(tag) + else: + dectree_extensions[enc_class]['leaves'].add(tag) + +faketags = set() +for (tag, enc) in iset.enc_ext_spaces.items(): + faketags.add(tag) + encs[tag] = ''.join(reversed(enc.replace(' ', ''))) + dectree_normal['leaves'].add(tag) + +faketags |= set(subinsn_groupings.keys()) + +def every_bit_counts(bitset): + for i in range(1, len(next(iter(bitset)))): + if len(set([bits[:i] + bits[i+1:] for bits in bitset])) == len(bitset): + return False + return True + +def auto_separate(node): + tags = node['leaves'] + if len(tags) <= 1: + return + enc_width = len(encs[next(iter(tags))]) + opcode_bit_for_all = \ + [all([encs[tag][i] in '01' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_0_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '0' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_1_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '1' \ + for tag in tags]) for i in range(enc_width)] + differentiator_opcode_bit = \ + [opcode_bit_for_all[i] and \ + not (opcode_bit_is_0_for_all[i] or \ + opcode_bit_is_1_for_all[i]) \ + for i in range(enc_width)] + best_width = 0 + for width in range(4, 0, -1): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + (len(bitset) == len(tags) or every_bit_counts(bitset)): + best_width = width + best_lsb = lsb + caught_all_tags = len(bitset) == len(tags) + break + if best_width != 0: + break + if best_width == 0: + raise Exception('Could not find a way to differentiate the encodings ' + + 'of the following tags:\n{}'.format('\n'.join(tags))) + if caught_all_tags: + for width in range(1, best_width): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + len(bitset) == len(tags): + best_width = width + best_lsb = lsb + break + else: + continue + break + node['separator_lsb'] = best_lsb + node['separator_width'] = best_width + node['children'] = [] + for value in range(2 ** best_width): + child = {} + bits = ''.join(reversed('{:0{}b}'.format(value, best_width))) + child['leaves'] = \ + set([tag for tag in tags \ + if encs[tag][best_lsb:best_lsb+best_width] == bits]) + node['children'].append(child) + for child in node['children']: + auto_separate(child) + +auto_separate(dectree_normal) +auto_separate(dectree_16bit) +if subinsn_groupings: + auto_separate(dectree_subinsn_groupings) +for dectree_subinsn in dectree_subinsns.values(): + auto_separate(dectree_subinsn) +for dectree_ext in dectree_extensions.values(): + auto_separate(dectree_ext) + +for tag in faketags: + del encs[tag] + +def table_name(parents, node): + path = parents + [node] + root = path[0] + tag = next(iter(node['leaves'])) + if tag in subinsn_groupings: + enc_width = len(subinsn_groupings[tag]['enc'].replace(' ', '')) + else: + tag = next(iter(node['leaves'] - faketags)) + enc_width = len(encs[tag]) + determining_bits = ['_'] * enc_width + for (parent, child) in zip(path[:-1], path[1:]): + lsb = parent['separator_lsb'] + width = parent['separator_width'] + value = parent['children'].index(child) + determining_bits[lsb:lsb+width] = \ + list(reversed('{:0{}b}'.format(value, width))) + if tag in subinsn_groupings: + name = 'DECODE_ROOT_EE' + else: + enc_class = iset.iset[tag]['enc_class'] + if enc_class in ext_enc_classes: + name = 'DECODE_EXT_{}'.format(enc_class) + elif enc_class in subinsn_enc_classes: + name = 'DECODE_SUBINSN_{}'.format(enc_class) + else: + name = 'DECODE_ROOT_{}'.format(enc_width) + if node != root: + name += '_' + ''.join(reversed(determining_bits)) + return name + +def print_node(f, node, parents): + if len(node['leaves']) <= 1: + return + name = table_name(parents, node) + lsb = node['separator_lsb'] + width = node['separator_width'] + print('DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + for child in node['children']: + if len(child['leaves']) == 0: + print('INVALID()', file=f) + elif len(child['leaves']) == 1: + (tag,) = child['leaves'] + if tag in subinsn_groupings: + class_a = subinsn_groupings[tag]['class_a'] + class_b = subinsn_groupings[tag]['class_b'] + enc = subinsn_groupings[tag]['enc'].replace(' ', '') + if 'RESERVED' in tag: + print('INVALID()', file=f) + else: + print('SUBINSNS({},{},{},"{}")'.\ + format(tag, class_a, class_b, enc), file=f) + elif tag in iset.enc_ext_spaces: + enc = iset.enc_ext_spaces[tag].replace(' ', '') + print('EXTSPACE({},"{}")'.format(tag, enc), file=f) + else: + enc = ''.join(reversed(encs[tag])) + print('TERMINAL({},"{}")'.format(tag, enc), file=f) + else: + print('TABLE_LINK({})'.format(table_name(parents + [node], child)), + file=f) + print('DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + print(file=f) + parents.append(node) + for child in node['children']: + print_node(f, child, parents) + parents.pop() + +def print_tree(f, tree): + print_node(f, tree, []) + +def print_match_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = ''.join(reversed(encs[tag])) + mask = int(re.sub(r'[^1]', r'0', enc.replace('0', '1')), 2) + match = int(re.sub(r'[^01]', r'0', enc), 2) + suffix = '' + print('DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)'.\ + format(suffix, tag, mask, match), file=f) + +regre = re.compile( + r'((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)') +immre = re.compile(r'[#]([rRsSuUm])(\d+)(?:[:](\d+))?') + +def ordered_unique(l): + return sorted(set(l), key=l.index) + +implicit_registers = { + 'SP' : 29, + 'FP' : 30, + 'LR' : 31 +} + +num_registers = { + 'R' : 32, + 'V' : 32 +} + +def print_op_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = encs[tag] + print(file=f) + print('DECODE_OPINFO({},'.format(tag), file=f) + regs = ordered_unique(regre.findall(iset.iset[tag]['syntax'])) + imms = ordered_unique(immre.findall(iset.iset[tag]['syntax'])) + regno = 0 + for reg in regs: + reg_type = reg[0] + reg_letter = reg[1][0] + reg_num_choices = int(reg[3].rstrip('S')) + reg_mapping = reg[0] + ''.join(['_' for letter in reg[1]]) + reg[3] + reg_enc_fields = re.findall(reg_letter + '+', enc) + if len(reg_enc_fields) == 0: + raise Exception('Tag "{}" missing register field!'.format(tag)) + if len(reg_enc_fields) > 1: + raise Exception('Tag "{}" has split register field!'.\ + format(tag)) + reg_enc_field = reg_enc_fields[0] + if 2 ** len(reg_enc_field) != reg_num_choices: + raise Exception('Tag "{}" has incorrect register field width!'.\ + format(tag)) + print(' DECODE_REG({},{},{})'.\ + format(regno, len(reg_enc_field), enc.index(reg_enc_field)), + file=f) + if reg_type in num_registers and \ + reg_num_choices != num_registers[reg_type]: + print(' DECODE_MAPPED_REG({},{})'.\ + format(regno, reg_mapping), file=f) + regno += 1 + def implicit_register_key(reg): + return implicit_registers[reg] + for reg in sorted( + set([r for r in (iset.iset[tag]['rregs'].split(',') + \ + iset.iset[tag]['wregs'].split(',')) \ + if r in implicit_registers]), key=implicit_register_key): + print(' DECODE_IMPL_REG({},{})'.\ + format(regno, implicit_registers[reg]), file=f) + regno += 1 + if imms and imms[0][0].isupper(): + imms = reversed(imms) + for imm in imms: + if imm[0].isupper(): + immno = 1 + else: + immno = 0 + imm_type = imm[0] + imm_width = int(imm[1]) + imm_shift = imm[2] + if imm_shift: + imm_shift = int(imm_shift) + else: + imm_shift = 0 + if imm_type.islower(): + imm_letter = 'i' + else: + imm_letter = 'I' + remainder = imm_width + for m in reversed(list(re.finditer(imm_letter + '+', enc))): + remainder -= m.end() - m.start() + print(' DECODE_IMM({},{},{},{})'.\ + format(immno, m.end() - m.start(), m.start(), remainder), + file=f) + if remainder != 0: + if imm[2]: + imm[2] = ':' + imm[2] + raise Exception('Tag "{}" has an incorrect number of ' + \ + 'encoding bits for immediate "{}"'.\ + format(tag, ''.join(imm))) + if imm_type.lower() in 'sr': + print(' DECODE_IMM_SXT({},{})'.\ + format(immno, imm_width), file=f) + if imm_type.lower() == 'n': + print(' DECODE_IMM_NEG({},{})'.\ + format(immno, imm_width), file=f) + if imm_shift: + print(' DECODE_IMM_SHIFT({},{})'.\ + format(immno, imm_shift), file=f) + print(')', file=f) + +if __name__ == '__main__': + f = io.StringIO() + print_tree(f, dectree_normal) + print_tree(f, dectree_16bit) + if subinsn_groupings: + print_tree(f, dectree_subinsn_groupings) + for (name, dectree_subinsn) in sorted(dectree_subinsns.items()): + print_tree(f, dectree_subinsn) + for (name, dectree_ext) in sorted(dectree_extensions.items()): + print_tree(f, dectree_ext) + print_match_info(f) + print_op_info(f) + open('dectree_generated.h', 'w').write(f.getvalue())
Signature · 1 line
2.7.4
RFC PATCH v3 24/34 Hexagon (target/hexagon) opcode data structures
In reply to Taylor Simpson--- target/hexagon/opcodes.h | 66 +++++++++++++++ target/hexagon/opcodes.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+) create mode 100644 target/hexagon/opcodes.h create mode 100644 target/hexagon/opcodes.c
target/hexagon/opcodes.h new file +66 -0
@@ -0,0 +1,66 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_OPCODES_H +#define HEXAGON_OPCODES_H + +#include "hex_arch_types.h" +#include "attribs.h" + +typedef enum { +#define OPCODE(IID) IID +#include "opcodes_def_generated.h" + XX_LAST_OPCODE +#undef OPCODE +} opcode_t; + +typedef enum { +NORMAL , +HALF , +SUBINSN_A , +SUBINSN_L1 , +SUBINSN_L2 , +SUBINSN_S1 , +SUBINSN_S2 , + EXT_noext, + EXT_mmvec, +XX_LAST_ENC_CLASS +}enc_class_t ; + +extern const char *opcode_names[]; + +extern const char *opcode_reginfo[]; +extern const char *opcode_rregs[]; +extern const char *opcode_wregs[]; + +typedef struct { +const char *const encoding; +size4u_t vals; +size4u_t dep_vals; +const enc_class_t enc_class; +}opcode_encoding_t ; + +extern opcode_encoding_t opcode_encodings[XX_LAST_OPCODE ]; + +extern size4u_t + opcode_attribs[XX_LAST_OPCODE ][(A_ZZ_LASTATTRIB /ATTRIB_WIDTH ) +1 ]; + +extern void opcode_init (void ); + +extern int opcode_which_immediate_is_extended (opcode_t opcode); + +#endif
target/hexagon/opcodes.c new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 24/34] Hexagon (target/hexagon) opcode data structures
target/hexagon/opcodes.h line 48
Quoted 5 lines · Taylor Simpson
target/hexagon/opcodes.h new file +5
-0+extern const char *opcode_names[]; + +extern const char *opcode_reginfo[]; +extern const char *opcode_rregs[]; +extern const char *opcode_wregs[];
const char * const
Quoted 1 line
+extern
opcode_encoding_topcode_encodings[XX_LAST_OPCODE];
const.
target/hexagon/opcodes.h line 60
Quoted 2 lines
target/hexagon/opcodes.h new file +2
-0+extern size4u_t + opcode_attribs[XX_LAST_OPCODE ][(A_ZZ_LASTATTRIB /ATTRIB_WIDTH ) +1 ];
const.
And using qemu/bitops.h if possible, as discussed earlier vs attribs.h.
Quoted 6 lines
target/hexagon/opcodes.c new file +6
-0+const char *opcode_short_semantics[] = { +#define OPCODE(X) NULL +#include "opcodes_def_generated.h" +#undef OPCODE +NULL +};
...
target/hexagon/opcodes.c line 176
Quoted 4 lines
target/hexagon/opcodes.c new file +4
-0+#define DEF_SHORTCODE (TAG ,SHORTCODE ) \ + opcode_short_semantics[TAG] = #SHORTCODE; +#include "shortcode_generated.h" +#undef DEF_SHORTCODE
Just initialize opcode_short_semantics with shortcode_generated.h in the first place. Then you don't need to create a table of NULL and overwrite at startup.
And you can also make the table constant.
target/hexagon/opcodes.c line 198
Quoted 4 lines
target/hexagon/opcodes.c new file +4
-0+if (p ==NULL ) { +g_assert_not_reached (); +return 0 ; + }
I prefer assert(p != NULL) to if (test) { abort(); }, where possible. E.g. this later one is fine:
target/hexagon/opcodes.c line 210
Quoted 7 lines
target/hexagon/opcodes.c new file +7
-0+if (islower (*p)) { +return 0 ; + }else if (isupper (*p)) { +return 1 ; + }else { +g_assert_not_reached (); + }
r~
RE: [RFC PATCH v3 24/34] Hexagon (target/hexagon) opcode data structures
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, August 26, 2020 9:26 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 24/34] Hexagon (target/hexagon) opcode data structures
Quoted 7 lines
target/hexagon/opcodes.h line 48
Quoted 5 lines
target/hexagon/opcodes.h new file +5
-0+extern const char *opcode_names[]; + +extern const char *opcode_reginfo[]; +extern const char *opcode_rregs[]; +extern const char *opcode_wregs[];const char * const
OK
Quoted 3 lines
Quoted 1 line
+extern
opcode_encoding_topcode_encodings[XX_LAST_OPCODE];const.
OK
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+extern size4u_t + opcode_attribs[XX_LAST_OPCODE][(A_ZZ_LASTATTRIB /
ATTRIB_WIDTH) + 1];const.
OK
Quoted 1 line
And using
qemu/bitops.hif possible, as discussed earlier vsattribs.h.
Do you mean replace the GET_ATTRIB macro with test_bit from qemu/bitops.h?
Quoted 6 lines
Just initialize
opcode_short_semanticswithshortcode_generated.hin the first
place. Then you don't need to create a table of NULL and overwrite at startup.And you can also make the table constant.
OK
Quoted 7 lines
target/hexagon/opcodes.c line 198
Quoted 4 lines
target/hexagon/opcodes.c new file +4
-0+if (p ==NULL ) { +g_assert_not_reached (); +return 0 ; + }I prefer assert(p != NULL) to if (test) {
abort(); }, where possible. E.g. this later one is fine:
OK
Re: [RFC PATCH v3 24/34] Hexagon (target/hexagon) opcode data structures
Quoted 3 lines · Taylor Simpson
Quoted 1 line
And using
qemu/bitops.hif possible, as discussed earlier vsattribs.h.Do you mean replace the
GET_ATTRIBmacro withtest_bitfromqemu/bitops.h?
No, just define GET_ATTRIB in terms of test_bit, and define opcode_attribs using BITS_TO_LONGS.
r~
RFC PATCH v3 25/34 Hexagon (target/hexagon) macros to interface with the generator
In reply to Taylor SimpsonVarious forms of declare, read, write, free
--- target/hexagon/macros.h | 364 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 target/hexagon/macros.h
target/hexagon/macros.h new file +364 -0
@@ -0,0 +1,364 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_MACROS_H +#define HEXAGON_MACROS_H + +#include "qemu.h" +#include "cpu.h" +#include "hex_regs.h" +#include "reg_fields.h" + +#ifdef QEMU_GENERATE +#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/* +* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_RREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_x (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_y (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) + +#define DECL_PREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_x (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_y (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) + +#define DECL_CREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_CREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) + +#define DECL_MREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_NEW_NREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_NREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_NEW_PREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_PREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_PREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_NEW_OREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_PAIR (NAME ,NUM ,X ,OFF ) \ + TCGv_i64 NAME = tcg_temp_local_new_i64(); \ + size1u_t NUM = REGNO(X) + OFF + +#define DECL_PAIR_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv_i64 NAME = tcg_temp_local_new_i64(); \ + size1u_t NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated) { \ + if (!is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + if (!is_preloaded(ctx, NUM + 1)) { \ + tcg_gen_mov_tl(hex_new_value[NUM + 1], hex_gpr[NUM + 1]); \ + } \ + } \ + } while (0) + +#define DECL_RREG_dd (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_ss (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) +#define DECL_RREG_tt (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) +#define DECL_RREG_xx (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_yy (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) + +#define DECL_CREG_dd (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_CREG_ss (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) + +#define DECL_IMM (NAME ,X ) \ + int NAME = IMMNO(X); \ + do { \ + NAME = NAME; \ + } while (0) +#define DECL_TCG_IMM (TCG_NAME ,VAL ) \ + TCGv TCG_NAME = tcg_const_tl(VAL) + +#define DECL_EA \ + TCGv EA; \ + do { \ + if (GET_ATTRIB(insn->opcode, A_CONDEXEC)) { \ + EA = tcg_temp_local_new(); \ + } else { \ + EA = tcg_temp_new(); \ + } \ + } while (0) + +#define LOG_REG_WRITE (RNUM ,VAL )\ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + gen_log_reg_write(RNUM, VAL, insn->slot, is_predicated); \ + ctx_log_reg_write(ctx, (RNUM)); \ + } while (0) + +#define LOG_PRED_WRITE (PNUM ,VAL ) \ + do { \ + gen_log_pred_write(PNUM, VAL); \ + ctx_log_pred_write(ctx, (PNUM)); \ + } while (0) + +#define FREE_REG (NAME ) \ + tcg_temp_free(NAME) +#define FREE_REG_READONLY (NAME ) \ +/* Nothing */ + +#define FREE_RREG_d (NAME ) FREE_REG(NAME) +#define FREE_RREG_e (NAME ) FREE_REG(NAME) +#define FREE_RREG_s (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_v (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_x (NAME ) FREE_REG(NAME) +#define FREE_RREG_y (NAME ) FREE_REG(NAME) + +#define FREE_PREG_d (NAME ) FREE_REG(NAME) +#define FREE_PREG_e (NAME ) FREE_REG(NAME) +#define FREE_PREG_s (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_v (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_x (NAME ) FREE_REG(NAME) + +#define FREE_CREG_d (NAME ) FREE_REG(NAME) +#define FREE_CREG_s (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_MREG_u (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_NEW_NREG_s (NAME ) FREE_REG(NAME) +#define FREE_NEW_NREG_t (NAME ) FREE_REG(NAME) + +#define FREE_NEW_PREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_NEW_PREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_NEW_PREG_v (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_NEW_OREG_s (NAME ) FREE_REG(NAME) + +#define FREE_REG_PAIR (NAME ) \ + tcg_temp_free_i64(NAME) + +#define FREE_RREG_dd (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_ss (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_tt (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_xx (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_yy (NAME ) FREE_REG_PAIR(NAME) + +#define FREE_CREG_dd (NAME ) FREE_REG_PAIR(NAME) +#define FREE_CREG_ss (NAME ) FREE_REG_PAIR(NAME) + +#define FREE_IMM (NAME )/* nothing */ +#define FREE_TCG_IMM (NAME ) tcg_temp_free(NAME) + +#define FREE_EA \ + tcg_temp_free(EA) +#else +#define LOG_REG_WRITE (RNUM ,VAL )\ + log_reg_write(env, RNUM, VAL, slot) +#define LOG_PRED_WRITE (RNUM ,VAL )\ + log_pred_write(env, RNUM, VAL) +#endif + +#define SLOT_WRAP (CODE ) \ + do { \ + TCGv slot = tcg_const_tl(insn->slot); \ + CODE; \ + tcg_temp_free(slot); \ + } while (0) + +#define PART1_WRAP (CODE ) \ + do { \ + TCGv part1 = tcg_const_tl(insn->part1); \ + CODE; \ + tcg_temp_free(part1); \ + } while (0) + +#define MARK_LATE_PRED_WRITE (RNUM )/* Not modelled in qemu */ + +#define REGNO (NUM ) (insn->regno[NUM]) +#define IMMNO (NUM ) (insn->immed[NUM]) + +#ifdef QEMU_GENERATE +#define READ_REG (dest,NUM ) \ + gen_read_reg(dest, NUM) +#define READ_REG_READONLY (dest,NUM ) \ + do { dest = hex_gpr[NUM]; } while (0) + +#define READ_RREG_s (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_t (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_u (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_x (dest,NUM ) \ + READ_REG(dest, NUM) +#define READ_RREG_y (dest,NUM ) \ + READ_REG(dest, NUM) + +#define READ_OREG_s (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) + +#define READ_CREG_s (dest,NUM ) \ + do { \ + if ((NUM) + HEX_REG_SA0 == HEX_REG_P3_0) { \ + gen_read_p3_0(dest); \ + } else { \ + READ_REG_READONLY(dest, ((NUM) + HEX_REG_SA0)); \ + } \ + } while (0) + +#define READ_MREG_u (dest,NUM ) \ + do { \ + READ_REG_READONLY(dest, ((NUM) + HEX_REG_M0)); \ + dest = dest; \ + } while (0) +#else +#define READ_REG (NUM ) \ + (env->gpr[(NUM)]) +#endif + +#ifdef QEMU_GENERATE +#define READ_REG_PAIR (tmp,NUM ) \ + tcg_gen_concat_i32_i64(tmp, hex_gpr[NUM], hex_gpr[(NUM) + 1]) +#define READ_RREG_ss (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_tt (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_xx (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_yy (tmp,NUM ) READ_REG_PAIR(tmp, NUM) + +#define READ_CREG_PAIR (tmp, i) \ + READ_REG_PAIR(tmp, ((i) + HEX_REG_SA0)) +#define READ_CREG_ss (tmp, i) READ_CREG_PAIR(tmp, i) +#endif + +#ifdef QEMU_GENERATE +#define READ_PREG (dest,NUM ) gen_read_preg(dest, (NUM)) +#define READ_PREG_READONLY (dest,NUM ) do { dest = hex_pred[NUM]; } while (0) + +#define READ_PREG_s (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_t (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_u (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_v (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_x (dest,NUM ) READ_PREG(dest, NUM) + +#define READ_NEW_PREG (pred,PNUM ) \ + do { pred = hex_new_pred_value[PNUM]; } while (0) +#define READ_NEW_PREG_t (pred,PNUM ) READ_NEW_PREG(pred, PNUM) +#define READ_NEW_PREG_u (pred,PNUM ) READ_NEW_PREG(pred, PNUM) +#define READ_NEW_PREG_v (pred,PNUM ) READ_NEW_PREG(pred, PNUM) + +#define READ_NEW_REG (tmp, i) \ + do { tmp = tcg_const_tl(i); } while (0) +#define READ_NEW_NREG_s (tmp, i) READ_NEW_REG(tmp, i) +#define READ_NEW_NREG_t (tmp, i) READ_NEW_REG(tmp, i) +#define READ_NEW_OREG_s (tmp, i) READ_NEW_REG(tmp, i) +#else +#define READ_PREG (NUM ) (env->pred[NUM]) +#endif + + +#define WRITE_RREG (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_d (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_e (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_x (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_y (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) + +#define WRITE_PREG (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_d (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_e (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_x (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) + +#ifdef QEMU_GENERATE +#define WRITE_CREG (i, tmp) \ + do { \ + if (i + HEX_REG_SA0 == HEX_REG_P3_0) { \ + gen_write_p3_0(tmp); \ + } else { \ + WRITE_RREG((i) + HEX_REG_SA0, tmp); \ + } \ + } while (0) +#define WRITE_CREG_d (NUM ,VAL ) WRITE_CREG(NUM, VAL) + +#define WRITE_CREG_PAIR (i, tmp) WRITE_REG_PAIR((i) + HEX_REG_SA0, tmp) +#define WRITE_CREG_dd (NUM ,VAL ) WRITE_CREG_PAIR(NUM, VAL) + +#define WRITE_REG_PAIR (NUM ,VAL ) \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + gen_log_reg_write_pair(NUM, VAL, insn->slot, is_predicated); \ + ctx_log_reg_write(ctx, (NUM)); \ + ctx_log_reg_write(ctx, (NUM) + 1); \ + } while (0) + +#define WRITE_RREG_dd (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#define WRITE_RREG_xx (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#define WRITE_RREG_yy (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#endif +
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generator
Quoted 14 lines · Taylor Simpson
target/hexagon/macros.h new file +14
-0+#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/*
target/hexagon/macros.h line 50
Quoted 10 lines
target/hexagon/macros.h new file +10
-0+* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF)
Is there a good reason for all these macros? Why not just bake this knowledge into gen_tcg_funcs.py? Seems like it would be just a couple of functions...
At present, both this and the intermediary files are unreadable. One has to pass genptr.c through -E and indent to see what's going on.
r~
RE: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generator
Quoted 41 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 6:49 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generatorQuoted 14 lines · Taylor Simpson
target/hexagon/macros.h new file +14
-0+#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/* target/hexagon/macros.h line 50
Quoted 10 lines
target/hexagon/macros.h new file +10
-0+* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF)Is there a good reason for all these macros? Why not just bake this knowledge into
gen_tcg_funcs.py? Seems like it would be just a couple of functions...
Quoted 2 lines
At present, both this and the intermediary files are unreadable. One has to pass
genptr.cthrough -E and indent to see what's going on.
I add the regid (see comment in hex_common.py) in order to reduce the number of TCGv temps and TCG code we generate. I originally had a single DEF/READ/WRITE/FREE set. We would always create a TCGv and copy to/from the temp. In read-only cases, we don't need a temp - we just point to the source. For write-only, we assign directly to the new_value. For read-write, we actually need the temp.
Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generator
Quoted 41 lines · Taylor Simpson
Quoted 41 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 6:49 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generatorQuoted 14 lines · Taylor Simpson
target/hexagon/macros.h new file +14
-0+#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/* target/hexagon/macros.h line 50
Quoted 10 lines
target/hexagon/macros.h new file +10
-0+* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF)Is there a good reason for all these macros? Why not just bake this knowledge into
gen_tcg_funcs.py? Seems like it would be just a couple of functions...
Quoted 4 lines
Quoted 2 lines
At present, both this and the intermediary files are unreadable. One has to pass
genptr.cthrough -E and indent to see what's going on.I add the regid...
No, that doesn't answer the question.
Why does DECL_RREG_d et al exist as macros at all? Why not emit the expansions directly by gen_tcg_funcs.py?
It seems to me that all this does is obfuscate the code, adding one more layer that one has to unwind in order to understand.
r~
RE: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generator
Quoted 65 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 2:59 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generatorQuoted 41 lines · Taylor Simpson
Quoted 41 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 6:49 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 25/34] Hexagon (target/hexagon) macros to interface with the generatorQuoted 14 lines · Taylor Simpson
target/hexagon/macros.h new file +14
-0+#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/* target/hexagon/macros.h line 50
Quoted 10 lines
target/hexagon/macros.h new file +10
-0+* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF)Is there a good reason for all these macros? Why not just bake this knowledge into
gen_tcg_funcs.py? Seems like it would be just a couple of functions...Quoted 1 line
Quoted 1 line
At present, both this and the intermediary files are unreadable. One has
to
Quoted 3 lines
Quoted 1 line
pass
genptr.cthrough -E and indent to see what's going on.I add the regid...
No, that doesn't answer the question.
Why does
DECL_RREG_det al exist as macros at all? Why not emit the expansions
directly bygen_tcg_funcs.py?
Quoted 5 lines
It seems to me that all this does is obfuscate the code, adding one more layer that one has to unwind in order to understand.
r~
This is partly historical. My intent was to keep the generator simple and mechanical and put the optimization and complexity into the macros. I will code this up and see if we think it's better.
RFC PATCH v3 26/34 Hexagon (target/hexagon) macros referenced in instruction semantics
In reply to Taylor Simpson--- target/hexagon/macros.h | 620 ++++++++++++++++++++++++++++++++++++++++++++- target/hexagon/op_helper.c | 21 -- 2 files changed, 619 insertions(+), 22 deletions(-)
target/hexagon/macros.h +619 -1
@@ -18,6 +18,8 @@#ifndef HEXAGON_MACROS_H #define HEXAGON_MACROS_H +#include "qemu/osdep.h" +#include "qemu/host-utils.h" #include "qemu.h" #include "cpu.h" #include "hex_regs.h"
@@ -241,7 +243,6 @@tcg_temp_free (part1); \ } while (0) -#define MARK_LATE_PRED_WRITE (RNUM )/* Not modelled in qemu */ #define REGNO (NUM ) (insn->regno[NUM])#define IMMNO (NUM ) (insn->immed[NUM])
@@ -362,3 +363,620 @@#define WRITE_RREG_yy (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL)#endif +#define PCALIGN 4 +#define PCALIGN_MASK (PCALIGN - 1) + +#define GET_FIELD (FIELD ,REGIN ) \ + fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \ + reg_field_info[FIELD].offset) + +#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)) + +#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 (DST ,VA ,SZ ,SIGN ) \ + do { \ + if (insn->slot == 0 && pkt->pkt_has_store_s1) { \ + gen_helper_merge_inflight_store##SZ##SIGN(DST, cpu_env, VA, DST); \ + } \ + } while (0) + +#define MEM_LOAD1s (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld8s(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 1, s); \ + } while (0) +#define MEM_LOAD1u (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld8u(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 1, u); \ + } while (0) +#define MEM_LOAD2s (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld16s(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 2, s); \ + } while (0) +#define MEM_LOAD2u (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld16u(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 2, u); \ + } while (0) +#define MEM_LOAD4s (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 4, s); \ + } while (0) +#define MEM_LOAD4u (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 4, u); \ + } while (0) +#define MEM_LOAD8u (DST ,VA ) \ + do { \ + tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx); \ + CHECK_NOSHUF(DST, VA, 8, u); \ + } while (0) +#else +#define MEM_LOAD1s (VA ) ((size1s_t)mem_load1(env, slot, VA)) +#define MEM_LOAD1u (VA ) ((size1u_t)mem_load1(env, slot, VA)) +#define MEM_LOAD2s (VA ) ((size2s_t)mem_load2(env, slot, VA)) +#define MEM_LOAD2u (VA ) ((size2u_t)mem_load2(env, slot, VA)) +#define MEM_LOAD4s (VA ) ((size4s_t)mem_load4(env, slot, VA)) +#define MEM_LOAD4u (VA ) ((size4u_t)mem_load4(env, slot, VA)) +#define MEM_LOAD8s (VA ) ((size8s_t)mem_load8(env, slot, VA)) +#define MEM_LOAD8u (VA ) ((size8u_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 ) \ + do { \ + REG = ((REG) & ~(((fCONSTLL(1) << (WIDTH)) - 1) << (OFFSET))) | \ + (((INVAL) & ((fCONSTLL(1) << (WIDTH)) - 1)) << (OFFSET)); \ + } while (0) +#define fEXTRACTU_BITS (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, (INREG >> OFFSET))) +#define fEXTRACTU_BIDIR (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8))) +#define fEXTRACTU_RANGE (INREG ,HIBIT ,LOWBIT ) \ + (fZXTN((HIBIT - LOWBIT + 1), 32, (INREG >> LOWBIT))) + +#define 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 fLSBNEW(0) +#define fLSBNEW1 fLSBNEW(1) +#else +#define fLSBNEW (PVAL ) (PVAL) +#define fLSBNEW0 new_pred_value(env, 0) +#define fLSBNEW1 new_pred_value(env, 1) +#endif + +#ifdef QEMU_GENERATE +static inline void gen_logical_not (TCGv dest,TCGv src) +{ +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_movcond_tl (TCG_COND_NE , dest, src, zero, zero, one); + +tcg_temp_free (one); +tcg_temp_free (zero); +} +#define fLSBOLDNOT (VAL ) \ + do { \ + tcg_gen_andi_tl(LSB, (VAL), 1); \ + tcg_gen_xori_tl(LSB, LSB, 1); \ + } while (0) +#define fLSBNEWNOT (PNUM ) \ + gen_logical_not(LSB, (PNUM)) +#else +#define fLSBNEWNOT (PNUM ) (!fLSBNEW(PNUM)) +#define fLSBOLDNOT (VAL ) (!fLSBOLD(VAL)) +#define fLSBNEW0NOT (!fLSBNEW0) +#define fLSBNEW1NOT (!fLSBNEW1) +#endif + +#define fNEWREG (RNUM ) ((int32_t)(env->new_value[(RNUM)])) + +#define fNEWREG_ST (RNUM ) (env->new_value[(RNUM)]) + +#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 ) ((VAL) & ((1LL << (N)) - 1)) +#define fSXTN (N ,M ,VAL ) \ + ((fZXTN(N, M, VAL) ^ (1LL << ((N) - 1))) - (1LL << ((N) - 1))) +#define fSATN (N ,VAL ) \ + ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATVALN(N, VAL)) +#define fADDSAT64 (DST ,A ,B ) \ + do { \ + size8u_t __a = fCAST8u(A); \ + size8u_t __b = fCAST8u(B); \ + size8u_t __sum = __a + __b; \ + size8u_t __xor = __a ^ __b; \ + const size8u_t __mask = 0x8000000000000000ULL; \ + if (__xor & __mask) { \ + DST = __sum; \ + } \ + else if ((__a ^ __sum) & __mask) { \ + if (__sum & __mask) { \ + DST = 0x7FFFFFFFFFFFFFFFLL; \ + fSET_OVERFLOW(); \ + } else { \ + DST = 0x8000000000000000LL; \ + fSET_OVERFLOW(); \ + } \ + } else { \ + DST = __sum; \ + } \ + } while (0) +#define 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 ) ((size4u_t)(A)) +#define fCAST4s (A ) ((size4s_t)(A)) +#define fCAST8u (A ) ((size8u_t)(A)) +#define fCAST8s (A ) ((size8s_t)(A)) +#define fCAST4_4s (A ) ((size4s_t)(A)) +#define fCAST4_4u (A ) ((size4u_t)(A)) +#define fCAST4_8s (A ) ((size8s_t)((size4s_t)(A))) +#define fCAST4_8u (A ) ((size8u_t)((size4u_t)(A))) +#define fCAST8_8s (A ) ((size8s_t)(A)) +#define fCAST8_8u (A ) ((size8u_t)(A)) +#define fCAST2_8s (A ) ((size8s_t)((size2s_t)(A))) +#define fCAST2_8u (A ) ((size8u_t)((size2u_t)(A))) +#define fZE8_16 (A ) ((size2s_t)((size1u_t)(A))) +#define fSE8_16 (A ) ((size2s_t)((size1s_t)(A))) +#define fSE16_32 (A ) ((size4s_t)((size2s_t)(A))) +#define fZE16_32 (A ) ((size4u_t)((size2u_t)(A))) +#define fSE32_64 (A ) ((size8s_t)((size4s_t)(A))) +#define fZE32_64 (A ) ((size8u_t)((size4u_t)(A))) +#define fSE8_32 (A ) ((size4s_t)((size1s_t)(A))) +#define fZE8_32 (A ) ((size4s_t)((size1u_t)(A))) +#define fMPY8UU (A ,B ) (int)(fZE8_16(A) * fZE8_16(B)) +#define fMPY8US (A ,B ) (int)(fZE8_16(A) * fSE8_16(B)) +#define fMPY8SU (A ,B ) (int)(fSE8_16(A) * fZE8_16(B)) +#define fMPY8SS (A ,B ) (int)((short)(A) * (short)(B)) +#define fMPY16SS (A ,B ) fSE32_64(fSE16_32(A) * fSE16_32(B)) +#define fMPY16UU (A ,B ) fZE32_64(fZE16_32(A) * fZE16_32(B)) +#define fMPY16SU (A ,B ) fSE32_64(fSE16_32(A) * fZE16_32(B)) +#define fMPY16US (A ,B ) fMPY16SU(B, A) +#define fMPY32SS (A ,B ) (fSE32_64(A) * fSE32_64(B)) +#define fMPY32UU (A ,B ) (fZE32_64(A) * fZE32_64(B)) +#define fMPY32SU (A ,B ) (fSE32_64(A) * fZE32_64(B)) +#define fMPY3216SS (A ,B ) (fSE32_64(A) * fSXTN(16, 64, B)) +#define fMPY3216SU (A ,B ) (fSE32_64(A) * fZXTN(16, 64, B)) +#define fROUND (A ) (A + 0x8000) +#define fCLIP (DST ,SRC ,U ) \ + do { \ + size4s_t maxv = (1 << U) - 1; \ + size4s_t minv = -(1 << U); \ + DST = fMIN(maxv, fMAX(SRC, minv)); \ + } while (0) +#define fCRND (A ) ((((A) & 0x3) == 0x3) ? ((A) + 1) : ((A))) +#define fRNDN (A ,N ) ((((N) == 0) ? (A) : (((fSE32_64(A)) + (1 << ((N) - 1)))))) +#define fCRNDN (A ,N ) (conv_round(A, N)) +#define fADD128 (A ,B ) (add128(A, B)) +#define fSUB128 (A ,B ) (sub128(A, B)) +#define fSHIFTR128 (A ,B ) (shiftr128(A, B)) +#define fSHIFTL128 (A ,B ) (shiftl128(A, B)) +#define fAND128 (A ,B ) (and128(A, B)) +#define fCAST8S_16S (A ) (cast8s_to_16s(A)) +#define fCAST16S_8S (A ) (cast16s_to_8s(A)) + +#define 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 ) (((size8s_t)(A)) << N) +#define fSATW (A ) fSATN(32, ((long long)A)) +#define fSAT (A ) fSATN(32, (A)) +#define fSAT_ORIG_SHL (A ,ORIG_REG ) \ + ((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) \ + ? fSATVALN(32, ((size4s_t)(ORIG_REG))) \ + : ((((ORIG_REG) > 0) && ((A) == 0)) ? fSATVALN(32, (ORIG_REG)) \ + : fSAT(A))) +#define fPASS (A ) A +#define fRND (A ) (((A) + 1) >> 1) +#define fBIDIR_SHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT)) - 1)) >> 1) \ + : (fCAST##REGSTYPE(SRC) << (SHAMT))) +#define fBIDIR_ASHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##s) +#define fBIDIR_LSHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##u) +#define fBIDIR_ASHIFTL_SAT (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT)) - 1)) >> 1) \ + : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT), (SRC))) +#define fBIDIR_SHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT)) - 1)) << 1) \ + : (fCAST##REGSTYPE(SRC) >> (SHAMT))) +#define fBIDIR_ASHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##s) +#define fBIDIR_LSHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##u) +#define fBIDIR_ASHIFTR_SAT (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) \ + << ((-(SHAMT)) - 1)) << 1, (SRC)) \ + : (fCAST##REGSTYPE##s(SRC) >> (SHAMT))) +#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))) +#define fFLOAT (A ) \ + ({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; }) +#define fUNFLOAT (A ) \ + ({ union { float f; size4u_t i; } _fipun; \ + _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; }) +#define fSFNANVAL () 0xffffffff +#define fSFINFVAL (A ) (((A) & 0x80000000) | 0x7f800000) +#define fSFONEVAL (A ) (((A) & 0x80000000) | fUNFLOAT(1.0)) +#define fCHECKSFNAN (DST ,A ) \ + do { \ + if (isnan(fFLOAT(A))) { \ + if ((fGETBIT(22, A)) == 0) { \ + fRAISEFLAGS(FE_INVALID); \ + } \ + DST = fSFNANVAL(); \ + } \ + } while (0) +#define fCHECKSFNAN3 (DST ,A ,B ,C ) \ + do { \ + fCHECKSFNAN(DST, A); \ + fCHECKSFNAN(DST, B); \ + fCHECKSFNAN(DST, C); \ + } while (0) +#define fSF_BIAS () 127 +#define fSF_MANTBITS () 23 +#define fSF_MUL_POW2 (A ,B ) \ + (fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS()))) +#define fSF_GETEXP (A ) (((A) >> fSF_MANTBITS()) & 0xff) +#define fSF_MAXEXP () (254) +#define fSF_RECIP_COMMON (N ,D ,O ,A ) arch_sf_recip_common(&N, &D, &O, &A) +#define fSF_INVSQRT_COMMON (N ,O ,A ) arch_sf_invsqrt_common(&N, &O, &A) +#define fFMAFX (A ,B ,C ,ADJ ) internal_fmafx(A, B, C, fSXTN(8, 64, ADJ)) +#define fFMAF (A ,B ,C ) internal_fmafx(A, B, C, 0) +#define fSFMPY (A ,B ) internal_mpyf(A, B) +#define fMAKESF (SIGN ,EXP ,MANT ) \ + ((((SIGN) & 1) << 31) | \ + (((EXP) & 0xff) << fSF_MANTBITS()) | \ + ((MANT) & ((1 << fSF_MANTBITS()) - 1))) +#define fDOUBLE (A ) \ + ({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; }) +#define fUNDOUBLE (A ) \ + ({ union { double f; size8u_t i; } _fipun; \ + _fipun.f = (A); \ + isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; }) +#define fDFNANVAL () 0xffffffffffffffffULL +#define fDF_ISNORMAL (X ) (fpclassify(fDOUBLE(X)) == FP_NORMAL) +#define fDF_ISDENORM (X ) (fpclassify(fDOUBLE(X)) == FP_SUBNORMAL) +#define fDF_ISBIG (X ) (fDF_GETEXP(X) >= 512) +#define fDF_MANTBITS () 52 +#define fDF_GETEXP (A ) (((A) >> fDF_MANTBITS()) & 0x7ff) +#define fFMA (A ,B ,C ) internal_fma(A, B, C) +#define fDF_MPY_HH (A ,B ,ACC ) internal_mpyhh(A, B, ACC) + +#ifdef QEMU_GENERATE +/* These will be needed if we write any FP instructions with TCG */ +#define fFPOP_START ()/* nothing */ +#define fFPOP_END ()/* nothing */ +#else +#define fFPOP_START () arch_fpop_start(env) +#define fFPOP_END () arch_fpop_end(env) +#endif + +#define fFPSETROUND_NEAREST () fesetround(FE_TONEAREST) +#define fFPSETROUND_CHOP () fesetround(FE_TOWARDZERO) +#define fFPCANCELFLAGS () feclearexcept(FE_ALL_EXCEPT) +#define fISINFPROD (A ,B ) \ + ((isinf(A) && isinf(B)) || \ + (isinf(A) && isfinite(B) && ((B) != 0.0)) || \ + (isinf(B) && isfinite(A) && ((A) != 0.0))) +#define fISZEROPROD (A ,B ) \ + ((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A))) +#define fRAISEFLAGS (A ) arch_raise_fpflag(A) +#define fDF_MAX (A ,B ) \ + (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B)) : fmax(A, B)) +#define fDF_MIN (A ,B ) \ + (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B)) : fmin(A, B)) +#define fSF_MAX (A ,B ) \ + (((A) == (B)) ? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B)) : fmaxf(A, B)) +#define fSF_MIN (A ,B ) \ + (((A) == (B)) ? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B)) : fminf(A, B)) + +#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 ) ((size1s_t)((SRC >> ((N) * 8)) & 0xff)) +#define fGETUBYTE (N ,SRC ) ((size1u_t)((SRC >> ((N) * 8)) & 0xff)) + +#define fSETBYTE (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(0x0ffLL << ((N) * 8))) | \ + (((size8u_t)((VAL) & 0x0ffLL)) << ((N) * 8)); \ + } while (0) +#define fGETHALF (N ,SRC ) ((size2s_t)((SRC >> ((N) * 16)) & 0xffff)) +#define fGETUHALF (N ,SRC ) ((size2u_t)((SRC >> ((N) * 16)) & 0xffff)) +#define fSETHALF (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(0x0ffffLL << ((N) * 16))) | \ + (((size8u_t)((VAL) & 0x0ffff)) << ((N) * 16)); \ + } while (0) +#define fSETHALFw fSETHALF +#define fSETHALFd fSETHALF + +#define fGETWORD (N ,SRC ) \ + ((size8s_t)((size4s_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL))) +#define fGETUWORD (N ,SRC ) \ + ((size8u_t)((size4u_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))) | (((size8u_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 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 { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fICINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fL2FETCH (ADDR ,HEIGHT ,WIDTH ,STRIDE ,FLAGS ) +#define fDCCLEANA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fDCCLEANINVA (REG ) \ + do { REG = 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
target/hexagon/op_helper.c +0 -21
@@ -88,27 +88,6 @@ static inline void log_pred_write(CPUHexagonState *env, int pnum, } } -static inline void log_store32 (CPUHexagonState *env,target_ulong addr, -target_ulong val,int width,int slot) -{ -HEX_DEBUG_LOG ("log_store%d(0x" TARGET_FMT_lx", " TARGET_FMT_ld -" [0x" TARGET_FMT_lx"])\n" , - width, addr, val, val); - env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data32 = val; -} - -static inline void log_store64 (CPUHexagonState *env,target_ulong addr, -int64_t val,int width,int slot) -{ -HEX_DEBUG_LOG ("log_store%d(0x" TARGET_FMT_lx", %ld [0x%lx])\n" , - width, addr, val, val); - env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data64 = val; -} -static inline void write_new_pc (CPUHexagonState *env,target_ulong addr) {HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr);
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 19 lines · Taylor Simpson
target/hexagon/macros.h +19
-0+/* +* 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. +* +*
target/hexagon/macros.h line 410
Quoted 10 lines
target/hexagon/macros.h +10
-0+* 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 (DST ,VA ,SZ ,SIGN ) \ + do { \ + if (insn->slot == 0 && pkt->pkt_has_store_s1) { \ + gen_helper_merge_inflight_store##SZ##SIGN(DST, cpu_env, VA, DST); \ + } \ + } while (0)
Ah, so I see what you're trying to do with the merge thing, which had the host-endian problems.
I think the merge stuff is a mistake. I think you can get the semantics that you want with
probe_read(ld_addr, ld_len)
qemu_st(st_value, st_addr)
qemu_ld(ld_value, ld_addr)
In this way, all exceptions are recognized before the store is complete, the normal memory operations handle any possible overlap.
target/hexagon/macros.h line 498
Quoted 5 lines
target/hexagon/macros.h +5
-0+#define fINSERT_BITS (REG ,WIDTH ,OFFSET ,INVAL ) \ + do { \ + REG = ((REG) & ~(((fCONSTLL(1) << (WIDTH)) - 1) << (OFFSET))) | \ + (((INVAL) & ((fCONSTLL(1) << (WIDTH)) - 1)) << (OFFSET)); \ + } while (0)
reg = deposit32(reg, offset, width, inval)
target/hexagon/macros.h line 504
Quoted 6 lines
target/hexagon/macros.h +6
-0+#define fEXTRACTU_BITS (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, (INREG >> OFFSET))) +#define fEXTRACTU_BIDIR (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8))) +#define fEXTRACTU_RANGE (INREG ,HIBIT ,LOWBIT ) \ + (fZXTN((HIBIT - LOWBIT + 1), 32, (INREG >> LOWBIT)))
extract32(inreg, offset, width)
Quoted 1 line
+#define
fZXTN(N, M, VAL)((VAL) & ((1LL << (N)) - 1))
extract32(VAL, 0, n)
target/hexagon/macros.h line 565
Quoted 2 lines
target/hexagon/macros.h +2
-0+#define fSXTN (N ,M ,VAL ) \ + ((fZXTN(N, M, VAL) ^ (1LL << ((N) - 1))) - (1LL << ((N) - 1)))
sextract32(val, 0, n)
Quoted 1 line
+#define fRND(A) (((A) + 1) >> 1)
Does A have a type that won't overflow?
For Arm we write this as
(A >> 1) + (A & 1)
target/hexagon/macros.h line 974
Quoted 6 lines
target/hexagon/macros.h +6
-0+#define fDCFETCH (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fICINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fL2FETCH (ADDR ,HEIGHT ,WIDTH ,STRIDE ,FLAGS ) +#define fDCCLEANA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fDCCLEANINVA (REG ) \ + do { REG = REG; } while (0)/* Nothing to do in qemu */
Is this "R=R" thing trying to avoid a compiler warning? Perhaps "(void)R" would be sufficient to avoid that?
Quoted 11 lines
target/hexagon/op_helper.c +0
-11-static inline void log_store32 (CPUHexagonState *env,target_ulong addr, -target_ulong val,int width,int slot) -{ -HEX_DEBUG_LOG ("log_store%d(0x" TARGET_FMT_lx", " TARGET_FMT_ld -" [0x" TARGET_FMT_lx"])\n" , - width, addr, val, val); - env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data32 = val; -} -
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum, · line 111
Quoted 10 lines
target/hexagon/op_helper.c +0
-10-static inline void log_store64 (CPUHexagonState *env,target_ulong addr, -int64_t val,int width,int slot) -{ -HEX_DEBUG_LOG ("log_store%d(0x" TARGET_FMT_lx", %ld [0x%lx])\n" , - width, addr, val, val); - env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data64 = val; -} -
Fold this back to wherever it came from. Clearly no need to introduce it in the first place.
r~
RE: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 30 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:17 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semanticstarget/hexagon/macros.h
Quoted 8 lines · Taylor Simpson
+ * 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.
+ */target/hexagon/macros.h +4
-0+#define CHECK_NOSHUF (DST ,VA ,SZ ,SIGN ) \ + do { \ + if (insn->slot == 0 && pkt->pkt_has_store_s1) { \ + gen_helper_merge_inflight_store##SZ##SIGN(DST, cpu_env, VA,DST); \
Review
Quoted 2 lines
(quoted diff) +2
-0+ } \ + } while (0)Ah, so I see what you're trying to do with the merge thing, which had the host-endian problems.
I think the merge stuff is a mistake. I think you can get the semantics that you want with
Quoted 6 lines
probe_read(ld_addr, ld_len)qemu_st(st_value, st_addr)qemu_ld(ld_value, ld_addr)In this way, all exceptions are recognized before the store is complete, the normal memory operations handle any possible overlap.
So, do this inside the helper? Or is there a way to generate TCG code?
Quoted 8 lines
target/hexagon/macros.h line 498
Quoted 6 lines
target/hexagon/macros.h +5
-0+#define fINSERT_BITS (REG ,WIDTH ,OFFSET ,INVAL ) \ + do { \ + REG = ((REG) & ~(((fCONSTLL(1) << (WIDTH)) - 1) << (OFFSET))) | \ + (((INVAL) & ((fCONSTLL(1) << (WIDTH)) - 1)) << (OFFSET)); \ + } while (0)reg =
deposit32(reg, offset, width, inval)
OK
Quoted 8 lines
target/hexagon/macros.h line 504
Quoted 6 lines
target/hexagon/macros.h +6
-0+#define fEXTRACTU_BITS (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, (INREG >> OFFSET))) +#define fEXTRACTU_BIDIR (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8))) +#define fEXTRACTU_RANGE (INREG ,HIBIT ,LOWBIT ) \ + (fZXTN((HIBIT - LOWBIT + 1), 32, (INREG >> LOWBIT)))
extract32(inreg, offset, width)
OK
Quoted 3 lines
Quoted 1 line
+#define
fZXTN(N, M, VAL)((VAL) & ((1LL << (N)) - 1))
extract32(VAL, 0, n)
OK
Quoted 4 lines
target/hexagon/macros.h line 565
Quoted 2 lines
target/hexagon/macros.h +2
-0+#define fSXTN (N ,M ,VAL ) \ + ((fZXTN(N, M, VAL) ^ (1LL << ((N) - 1))) - (1LL << ((N) - 1)))
sextract32(val, 0, n)
OK
Quoted 6 lines
Quoted 1 line
+#define fRND(A) (((A) + 1) >> 1)
Does A have a type that won't overflow?
For Arm we write this as(A >> 1) + (A & 1)
Will investigate
Quoted 4 lines
Quoted 1 line
+#define fDCFETCH(REG) do { REG = REG; } while (0) /* Nothing to do in
qemu */
Quoted 1 line
+#define fICINVA(REG) do { REG = REG; } while (0) /* Nothing to do in
qemu */
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define fL2FETCH(ADDR, HEIGHT, WIDTH, STRIDE, FLAGS) +#define fDCCLEANA(REG) do { REG = REG; } while (0) /* Nothing to do inqemu */
target/hexagon/macros.h line 974
Quoted 2 lines
target/hexagon/macros.h +2
-0+#define fDCCLEANINVA (REG ) \ + do { REG = REG; } while (0)/* Nothing to do in qemu */ Is this "R=R" thing trying to avoid a compiler warning? Perhaps "(void)R" would be sufficient to avoid that?
Yes, it avoids a compiler warning. Will change to (void)
Quoted 17 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 4 lines
target/hexagon/op_helper.c +0
-4-static inline void log_store32 (CPUHexagonState *env,target_ulong addr, -target_ulong val,int width,int slot) -{ - HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", "
TARGET_FMT_ldQuoted 12 lines
target/hexagon/op_helper.c +0
-12-" [0x" TARGET_FMT_lx"])\n" , - width, addr, val, val); - env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data32 = val; -} - -static inline void log_store64 (CPUHexagonState *env,target_ulong addr, -int64_t val,int width,int slot) -{ -HEX_DEBUG_LOG ("log_store%d(0x" TARGET_FMT_lx", %ld [0x%lx])\n" , - width, addr, val, val);
Quoted 8 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum, · line 111
Quoted 5 lines
target/hexagon/op_helper.c +0
-5- env->mem_log_stores[slot].va = addr; - env->mem_log_stores[slot].width = width; - env->mem_log_stores[slot].data64 = val; -} -Fold this back to wherever it came from. Clearly no need to introduce it in the first place.
These are invoked by the MEM_STORE macros. Are you saying to put this code there?
Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 11 lines · Taylor Simpson
Quoted 9 lines
I think the merge stuff is a mistake. I think you can get the semantics that you want with
probe_read(ld_addr, ld_len)qemu_st(st_value, st_addr)qemu_ld(ld_value, ld_addr)In this way, all exceptions are recognized before the store is complete, the normal memory operations handle any possible overlap.
So, do this inside the helper? Or is there a way to generate TCG code?
I was thinking TCG code, where you can look at the packet before any code gen, and decide whether or not this situation actually applies.
The probe is a simple helper call, for which the generic machinery exists (probe_access, probe_write, probe_read). All you have to do is write the wrapper.
The loads and stores are, well, normal loads and stores.
r~
RE: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
In reply to Richard HendersonQuoted 18 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:17 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semanticsAh, so I see what you're trying to do with the merge thing, which had the host-endian problems.
I think the merge stuff is a mistake. I think you can get the semantics that you want with
Quoted 6 lines
probe_read(ld_addr, ld_len)qemu_st(st_value, st_addr)qemu_ld(ld_value, ld_addr)In this way, all exceptions are recognized before the store is complete, the normal memory operations handle any possible overlap.
Following up on this...
1) We don't need to do the probe_read because the load has already happened at this point.
2) I'm not familiar with qemu_st/qemu_ld. Are these shorthand for tcg_gen_qemu_st*/tcg_gen_qemu_ld*? We can't actually do the store at this point because it would alter the memory before we are sure the packet will commit (i.e., there might be still be an exception raised by another instruction in the packet).
3) How important is it to support big endian hosts? Would it be OK to put something like this to declare it isn't supported for Hexagon? #if defined(HOST_WORDS_BIGENDIAN)
#error Hexagon guest not supported on big endian host
#endif
4) If the above is not OK, are the macros in bswap.h the correct ones to use? Is this pseudo-code correct? store_val = le32_to_cpu(store_val);load_val = le32_to_cpu(load_val);
<merge bytes>
/* store_val is dead so no need to convert back */load_val = cpu_to_le32(load_val)
Thanks,
Taylor
Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 22 lines · Taylor Simpson
Quoted 22 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:17 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semanticsAh, so I see what you're trying to do with the merge thing, which had the host-endian problems.
I think the merge stuff is a mistake. I think you can get the semantics that you want with
probe_read(ld_addr, ld_len)qemu_st(st_value, st_addr)qemu_ld(ld_value, ld_addr)
Quoted 6 lines
Quoted 2 lines
In this way, all exceptions are recognized before the store is complete, the normal memory operations handle any possible overlap.
Following up on this...
1) We don't need to do the
probe_readbecause the load has already happened at this point.
What do you mean "has already happened"? How can it have done without doing the merging by hand. Which this operation ordering is intended to make unnecessary.
I think you're missing the point.
Quoted 1 line
2) I'm not familiar with qemu_st/qemu_ld. Are these shorthand for tcg_gen_qemu_st*/tcg_gen_qemu_ld*?
Yes.
Quoted 1 line
We can't actually do the store at this point because it would alter the memory before we are sure the packet will commit (i.e., there might be still be an exception raised by another instruction in the packet).
What other instruction? Give me a concrete example so that I can give you a concrete answer.
I think you may need to do more preprocessing of the entire packet so that you can answer this sort of question (is there any other possible exception) when generating code.
Quoted 4 lines
3) How important is it to support big endian hosts? Would it be OK to put something like this to declare it isn't supported for Hexagon? #if
defined(HOST_WORDS_BIGENDIAN)
#error Hexagon guest not supported on big endian host
#endif
That would make ./configure && make fail on such a host. So, no, you can't do that.
Quoted 7 lines
4) If the above is not OK, are the macros in
bswap.hthe correct ones to use? Is this pseudo-code correct?store_val=le32_to_cpu(store_val);load_val=le32_to_cpu(load_val);
<merge bytes>
/*store_valis dead so no need to convert back */load_val=cpu_to_le32(load_val)
There's some misuse of cpu_to_le32 vs le32_to_cpu there (I've never liked those names, but it helps to think about what form the data is already in).
r~
RE: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 27 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, October 8, 2020 11:31 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semanticsQuoted 11 lines
Quoted 11 lines
Ah, so I see what you're trying to do with the merge thing, which had the host-endian problems.
I think the merge stuff is a mistake. I think you can get the semantics that you want with
probe_read(ld_addr, ld_len)qemu_st(st_value, st_addr)qemu_ld(ld_value, ld_addr)In this way, all exceptions are recognized before the store is complete,
the
Quoted 4 lines
Quoted 1 line
normal memory operations handle any possible overlap.
Following up on this...
Quoted 8 lines
Quoted 1 line
1) We don't need to do the
probe_readbecause the load has alreadyhappened at this point.
What do you mean "has already happened"?
How can it have done without doing the merging by hand. Which this operation ordering is intended to make unnecessary.I think you're missing the point.
Sorry I wasn't clear. We have done the load from memory as it was at the beginning of the packet. The result of the store is in mem_log_stores in CPUHexagonState. This code updates the bytes that were loaded with any overlapping bytes from the store that hasn't been committed yet.
Quoted 5 lines
Quoted 3 lines
2) I'm not familiar with qemu_st/qemu_ld. Are these shorthand for
tcg_gen_qemu_st*/tcg_gen_qemu_ld*?
Quoted 8 lines
Yes.
Quoted 1 line
We can't actually do the store at this point because it would alter the
memory before we are sure the packet will commit (i.e., there might be still be an exception raised by another instruction in the packet).
What other instruction? Give me a concrete example so that I can give you a concrete answer.
Remember, there can be 4 instructions in a packet. This code is only dealing with two of them (a load and a store). Here's an example where a different instruction in the packet can fault.
67f8: c0 40 21 1f 1f2140c0 { v0.uh = vsat(v0.uw,v1.uw)
67fc: 00 45 02 a1 a1024500 memb(r2+#0) = r5
6800: 02 c0 04 91 9104c002 r2 = memb(r4+#0) }The vsat instruction requires a vector context. If the thread doesn't have a vector context, an exception will be raised. The OS can provide a context and replay the packet.
Quoted 23 lines
I think you may need to do more preprocessing of the entire packet so that you
can answer this sort of question (is there any other possible exception) when generating code.Quoted 1 line
3) How important is it to support big endian hosts? Would it be OK to put
something like this to declare it isn't supported for Hexagon?
Quoted 3 lines
#if
defined(HOST_WORDS_BIGENDIAN)
#error Hexagon guest not supported on big endian host #endifThat would make ./configure && make fail on such a host. So, no, you can't do that.
Quoted 2 lines
4) If the above is not OK, are the macros in
bswap.hthe correct ones touse? Is this pseudo-code correct?
Quoted 5 lines
store_val=le32_to_cpu(store_val);load_val=le32_to_cpu(load_val);
<merge bytes>
/*store_valis dead so no need to convert back */load_val=cpu_to_le32(load_val)
Quoted 3 lines
There's some misuse of
cpu_to_le32vsle32_to_cputhere (I've never liked those
names, but it helps to think about what form the data is already in).
So, what is the right sequence?
Thanks,
Taylor
Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 5 lines · Taylor Simpson
Quoted 3 lines
How can it have done without doing the merging by hand. Which this operation ordering is intended to make unnecessary.
I think you're missing the point.
Sorry I wasn't clear. We have done the load from memory as it was at the beginning of the packet. The result of the store is in
mem_log_storesin CPUHexagonState. This code updates the bytes that were loaded with any overlapping bytes from the store that hasn't been committed yet.
Right, so you *are* missing the point.
The point is to *not* do the load earlier, but only probe the memory for readability so that any exception is recognized before the store commits.
Then, after the store, actually perform the load. Thus any overlapping bytes get the values that they should.
Voila, no by-hand merging.
Quoted 5 lines
67f8: c0 40 21 1f 1f2140c0 { v0.uh = vsat(v0.uw,v1.uw) 67fc: 00 45 02 a1 a1024500 memb(r2+#0) = r5 6800: 02 c0 04 91 9104c002 r2 = memb(r4+#0) }The vsat instruction requires a vector context. If the thread doesn't have a vector context, an exception will be raised. The OS can provide a context and replay the packet.
Sure.
Is there any per-packet exception priority that would require a fault from the store to be provided in preference to the fault for the vector context?
Anyway, I'm suggesting ordering the operations within the packet to be one that's most convenient for us.
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
store_val=le32_to_cpu(store_val);load_val=le32_to_cpu(load_val);
<merge bytes>
/*store_valis dead so no need to convert back */load_val=cpu_to_le32(load_val)There's some misuse of
cpu_to_le32vsle32_to_cputhere (I've never liked those
names, but it helps to think about what form the data is already in).So, what is the right sequence?
Well, <merge_bytes> wants to operate on a le ordering, so the final load_val assignment should use le32_to_cpu. Think about this in terms of units, like Fahrenheit vs Celsius.
As for the other two, it depends on where the values come from. Probably they should be cpu_to_le32, but I can't tell without extra context.
r~
RE: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 22 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, October 8, 2020 2:02 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semanticsQuoted 1 line · Taylor Simpson
Quoted 1 line
How can it have done without doing the merging by hand. Which this
operation ordering is intended to make unnecessary.
Quoted 4 lines
Quoted 2 lines
I think you're missing the point.
Sorry I wasn't clear. We have done the load from memory as it was at the
beginning of the packet. The result of the store is in
mem_log_storesin CPUHexagonState. This code updates the bytes that were loaded with any overlapping bytes from the store that hasn't been committed yet.
Quoted 7 lines
Right, so you *are* missing the point.
The point is to *not* do the load earlier, but only probe the memory for readability so that any exception is recognized before the store commits.
Then, after the store, actually perform the load. Thus any overlapping bytes get the values that they should.
That's what I coded originally, but after sleeping on it decided it could lead to problems. See below...
Quoted 6 lines
Voila, no by-hand merging.
Quoted 4 lines
67f8: c0 40 21 1f 1f2140c0 { v0.uh = vsat(v0.uw,v1.uw) 67fc: 00 45 02 a1 a1024500 memb(r2+#0) = r5 6800: 02 c0 04 91 9104c002 r2 = memb(r4+#0) }
Quoted 8 lines
Quoted 1 line
The vsat instruction requires a vector context. If the thread doesn't have a
vector context, an exception will be raised. The OS can provide a context and replay the packet.
Sure.
Is there any per-packet exception priority that would require a fault from the store to be provided in preference to the fault for the vector context?
I don't think there's a priority for the exceptions. In this example, any of the 3 instructions could generate an exception. The thing I'm worried about isn't that the store could generate an exception. The problem is letting the store change the machine state before we're sure none of the instructions will raise an exception. Maybe I'm worrying about something that would never result in different behavior - if the packet gets replayed, we'll just store the same value again.
I'll reach out to the architects and ask if there is a case where doing the store first could be a problem - and also about the priority of exceptions.
Quoted 2 lines
Anyway, I'm suggesting ordering the operations within the packet to be one that's most convenient for us.
This may or may not be possible. We already have to reorder to put .new consumers after the producers, and we have to keep the change-of-flow instructions in the original order. So, I'm reluctant to go down this path worrying that there will be a long tail of corner case bugs to engineer out.
Re: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 1 line · Taylor Simpson
I'll reach out to the architects and ask if there is a case where doing the store first could be a problem - and also about the priority of exceptions.
Of course there are cases where doing the store first will cause problems.
Quoted 1 line
This may or may not be possible. We already have to reorder to put .new consumers after the producers, and we have to keep the change-of-flow instructions in the original order. So, I'm reluctant to go down this path worrying that there will be a long tail of corner case bugs to engineer out.
Well, do as you like, I suppose, but I think the merging thing that you were trying to do is just as fraught with peril.
r~
RE: [RFC PATCH v3 26/34] Hexagon (target/hexagon) macros referenced in instruction semantics
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, October 9, 2020 6:59 AMQuoted 1 line · Taylor Simpson
I'll reach out to the architects and ask if there is a case where doing the
store first could be a problem - and also about the priority of exceptions.
Of course there are cases where doing the store first will cause problems.
Quoted 7 lines
Quoted 1 line
This may or may not be possible. We already have to reorder to put .new
consumers after the producers, and we have to keep the change-of-flow instructions in the original order. So, I'm reluctant to go down this path worrying that there will be a long tail of corner case bugs to engineer out.
Well, do as you like, I suppose, but I think the merging thing that you were trying to do is just as fraught with peril.
Thanks for your patience on this. After speaking to the architects and putting more comments in the decoder (per your feedback), I'm convinced that doing the store first won't lead to problems. So, I'll move forward with your suggestion.
In other news, this change and the switch to qemu softfloat are the only blockers from your review. Once these are done, I'll submit v5 of the series. Thanks for your feedback, it's made our code significantly better.
Thanks
Taylor
RFC PATCH v3 27/34 Hexagon (target/hexagon) instruction classes
In reply to Taylor SimpsonDetermine legal VLIW slots for each instruction
--- target/hexagon/iclass.h | 46 ++++++++++++++++++++ target/hexagon/iclass.c | 88 ++++++++++++++++++++++++++++++++++++++ target/hexagon/imported/iclass.def | 52 ++++++++++++++++++++++ 3 files changed, 186 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 +46 -0
@@ -0,0 +1,46 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_ICLASS_H +#define HEXAGON_ICLASS_H + +#include "opcodes.h" + +#define ICLASS_FROM_TYPE (TYPE ) ICLASS_##TYPE + +typedef enum { + +#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) ICLASS_FROM_TYPE(TYPE), +#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + +#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS ) ICLASS_FROM_TYPE(TYPE), +#define DEF_PP_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + +ICLASS_FROM_TYPE (COPROC_VX ), +ICLASS_FROM_TYPE (COPROC_VMEM ), +NUM_ICLASSES +} iclass_t; + +extern const char *find_iclass_slots (opcode_t opcode,int itype); + +#endif
target/hexagon/iclass.c new file +88 -0
88 lines not on this page · raw message
target/hexagon/imported/iclass.def new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 27/34] Hexagon (target/hexagon) instruction classes
Quoted 1 line · Taylor Simpson
+}
iclass_t;
...
Quoted 1 line
+extern const char *find_iclass_slots(opcode_t opcode, int itype);
...
target/hexagon/iclass.c line 23
Quoted 3 lines
target/hexagon/iclass.c new file +3
-0+typedef struct { +const char *const slots; +}iclass_info_t ;
I'll note that you aren't following our CODING_STYLE for types. Which of these need to match imported/ and which can you fix.
target/hexagon/iclass.h line 37
Quoted 13 lines
target/hexagon/iclass.h new file +13
-0+typedef enum { + +#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) ICLASS_FROM_TYPE(TYPE), +#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + +#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS ) ICLASS_FROM_TYPE(TYPE), +#define DEF_PP_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32
Any particular reason why you're defining one as nothing, and doing this dance twice?
target/hexagon/iclass.c line 50
Quoted 5 lines
target/hexagon/iclass.c new file +5
-0+const char *find_iclass_slots (opcode_t opcode,int itype) +{ +/* There are some exceptions to what the iclass dictates */ +if (GET_ATTRIB (opcode,A_ICOP )) { +return "2" ;
Why are you returning a string and not a simple bitmask?
Quoted 1 line
+ [
ICLASS_FROM_TYPE(TYPE)] = { .slots = #SLOTS },
This could be converted to the bitmask with
enum {
SLOTS_0 = (1 << 0),
SLOTS_1 = (1 << 1),
SLOTS_23 = (1 << 2) | (1 << 3),
...
};static const uint8_t iclass_info[] = {
#define DEF_ICLASS(TYPE, SLOTS) \
[ICLASS_##TYPE] = SLOTS_##SLOTS#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) \
DEF_ICLASS(TYPE, SLOTS)
#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) \
DEF_ICLASS(TYPE, SLOTS)
At which point the ultimate consumer,
Quoted 7 lines
for (i = 0, slot = 3; i < pkt->num_insns; i++) {
valid_slot_str = get_valid_slot_str(pkt, i);
while (strchr(valid_slot_str, '0' + slot) == NULL) {
slot--;
}
pkt->insn[i].slot = slot;becomes a simple integer mask check.
r~
RE: [RFC PATCH v3 27/34] Hexagon (target/hexagon) instruction classes
Quoted 15 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:37 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 27/34] Hexagon (target/hexagon) instruction classesQuoted 1 line · Taylor Simpson
+}
iclass_t;...
Quoted 1 line
+extern const char *find_iclass_slots(opcode_t opcode, int itype);
Quoted 8 lines
...
target/hexagon/iclass.c line 23
Quoted 3 lines
target/hexagon/iclass.c new file +3
-0+typedef struct { +const char *const slots; +}iclass_info_t ;I'll note that you aren't following our
CODING_STYLEfor types. Which of these
need to match imported/ and which can you fix.
So, this should be CamelCase? I should be able to fix all of them.
Quoted 12 lines
target/hexagon/iclass.h
Quoted 4 lines
target/hexagon/iclass.h new file +3
-0+typedef enum { + +#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS)
ICLASS_FROM_TYPE(TYPE),target/hexagon/iclass.h
Quoted 6 lines
target/hexagon/iclass.h new file +6
-0+#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + +#define DEF_EE_ICLASS32 (TYPE ,SLOTS ,UNITS )
ICLASS_FROM_TYPE(TYPE),
Quoted 8 lines
target/hexagon/iclass.h line 37
Quoted 4 lines
target/hexagon/iclass.h new file +4
-0+#define DEF_PP_ICLASS32 (TYPE ,SLOTS ,UNITS )/* nothing */ +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32Any particular reason why you're defining one as nothing, and doing this dance
twice?
Will investigate.
Quoted 7 lines
target/hexagon/iclass.c line 50
Quoted 5 lines
target/hexagon/iclass.c new file +5
-0+const char *find_iclass_slots (opcode_t opcode,int itype) +{ +/* There are some exceptions to what the iclass dictates */ +if (GET_ATTRIB (opcode,A_ICOP )) { +return "2" ;Why are you returning a string and not a simple bitmask?
Will fix
Quoted 25 lines
Quoted 1 line
+ [
ICLASS_FROM_TYPE(TYPE)] = { .slots = #SLOTS },This could be converted to the bitmask with
enum { SLOTS_0 = (1 << 0), SLOTS_1 = (1 << 1), SLOTS_23 = (1 << 2) | (1 << 3), ... };static const
uint8_ticlass_info[] = {#define DEF_ICLASS(TYPE, SLOTS) \ [ICLASS_##TYPE] = SLOTS_##SLOTS#define
DEF_PP_ICLASS32(TYPE, SLOTS, UNITS)\
DEF_ICLASS(TYPE, SLOTS)
#defineDEF_EE_ICLASS32(TYPE, SLOTS, UNITS)\
DEF_ICLASS(TYPE, SLOTS)At which point the ultimate consumer,
Quoted 3 lines
for (i = 0, slot = 3; i < pkt->num_insns; i++) { valid_slot_str = get_valid_slot_str(pkt, i);
Quoted 6 lines
Quoted 4 lines
while (strchr(valid_slot_str, '0' + slot) == NULL) { slot--; } pkt->insn[i].slot = slot;becomes a simple integer mask check.
Will fix
Re: [RFC PATCH v3 27/34] Hexagon (target/hexagon) instruction classes
Quoted 1 line · Taylor Simpson
So, this should be CamelCase? I should be able to fix all of them.
Yes, they should. Thanks.
r~
RFC PATCH v3 28/34 Hexagon (target/hexagon) TCG generation helpers
In reply to Taylor SimpsonHelpers for reading and writing registers
Helpers for load-locked/store-conditional
--- target/hexagon/genptr_helpers.h | 244 ++++++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 18 +++ 2 files changed, 262 insertions(+) create mode 100644 target/hexagon/genptr_helpers.h
target/hexagon/genptr_helpers.h new file +244 -0
@@ -0,0 +1,244 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_GENPTR_HELPERS_H +#define HEXAGON_GENPTR_HELPERS_H + +#include "tcg/tcg.h" + +static inline TCGv gen_read_reg (TCGv result,int num) +{ +tcg_gen_mov_tl (result, hex_gpr[num]); +return result; +} + +static inline TCGv gen_read_preg (TCGv pred,uint8_t num) +{ +tcg_gen_mov_tl (pred, hex_pred[num]); +return pred; +} + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated) +{ +if (is_predicated) { +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); +TCGv slot_mask =tcg_temp_new (); + +tcg_gen_andi_tl (slot_mask, hex_slot_cancelled,1 << slot); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum], slot_mask, zero, + val, hex_new_value[rnum]); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movcond_tl (TCG_COND_EQ , hex_reg_written[rnum], slot_mask, zero, + one, hex_reg_written[rnum]); +#endif + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (slot_mask); + }else { +tcg_gen_mov_tl (hex_new_value[rnum], val); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movi_tl (hex_reg_written[rnum],1 ); +#endif + } +} + +static inline void gen_log_reg_write_pair (int rnum,TCGv_i64 val,int slot, +int is_predicated) +{ +TCGv val32 =tcg_temp_new (); + +if (is_predicated) { +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); +TCGv slot_mask =tcg_temp_new (); + +tcg_gen_andi_tl (slot_mask, hex_slot_cancelled,1 << slot); +/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum], slot_mask, zero, + val32, hex_new_value[rnum]); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movcond_tl (TCG_COND_EQ , hex_reg_written[rnum], + slot_mask, zero, + one, hex_reg_written[rnum]); +#endif + +/* High word */ +tcg_gen_extrh_i64_i32 (val32, val); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum +1 ], + slot_mask, zero, + val32, hex_new_value[rnum +1 ]); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movcond_tl (TCG_COND_EQ , hex_reg_written[rnum +1 ], + slot_mask, zero, + one, hex_reg_written[rnum +1 ]); +#endif + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (slot_mask); + }else { +/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum], val32); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movi_tl (hex_reg_written[rnum],1 ); +#endif + +/* High word */ +tcg_gen_extrh_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum +1 ], val32); +#if HEX_DEBUG +/* Do this so HELPER(debug_commit_end) will know */ +tcg_gen_movi_tl (hex_reg_written[rnum +1 ],1 ); +#endif + } + +tcg_temp_free (val32); +} + +static inline void gen_log_pred_write (int pnum,TCGv val) +{ +TCGv zero =tcg_const_tl (0 ); +TCGv base_val =tcg_temp_new (); +TCGv and_val =tcg_temp_new (); +TCGv pred_written =tcg_temp_new (); + +/* Multiple writes to the same preg are and'ed together */ +tcg_gen_andi_tl (base_val, val,0xff ); +tcg_gen_and_tl (and_val, base_val, hex_new_pred_value[pnum]); +tcg_gen_andi_tl (pred_written, hex_pred_written,1 << pnum); +tcg_gen_movcond_tl (TCG_COND_NE , hex_new_pred_value[pnum], + pred_written, zero, + and_val, base_val); +tcg_gen_ori_tl (hex_pred_written, hex_pred_written,1 << pnum); + +tcg_temp_free (zero); +tcg_temp_free (base_val); +tcg_temp_free (and_val); +tcg_temp_free (pred_written); +} + +static inline void gen_read_p3_0 (TCGv control_reg) +{ +TCGv pval =tcg_temp_new (); +int i; +tcg_gen_movi_tl (control_reg,0 ); +for (i =NUM_PREGS -1 ; i >=0 ; i--) { +tcg_gen_shli_tl (control_reg, control_reg,8 ); +tcg_gen_andi_tl (pval, hex_pred[i],0xff ); +tcg_gen_or_tl (control_reg, control_reg, pval); + } +tcg_temp_free (pval); +} + +static inline void gen_write_p3_0 (TCGv tmp) +{ +TCGv control_reg =tcg_temp_new (); +TCGv pred_val =tcg_temp_new (); +int i; + +tcg_gen_mov_tl (control_reg, tmp); +for (i =0 ; i <NUM_PREGS ; i++) { +tcg_gen_andi_tl (pred_val, control_reg,0xff ); +tcg_gen_mov_tl (hex_pred[i], pred_val); +tcg_gen_shri_tl (control_reg, control_reg,8 ); + } +tcg_temp_free (control_reg); +tcg_temp_free (pred_val); +} + +static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +{ +tcg_gen_qemu_ld32u (dest, vaddr, mem_index); +tcg_gen_mov_tl (hex_llsc_addr, vaddr); +tcg_gen_mov_tl (hex_llsc_val, dest); +} + +static inline void gen_load_locked8u (TCGv_i64 dest,TCGv vaddr,int mem_index) +{ +tcg_gen_qemu_ld64 (dest, vaddr, mem_index); +tcg_gen_mov_tl (hex_llsc_addr, vaddr); +tcg_gen_mov_i64 (hex_llsc_val_i64, dest); +} + +static inline void gen_store_conditional4 (CPUHexagonState *env, +DisasContext *ctx,int prednum, +TCGv pred,TCGv vaddr,TCGv src) +{ +TCGLabel *fail =gen_new_label (); +TCGLabel *done =gen_new_label (); + +tcg_gen_brcond_tl (TCG_COND_NE , vaddr, hex_llsc_addr, fail); + +TCGv one =tcg_const_tl (0xff ); +TCGv zero =tcg_const_tl (0 ); +TCGv tmp =tcg_temp_new (); +tcg_gen_atomic_cmpxchg_tl (tmp, hex_llsc_addr, hex_llsc_val, src, + ctx->mem_idx,MO_32 ); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_pred[prednum], tmp, hex_llsc_val, + one, zero); +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (tmp); +tcg_gen_br (done); + +gen_set_label (fail); +tcg_gen_movi_tl (pred,0 ); + +gen_set_label (done); +tcg_gen_movi_tl (hex_llsc_addr, ~0 ); +} + +static inline void gen_store_conditional8 (CPUHexagonState *env, +DisasContext *ctx,int prednum, +TCGv pred,TCGv vaddr,TCGv_i64 src) +{ +TCGLabel *fail =gen_new_label (); +TCGLabel *done =gen_new_label (); + +tcg_gen_brcond_tl (TCG_COND_NE , vaddr, hex_llsc_addr, fail); + +TCGv_i64 one =tcg_const_i64 (0xff ); +TCGv_i64 zero =tcg_const_i64 (0 ); +TCGv_i64 tmp =tcg_temp_new_i64 (); +tcg_gen_atomic_cmpxchg_i64 (tmp, hex_llsc_addr, hex_llsc_val_i64, src, + ctx->mem_idx,MO_64 ); +tcg_gen_movcond_i64 (TCG_COND_EQ , tmp, tmp, hex_llsc_val_i64, + one, zero); +tcg_gen_extrl_i64_i32 (hex_pred[prednum], tmp); +tcg_temp_free_i64 (one); +tcg_temp_free_i64 (zero); +tcg_temp_free_i64 (tmp); +tcg_gen_br (done); + +gen_set_label (fail); +tcg_gen_movi_tl (pred,0 ); + +gen_set_label (done); +tcg_gen_movi_tl (hex_llsc_addr, ~0 ); +} + +#endif
target/hexagon/op_helper.c +18 -0
@@ -88,6 +88,24 @@ static inline void log_pred_write(CPUHexagonState *env, int pnum, } } +static inline void log_store32 (CPUHexagonState *env,target_ulong addr, +int32_t val,int width,int slot) +{ +HEX_DEBUG_LOG ("log_store%d(0x%x, %d [0x%x])\n" , width, addr, val, val); + env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data32 = val; +} + +static inline void log_store64 (CPUHexagonState *env,target_ulong addr, +int64_t val,int width,int slot) +{ +HEX_DEBUG_LOG ("log_store%d(0x%x, %ld [0x%lx])\n" , width, addr, val, val); + env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data64 = val; +} +static inline void write_new_pc (CPUHexagonState *env,target_ulong addr) {HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr);
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpers
Quoted 42 lines · Taylor Simpson
Helpers for reading and writing registers
Helpers for load-locked/store-conditionalSigned-off-by Taylor Simpson <[email protected]>--- target/hexagon/genptr_helpers.h | 244 ++++++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 18 +++ 2 files changed, 262 insertions(+) create mode 100644 target/hexagon/genptr_helpers.htarget/hexagon/genptr_helpers.h new file +26
-0@@ -0,0 +1,244 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_GENPTR_HELPERS_H +#define HEXAGON_GENPTR_HELPERS_H + +#include "tcg/tcg.h" + +static inline TCGv gen_read_reg (TCGv result,int num) +{ +tcg_gen_mov_tl (result, hex_gpr[num]); +return result;
target/hexagon/genptr_helpers.h line 36
Quoted 10 lines
target/hexagon/genptr_helpers.h new file +10
-0+} + +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_reg_write (int rnum,TCGv val,int slot, +int is_predicated)
These are quite large. Why are they marked inline?
target/hexagon/genptr_helpers.h line 104
Quoted 3 lines
target/hexagon/genptr_helpers.h new file +3
-0+/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum], val32);
Why are you extracting into a temporary?
This could be done with
tcg_gen_extr_i64_i32(hex_new_value[rnum],
hex_new_value[rnum + 1], val);target/hexagon/genptr_helpers.h line 152
Quoted 9 lines
target/hexagon/genptr_helpers.h new file +9
-0+static inline void gen_read_p3_0 (TCGv control_reg) +{ +TCGv pval =tcg_temp_new (); +int i; +tcg_gen_movi_tl (control_reg,0 ); +for (i =NUM_PREGS -1 ; i >=0 ; i--) { +tcg_gen_shli_tl (control_reg, control_reg,8 ); +tcg_gen_andi_tl (pval, hex_pred[i],0xff ); +tcg_gen_or_tl (control_reg, control_reg, pval);
tcg_gen_deposit_tl(control_reg, control_reg,
hex_pred[i], i * 8, 8);
target/hexagon/genptr_helpers.h line 167
Quoted 4 lines
target/hexagon/genptr_helpers.h new file +4
-0+for (i =0 ; i <NUM_PREGS ; i++) { +tcg_gen_andi_tl (pred_val, control_reg,0xff ); +tcg_gen_mov_tl (hex_pred[i], pred_val); +tcg_gen_shri_tl (control_reg, control_reg,8 );
tcg_gen_extract_tl(hex_pred[i], control_reg, i * 8, 8);
Quoted 7 lines
target/hexagon/genptr_helpers.h new file +7
-0+static inline void log_store32 (CPUHexagonState *env,target_ulong addr, +int32_t val,int width,int slot) +{ +HEX_DEBUG_LOG ("log_store%d(0x%x, %d [0x%x])\n" , width, addr, val, val); + env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data32 = val;
target/hexagon/genptr_helpers.h line 69
Quoted 10 lines
target/hexagon/genptr_helpers.h new file +10
-0+} + +static inline void log_store64 (CPUHexagonState *env,target_ulong addr, +int64_t val,int width,int slot) +{ +HEX_DEBUG_LOG ("log_store%d(0x%x, %ld [0x%lx])\n" , width, addr, val, val); + env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data64 = val; +}
... or fold this re-addition back into where it was accidentally removed. ;-)
r~
RE: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpers
Quoted 25 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:49 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpersQuoted 6 lines · Taylor Simpson
Helpers for reading and writing registers
Helpers for load-locked/store-conditionalSigned-off-by Taylor Simpson <[email protected]>--- target/hexagon/genptr_helpers.h | 244++++++++++++++++++++++++++++++++++++++++
Review
Quoted 5 lines
target/hexagon/op_helper.c | 18 +++ 2 files changed, 262 insertions(+) create mode 100644 target/hexagon/genptr_helpers.h(quoted diff) +0
-0
b/target/hexagon/genptr_helpers.h
Quoted 10 lines
target/hexagon/genptr_helpers.h line 3
Quoted 8 lines
new file mode 100644
index 0000000..ffcb1e3target/hexagon/genptr_helpers.h new file +3
-0@@ -0,0 +1,244 @@ + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated)These are quite large. Why are they marked inline?
Since this is a header file, it prevents the compiler from complaining when they aren't used.
Quoted 10 lines
target/hexagon/genptr_helpers.h line 104
Quoted 4 lines
target/hexagon/genptr_helpers.h new file +3
-0+/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum], val32);Why are you extracting into a temporary?
This could be done withtcg_gen_extr_i64_i32(hex_new_value[rnum], hex_new_value[rnum + 1], val);
OK
Quoted 11 lines
target/hexagon/genptr_helpers.h line 152
Quoted 9 lines
target/hexagon/genptr_helpers.h new file +9
-0+static inline void gen_read_p3_0 (TCGv control_reg) +{ +TCGv pval =tcg_temp_new (); +int i; +tcg_gen_movi_tl (control_reg,0 ); +for (i =NUM_PREGS -1 ; i >=0 ; i--) { +tcg_gen_shli_tl (control_reg, control_reg,8 ); +tcg_gen_andi_tl (pval, hex_pred[i],0xff ); +tcg_gen_or_tl (control_reg, control_reg, pval);tcg_gen_deposit_tl(control_reg,
control_reg,
Quoted 1 line
hex_pred[i], i * 8, 8);
OK
Quoted 6 lines
target/hexagon/genptr_helpers.h line 167
Quoted 4 lines
target/hexagon/genptr_helpers.h new file +4
-0+for (i =0 ; i <NUM_PREGS ; i++) { +tcg_gen_andi_tl (pred_val, control_reg,0xff ); +tcg_gen_mov_tl (hex_pred[i], pred_val); +tcg_gen_shri_tl (control_reg, control_reg,8 );
tcg_gen_extract_tl(hex_pred[i], control_reg, i * 8, 8);
OK
Quoted 15 lines
target/hexagon/genptr_helpers.h line 23
Quoted 4 lines
target/hexagon/genptr_helpers.h new file +4
-0+static inline void log_store32 (CPUHexagonState *env,target_ulong addr, +int32_t val,int width,int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %d [0x%x])\n", width, addr, val,val);
target/hexagon/genptr_helpers.h line 32
Quoted 9 lines
target/hexagon/genptr_helpers.h new file +9
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data32 = val; +} + +static inline void log_store64 (CPUHexagonState *env,target_ulong addr, +int64_t val,int width,int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %ld [0x%lx])\n", width, addr,val, val);
Quoted 6 lines
target/hexagon/genptr_helpers.h line 36
Quoted 4 lines
target/hexagon/genptr_helpers.h new file +4
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data64 = val; +}... or fold this re-addition back into where it was accidentally removed. ;-)
Could you elaborate?
Re: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpers
Quoted 9 lines · Taylor Simpson
Quoted 7 lines
target/hexagon/genptr_helpers.h line 3
Quoted 5 lines
+++
b/target/hexagon/genptr_helpers.htarget/hexagon/genptr_helpers.h new file +3
-0@@ -0,0 +1,244 @@ + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated)These are quite large. Why are they marked inline?
Since this is a header file, it prevents the compiler from complaining when they aren't used.
Ok, why are they in a header file?
Why would they be unused, come to that?
The header file is used exactly once, by genptr.c. Seems to me they could just as well be *in* genptr.c.
If the functions are not used, just remove them?
Quoted 15 lines
Quoted 15 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 4 lines
target/hexagon/op_helper.c +4
-0+static inline void log_store32 (CPUHexagonState *env,target_ulong addr, +int32_t val,int width,int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %d [0x%x])\n", width, addr, val,val);
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 9 lines
target/hexagon/op_helper.c +9
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data32 = val; +} + +static inline void log_store64 (CPUHexagonState *env,target_ulong addr, +int64_t val,int width,int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %ld [0x%lx])\n", width, addr,val, val);
Quoted 8 lines
Quoted 6 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum, · line 107
Quoted 4 lines
target/hexagon/op_helper.c +4
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data64 = val; +}... or fold this re-addition back into where it was accidentally removed. ;-)
Could you elaborate?
You added this code in one patch (didn't check which), removed it in patch 26, and re-added it here in patch 28.
r~
RE: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpers
Quoted 23 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 2:52 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 28/34] Hexagon (target/hexagon) TCG generation helpersQuoted 9 lines · Taylor Simpson
Quoted 7 lines
target/hexagon/genptr_helpers.h line 3
Quoted 5 lines
+++
b/target/hexagon/genptr_helpers.htarget/hexagon/genptr_helpers.h new file +3
-0@@ -0,0 +1,244 @@ + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated)These are quite large. Why are they marked inline?
Since this is a header file, it prevents the compiler from complaining when
they aren't used.
Quoted 8 lines
Ok, why are they in a header file?
Why would they be unused, come to that?The header file is used exactly once, by
genptr.c. Seems to me they could just
as well be *in*genptr.c.If the functions are not used, just remove them?
I could have sworn it was included in more than one C file. I'll move the contents to genptr.c.
Quoted 23 lines
Quoted 1 line
Quoted 1 line
Review line 4
Quoted 1 line
(quoted diff) +1
-0+static inline void log_store32(CPUHexagonState *env, target_ulongaddr,
Quoted 3 lines
Quoted 3 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 3 lines
target/hexagon/op_helper.c +3
-0+ int32_t val, int width, int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %d [0x%x])\n", width, addr,val,
Quoted 7 lines
Quoted 7 lines
val);
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 6 lines
target/hexagon/op_helper.c +6
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data32 = val; +} + +static inline void log_store64(CPUHexagonState *env, target_ulongaddr,
Quoted 9 lines
Quoted 9 lines
target/hexagon/op_helper.c static inline void log_pred_write(CPUHexagonState *env, int pnum,
Quoted 3 lines
target/hexagon/op_helper.c +3
-0+ int64_t val, int width, int slot) +{ + HEX_DEBUG_LOG("log_store%d(0x%x, %ld [0x%lx])\n", width, addr,val, val);
Quoted 4 lines
target/hexagon/op_helper.c +4
-0+ env->mem_log_stores[slot].va = addr; + env->mem_log_stores[slot].width = width; + env->mem_log_stores[slot].data64 = val; +}
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
... or fold this re-addition back into where it was accidentally removed. ;-)
Could you elaborate?
You added this code in one patch (didn't check which), removed it in patch 26,
and re-added it here in patch 28.
My apologies, this is my screwing up the git rebase. I'll fix it.
Quoted 3 lines
r~
RFC PATCH v3 29/34 Hexagon (target/hexagon) TCG generation
In reply to Taylor SimpsonInclude the generated files and set up the data structures
--- target/hexagon/genptr.h | 25 ++++++++++++++++++++++ target/hexagon/genptr.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 target/hexagon/genptr.h create mode 100644 target/hexagon/genptr.c
target/hexagon/genptr.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_GENPTR_H +#define HEXAGON_GENPTR_H + +#include "insn.h" + +extern semantic_insn_t opcode_genptr[]; + +#endif
target/hexagon/genptr.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 29/34] Hexagon (target/hexagon) TCG generation
Quoted 6 lines · Taylor Simpson
target/hexagon/genptr.c new file +6
-0+/* Fill in the table with NULLs because not all the opcodes have DEF_QEMU */ +semantic_insn_t opcode_genptr[] = { +#define OPCODE(X) NULL +#include "opcodes_def_generated.h" +NULL +#undef OPCODE
target/hexagon/genptr.c line 55
Quoted 10 lines
target/hexagon/genptr.c new file +10
-0+}; + +/* This function overwrites the NULL entries where we have a DEF_QEMU */ +void init_genptr (void ) +{ +#define DEF_TCG_FUNC (TAG ,GENFN ) \ + opcode_genptr[TAG] = generate_##TAG; +#include "tcg_funcs_generated.h" +#undef DEF_TCG_FUNC +}
Just size the array properly to start.
const semantic_insn_t opcode_genptr[XX_LAST_OPCODE] = {
#define DEF_TCG_FUNC(TAG, GENFN) \
[TAG] = generate_##TAG,#include "tcg_funcs_generated.h"
};
RE: [RFC PATCH v3 29/34] Hexagon (target/hexagon) TCG generation
Quoted 33 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 7:58 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 29/34] Hexagon (target/hexagon) TCG generationQuoted 1 line · Taylor Simpson
+/* Fill in the table with NULLs because not all the opcodes have
DEF_QEMU*/target/hexagon/genptr.c
Quoted 8 lines
target/hexagon/genptr.c new file +8
-0+semantic_insn_t opcode_genptr[] = { +#define OPCODE(X) NULL +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +/* This function overwrites the NULL entries where we have a DEF_QEMU */
target/hexagon/genptr.c line 55
Quoted 7 lines
target/hexagon/genptr.c new file +7
-0+void init_genptr (void ) +{ +#define DEF_TCG_FUNC (TAG ,GENFN ) \ + opcode_genptr[TAG] = generate_##TAG; +#include "tcg_funcs_generated.h" +#undef DEF_TCG_FUNC +}Just size the array properly to start.
Quoted 7 lines
const
semantic_insn_topcode_genptr[XX_LAST_OPCODE] = {#define DEF_TCG_FUNC(TAG, GENFN) \ [TAG] = generate_##TAG,#include "
tcg_funcs_generated.h"};
OK
RFC PATCH v3 30/34 Hexagon (target/hexagon) TCG for instructions with multiple definitions
In reply to Taylor SimpsonHelpers won't work if there are multiple definitions, so we override these instructions using #define fGEN_TCG_<tag>.
--- target/hexagon/gen_tcg.h | 198 +++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/helper.h | 2 + target/hexagon/genptr.c | 1 + 3 files changed, 201 insertions(+) create mode 100644 target/hexagon/gen_tcg.h
target/hexagon/gen_tcg.h new file +198 -0
@@ -0,0 +1,198 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_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
target/hexagon/helper.h +2 -0
@@ -15,6 +15,8 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "gen_tcg.h" + DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(debug_start_packet, void, env)DEF_HELPER_3 (debug_check_store_width, void, env, int, int)
target/hexagon/genptr.c +1 -0
@@ -26,6 +26,7 @@#include "translate.h" #include "macros.h" #include "genptr_helpers.h" +#include "gen_tcg.h" #define DEF_TCG_FUNC (TAG ,GENFN ) \ static void generate_##TAG(CPUHexagonState *env, DisasContext *ctx, \
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
target/hexagon/helper.h line 18
Quoted 6 lines · Taylor Simpson
+++
b/target/hexagon/helper.htarget/hexagon/helper.h +1
-0@@ -15,6 +15,8 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "gen_tcg.h"
Why would you need this here? Definitely looks wrong.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 12 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 8:03 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsOn 8/18/20 8:50 AM, Taylor Simpson wrote:
Quoted 8 lines
target/hexagon/helper.h line 18
Quoted 6 lines
+++
b/target/hexagon/helper.htarget/hexagon/helper.h +1
-0@@ -15,6 +15,8 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "gen_tcg.h" Why would you need this here? Definitely looks wrong.
I'll add the following comment to indicate what's going on
/*
* Each of the generated helpers is wrapped with #ifndef fGEN_TCG_<tag>.
* For example
* #ifndef fGEN_TCG_A2_add * DEF_HELPER_3(A2_add, s32, env, s32, s32) * #endif
* We include gen_tcg.h here to provide definitions of fGEN_TCG for any instructions that
* are overridden.
*
* This prevents unused helpers from taking up space in the executable.
*/
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 5 lines · Taylor Simpson
I'll add the following comment to indicate what's going on
/*
* Each of the generated helpers is wrapped with #ifndef fGEN_TCG_<tag>.
* For example
Quoted 8 lines
* #ifndef fGEN_TCG_A2_add * DEF_HELPER_3(A2_add, s32, env, s32, s32) * #endif* We include
gen_tcg.hhere to provide definitions offGEN_TCGfor any instructions that
* are overridden.
*
* This prevents unused helpers from taking up space in the executable.
*/
Ah, hum. Well.
How about we figure out a way to communicate to the generator scripts which functions have been implemented "directly", and don't need to be generated at all?
I don't see why we have to wait until the c preprocessor to remove this unused code, and the less we have of it, the better.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 30 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 3:13 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 4 lines · Taylor Simpson
I'll add the following comment to indicate what's going on
/*
* Each of the generated helpers is wrapped with #ifndeffGEN_TCG_<tag>.
Quoted 5 lines
* For example
* #ifndef fGEN_TCG_A2_add * DEF_HELPER_3(A2_add, s32, env, s32, s32) * #endif* We include
gen_tcg.hhere to provide definitions offGEN_TCGfor anyinstructions that
Quoted 4 lines
* are overridden.
*
* This prevents unused helpers from taking up space in the executable. */Ah, hum. Well.
Quoted 9 lines
How about we figure out a way to communicate to the generator scripts which
functions have been implemented "directly", and don't need to be generated at all?I don't see why we have to wait until the c preprocessor to remove this unused
code, and the less we have of it, the better.
A few reasons
- Makes it easy to override instruction helpers. All one has to do is #define fGEN_TCG_<tag>.
- When debugging the override, sometimes you want to quickly revert back to the helper. Or if you've written a bunch of overrides in one shot and then find that a test case is failing, you can binary search which one to turn off and get the test to pass. This is the one with the bug to fix.
- Reduces time for an incremental build. When we add or delete an override, we don't have to re-run the generator.
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 35 lines · Taylor Simpson
Quoted 35 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 3:13 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 4 lines · Taylor Simpson
I'll add the following comment to indicate what's going on
/*
* Each of the generated helpers is wrapped with #ifndeffGEN_TCG_<tag>.
Quoted 5 lines
* For example
* #ifndef fGEN_TCG_A2_add * DEF_HELPER_3(A2_add, s32, env, s32, s32) * #endif* We include
gen_tcg.hhere to provide definitions offGEN_TCGfor anyinstructions that
Quoted 4 lines
* are overridden.
*
* This prevents unused helpers from taking up space in the executable. */Ah, hum. Well.
How about we figure out a way to communicate to the generator scripts which
functions have been implemented "directly", and don't need to be generated at all?
Quoted 7 lines
Quoted 4 lines
I don't see why we have to wait until the c preprocessor to remove this unused
code, and the less we have of it, the better.A few reasons
- Makes it easy to override instruction helpers. All one has to do is #define fGEN_TCG_<tag>.
If the generator can examine, say, genptr_override.c.inc, then you don't even have to add a #define. Just add the code.
Perhaps something like
DEFINE_FGEN(tag)
{
// some code
}where DEFINE_FGEN expands to the appropriate function declaration. The generator then need only grep '^DEFINE_FGEN' and extract the list of overridden tags.
Quoted 1 line
- When debugging the override, sometimes you want to quickly revert back to the helper. Or if you've written a bunch of overrides in one shot and then find that a test case is failing, you can binary search which one to turn off and get the test to pass. This is the one with the bug to fix.
No difference there, just binary searching on different text.
Quoted 1 line
- Reduces time for an incremental build. When we add or delete an override, we don't have to re-run the generator.
About this I care not at all. I can't imagine that more than fractions of a second are at stake.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 66 lines
Quoted 13 lines
Quoted 13 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 3:13 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 2 lines · Taylor Simpson
I'll add the following comment to indicate what's going on
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
/*
* Each of the generated helpers is wrapped with #ifndeffGEN_TCG_<tag>.
Quoted 5 lines
* For example
* #ifndef fGEN_TCG_A2_add * DEF_HELPER_3(A2_add, s32, env, s32, s32) * #endif* We include
gen_tcg.hhere to provide definitions offGEN_TCGforany
Quoted 13 lines
Quoted 13 lines
instructions that
Quoted 4 lines
* are overridden.
*
* This prevents unused helpers from taking up space in the executable. */Ah, hum. Well.
How about we figure out a way to communicate to the generator scripts which
functions have been implemented "directly", and don't need to be generated at all?Quoted 7 lines
Quoted 4 lines
I don't see why we have to wait until the c preprocessor to remove this unused
code, and the less we have of it, the better.A few reasons
- Makes it easy to override instruction helpers. All one has to do is #definefGEN_TCG_<tag>.
If the generator can examine, say, genptr_override.c.inc, then you don't even
have to add a #define. Just add the code.Perhaps something like
DEFINE_FGEN(tag){ // some code }where
DEFINE_FGENexpands to the appropriate function declaration. The generator then need only grep '^DEFINE_FGEN' and extract the list of overridden
tags.Quoted 1 line
- When debugging the override, sometimes you want to quickly revert back
to the helper. Or if you've written a bunch of overrides in one shot and then find that a test case is failing, you can binary search which one to turn off and get the test to pass. This is the one with the bug to fix.
Quoted 7 lines
No difference there, just binary searching on different text.
Quoted 1 line
- Reduces time for an incremental build. When we add or delete an
override, we don't have to re-run the generator.
About this I care not at all. I can't imagine that more than fractions of a second are at stake.
I can modify the generator to skip instructions with overrides.
There are some assumptions here I'd like to clarify. When I started this discussion, there seemed to be general resistance to the concept of a generator. Because of this, I made the generator as simple as possible and pushed the complexity and optimization into code that consumes the output of the generator. Also, I assumed people wouldn't read the output of the generator, so I didn't focus on making it readable.
Now, it sounds like my assumptions were not correct. You pointed out two things to do in the generator
- Expand the macros inline
- Skip the instructions that have overrides
I addition, there other things I should do if we want the generated files to be more readable
- Indent the code
- Only generate one of the fGEN_TCG_<tag> or gen_helper_<tag>
- Generate the declaration of the generate_<tag> function instead of just the body
Thoughts?
Thanks,
Taylor
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 6 lines · Taylor Simpson
There are some assumptions here I'd like to clarify. When I started this discussion, there seemed to be general resistance to the concept of a generator. Because of this, I made the generator as simple as possible and pushed the complexity and optimization into code that consumes the output of the generator. Also, I assumed people wouldn't read the output of the generator, so I didn't focus on making it readable.
Except, at some point, one has to debug this code.
If the code is unreadable, how do you figure out what's broken?
Quoted 3 lines
Now, it sounds like my assumptions were not correct. You pointed out two things to do in the generator> - Expand the macros inline
- Skip the instructions that have overrides
Yes please.
Quoted 2 lines
I addition, there other things I should do if we want the generated files to be more readable
- Indent the code
Helpful, yes.
I wouldn't worry about nested statements within the *.def files too much, except to put each ";" terminated statement on a new line, so that gdb's step command goes to the next statement instead of skipping everything all at once.
Quoted 1 line
- Only generate one of the fGEN_TCG_<tag> or gen_helper_<tag>
That would be part of "skip the instructions that have overrides", would it not?
Quoted 1 line
- Generate the declaration of the generate_<tag> function instead of just the body
I'm not quite sure what this means.
Aren't the "generate_<tag>" functions private to genptr.c? Why would we need a separate declaration of them, as opposed to just a definition?
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 40 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 11:29 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 4 lines · Taylor Simpson
There are some assumptions here I'd like to clarify. When I started this discussion, there seemed to be general resistance to the concept of a generator. Because of this, I made the generator as simple as possible and pushed the complexity and optimization into code that consumes the
output of
Quoted 2 lines
the generator. Also, I assumed people wouldn't read the output of the generator, so I didn't focus on making it readable.
Except, at some point, one has to debug this code.
If the code is unreadable, how do you figure out what's broken?Quoted 3 lines
Now, it sounds like my assumptions were not correct. You pointed out two things to do in the generator> - Expand the macros inline
- Skip the instructions that have overridesYes please.
Quoted 1 line
I addition, there other things I should do if we want the generated files to
be more readable
Quoted 1 line
- Indent the code
Helpful, yes.
I wouldn't worry about nested statements within the *.def files too much, except to put each ";" terminated statement on a new line, so that gdb's step command goes to the next statement instead of skipping everything all at once.
Quoted 4 lines
Quoted 1 line
- Only generate one of the fGEN_TCG_<tag> or gen_helper_<tag>
That would be part of "skip the instructions that have overrides", would it not?
Just to be explicit, the code that generates code is generated as
#ifdef fGEN_TCG_A2_add
fGEN_TCG_A2_add({ RdV=RsV+RtV;});
#else
do {
gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
} while (0);
#endif
If we're going to have the generator know if there is an override, this would be more readable as either
fGEN_TCG_A2_add({ RdV=RsV+RtV;});
or
gen_helper_A2_add(RdV, cpu_env, RsV, RtV);Quoted 8 lines
Quoted 1 line
- Generate the declaration of the generate_<tag> function instead of just
the body
I'm not quite sure what this means.
Aren't the "generate_<tag>" functions private to
genptr.c? Why would we need a
separate declaration of them, as opposed to just a definition?
In genptr.c, there is
#define DEF_TCG_FUNC(TAG, GENFN) \
static void generate_##TAG(CPUHexagonState *env, DisasContext *ctx, \
insn_t *insn, packet_t *pkt) \
{ \
GENFN \
}
#include "tcg_funcs_generated.h"
#undef DEF_TCG_FUNCThe generated code only has the body of the function. It would be more readable to move the static void generate_##TAG ... into the generated code.
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 12 lines · Taylor Simpson
Just to be explicit, the code that generates code is generated as
#ifdef fGEN_TCG_A2_add fGEN_TCG_A2_add({ RdV=RsV+RtV;}); #else do { gen_helper_A2_add(RdV, cpu_env, RsV, RtV); } while (0); #endif If we're going to have the generator know if there is an override, this would be more readable as either fGEN_TCG_A2_add({ RdV=RsV+RtV;}); or gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
Not quite, see below.
Quoted 9 lines
In
genptr.c, there is#define DEF_TCG_FUNC(TAG, GENFN) \ static void generate_##TAG(CPUHexagonState *env, DisasContext *ctx, \ insn_t *insn, packet_t *pkt) \ { \ GENFN \ } #include "tcg_funcs_generated.h" #undef DEF_TCG_FUNC
Quoted 3 lines
The generated code only has the body of the function. It would be more readable to move the static void generate_##TAG ... into the generated code.
Yes.
The fGEN_TCG_A2_add macro does not require nor use that {...} argument. What it *does* need are the same arguments as are given to generate_<rtag>. I assume you are using those arguments implicitly in your current fGEN_TCG_<rtag> instances?
It would be cleanest to only have the generate_* functions.
Either they are written by hand (replacing the current fGEN_TCG_*), or they are generated. In either case, there's just the one level of indirection from opcode_genptr[].
I'd imagine
--- genptr.c
#define DEF_TCG_FUNC(TAG) \
static void generate_##TAG(CPUHexagonState *env, \
DisasContext *ctx, insn_t *insn, packet_t *pkt)
/*
* All IIDs with an explicit implementation,
* overriding the auto-generated helper functions. */
DEF_TCG_FUNC(A2_add)
{
/* { RdV=RsV+RtV;} */
tcg_gen_add_tl(args...);
}/*
* Generate calls to the auto-generate helpers,
* and slot everything into the opcode_genptr table. */
#include "genptr_generated.c.inc"
--- genptr_generated.c.inc
DEF_TCG_FUNC(A4_tlbmatch)
{
gen_helper_A4_tlbmatch(args...);
}
// etc
const SemanticInsn opcode_genptr[] = {
// All IID's, generated or not.
};---
This leaves genptr.c as the file to grep for '^DEF_TCG_FUNC'.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 1:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 1 line
The
fGEN_TCG_A2_addmacro does not require nor use that {...} argument.
The fGEN_TCG_A2_add macro does need that argument, but there are cases that do need it. Here's an example from gen_tcg.h
#define fGEN_TCG_L2_loadrub_pr(SHORTCODE) SHORTCODE
This is explained in the README, but basically the argument is useful if we can properly define the macros that it contains to generate TCG.
Quoted 4 lines
What it *does* need are the same arguments as are given to generate_<rtag>. I assume you are using those arguments implicitly in your current fGEN_TCG_<rtag>
instances?
Yes
Quoted 21 lines
It would be cleanest to only have the generate_* functions.
Either they are written by hand (replacing the current fGEN_TCG_*), or they are
generated. In either case, there's just the one level of indirection from opcode_genptr[].I'd imagine
---
genptr.c#define
DEF_TCG_FUNC(TAG)\
static void generate_##TAG(CPUHexagonState *env, \
DisasContext *ctx,insn_t*insn,packet_t*pkt)/*
* All IIDs with an explicit implementation,
* overriding the auto-generated helper functions. */
Quoted 5 lines
DEF_TCG_FUNC(A2_add){ /* { RdV=RsV+RtV;} */ tcg_gen_add_tl(args...); }
There's additional generated code before and after the tcg_gen_add_tl. IMO, we don't want the person who writes an override having to reproduce the generated code. Assuming we have a definition of fGEN_TCG_A2_add and we have the generator intelligently expanding the macros, this is what will be generated.
static void generate_A2_add(CPUHexagonState *env, DisasContext *ctx, insn_t *insn, packet_t *pkt) {
/* A2_add */
int RdN =insn->regno[0];
TCGv RdV = tcg_temp_local_new();
int RsN = insn->regno[1];
TCGv RsV = hex_gpr[RsN];
int RtN = insn->regno[2];
TCGv RtV = hex_gpr[RtN];
fGEN_TCG_A2_add({ RdV=RsV+RtV;});
gen_log_reg_write(RdN, RdV, insn->slot, 0); ctx_log_reg_write(ctx, RdN);
tcg_temp_free(RdV);
/* A2_add */
}
If there weren't an override, we'd get this
static void generate_A2_add(CPUHexagonState *env, DisasContext *ctx, insn_t *insn, packet_t *pkt) {
/* A2_add */
int RdN =insn->regno[0];
TCGv RdV = tcg_temp_local_new();
int RsN = insn->regno[1];
TCGv RsV = hex_gpr[RsN];
int RtN = insn->regno[2];
TCGv RtV = hex_gpr[RtN];
gen_helper_A2_add(RdV, cpu_env, RsV, RtV); /* Only difference is this line */
gen_log_reg_write(RdN, RdV, insn->slot, 0); ctx_log_reg_write(ctx, RdN);
tcg_temp_free(RdV);
/* A2_add */
}
The fGEN_TCG_<tag> macro can also mention the operands of the instruction (RdV, RsV, RtV in this example).
Unlike the generate_<tag> functions that all have the same signature. The overrides would have different signatures. This would be more defensive programming because you know exactly where the variables come from but more verbose when writing the overrides by hand. Also, note that these need to be macros in order to take advantage of the SHORTCODE.
In other words, instead of
#define fGEN_TCG_A2_add(SHORTCODE) tcg_gen_add_tl(RdV, RsV, RtV)
We would write
#define fGEN_TCG_A2_add(env, ctx, insn, pkt, RdV, RsV, RtV, SHORTCODE) tcg_gen_add_tl(RdV, RsV, RtV);
Personally, I prefer the former, but will change to the latter if you feel strongly.
I'm not married to the fGEN_TCG_<tag> name. DEF_TCG_<tag> would also be fine.
Quoted 26 lines
/*
* Generate calls to the auto-generate helpers,
* and slot everything into theopcode_genptrtable. */
#include "genptr_generated.c.inc"--- genptr_generated.c.inc
DEF_TCG_FUNC(A4_tlbmatch){ gen_helper_A4_tlbmatch(args...); }// etc
const SemanticInsn opcode_genptr[] = { // All IID's, generated or not. };---
This leaves
genptr.cas the file to grep for '^DEF_TCG_FUNC'.r~
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 11 lines · Taylor Simpson
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 1:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 7 lines
Quoted 1 line
The
fGEN_TCG_A2_addmacro does not require nor use that {...} argument.The
fGEN_TCG_A2_addmacro does need that argument, but there are cases that do need it. Here's an example fromgen_tcg.h#define fGEN_TCG_L2_loadrub_pr(SHORTCODE) SHORTCODEThis is explained in the README, but basically the argument is useful if we can properly define the macros that it contains to generate TCG.
We're certainly not going to be able to handle e.g. "+" or "if", so it is going to work only for the most trivial of SHORTCODE.
Though in fact loadrub_pr makes that grade...
Quoted 4 lines
IMO, we don't want the person who writes an override having to reproduce the generated code. Assuming we have a definition of
fGEN_TCG_A2_addand we have the generator intelligently expanding the macros, this is what will be generated.
You need to give me a better example that A2_add, then. Because I see that being exactly one line, calling a helper that handles all instructions of the same format, passing tcg_gen_add_tl as a callback.
Have a browse through my recent microblaze decodetree conversion. Note that the basic logical operations are implemented with exactly one source line.
Quoted 9 lines
Unlike the generate_<tag> functions that all have the same signature. The overrides would have different signatures. This would be more defensive programming because you know exactly where the variables come from but more verbose when writing the overrides by hand. Also, note that these need to be macros in order to take advantage of the SHORTCODE.
In other words, instead of
#definefGEN_TCG_A2_add(SHORTCODE)tcg_gen_add_tl(RdV, RsV, RtV)We would write
#definefGEN_TCG_A2_add(env, ctx, insn, pkt, RdV, RsV, RtV, SHORTCODE)tcg_gen_add_tl(RdV, RsV, RtV);Personally, I prefer the former, but will change to the latter if you feel strongly.
This comes from trying to handle instructions in different ways, but represent them all the same.
I guess I see the attraction of the magic non-parameters -- you get a compilation error if the variable is not present, but are not tied to positional parameters.
Ho hum. Maybe I'm trying to overthink this too much before tackling the ultimate goal of full parsing of the SHORTCODE.
Perhaps the only thing for the short term is to have the generator grep genptr.c for "#define fGEN", to choose between the two alternatives: inline generation or out-of-line helper generation.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 28 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 8:41 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 11 lines · Taylor Simpson
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 1:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 1 line
Quoted 1 line
The
fGEN_TCG_A2_addmacro does not require nor use that {...}argument.
Quoted 2 lines
The
fGEN_TCG_A2_addmacro does need that argument, but there arecases that
Quoted 8 lines
Quoted 4 lines
do need it. Here's an example from
gen_tcg.h#define fGEN_TCG_L2_loadrub_pr(SHORTCODE) SHORTCODEThis is explained in the README, but basically the argument is useful if we can properly define the macros that it contains to generate TCG.
We're certainly not going to be able to handle e.g. "+" or "if", so it is going to work only for the most trivial of SHORTCODE.
Though in fact
loadrub_prmakes that grade...
The prior version of this series included all the overrides I've written to date. To reduce the size of this version, I removed most of them and only left the ones that are essential for correct execution. I plan to submit the others in subsequent series. Anyway, there are >50 overrides of load/store instructions that leverage SHORTCODE.
Quoted 9 lines
Quoted 1 line
IMO, we don't want the person who writes an override having to
reproduce the
Quoted 1 line
generated code. Assuming we have a definition of
fGEN_TCG_A2_addandwe
Quoted 2 lines
have the generator intelligently expanding the macros, this is what will be generated.
You need to give me a better example that
A2_add, then. Because I see that being exactly one line, calling a helper that handles all instructions of the same format, passingtcg_gen_add_tlas a callback.
Here's a more complicated example for a predicated post-increment load
Static void generate_L2_ploadrit_pi(CPUHexagonState *env, DisasContext*cts, insn_t *insn, packet_t *pkt) {
/* L2_ploadrit_pi */
TCGv EA = tcg_temp_local_new();
int PtN = insn->regno[0];
TCGv PtV = hex_pred[PtN];
int RdN = insn->regno[1];
TCGv RdV = tcg_temp_local_new();
if (!is_preloaded(ctx, RdN)) {
tcg_gen_mov_tl(hex_hew_value[RdN], hex_gpr[RdN]);
}
int RxN = insn->regno[2];
TCGv RxV = tcg_temp_local_new();
if (!is_preloaded(ctx, RxN)) {
tcg_gen_mov_tl(hex_new_value[RdN], hex_gpr[RxN]);
}int siV = insn->immed[0];tcg_gen_mov_tl(RxV, hex_gpr[RxN]);fGEN_TCG_L2_ploadrit_pi({fEA_REG(RxV); if(fLSBOLD(PtV)){ fPM_I(RxV,siV); fLOAD(1,4,u,EA,RdV);} else {LOAD_CANCEL(EA);}}); gen_log_reg_write(RdN, RdV, insn->slot, 1);gen_log_reg_write(RxN, RxV, insn->slot, 1);tcg_temp_free(EA);tcg_temp_free(RdV);tcg_temp_free(RxV);
/* L2_ploadrit_pi */
}
Quoted 3 lines
Have a browse through my recent microblaze decodetree conversion. Note that
the basic logical operations are implemented with exactly one source line.
With a helper function, our compares are all one line also
static inline void gen_compare(TCGCond cond, TCGv res, TCGv arg1, TCGv arg2)
{
TCGv one = tcg_const_tl(0xff);
TCGv zero = tcg_const_tl(0);
tcg_gen_movcond_tl(cond, res, arg1, arg2, one, zero);
tcg_temp_free(one);
tcg_temp_free(zero);
}/* Compare instructions */
#define fGEN_TCG_C2_cmpeq(SHORTCODE) \
gen_compare(TCG_COND_EQ, PdV, RsV, RtV)
#define fGEN_TCG_C4_cmpneq(SHORTCODE) \
gen_compare(TCG_COND_NE, PdV, RsV, RtV)
#define fGEN_TCG_C2_cmpgt(SHORTCODE) \
gen_compare(TCG_COND_GT, PdV, RsV, RtV)
#define fGEN_TCG_C2_cmpgtu(SHORTCODE) \
gen_compare(TCG_COND_GTU, PdV, RsV, RtV)
...
Quoted 20 lines
Quoted 1 line
Unlike the generate_<tag> functions that all have the same signature. The
overrides would have different signatures. This would be more defensive programming because you know exactly where the variables come from but more verbose when writing the overrides by hand. Also, note that these need to be macros in order to take advantage of the SHORTCODE.
Quoted 6 lines
In other words, instead of
#definefGEN_TCG_A2_add(SHORTCODE)tcg_gen_add_tl(RdV, RsV, RtV)We would write
#define fGEN_TCG_A2_add(env, ctx, insn, pkt, RdV, RsV, RtV,SHORTCODE)
tcg_gen_add_tl(RdV, RsV, RtV);Quoted 2 lines
Personally, I prefer the former, but will change to the latter if you feel
strongly.
This comes from trying to handle instructions in different ways, but represent
them all the same.
Quoted 6 lines
I guess I see the attraction of the magic non-parameters -- you get a compilation error if the variable is not present, but are not tied to positional parameters.
Ho hum. Maybe I'm trying to overthink this too much before tackling the ultimate goal of full parsing of the SHORTCODE.
Alessandro ([email protected]) and Niccolo ([email protected]) are working on this 😊
Quoted 3 lines
Perhaps the only thing for the short term is to have the generator grep
genptr.cfor "#define fGEN", to choose between the two alternatives: inline generation or out-of-line helper generation.
That's certainly doable. It will also be good to implement some of your other ideas
- Have the generator expand the DECL/READ/WRITE/FREE macros will make the generated code more readable and we can specialize them for predicated vs non-predicated instructions which will make translation faster.
- Generate the entire generate_<tag> function instead of just the body will make the generated code more readable.
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 21 lines
Quoted 14 lines · Taylor Simpson
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 1:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 4 lines
Ho hum. Maybe I'm trying to overthink this too much before tackling the ultimate goal of full parsing of the SHORTCODE.
Perhaps the only thing for the short term is to have the generator grepgenptr.cfor "#define fGEN", to choose between the two alternatives:inline
Quoted 1 line
generation or out-of-line helper generation.
Quoted 7 lines
That's certainly doable. It will also be good to implement some of your other ideas
- Have the generator expand the DECL/READ/WRITE/FREE macros will make the generated code more readable and we can specialize them for predicated vs non-predicated instructions which will make translation faster.
- Generate the entire generate_<tag> function instead of just the body will make the generated code more readable.
I've made these changes to the generator. I hope you like the results. As an example, here is what we generate for the add instruction
DEF_TCG_FUNC(A2_add,
static void generate_A2_add(
CPUHexagonState *env,
DisasContext *ctx,
insn_t *insn,
packet_t *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);
})And here is how the generated file gets used in genptr.c
#define DEF_TCG_FUNC(TAG, GENFN) \
GENFN
#include "tcg_funcs_generated.h"
#undef DEF_TCG_FUNC
/*
* Not all opcodes have generate_<tag> functions, so initialize
* the table from the tcg_funcs_generated.h file.
*/
const semantic_insn_t opcode_genptr[XX_LAST_OPCODE] = {
#define DEF_TCG_FUNC(TAG, GENFN) \
[TAG] = generate_##TAG,#include "tcg_funcs_generated.h"
#undef DEF_TCG_FUNC
};
I've also addressed several of the items from Richard's review, so I'll resubmit the series once I figure out how to get "make check-tcg" working under meson.
Thanks,
Taylor
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 37 lines · Taylor Simpson
Quoted 21 lines
Quoted 14 lines · Taylor Simpson
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 1:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 4 lines
Ho hum. Maybe I'm trying to overthink this too much before tackling the ultimate goal of full parsing of the SHORTCODE.
Perhaps the only thing for the short term is to have the generator grepgenptr.cfor "#define fGEN", to choose between the two alternatives:inline
Quoted 1 line
generation or out-of-line helper generation.
Quoted 7 lines
That's certainly doable. It will also be good to implement some of your other ideas
- Have the generator expand the DECL/READ/WRITE/FREE macros will make the generated code more readable and we can specialize them for predicated vs non-predicated instructions which will make translation faster.
- Generate the entire generate_<tag> function instead of just the body will make the generated code more readable.I've made these changes to the generator. I hope you like the results. As an example, here is what we generate for the add instruction
DEF_TCG_FUNC(A2_add,
static void generate_A2_add(
CPUHexagonState *env,
DisasContext *ctx,
insn_t*insn,
packet_t*pkt)
Quoted 10 lines
{
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);
})I would be happier if the entire function body were not in a macro. Have you tried to set a gdb breakpoint in one of these? Once upon a time at least, this would have resulted in all lines of the function becoming one "source line" in the debug info.
I also think the full function prototype is unnecessary, and the replication of "A2_add" undesirable.
I would prefer the function prototype itself to be macro-ized.
E.g.
DEF_TCG_FUNC(A2_add)
{
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);
}with
#define DEF_TCG_FUNC(TAG) \
static void generate_##TAG(CPUHexagonState *env, \
DisasContext *ctx, \
insn_t *insn, \ packet_t *pkt)
Quoted 12 lines
And here is how the generated file gets used in
genptr.c#define
DEF_TCG_FUNC(TAG, GENFN)\
GENFN
#include "tcg_funcs_generated.h"
#undefDEF_TCG_FUNC/*
* Not all opcodes have generate_<tag> functions, so initialize
* the table from thetcg_funcs_generated.hfile.
*/
constsemantic_insn_topcode_genptr[XX_LAST_OPCODE] = {
Quoted 5 lines
#define DEF_TCG_FUNC(TAG, GENFN) \ [TAG] = generate_##TAG,#include "
tcg_funcs_generated.h"
#undefDEF_TCG_FUNC
};
Obviously, the macro I propose above cannot be directly reused, as you do here.
But I also think we should not try to do so.
You've got a script generating stuff. It can just as easily generate two different lists. You're trying to do too much with the C preprocessor and too little with python.
At some point in the v3 thread, I had suggested grepping for some macro in order to indicate to the python script which tags are implemented manually. My definition above is easy to look for: exactly one thing on the line, easy regexp.
Quoted 1 line
I've also addressed several of the items from Richard's review, so I'll resubmit the series once I figure out how to get "make check-tcg" working under meson.
Yes, make check-tcg is currently broken, as are a few other check-foo. I've not yet had the courage to look into it, hoping that someone else will do it first.
r~
RE: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 32 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, September 24, 2020 9:04 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitionsQuoted 2 lines
I've made these changes to the generator. I hope you like the results. As
an example, here is what we generate for the add instruction
Quoted 7 lines
DEF_TCG_FUNC(A2_add,
static void generate_A2_add(
CPUHexagonState *env,
DisasContext *ctx,
insn_t*insn,
packet_t*pkt)Quoted 10 lines
{ 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); })
Quoted 4 lines
I would be happier if the entire function body were not in a macro. Have you tried to set a gdb breakpoint in one of these? Once upon a time at least, this would have resulted in all lines of the function becoming one "source line" in the debug info.
Good point. It still comes out as a single line.
Quoted 45 lines
I also think the full function prototype is unnecessary, and the replication of "
A2_add" undesirable.I would prefer the function prototype itself to be macro-ized.
E.g.
DEF_TCG_FUNC(A2_add){ 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); }with
#define DEF_TCG_FUNC(TAG) \ static void generate_##TAG(CPUHexagonState *env, \ DisasContext *ctx, \ insn_t *insn, \
packet_t*pkt)Quoted 12 lines
And here is how the generated file gets used in
genptr.c#define
DEF_TCG_FUNC(TAG, GENFN)\
GENFN
#include "tcg_funcs_generated.h"
#undefDEF_TCG_FUNC/*
* Not all opcodes have generate_<tag> functions, so initialize
* the table from thetcg_funcs_generated.hfile.
*/
constsemantic_insn_topcode_genptr[XX_LAST_OPCODE] = {Quoted 5 lines
#define DEF_TCG_FUNC(TAG, GENFN) \ [TAG] = generate_##TAG,#include "
tcg_funcs_generated.h"
#undefDEF_TCG_FUNC
};
Quoted 7 lines
Obviously, the macro I propose above cannot be directly reused, as you do here.
But I also think we should not try to do so.You've got a script generating stuff. It can just as easily generate two different lists. You're trying to do too much with the C preprocessor and too little with python.
Sure, generating two lists was also suggested by Alessandro ([email protected]). Although doing more in python and less with the C preprocessor would lead to the conclusion we shouldn't define the function prototype in a macro. If we generate two lists, what is the advantage of putting the function signature in a macro vs generating?
Quoted 6 lines
At some point in the v3 thread, I had suggested grepping for some macro in order to indicate to the python script which tags are implemented manually. My
definition above is easy to look for: exactly one thing on the line, easy regexp.
This is already done as well. As you may recall, we were previously generating
#ifdef fGEN_TCG_A2_add
fGEN_TCG_A2_add({ RdV=RsV+RtV;});
#else
do {
gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
} while (0);The generator now searches for "#define fGEN_TCG_<tag>" and generates different code depending on what it finds. This version of the series only contains overrides that are required for correct execution. So, A2_add isn't there. When we do override it, the generator produces this
static void generate_A2_add(
CPUHexagonState *env,
DisasContext *ctx,
insn_t *insn,
packet_t *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]];
fGEN_TCG_A2_add({ RdV=RsV+RtV;}); <---- This line is different
gen_log_reg_write(RdN, RdV);
ctx_log_reg_write(ctx, RdN);
tcg_temp_free(RdV);
}Also, if it finds the override, it doesn't generate the DEF_HELPER or the helper function. That means we don't include tcg_gen.h in helper.h as you suggested.
Thanks,
Taylor
Re: [RFC PATCH v3 30/34] Hexagon (target/hexagon) TCG for instructions with multiple definitions
Quoted 5 lines · Taylor Simpson
Quoted 3 lines
You've got a script generating stuff. It can just as easily generate two different lists. You're trying to do too much with the C preprocessor and too little with python.
Sure, generating two lists was also suggested by Alessandro ([email protected]). Although doing more in python and less with the C preprocessor would lead to the conclusion we shouldn't define the function prototype in a macro. If we generate two lists, what is the advantage of putting the function signature in a macro vs generating?
None, because...
Quoted 7 lines
Quoted 5 lines
At some point in the v3 thread, I had suggested grepping for some macro in order to indicate to the python script which tags are implemented manually. My
definition above is easy to look for: exactly one thing on the line, easy regexp.This is already done as well. As you may recall, we were previously generating
Quoted 8 lines
#ifdef fGEN_TCG_A2_add fGEN_TCG_A2_add({ RdV=RsV+RtV;}); #else do { gen_helper_A2_add(RdV, cpu_env, RsV, RtV); } while (0);The generator now searches for "#define fGEN_TCG_<tag>" ...
... I'd forgotten that they were two different macros.
Quoted 1 line
Also, if it finds the override, it doesn't generate the
DEF_HELPERor the helper function. That means we don't includetcg_gen.hinhelper.has you suggested.
Excellent.
r~
RFC PATCH v3 31/34 Hexagon (target/hexagon) translation
In reply to Taylor SimpsonRead 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 | 103 +++++++ target/hexagon/translate.c | 730 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 833 insertions(+) create mode 100644 target/hexagon/translate.h create mode 100644 target/hexagon/translate.c
target/hexagon/translate.h new file +103 -0
@@ -0,0 +1,103 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_TRANSLATE_H +#define HEXAGON_TRANSLATE_H + +#include "cpu.h" +#include "exec/translator.h" +#include "tcg/tcg-op.h" +#include "internal.h" + +typedef struct DisasContext { +DisasContextBase base; +uint32_t mem_idx; +int reg_log[REG_WRITES_MAX ]; +int reg_log_idx; +int preg_log[PRED_WRITES_MAX ]; +int preg_log_idx; +uint8_t store_width[STORES_MAX ]; +}DisasContext ; + +static inline void ctx_log_reg_write (DisasContext *ctx,int rnum) +{ +#if HEX_DEBUG +int i; +for (i =0 ; i < ctx->reg_log_idx; i++) { +if (ctx->reg_log[i] == rnum) { +HEX_DEBUG_LOG ("WARNING: Multiple writes to r%d\n" , rnum); + } + } +#endif + ctx->reg_log[ctx->reg_log_idx] = rnum; + ctx->reg_log_idx++; +} + +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) +{ +int i; +for (i =0 ; i < ctx->reg_log_idx; i++) { +if (ctx->reg_log[i] == num) { +return true; + } + } +return false; +} + +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; + +static inline void gen_slot_cancelled_check (TCGv check,int slot_num) +{ +TCGv mask =tcg_const_tl (1 << slot_num); +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_and_tl (mask, hex_slot_cancelled, mask); +tcg_gen_movcond_tl (TCG_COND_NE , check, mask, zero, one, zero); + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (mask); +} + +extern void gen_exception (int excp); +extern void gen_exception_debug (void ); + +#endif
target/hexagon/translate.c new file +730 -0
730 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 31/34] Hexagon (target/hexagon) translation
Quoted 58 lines · 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 packetSigned-off-by Taylor Simpson <[email protected]>--- target/hexagon/translate.h | 103 +++++++ target/hexagon/translate.c | 730 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 833 insertions(+) create mode 100644 target/hexagon/translate.h create mode 100644 target/hexagon/translate.ctarget/hexagon/translate.h new file +38
-0@@ -0,0 +1,103 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_TRANSLATE_H +#define HEXAGON_TRANSLATE_H + +#include "cpu.h" +#include "exec/translator.h" +#include "tcg/tcg-op.h" +#include "internal.h" + +typedef struct DisasContext { +DisasContextBase base; +uint32_t mem_idx; +int reg_log[REG_WRITES_MAX ]; +int reg_log_idx; +int preg_log[PRED_WRITES_MAX ]; +int preg_log_idx; +uint8_t store_width[STORES_MAX ]; +}DisasContext ; + +static inline void ctx_log_reg_write (DisasContext *ctx,int rnum) +{ +#if HEX_DEBUG
target/hexagon/translate.h line 48
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+int i; +for (i =0 ; i < ctx->reg_log_idx; i++) { +if (ctx->reg_log[i] == rnum) { +HEX_DEBUG_LOG ("WARNING: Multiple writes to r%d\n" , rnum); + } + } +#endif + ctx->reg_log[ctx->reg_log_idx] = rnum; + ctx->reg_log_idx++; +}
Why not just keep a bitmask of the rnum written?
Does the order of this log really matter?
target/hexagon/translate.h line 65
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+static inline bool is_preloaded (DisasContext *ctx,int num) +{ +int i; +for (i =0 ; i < ctx->reg_log_idx; i++) { +if (ctx->reg_log[i] == num) { +return true; + } + } +return false; +}
It would mean this one becomes constant time.
target/hexagon/translate.h line 93
Quoted 8 lines
target/hexagon/translate.h new file +8
-0+static inline void gen_slot_cancelled_check (TCGv check,int slot_num) +{ +TCGv mask =tcg_const_tl (1 << slot_num); +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_and_tl (mask, hex_slot_cancelled, mask); +tcg_gen_movcond_tl (TCG_COND_NE , check, mask, zero, one, zero);
This is a bit silly. Better as
tcg_gen_extract_i32(check, hex_slot_cancelled, slot_num, 1);
Quoted 25 lines
target/hexagon/translate.h new file +25
-0+static int read_packet_words (CPUHexagonState *env,DisasContext *ctx, +uint32_t words[]) +{ +bool found_end = false; +int max_words; +int nwords; +int i; + +/* Make sure we don't cross a page boundary */ + max_words = -(ctx->base.pc_next |TARGET_PAGE_MASK ) /sizeof (uint32_t ); +if (max_words <PACKET_WORDS_MAX ) { +/* Might cross a page boundary */ +if (ctx->base.num_insns ==1 ) { +/* OK if it's the first packet in the TB */ + max_words =PACKET_WORDS_MAX ; + } + }else { + max_words =PACKET_WORDS_MAX ; + } + +memset (words,0 ,PACKET_WORDS_MAX *sizeof (uint32_t )); +for (nwords =0 ; !found_end && nwords < max_words; nwords++) { + words[nwords] =cpu_ldl_code (env, + ctx->base.pc_next + nwords *sizeof (uint32_t )); + found_end =is_packet_end (words[nwords]);
target/hexagon/translate.h line 101
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+ } +if (!found_end) { +if (nwords ==PACKET_WORDS_MAX ) { +/* Read too many words without finding the end */ +gen_exception (HEX_EXCP_INVALID_PACKET ); + ctx->base.is_jmp =DISAS_NORETURN ; +return 0 ; + } +/* Crosses page boundary - defer to next TB */ + ctx->base.is_jmp =DISAS_TOO_MANY ;
The problem with this is that the translator has asked for the next insn, and you havn't provided it.
One way to fix this might be to decrement ctx->base.num_insns, to compensate for the increment that *will* happen after you return.
Another way, which involves less poking about into internals is to look for the next packet once you've completed the current packet. This is what Arm does for thumb2 insns:
Quoted 6 lines
if (dc->base.is_jmp == DISAS_NEXT
&& (dc->base.pc_next - dc->page_start >= TARGET_PAGE_SIZE
|| (dc->base.pc_next - dc->page_start >= TARGET_PAGE_SIZE - 3
&& insn_crosses_page(env, dc)))) {
dc->base.is_jmp = DISAS_TOO_MANY;
}I.e. you only have to do this for the few packets that are near enough to the end of the page that PACKET_WORDS_MAX crosses.
target/hexagon/translate.h
Quoted 8 lines
target/hexagon/translate.h new file +8
-0+tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->base.pc_next); +tcg_gen_movi_tl (hex_slot_cancelled,0 ); +if (pkt->pkt_has_cof) { +tcg_gen_movi_tl (hex_branch_taken,0 ); +tcg_gen_movi_tl (hex_next_PC, next_PC); + } +tcg_gen_movi_tl (hex_pred_written,0 ); +}
Surely you don't need to actually set PC for every PC?
Nor set hex_slot_cancelled if the packet contains nothing that can cancel anything. Nor set hex_pred_written if no predicates are written.
target/hexagon/translate.h
Quoted 6 lines
target/hexagon/translate.h new file +6
-0+TCGv cancelled =tcg_temp_local_new (); +TCGLabel *label_end =gen_new_label (); + +/* Don't do anything if the slot was cancelled */ +gen_slot_cancelled_check (cancelled, slot_num); +tcg_gen_brcondi_tl (TCG_COND_NE , cancelled,0 , label_end);
cancelled does not need to be local; it is consumed by the branch and not consumed afterward. Just free it here.
target/hexagon/translate.h
Quoted 8 lines
target/hexagon/translate.h new file +8
-0+/* +* If we know the width from the DisasContext, we can +* generate much cleaner code. +* Unfortunately, not all instructions execute the fSTORE +* macro during code generation. Anything that uses the +* generic helper will have this problem. Instructions +* that use fWRAP to generate proper TCG code will be OK. +*/
OMG. How disgusting.
target/hexagon/translate.h
Quoted 4 lines
target/hexagon/translate.h new file +4
-0+ value =tcg_temp_new (); +tcg_gen_mov_tl (value, hex_store_val32[slot_num]); +tcg_gen_qemu_st8 (value, address, ctx->mem_idx); +tcg_temp_free (value);
Why are you copying to a temporary?
target/hexagon/translate.h
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+default : +/* +* If we get to here, we don't know the width at +* TCG generation time, we'll generate branching +* based on the width at runtime. +*/ + label_w2 =gen_new_label (); + label_w4 =gen_new_label (); + label_w8 =gen_new_label (); +TCGv width =tcg_temp_local_new ();
You might as well make this a helper. This is going to generate a *lot* of code.
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+static void gen_exec_counters (packet_t *pkt) +{ +int num_insns = pkt->num_insns; +int num_real_insns =0 ; +int i; + +for (i =0 ; i < num_insns; i++) { +if (!pkt->insn[i].is_endloop && + !pkt->insn[i].part1 && + !GET_ATTRIB (pkt->insn[i].opcode,A_IT_NOP )) {
target/hexagon/translate.h
Quoted 10 lines
target/hexagon/translate.h new file +10
-0+ num_real_insns++; + } + } + +tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_PKT_CNT ], + hex_gpr[HEX_REG_QEMU_PKT_CNT ],1 ); +if (num_real_insns) { +tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_INSN_CNT ], + hex_gpr[HEX_REG_QEMU_INSN_CNT ], num_real_insns); + }
tcg_gen_addi_tl will check for the immediate == 0.
As with updating PC for every insn, this is going to be expensive.
You could accumulate these values through the TB and then update them at the end. You'd need to store the intermediate values in the space managed by TARGET_INSN_START_EXTRA_WORDS, so that you can update them on any exceptional path out of the TB, in restore_state_to_opc().
target/hexagon/translate.h
Quoted 2 lines
target/hexagon/translate.h new file +2
-0+if (end_tb) { +tcg_gen_exit_tb (NULL ,0 );
This misses out on ctx->base.singlestep_enabled, and almost certainly belongs in hexagon_tr_tb_stop. Use
#define DISAS_EXIT DISAS_TARGET_0
or some other appropriate naming.
r~
RE: [RFC PATCH v3 31/34] Hexagon (target/hexagon) translation
Quoted 10 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 8:50 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 31/34] Hexagon (target/hexagon) translation
Quoted 16 lines
target/hexagon/translate.h line 48
Quoted 13 lines
target/hexagon/translate.h new file +13
-0+static inline void ctx_log_reg_write (DisasContext *ctx,int rnum) +{ +#if HEX_DEBUG +int i; +for (i =0 ; i < ctx->reg_log_idx; i++) { +if (ctx->reg_log[i] == rnum) { +HEX_DEBUG_LOG ("WARNING: Multiple writes to r%d\n" , rnum); + } + } +#endif + ctx->reg_log[ctx->reg_log_idx] = rnum; + ctx->reg_log_idx++; +}Why not just keep a bitmask of the rnum written?
Does the order of this log really matter?
OK
Quoted 11 lines
target/hexagon/translate.h line 93
Quoted 8 lines
target/hexagon/translate.h new file +8
-0+static inline void gen_slot_cancelled_check (TCGv check,int slot_num) +{ +TCGv mask =tcg_const_tl (1 << slot_num); +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_and_tl (mask, hex_slot_cancelled, mask); +tcg_gen_movcond_tl (TCG_COND_NE , check, mask, zero, one, zero);This is a bit silly. Better as
Quoted 1 line
tcg_gen_extract_i32(check, hex_slot_cancelled, slot_num, 1);
OK
Quoted 56 lines
target/hexagon/translate.c
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 max_words; +int nwords; +int i; + +/* Make sure we don't cross a page boundary */ + max_words = -(ctx->base.pc_next | TARGET_PAGE_MASK) /
sizeof(uint32_t);Quoted 15 lines
target/hexagon/translate.c new file +15
-0+if (max_words <PACKET_WORDS_MAX ) { +/* Might cross a page boundary */ +if (ctx->base.num_insns ==1 ) { +/* OK if it's the first packet in the TB */ + max_words =PACKET_WORDS_MAX ; + } + }else { + max_words =PACKET_WORDS_MAX ; + } + +memset (words,0 ,PACKET_WORDS_MAX *sizeof (uint32_t )); +for (nwords =0 ; !found_end && nwords < max_words; nwords++) { + words[nwords] =cpu_ldl_code (env, + ctx->base.pc_next + nwords *sizeof (uint32_t )); + found_end =is_packet_end (words[nwords]);target/hexagon/translate.c line 116
Quoted 10 lines
target/hexagon/translate.c new file +10
-0+ } +if (!found_end) { +if (nwords ==PACKET_WORDS_MAX ) { +/* Read too many words without finding the end */ +gen_exception (HEX_EXCP_INVALID_PACKET ); + ctx->base.is_jmp =DISAS_NORETURN ; +return 0 ; + } +/* Crosses page boundary - defer to next TB */ + ctx->base.is_jmp =DISAS_TOO_MANY ;The problem with this is that the translator has asked for the next insn, and you havn't provided it.
One way to fix this might be to decrement
ctx->base.num_insns, to compensate
for the increment that *will* happen after you return.Another way, which involves less poking about into internals is to look for the next packet once you've completed the current packet. This is what Arm does
for thumb2 insns:Quoted 6 lines
if (dc->base.is_jmp == DISAS_NEXT && (dc->base.pc_next - dc->page_start >= TARGET_PAGE_SIZE || (dc->base.pc_next - dc->page_start >= TARGET_PAGE_SIZE - 3 && insn_crosses_page(env, dc)))) { dc->base.is_jmp = DISAS_TOO_MANY; }
Quoted 2 lines
I.e. you only have to do this for the few packets that are near enough to the end of the page that
PACKET_WORDS_MAXcrosses.
I'm actually checking two conditions here.
1) packet crossing a page boundary
2) reading too many words without finding the end of the packet. I guess it would be better to separate them.
What is the correct behavior for the second case? Should we return an error code from here and have the higher level code generate the invalid packet exception?
Quoted 10 lines
target/hexagon/translate.c line 157
Quoted 8 lines
target/hexagon/translate.c new file +8
-0+tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->base.pc_next); +tcg_gen_movi_tl (hex_slot_cancelled,0 ); +if (pkt->pkt_has_cof) { +tcg_gen_movi_tl (hex_branch_taken,0 ); +tcg_gen_movi_tl (hex_next_PC, next_PC); + } +tcg_gen_movi_tl (hex_pred_written,0 ); +}Surely you don't need to actually set PC for every PC?
What do other targets do?
Quoted 2 lines
Nor set
hex_slot_cancelledif the packet contains nothing that can cancel anything. Nor sethex_pred_writtenif no predicates are written.
Checking for instructions that can cancel is pretty straightforward because we have the CONDEXEC attribute. Checking if any predicates are written will be more complex. I'll scratch my head and figure out the cleanest way to do this.
Quoted 10 lines
target/hexagon/translate.c line 297
Quoted 7 lines
target/hexagon/translate.c new file +6
-0+TCGv cancelled =tcg_temp_local_new (); +TCGLabel *label_end =gen_new_label (); + +/* Don't do anything if the slot was cancelled */ +gen_slot_cancelled_check (cancelled, slot_num); +tcg_gen_brcondi_tl (TCG_COND_NE , cancelled,0 , label_end);cancelled does not need to be local; it is consumed by the branch and not consumed afterward. Just free it here.
OK
Quoted 10 lines
target/hexagon/translate.c line 310
Quoted 8 lines
target/hexagon/translate.c new file +8
-0+/* +* If we know the width from the DisasContext, we can +* generate much cleaner code. +* Unfortunately, not all instructions execute the fSTORE +* macro during code generation. Anything that uses the +* generic helper will have this problem. Instructions +* that use fWRAP to generate proper TCG code will be OK. +*/ OMG. How disgusting.
The word "generic" is a typo - should be "generated". In order to keep this series small, we're only overriding the helper for the minimal number of instructions. Over time, we'll override all the stores and we can eliminate this.
Quoted 6 lines
target/hexagon/translate.c line 322
Quoted 4 lines
target/hexagon/translate.c new file +4
-0+ value =tcg_temp_new (); +tcg_gen_mov_tl (value, hex_store_val32[slot_num]); +tcg_gen_qemu_st8 (value, address, ctx->mem_idx); +tcg_temp_free (value);Why are you copying to a temporary?
Will fix.
Quoted 11 lines
target/hexagon/translate.c line 354
Quoted 10 lines
target/hexagon/translate.c new file +10
-0+default : +/* +* If we get to here, we don't know the width at +* TCG generation time, we'll generate branching +* based on the width at runtime. +*/ + label_w2 =gen_new_label (); + label_w4 =gen_new_label (); + label_w8 =gen_new_label (); +TCGv width =tcg_temp_local_new ();
Quoted 2 lines
You might as well make this a helper. This is going to generate a *lot* of code.
This is the part that will go away when we override all the stores.
Quoted 14 lines
Quoted 14 lines
target/hexagon/translate.c new file +14
-0+static void gen_exec_counters (packet_t *pkt) +{ +int num_insns = pkt->num_insns; +int num_real_insns =0 ; +int i; + +for (i =0 ; i < num_insns; i++) { +if (!pkt->insn[i].is_endloop && + !pkt->insn[i].part1 && + !GET_ATTRIB (pkt->insn[i].opcode,A_IT_NOP )) { + num_real_insns++; + } + } +
Quoted 8 lines
target/hexagon/translate.c line 470
Quoted 6 lines
target/hexagon/translate.c new file +6
-0+tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_PKT_CNT ], + hex_gpr[HEX_REG_QEMU_PKT_CNT ],1 ); +if (num_real_insns) { +tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_INSN_CNT ], + hex_gpr[HEX_REG_QEMU_INSN_CNT ], num_real_insns); + }
tcg_gen_addi_tlwill check for the immediate == 0.
OK, great. I also see that tcg_gen_mov_i32 will check that the source and dest are different. So no TCG code will be generated.
Quoted 8 lines
As with updating PC for every insn, this is going to be expensive.
You could accumulate these values through the TB and then update them at the
end. You'd need to store the intermediate values in the space managed byTARGET_INSN_START_EXTRA_WORDS, so that you can update them on any exceptional
path out of the TB, inrestore_state_to_opc().
OK
Quoted 10 lines
target/hexagon/translate.c line 499
Quoted 2 lines
target/hexagon/translate.c new file +2
-0+if (end_tb) { +tcg_gen_exit_tb (NULL ,0 );This misses out on
ctx->base.singlestep_enabled, and almost certainly belongs
inhexagon_tr_tb_stop. Use#define
DISAS_EXITDISAS_TARGET_0or some other appropriate naming.
OK
Re: [RFC PATCH v3 31/34] Hexagon (target/hexagon) translation
Quoted 6 lines · Taylor Simpson
I'm actually checking two conditions here.
1) packet crossing a page boundary
2) reading too many words without finding the end of the packet. I guess it would be better to separate them.What is the correct behavior for the second case? Should we return an error code from here and have the higher level code generate the invalid packet exception?
I would return an error code.
In fact, I would also pass in the max number of words to read:
static int read_packet_words(CPUHexagonState *env,
DisasContext *ctx, uint32_t words[PACKET_WORDS_MAX], int max_words)
{
// stuff
return !found_end ? 0 : nwords;
}
Then, in translate_packet,
uint32_t words[PACKET_WORDS_MAX];
int nwords = read_packet_words(env, ctx, words,
PACKET_WORDS_MAX);
if (nwords == 0) {
// raise exception
return;
}
decode_and_translate_packet(env, ctx, words, nwords);
/* If we're going to try for another packet... */
if (ctx->base.is_jmp == DISAS_NEXT &&
ctx->base.num_insns < ctx->base.num_insns) {
/*
* Remember the end of the page containing the
* first packet. Note that the first packet
* is allowed to span two pages, so this is not
* necessarily the same as the end of the page
* containing ctx->base.pc_start.
*/
if (ctx->base.num_insns == 1) {
ctx->page_end
= TARGET_PAGE_ALIGN(ctx->base.pc_next);
}
/*
* If there are not PACKET_WORDS_MAX remaining on
* the page, check to see if a full packet remains.
* If not, split the TB so that the packet that
* crosses the page begins the next TB.
*/
target_long left = ctx->page_end - ctx->base.pc_next;
tcg_debug_assert(left >= 0);
if (left == 0
|| (left < PACKET_WORDS_MAX * 4 &&
!read_packet_words(env, ctx, words, left / 4)) {
ctx->base.is_jmp = DISAS_TOO_MANY;
}
}The reason for all this is to properly capture the behaviour of instruction execution vs SIGSEGV.
First, during translate we do not want to read from the next page unless absolutely necessary. Doing so could raise SIGSEGV before it would be appropriate, e.g. because the TB should have branched away (or raised SIGFPE, or anything else) before getting that far.
Second, when dispatching a TB, we check the 1 or 2 pages that the TB occupies for validity. If the second page is invalid, we raise SIGSEGV without executing the TB at all. Which makes it appear as if the SIGSEGV happened at the first insn of the TB. Which is correct if and only if the first insn is the one that did cross the page.
Quoted 3 lines
Quoted 1 line
Surely you don't need to actually set PC for every PC?
What do other targets do?
If you have a pc-relative instruction, e.g. x86_64's
lea offset(%rip), %rax
then you just use the known immediate for %rip:
tcg_gen_movi_tl(cpu_reg[eax], ctx->base.pc_next + offset);
Normally, PC is only valid when explicitly returning to the cpu loop (tcg_gen_exit_tb, static exception), for indirect branching (tcg_gen_lookup_and_goto_ptr), or after dynamic exception unwinding (restore_state_to_opc).
When using goto_tb, we can get away with *assuming* static state, because the values get baked into the link to a specific next-TB. That's why the general form is
tcg_gen_goto_tb(n); gen_set_pc_im(s, dest); tcg_gen_exit_tb(s->base.tb, n);
The first time we cross link N, the link is unset, which causes the goto_tb to continue to the next tcg opcode. Which then sets all of the static state that has been assumed (often, as here, just the pc). We then exit, telling the cpu_loop to examine cpu state, locate the next TB, and fill in link N from the current TB.
The second time we cross link N, the link is set, which causes the goto_tb to continue immediately to the next TB. We do not execute the store to PC, as it is implied by next_tb->pc.
r~
RFC PATCH v3 32/34 Hexagon (linux-user/hexagon) Linux user emulation
In reply to Taylor SimpsonImplementation 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 | 343 ++++++++++++++++++++++++++++++++++++ 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 | 46 +++++ linux-user/hexagon/target_syscall.h | 32 ++++ linux-user/hexagon/termbits.h | 18 ++ linux-user/syscall_defs.h | 33 ++++ linux-user/elfload.c | 16 ++ linux-user/hexagon/cpu_loop.c | 99 +++++++++++ linux-user/hexagon/signal.c | 276 +++++++++++++++++++++++++++++ linux-user/syscall.c | 2 + scripts/gensyscalls.sh | 3 +- 15 files changed, 1021 insertions(+), 1 deletion(-) 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
@@ -0,0 +1,18 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../generic/sockbits.h"
linux-user/hexagon/syscall_nr.h new file +343 -0
343 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
@@ -0,0 +1,40 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_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
@@ -0,0 +1,18 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../generic/fcntl.h"
linux-user/hexagon/target_signal.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_TARGET_SIGNAL_H +#define HEXAGON_TARGET_SIGNAL_H + +typedef struct target_sigaltstack { +abi_ulong ss_sp; +abi_int ss_flags; +abi_ulong ss_size; +}target_stack_t ; + +#define TARGET_SS_ONSTACK 1 +#define TARGET_SS_DISABLE 2 + +#define TARGET_MINSIGSTKSZ 2048 + +#include "../generic/signal.h" + +#endif /* TARGET_SIGNAL_H */
linux-user/hexagon/target_structs.h new file +46 -0
46 lines not on this page · raw message
linux-user/hexagon/target_syscall.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_TARGET_SYSCALL_H +#define HEXAGON_TARGET_SYSCALL_H + +struct target_pt_regs { +abi_long sepc; +abi_long sp; +}; + +#define UNAME_MACHINE "hexagon" +#define UNAME_MINIMUM_RELEASE "4.15.0" + +#define TARGET_MLOCKALL_MCL_CURRENT 1 +#define TARGET_MLOCKALL_MCL_FUTURE 2 + +#endif
linux-user/hexagon/termbits.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright(c) 2019-2020 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../i386/termbits.h"
linux-user/syscall_defs.h +33 -0
@@ -102,6 +102,14 @@#define TARGET_IOC_WRITE 2U#define TARGET_IOC_READ 1U +#elif defined(TARGET_HEXAGON ) + +#define TARGET_IOC_SIZEBITS 14 + +#define TARGET_IOC_NONE 0U +#define TARGET_IOC_WRITE 1U +#define TARGET_IOC_READ 2U +#else #error unsupported CPU#endif
@@ -2136,6 +2144,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
@@ -1475,6 +1475,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 +99 -0
99 lines not on this page · raw message
linux-user/hexagon/signal.c new file +276 -0
276 lines not on this page · raw message
linux-user/syscall.c +2 -0
@@ -522,6 +522,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
scripts/gensyscalls.sh +2 -1
@@ -53,7 +53,7 @@ read_includes() filter_defines() { - grep -e "#define __NR_" -e "#define __NR3264" + grep -e "#define __NR_" -e "#define __NR3264" | grep -v __NR_syscalls } rename_defines()
@@ -99,4 +99,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
Re: [RFC PATCH v3 32/34] Hexagon (linux-user/hexagon) Linux user emulation
Quoted 5 lines · Taylor Simpson
Implementation of Linux user emulation for Hexagon
Some common files modified in addition to new files in linux-user/hexagonSigned-off-by Taylor Simpson <[email protected]>---
Looks plausible.
r~
RFC PATCH v3 33/34 Hexagon (tests/tcg/hexagon) TCG tests
In reply to Taylor SimpsonModify tests/tcg/configure.sh
Add reference files to tests/tcg/hexagon
Add Hexagon-specific tests
--- tests/tcg/hexagon/atomics.c | 122 ++++++ tests/tcg/hexagon/clrtnew.c | 56 +++ tests/tcg/hexagon/dual_stores.c | 60 +++ tests/tcg/hexagon/exec_counters.c | 57 +++ tests/tcg/hexagon/mem_noshuf.c | 291 ++++++++++++++ tests/tcg/hexagon/misc.c | 293 ++++++++++++++ tests/tcg/hexagon/preg_alias.c | 106 +++++ tests/tcg/hexagon/pthread_cancel.c | 43 +++ tests/tcg/hexagon/sfminmax.c | 62 +++ tests/tcg/configure.sh | 4 +- tests/tcg/hexagon/Makefile.target | 49 +++ tests/tcg/hexagon/first.S | 57 +++ tests/tcg/hexagon/float_convs.ref | 748 ++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/float_madds.ref | 768 +++++++++++++++++++++++++++++++++++++ 14 files changed, 2715 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/atomics.c create mode 100644 tests/tcg/hexagon/clrtnew.c create mode 100644 tests/tcg/hexagon/dual_stores.c create mode 100644 tests/tcg/hexagon/exec_counters.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/pthread_cancel.c create mode 100644 tests/tcg/hexagon/sfminmax.c 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
tests/tcg/hexagon/atomics.c new file +122 -0
@@ -0,0 +1,122 @@ +#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/clrtnew.c new file +56 -0
56 lines not on this page · raw message
tests/tcg/hexagon/dual_stores.c new file +60 -0
60 lines not on this page · raw message
tests/tcg/hexagon/exec_counters.c new file +57 -0
57 lines not on this page · raw message
tests/tcg/hexagon/mem_noshuf.c new file +291 -0
291 lines not on this page · raw message
tests/tcg/hexagon/misc.c new file +293 -0
293 lines not on this page · raw message
tests/tcg/hexagon/preg_alias.c new file +106 -0
106 lines not on this page · raw message
tests/tcg/hexagon/pthread_cancel.c new file +43 -0
43 lines not on this page · raw message
tests/tcg/hexagon/sfminmax.c new file +62 -0
62 lines not on this page · raw message
tests/tcg/configure.sh +3 -1
@@ -69,6 +69,8 @@ fi : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"} : ${cross_cc_x86_64="x86_64-pc-linux-gnu-gcc"} : ${cross_cc_cflags_x86_64="-m64"} +: ${cross_cc_hexagon="hexagon-linux-clang"} +: ${cross_cc_cflags_hexagon="-mv67 -O2 -Wno-incompatible-pointer-types"} for target in $target_list; do arch=${target%%-*}
@@ -94,7 +96,7 @@ for target in $target_list; do xtensa|xtensaeb) arches=xtensa ;; - alpha|cris|hppa|i386|lm32|m68k|openrisc|riscv64|s390x|sh4|sparc64) + alpha|cris|hppa|i386|lm32|m68k|openrisc|riscv64|s390x|sh4|sparc64|hexagon) arches=$target ;; *)
tests/tcg/hexagon/Makefile.target new file +49 -0
49 lines not on this page · raw message
tests/tcg/hexagon/first.S new file +57 -0
57 lines not on this page · raw message
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
Re: [RFC PATCH v3 33/34] Hexagon (tests/tcg/hexagon) TCG tests
Quoted 6 lines · Taylor Simpson
Modify
tests/tcg/configure.sh
Add reference files to tests/tcg/hexagon
Add Hexagon-specific testsSigned-off-by Taylor Simpson <[email protected]>---
Looks ok.
Could you please work with Alex Bennee to set up a tests/docker/dockerfile/ script containing the cross-compiler from the Qualcomm SDK? That way these tests can be run automatically.
Compare debian-xtensa-cross.docker, which is similar.
r~
Re: [RFC PATCH v3 33/34] Hexagon (tests/tcg/hexagon) TCG tests
Quoted 5 lines · On Fri, 28 Aug 2020 20:05:44 -0700 Richard Henderson…
Could you please work with Alex Bennee to set up a tests/docker/dockerfile/ script containing the cross-compiler from the Qualcomm SDK? That way these tests can be run automatically.
Compare debian-xtensa-cross.docker, which is similar.
We already have something similar, but it didn't make it in this patchset. We put an effort in putting together a fully open source toolchain.
It takes a while to build, but we'll provide a pre-built image on dockerhub.
Eventually, upstream LLVM and musl will be in sync and it will be no longer necessary to build it by hand.
Signature · 4 lines
Alessandro Di Federico rev.ng P.S. Richard: thanks a lot for the thorough reviews.
RFC PATCH v3 34/34 Hexagon build infrastructure
In reply to Taylor SimpsonAdd file to default-configs
Change configure
Add target/hexagon/Makefile.objs
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.
--- configure | 9 ++ default-configs/hexagon-linux-user.mak | 1 + scripts/qemu-binfmt-conf.sh | 6 +- target/hexagon/Makefile.objs | 203 +++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 default-configs/hexagon-linux-user.mak create mode 100644 target/hexagon/Makefile.objs
configure +9 -0
@@ -8275,6 +8275,12 @@ case "$target_name" in bflt="yes" mttcg="yes" ;; + hexagon) + TARGET_BASE_ARCH=hexagon + TARGET_ABI_DIR=hexagon + mttcg=yes + target_compiler=$cross_cc_hexagon + ;; *) error_exit "Unsupported target CPU" ;;
@@ -8447,6 +8453,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do xtensa*) disas_config "XTENSA" ;; + hexagon) + disas_config "HEXAGON" + ;; esac done if test "$tcg_interpreter" = "yes" ; then
default-configs/hexagon-linux-user.mak new file +1 -0
@@ -0,0 +1 @@ +# Default configuration for hexagon-linux-user
scripts/qemu-binfmt-conf.sh +5 -1
@@ -4,7 +4,7 @@ qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \ ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \ sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \ -microblaze microblazeel or1k x86_64" +microblaze microblazeel or1k x86_64 hexagon" i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
@@ -136,6 +136,10 @@ or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\ or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' or1k_family=or1k +hexagon_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xa4\x00' +hexagon_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +hexagon_family=hexagon + qemu_get_family() { cpu=${HOST_ARCH:-$(uname -m)} case "$cpu" in
target/hexagon/Makefile.objs new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH v3 34/34] Hexagon build infrastructure
Quoted 11 lines · Taylor Simpson
Add file to default-configs
Change configure
Add target/hexagon/Makefile.objs
Changescripts/qemu-binfmt-conf.shWe 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.
Signed-off-by Taylor Simpson <[email protected]>---
This will have to be updated for the meson conversion.
I don't understand it all myself, and all of those generated files will need special attention.
r~
RE: [RFC PATCH v3 34/34] Hexagon build infrastructure
Quoted 10 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 9:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 34/34] Hexagon build infrastructure
Quoted 5 lines
This will have to be updated for the meson conversion.
I don't understand it all myself, and all of those generated files will need special attention.
I've made the changes for meson, including converting target/hexagon/Makefile.objs to target/hexagon/meson.build, and I can build qemu-hexagon with
mkdir build
cd build
configure --target-list=hexagon-linux-user
makeHowever, when I run "make check-tcg", nothing actually happens.
BUILD TCG tests for hexagon-linux-user
Generating qemu-version.h with a meson_exe.py custom command
RUN TCG tests for hexagon-linux-user
What am I missing? Has some other command replaced "make check-tcg"?
Thanks,
Taylor
Re: [RFC PATCH v3 34/34] Hexagon build infrastructure
Hi Taylor,
Quoted 20 lines · Taylor Simpson
Quoted 8 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 9:20 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 34/34] Hexagon build infrastructureQuoted 5 lines
This will have to be updated for the meson conversion.
I don't understand it all myself, and all of those generated files will need special attention.
I've made the changes for meson, including converting target/hexagon/Makefile.objs to target/hexagon/meson.build, and I can build qemu-hexagon with
mkdir build cd build configure --target-list=hexagon-linux-user make
Quoted 6 lines
However, when I run "make check-tcg", nothing actually happens.
BUILD TCG tests for hexagon-linux-user
Generatingqemu-version.hwith ameson_exe.pycustom command
RUN TCG tests for hexagon-linux-userWhat am I missing? Has some other command replaced "make check-tcg"?
Maybe that patch from Paolo fixes it:
https://www.mail-archive.com/[email protected]/msg742912.html
Quoted 5 lines
Thanks,
Taylor
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: [RFC PATCH v3 00/34] 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]
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
149d5a8 Hexagon build infrastructure
4db60b1 Hexagon (tests/tcg/hexagon) TCG tests
3799611 Hexagon (linux-user/hexagon) Linux user emulation
a71a593 Hexagon (target/hexagon) translation
edab971 Hexagon (target/hexagon) TCG for instructions with multiple definitions e932b7e Hexagon (target/hexagon) TCG generation
77ada1d Hexagon (target/hexagon) TCG generation helpers
be70802 Hexagon (target/hexagon) instruction classes
33ce822 Hexagon (target/hexagon) macros referenced in instruction semantics f44d484 Hexagon (target/hexagon) macros to interface with the generator c4e4b84 Hexagon (target/hexagon) opcode data structures
64f25a3 Hexagon (target/hexagon) generater phase 4 - decode tree 799a8cb Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree fd0b8ef Hexagon (target/hexagon) generator phase 2 - generate header files 01ee39f Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics 56a8168 Hexagon (target/hexagon/imported) arch import - instruction encoding fe828ec Hexagon (target/hexagon/imported) arch import - instruction semantics 47fcbc9 Hexagon (target/hexagon/imported) arch import - macro definitions 032fa2d Hexagon (target/hexagon) utility functions
90e2392 Hexagon (target/hexagon) instruction printing
e4a75c2 Hexagon (target/hexagon) instruction/packet decode
720bbdf Hexagon (target/hexagon) register map
4a5c3d8 Hexagon (target/hexagon) instruction attributes
01bf963 Hexagon (target/hexagon) register fields
934c416 Hexagon (target/hexagon) instruction and packet types
e905475 Hexagon (target/hexagon) architecture types
e10c00c Hexagon (target/hexagon) GDB Stub
54222f4 Hexagon (target/hexagon) scalar core helpers
8c90070 Hexagon (disas) disassembler
fc17f04 Hexagon (target/hexagon) register names
87807c4 Hexagon (target/hexagon) scalar core definition
28282ee Hexagon (include/elf.h) ELF machine definition
acf59c5 Hexagon (target/hexagon) README
360594d Hexagon Update MAINTAINERS file
=== OUTPUT BEGIN ===
1/34 Checking commit 360594de302c (Hexagon Update MAINTAINERS file) 2/34 Checking commit acf59c5f8d57 (Hexagon (target/hexagon) README)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
total: 0 errors, 1 warnings, 254 lines checked
Patch 2/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/34 Checking commit 28282eeb25c8 (Hexagon (include/elf.h) ELF machine definition) 4/34 Checking commit 87807c4ee5ed (Hexagon (target/hexagon) scalar core definition)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
total: 0 errors, 1 warnings, 580 lines checked
Patch 4/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/34 Checking commit fc17f04e763d (Hexagon (target/hexagon) register names)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644
total: 0 errors, 1 warnings, 83 lines checked
Patch 5/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/34 Checking commit 8c900700b508 (Hexagon (disas) disassembler)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #26:
new file mode 100644
total: 0 errors, 1 warnings, 76 lines checked
Patch 6/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
7/34 Checking commit 54222f424b69 (Hexagon (target/hexagon) scalar core helpers)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644
total: 0 errors, 1 warnings, 401 lines checked
Patch 7/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/34 Checking commit e10c00cef005 (Hexagon (target/hexagon) GDB Stub)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #26:
new file mode 100644
total: 0 errors, 1 warnings, 63 lines checked
Patch 8/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
9/34 Checking commit e9054759731f (Hexagon (target/hexagon) architecture types)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
total: 0 errors, 1 warnings, 43 lines checked
Patch 9/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
10/34 Checking commit 934c416b066b (Hexagon (target/hexagon) instruction and packet types)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644
total: 0 errors, 1 warnings, 75 lines checked
Patch 10/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/34 Checking commit 01bf963045a8 (Hexagon (target/hexagon) register fields)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
ERROR: Macros with complex values should be enclosed in parenthesis #84: FILE: target/hexagon/reg_fields.h:33:
+#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \
+ TAG,
total: 1 errors, 1 warnings, 146 lines checked
Patch 11/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
12/34 Checking commit 4a5c3d8b0344 (Hexagon (target/hexagon) instruction attributes)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644
ERROR: Macros with complex values should be enclosed in parenthesis #37: FILE: target/hexagon/attribs.h:22:
+#define DEF_ATTRIB(NAME, ...) A_##NAME,
total: 1 errors, 1 warnings, 130 lines checked
Patch 12/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
13/34 Checking commit 720bbdf3c5d8 (Hexagon (target/hexagon) register map)
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 13/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
14/34 Checking commit e4a75c280804 (Hexagon (target/hexagon) instruction/packet decode)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #22:
new file mode 100644
ERROR: Macros with complex values should be enclosed in parenthesis #118: FILE: target/hexagon/decode.c:92:
+#define DECODE_SEPARATOR_BITS(START, WIDTH) NULL, START, WIDTH
ERROR: Macros with multiple statements should be enclosed in a do - while loop #721: FILE: target/hexagon/q6v_decode.c:51:
+#define DECODE_OPINFO(TAG, BEH) \
+ case TAG: \
+ { BEH } \
+ break; \
+
total: 2 errors, 1 warnings, 1005 lines checked
Patch 14/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
15/34 Checking commit 90e239256680 (Hexagon (target/hexagon) instruction printing)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644
ERROR: Macros with multiple statements should be enclosed in a do - while loop #61: FILE: target/hexagon/printinsn.c:46:
+#define DEF_PRINTINFO(TAG, FMT, ...) \
+ case TAG: \
+ snprintf(buf, n, FMT, __VA_ARGS__);\
+ break;
total: 1 errors, 1 warnings, 120 lines checked
Patch 15/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
16/34 Checking commit 032fa2d6f2f2 (Hexagon (target/hexagon) utility functions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
WARNING: Block comments use a leading /* on a separate line #1326: FILE: target/hexagon/fma_emu.c:470:
+ /* result zero */ \
WARNING: Block comments use a leading /* on a separate line #1334: FILE: target/hexagon/fma_emu.c:478:
+ /* Normalize right */ \
WARNING: Block comments use a leading /* on a separate line #1335: FILE: target/hexagon/fma_emu.c:479:
+ /* We want MANTBITS bits of mantissa plus the leading one. */ \
WARNING: Block comments use a leading /* on a separate line #1336: FILE: target/hexagon/fma_emu.c:480:
+ /* That means that we want MANTBITS+1 bits, or 0x000000000000FF_FFFF */ \
WARNING: Block comments use a leading /* on a separate line #1337: FILE: target/hexagon/fma_emu.c:481:
+ /* So we need to normalize right while the high word is non-zero and \
WARNING: Block comments should align the * on each line #1338: FILE: target/hexagon/fma_emu.c:482:
+ /* 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 #1342: FILE: target/hexagon/fma_emu.c:486:
+ /* \
WARNING: Block comments use a leading /* on a separate line #1352: FILE: target/hexagon/fma_emu.c:496:
+ /* \
WARNING: Block comments use a leading /* on a separate line #1359: FILE: target/hexagon/fma_emu.c:503:
+ /* \
WARNING: Block comments use a leading /* on a separate line #1368: FILE: target/hexagon/fma_emu.c:512:
+ /* OK, we're relatively canonical... now we need to round */ \
WARNING: Block comments use a leading /* on a separate line #1373: FILE: target/hexagon/fma_emu.c:517:
+ /* Chop and we're done */ \
WARNING: Block comments use a leading /* on a separate line #1387: FILE: target/hexagon/fma_emu.c:531:
+ /* round up if guard is 1, down if guard is zero */ \
WARNING: Block comments use a leading /* on a separate line #1390: FILE: target/hexagon/fma_emu.c:534:
+ /* exactly .5, round up if odd */ \
WARNING: Block comments use a leading /* on a separate line #1396: FILE: target/hexagon/fma_emu.c:540:
+ /* \
WARNING: Block comments use a leading /* on a separate line #1405: FILE: target/hexagon/fma_emu.c:549:
+ /* Overflow? */ \
WARNING: Block comments use a leading /* on a separate line #1407: FILE: target/hexagon/fma_emu.c:551:
+ /* Yep, inf result */ \
WARNING: Block comments use a leading /* on a separate line #1429: FILE: target/hexagon/fma_emu.c:573:
+ /* Underflow? */ \
WARNING: Block comments use a leading /* on a separate line #1431: FILE: target/hexagon/fma_emu.c:575:
+ /* Leading one means: No, we're normal. So, we should be done... */ \
total: 0 errors, 19 warnings, 1623 lines checked
Patch 16/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
17/34 Checking commit 47fcbc98752d (Hexagon (target/hexagon/imported) arch import - macro definitions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#15:
new file mode 100755
total: 0 errors, 1 warnings, 1529 lines checked
Patch 17/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
18/34 Checking commit fe828ec04435 (Hexagon (target/hexagon/imported) arch import - instruction semantics)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#19:
new file mode 100644
total: 0 errors, 1 warnings, 5337 lines checked
Patch 18/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
19/34 Checking commit 56a816808b60 (Hexagon (target/hexagon/imported) arch import - instruction encoding)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#14:
new file mode 100644
total: 0 errors, 1 warnings, 2385 lines checked
Patch 19/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
20/34 Checking commit 01ee39f0b141 (Hexagon (target/hexagon) generator phase 1 - C preprocessor for semantics)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#17:
new file mode 100644
ERROR: suspicious ; after while (0)
#82: FILE: target/hexagon/gen_semantics.c:61:
+ } while (0);
total: 1 errors, 1 warnings, 88 lines checked
Patch 20/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
21/34 Checking commit fd0b8efdcba8 (Hexagon (target/hexagon) generator phase 2 - generate header files)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#30:
new file mode 100755
total: 0 errors, 1 warnings, 1354 lines checked
Patch 21/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
22/34 Checking commit 799a8cb9426a (Hexagon (target/hexagon) generator phase 3 - C preprocessor for decode tree)
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 #76: FILE: target/hexagon/gen_dectree_import.c:57:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
ERROR: Macros with complex values should be enclosed in parenthesis #85: FILE: target/hexagon/gen_dectree_import.c:66:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
ERROR: suspicious ; after while (0)
#182: FILE: target/hexagon/gen_dectree_import.c:163:
+ } while (0);
total: 3 errors, 1 warnings, 191 lines checked
Patch 22/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
23/34 Checking commit 64f25a3e9492 (Hexagon (target/hexagon) generater phase 4 - decode tree)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#13:
new file mode 100755
total: 0 errors, 1 warnings, 352 lines checked
Patch 23/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
24/34 Checking commit c4e4b843d932 (Hexagon (target/hexagon) opcode data structures)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644
ERROR: Macros with complex values should be enclosed in parenthesis #56: FILE: target/hexagon/opcodes.c:41:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) REGINFO,
ERROR: Macros with complex values should be enclosed in parenthesis #66: FILE: target/hexagon/opcodes.c:51:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
ERROR: Macros with complex values should be enclosed in parenthesis #76: FILE: target/hexagon/opcodes.c:61:
+#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
ERROR: Macros with complex values should be enclosed in parenthesis #180: FILE: target/hexagon/opcodes.c:165:
+#define ATTRIBS(...) , ## __VA_ARGS__, 0
total: 4 errors, 1 warnings, 277 lines checked
Patch 24/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
25/34 Checking commit f44d4844c738 (Hexagon (target/hexagon) macros to interface with the generator)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#13:
new file mode 100644
total: 0 errors, 1 warnings, 364 lines checked
Patch 25/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
26/34 Checking commit 33ce822b03e9 (Hexagon (target/hexagon) macros referenced in instruction semantics) 27/34 Checking commit be70802f716c (Hexagon (target/hexagon) instruction classes)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#13:
new file mode 100644
ERROR: Macros with complex values should be enclosed in parenthesis #138: 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 #144: FILE: target/hexagon/iclass.h:33:
+#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) ICLASS_FROM_TYPE(TYPE),
total: 2 errors, 1 warnings, 186 lines checked
Patch 27/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
28/34 Checking commit 77ada1dc6124 (Hexagon (target/hexagon) TCG generation helpers)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644
total: 0 errors, 1 warnings, 268 lines checked
Patch 28/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
29/34 Checking commit e932b7e1745b (Hexagon (target/hexagon) TCG generation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
total: 0 errors, 1 warnings, 80 lines checked
Patch 29/34 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
30/34 Checking commit edab9714dc4f (Hexagon (target/hexagon) TCG for instructions with multiple definitions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#14:
new file mode 100644
total: 0 errors, 1 warnings, 213 lines checked
Patch 30/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
31/34 Checking commit a71a593d99c6 (Hexagon (target/hexagon) translation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #17:
new file mode 100644
total: 0 errors, 1 warnings, 833 lines checked
Patch 31/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
32/34 Checking commit 3799611b203f (Hexagon (linux-user/hexagon) Linux user emulation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #41:
new file mode 100644
total: 0 errors, 1 warnings, 1056 lines checked
Patch 32/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
33/34 Checking commit 4db60b131aa7 (Hexagon (tests/tcg/hexagon) TCG tests)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #37:
new file mode 100644
total: 0 errors, 1 warnings, 2728 lines checked
Patch 33/34 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
34/34 Checking commit 149d5a836f53 (Hexagon build infrastructure)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #47:
new file mode 100644
WARNING: line over 80 characters
#70: 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
#71: 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, 243 lines checked
Patch 34/34 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]
Quoted 9 lines · Taylor Simpson
This series adds support for the Hexagon processor with Linux user support
See patch 02/34 Hexagon README for detailed information.
Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.
We have a parallel effort to make the Hexagon Linux toolchain inside a docker container publically available.
Oh, excellent.
Quoted 2 lines
*** Future items under consideration ***
Use qemu softfloat
This is a blocker. It's definitely not hard.
Quoted 1 line
Use qemu decodetree
This would certainly clean up all of the string processing that I mentioned. It seems like it would be just as easy to convert into the decodetree format as what you're currently doing for dectree_generated.h. Indeed, easier, since you only need the ones that are TERMINAL(). All of the other things labeled TABLE_LINK are handled by decodetree itself.
Anyway, I've completed what review I planed to do against this version.
r~
Richard,
Thank you so much for the feedback. I really appreciate it.
I'll get to work addressing the issues. Since some of the items will take longer than others, please advise whether it's preferred to send intermediate updates or wait until they are all addressed.
Taylor
Quoted 41 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, August 28, 2020 9:27 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 00/34] Hexagon patch seriesQuoted 8 lines · Taylor Simpson
This series adds support for the Hexagon processor with Linux user support
See patch 02/34 Hexagon README for detailed information.
Once the series is applied, the Hexagon port will pass "make check-tcg". The series also includes Hexagon-specific tests in tcg/tests/hexagon.
We have a parallel effort to make the Hexagon Linux toolchain inside a
docker
Quoted 1 line
container publically available.
Oh, excellent.
Quoted 2 lines
*** Future items under consideration ***
Use qemu softfloatThis is a blocker. It's definitely not hard.
Quoted 1 line
Use qemu decodetree
This would certainly clean up all of the string processing that I mentioned. It seems like it would be just as easy to convert into the decodetree format as
what you're currently doing fordectree_generated.h. Indeed, easier, since you
only need the ones that areTERMINAL(). All of the other things labeledTABLE_LINKare handled by decodetree itself.Anyway, I've completed what review I planed to do against this version.
r~
Quoted 5 lines · Taylor Simpson
Richard,
Thank you so much for the feedback. I really appreciate it.
I'll get to work addressing the issues. Since some of the items will take longer than others, please advise whether it's preferred to send intermediate updates or wait until they are all addressed.
I don't mind intermediate updates. Just keep a list in the cover letter of the things that are still on the to-do list, and I'll not focus on those.
We could also talk about what portions of the to-do list are blocker, and what can be done via normal development. Because neither you nor I want to carry around this huge patch set forever.
r~
Quoted 9 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, August 30, 2020 5:33 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 00/34] Hexagon patch series
Quoted 7 lines
I don't mind intermediate updates. Just keep a list in the cover letter of the things that are still on the to-do list, and I'll not focus on those.
We could also talk about what portions of the to-do list are blocker, and what can be done via normal development. Because neither you nor I want to carry
around this huge patch set forever.
OK, here's the list of items. Let me know if I missed anything. I'll indicate which ones can be done quickly and which ones would take more time. I added a column for blocker if you or anyone else has input on that.
PatchItemEffortBlocker
Use qemu softfloat??Yes
Use qemu decodetree.py??
SeveralUse const when appropriatesmall
SeveralRemove anything after g_assert_not_reachedsmall
SeveralFix log_store32/64 add/remove/add in patch seriessmall SeveralFollow naming guidelines for structs and enumssmall
04Move decls to cpu-param.hsmall
04Remove CONFIG_USER_ONLY ifdef'ssmall
04Remove DEBUG_HEXAGONsmall
04Remove stack pointer modification hack, use qemu mechanismsmall 04Add property x-lldb-compat to control output in logsmall 06Include instruction and raw bytes in disassemblysmall
07Use DEF_HELPER_FLAGSsmall
07, 26Endianness of merge_bytessmall
07Fix overlap testsmall
07Remove HELPER(debug_value)/HELPER(debug_value_i64)small 09Include "qemu/osdep.h" instead of <stdint.h>small
10 (and others)Stick with stdint.h types except in imported filessmall 11Remove description from reg field definitionssmall
13Move regmap.h into decode.csmall
14, 27Use bit mask instead of strings in decodingsmall
14Add comments to decodersmall
16Use qemu/int128.hmedium
17Squash patches dealing with imported filessmall
24Use qemu/bitops.h for instruction attributessmall
24Fix initialization of opcode_short_semanticssmall
24Change if (p == NULL) { g_assert_not_reached(); } to assert(p != NULL)small 25Expand DECL/READ/WRITE/FREE macros into generated codesmall 26Rewrite fINSERT*, fEXTRACT*, f?XTN macrossmall
26Investigate fRND macrosmall
26Change REG = REG to (VOID)REG to suppress compiler warningsmall 27Remove multiple includes of imported/iclass.defsmall
28Move genptr_helpers.h into genptr.csmall
28Remove unneeded tempssmall
28Use tcg_gen_deposit_tl and tcg_gen_extract_tl when dealing with p3_0small 29Size opcode_genptr[] properly and initialize with [TAG] = generate_##TAGsmall 30Don't generate helpers for instructions that are overriddensmall Don't include "gen_tcg.h" in helper.h
31Use bitmask for ctx->reg_log instead of an arraysmall
31Use tcg_gen_extract_i32 for gen_slot_cancelled_checksmall 31Properly deal with reading instructions across a page boundary and toomedium many instructions before finding end-of-packet
31Don't set PC at the beginning of every packetmedium
31Don't set slot_cancelled unless neededsmall
31Don't set hex_pred_written unless neededmedium
31Change cancelled variable to not localsmall
31Remove unnecessary tempsmall
31Let tcg_gen_addi_tl check for zerosmall
31Move gen_exec_counters to end of TB instead of every packetmedium 31Move end of TB handling to hexagon_tr_tb_stopsmall
Quoted 6 lines · Taylor Simpson
OK, here's the list of items. Let me know if I missed anything. I'll indicate which ones can be done quickly and which ones would take more time. I added a column for blocker if you or anyone else has input on that.
PatchItemEffortBlocker
Use qemu softfloat??Yes
Hmm, this table didn't render. Below, yes/no for blocker column.
Quoted 1 line
Use qemu
decodetree.py??
no
Quoted 1 line
SeveralUse const when appropriatesmall
yes
Quoted 1 line
SeveralRemove anything after
g_assert_not_reachedsmall
yes
Quoted 1 line
SeveralFix log_store32/64 add/remove/add in patch seriessmall
yes
Quoted 1 line
SeveralFollow naming guidelines for structs and enumssmall
yes
Quoted 1 line
04Move decls to cpu-param.hsmall
Yes. The only reason this even compiled is that you don't do system mode yet. ;-)
Quoted 1 line
04Remove
CONFIG_USER_ONLYifdef'ssmall
yes
Quoted 1 line
04Remove
DEBUG_HEXAGONsmall
yes
Quoted 1 line
04Remove stack pointer modification hack, use qemu mechanismsmall
yes
Quoted 1 line
04Add property x-lldb-compat to control output in logsmall
yes
Quoted 1 line
06Include instruction and raw bytes in disassemblysmall
yes
Quoted 1 line
07Use
DEF_HELPER_FLAGSsmall
no, but should be easy.
Quoted 1 line
07, 26Endianness of
merge_bytessmall
Yes, one way or another; hopefully by removing all of the merge_bytes and using probe_read.
Quoted 1 line
07Fix overlap testsmall
yes
Quoted 1 line
07Remove HELPER(debug_value)/HELPER(debug_value_i64)small
yes
Quoted 1 line
09Include "
qemu/osdep.h" instead of <stdint.h>small
yes
Quoted 1 line
10 (and others)Stick with
stdint.htypes except in imported filessmall
yes
Quoted 1 line
11Remove description from reg field definitionssmall
yes
Quoted 1 line
13Move
regmap.hinto decode.csmall
yes
Quoted 1 line
14, 27Use bit mask instead of strings in decodingsmall
no, but should be easy.
Quoted 1 line
14Add comments to decodersmall
yes
Quoted 1 line
16Use qemu/int128.hmedium
no
Quoted 1 line
17Squash patches dealing with imported filessmall
yes
Quoted 1 line
24Use
qemu/bitops.hfor instruction attributessmall
no
Quoted 1 line
24Fix initialization of
opcode_short_semanticssmall
yes
Quoted 1 line
24Change if (p == NULL) {
g_assert_not_reached(); } to assert(p != NULL)small
no
Quoted 1 line
25Expand DECL/READ/WRITE/FREE macros into generated codesmall
Yes.
In the end I think some of these will in the end want to be helper functions. As I was thinking how to best write A2_add, I was thinking
/* TODO: You currently have an "offset" parameter to
DECL_REG. I can't see that it is ever used? I would *hope* that this could be resolved earlier, so that by this time insn->regno[*] is absolute. */
static int resolve_regno(Insn *insn, int slot, int off);
/* Return hex_new_value[regno]; log the write. */ static TCGv reg_for_write(DisasContext *ctx, int regno);
/* Return hex_reg[regno]; force up-to-date value for PC. */ static TCGv reg_for_read(DisasContext *ctx, int regno);
/* if (preg) hex_new_value[regno] = hex_reg[regno],
or !preg if !test_positive.
Leaves hex_new_value[] canonical for gen_reg_writes, no extra temporary required. */
static void gen_cancel_reg(DisasContext *ctx, int preg,
int rreg, bool test_positive);
DEF_TCG_FUNC(A2_add)
{
int rd = resolve_regno(insn, 0, 0);
int rs = resolve_regno(insn, 1, 0);
int rt = resolve_regno(insn, 2, 0);
tcg_gen_add_tl(reg_for_write(ctx, rd),
reg_for_read(ctx, rs),
reg_for_read(ctx, rt));
}DEF_TCG_FUNC(A2_paddit)
{
int pu = resolve_regno(insn, 0, 0);
int rd = resolve_regno(insn, 1, 0);
int rs = resolve_regno(insn, 2, 0);
int rt = resolve_regno(insn, 3, 0);
tcg_gen_add_tl(reg_for_write(ctx, rd),
reg_for_read(ctx, rs),
reg_for_read(ctx, rt));
gen_cancel_reg(ctx, insn, rd, pu, true);
}However, I don't think we have to have a comprehensive set of these now. We can expand everything into the generator to start, then adjust the generator as we add helper functions and use them within the overrides.
Quoted 1 line
26Rewrite fINSERT*, fEXTRACT*, f?XTN macrossmall
yes
Quoted 1 line
26Investigate fRND macrosmall
no, but should be easy.
Quoted 1 line
26Change REG = REG to (VOID)REG to suppress compiler warningsmall
yes
Quoted 1 line
27Remove multiple includes of imported/iclass.defsmall
yes
Quoted 1 line
28Move
genptr_helpers.hinto genptr.csmall
yes
Quoted 1 line
28Remove unneeded tempssmall
no
Quoted 1 line
28Use
tcg_gen_deposit_tlandtcg_gen_extract_tlwhen dealing withp3_0small
no
Quoted 1 line
29Size opcode_genptr[] properly and initialize with [TAG] = generate_##TAGsmall
yes; i think this will fall out of other changes.
Quoted 1 line
30Don't generate helpers for instructions that are overriddensmall
yes
Quoted 1 line
Don't include "
gen_tcg.h" inhelper.h
yes
Quoted 1 line
31Use bitmask for
ctx->reg_loginstead of an arraysmall
yes
Quoted 1 line
31Use
tcg_gen_extract_i32forgen_slot_cancelled_checksmall
yes
Quoted 2 lines
31Properly deal with reading instructions across a page boundary and toomedium many instructions before finding end-of-packet
Yes, this should be easy. Unless there's some surprise in the code I have already suggested code.
Quoted 1 line
31Don't set PC at the beginning of every packetmedium
no
Quoted 1 line
31Don't set
slot_cancelledunless neededsmall
no
Quoted 1 line
31Don't set
hex_pred_writtenunless neededmedium
no
Quoted 1 line
31Change cancelled variable to not localsmall
yes
Quoted 1 line
31Remove unnecessary tempsmall
yes
Quoted 1 line
31Let
tcg_gen_addi_tlcheck for zerosmall
yes
Quoted 1 line
31Move
gen_exec_countersto end of TB instead of every packetmedium
no
Quoted 1 line
31Move end of TB handling to
hexagon_tr_tb_stopsmall
yes
r~
Quoted 12 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Monday, August 31, 2020 2:44 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v3 00/34] Hexagon patch seriesQuoted 2 lines · Taylor Simpson
OK, here's the list of items. Let me know if I missed anything. I'll indicate which ones can be done quickly and which ones would take more
Quoted 7 lines
time.
Quoted 4 lines
I added a column for blocker if you or anyone else has input on that.
PatchItemEffortBlocker
Use qemu softfloat??YesHmm, this table didn't render. Below, yes/no for blocker column.
Sorry about that - not sure what happened.
I will work all those you marked "yes" or "no, but should be easy".
Quoted 6 lines
Quoted 1 line
25Expand DECL/READ/WRITE/FREE macros into generated codesmall
Yes.
In the end I think some of these will in the end want to be helper functions. As I was thinking how to best write
A2_add, I was thinking
See my response to the thread on patch 30/34.
Since you mention A2_paddit, here's what it would look like assuming it is overridden.
static void generate_A2_paddt(CPUHexagonState *env, DisasContext *ctx, insn_t *insn, packet_t *pkt) {
/* A2_paddit */
int PuN = insn->regno[0];
TCGv PuV = hex_pred[PuN];
Int RdN = insn->regno[1];
TCGv RdV = tcg_temp_local_new();
if (!is_preloaded(ctx, RdN)) {
tcg_gen_mov_tl(hex_new_value[RdN], hex_gpr[RdN]);
}int RsN = insn->regno[2]; TCGv RsV = hex_gpr[RsN]; int siV = insn->immed[0];
fGEN_TCG_A2_paddit({if(fLSBOLD(PuV)){fIMMEXT(siV); RdV=RsV+siV;} else {CANCEL;}});
gen_log_reg_write(RdN, RdV, insn->slot, 1); /* Only does the write if we haven't cancelled */ctx_log_reg_write(ctx, RdN);
tcg_temp_free(RdV);
/* A2_paddit */
}
Here's what the override looks like (there are a bunch of these, so we have a helper macro which could also be a function) /* Predicated add instructions */
#define GEN_TCG_padd(PRED, ADD) \
do { \
TCGv LSB = tcg_temp_new(); \
TCGv mask = tcg_temp_new(); \
TCGv zero = tcg_const_tl(0); \
PRED; \
ADD; \
tcg_gen_movi_tl(mask, 1 << insn->slot); \
tcg_gen_or_tl(mask, hex_slot_cancelled, mask); \
tcg_gen_movcond_tl(TCG_COND_NE, hex_slot_cancelled, LSB, zero, \
hex_slot_cancelled, mask); \
tcg_temp_free(LSB); \
tcg_temp_free(mask); \
tcg_temp_free(zero); \
} while (0)#define fGEN_TCG_A2_paddit(SHORTCODE) \
GEN_TCG_padd(fLSBOLD(PuV), tcg_gen_addi_tl(RdV, RsV, siV))
Quoted 7 lines · Taylor Simpson
Richard,
Thank you so much for the feedback. I really appreciate it.
I'll get to work addressing the issues. Since some of the items will take longer than others, please advise whether it's preferred to send intermediate updates or wait until they are all addressed.
Taylor
Which branch of https://github.com/quic/qemu do I pull to try this without scraping 30 patches out of the mailing list?
Quoted 8 lines
Quoted 8 lines
Quoted 4 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.
We have a parallel effort to make the Hexagon Linux toolchain inside a
docker
Quoted 1 line
container publically available.
Oh, excellent.
Is that a follow-up to https://www.spinics.net/lists/linux-hexagon/msg01706.html
and is this a clang toolchain or a gcc toolchain?
I've noticed gcc 9.2 has hexagon in config.guess and config.sub, but the only other file outside of the test suite containing the word "hexagon" in a case insensitive match is the Changelog saying Linas Veptas added it to config.guess and config.sub in 2011. And while https://github.com/quic has a musl fork it doesn't have any compiler or linker forks...
Rob
Quoted 3 lines
-----Original Message-----
From: Qemu-devel <[email protected]> On Behalf Of Rob Landley
...
Quoted 6 lines · Taylor Simpson
Quoted 4 lines
Richard,
Thank you so much for the feedback. I really appreciate it.
Quoted 8 lines
Quoted 1 line
I'll get to work addressing the issues. Since some of the items will take longer
than others, please advise whether it's preferred to send intermediate updates or wait until they are all addressed.
Quoted 2 lines
Taylor
Which branch of https://github.com/quic/qemu do I pull to try this without scraping 30 patches out of the mailing list?
IIRC this patch series was "small_series_v3"
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 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.
We have a parallel effort to make the Hexagon Linux toolchain inside a
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
docker
Quoted 1 line
container publically available.
Oh, excellent.
Is that a follow-up to https://www.spinics.net/lists/linux-
hexagon/msg01706.html
and is this a clang toolchain or a gcc toolchain?
It's a clang toolchain.
Quoted 5 lines
I've noticed gcc 9.2 has hexagon in config.guess and config.sub, but the only other file outside of the test suite containing the word "hexagon" in a case insensitive match is the Changelog saying Linas Veptas added it to config.guess and config.sub in 2011. And while https://github.com/quic has a musl fork it doesn't have any compiler or linker forks...
clang and lld support for hexagon exists in the upstream llvm-project repo.
-Brian