Hexagon update: bug fixes, performance, idef-parser
The following changes since commit 4208e6ae114ac8266dcacc9696a443ce5c37b04e:
Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1
for you to fetch changes up to 585a86b1041a45c3b4074440c7f1b54944570867:
target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)
----------------------------------------------------------------
******************************************************************
***** WARNING *****
***** This PR requires updated CI containers with flex/bison *****
******************************************************************
1)
Performance improvement
Add pkt and insn to DisasContext
Many functions need information from all 3 structures, so merge them together.
2)
Bug fix
Fix predicated assignment to .tmp and .cur
3)
Performance improvement
Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat These functions will not be handled by idef-parser
4-11)
The final 8 patches improve change-of-flow handling.
Currently, we set the PC to a new address before exiting a TB. The ultimate goal is to use direct block chaining. However, several steps are needed along the way.
4)
When a packet has more than one change-of-flow (COF) instruction, only the first one taken is considered. The runtime bookkeeping is only needed when there is more than one COF instruction in a packet.
5, 6)
Remove PC and next_PC from the runtime state and always use a translation-time constant. Note that next_PC is used by call instructions to set LR and by conditional COF instructions to set the fall-through address.
7, 8, 9)
Add helper overrides for COF instructions. In particular, we must distinguish those that use a PC-relative address for the destination. These are candidates for direct block chaining later.
10)
Use direct block chaining for packets that have a single PC-relative COF instruction. Instead of generating the code while processing the instruction, we record the effect in DisasContext and generate the code during gen_end_tb.
11)
Use direct block chaining for tight loops. We look for TBs that end with an endloop0 that will branch back to the TB start address.
12-21)
Instruction definition parser (idef-parser) from rev.ng Parses the instruction semantics and generates TCG
----------------------------------------------------------------
Alessandro Di Federico (4):
target/hexagon: update MAINTAINERS for idef-parser target/hexagon: import README for idef-parser target/hexagon: prepare input for the idef-parser target/hexagon: call idef-parser functions
Anton Johansson (1):
target/hexagon: import parser for idef-parser
Niccolò Izzo (2):
target/hexagon: introduce new helper functions target/hexagon: import additional tests
Paolo Montesel (3):
target/hexagon: make slot number an unsigned target/hexagon: make helper functions non-static target/hexagon: import lexer for idef-parser
Taylor Simpson (11):
Hexagon (target/hexagon) Add pkt and insn to DisasContext Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur Hexagon (target/hexagon) Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat Hexagon (target/hexagon) Only use branch_taken when packet has multi cof Hexagon (target/hexagon) Remove PC from the runtime state Hexagon (target/hexagon) Remove next_PC from runtime state Hexagon (target/hexagon) Add overrides for direct call instructions Hexagon (target/hexagon) Add overrides for compound compare and jump Hexagon (target/hexagon) Add overrides for various forms of jump Hexagon (target/hexagon) Use direct block chaining for direct jump/branch Hexagon (target/hexagon) Use direct block chaining for tight loops
target/hexagon/idef-parser/README.rst | 722 ++++++++ target/hexagon/cpu.h | 14 +- target/hexagon/gen_tcg.h | 412 ++++- target/hexagon/gen_tcg_hvx.h | 6 +- target/hexagon/genptr.h | 36 + target/hexagon/idef-parser/idef-parser.h | 253 +++ target/hexagon/idef-parser/parser-helpers.h | 376 +++++ target/hexagon/insn.h | 9 +- target/hexagon/macros.h | 27 +- target/hexagon/mmvec/macros.h | 4 +- target/hexagon/op_helper.h | 37 + target/hexagon/translate.h | 20 +- target/hexagon/decode.c | 15 +- target/hexagon/genptr.c | 585 ++++++- target/hexagon/idef-parser/parser-helpers.c | 2360 +++++++++++++++++++++++++++ target/hexagon/op_helper.c | 55 +- target/hexagon/translate.c | 229 ++- tests/tcg/hexagon/hvx_misc.c | 72 + tests/tcg/hexagon/usr.c | 34 +- MAINTAINERS | 9 + meson_options.txt | 3 + target/hexagon/README | 5 + target/hexagon/gen_helper_funcs.py | 30 +- target/hexagon/gen_helper_protos.py | 31 +- target/hexagon/gen_idef_parser_funcs.py | 130 ++ target/hexagon/gen_tcg_funcs.py | 79 +- target/hexagon/hex_common.py | 40 +- target/hexagon/idef-parser/idef-parser.lex | 471 ++++++ target/hexagon/idef-parser/idef-parser.y | 965 +++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++ target/hexagon/idef-parser/prepare | 24 + target/hexagon/meson.build | 158 +- tests/tcg/hexagon/Makefile.target | 28 +- tests/tcg/hexagon/crt.S | 14 + tests/tcg/hexagon/test_abs.S | 17 + tests/tcg/hexagon/test_bitcnt.S | 40 + tests/tcg/hexagon/test_bitsplit.S | 22 + tests/tcg/hexagon/test_call.S | 64 + tests/tcg/hexagon/test_clobber.S | 29 + tests/tcg/hexagon/test_cmp.S | 31 + tests/tcg/hexagon/test_dotnew.S | 38 + tests/tcg/hexagon/test_ext.S | 13 + tests/tcg/hexagon/test_fibonacci.S | 30 + tests/tcg/hexagon/test_hl.S | 16 + tests/tcg/hexagon/test_hwloops.S | 19 + tests/tcg/hexagon/test_jmp.S | 22 + tests/tcg/hexagon/test_lsr.S | 36 + tests/tcg/hexagon/test_mpyi.S | 17 + tests/tcg/hexagon/test_packet.S | 29 + tests/tcg/hexagon/test_reorder.S | 33 + tests/tcg/hexagon/test_round.S | 29 + tests/tcg/hexagon/test_vavgw.S | 31 + tests/tcg/hexagon/test_vcmpb.S | 30 + tests/tcg/hexagon/test_vcmpw.S | 30 + tests/tcg/hexagon/test_vlsrw.S | 20 + tests/tcg/hexagon/test_vmaxh.S | 35 + tests/tcg/hexagon/test_vminh.S | 35 + tests/tcg/hexagon/test_vpmpyh.S | 28 + tests/tcg/hexagon/test_vspliceb.S | 31 + 59 files changed, 7908 insertions(+), 210 deletions(-) create mode 100644 target/hexagon/idef-parser/README.rst create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/parser-helpers.h create mode 100644 target/hexagon/op_helper.h create mode 100644 target/hexagon/idef-parser/parser-helpers.c create mode 100644 target/hexagon/gen_idef_parser_funcs.py create mode 100644 target/hexagon/idef-parser/idef-parser.lex create mode 100644 target/hexagon/idef-parser/idef-parser.y create mode 100644 target/hexagon/idef-parser/macros.inc create mode 100755 target/hexagon/idef-parser/prepare create mode 100644 tests/tcg/hexagon/crt.S create mode 100644 tests/tcg/hexagon/test_abs.S create mode 100644 tests/tcg/hexagon/test_bitcnt.S create mode 100644 tests/tcg/hexagon/test_bitsplit.S create mode 100644 tests/tcg/hexagon/test_call.S create mode 100644 tests/tcg/hexagon/test_clobber.S create mode 100644 tests/tcg/hexagon/test_cmp.S create mode 100644 tests/tcg/hexagon/test_dotnew.S create mode 100644 tests/tcg/hexagon/test_ext.S create mode 100644 tests/tcg/hexagon/test_fibonacci.S create mode 100644 tests/tcg/hexagon/test_hl.S create mode 100644 tests/tcg/hexagon/test_hwloops.S create mode 100644 tests/tcg/hexagon/test_jmp.S create mode 100644 tests/tcg/hexagon/test_lsr.S create mode 100644 tests/tcg/hexagon/test_mpyi.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
[PULL 10/21] Hexagon (target/hexagon) Use direct block chaining for direct jump/branch
Direct block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chaining
Recall that Hexagon allows packets with multiple jumps where only the first one with a true predicate will actually jump. We can use tcg_gen_goto_tb/tcg_gen_exit_tb when the packet contains a single PC-relative branch or jump. If not, we use tcg_gen_lookup_and_goto_ptr.
We add the following to DisasContext in order to delay the branching until the end of packet commit (in gen_end_tb)
branch_cond
The TCGCond condition under which the branch is taken When branch_cond == TCG_COND_NEVER, there isn't a single direct branch in this packet.
When branch_cond != TCG_COND_ALWAYS, the value is in hex_branch_taken
branch_dest
The destination of the branch
Message-Id: <[email protected]>
--- target/hexagon/translate.h | 2 ++ target/hexagon/genptr.c | 12 +++++++++++- target/hexagon/translate.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-)
target/hexagon/translate.h +2 -0
@@ -57,6 +57,8 @@ typedef struct DisasContext {bool qreg_is_predicated[NUM_QREGS ];int qreg_log_idx;bool pre_commit; +TCGCond branch_cond; +target_ulong branch_dest; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
target/hexagon/genptr.c +11 -1
@@ -484,7 +484,17 @@ static void gen_write_new_pc_pcrel(DisasContext *ctx, int pc_off, TCGCond cond, TCGv pred) {target_ulong dest = ctx->pkt->pc + pc_off; -gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), cond, pred); +if (ctx->pkt->pkt_has_multi_cof) { +gen_write_new_pc_addr (ctx,tcg_constant_tl (dest), cond, pred); + }else { +/* Defer this jump to the end of the TB */ + ctx->branch_cond =TCG_COND_ALWAYS ; +if (pred !=NULL ) { + ctx->branch_cond = cond; +tcg_gen_mov_tl (hex_branch_taken, pred); + } + ctx->branch_dest = dest; + } }static void gen_compare (TCGCond cond,TCGv res,TCGv arg1,TCGv arg2)
target/hexagon/translate.c +33 -1
@@ -116,10 +116,41 @@ static void gen_exec_counters(DisasContext *ctx) hex_gpr[HEX_REG_QEMU_HVX_CNT], ctx->num_hvx_insns); } +static bool use_goto_tb (DisasContext *ctx,target_ulong dest) +{ +return translator_use_goto_tb (&ctx->base, dest); +} + +static void gen_goto_tb (DisasContext *ctx,int idx,target_ulong dest) +{ +if (use_goto_tb (ctx, dest)) { +tcg_gen_goto_tb (idx); +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], dest); +tcg_gen_exit_tb (ctx->base.tb, idx); + }else { +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], dest); +tcg_gen_lookup_and_goto_ptr (); + } +} +static void gen_end_tb (DisasContext *ctx) {gen_exec_counters (ctx); -tcg_gen_exit_tb (NULL ,0 ); + +if (ctx->branch_cond !=TCG_COND_NEVER ) { +if (ctx->branch_cond !=TCG_COND_ALWAYS ) { +TCGLabel *skip =gen_new_label (); +tcg_gen_brcondi_tl (ctx->branch_cond, hex_branch_taken,0 , skip); +gen_goto_tb (ctx,0 , ctx->branch_dest); +gen_set_label (skip); +gen_goto_tb (ctx,1 , ctx->next_PC); + }else { +gen_goto_tb (ctx,0 , ctx->branch_dest); + } + }else { +tcg_gen_lookup_and_goto_ptr (); + } + ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -807,6 +838,7 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase, ctx->num_packets =0 ; ctx->num_insns =0 ; ctx->num_hvx_insns =0 ; + ctx->branch_cond =TCG_COND_NEVER ; }static void hexagon_tr_tb_start (DisasContextBase *db,CPUState *cpu)
Signature · 1 line
2.17.1
[PULL 16/21] target/hexagon: introduce new helper functions
In reply to Taylor SimpsonFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code, to correctly implement instruction semantics. "Helper" functions, in the context of this patch, refers to functions which provide a manual TCG implementation of certain features.
Message-Id: <[email protected]>
--- target/hexagon/genptr.h | 13 ++++ target/hexagon/macros.h | 9 +++ target/hexagon/genptr.c | 146 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 166 insertions(+), 2 deletions(-)
target/hexagon/genptr.h +13 -0
@@ -33,9 +33,22 @@ void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src, uint32_t slot);void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot);void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot);void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,uint32_t slot); +TCGv gen_read_reg (TCGv result,int num);TCGv gen_read_preg (TCGv pred,uint8_t num);void gen_log_reg_write (int rnum,TCGv val);void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val); +void gen_set_usr_field (int field,TCGv val); +void gen_set_usr_fieldi (int field,int x); +void gen_set_usr_field_if (int field,TCGv val); +void gen_sat_i32 (TCGv dest,TCGv source,int width); +void gen_sat_i32_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_satu_i32 (TCGv dest,TCGv source,int width); +void gen_satu_i32_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_sat_i64 (TCGv_i64 dest,TCGv_i64 source,int width); +void gen_sat_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width); +void gen_satu_i64 (TCGv_i64 dest,TCGv_i64 source,int width); +void gen_satu_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width); +void gen_add_sat_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b);TCGv gen_8bitsof (TCGv result,TCGv value);void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src);TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign);
target/hexagon/macros.h +9 -0
@@ -197,7 +197,16 @@#define MEM_STORE8 (VA ,DATA ,SLOT ) log_store64(env, VA, DATA, 8, SLOT)#endif +#ifdef QEMU_GENERATE +static inline void gen_cancel (uint32_t slot) +{ +tcg_gen_ori_tl (hex_slot_cancelled, hex_slot_cancelled,1 << slot); +} + +#define CANCEL gen_cancel(slot); +#else #define CANCEL cancel_slot(env, slot) +#endif #define LOAD_CANCEL (EA ) do { CANCEL; } while (0)
target/hexagon/genptr.c +144 -2
169 lines not on this page · raw message
Signature · 1 line
2.17.1
[PULL 15/21] target/hexagon: make helper functions non-static
In reply to Taylor SimpsonFrom: Paolo Montesel <[email protected]>
Make certain helper functions non-static, making them available outside genptr.c. These functions are required by code generated by the idef-parser.
This commit also makes some functions in op_helper.c non-static in order to avoid having them marked as unused when using the idef-parser generated code.
Message-Id: <[email protected]>
--- target/hexagon/genptr.h | 23 +++++++++++++++++++ target/hexagon/op_helper.h | 37 +++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 45 ++++++++++++++++++++++---------------- target/hexagon/op_helper.c | 29 +++++++++++------------- 4 files changed, 99 insertions(+), 35 deletions(-) create mode 100644 target/hexagon/op_helper.h
target/hexagon/genptr.h +23 -0
@@ -19,7 +19,30 @@#define HEXAGON_GENPTR_H #include "insn.h" +#include "tcg/tcg.h" +#include "translate.h" extern const SemanticInsn opcode_genptr[]; +void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot); +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); +void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); +void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); +void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,uint32_t slot); +void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); +void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); +void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); +void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,uint32_t slot); +TCGv gen_read_preg (TCGv pred,uint8_t num); +void gen_log_reg_write (int rnum,TCGv val); +void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val); +TCGv gen_8bitsof (TCGv result,TCGv value); +void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src); +TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign); +TCGv gen_get_byte_i64 (TCGv result,int N ,TCGv_i64 src,bool sign); +TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign); +void gen_set_half (int N ,TCGv result,TCGv src); +void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src); +void probe_noshuf_load (TCGv va,int s,int mi); +#endif
target/hexagon/op_helper.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HEXAGON_OP_HELPER_H +#define HEXAGON_OP_HELPER_H + +/* Misc functions */ +void cancel_slot (CPUHexagonState *env,uint32_t slot); +void write_new_pc (CPUHexagonState *env,bool pkt_has_multi_cof,target_ulong addr); + +uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); + +void log_reg_write (CPUHexagonState *env,int rnum, +target_ulong val,uint32_t slot); +void log_store64 (CPUHexagonState *env,target_ulong addr, +int64_t val,int width,int slot); +void log_store32 (CPUHexagonState *env,target_ulong addr, +target_ulong val,int width,int slot); + +#endif
target/hexagon/genptr.c +26 -19
153 lines not on this page · raw message
target/hexagon/op_helper.c +13 -16
@@ -29,6 +29,7 @@#include "fma_emu.h" #include "mmvec/mmvec.h" #include "mmvec/macros.h" +#include "op_helper.h" #define SF_BIAS 127#define SF_MANTBITS 23
@@ -50,8 +51,8 @@ G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp)do_raise_exception_err (env, excp,0 ); } -static void log_reg_write (CPUHexagonState *env,int rnum, -target_ulong val,uint32_t slot) +void log_reg_write (CPUHexagonState *env,int rnum, +target_ulong val,uint32_t slot) {HEX_DEBUG_LOG ("log_reg_write[%d] = " TARGET_FMT_ld" (0x" TARGET_FMT_lx")" , rnum, val, val);
@@ -82,8 +83,8 @@ static void log_pred_write(CPUHexagonState *env, int pnum, target_ulong val) } } -static void log_store32 (CPUHexagonState *env,target_ulong addr, -target_ulong val,int width,int slot) +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 ", %" PRId32 " [0x08%" PRIx32 "])\n",
@@ -93,8 +94,8 @@ static void log_store32(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data32 = val; } -static void log_store64 (CPUHexagonState *env,target_ulong addr, -int64_t val,int width,int slot) +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 ", %" PRId64 " [0x016%" PRIx64 "])\n",
@@ -104,7 +105,7 @@ static void log_store64(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data64 = val; } -static void write_new_pc (CPUHexagonState *env,bool pkt_has_multi_cof, +void write_new_pc (CPUHexagonState *env,bool pkt_has_multi_cof,target_ulong addr) {HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr);
@@ -541,32 +542,28 @@ static void check_noshuf(CPUHexagonState *env, uint32_t slot, } } -static uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot, vaddr,1 );return cpu_ldub_data_ra (env, vaddr, ra); } -static uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot, vaddr,2 );return cpu_lduw_data_ra (env, vaddr, ra); } -static uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot, vaddr,4 );return cpu_ldl_data_ra (env, vaddr, ra); } -static uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot, vaddr,8 );
@@ -1471,7 +1468,7 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV) } } -static void cancel_slot (CPUHexagonState *env,uint32_t slot) +void cancel_slot (CPUHexagonState *env,uint32_t slot) {HEX_DEBUG_LOG ("Slot %d cancelled\n" , slot); env->slot_cancelled |= (1 << slot);
Signature · 1 line
2.17.1
[PULL 19/21] target/hexagon: import parser for idef-parser
In reply to Taylor SimpsonFrom: Anton Johansson <[email protected]>
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/parser-helpers.h | 376 +++ target/hexagon/idef-parser/parser-helpers.c | 2360 +++++++++++++++++++ target/hexagon/idef-parser/idef-parser.y | 965 ++++++++ target/hexagon/meson.build | 29 + 4 files changed, 3730 insertions(+) create mode 100644 target/hexagon/idef-parser/parser-helpers.h create mode 100644 target/hexagon/idef-parser/parser-helpers.c create mode 100644 target/hexagon/idef-parser/idef-parser.y
target/hexagon/idef-parser/parser-helpers.h new file +376 -0
@@ -0,0 +1,376 @@ +/* +* Copyright(c) 2019-2022 rev.ng Labs Srl. 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 PARSER_HELPERS_H +#define PARSER_HELPERS_H + +#include <assert.h> +#include <inttypes.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "tcg/tcg-cond.h" + +#include "idef-parser.tab.h" +#include "idef-parser.yy.h" +#include "idef-parser.h" + +/* Decomment this to disable yyasserts */ +/* #define NDEBUG */ + +#define ERR_LINE_CONTEXT 40 + +#define START_COMMENT "/" "*" +#define END_COMMENT "*" "/" + +void yyerror (YYLTYPE *locp, +yyscan_t scanner __attribute__((unused)), +Context *c, +const char *s); + +#ifndef NDEBUG +#define yyassert (context, locp, condition, msg) \ + if (!(condition)) { \ + yyerror(locp, (context)->scanner, (context), (msg)); \ + } +#endif + +bool is_direct_predicate (HexValue *value); + +bool is_inside_ternary (Context *c); + +/** +* Print functions +*/ + +void str_print (Context *c,YYLTYPE *locp,const char *string); + +void uint8_print (Context *c,YYLTYPE *locp,uint8_t *num); + +void uint64_print (Context *c,YYLTYPE *locp,uint64_t *num); + +void int_print (Context *c,YYLTYPE *locp,int *num); + +void uint_print (Context *c,YYLTYPE *locp,unsigned *num); + +void tmp_print (Context *c,YYLTYPE *locp,HexTmp *tmp); + +void pred_print (Context *c,YYLTYPE *locp,HexPred *pred,bool is_dotnew); + +void reg_compose (Context *c,YYLTYPE *locp,HexReg *reg,char reg_id[5 ]); + +void reg_print (Context *c,YYLTYPE *locp,HexReg *reg); + +void imm_print (Context *c,YYLTYPE *locp,HexImm *imm); + +void var_print (Context *c,YYLTYPE *locp,HexVar *var); + +void rvalue_print (Context *c,YYLTYPE *locp,void *pointer); + +void out_assert (Context *c,YYLTYPE *locp,void *dummy); + +/** +* Copies output code buffer into stdout +*/ +void commit (Context *c); + +#define OUT_IMPL (c, locp, x) \ + _Generic(*(x), \ + char: str_print, \ + uint8_t: uint8_print, \ + uint64_t: uint64_print, \ + int: int_print, \ + unsigned: uint_print, \ + HexValue: rvalue_print, \ + default: out_assert \ + )(c, locp, x); + +/* FOREACH macro */ +#define FE_1 (c, locp,WHAT ,X ) WHAT(c, locp, X) +#define FE_2 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_1(c, locp, WHAT, __VA_ARGS__) +#define FE_3 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_2(c, locp, WHAT, __VA_ARGS__) +#define FE_4 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_3(c, locp, WHAT, __VA_ARGS__) +#define FE_5 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_4(c, locp, WHAT, __VA_ARGS__) +#define FE_6 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_5(c, locp, WHAT, __VA_ARGS__) +#define FE_7 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_6(c, locp, WHAT, __VA_ARGS__) +#define FE_8 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_7(c, locp, WHAT, __VA_ARGS__) +#define FE_9 (c, locp,WHAT ,X , ...) \ + WHAT(c, locp, X)FE_8(c, locp, WHAT, __VA_ARGS__) +/* repeat as needed */ + +#define GET_MACRO (_1, _2, _3, _4, _5, _6, _7, _8, _9,NAME , ...) NAME + +#define FOR_EACH (c, locp, action, ...) \ + do { \ + GET_MACRO(__VA_ARGS__, \ + FE_9, \ + FE_8, \ + FE_7, \ + FE_6, \ + FE_5, \ + FE_4, \ + FE_3, \ + FE_2, \ + FE_1)(c, locp, action, \ + __VA_ARGS__) \ + } while (0) + +#define OUT (c, locp, ...) FOR_EACH((c), (locp), OUT_IMPL, __VA_ARGS__) + +const char *cmp_swap (Context *c,YYLTYPE *locp,const char *type); + +/** +* Temporary values creation +*/ + +HexValue gen_tmp (Context *c, +YYLTYPE *locp, +unsigned bit_width, +HexSignedness signedness); + +HexValue gen_tmp_value (Context *c, +YYLTYPE *locp, +const char *value, +unsigned bit_width, +HexSignedness signedness); + +HexValue gen_imm_value (Context *c __attribute__((unused)), +YYLTYPE *locp, +int value, +unsigned bit_width, +HexSignedness signedness); + +HexValue gen_imm_qemu_tmp (Context *c,YYLTYPE *locp,unsigned bit_width, +HexSignedness signedness); + +void gen_rvalue_free (Context *c,YYLTYPE *locp,HexValue *rvalue); + +HexValue rvalue_materialize (Context *c,YYLTYPE *locp,HexValue *rvalue); + +HexValue gen_rvalue_extend (Context *c,YYLTYPE *locp,HexValue *rvalue); + +HexValue gen_rvalue_truncate (Context *c,YYLTYPE *locp,HexValue *rvalue); + +void gen_varid_allocate (Context *c, +YYLTYPE *locp, +HexValue *varid, +unsigned bit_width, +HexSignedness signedness); + +/** +* Code generation functions +*/ + +HexValue gen_bin_cmp (Context *c, +YYLTYPE *locp, +TCGCond type, +HexValue *op1, +HexValue *op2); + +HexValue gen_bin_op (Context *c, +YYLTYPE *locp, +OpType type, +HexValue *op1, +HexValue *op2); + +HexValue gen_cast_op (Context *c, +YYLTYPE *locp, +HexValue *src, +unsigned target_width, +HexSignedness signedness); + +/** +* gen_extend_op extends a region of src_width_ptr bits stored in a +* value_ptr to the size of dst_width. Note: src_width_ptr is a +* HexValue * to handle the special case where it is unknown at +* translation time. +*/ +HexValue gen_extend_op (Context *c, +YYLTYPE *locp, +HexValue *src_width, +unsigned dst_width, +HexValue *value, +HexSignedness signedness); + +void gen_rdeposit_op (Context *c, +YYLTYPE *locp, +HexValue *dst, +HexValue *value, +HexValue *begin, +HexValue *width); + +void gen_deposit_op (Context *c, +YYLTYPE *locp, +HexValue *dst, +HexValue *value, +HexValue *index, +HexCast *cast); + +HexValue gen_rextract_op (Context *c, +YYLTYPE *locp, +HexValue *src, +unsigned begin, +unsigned width); + +HexValue gen_extract_op (Context *c, +YYLTYPE *locp, +HexValue *src, +HexValue *index, +HexExtract *extract); + +HexValue gen_read_reg (Context *c,YYLTYPE *locp,HexValue *reg); + +void gen_write_reg (Context *c,YYLTYPE *locp,HexValue *reg,HexValue *value); + +void gen_assign (Context *c, +YYLTYPE *locp, +HexValue *dst, +HexValue *value); + +HexValue gen_convround (Context *c, +YYLTYPE *locp, +HexValue *src); + +HexValue gen_round (Context *c, +YYLTYPE *locp, +HexValue *src, +HexValue *position); + +HexValue gen_convround_n (Context *c, +YYLTYPE *locp, +HexValue *src, +HexValue *pos); + +/** +* Circular addressing mode with auto-increment +*/ +void gen_circ_op (Context *c, +YYLTYPE *locp, +HexValue *addr, +HexValue *increment, +HexValue *modifier); + +HexValue gen_locnt_op (Context *c,YYLTYPE *locp,HexValue *src); + +HexValue gen_ctpop_op (Context *c,YYLTYPE *locp,HexValue *src); + +HexValue gen_rotl (Context *c,YYLTYPE *locp,HexValue *src,HexValue *n); + +HexValue gen_deinterleave (Context *c,YYLTYPE *locp,HexValue *mixed); + +HexValue gen_interleave (Context *c, +YYLTYPE *locp, +HexValue *odd, +HexValue *even); + +HexValue gen_carry_from_add (Context *c, +YYLTYPE *locp, +HexValue *op1, +HexValue *op2, +HexValue *op3); + +void gen_addsat64 (Context *c, +YYLTYPE *locp, +HexValue *dst, +HexValue *op1, +HexValue *op2); + +void gen_inst (Context *c,GString *iname); + +void gen_inst_init_args (Context *c,YYLTYPE *locp); + +void gen_inst_code (Context *c,YYLTYPE *locp); + +void gen_pred_assign (Context *c,YYLTYPE *locp,HexValue *left_pred, +HexValue *right_pred); + +void gen_cancel (Context *c,YYLTYPE *locp); + +void gen_load_cancel (Context *c,YYLTYPE *locp); + +void gen_load (Context *c,YYLTYPE *locp,HexValue *size, +HexSignedness signedness,HexValue *ea,HexValue *dst); + +void gen_store (Context *c,YYLTYPE *locp,HexValue *size,HexValue *ea, +HexValue *src); + +void gen_sethalf (Context *c,YYLTYPE *locp,HexCast *sh,HexValue *n, +HexValue *dst,HexValue *value); + +void gen_setbits (Context *c,YYLTYPE *locp,HexValue *hi,HexValue *lo, +HexValue *dst,HexValue *value); + +unsigned gen_if_cond (Context *c,YYLTYPE *locp,HexValue *cond); + +unsigned gen_if_else (Context *c,YYLTYPE *locp,unsigned index); + +HexValue gen_rvalue_pred (Context *c,YYLTYPE *locp,HexValue *pred); + +HexValue gen_rvalue_var (Context *c,YYLTYPE *locp,HexValue *var); + +HexValue gen_rvalue_mpy (Context *c,YYLTYPE *locp,HexMpy *mpy,HexValue *op1, +HexValue *op2); + +HexValue gen_rvalue_not (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_notl (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_sat (Context *c,YYLTYPE *locp,HexSat *sat,HexValue *n, +HexValue *value); + +HexValue gen_rvalue_fscr (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_abs (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_neg (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_brev (Context *c,YYLTYPE *locp,HexValue *value); + +HexValue gen_rvalue_ternary (Context *c,YYLTYPE *locp,HexValue *cond, +HexValue *true_branch,HexValue *false_branch); + +const char *cond_to_str (TCGCond cond); + +void emit_header (Context *c); + +void emit_arg (Context *c,YYLTYPE *locp,HexValue *arg); + +void emit_footer (Context *c); + +void track_string (Context *c,GString *s); + +void free_variables (Context *c,YYLTYPE *locp); + +void free_instruction (Context *c); + +void assert_signedness (Context *c, +YYLTYPE *locp, +HexSignedness signedness); + +#endif /* PARSER_HELPERS_h */
target/hexagon/idef-parser/parser-helpers.c new file +2360 -0
2,360 lines not on this page · raw message
target/hexagon/idef-parser/idef-parser.y new file +965 -0
264 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PULL 19/21] target/hexagon: import parser for idef-parser
Quoted 9 lines · Taylor Simpson
From: Anton Johansson <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Paolo Montesel <[email protected]>Signed-off-by Anton Johansson <[email protected]>Signed-off-by Taylor Simpson <[email protected]>Reviewed-by Taylor Simpson <[email protected]>Message-Id: <[email protected]>
Hi; Coverity points out (CID 976926) that here:
target/hexagon/idef-parser/idef-parser.y line 856
Quoted 6 lines
target/hexagon/idef-parser/idef-parser.y new file +3
-0+lvalue : FAIL + { + @1.last_column = @1.last_column;
...we have coded an "x = x" assignment that has no effect. Was this supposed to be something else, or should it just be deleted?
target/hexagon/idef-parser/idef-parser.y line 867
Quoted 11 lines
target/hexagon/idef-parser/idef-parser.y new file +11
-0+ yyassert(c, &@1, false, "Encountered a FAIL token as lvalue.\n"); + } + | REG + { + $$ = $1; + } + | var + { + $$ = $1; + } + ;
thanks
-- PMM
Re: [PULL 19/21] target/hexagon: import parser for idef-parser
Quoted 7 lines · Peter Maydell
target/hexagon/idef-parser/idef-parser.y line 856
Quoted 3 lines · Taylor Simpson
target/hexagon/idef-parser/idef-parser.y new file +3
-0+lvalue : FAIL + { + @1.last_column = @1.last_column;...we have coded an "x = x" assignment that has no effect. Was this supposed to be something else, or should it just be deleted?
Ah, thanks! This line can be deleted, I'll go ahead and submit a patch.
Signature · 2 lines
Anton Johansson, rev.ng Labs Srl.
[PULL 18/21] target/hexagon: import lexer for idef-parser
In reply to Taylor SimpsonFrom: Paolo Montesel <[email protected]>
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/idef-parser.h | 253 +++++++++++ target/hexagon/idef-parser/idef-parser.lex | 471 +++++++++++++++++++++ target/hexagon/meson.build | 6 + 3 files changed, 730 insertions(+) create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/idef-parser.lex
target/hexagon/idef-parser/idef-parser.h new file +253 -0
@@ -0,0 +1,253 @@ +/* +* Copyright(c) 2019-2022 rev.ng Labs Srl. 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 IDEF_PARSER_H +#define IDEF_PARSER_H + +#include <inttypes.h> +#include <stdio.h> +#include <stdbool.h> +#include <glib.h> + +#define TCGV_NAME_SIZE 7 +#define MAX_WRITTEN_REGS 32 +#define OFFSET_STR_LEN 32 +#define ALLOC_LIST_LEN 32 +#define ALLOC_NAME_SIZE 32 +#define INIT_LIST_LEN 32 +#define OUT_BUF_LEN (1024 * 1024) +#define SIGNATURE_BUF_LEN (128 * 1024) +#define HEADER_BUF_LEN (128 * 1024) + +/* Variadic macros to wrap the buffer printing functions */ +#define EMIT (c, ...) \ + do { \ + g_string_append_printf((c)->out_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_SIG (c, ...) \ + do { \ + g_string_append_printf((c)->signature_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_HEAD (c, ...) \ + do { \ + g_string_append_printf((c)->header_str, __VA_ARGS__); \ + } while (0) + +/** +* Type of register, assigned to the HexReg.type field +*/ +typedef enum {GENERAL_PURPOSE ,CONTROL ,MODIFIER ,DOTNEW }HexRegType ; + +typedef enum {UNKNOWN_SIGNEDNESS ,SIGNED ,UNSIGNED }HexSignedness ; + +/** +* Semantic record of the REG tokens, identifying registers +*/ +typedef struct HexReg { +uint8_t id;/**< Identifier of the register */ +HexRegType type;/**< Type of the register */ +unsigned bit_width;/**< Bit width of the reg, 32 or 64 bits */ +}HexReg ; + +/** +* Data structure, identifying a TCGv temporary value +*/ +typedef struct HexTmp { +unsigned index;/**< Index of the TCGv temporary value */ +}HexTmp ; + +/** +* Enum of the possible immediated, an immediate is a value which is known +* at tinycode generation time, e.g. an integer value, not a TCGv +*/ +enum ImmUnionTag { +I , +VARIABLE , +VALUE , +QEMU_TMP , +IMM_PC , +IMM_NPC , +IMM_CONSTEXT , +}; + +/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { +union { +char id;/**< Identifier, used when type is VARIABLE */ +uint64_t value;/**< Immediate value, used when type is VALUE */ +uint64_t index;/**< Index, used when type is QEMU_TMP */ + }; +enum ImmUnionTag type;/**< Type of the immediate */ +}HexImm ; + +/** +* Semantic record of the PRED token, identifying a predicate +*/ +typedef struct HexPred { +char id;/**< Identifier of the predicate */ +}HexPred ; + +/** +* Semantic record of the SAT token, identifying the saturate operator +* Note: All saturates are assumed to implicitly set overflow. +*/ +typedef struct HexSat { +HexSignedness signedness;/**< Signedness of the sat. op. */ +}HexSat ; + +/** +* Semantic record of the CAST token, identifying the cast operator +*/ +typedef struct HexCast { +unsigned bit_width;/**< Bit width of the cast operator */ +HexSignedness signedness;/**< Unsigned flag for the cast operator */ +}HexCast ; + +/** +* Semantic record of the EXTRACT token, identifying the cast operator +*/ +typedef struct HexExtract { +unsigned bit_width;/**< Bit width of the extract operator */ +unsigned storage_bit_width;/**< Actual bit width of the extract operator */ +HexSignedness signedness;/**< Unsigned flag for the extract operator */ +}HexExtract ; + +/** +* Semantic record of the MPY token, identifying the fMPY multiplication +* operator +*/ +typedef struct HexMpy { +unsigned first_bit_width;/**< Bit width of 1st operand of fMPY */ +unsigned second_bit_width;/**< Bit width of 2nd operand of fMPY */ +HexSignedness first_signedness;/**< Signedness of 1st operand of fMPY */ +HexSignedness second_signedness;/**< Signedness of 2nd operand of fMPY */ +}HexMpy ; + +/** +* Semantic record of the VARID token, identifying declared variables +* of the input language +*/ +typedef struct HexVar { +GString *name;/**< Name of the VARID variable */ +}HexVar ; + +/** +* Data structure uniquely identifying a declared VARID variable, used for +* keeping track of declared variable, so that any variable is declared only +* once, and its properties are propagated through all the subsequent instances +* of that variable +*/ +typedef struct Var { +GString *name;/**< Name of the VARID variable */ +uint8_t bit_width;/**< Bit width of the VARID variable */ +HexSignedness signedness;/**< Unsigned flag for the VARID var */ +}Var ; + +/** +* Enum of the possible rvalue types, used in the HexValue.type field +*/ +typedef enum RvalueUnionTag { +REGISTER ,REGISTER_ARG ,TEMP ,IMMEDIATE ,PREDICATE ,VARID +}RvalueUnionTag ; + +/** +* Semantic record of the rvalue token, identifying any numeric value, +* immediate or register based. The rvalue tokens are combined together +* through the use of several operators, to encode expressions +*/ +typedef struct HexValue { +union { +HexReg reg;/**< rvalue of register type */ +HexTmp tmp;/**< rvalue of temporary type */ +HexImm imm;/**< rvalue of immediate type */ +HexPred pred;/**< rvalue of predicate type */ +HexVar var;/**< rvalue of declared variable type */ + }; +RvalueUnionTag type;/**< Type of the rvalue */ +unsigned bit_width;/**< Bit width of the rvalue */ +HexSignedness signedness;/**< Unsigned flag for the rvalue */ +bool is_dotnew;/**< rvalue of predicate type is dotnew? */ +bool is_manual;/**< Opt out of automatic freeing of params */ +}HexValue ; + +/** +* State of ternary operator +*/ +typedef enum TernaryState {IN_LEFT ,IN_RIGHT }TernaryState ; + +/** +* Data structure used to handle side effects inside ternary operators +*/ +typedef struct Ternary { +TernaryState state; +HexValue cond; +}Ternary ; + +/** +* Operator type, used for referencing the correct operator when calling the +* gen_bin_op() function, which in turn will generate the correct code to +* execute the operation between the two rvalues +*/ +typedef enum OpType { +ADD_OP ,SUB_OP ,MUL_OP ,ASL_OP ,ASR_OP ,LSR_OP ,ANDB_OP ,ORB_OP , +XORB_OP ,ANDL_OP ,MINI_OP ,MAXI_OP +}OpType ; + +/** +* Data structure including instruction specific information, to be cleared +* out after the compilation of each instruction +*/ +typedef struct Inst { +GString *name;/**< Name of the compiled instruction */ +char *code_begin;/**< Beginning of instruction input code */ +char *code_end;/**< End of instruction input code */ +unsigned tmp_count;/**< Index of the last declared TCGv temp */ +unsigned qemu_tmp_count;/**< Index of the last declared int temp */ +unsigned if_count;/**< Index of the last declared if label */ +unsigned error_count;/**< Number of generated errors */ +GArray *allocated;/**< Allocated declaredVARID vars */ +GArray *init_list;/**< List of initialized registers */ +GArray *strings;/**< Strings allocated by the instruction */ +}Inst ; + +/** +* Data structure representing the whole translation context, which in a +* reentrant flex/bison parser just like ours is passed between the scanner +* and the parser, holding all the necessary information to perform the +* parsing, this data structure survives between the compilation of different +* instructions +*/ +typedef struct Context { +void *scanner;/**< Reentrant parser state pointer */ +char *input_buffer;/**< Buffer containing the input code */ +GString *out_str;/**< String containing the output code */ +GString *signature_str;/**< String containing the signatures code */ +GString *header_str;/**< String containing the header code */ +FILE *defines_file;/**< FILE * of the generated header */ +FILE *output_file;/**< FILE * of the C output file */ +FILE *enabled_file;/**< FILE * of the list of enabled inst */ +GArray *ternary;/**< Array to track nesting of ternary ops */ +unsigned total_insn;/**< Number of instructions in input file */ +unsigned implemented_insn;/**< Instruction compiled without errors */ +Inst inst;/**< Parsing data of the current inst */ +}Context ; + +#endif /* IDEF_PARSER_H */
target/hexagon/idef-parser/idef-parser.lex new file +471 -0
471 lines not on this page · raw message
target/hexagon/meson.build +6 -0
@@ -197,6 +197,12 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs depend_files: [idef_parser_dir / 'macros.inc'], command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'], ) + + flex = generator( + find_program('flex'), + output: ['@[email protected]', '@[email protected]'], + arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@'] + ) endif target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.17.1
[PULL 14/21] target/hexagon: make slot number an unsigned
In reply to Taylor SimpsonFrom: Paolo Montesel <[email protected]>
Message-Id: <[email protected]>
--- target/hexagon/macros.h | 2 +- target/hexagon/genptr.c | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-)
target/hexagon/macros.h +1 -1
@@ -202,7 +202,7 @@#define LOAD_CANCEL (EA ) do { CANCEL; } while (0)#ifdef QEMU_GENERATE -static inline void gen_pred_cancel (TCGv pred,int slot_num) +static inline void gen_pred_cancel (TCGv pred,uint32_t slot_num) {TCGv slot_mask =tcg_temp_new ();TCGv tmp =tcg_temp_new ();
target/hexagon/genptr.c +13 -11
@@ -30,7 +30,8 @@#include "gen_tcg.h" #include "gen_tcg_hvx.h" -static inline void gen_log_predicated_reg_write (int rnum,TCGv val,int slot) +static inline void gen_log_predicated_reg_write (int rnum,TCGv val, +uint32_t slot) {TCGv zero =tcg_constant_tl (0 );TCGv slot_mask =tcg_temp_new ();
@@ -62,7 +63,8 @@ static inline void gen_log_reg_write(int rnum, TCGv val) } } -static void gen_log_predicated_reg_write_pair (int rnum,TCGv_i64 val,int slot) +static void gen_log_predicated_reg_write_pair (int rnum,TCGv_i64 val, +uint32_t slot) {TCGv val32 =tcg_temp_new ();TCGv zero =tcg_constant_tl (0 );
@@ -394,54 +396,54 @@ static inline void gen_store_conditional8(DisasContext *ctx,tcg_gen_movi_tl (hex_llsc_addr, ~0 ); } -static inline void gen_store32 (TCGv vaddr,TCGv src,int width,int slot) +static inline void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot) {tcg_gen_mov_tl (hex_store_addr[slot], vaddr);tcg_gen_movi_tl (hex_store_width[slot], width);tcg_gen_mov_tl (hex_store_val32[slot], src); } -static inline void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,int slot) +static inline void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) {gen_store32 (vaddr, src,1 , slot); } -static inline void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,int slot) +static inline void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store1 (cpu_env, vaddr, tmp, slot); } -static inline void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,int slot) +static inline void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) {gen_store32 (vaddr, src,2 , slot); } -static inline void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,int slot) +static inline void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store2 (cpu_env, vaddr, tmp, slot); } -static inline void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,int slot) +static inline void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) {gen_store32 (vaddr, src,4 , slot); } -static inline void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,int slot) +static inline void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store4 (cpu_env, vaddr, tmp, slot); } -static inline void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,int slot) +static inline void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,uint32_t slot) {tcg_gen_mov_tl (hex_store_addr[slot], vaddr);tcg_gen_movi_tl (hex_store_width[slot],8 );tcg_gen_mov_i64 (hex_store_val64[slot], src); } -static inline void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,int slot) +static inline void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,uint32_t slot) {TCGv_i64 tmp =tcg_constant_i64 (src);gen_store8 (cpu_env, vaddr, tmp, slot);
Signature · 1 line
2.17.1
[PULL 04/21] Hexagon (target/hexagon) Only use branch_taken when packet has multi cof
In reply to Taylor SimpsonWhen a packet has more than one change-of-flow instruction, only the first one to branch is considered. We use the branch_taken variable to keep track of this.
However, when there is a single cof instruction, we don't need the same amount of bookkeeping.
We add the pkt_has_multi_cof member to the Packet structure, and pass this information to the needed functions.
When there is a generated helper function with cof, the generator will pass this pkt_has_multi_cof as a runtime value.
Message-Id: <[email protected]>
--- target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/decode.c | 15 +++++++++++++-- target/hexagon/op_helper.c | 24 +++++++++++++++--------- target/hexagon/translate.c | 4 +++- target/hexagon/gen_helper_funcs.py | 5 ++++- target/hexagon/gen_helper_protos.py | 8 ++++++-- target/hexagon/gen_tcg_funcs.py | 5 +++++ target/hexagon/hex_common.py | 3 +++ 9 files changed, 51 insertions(+), 16 deletions(-)
target/hexagon/insn.h +1 -0
@@ -57,6 +57,7 @@ struct Packet {/* Pre-decodes about COF */ bool pkt_has_cof;/* Has any change-of-flow */ +bool pkt_has_multi_cof;/* Has more than one change-of-flow */ bool pkt_has_endloop;bool pkt_has_dczeroa;
target/hexagon/macros.h +1 -1
@@ -407,7 +407,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#define fCHECK_PCALIGN (A ) -#define fWRITE_NPC (A ) write_new_pc(env, A) +#define fWRITE_NPC (A ) write_new_pc(env, pkt_has_multi_cof != 0, A)#define fBRANCH (LOC ,TYPE ) fWRITE_NPC(LOC)#define fJUMPR (REGNO ,TARGET ,TYPE ) fBRANCH(TARGET, COF_TYPE_JUMPR)
target/hexagon/decode.c +13 -2
@@ -388,6 +388,7 @@ static void decode_set_insn_attr_fields(Packet *pkt)uint16_t opcode; pkt->pkt_has_cof = false; + pkt->pkt_has_multi_cof = false; pkt->pkt_has_endloop = false; pkt->pkt_has_dczeroa = false;
@@ -412,13 +413,23 @@ static void decode_set_insn_attr_fields(Packet *pkt) } } - pkt->pkt_has_cof |=decode_opcode_can_jump (opcode); +if (decode_opcode_can_jump (opcode)) { +if (pkt->pkt_has_cof) { + pkt->pkt_has_multi_cof = true; + } + pkt->pkt_has_cof = true; + } pkt->insn[i].is_endloop =decode_opcode_ends_loop (opcode); pkt->pkt_has_endloop |= pkt->insn[i].is_endloop; - pkt->pkt_has_cof |= pkt->pkt_has_endloop; +if (pkt->pkt_has_endloop) { +if (pkt->pkt_has_cof) { + pkt->pkt_has_multi_cof = true; + } + pkt->pkt_has_cof = true; + } } }
target/hexagon/op_helper.c +15 -9
@@ -104,20 +104,26 @@ static void log_store64(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data64 = val; } -static void write_new_pc (CPUHexagonState *env,target_ulong addr) +static void write_new_pc (CPUHexagonState *env,bool pkt_has_multi_cof, +target_ulong addr) {HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr); -/* -* If more than one branch is taken in a packet, only the first one -* is actually done. -*/ -if (env->branch_taken) { -HEX_DEBUG_LOG ("INFO: multiple branches taken in same packet, " -"ignoring the second one\n" ); +if (pkt_has_multi_cof) { +/* +* If more than one branch is taken in a packet, only the first one +* is actually done. +*/ +if (env->branch_taken) { +HEX_DEBUG_LOG ("INFO: multiple branches taken in same packet, " +"ignoring the second one\n" ); + }else { +fCHECK_PCALIGN (addr); + env->next_PC = addr; + env->branch_taken =1 ; + } }else {fCHECK_PCALIGN (addr); - env->branch_taken =1 ; env->next_PC = addr; } }
target/hexagon/translate.c +3 -1
@@ -248,7 +248,9 @@ static void gen_start_packet(DisasContext *ctx)tcg_gen_movi_tl (hex_slot_cancelled,0 ); }if (pkt->pkt_has_cof) { -tcg_gen_movi_tl (hex_branch_taken,0 ); +if (pkt->pkt_has_multi_cof) { +tcg_gen_movi_tl (hex_branch_taken,0 ); + }tcg_gen_movi_tl (hex_next_PC, next_PC); }if (need_pred_written (pkt)) {
target/hexagon/gen_helper_funcs.py +4 -1
@@ -1,7 +1,7 @@ #!/usr/bin/env python3 ## -## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +## Copyright(c) 2019-2022 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
@@ -238,6 +238,9 @@ def gen_helper_function(f, tag, tagregs, tagimms): gen_helper_arg_imm(f,immlett) i += 1 + if (hex_common.need_pkt_has_multi_cof(tag)): + f.write(", uint32_t pkt_has_multi_cof") + if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +6 -2
@@ -1,7 +1,7 @@ #!/usr/bin/env python3 ## -## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +## Copyright(c) 2019-2022 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
@@ -82,6 +82,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## Figure out how many arguments the helper will take if (numscalarresults == 0): def_helper_size = len(regs)+len(imms)+numscalarreadwrite+1 + if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
@@ -89,6 +90,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): f.write(', void' ) else: def_helper_size = len(regs)+len(imms)+numscalarreadwrite + if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag))
@@ -126,7 +128,9 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): for immlett,bits,immshift in imms: f.write(", s32") - ## Add the arguments for the instruction slot and part1 (if needed) + ## Add the arguments for the instruction pkt_has_multi_cof, slot and + ## part1 (if needed) + if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +5 -0
@@ -622,6 +622,9 @@ def gen_tcg_func(f, tag, regs, imms): ## Generate the call to the helper for immlett,bits,immshift in imms: gen_helper_decl_imm(f,immlett) + if hex_common.need_pkt_has_multi_cof(tag): + f.write(" TCGv pkt_has_multi_cof = ") + f.write("tcg_constant_tl(ctx->pkt->pkt_has_multi_cof);\n") if hex_common.need_part1(tag): f.write(" TCGv part1 = tcg_constant_tl(insn->part1);\n") if hex_common.need_slot(tag):
@@ -654,6 +657,8 @@ def gen_tcg_func(f, tag, regs, imms): for immlett,bits,immshift in imms: gen_helper_call_imm(f,immlett) + if hex_common.need_pkt_has_multi_cof(tag): + f.write(", pkt_has_multi_cof") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +3 -0
@@ -207,6 +207,9 @@ def need_part1(tag): def need_ea(tag): return re.compile(r"\bEA\b").search(semdict[tag]) +def need_pkt_has_multi_cof(tag): + return 'A_COF' in attribdict[tag] + def skip_qemu_helper(tag): return tag in overrides.keys()
Signature · 1 line
2.17.1
[PULL 17/21] target/hexagon: prepare input for the idef-parser
In reply to Taylor SimpsonFrom: Alessandro Di Federico <[email protected]>
Introduce infrastructure necessary to produce a file suitable for being parsed by the idef-parser. A build option is also added to fully disable the output of idef-parser, which is useful for debugging.
Message-Id: <[email protected]>
--- meson_options.txt | 3 + target/hexagon/gen_idef_parser_funcs.py | 130 ++++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 20 ++++ 5 files changed, 317 insertions(+) create mode 100644 target/hexagon/gen_idef_parser_funcs.py create mode 100644 target/hexagon/idef-parser/macros.inc create mode 100755 target/hexagon/idef-parser/prepare
meson_options.txt +3 -0
@@ -321,3 +321,6 @@ option('profiler', type: 'boolean', value: false, description: 'profiler support') option('slirp_smbd', type : 'feature', value : 'auto', description: 'use smbd (at path --smbd=*) in slirp networking') + +option('hexagon_idef_parser', type : 'boolean', value : true, + description: 'use idef-parser to automatically generate TCG code for the Hexagon frontend')
target/hexagon/gen_idef_parser_funcs.py new file +130 -0
130 lines not on this page · raw message
target/hexagon/idef-parser/macros.inc new file +140 -0
140 lines not on this page · raw message
target/hexagon/idef-parser/prepare new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/bash + +# +# Copyright(c) 2019-2021 rev.ng Labs Srl. 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/>. +# + +set -e +set -o pipefail + +# Run the preprocessor and drop comments +cpp "$@"
target/hexagon/meson.build +20 -0
@@ -21,6 +21,7 @@ hex_common_py = 'hex_common.py' attribs_def = meson.current_source_dir() / 'attribs_def.h.inc' gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h' gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h' +idef_parser_dir = meson.current_source_dir() / 'idef-parser' # # Step 1
@@ -179,4 +180,23 @@ hexagon_ss.add(files( 'mmvec/system_ext_mmvec.c', )) +idef_parser_enabled = get_option('hexagon_idef_parser') +if idef_parser_enabled and 'hexagon-linux-user' in target_dirs + idef_parser_input_generated = custom_target( + 'idef_parser_input.h.inc', + output: 'idef_parser_input.h.inc', + depends: [semantics_generated], + depend_files: [hex_common_py], + command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, attribs_def, '@OUTPUT@'], + ) + + preprocessed_idef_parser_input_generated = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + depend_files: [idef_parser_dir / 'macros.inc'], + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'], + ) +endif + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.17.1
Re: [PULL 17/21] target/hexagon: prepare input for the idef-parser
Quoted 27 lines · Taylor Simpson
From: Alessandro Di Federico <[email protected]>
Introduce infrastructure necessary to produce a file suitable for being parsed by the idef-parser. A build option is also added to fully disable the output of idef-parser, which is useful for debugging.
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Anton Johansson <[email protected]>Signed-off-by Taylor Simpson <[email protected]>Reviewed-by Taylor Simpson <[email protected]>Message-Id: <[email protected]>
--- meson_options.txt | 3 + target/hexagon/gen_idef_parser_funcs.py | 130 ++++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 20 ++++ 5 files changed, 317 insertions(+)create mode 100644
target/hexagon/gen_idef_parser_funcs.pycreate mode 100644 target/hexagon/idef-parser/macros.inc create mode 100755 target/hexagon/idef-parser/preparemeson_options.txt +0
-0
meson_options.txt option('profiler', type: 'boolean', value: false, · line 326
Quoted 6 lines
meson_options.txt +3
-0@@ -321,3 +321,6 @@ option('profiler', type: 'boolean', value: false, description: 'profiler support') option('slirp_smbd', type : 'feature', value : 'auto', description: 'use smbd (at path --smbd=*) in slirp networking') + +option('hexagon_idef_parser', type : 'boolean', value : true, + description: 'use idef-parser to automatically generate TCG code for the Hexagon frontend')
I'm now seeing changes to scripts/meson-buildoptions.sh after rebuilding QEMU ... looks like you likely forgot to update that file with the automatic update after changing meson_options.txt ?
Thomas
Re: [PULL 17/21] target/hexagon: prepare input for the idef-parser
Quoted 3 lines · On Thu, 29 Dec 2022 11:41:22 +0100 Thomas Huth <[email protected]> wrote:
I'm now seeing changes to
scripts/meson-buildoptions.shafter rebuilding QEMU ... looks like you likely forgot to update that file with the automatic update after changing meson_options.txt ?
Ah, there seems to be another couple of unrelated missing updates to scripts/meson-buildoptions.sh.
Makefile seems to rely on modification dates of files in the source tree, but git does not track those.
git clone ...
mkdir build
./configure ...
make update-buildoptions # Does nothing touch ../meson_options.txt
make update-buildoptions # Actually makes changes
Also, AFAIU the update-buildoptions target is not available in ninja. However maybe this is not a bug since the doc says to use make.
Anyway, patch coming soon!
Signature · 2 lines
Alessandro Di Federico rev.ng Labs
[PULL 11/21] Hexagon (target/hexagon) Use direct block chaining for tight loops
In reply to Taylor SimpsonDirect block chaining is documented here
https://qemu.readthedocs.io/en/latest/devel/tcg.html#direct-block-chaining
Hexagon inner loops end with the endloop0 instruction
To go back to the beginning of the loop, this instructions writes to PC from register SA0 (start address 0). To use direct block chaining, we have to assign PC with a constant value. So, we specialize the code generation when the start of the translation block is equal to SA0.
When this is the case, we defer the compare/branch from endloop0 to gen_end_tb. When this is done, we can assign the start address of the TB to PC.
Message-Id: <[email protected]>
--- target/hexagon/cpu.h | 13 +++--- target/hexagon/gen_tcg.h | 3 ++ target/hexagon/translate.h | 1 + target/hexagon/genptr.c | 84 ++++++++++++++++++++++++++++++++++++++ target/hexagon/translate.c | 33 +++++++++++++++ 5 files changed, 129 insertions(+), 5 deletions(-)
target/hexagon/cpu.h +8 -5
@@ -25,6 +25,7 @@#include "mmvec/mmvec.h" #include "qom/object.h" #include "hw/core/cpu.h" +#include "hw/registerfields.h" #define NUM_PREGS 4#define TOTAL_PER_THREAD_REGS 64
@@ -152,16 +153,18 @@ struct ArchCPU {#include "cpu_bits.h" +FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1) +static inline void cpu_get_tb_cpu_state (CPUHexagonState *env,target_ulong *pc,target_ulong *cs_base,uint32_t *flags) { +uint32_t hex_flags =0 ; *pc = env->gpr[HEX_REG_PC ]; *cs_base =0 ; -#ifdef CONFIG_USER_ONLY - *flags =0 ; -#else -#error System mode not supported on Hexagon yet -#endif +if (*pc == env->gpr[HEX_REG_SA0 ]) { + hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,IS_TIGHT_LOOP ,1 ); + } + *flags = hex_flags; }static inline int cpu_mmu_index (CPUHexagonState *env,bool ifetch)
target/hexagon/gen_tcg.h +3 -0
@@ -620,6 +620,9 @@#define fGEN_TCG_J2_callf (SHORTCODE ) \ gen_cond_call(ctx, PuV, TCG_COND_NE, riV) +#define fGEN_TCG_J2_endloop0 (SHORTCODE ) \ + gen_endloop0(ctx) +/* * Compound compare and jump instructions * Here is a primer to understand the tag names
target/hexagon/translate.h +1 -0
@@ -59,6 +59,7 @@ typedef struct DisasContext {bool pre_commit;TCGCond branch_cond;target_ulong branch_dest; +bool is_tight_loop; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
target/hexagon/genptr.c +84 -0
96 lines not on this page · raw message
target/hexagon/translate.c +33 -0
@@ -135,6 +135,8 @@ static void gen_goto_tb(DisasContext *ctx, int idx, target_ulong dest)static void gen_end_tb (DisasContext *ctx) { +Packet *pkt = ctx->pkt; +gen_exec_counters (ctx);if (ctx->branch_cond !=TCG_COND_NEVER ) {
@@ -147,6 +149,18 @@ static void gen_end_tb(DisasContext *ctx) }else {gen_goto_tb (ctx,0 , ctx->branch_dest); } + }else if (ctx->is_tight_loop && + pkt->insn[pkt->num_insns -1 ].opcode == J2_endloop0) { +/* +* When we're in a tight loop, we defer the endloop0 processing +* to take advantage of direct block chaining +*/ +TCGLabel *skip =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_LEU , hex_gpr[HEX_REG_LC0 ],1 , skip); +tcg_gen_subi_tl (hex_gpr[HEX_REG_LC0 ], hex_gpr[HEX_REG_LC0 ],1 ); +gen_goto_tb (ctx,0 , ctx->base.tb->pc); +gen_set_label (skip); +gen_goto_tb (ctx,1 , ctx->next_PC); }else {tcg_gen_lookup_and_goto_ptr (); }
@@ -337,6 +351,15 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum)*/ bool is_predicated =GET_ATTRIB (opcode,A_CONDEXEC ) || rnum ==HEX_REG_USR ; + +/* LC0/LC1 is conditionally written by endloop instructions */ +if ((rnum ==HEX_REG_LC0 || rnum ==HEX_REG_LC1 ) && + (opcode == J2_endloop0 || + opcode == J2_endloop1 || + opcode == J2_endloop01)) { + is_predicated = true; + } +if (is_predicated && !is_preloaded (ctx, rnum)) {tcg_gen_mov_tl (hex_new_value[rnum], hex_gpr[rnum]); }
@@ -420,6 +443,14 @@ static void gen_reg_writes(DisasContext *ctx)int reg_num = ctx->reg_log[i];tcg_gen_mov_tl (hex_gpr[reg_num], hex_new_value[reg_num]); + +/* +* ctx->is_tight_loop is set when SA0 points to the beginning of the TB. +* If we write to SA0, we have to turn off tight loop handling. +*/ +if (reg_num ==HEX_REG_SA0 ) { + ctx->is_tight_loop = false; + } } }
@@ -833,12 +864,14 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) {DisasContext *ctx =container_of (dcbase, DisasContext, base); +uint32_t hex_flags = dcbase->tb->flags; ctx->mem_idx =MMU_USER_IDX ; ctx->num_packets =0 ; ctx->num_insns =0 ; ctx->num_hvx_insns =0 ; ctx->branch_cond =TCG_COND_NEVER ; + ctx->is_tight_loop =FIELD_EX32 (hex_flags,TB_FLAGS ,IS_TIGHT_LOOP ); }static void hexagon_tr_tb_start (DisasContextBase *db,CPUState *cpu)
Signature · 1 line
2.17.1
[PULL 01/21] Hexagon (target/hexagon) Add pkt and insn to DisasContext
In reply to Taylor SimpsonThis enables us to reduce the number of parameters to many functions In particular, the generated functions previously took all 3 as arguments
Not only does this simplify the code, it improves the translation time
Message-Id: <[email protected]>
--- target/hexagon/gen_tcg_hvx.h | 6 +- target/hexagon/insn.h | 7 +- target/hexagon/macros.h | 10 +-- target/hexagon/mmvec/macros.h | 4 +- target/hexagon/translate.h | 9 ++- target/hexagon/genptr.c | 6 +- target/hexagon/translate.c | 120 +++++++++++++++++--------------- target/hexagon/gen_tcg_funcs.py | 15 ++-- 8 files changed, 89 insertions(+), 88 deletions(-)
target/hexagon/gen_tcg_hvx.h +3 -3
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 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
@@ -697,7 +697,7 @@ static inline void assert_vhist_tmp(DisasContext *ctx)#define fGEN_TCG_NEWVAL_VEC_STORE (GET_EA ,INC ) \ do { \ GET_EA; \ - gen_vreg_store(ctx, insn, pkt, EA, OsN_off, insn->slot, true); \ + gen_vreg_store(ctx, EA, OsN_off, insn->slot, true); \ INC; \ } while (0)
@@ -736,7 +736,7 @@ static inline void assert_vhist_tmp(DisasContext *ctx)PRED ; \tcg_gen_brcondi_tl (TCG_COND_EQ ,LSB ,0 , false_label); \tcg_temp_free (LSB ); \ -gen_vreg_store (ctx, insn, pkt,EA ,SRCOFF , insn->slot,ALIGN ); \ +gen_vreg_store (ctx,EA ,SRCOFF , insn->slot,ALIGN ); \INC ; \tcg_gen_br (end_label); \gen_set_label (false_label); \
target/hexagon/insn.h +2 -5
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 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
@@ -28,10 +28,7 @@ struct Instruction;struct Packet ;struct DisasContext ; -typedef void (*SemanticInsn )(CPUHexagonState *env, -struct DisasContext *ctx, -struct Instruction *insn, -struct Packet *pkt); +typedef void (*SemanticInsn )(struct DisasContext *ctx);struct Instruction {SemanticInsn generate;/* pointer to genptr routine */
target/hexagon/macros.h +5 -5
@@ -94,9 +94,9 @@*/ #define CHECK_NOSHUF (VA ,SIZE ) \ do { \ - if (insn->slot == 0 && pkt->pkt_has_store_s1) { \ + if (insn->slot == 0 && ctx->pkt->pkt_has_store_s1) { \ probe_noshuf_load(VA, SIZE, ctx->mem_idx); \ - process_store(ctx, pkt, 1); \ + process_store(ctx, 1); \ } \ } while (0)
@@ -105,12 +105,12 @@TCGLabel *label =gen_new_label (); \tcg_gen_brcondi_tl (TCG_COND_EQ ,PRED ,0 , label); \GET_EA ; \ -if (insn->slot ==0 && pkt->pkt_has_store_s1) { \ +if (insn->slot ==0 && ctx->pkt->pkt_has_store_s1) { \probe_noshuf_load (EA ,SIZE , ctx->mem_idx); \ } \gen_set_label (label); \ -if (insn->slot ==0 && pkt->pkt_has_store_s1) { \ -process_store (ctx, pkt,1 ); \ +if (insn->slot ==0 && ctx->pkt->pkt_has_store_s1) { \ +process_store (ctx,1 ); \ } \ }while (0 )
target/hexagon/mmvec/macros.h +2 -2
@@ -288,7 +288,7 @@#endif #ifdef QEMU_GENERATE #define fSTOREMMV (EA ,SRC ) \ - gen_vreg_store(ctx, insn, pkt, EA, SRC##_off, insn->slot, true) + gen_vreg_store(ctx, EA, SRC##_off, insn->slot, true)#endif #ifdef QEMU_GENERATE #define fSTOREMMVQ (EA ,SRC ,MASK ) \
@@ -300,7 +300,7 @@#endif #ifdef QEMU_GENERATE #define fSTOREMMVU (EA ,SRC ) \ - gen_vreg_store(ctx, insn, pkt, EA, SRC##_off, insn->slot, false) + gen_vreg_store(ctx, EA, SRC##_off, insn->slot, false)#endif #define fVFOREACH (WIDTH ,VAR ) for (VAR = 0; VAR < fVELEM(WIDTH); VAR++)#define fVARRAY_ELEMENT_ACCESS (ARRAY ,TYPE ,INDEX ) \
target/hexagon/translate.h +6 -3
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 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
@@ -23,10 +23,13 @@#include "cpu.h" #include "exec/translator.h" #include "tcg/tcg-op.h" +#include "insn.h" #include "internal.h" typedef struct DisasContext { DisasContextBase base; + Packet *pkt; + Insn *insn; uint32_t mem_idx; uint32_t num_packets; uint32_t num_insns;
@@ -147,6 +150,6 @@ extern TCGv hex_vstore_addr[VSTORES_MAX];extern TCGv hex_vstore_size[VSTORES_MAX ];extern TCGv hex_vstore_pending[VSTORES_MAX ]; -bool is_gather_store_insn (Insn *insn,Packet *pkt); -void process_store (DisasContext *ctx,Packet *pkt,int slot_num); +bool is_gather_store_insn (DisasContext *ctx); +void process_store (DisasContext *ctx,int slot_num);#endif
target/hexagon/genptr.c +3 -3
@@ -551,13 +551,13 @@ static void gen_vreg_load(DisasContext *ctx, intptr_t dstoff, TCGv src,tcg_temp_free_i64 (tmp); } -static void gen_vreg_store (DisasContext *ctx,Insn *insn,Packet *pkt, -TCGv EA ,intptr_t srcoff,int slot,bool aligned) +static void gen_vreg_store (DisasContext *ctx,TCGv EA ,intptr_t srcoff, +int slot,bool aligned) { intptr_t dstoff = offsetof(CPUHexagonState, vstore[slot].data); intptr_t maskoff = offsetof(CPUHexagonState, vstore[slot].mask); -if (is_gather_store_insn (insn, pkt)) { +if (is_gather_store_insn (ctx)) {TCGv sl =tcg_constant_tl (slot);gen_helper_gather_store (cpu_env,EA , sl);return ;
target/hexagon/translate.c +63 -57
270 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +5 -10
@@ -561,11 +561,7 @@ def genptr_dst_write_opn(f,regtype, regid, tag): ## Generate the TCG code to call the helper ## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} ## We produce: -## static void generate_A2_add() -## CPUHexagonState *env -## DisasContext *ctx, -## Insn *insn, -## Packet *pkt) +## static void generate_A2_add(DisasContext *ctx) ## { ## TCGv RdV = tcg_temp_local_new(); ## const int RdN = insn->regno[0];
@@ -584,12 +580,11 @@ def genptr_dst_write_opn(f,regtype, regid, tag): ## <GEN> is gen_helper_A2_add(RdV, cpu_env, RsV, RtV); ## def gen_tcg_func(f, tag, regs, imms): - f.write("static void generate_%s(\n" %tag) - f.write(" CPUHexagonState *env,\n") - f.write(" DisasContext *ctx,\n") - f.write(" Insn *insn,\n") - f.write(" Packet *pkt)\n") + f.write("static void generate_%s(DisasContext *ctx)\n" %tag) f.write('{\n') + + f.write(" Insn *insn __attribute__((unused)) = ctx->insn;\n") + if hex_common.need_ea(tag): gen_decl_ea_tcg(f, tag) i=0 ## Declare all the operands (regs and immediates)
Signature · 1 line
2.17.1
[PULL 21/21] target/hexagon: import additional tests
In reply to Taylor SimpsonFrom: Niccolò Izzo <[email protected]>
Message-Id: <[email protected]>
--- tests/tcg/hexagon/Makefile.target | 28 ++++++++++++- tests/tcg/hexagon/crt.S | 14 +++++++ tests/tcg/hexagon/test_abs.S | 17 ++++++++ tests/tcg/hexagon/test_bitcnt.S | 40 +++++++++++++++++++ tests/tcg/hexagon/test_bitsplit.S | 22 ++++++++++ tests/tcg/hexagon/test_call.S | 64 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_clobber.S | 29 ++++++++++++++ tests/tcg/hexagon/test_cmp.S | 31 +++++++++++++++ tests/tcg/hexagon/test_dotnew.S | 38 ++++++++++++++++++ tests/tcg/hexagon/test_ext.S | 13 ++++++ tests/tcg/hexagon/test_fibonacci.S | 30 ++++++++++++++ tests/tcg/hexagon/test_hl.S | 16 ++++++++ tests/tcg/hexagon/test_hwloops.S | 19 +++++++++ tests/tcg/hexagon/test_jmp.S | 22 ++++++++++ tests/tcg/hexagon/test_lsr.S | 36 +++++++++++++++++ tests/tcg/hexagon/test_mpyi.S | 17 ++++++++ tests/tcg/hexagon/test_packet.S | 29 ++++++++++++++ tests/tcg/hexagon/test_reorder.S | 33 +++++++++++++++ tests/tcg/hexagon/test_round.S | 29 ++++++++++++++ tests/tcg/hexagon/test_vavgw.S | 31 +++++++++++++++ tests/tcg/hexagon/test_vcmpb.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vcmpw.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vlsrw.S | 20 ++++++++++ tests/tcg/hexagon/test_vmaxh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vminh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vpmpyh.S | 28 +++++++++++++ tests/tcg/hexagon/test_vspliceb.S | 31 +++++++++++++++ 27 files changed, 766 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/crt.S create mode 100644 tests/tcg/hexagon/test_abs.S create mode 100644 tests/tcg/hexagon/test_bitcnt.S create mode 100644 tests/tcg/hexagon/test_bitsplit.S create mode 100644 tests/tcg/hexagon/test_call.S create mode 100644 tests/tcg/hexagon/test_clobber.S create mode 100644 tests/tcg/hexagon/test_cmp.S create mode 100644 tests/tcg/hexagon/test_dotnew.S create mode 100644 tests/tcg/hexagon/test_ext.S create mode 100644 tests/tcg/hexagon/test_fibonacci.S create mode 100644 tests/tcg/hexagon/test_hl.S create mode 100644 tests/tcg/hexagon/test_hwloops.S create mode 100644 tests/tcg/hexagon/test_jmp.S create mode 100644 tests/tcg/hexagon/test_lsr.S create mode 100644 tests/tcg/hexagon/test_mpyi.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
tests/tcg/hexagon/Makefile.target +27 -1
@@ -24,7 +24,7 @@ CFLAGS += -fno-unroll-loops HEX_SRC=$(SRC_PATH)/tests/tcg/hexagon VPATH += $(HEX_SRC) -first: $(HEX_SRC)/first.S +%: $(HEX_SRC)/%.S $(HEX_SRC)/crt.S $(CC) -static -mv67 -nostdlib $^ -o $@ HEX_TESTS = first
@@ -44,6 +44,32 @@ HEX_TESTS += atomics HEX_TESTS += fpstuff HEX_TESTS += overflow +HEX_TESTS += test_abs +HEX_TESTS += test_bitcnt +HEX_TESTS += test_bitsplit +HEX_TESTS += test_call +HEX_TESTS += test_clobber +HEX_TESTS += test_cmp +HEX_TESTS += test_dotnew +HEX_TESTS += test_ext +HEX_TESTS += test_fibonacci +HEX_TESTS += test_hl +HEX_TESTS += test_hwloops +HEX_TESTS += test_jmp +HEX_TESTS += test_lsr +HEX_TESTS += test_mpyi +HEX_TESTS += test_packet +HEX_TESTS += test_reorder +HEX_TESTS += test_round +HEX_TESTS += test_vavgw +HEX_TESTS += test_vcmpb +HEX_TESTS += test_vcmpw +HEX_TESTS += test_vlsrw +HEX_TESTS += test_vmaxh +HEX_TESTS += test_vminh +HEX_TESTS += test_vpmpyh +HEX_TESTS += test_vspliceb + TESTS += $(HEX_TESTS) # This test has to be compiled for the -mv67t target
tests/tcg/hexagon/crt.S new file +14 -0
@@ -0,0 +1,14 @@ +#define SYS_exit_group 94 + + .text + .globl pass +pass: + r0 = #0 + r6 = #SYS_exit_group + trap0(#1) + + .globl fail +fail: + r0 = #1 + r6 = #SYS_exit_group + trap0(#1)
tests/tcg/hexagon/test_abs.S new file +17 -0
@@ -0,0 +1,17 @@ +/* Purpose: test example, verify the soundness of the abs operation */ + + .text + .globl _start + +_start: + { + r1 = #-2 + r2 = #2 + } + { + r3 = abs(r1) + } + { + p0 = cmp.eq(r3, r2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitcnt.S new file +40 -0
@@ -0,0 +1,40 @@ +/* + * Purpose: test example, verify the soundness of the cl[01] operations. + * + * The number 0x000001aa has 23 leading zeroes + * they become 55 when considered as 64 bit register + * and it has 1 trailing zero. + */ + .text + .globl _start + +_start: + { + r0 = #426 + r1 = #0 + } + { + r2 = cl0(r0) + } + { + p0 = cmp.eq(r2, #23); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r2 = cl0(r1:0) + } + { + p0 = cmp.eq(r2, #55); if (p0.new) jump:t test3 + jump fail + } + +test3: + { + r2 = ct0(r0) + } + { + p0 = cmp.eq(r2, #1); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitsplit.S new file +22 -0
@@ -0,0 +1,22 @@ +/* Purpose: test example, verify the soundness of the bitsplit operation */ + + .text + .globl _start + +_start: + { + r1 = #187 + } + { + r3:2 = bitsplit(r1, #3) + } + { + p0 = cmp.eq(r2, #3); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #23); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_call.S new file +64 -0
64 lines not on this page · raw message
tests/tcg/hexagon/test_clobber.S new file +29 -0
@@ -0,0 +1,29 @@ +/* + * Purpose: demonstrate the succesful operation of the register save mechanism, + * in which the caller saves the registers that will be clobbered, and restores + * them after the call. + */ + + .text + .globl _start + +_start: + allocframe(#8) + { + r16 = #47 + r17 = #155 + } + memd(sp+#0) = r17:16 + { + r16 = #255 + r17 = #42 + } + { + deallocframe + r17:16 = memd(sp+#0) + } + { + p0 = cmp.eq(r16, #47) + p0 = cmp.eq(r17, #155); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_cmp.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test a signed and unsigned comparison */ + + .text + .globl _start + +_start: + { + jump signed + } + + .globl signed +signed: + { + r0 = #-2 + r1 = #0 + } + { + p0 = cmp.lt(r0, r1); if (p0.new) jump:t unsigned + jump fail + } + + .globl unsigned +unsigned: + { + r0 = #-2 + r1 = #0 + } + { + p0 = cmp.gtu(r0, r1); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_dotnew.S new file +38 -0
@@ -0,0 +1,38 @@ +/* Purpose: test the .new operator while performing memory stores. */ + + .text + .globl _start + +_start: + { + allocframe(#16) + } + { + r0 = #1 + memw(sp+#0) = r0.new + } + { + r1 = #2 + memw(sp+#4) = r1.new + } + { + r2 = #3 + memw(sp+#8) = r2.new + } + { + r0 = memw(sp+#8) + } + { + r1 = memw(sp+#4) + } + { + r2 = memw(sp+#0) + } + { + r3 = mpyi(r1, r2) + } + { + deallocframe + p0 = cmp.eq(r3, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_ext.S new file +13 -0
@@ -0,0 +1,13 @@ +/* Purpose: test immediate extender instructions. */ + + .text + .globl _start + +_start: + { + r2 = ##-559038737 + } + { + p0 = cmp.eq(r2, ##-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_fibonacci.S new file +30 -0
@@ -0,0 +1,30 @@ +/* Purpose: computes the Fibonacci series up to a constant number. */ + + .text + .globl _start + +_start: + { + r2 = #100 + } + { + p0 = cmp.gt(r2, #0); if (!p0.new) jump:nt .LBB0_3 + } + { + r3 = #0 + r4 = #1 + } +.LBB0_2: + { + r5 = r4 + } + { + p0 = cmp.gt(r2, r5); if (p0.new) jump:nt .LBB0_2 + r4 = add(r3, r4) + r3 = r5 + } +.LBB0_3: + { + p0 = cmp.eq(r3, #144); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hl.S new file +16 -0
@@ -0,0 +1,16 @@ +/* Purpose: test example, verify the soundness of the high/low assignment */ + + .text + .globl _start + +_start: + { + r0.H = #42 + } + { + r0.L = #69 + } + { + p0 = cmp.eq(r0, #2752581); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hwloops.S new file +19 -0
@@ -0,0 +1,19 @@ +/* Purpose: simple C Program to test hardware loops. */ + + .text + .globl _start + +_start: + { + loop0(.LBB0_1, #10) + r2 = #0 + } +.LBB0_1: + { + r2 = add(r2, #1) + nop + }:endloop0 + { + p0 = cmp.eq(r2, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_jmp.S new file +22 -0
@@ -0,0 +1,22 @@ +/* Purpose: test example, verify the soundness of the jump operation */ + +#define SYS_exit_group 94 + + .text + .globl _start + +_start: + { + jump pass + } + /* + * Inlined fail label in crt.S so we can fail without + * having a functioning jump + */ + { + r0 = #1 + r6 = #SYS_exit_group + } + { + trap0(#1) + }
tests/tcg/hexagon/test_lsr.S new file +36 -0
@@ -0,0 +1,36 @@ +/* Purpose: test the soundness of the lsr operation */ + + .text + .globl _start + +_start: + { + r0 = #-56984 + r1 = #2147483647 + } + { + r2 = #0x19 + } + { + r0 &= lsr(r1, r2) + } + { + p0 = cmp.eq(r0, #0x28); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r0 = #0x0000000a + r1 = #0x00000000 + } + { + r2 = #-1 + } + { + r1:0 = lsl(r1:0, r2) + } + { + p0 = cmp.eq(r0, #0x5); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_mpyi.S new file +17 -0
@@ -0,0 +1,17 @@ +/* Purpose: test a simple multiplication operation */ + + .text + .globl _start + +_start: + { + r1 = #4 + r2 = #6 + } + { + r3 = mpyi(r1, r2) + } + { + p0 = cmp.eq(r3, #24); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_packet.S new file +29 -0
@@ -0,0 +1,29 @@ +/* + * Purpose: test that writes of a register in a packet are performed only after + * that packet has finished its execution. + */ + + .text + .globl _start + +_start: + { + allocframe(#8) + } + { + r2 = #4 + r3 = #6 + } + { + memw(sp+#0) = r2 + } + { + r3 = memw(sp+#0) + r0 = add(r2, r3) + } + { + deallocframe + p0 = cmp.eq(r3, #4) + p0 = cmp.eq(r0, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_reorder.S new file +33 -0
@@ -0,0 +1,33 @@ +/* + * Purpose: demonstrate handling of .new uses appearing before the associated + * definition. + * Here we perform a jump that skips the code resetting R2 from 0xDEADBEEF to 0, + * only if P0.new is true, but P0 is assigned to 1 (R4) in the next instruction + * in the packet. + */ + + .text + .globl _start + +_start: + { + r2 = #-559038737 + } + { + r4 = #1 + } + { + if (p0.new) jump:nt skip + p0 = r4; + } + +fallthrough: + { + r2 = #0 + } + +skip: + { + p0 = cmp.eq(r2, #-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_round.S new file +29 -0
@@ -0,0 +1,29 @@ +/* + * Purpose: test example, verify the soundness of the cround operation + * 106 = 0b1101010 with the comma at third digit is 12.5 which is crounded to 12 + * but rounded to 13. + */ + + .text + .globl _start + +_start: + { + r1 = #200 + } + { + r2 = round(r1, #4) + } + { + p0 = cmp.eq(r2, #13); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r2 = cround(r1, #4) + } + { + p0 = cmp.eq(r2, #12); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vavgw.S new file +31 -0
@@ -0,0 +1,31 @@ +/* + * Purpose: test example, verify the soundness of the vavgw operation. + * + * 0x00030001 averaged with 0x00010003 results 0x00020002. + */ + + .text + .globl _start + +_start: + { + r0 = #3 + r1 = #1 + } + { + r2 = #1 + r3 = #3 + } + { + r1:0 = vavgw(r1:0, r3:2):crnd + } + { + p0 = cmp.eq(r0, #2); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpb.S new file +30 -0
@@ -0,0 +1,30 @@ +/* + * Purpose: test example, verify the soundness of the vector compare bytes + * operation. + * + * Vector byte comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0b11110000 in binary, or 0xf0 in hex. + */ + + .text + .globl _start + +_start: + { + r0 = #0x87654321 + r1 = #0x12345678 + } + { + r2 = #0x00000000 + r3 = #0x12345678 + } + { + p2 = vcmpb.eq(r1:0, r3:2) + } + { + r4 = p2 + } + { + p0 = cmp.eq(r4, #0xf0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpw.S new file +30 -0
@@ -0,0 +1,30 @@ +/* + * Purpose: test example, verify the soundness of the vector compare words + * operation. + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0b11110000 in binary, or 0xf0 in hex. + */ + + .text + .globl _start + +_start: + { + r0 = #0x87654321 + r1 = #0x12345678 + } + { + r2 = #0x00000000 + r3 = #0x12345678 + } + { + p2 = vcmpw.eq(r1:0, r3:2) + } + { + r4 = p2 + } + { + p0 = cmp.eq(r4, #0xf0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vlsrw.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test the soundness of the vlsrw operation */ + + .text + .globl _start + +_start: + { + r0 = #0x00000001 + r1 = #0x00000001 + } + { + r1:0 = vlsrw(r1:0, #1) + } + { + r0 = add(r0, r1) + } + { + p0 = cmp.eq(r0, #0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vmaxh.S new file +35 -0
@@ -0,0 +1,35 @@ +/* + * Purpose: test example, verify the soundness of the vrmaxh operation. + * + * The maximum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * input: r1 = 0x00010003 r0 = 0x00010005 r3 = 0x00030002 r2 = 0x00020007 + * output: r1 = 0x00030003 r0 = 0x00020007 + */ + + .text + .globl _start + +_start: + { + r0 = #65541 + r1 = #65539 + } + { + r2 = #131079 + r3 = #196610 + } + { + r1:0 = vmaxh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #131079); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #196611); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vminh.S new file +35 -0
@@ -0,0 +1,35 @@ +/* + * Purpose: test example, verify the soundness of the vrmaxh operation. + * + * The minimum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * input: r1 = 0x00010003 r0 = 0x00010005 r3 = 0x00030002 r2 = 0x00020007 + * output: r1 = 0x00010002 r0 = 0x00010005 + */ + + .text + .globl _start + +_start: + { + r0 = #65541 + r1 = #65539 + } + { + r2 = #131079 + r3 = #196610 + } + { + r1:0 = vminh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #65541); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #65538); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vpmpyh.S new file +28 -0
@@ -0,0 +1,28 @@ +/* + * Purpose: test example, verify the soundness of the vpmpyh operator. + * + * 0x01020304 vector polynomial multiplied with 0x04030201 results + * 0x000400060b060b04. + */ + + .text + .globl _start + +_start: + { + r0 = #16909060 + r1 = #67305985 + } + { + r1:0 = vpmpyh(r0, r1) + } + { + p0 = cmp.eq(r0, #184945412); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #262150); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vspliceb.S new file +31 -0
@@ -0,0 +1,31 @@ +/* + * Purpose: test example, verify the soundness of the vspliceb operation + * the operation is a binary splice of two 64bit operators. + * + * vspliceb(0xffffffffffffffff,0x0000000000000000,5) = 0x000000ffffffffff. + */ + .text + .globl _start + +_start: + { + r0 = #-1 + r1 = #-1 + } + { + r2 = #0 + r3 = #0 + } + { + r5:4 = vspliceb(r1:0, r3:2, #5) + } + { + p0 = cmp.eq(r4, #-1); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r5, #255); if (p0.new) jump:t pass + jump fail + }
Signature · 1 line
2.17.1
[PULL 03/21] Hexagon (target/hexagon) Add overrides for S2_asr_r_r_sat/S2_asl_r_r_sat
In reply to Taylor SimpsonThese instructions will not be generated by idef-parser, so we override them manually.
Test cases added to tests/tcg/hexagon/usr.c
Message-Id: <[email protected]>
--- target/hexagon/gen_tcg.h | 10 +++- target/hexagon/genptr.c | 104 +++++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/usr.c | 34 ++++++++++--- 3 files changed, 141 insertions(+), 7 deletions(-)
target/hexagon/gen_tcg.h +9 -1
@@ -1,5 +1,5 @@/* -* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* Copyright(c) 2019-2022 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
@@ -612,6 +612,14 @@tcg_temp_free (tmp); \ }while (0 ) +/* r0 = asr(r1, r2):sat */ +#define fGEN_TCG_S2_asr_r_r_sat (SHORTCODE ) \ + gen_asr_r_r_sat(RdV, RsV, RtV) + +/* r0 = asl(r1, r2):sat */ +#define fGEN_TCG_S2_asl_r_r_sat (SHORTCODE ) \ + gen_asl_r_r_sat(RdV, RsV, RtV) +/* Floating point */ #define fGEN_TCG_F2_conv_sf2df (SHORTCODE ) \ gen_helper_conv_sf2df(RddV, cpu_env, RsV)
target/hexagon/genptr.c +104 -0
110 lines not on this page · raw message
tests/tcg/hexagon/usr.c +28 -6
@@ -429,6 +429,7 @@ FUNC_P_OP_P(vabshsat, "%0 = vabsh(%2):sat") FUNC_P_OP_PP(vnavgwr, "%0 = vnavgw(%2, %3):rnd:sat") FUNC_R_OP_RI(round_ri_sat, "%0 = round(%2, #%3):sat") FUNC_R_OP_RR(asr_r_r_sat, "%0 = asr(%2, %3):sat") +FUNC_R_OP_RR(asl_r_r_sat, "%0 = asl(%2, %3):sat")FUNC_XPp_OP_PP (ACS ,"%0, p2 = vacsh(%3, %4)" )
@@ -907,12 +908,33 @@ int main()TEST_R_OP_RI (round_ri_sat,0x0000ffff ,2 ,0x00004000 ,USR_CLEAR );TEST_R_OP_RI (round_ri_sat,0x7fffffff ,2 ,0x1fffffff ,USR_OVF ); -TEST_R_OP_RR (asr_r_r_sat,0x0000ffff ,0x00000002 ,0x00003fff , -USR_CLEAR ); -TEST_R_OP_RR (asr_r_r_sat,0x00ffffff ,0xfffffff5 ,0x7fffffff , -USR_OVF ); -TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0xfffffff5 ,0x80000000 , -USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x0000ffff ,0x02 ,0x00003fff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0x01 ,0xc0000000 ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0xffffffff ,0x01 ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,0x00ffffff ,0xf5 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x80000000 ,0xf5 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0x7fff0000 ,0x42 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0xff000000 ,0x42 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,4096 ,32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,4096 ,-32 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,-4096 ,32 ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,-4096 ,-32 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asr_r_r_sat,0 ,-32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asr_r_r_sat,1 ,-32 ,0x7fffffff ,USR_OVF ); + +TEST_R_OP_RR (asl_r_r_sat,0x00000000 ,0x40 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0x80000000 ,0xff ,0xc0000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0xffffffff ,0xff ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0x00ffffff ,0x0b ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0x80000000 ,0x0b ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0x7fff0000 ,0xbe ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,0xff000000 ,0xbe ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,4096 ,32 ,0x7fffffff ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,4096 ,-32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,-4096 ,32 ,0x80000000 ,USR_OVF ); +TEST_R_OP_RR (asl_r_r_sat,-4096 ,-32 ,0xffffffff ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,0 ,32 ,0x00000000 ,USR_CLEAR ); +TEST_R_OP_RR (asl_r_r_sat,1 ,32 ,0x7fffffff ,USR_OVF ); TEST_XPp_OP_PP(ACS, 0x0004000300020001ULL, 0x0001000200030004ULL, 0x0000000000000000ULL, 0x0004000300030004ULL, 0xf0,
Signature · 1 line
2.17.1
[PULL 13/21] target/hexagon: import README for idef-parser
In reply to Taylor SimpsonFrom: Alessandro Di Federico <[email protected]>
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/README.rst | 722 ++++++++++++++++++++++++++ target/hexagon/README | 5 + 2 files changed, 727 insertions(+) create mode 100644 target/hexagon/idef-parser/README.rst
target/hexagon/idef-parser/README.rst new file +722 -0
@@ -0,0 +1,722 @@ +Hexagon ISA instruction definitions to tinycode generator compiler +------------------------------------------------------------------ + +idef-parser is a small compiler able to translate the Hexagon ISA description +language into tinycode generator code, that can be easily integrated into QEMU. + +Compilation Example +------------------- + +To better understand the scope of the idef-parser, we'll explore an applicative +example. Let's start by one of the simplest Hexagon instruction: the ``add``. + +The ISA description language represents the ``add`` instruction as +follows: + +.. code:: c + + A2_add(RdV, in RsV, in RtV) { + { RdV=RsV+RtV;} + } + +idef-parser will compile the above code into the following code: + +.. code:: c + + /* A2_add */ + void emit_A2_add(DisasContext *ctx, Insn *insn, Packet *pkt, TCGv_i32 RdV, + TCGv_i32 RsV, TCGv_i32 RtV) + /* { RdV=RsV+RtV;} */ + { + TCGv_i32 tmp_0 = tcg_temp_new_i32(); + tcg_gen_add_i32(tmp_0, RsV, RtV); + tcg_gen_mov_i32(RdV, tmp_0); + tcg_temp_free_i32(tmp_0); + } + +The output of the compilation process will be a function, containing the +tinycode generator code, implementing the correct semantics. That function will +not access any global variable, because all the accessed data structures will be +passed explicitly as function parameters. Among the passed parameters we will +have TCGv (tinycode variables) representing the input and output registers of +the architecture, integers representing the immediates that come from the code, +and other data structures which hold information about the disassemblation +context (``DisasContext`` struct). + +Let's begin by describing the input code. The ``add`` instruction is associated +with a unique identifier, in this case ``A2_add``, which allows to distinguish +variants of the same instruction, and expresses the class to which the +instruction belongs, in this case ``A2`` corresponds to the Hexagon +``ALU32/ALU`` instruction subclass. + +After the instruction identifier, we have a series of parameters that represents +TCG variables that will be passed to the generated function. Parameters marked +with ``in`` are already initialized, while the others are output parameters. + +We will leverage this information to infer several information: + +- Fill in the output function signature with the correct TCGv registers +- Fill in the output function signature with the immediate integers +- Keep track of which registers, among the declared one, have been + initialized + +Let's now observe the actual instruction description code, in this case: + +.. code:: c + + { RdV=RsV+RtV;} + +This code is composed by a subset of the C syntax, and is the result of the +application of some macro definitions contained in the ``macros.h`` file. + +This file is used to reduce the complexity of the input language where complex +variants of similar constructs can be mapped to a unique primitive, so that the +idef-parser has to handle a lower number of computation primitives. + +As you may notice, the description code modifies the registers which have been +declared by the declaration statements. In this case all the three registers +will be declared, ``RsV`` and ``RtV`` will also be read and ``RdV`` will be +written. + +Now let's have a quick look at the generated code, line by line. + +:: + + TCGv_i32 tmp_0 = tcg_temp_new_i32(); + +This code starts by declaring a temporary TCGv to hold the result from the sum +operation. + +:: + + tcg_gen_add_i32(tmp_0, RsV, RtV); + +Then, we are generating the sum tinycode operator between the selected +registers, storing the result in the just declared temporary. + +:: + + tcg_gen_mov_i32(RdV, tmp_0); + +The result of the addition is now stored in the temporary, we move it into the +correct destination register. This code may seem inefficient, but QEMU will +perform some optimizations on the tinycode, reducing the unnecessary copy. + +:: + + tcg_temp_free_i32(tmp_0); + +Finally, we free the temporary we used to hold the addition result. + +Parser Input +------------ + +Before moving on to the structure of idef-parser itself, let us spend some words +on its' input. There are two preprocessing steps applied to the generated +instruction semantics in ``semantics_generated.pyinc`` that we need to consider. +Firstly, + +:: + + gen_idef_parser_funcs.py + +which takes instruction semantics in ``semantics_generated.pyinc`` to C-like +pseudo code, output into ``idef_parser_input.h.inc``. For instance, the +``J2_jumpr`` instruction which jumps to an address stored in a register +argument. This is instruction is defined as + +:: + + SEMANTICS( \ + "J2_jumpr", \ + "jumpr Rs32", \ + """{fJUMPR(RsN,RsV,COF_TYPE_JUMPR);}""" \ + ) + +in ``semantics_generated.pyinc``. Running ``gen_idef_parser_funcs.py`` +we obtain the pseudo code + +:: + + J2_jumpr(in RsV) { + {fJUMPR(RsN,RsV,COF_TYPE_JUMPR);} + } + +with macros such as ``fJUMPR`` intact. + +The second step is to expand macros into a form suitable for our parser. +These macros are defined in ``idef-parser/macros.inc`` and the step is +carried out by the ``prepare`` script which runs the C preprocessor on +``idef_parser_input.h.inc`` to produce +``idef_parser_input.preprocessed.h.inc``. + +To finish the above example, after preprocessing ``J2_jumpr`` we obtain + +:: + + J2_jumpr(in RsV) { + {(PC = RsV);} + } + +where ``fJUMPR(RsN,RsV,COF_TYPE_JUMPR);`` was expanded to ``(PC = RsV)``, +signifying a write to the Program Counter ``PC``. Note, that ``PC`` in +this expression is not a variable in the strict C sense since it is not +declared anywhere, but rather a symbol which is easy to match in +idef-parser later on. + +Parser Structure +---------------- + +The idef-parser is built using the ``flex`` and ``bison``. + +``flex`` is used to split the input string into tokens, each described using a +regular expression. The token description is contained in the +``idef-parser.lex`` source file. The flex-generated scanner takes care also to +extract from the input text other meaningful information, e.g., the numerical +value in case of an immediate constant, and decorates the token with the +extracted information. + +``bison`` is used to generate the actual parser, starting from the parsing +description contained in the ``idef-parser.y`` file. The generated parser +executes the ``main`` function at the end of the ``idef-parser.y`` file, which +opens input and output files, creates the parsing context, and eventually calls +the ``yyparse()`` function, which starts the execution of the LALR(1) parser +(see `Wikipedia <https://en.wikipedia.org/wiki/LALR_parser>`__ for more +information about LALR parsing techniques). The LALR(1) parser, whenever it has +to shift a token, calls the ``yylex()`` function, which is defined by the +flex-generated code, and reads the input file returning the next scanned token. + +The tokens are mapped on the source language grammar, defined in the +``idef-parser.y`` file to build a unique syntactic tree, according to the +specified operator precedences and associativity rules. + +The grammar describes the whole file which contains the Hexagon instruction +descriptions, therefore it starts from the ``input`` nonterminal, which is a +list of instructions, each instruction is represented by the following grammar +rule, representing the structure of the input file shown above: + +:: + + instruction : INAME arguments code + | error + + arguments : '(' ')' + | '(' argument_list ')'; + + argument_list : argument_decl ',' argument_list + | argument_decl + + argument_decl : REG + | PRED + | IN REG + | IN PRED + | IMM + | var + ; + + code : '{' statements '}' + + statements : statements statement + | statement + + statement : control_statement + | var_decl ';' + | rvalue ';' + | code_block + | ';' + + code_block : '{' statements '}' + | '{' '}' + +With this initial portion of the grammar we are defining the instruction, its' +arguments, and its' statements. Each argument is defined by the +``argument_decl`` rule, and can be either + +:: + + Description Example + ---------------------------------------- + output register RsV + output predicate register P0 + input register in RsV + input predicate register in P0 + immediate value 1234 + local variable EA + +Note, the only local variable allowed to be used as an argument is the effective +address ``EA``. Similarly, each statement can be a ``control_statement``, a +variable declaration such as ``int a;``, a code block, which is just a +bracket-enclosed list of statements, a ``';'``, which is a ``nop`` instruction, +and an ``rvalue ';'``. + +Expressions +~~~~~~~~~~~ + +Allowed in the input code are C language expressions with a few exceptions +to simplify parsing. For instance, variable names such as ``RdV``, ``RssV``, +``PdV``, ``CsV``, and other idiomatic register names from Hexagon, are +reserved specifically for register arguments. These arguments then map to +``TCGv_i32`` or ``TCGv_i64`` depending on the register size. Similarly, ``UiV``, +``riV``, etc. refer to immediate arguments and will map to C integers. + +Also, as mentioned earlier, the names ``PC``, ``SP``, ``FP``, etc. are used to +refer to Hexagon registers such as the program counter, stack pointer, and frame +pointer seen here. Writes to these registers then correspond to assignments +``PC = ...``, and reads correspond to uses of the variable ``PC``. + +Moreover, another example of one such exception is the selective expansion of +macros present in ``macros.h``. As an example, consider the ``fABS`` macro which +in plain C is defined as + +:: + + #define fABS(A) (((A) < 0) ? (-(A)) : (A)) + +and returns the absolute value of the argument ``A``. This macro is not included +in ``idef-parser/macros.inc`` and as such is not expanded and kept as a "call" +``fABS(...)``. Reason being, that ``fABS`` is easier to match and map to +``tcg_gen_abs_<width>``, compared to the full ternary expression above. Loads of +macros in ``macros.h`` are kept unexpanded to aid in parsing, as seen in the +example above, for more information see ``idef-parser/idef-parser.lex``. + +Finally, in mapping these input expressions to tinycode generators, idef-parser +tries to perform as much as possible in plain C. Such as, performing binary +operations in C instead of tinycode generators, thus effectively constant +folding the expression. + +Variables and Variable Declarations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Similarly to C, variables in the input code must be explicitly declared, such as +``int var1;`` which declares an uninitialized variable ``var1``. Initialization +``int var2 = 0;`` is also allowed and behaves as expected. In tinycode +generators the previous declarations are mapped to + +:: + + int var1; -> TCGv_i32 var1 = tcg_temp_local_new_i32(); + + int var2 = 0; -> TCGv_i32 var1 = tcg_temp_local_new_i32(); + tcg_gen_movi_i32(j, ((int64_t) 0ULL)); + +which are later automatically freed at the end of the function they're declared +in. Contrary to C, we only allow variables to be declared with an integer type +specified in the following table (without permutation of keywords) + +:: + + type bit-width signedness + ---------------------------------------------------------- + int 32 signed + signed + signed int + + unsigned 32 unsigned + unsigned int + + long 64 signed + long int + signed long + signed long int + + unsigned long 64 unsigned + unsigned long int + + long long 64 signed + long long int + signed long long + signed long long int + + unsigned long long 64 unsigned + unsigned long long int + + size[1,2,4,8][s,u]_t 8-64 signed or unsigned + +In idef-parser, variable names are matched by a generic ``VARID`` token, +which will feature the variable name as a decoration. For a variable declaration +idef-parser calls ``gen_varid_allocate`` with the ``VARID`` token to save the +name, size, and bit width of the newly declared variable. In addition, this +function also ensures that variables aren't declared multiple times, and prints +and error message if that is the case. Upon use of a variable, the ``VARID`` +token is used to lookup the size and bit width of the variable. + +Type System +~~~~~~~~~~~ + +idef-parser features a simple type system which is used to correctly implement +the signedness and bit width of the operations. + +The type of each ``rvalue`` is determined by two attributes: its bit width +(``unsigned bit_width``) and its signedness (``HexSignedness signedness``). + +For each operation, the type of ``rvalue``\ s influence the way in which the +operands are handled and emitted. For example a right shift between signed +operators will be an arithmetic shift, while one between unsigned operators +will be a logical shift. If one of the two operands is signed, and the other +is unsigned, the operation will be signed. + +The bit width also influences the outcome of the operations, in particular while +the input languages features a fine granularity type system, with types of 8, +16, 32, 64 (and more for vectorial instructions) bits, the tinycode only +features 32 and 64 bit widths. We propagate as much as possible the fine +granularity type, until the value has to be used inside an operation between +``rvalue``\ s; in that case if one of the two operands is greater than 32 bits +we promote the whole operation to 64 bit, taking care of properly extending the +two operands. Fortunately, the most critical instructions already feature +explicit casts and zero/sign extensions which are properly propagated down to +our parser. + +The combination of ``rvalue``\ s are handled through the use of the +``gen_bin_op`` and ``gen_bin_cmp`` helper functions. These two functions handle +the appropriate compile-time or run-time emission of operations to perform the +required computation. + +Control Statements +~~~~~~~~~~~~~~~~~~ + +``control_statement``\ s are all the statements which modify the order of +execution of the generated code according to input parameters. They are expanded +by the following grammar rule: + +:: + + control_statement : frame_check + | cancel_statement + | if_statement + | for_statement + | fpart1_statement + +``if_statement``\ s require the emission of labels and branch instructions which +effectively perform conditional jumps (``tcg_gen_brcondi``) according to the +value of an expression. Note, the tinycode generators we produce for conditional +statements do not perfectly mirror what would be expected in C, for instance we +do not reproduce short-circuiting of the ``&&`` operator, and use of the ``||`` +operator is disallowed. All the predicated instructions, and in general all the +instructions where there could be alternative values assigned to an ``lvalue``, +like C-style ternary expressions: + +:: + + rvalue : rvalue QMARK rvalue COLON rvalue + +are handled using the conditional move tinycode instruction +(``tcg_gen_movcond``), which avoids the additional complexity of managing labels +and jumps. + +Instead, regarding the ``for`` loops, exploiting the fact that they always +iterate on immediate values, therefore their iteration ranges are always known +at compile time, we implemented those emitting plain C ``for`` loops. This is +possible because the loops will be executed in the QEMU code, leading to the +consequential unrolling of the for loop, since the tinycode generator +instructions will be executed multiple times, and the respective generated +tinycode will represent the unrolled execution of the loop. + +Parsing Context +~~~~~~~~~~~~~~~ + +All the helper functions in ``idef-parser.y`` carry two fixed parameters, which +are the parsing context ``c`` and the ``YYLLOC`` location information. The +context is explicitly passed to all the functions because the parser we generate +is a reentrant one, meaning that it does not have any global variable, and +therefore the instruction compilation could easily be parallelized in the +future. Finally for each rule we propagate information about the location of the +involved tokens to generate pretty error reporting, able to highlight the +portion of the input code which generated each error. + +Debugging +--------- + +Developing the idef-parser can lead to two types of errors: compile-time errors +and parsing errors. + +Compile-time errors in Bison-generated parsers are usually due to conflicts in +the described grammar. Conflicts forbid the grammar to produce a unique +derivation tree, thus must be solved (except for the dangling else problem, +which is marked as expected through the ``%expect 1`` Bison option). + +For solving conflicts you need a basic understanding of `shift-reduce conflicts +<https://www.gnu.org/software/Bison/manual/html_node/Shift_002fReduce.html>`__ +and `reduce-reduce conflicts +<https://www.gnu.org/software/Bison/manual/html_node/Reduce_002fReduce.html>`__, +then, if you are using a Bison version > 3.7.1 you can ask Bison to generate +some counterexamples which highlight ambiguous derivations, passing the +``-Wcex`` option to Bison. In general shift/reduce conflicts are solved by +redesigning the grammar in an unambiguous way or by setting the token priority +correctly, while reduce/reduce conflicts are solved by redesigning the +interested part of the grammar. + +Run-time errors can be divided between lexing and parsing errors, lexing errors +are hard to detect, since the ``var`` token will catch everything which is not +catched by other tokens, but easy to fix, because most of the time a simple +regex editing will be enough. + +idef-parser features a fancy parsing error reporting scheme, which for each +parsing error reports the fragment of the input text which was involved in the +parsing rule that generated an error. + +Implementing an instruction goes through several sequential steps, here are some +suggestions to make each instruction proceed to the next step. + +- not-emitted + + Means that the parsing of the input code relative to that instruction failed, + this could be due to a lexical error or to some mismatch between the order of + valid tokens and a parser rule. You should check that tokens are correctly + identified and mapped, and that there is a rule matching the token sequence + that you need to parse. + +- emitted + + This instruction class contains all the instructions which are emitted but + fail to compile when included in QEMU. The compilation errors are shown by + the QEMU building process and will lead to fixing the bug. Most common + errors regard the mismatch of parameters for tinycode generator functions, + which boil down to errors in the idef-parser type system. + +- compiled + + These instruction generate valid tinycode generator code, which however fail + the QEMU or the harness tests, these cases must be handled manually by + looking into the failing tests and looking at the generated tinycode + generator instruction and at the generated tinycode itself. Tip: handle the + failing harness tests first, because they usually feature only a single + instruction, thus will require less execution trace navigation. If a + multi-threaded test fail, fixing all the other tests will be the easier + option, hoping that the multi-threaded one will be indirectly fixed. + + An example of debugging this type of failure is provided in the following + section. + +- tests-passed + + This is the final goal for each instruction, meaning that the instruction + passes the test suite. + +Another approach to fix QEMU system test, where many instructions might fail, is +to compare the execution trace of your implementation with the reference +implementations already present in QEMU. To do so you should obtain a QEMU build +where the instruction pass the test, and run it with the following command: + +:: + + sudo unshare -p sudo -u <USER> bash -c \ + 'env -i <qemu-hexagon full path> -d cpu <TEST>' + +And do the same for your implementation, the generated execution traces will be +inherently aligned and can be inspected for behavioral differences using the +``diff`` tool. + +Example of debugging erroneous tinycode generator code +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The goal of this section is to provide a complete example of debugging +incorrectly emitted tinycode generator for a single instruction. + +Let's first introduce a bug in the tinycode generator of the ``A2_add`` +instruction, + +:: + + void emit_A2_add(DisasContext *ctx, Insn *insn, Packet *pkt, TCGv_i32 RdV, + TCGv_i32 RsV, TCGv_i32 RtV) + /* RdV=RsV+RtV;} */ + { + TCGv_i32 tmp_0 = tcg_temp_new_i32(); + tcg_gen_add_i32(tmp_0, RsV, RsV); + tcg_gen_mov_i32(RdV, tmp_0); + tcg_temp_free_i32(tmp_0); + } + +Here the bug, albeit hard to spot, is in ``tcg_gen_add_i32(tmp_0, RsV, RsV);`` +where we compute ``RsV + RsV`` instead of ``RsV + RtV``, as would be expected. +This particular bug is a bit tricky to pinpoint when debugging, since the +``A2_add`` instruction is so ubiquitous. As a result, pretty much all tests will +fail and therefore not provide a lot of information about the bug. + +For example, let's run the ``check-tcg`` tests + +:: + + make check-tcg TIMEOUT=1200 \ + DOCKER_IMAGE=debian-hexagon-cross \ + ENGINE=podman V=1 \ + DOCKER_CROSS_CC_GUEST=hexagon-unknown-linux-musl-clang + +In the output, we find a failure in the very first test case ``float_convs`` +due to a segmentation fault. Similarly, all harness and libc tests will fail as +well. At this point we have no clue where the actual bug lies, and need to start +ruling out instructions. As such a good starting point is to utilize the debug +options ``-d in_asm,cpu`` of QEMU to inspect the Hexagon instructions being run, +alongside the CPU state. We additionally need a working version of the emulator +to compare our buggy CPU state against, running + +:: + + meson configure -Dhexagon_idef_parser_enabled=false + +will disable the idef-parser for all instructions and fallback on manual +tinycode generator overrides, or on helper function implementations. Recompiling +gives us ``qemu-hexagon`` which passes all tests. If ``qemu-heaxgon-buggy`` is +our binary with the incorrect tinycode generators, we can compare the CPU state +between the two versions + +:: + + ./qemu-hexagon-buggy -d in_asm,cpu float_convs &> out_buggy + ./qemu-hexagon -d in_asm,cpu float_convs &> out_working + +Looking at ``diff -u out_buggy out_working`` shows us that the CPU state begins +to diverge on line 141, with an incorrect value in the ``R1`` register + +:: + + @@ -138,7 +138,7 @@ + + General Purpose Registers = { + r0 = 0x4100f9c0 + - r1 = 0x00042108 + + r1 = 0x00000000 + r2 = 0x00021084 + r3 = 0x00000000 + r4 = 0x00000000 + +If we also look into ``out_buggy`` directly we can inspect the input assembly +which the caused the incorrect CPU state, around line 141 we find + +:: + + 116 | ---------------- + 117 | IN: _start_c + 118 | 0x000210b0: 0xa09dc002 { allocframe(R29,#0x10):raw } + ... | ... + 137 | 0x000210fc: 0x5a00c4aa { call PC+2388 } + 138 | + 139 | General Purpose Registers = { + 140 | r0 = 0x4100fa70 + 141 | r1 = 0x00042108 + 142 | r2 = 0x00021084 + 143 | r3 = 0x00000000 + +Importantly, we see some Hexagon assembly followed by a dump of the CPU state, +now the CPU state is actually dumped before the input assembly above is ran. +As such, we are actually interested in the instructions ran before this. + +Scrolling up a bit, we find + +:: + + 54 | ---------------- + 55 | IN: _start + 56 | 0x00021088: 0x6a09c002 { R2 = C9/pc } + 57 | 0x0002108c: 0xbfe2ff82 { R2 = add(R2,#0xfffffffc) } + 58 | 0x00021090: 0x9182c001 { R1 = memw(R2+#0x0) } + 59 | 0x00021094: 0xf302c101 { R1 = add(R2,R1) } + 60 | 0x00021098: 0x7800c01e { R30 = #0x0 } + 61 | 0x0002109c: 0x707dc000 { R0 = R29 } + 62 | 0x000210a0: 0x763dfe1d { R29 = and(R29,#0xfffffff0) } + 63 | 0x000210a4: 0xa79dfdfe { memw(R29+#0xfffffff8) = R29 } + 64 | 0x000210a8: 0xbffdff1d { R29 = add(R29,#0xfffffff8) } + 65 | 0x000210ac: 0x5a00c002 { call PC+4 } + 66 | + 67 | General Purpose Registers = { + 68 | r0 = 0x00000000 + 69 | r1 = 0x00000000 + 70 | r2 = 0x00000000 + 71 | r3 = 0x00000000 + +Remember, the instructions on lines 56-65 are ran on the CPU state shown below +instructions, and as the CPU state has not diverged at this point, we know the +starting state is accurate. The bug must then lie within the instructions shown +here. Next we may notice that ``R1`` is only touched by lines 57 and 58, that is +by + +:: + + 58 | 0x00021090: 0x9182c001 { R1 = memw(R2+#0x0) } + 59 | 0x00021094: 0xf302c101 { R1 = add(R2,R1) } + +Therefore, we are either dealing with an correct load instruction +``R1 = memw(R2+#0x0)`` or with an incorrect add ``R1 = add(R2,R1)``. At this +point it might be easy enough to go directly to the emitted code for the +instructions mentioned and look for bugs, but we could also run +``./qemu-heaxgon -d op,in_asm float_conv`` where we find for the following +tinycode for the Hexagon ``add`` instruction + +:: + + ---- 00021094 + mov_i32 pkt_has_store_s1,$0x0 + add_i32 tmp0,r2,r2 + mov_i32 loc2,tmp0 + mov_i32 new_r1,loc2 + mov_i32 r1,new_r1 + +Here we have finally located our bug ``add_i32 tmp0,r2,r2``. + +Limitations and Future Development +---------------------------------- + +The main limitation of the current parser is given by the syntax-driven nature +of the Bison-generated parsers. This has the severe implication of only being +able to generate code in the order of evaluation of the various rules, without, +in any case, being able to backtrack and alter the generated code. + +An example limitation is highlighted by this statement of the input language: + +:: + + { (PsV==0xff) ? (PdV=0xff) : (PdV=0x00); } + +This ternary assignment, when written in this form requires us to emit some +proper control flow statements, which emit a jump to the first or to the second +code block, whose implementation is extremely convoluted, because when matching +the ternary assignment, the code evaluating the two assignments will be already +generated. + +Instead we pre-process that statement, making it become: + +:: + + { PdV = ((PsV==0xff)) ? 0xff : 0x00; } + +Which can be easily matched by the following parser rules: + +:: + + statement | rvalue ';' + + rvalue : rvalue QMARK rvalue COLON rvalue + | rvalue EQ rvalue + | LPAR rvalue RPAR + | assign_statement + | IMM + + assign_statement : pred ASSIGN rvalue + +Another example that highlight the limitation of the flex/bison parser can be +found even in the add operation we already saw: + +:: + + TCGv_i32 tmp_0 = tcg_temp_new_i32(); + tcg_gen_add_i32(tmp_0, RsV, RtV); + tcg_gen_mov_i32(RdV, tmp_0); + +The fact that we cannot directly use ``RdV`` as the destination of the sum is a +consequence of the syntax-driven nature of the parser. In fact when we parse the +assignment, the ``rvalue`` token, representing the sum has already been reduced, +and thus its code emitted and unchangeable. We rely on the fact that QEMU will +optimize our code reducing the useless move operations and the relative +temporaries. + +A possible improvement of the parser regards the support for vectorial +instructions and floating point instructions, which will require the extension +of the scanner, the parser, and a partial re-design of the type system, allowing +to build the vectorial semantics over the available vectorial tinycode generator +primitives. + +A more radical improvement will use the parser, not to generate directly the +tinycode generator code, but to generate an intermediate representation like the +LLVM IR, which in turn could be compiled using the clang TCG backend. That code +could be furtherly optimized, overcoming the limitations of the syntax-driven +parsing and could lead to a more optimized generated code.
target/hexagon/README +5 -0
@@ -27,6 +27,10 @@ Hexagon-specific code are encode*.def Encoding patterns for each instruction iclass.def Instruction class definitions used to determine legal VLIW slots for each instruction + qemu/target/hexagon/idef-parser + Parser that, given the high-level definitions of an instruction, + produces a C function generating equivalent tiny code instructions. + See README.rst. qemu/linux-user/hexagon Helpers for loading the ELF file and making Linux system calls, signals, etc
@@ -47,6 +51,7 @@ header files in <BUILD_DIR>/target/hexagon gen_tcg_funcs.py -> tcg_funcs_generated.c.inc gen_tcg_func_table.py -> tcg_func_table_generated.c.inc gen_helper_funcs.py -> helper_funcs_generated.c.inc + gen_idef_parser_funcs.py -> idef_parser_input.h Qemu helper functions have 3 parts DEF_HELPER declaration indicates the signature of the helper
Signature · 1 line
2.17.1
[PULL 02/21] Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur
In reply to Taylor SimpsonHere are example instructions with a predicated .tmp/.cur assignment
if (p1) v12.tmp = vmem(r7 + #0)
if (p0) v12.cur = vmem(r9 + #0)The .tmp/.cur indicates that references to v12 in the same packet take the result of the load. However, when the predicate is false, the value at the start of the packet should be used. After the packet commits, the .tmp value is dropped, but the .cur value is maintained.
To fix this bug, we preload the original value from the HVX register into the temporary used for the result.
Test cases added to tests/tcg/hexagon/hvx_misc.c
Message-Id: <[email protected]>
--- target/hexagon/translate.h | 6 +++ tests/tcg/hexagon/hvx_misc.c | 72 +++++++++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 12 ++++++ 3 files changed, 90 insertions(+)
target/hexagon/translate.h +6 -0
@@ -86,6 +86,12 @@ static inline bool is_preloaded(DisasContext *ctx, int num)return test_bit (num, ctx->regs_written); } +static inline bool is_vreg_preloaded (DisasContext *ctx,int num) +{ +return test_bit (num, ctx->vregs_updated) || +test_bit (num, ctx->vregs_updated_tmp); +} +intptr_t ctx_future_vreg_off (DisasContext *ctx,int regnum,int num,bool alloc_ok); intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
tests/tcg/hexagon/hvx_misc.c +72 -0
84 lines not on this page · raw message
target/hexagon/gen_tcg_funcs.py +12 -0
@@ -173,6 +173,18 @@ def genptr_decl(f, tag, regtype, regid, regno): f.write(" ctx_future_vreg_off(ctx, %s%sN," % \ (regtype, regid)) f.write(" 1, true);\n"); + if 'A_CONDEXEC' in hex_common.attribdict[tag]: + f.write(" if (!is_vreg_preloaded(ctx, %s)) {\n" % (regN)) + f.write(" intptr_t src_off =") + f.write(" offsetof(CPUHexagonState, VRegs[%s%sN]);\n"% \ + (regtype, regid)) + f.write(" tcg_gen_gvec_mov(MO_64, %s%sV_off,\n" % \ + (regtype, regid)) + f.write(" src_off,\n") + f.write(" sizeof(MMVector),\n") + f.write(" sizeof(MMVector));\n") + f.write(" }\n") + if (not hex_common.skip_qemu_helper(tag)): f.write(" TCGv_ptr %s%sV = tcg_temp_new_ptr();\n" % \ (regtype, regid))
Signature · 1 line
2.17.1
[PULL 20/21] target/hexagon: call idef-parser functions
In reply to Taylor SimpsonFrom: Alessandro Di Federico <[email protected]>
Extend gen_tcg_funcs.py in order to emit calls to the functions emitted by the idef-parser, if available.
Message-Id: <[email protected]>
--- target/hexagon/gen_helper_funcs.py | 17 ++++- target/hexagon/gen_helper_protos.py | 17 ++++- target/hexagon/gen_tcg_funcs.py | 41 ++++++++++- target/hexagon/hex_common.py | 10 +++ target/hexagon/meson.build | 103 ++++++++++++++++++++-------- 5 files changed, 154 insertions(+), 34 deletions(-)
target/hexagon/gen_helper_funcs.py +16 -1
@@ -298,11 +298,24 @@ def main(): hex_common.read_attribs_file(sys.argv[2]) hex_common.read_overrides_file(sys.argv[3]) hex_common.read_overrides_file(sys.argv[4]) + ## Whether or not idef-parser is enabled is + ## determined by the number of arguments to + ## this script: + ## + ## 5 args. -> not enabled, + ## 6 args. -> idef-parser enabled. + ## + ## The 6:th arg. then holds a list of the successfully + ## parsed instructions. + is_idef_parser_enabled = len(sys.argv) > 6 + if is_idef_parser_enabled: + hex_common.read_idef_parser_enabled_file(sys.argv[5]) hex_common.calculate_attribs() tagregs = hex_common.get_tagregs() tagimms = hex_common.get_tagimms() - with open(sys.argv[5], 'w') as f: + output_file = sys.argv[-1] + with open(output_file, 'w') as f: for tag in hex_common.tags: ## Skip the priv instructions if ( "A_PRIV" in hex_common.attribdict[tag] ) :
@@ -319,6 +332,8 @@ def main(): continue if ( hex_common.skip_qemu_helper(tag) ): continue + if ( hex_common.is_idef_parser_enabled(tag) ): + continue gen_helper_function(f, tag, tagregs, tagimms)
target/hexagon/gen_helper_protos.py +16 -1
@@ -146,11 +146,24 @@ def main(): hex_common.read_attribs_file(sys.argv[2]) hex_common.read_overrides_file(sys.argv[3]) hex_common.read_overrides_file(sys.argv[4]) + ## Whether or not idef-parser is enabled is + ## determined by the number of arguments to + ## this script: + ## + ## 5 args. -> not enabled, + ## 6 args. -> idef-parser enabled. + ## + ## The 6:th arg. then holds a list of the successfully + ## parsed instructions. + is_idef_parser_enabled = len(sys.argv) > 6 + if is_idef_parser_enabled: + hex_common.read_idef_parser_enabled_file(sys.argv[5]) hex_common.calculate_attribs() tagregs = hex_common.get_tagregs() tagimms = hex_common.get_tagimms() - with open(sys.argv[5], 'w') as f: + output_file = sys.argv[-1] + with open(output_file, 'w') as f: for tag in hex_common.tags: ## Skip the priv instructions if ( "A_PRIV" in hex_common.attribdict[tag] ) :
@@ -168,6 +181,8 @@ def main(): if ( hex_common.skip_qemu_helper(tag) ): continue + if ( hex_common.is_idef_parser_enabled(tag) ): + continue gen_helper_prototype(f, tag, tagregs, tagimms)
target/hexagon/gen_tcg_funcs.py +39 -2
58 lines not on this page · raw message
target/hexagon/hex_common.py +10 -0
@@ -28,6 +28,7 @@ attribinfo = {} # Register information and misc tags = [] # list of all tags overrides = {} # tags with helper overrides +idef_parser_enabled = {} # tags enabled for idef-parser # We should do this as a hash for performance, # but to keep order let's keep it as a list.
@@ -245,6 +246,9 @@ def is_tmp_result(tag): def is_new_result(tag): return ('A_CVI_NEW' in attribdict[tag]) +def is_idef_parser_enabled(tag): + return tag in idef_parser_enabled + def imm_name(immlett): return "%siV" % immlett
@@ -276,3 +280,9 @@ def read_overrides_file(name): continue tag = overridere.findall(line)[0] overrides[tag] = True + +def read_idef_parser_enabled_file(name): + global idef_parser_enabled + with open(name, "r") as idef_parser_enabled_file: + lines = idef_parser_enabled_file.read().strip().split("\n") + idef_parser_enabled = set(lines)
target/hexagon/meson.build +73 -30
134 lines not on this page · raw message
Signature · 1 line
2.17.1
[PULL 09/21] Hexagon (target/hexagon) Add overrides for various forms of jump
In reply to Taylor SimpsonMessage-Id: <[email protected]>
--- target/hexagon/gen_tcg.h | 201 +++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 43 +++++++++ 2 files changed, 244 insertions(+)
target/hexagon/gen_tcg.h +201 -0
@@ -797,6 +797,207 @@#define fGEN_TCG_J4_tstbit0_fp1_jump_t (SHORTCODE ) \ gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_NE, riV) +#define fGEN_TCG_J2_jump (SHORTCODE ) \ + gen_jump(ctx, riV) +#define fGEN_TCG_J2_jumpr (SHORTCODE ) \ + gen_jumpr(ctx, RsV) +#define fGEN_TCG_J4_jumpseti (SHORTCODE ) \ + do { \ + tcg_gen_movi_tl(RdV, UiV); \ + gen_jump(ctx, riV); \ + } while (0) + +#define fGEN_TCG_cond_jumpt (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jump(ctx, TCG_COND_EQ, LSB, riV); \ + tcg_temp_free(LSB); \ + } while (0) +#define fGEN_TCG_cond_jumpf (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jump(ctx, TCG_COND_NE, LSB, riV); \ + tcg_temp_free(LSB); \ + } while (0) + +#define fGEN_TCG_J2_jumpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumptpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumpf (SHORTCODE ) \ + fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumpfpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpf(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumptnew (SHORTCODE ) \ + gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) +#define fGEN_TCG_J2_jumptnewpt (SHORTCODE ) \ + gen_cond_jump(ctx, TCG_COND_EQ, PuN, riV) +#define fGEN_TCG_J2_jumpfnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumpfnew (SHORTCODE ) \ + fGEN_TCG_cond_jumpf(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprz (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_NE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprzpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_NE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprnz (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_EQ, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprnzpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_EQ, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprgtez (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_GE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprgtezpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_GE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprltez (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_LE, LSB, RsV, 0)) +#define fGEN_TCG_J2_jumprltezpt (SHORTCODE ) \ + fGEN_TCG_cond_jumpt(tcg_gen_setcondi_tl(TCG_COND_LE, LSB, RsV, 0)) + +#define fGEN_TCG_cond_jumprt (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jumpr(ctx, RsV, TCG_COND_EQ, LSB); \ + tcg_temp_free(LSB); \ + } while (0) +#define fGEN_TCG_cond_jumprf (COND ) \ + do { \ + TCGv LSB = tcg_temp_new(); \ + COND; \ + gen_cond_jumpr(ctx, RsV, TCG_COND_NE, LSB); \ + tcg_temp_free(LSB); \ + } while (0) + +#define fGEN_TCG_J2_jumprt (SHORTCODE ) \ + fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprtpt (SHORTCODE ) \ + fGEN_TCG_cond_jumprt(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprf (SHORTCODE ) \ + fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprfpt (SHORTCODE ) \ + fGEN_TCG_cond_jumprf(fLSBOLD(PuV)) +#define fGEN_TCG_J2_jumprtnew (SHORTCODE ) \ + fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprtnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumprt(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprfnew (SHORTCODE ) \ + fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) +#define fGEN_TCG_J2_jumprfnewpt (SHORTCODE ) \ + fGEN_TCG_cond_jumprf(fLSBNEW(PuN)) + +/* +* New value compare & jump instructions +* if ([!]COND(r0.new, r1) jump:t address +* if ([!]COND(r0.new, #7) jump:t address +*/ +#define fGEN_TCG_J4_cmpgt_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgt_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeq_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_EQ, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_EQ, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_NE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpeq_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_NE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmplt_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LT, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GE, NsN, RtV, riV) +#define fGEN_TCG_J4_cmplt_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GE, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeqi_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpgti_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgti_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpltu_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GEU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpltu_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GEU, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpgtui_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GTU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GTU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LEU, NsN, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LEU, NsN, UiV, riV) + +#define fGEN_TCG_J4_cmpgtu_t_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_t_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_GTU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_f_jumpnv_t (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LEU, NsN, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_f_jumpnv_nt (SHORTCODE ) \ + gen_cmp_jumpnv(ctx, TCG_COND_LEU, NsN, RtV, riV) + +#define fGEN_TCG_J4_cmpeqn1_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_EQ, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, -1, riV) +#define fGEN_TCG_J4_cmpeqn1_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_NE, NsN, -1, riV) + +#define fGEN_TCG_J4_cmpgtn1_t_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_t_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_GT, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_f_jumpnv_t (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, -1, riV) +#define fGEN_TCG_J4_cmpgtn1_f_jumpnv_nt (SHORTCODE ) \ + gen_cmpi_jumpnv(ctx, TCG_COND_LE, NsN, -1, riV) + +#define fGEN_TCG_J4_tstbit0_t_jumpnv_t (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_t_jumpnv_nt (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_f_jumpnv_t (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_NE, riV) +#define fGEN_TCG_J4_tstbit0_f_jumpnv_nt (SHORTCODE ) \ + gen_testbit0_jumpnv(ctx, NsN, TCG_COND_NE, riV) + +/* r0 = r1 ; jump address */ +#define fGEN_TCG_J4_jumpsetr (SHORTCODE ) \ + do { \ + tcg_gen_mov_tl(RdV, RsV); \ + gen_jump(ctx, riV); \ + } while (0) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +43 -0
61 lines not on this page · raw message
Signature · 1 line
2.17.1
[PULL 06/21] Hexagon (target/hexagon) Remove next_PC from runtime state
In reply to Taylor SimpsonThe imported files don't properly mark all CONDEXEC instructions, so we add some logic to hex_common.py to add the attribute.
Message-Id: <[email protected]>
--- target/hexagon/cpu.h | 1 - target/hexagon/gen_tcg.h | 6 ++++++ target/hexagon/macros.h | 2 +- target/hexagon/translate.h | 2 +- target/hexagon/op_helper.c | 6 +++--- target/hexagon/translate.c | 29 +++++++++++++++++++++++------ target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 21 +++++++++++++++++++++ 10 files changed, 65 insertions(+), 12 deletions(-)
target/hexagon/cpu.h +0 -1
@@ -78,7 +78,6 @@ typedef struct CPUArchState {target_ulong gpr[TOTAL_PER_THREAD_REGS ];target_ulong pred[NUM_PREGS ];target_ulong branch_taken; -target_ulong next_PC;/* For comparing with LLDB on target - see adjust_stack_ptrs function */ target_ulong last_pc_dumped;
target/hexagon/gen_tcg.h +6 -0
@@ -612,6 +612,12 @@tcg_temp_free (tmp); \ } while (0) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ + do { \ + uiV = uiV; \ + tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->next_PC); \ + } while (0) +/* r0 = asr(r1, r2):sat */ #define fGEN_TCG_S2_asr_r_r_sat (SHORTCODE ) \ gen_asr_r_r_sat(RdV, RsV, RtV)
target/hexagon/macros.h +1 -1
@@ -400,7 +400,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#endif #define fREAD_PC () (PC) -#define fREAD_NPC () (env->next_PC & (0xfffffffe)) +#define fREAD_NPC () (next_PC & (0xfffffffe))#define fREAD_P0 () (READ_PREG(0))#define fREAD_P3 () (READ_PREG(3))
target/hexagon/translate.h +1 -1
@@ -30,6 +30,7 @@ typedef struct DisasContext {DisasContextBase base;Packet *pkt;Insn *insn; +uint32_t next_PC;uint32_t mem_idx;uint32_t num_packets;uint32_t num_insns;
@@ -134,7 +135,6 @@ static inline void ctx_log_qreg_write(DisasContext *ctx,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;
target/hexagon/op_helper.c +3 -3
@@ -119,12 +119,12 @@ static void write_new_pc(CPUHexagonState *env, bool pkt_has_multi_cof, "ignoring the second one\n"); }else {fCHECK_PCALIGN (addr); - env->next_PC = addr; + env->gpr[HEX_REG_PC ] = addr; env->branch_taken =1 ; } }else {fCHECK_PCALIGN (addr); - env->next_PC = addr; + env->gpr[HEX_REG_PC ] = addr; } }
@@ -299,7 +299,7 @@ void HELPER(debug_commit_end)(CPUHexagonState *env, int has_st0, int has_st1) } } -HEX_DEBUG_LOG ("Next PC = " TARGET_FMT_lx"\n" , env->next_PC); +HEX_DEBUG_LOG ("Next PC = " TARGET_FMT_lx"\n" , env->gpr[HEX_REG_PC ]); HEX_DEBUG_LOG("Exec counters: pkt = " TARGET_FMT_lx ", insn = " TARGET_FMT_lx ", hvx = " TARGET_FMT_lx "\n",
target/hexagon/translate.c +23 -6
@@ -31,7 +31,6 @@TCGv hex_gpr[TOTAL_PER_THREAD_REGS ];TCGv hex_pred[NUM_PREGS ]; -TCGv hex_next_PC;TCGv hex_this_PC;TCGv hex_slot_cancelled;TCGv hex_branch_taken;
@@ -120,7 +119,6 @@ static void gen_exec_counters(DisasContext *ctx)static void gen_end_tb (DisasContext *ctx) {gen_exec_counters (ctx); -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], hex_next_PC);tcg_gen_exit_tb (NULL ,0 ); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -128,7 +126,7 @@ static void gen_end_tb(DisasContext *ctx)static void gen_exception_end_tb (DisasContext *ctx,int excp) {gen_exec_counters (ctx); -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], hex_next_PC); +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->next_PC);gen_exception_raw (excp); ctx->base.is_jmp =DISAS_NORETURN ;
@@ -204,6 +202,24 @@ static bool need_pred_written(Packet *pkt)return check_for_attrib (pkt,A_WRITES_PRED_REG ); } +static bool need_next_PC (DisasContext *ctx) +{ +Packet *pkt = ctx->pkt; + +/* Check for conditional control flow or HW loop end */ +for (int i =0 ; i < pkt->num_insns; i++) { +uint16_t opcode = pkt->insn[i].opcode; +if (GET_ATTRIB (opcode,A_CONDEXEC ) &&GET_ATTRIB (opcode,A_COF )) { +return true; + } +if (GET_ATTRIB (opcode,A_HWLOOP0_END ) || +GET_ATTRIB (opcode,A_HWLOOP1_END )) { +return true; + } + } +return false; +} +static void gen_start_packet (DisasContext *ctx) {Packet *pkt = ctx->pkt;
@@ -211,6 +227,7 @@ static void gen_start_packet(DisasContext *ctx)int i;/* Clear out the disassembly context */ + ctx->next_PC = next_PC; ctx->reg_log_idx =0 ;bitmap_zero (ctx->regs_written,TOTAL_PER_THREAD_REGS ); ctx->preg_log_idx =0 ;
@@ -243,7 +260,9 @@ static void gen_start_packet(DisasContext *ctx)if (pkt->pkt_has_multi_cof) {tcg_gen_movi_tl (hex_branch_taken,0 ); } -tcg_gen_movi_tl (hex_next_PC, next_PC); +if (need_next_PC (ctx)) { +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], next_PC); + } }if (need_pred_written (pkt)) {tcg_gen_movi_tl (hex_pred_written,0 );
@@ -936,8 +955,6 @@ void hexagon_translate_init(void) } hex_pred_written =tcg_global_mem_new (cpu_env, offsetof(CPUHexagonState , pred_written),"pred_written" ); - hex_next_PC =tcg_global_mem_new (cpu_env, - offsetof(CPUHexagonState , next_PC),"next_PC" ); hex_this_PC =tcg_global_mem_new (cpu_env, offsetof(CPUHexagonState , this_PC),"this_PC" ); hex_slot_cancelled = tcg_global_mem_new(cpu_env,
target/hexagon/gen_helper_funcs.py +4 -0
@@ -245,6 +245,10 @@ def gen_helper_function(f, tag, tagregs, tagimms): if i > 0: f.write(", ") f.write("target_ulong PC") i += 1 + if hex_common.helper_needs_next_PC(tag): + if i > 0: f.write(", ") + f.write("target_ulong next_PC") + i += 1 if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +3 -0
@@ -86,6 +86,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 if hex_common.need_PC(tag): def_helper_size += 1 + if hex_common.helper_needs_next_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## The return type is void f.write(', void' )
@@ -95,6 +96,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 if hex_common.need_PC(tag): def_helper_size += 1 + if hex_common.helper_needs_next_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## Generate the qemu DEF_HELPER type for each result
@@ -134,6 +136,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## part1 (if needed) if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') if hex_common.need_PC(tag): f.write(', i32') + if hex_common.helper_needs_next_PC(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +3 -0
@@ -631,6 +631,8 @@ def gen_tcg_func(f, tag, regs, imms): f.write(" TCGv slot = tcg_constant_tl(insn->slot);\n") if hex_common.need_PC(tag): f.write(" TCGv PC = tcg_constant_tl(ctx->pkt->pc);\n") + if hex_common.helper_needs_next_PC(tag): + f.write(" TCGv next_PC = tcg_constant_tl(ctx->next_PC);\n") f.write(" gen_helper_%s(" % (tag)) i=0 ## If there is a scalar result, it is the return type
@@ -662,6 +664,7 @@ def gen_tcg_func(f, tag, regs, imms): if hex_common.need_pkt_has_multi_cof(tag): f.write(", pkt_has_multi_cof") if hex_common.need_PC(tag): f.write(", PC") + if hex_common.helper_needs_next_PC(tag): f.write(", next_PC") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +21 -0
@@ -66,6 +66,19 @@ def add_qemu_macro_attrib(name, attrib): macros[name].attribs.add(attrib) immextre = re.compile(r'f(MUST_)?IMMEXT[(]([UuSsRr])') + +def is_cond_jump(tag): + if tag == 'J2_rte': + return False + if ('A_HWLOOP0_END' in attribdict[tag] or + 'A_HWLOOP1_END' in attribdict[tag]): + return False + return \ + re.compile(r"(if.*fBRANCH)|(if.*fJUMPR)").search(semdict[tag]) != None + +def is_cond_call(tag): + return re.compile(r"(if.*fCALL)").search(semdict[tag]) != None + def calculate_attribs(): add_qemu_macro_attrib('fREAD_PC', 'A_IMPLICIT_READS_PC') add_qemu_macro_attrib('fTRAP', 'A_IMPLICIT_READS_PC')
@@ -96,6 +109,11 @@ def calculate_attribs(): for regtype, regid, toss, numregs in regs: if regtype == "P" and is_written(regid): attribdict[tag].add('A_WRITES_PRED_REG') + # Mark conditional jumps and calls + # Not all instructions are properly marked with A_CONDEXEC + for tag in tags: + if is_cond_jump(tag) or is_cond_call(tag): + attribdict[tag].add('A_CONDEXEC') def SEMANTICS(tag, beh, sem): #print tag,beh,sem
@@ -211,6 +229,9 @@ def need_ea(tag): def need_PC(tag): return 'A_IMPLICIT_READS_PC' in attribdict[tag] +def helper_needs_next_PC(tag): + return 'A_CALL' in attribdict[tag] + def need_pkt_has_multi_cof(tag): return 'A_COF' in attribdict[tag]
Signature · 1 line
2.17.1
[PULL 08/21] Hexagon (target/hexagon) Add overrides for compound compare and jump
In reply to Taylor SimpsonMessage-Id: <[email protected]>
--- target/hexagon/gen_tcg.h | 177 +++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.c | 90 ++++++++++++++++++++ 2 files changed, 267 insertions(+)
target/hexagon/gen_tcg.h +177 -0
@@ -620,6 +620,183 @@#define fGEN_TCG_J2_callf (SHORTCODE ) \ gen_cond_call(ctx, PuV, TCG_COND_NE, riV) +/* +* Compound compare and jump instructions +* Here is a primer to understand the tag names +* +* Comparison +* cmpeqi compare equal to an immediate +* cmpgti compare greater than an immediate +* cmpgtiu compare greater than an unsigned immediate +* cmpeqn1 compare equal to negative 1 +* cmpgtn1 compare greater than negative 1 +* cmpeq compare equal (two registers) +* cmpgtu compare greater than unsigned (two registers) +* tstbit0 test bit zero +* +* Condition +* tp0 p0 is true p0 = cmp.eq(r0,#5); if (p0.new) jump:nt address +* fp0 p0 is false p0 = cmp.eq(r0,#5); if (!p0.new) jump:nt address +* tp1 p1 is true p1 = cmp.eq(r0,#5); if (p1.new) jump:nt address +* fp1 p1 is false p1 = cmp.eq(r0,#5); if (!p1.new) jump:nt address +* +* Prediction (not modelled in qemu) +* _nt not taken +* _t taken +*/ +#define fGEN_TCG_J4_cmpeq_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_EQ, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpeq_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_EQ, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpgt_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_GT, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgt_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_GT, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpgtu_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 0, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 0, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_t(ctx, 1, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_GTU, RsV, RtV, riV) +#define fGEN_TCG_J4_cmpgtu_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_jmp_f(ctx, 1, TCG_COND_GTU, RsV, RtV, riV) + +#define fGEN_TCG_J4_cmpeqi_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_EQ, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpeqi_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_EQ, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpgti_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_GT, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgti_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_GT, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpgtui_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 0, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 0, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_t(ctx, 1, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_GTU, RsV, UiV, riV) +#define fGEN_TCG_J4_cmpgtui_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmpi_jmp_f(ctx, 1, TCG_COND_GTU, RsV, UiV, riV) + +#define fGEN_TCG_J4_cmpeqn1_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 0, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 0, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 0, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 0, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 1, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 1, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 1, TCG_COND_EQ, RsV, riV) +#define fGEN_TCG_J4_cmpeqn1_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 1, TCG_COND_EQ, RsV, riV) + +#define fGEN_TCG_J4_cmpgtn1_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 0, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 0, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 0, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 0, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 1, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_t(ctx, 1, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 1, TCG_COND_GT, RsV, riV) +#define fGEN_TCG_J4_cmpgtn1_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_cmp_n1_jmp_f(ctx, 1, TCG_COND_GT, RsV, riV) + +#define fGEN_TCG_J4_tstbit0_tp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_tp0_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_fp0_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_NE, riV) +#define fGEN_TCG_J4_tstbit0_fp0_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 0, RsV, TCG_COND_NE, riV) +#define fGEN_TCG_J4_tstbit0_tp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_tp1_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_EQ, riV) +#define fGEN_TCG_J4_tstbit0_fp1_jump_nt (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_NE, riV) +#define fGEN_TCG_J4_tstbit0_fp1_jump_t (SHORTCODE ) \ + gen_cmpnd_tstbit0_jmp(ctx, 1, RsV, TCG_COND_NE, riV) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +90 -0
96 lines not on this page · raw message
Signature · 1 line
2.17.1
[PULL 05/21] Hexagon (target/hexagon) Remove PC from the runtime state
In reply to Taylor SimpsonAdd pc field to Packet structure
For helpers that need PC, pass an extra argument
Remove slot arg from conditional jump helpers
On a trap0, copy pkt->pc into hex_gpr[HEX_REG_PC]
Message-Id: <[email protected]>
--- target/hexagon/gen_tcg.h | 7 +++++++ target/hexagon/insn.h | 1 + target/hexagon/macros.h | 2 +- target/hexagon/translate.c | 9 +-------- target/hexagon/gen_helper_funcs.py | 4 ++++ target/hexagon/gen_helper_protos.py | 3 +++ target/hexagon/gen_tcg_funcs.py | 3 +++ target/hexagon/hex_common.py | 6 +++++- 8 files changed, 25 insertions(+), 10 deletions(-)
target/hexagon/gen_tcg.h +7 -0
@@ -750,4 +750,11 @@ RsV = RsV; \ } while (0) +#define fGEN_TCG_J2_trap0 (SHORTCODE ) \ + do { \ + uiV = uiV; \ + tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->pkt->pc); \ + TCGv excp = tcg_constant_tl(HEX_EXCP_TRAP0); \ + gen_helper_raise_exception(cpu_env, excp); \ + } while (0)#endif
target/hexagon/insn.h +1 -0
@@ -54,6 +54,7 @@ typedef struct Instruction Insn;struct Packet {uint16_t num_insns;uint16_t encod_pkt_size_in_bytes; +uint32_t pc;/* Pre-decodes about COF */ bool pkt_has_cof;/* Has any change-of-flow */
target/hexagon/macros.h +1 -1
@@ -398,7 +398,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#else #define fREAD_GP () READ_REG(HEX_REG_GP)#endif -#define fREAD_PC () (READ_REG(HEX_REG_PC)) +#define fREAD_PC () (PC)#define fREAD_NPC () (env->next_PC & (0xfffffffe))
target/hexagon/translate.c +1 -8
@@ -194,11 +194,6 @@ static bool check_for_attrib(Packet *pkt, int attrib)return false; } -static bool need_pc (Packet *pkt) -{ -return check_for_attrib (pkt,A_IMPLICIT_READS_PC ); -} -static bool need_slot_cancelled (Packet *pkt) {return check_for_attrib (pkt,A_CONDEXEC );
@@ -241,9 +236,6 @@ static void gen_start_packet(DisasContext *ctx) }/* Initialize the runtime state for packet semantics */ -if (need_pc (pkt)) { -tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->base.pc_next); - }if (need_slot_cancelled (pkt)) {tcg_gen_movi_tl (hex_slot_cancelled,0 ); }
@@ -772,6 +764,7 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx) }if (decode_packet (nwords, words, &pkt, false) >0 ) { + pkt.pc = ctx->base.pc_next;HEX_DEBUG_PRINT_PKT (&pkt); ctx->pkt = &pkt;gen_start_packet (ctx);
target/hexagon/gen_helper_funcs.py +4 -0
@@ -241,6 +241,10 @@ def gen_helper_function(f, tag, tagregs, tagimms): if (hex_common.need_pkt_has_multi_cof(tag)): f.write(", uint32_t pkt_has_multi_cof") + if hex_common.need_PC(tag): + if i > 0: f.write(", ") + f.write("target_ulong PC") + i += 1 if hex_common.need_slot(tag): if i > 0: f.write(", ") f.write("uint32_t slot")
target/hexagon/gen_helper_protos.py +3 -0
@@ -85,6 +85,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 + if hex_common.need_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## The return type is void f.write(', void' )
@@ -93,6 +94,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): if hex_common.need_pkt_has_multi_cof(tag): def_helper_size += 1 if hex_common.need_part1(tag): def_helper_size += 1 if hex_common.need_slot(tag): def_helper_size += 1 + if hex_common.need_PC(tag): def_helper_size += 1 f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) ## Generate the qemu DEF_HELPER type for each result
@@ -131,6 +133,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms): ## Add the arguments for the instruction pkt_has_multi_cof, slot and ## part1 (if needed) if hex_common.need_pkt_has_multi_cof(tag): f.write(', i32') + if hex_common.need_PC(tag): f.write(', i32') if hex_common.need_slot(tag): f.write(', i32' ) if hex_common.need_part1(tag): f.write(' , i32' ) f.write(')\n')
target/hexagon/gen_tcg_funcs.py +3 -0
@@ -629,6 +629,8 @@ def gen_tcg_func(f, tag, regs, imms): f.write(" TCGv part1 = tcg_constant_tl(insn->part1);\n") if hex_common.need_slot(tag): f.write(" TCGv slot = tcg_constant_tl(insn->slot);\n") + if hex_common.need_PC(tag): + f.write(" TCGv PC = tcg_constant_tl(ctx->pkt->pc);\n") f.write(" gen_helper_%s(" % (tag)) i=0 ## If there is a scalar result, it is the return type
@@ -659,6 +661,7 @@ def gen_tcg_func(f, tag, regs, imms): if hex_common.need_pkt_has_multi_cof(tag): f.write(", pkt_has_multi_cof") + if hex_common.need_PC(tag): f.write(", PC") if hex_common.need_slot(tag): f.write(", slot") if hex_common.need_part1(tag): f.write(", part1" ) f.write(");\n")
target/hexagon/hex_common.py +5 -1
@@ -194,7 +194,8 @@ def is_new_val(regtype, regid, tag): return regtype+regid+'N' in semdict[tag] def need_slot(tag): - if ('A_CONDEXEC' in attribdict[tag] or + if (('A_CONDEXEC' in attribdict[tag] and + 'A_JUMP' not in attribdict[tag]) or 'A_STORE' in attribdict[tag] or 'A_LOAD' in attribdict[tag]): return 1
@@ -207,6 +208,9 @@ def need_part1(tag): def need_ea(tag): return re.compile(r"\bEA\b").search(semdict[tag]) +def need_PC(tag): + return 'A_IMPLICIT_READS_PC' in attribdict[tag] + def need_pkt_has_multi_cof(tag): return 'A_COF' in attribdict[tag]
Signature · 1 line
2.17.1
[PULL 07/21] Hexagon (target/hexagon) Add overrides for direct call instructions
In reply to Taylor SimpsonAdd overrides for
J2_call
J2_callt
J2_callfMessage-Id: <[email protected]>
--- target/hexagon/gen_tcg.h | 8 ++++++ target/hexagon/genptr.c | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
target/hexagon/gen_tcg.h +8 -0
@@ -612,6 +612,14 @@tcg_temp_free (tmp); \ } while (0) +#define fGEN_TCG_J2_call (SHORTCODE ) \ + gen_call(ctx, riV) + +#define fGEN_TCG_J2_callt (SHORTCODE ) \ + gen_cond_call(ctx, PuV, TCG_COND_EQ, riV) +#define fGEN_TCG_J2_callf (SHORTCODE ) \ + gen_cond_call(ctx, PuV, TCG_COND_NE, riV) +#define fGEN_TCG_J2_pause (SHORTCODE ) \ do { \ uiV = uiV; \
target/hexagon/genptr.c +55 -0
61 lines not on this page · raw message
Signature · 1 line
2.17.1
[PULL 12/21] target/hexagon: update MAINTAINERS for idef-parser
In reply to Taylor SimpsonFrom: Alessandro Di Federico <[email protected]>
Message-Id: <[email protected]>
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -197,6 +197,8 @@ Hexagon TCG CPUs M: Taylor Simpson <[email protected]> S: Supported F: target/hexagon/ +X: target/hexagon/idef-parser/ +X: target/hexagon/gen_idef_parser_funcs.py F: linux-user/hexagon/ F: tests/tcg/hexagon/ F: disas/hexagon.c
@@ -204,6 +206,13 @@ F: configs/targets/hexagon-linux-user/default.mak F: docker/dockerfiles/debian-hexagon-cross.docker F: docker/dockerfiles/debian-hexagon-cross.docker.d/build-toolchain.sh +Hexagon idef-parser +M: Alessandro Di Federico <[email protected]> +M: Anton Johansson <[email protected]> +S: Supported +F: target/hexagon/idef-parser/ +F: target/hexagon/gen_idef_parser_funcs.py + HPPA (PA-RISC) TCG CPUs M: Richard Henderson <[email protected]> S: Maintained
Signature · 1 line
2.17.1
Quoted 11 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1
for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:
Quoted 8 lines
target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)
----------------------------------------------------------------
******************************************************************
***** WARNING *****
***** This PR requires updated CI containers with flex/bison *****
******************************************************************
Does that mean somebody needs to do something before I can merge this?
thanks
-- PMM
Quoted 4 lines · Peter Maydell
Does that mean somebody needs to do something before I can merge this?
thanks
-- PMM
Hi Peter,
no one needs to do anything about the CI, it has already been taken care of.
All containers that need flex/bison have it, and the debian-hexagon-cross container has already been rebuilt manually and pushed by Alex.
cheers,
Signature · 2 lines
Anton Johansson, rev.ng Labs Srl.
Quoted 5 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)
Quoted 7 lines
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1
for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)
Failed to build, s390x:
https://gitlab.com/qemu-project/qemu/-/jobs/3492490152
Program scripts/decodetree.py found: YES (/usr/bin/python3 /home/gitlab-runner/builds/-LCfcJ2T/0/qemu-project/qemu/scripts/decodetree.py) Program flex found: NO
../target/hexagon/meson.build:179:4: ERROR: Program 'flex' not found or not executable
Can you get the CI requirements sorted out first, and then let me know when I can try re-merging this, please?
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Failed to build, s390x:
https://gitlab.com/qemu-project/qemu/-/jobs/3492490152
Program
scripts/decodetree.pyfound: YES (/usr/bin/python3/home/gitlab-runner/builds/-LCfcJ2T/0/qemu-project/qemu/scripts/decodetree.py) Program flex found: NO
../target/hexagon/meson.build:179:4: ERROR: Program 'flex' not found or not executable
Quoted 5 lines
Can you get the CI requirements sorted out first, and then let me know when I can try re-merging this, please?
thanks
-- PMM
Oh, this is my bad. I didn't know we built Hexagon on s390x, I naively assumed the CI jobs ran locally matched those upstream.
I'll send a patch adding flex/bison to s390x then.
Thanks,
Signature · 2 lines
Anton Johansson, rev.ng Labs Srl.
Quoted 19 lines · Peter Maydell
Quoted 5 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)Quoted 7 lines
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)Failed to build, s390x:
Quoted 8 lines
Program
scripts/decodetree.pyfound: YES (/usr/bin/python3/home/gitlab-runner/builds/-LCfcJ2T/0/qemu-project/qemu/scripts/decodetree.py) Program flex found: NO
../target/hexagon/meson.build:179:4: ERROR: Program 'flex' not found or not executableCan you get the CI requirements sorted out first, and then let me know when I can try re-merging this, please?
Our s390x host won't be affected by any of the scripts, it simply needs to be installed.
Alex, can you please install flex + bison on s390x.ci.qemu.org?
r~
Quoted 27 lines · Richard Henderson
Quoted 25 lines · Peter Maydell
Quoted 5 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)Quoted 7 lines
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)Failed to build, s390x:
https://gitlab.com/qemu-project/qemu/-/jobs/3492490152
Program
scripts/decodetree.pyfound: YES (/usr/bin/python3/home/gitlab-runner/builds/-LCfcJ2T/0/qemu-project/qemu/scripts/decodetree.py) Program flex found: NO
../target/hexagon/meson.build:179:4: ERROR: Program 'flex' not found or not executable
Quoted 7 lines
Quoted 2 lines
Can you get the CI requirements sorted out first, and then let me know when I can try re-merging this, please?
Our s390x host won't be affected by any of the scripts, it simply needs to be installed.
Alex, can you please install flex + bison on s390x.ci.qemu.org?
Ah, if that's all we need to do, I have access for that. I'll install the packages and retry.
thanks
-- PMM
Quoted 29 lines · Peter Maydell
Quoted 27 lines · Richard Henderson
Quoted 25 lines · Peter Maydell
Quoted 5 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)Quoted 7 lines
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)Failed to build, s390x:
https://gitlab.com/qemu-project/qemu/-/jobs/3492490152
Program
scripts/decodetree.pyfound: YES (/usr/bin/python3/home/gitlab-runner/builds/-LCfcJ2T/0/qemu-project/qemu/scripts/decodetree.py) Program flex found: NO
../target/hexagon/meson.build:179:4: ERROR: Program 'flex' not found or not executable
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Can you get the CI requirements sorted out first, and then let me know when I can try re-merging this, please?
Our s390x host won't be affected by any of the scripts, it simply needs to be installed.
scripts/ci/setup/build-environment.yml need to be updated although.
Quoted 7 lines
Quoted 1 line
Alex, can you please install flex + bison on s390x.ci.qemu.org?
Ah, if that's all we need to do, I have access for that. I'll install the packages and retry.
thanks
-- PMM
Peter Maydell
AppliedQuoted 5 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu into staging (2022-12-15 21:39:56 +0000)
Quoted 7 lines
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1
for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes. (In particular there is a section of the changelog for 'Build Dependencies' -- please add something there indicating under what circumstances flex/bison are now required.)
-- PMM
Quoted 24 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, December 19, 2022 4:28 AM
To: Taylor Simpson <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Brian Cain <[email protected]>; Matheus Bernardino (QUIC) <[email protected]>; [email protected]
Subject: Re: [PULL 00/21] Hexagon update: bug fixes, performance, idef- parserQuoted 2 lines · Taylor Simpson
The following changes since commit
4208e6ae114ac8266dcacc9696a443ce5c37b04e:Quoted 8 lines
Merge tag 'pull-request-2022-12-15' of https://gitlab.com/thuth/qemu
into staging (2022-12-15 21:39:56 +0000)are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20221216-1
Quoted 7 lines
Quoted 1 line
for you to fetch changes up to
585a86b1041a45c3b4074440c7f1b54944570867:Quoted 2 lines
target/hexagon: import additional tests (2022-12-16 12:30:28 -0800)
Applied, thanks.
Thanks!!
Quoted 5 lines
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes. (In particular there is a section of the changelog for 'Build Dependencies' -- please add something there indicating under what circumstances flex/bison are now required.)
I've forgotten my password. How do I reset it?
Taylor
Quoted 3 lines · On Mon, 19 Dec 2022 18:54:22 +0000 Taylor Simpson <[email protected]> wrote:
Quoted 1 line
Applied, thanks.
Thanks!!
Thanks from our side too! :)
We started this project back in 2015, I'm really happy we finally got it in!
Signature · 2 lines
Alessandro Di Federico rev.ng Labs
Hi,
Quoted 5 lines · Taylor Simpson
----------------------------------------------------------------
12-21)
Instruction definition parser (idef-parser) from rev.ng Parses the instruction semantics and generates TCG
Building QEMU with Clang I'm now getting:
target/hexagon/idef-parser.p/idef-parser.tab.c:2197:9: error: variable 'yynerrs' set but not used [-Werror,-Wunused-but-set-variable]
int yynerrs = 0;
^Regards,
Phil.
Quoted 10 lines · Philippe Mathieu-Daudé
Hi,
Quoted 5 lines · Taylor Simpson
----------------------------------------------------------------
12-21)
Instruction definition parser (idef-parser) from rev.ng Parses the instruction semantics and generates TCG
Quoted 5 lines
Building QEMU with Clang I'm now getting:
target/hexagon/idef-parser.p/idef-parser.tab.c:2197:9: error: variable 'yynerrs' set but not used [-Werror,-Wunused-but-set-variable]
int yynerrs = 0;
^
idef-parser.tab.c is built using:
193 idef_parser = executable(
194 'idef-parser',
195 [flex.process(idef_parser_dir / 'idef-parser.lex'),
196 bison.process(idef_parser_dir / 'idef-parser.y'),
197 idef_parser_dir / 'parser-helpers.c'],
198 include_directories: ['idef-parser', '../../include/'],
199 dependencies: [glib_dep],
200 c_args: ['-Wextra'],
^^^^^^^^201 native: true
202 )
(see commit c0a41ee631 "target/hexagon: import parser for idef-parser")
Do we really need this level? IIUC the problem with -Wextra is using a newer compiler toolchain it can include warnings we haven't fixed. Maybe worthwhile but it can break from times to times.
Using '-Wextra -Wno-unused-but-set-variable' seems a hack. I guess I'd simply remove -Wextra for simplicity, since no much value is added here.
Regards,
Phil.
Quoted 3 lines · On Tue, 20 Dec 2022 08:30:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Do we really need this level? IIUC the problem with -Wextra is using a newer compiler toolchain it can include warnings we haven't fixed. Maybe worthwhile but it can break from times to times.
I think we just wanted to be overly zealous.
Flags typically used by QEMU are fine.
Shall I send a patch to drop -Wextra?
Signature · 2 lines
Alessandro Di Federico rev.ng Labs
Quoted 11 lines · Alessandro Di Federico
Quoted 3 lines · On Tue, 20 Dec 2022 08:30:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Do we really need this level? IIUC the problem with -Wextra is using a newer compiler toolchain it can include warnings we haven't fixed. Maybe worthwhile but it can break from times to times.
I think we just wanted to be overly zealous.
Flags typically used by QEMU are fine.Shall I send a patch to drop -Wextra?
Well I think so, but meanwhile I'm surprised nobody else reported that, not even the CI.
Quoted 22 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, December 20, 2022 8:20 AM
To: Alessandro Di Federico <[email protected]>
Cc: Taylor Simpson <[email protected]>; [email protected]; Paolo Montesel <[email protected]>; Anton Johansson <[email protected]>; [email protected]; [email protected]; Brian Cain <[email protected]>; Matheus Bernardino (QUIC) <[email protected]>; [email protected]
Subject: Re: [PULL 00/21] Hexagon update: bug fixes, performance, idef- parserQuoted 7 lines · Alessandro Di Federico
Quoted 3 lines · On Tue, 20 Dec 2022 08:30:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Do we really need this level? IIUC the problem with -Wextra is using a newer compiler toolchain it can include warnings we haven't fixed. Maybe worthwhile but it can break from times to times.
Quoted 7 lines
Quoted 4 lines
I think we just wanted to be overly zealous.
Flags typically used by QEMU are fine.Shall I send a patch to drop -Wextra?
Well I think so, but meanwhile I'm surprised nobody else reported that, not even the CI.
What version of clang are you using? I tried 15.0.6, but just dropping the -W extra didn't fix the problem. This worked for me
target/hexagon/meson.build +1 -1
@@ -197,7 +197,7 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs idef_parser_dir / 'parser-helpers.c'], include_directories: ['idef-parser', '../../include/'], dependencies: [glib_dep], - c_args: ['-Wextra'], + c_args: ['-Wno-unused-but-set-variable'], native: true )
Taylor