hex queue
The following changes since commit 3e246da2c3f85298b52f8a1154b832acf36aa656:
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2024-06-08 07:40:08 -0700)
are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20240608
for you to fetch changes up to 1967a1ea985299c090dfd3efc1e5323ce60d75df:
target/hexagon: idef-parser simplify predicate init (2024-06-08 17:49:36 -0700)
----------------------------------------------------------------
* hexagon: idef-parser cleanup
* hexagon: implement PC alignment exception, tests
* hexagon: fix for HVX new-value store
----------------------------------------------------------------
Anton Johansson (4):
target/hexagon: idef-parser remove unused defines target/hexagon: idef-parser remove undefined functions target/hexagon: idef-parser fix leak of init_list target/hexagon: idef-parser simplify predicate init
Matheus Tavares Bernardino (2):
Hexagon: fix HVX store new
Hexagon: add PC alignment check and exception
linux-user/hexagon/cpu_loop.c | 4 ++ target/hexagon/cpu.h | 7 ++ target/hexagon/cpu_bits.h | 4 ++ target/hexagon/gen_trans_funcs.py | 9 ++- target/hexagon/idef-parser/idef-parser.h | 10 --- target/hexagon/idef-parser/idef-parser.y | 2 - target/hexagon/idef-parser/parser-helpers.c | 35 +++++---- target/hexagon/idef-parser/parser-helpers.h | 13 ---- target/hexagon/macros.h | 3 - target/hexagon/op_helper.c | 9 ++- tests/tcg/hexagon/Makefile.target | 2 + tests/tcg/hexagon/hvx_misc.c | 23 ++++++ tests/tcg/hexagon/unaligned_pc.c | 107 ++++++++++++++++++++++++++++ 13 files changed, 179 insertions(+), 49 deletions(-) create mode 100644 tests/tcg/hexagon/unaligned_pc.c
[PULL 1/6] Hexagon: fix HVX store new
From: Matheus Tavares Bernardino <[email protected]>
At 09a7e7db0f (Hexagon (target/hexagon) Remove uses of op_regs_generated.h.inc, 2024-03-06), we've changed the logic of check_new_value() to use the new pre-calculated packet->insn[...].dest_idx instead of calculating the index on the fly using opcode_reginfo[...]. The dest_idx index is calculated roughly like the following:
for reg in iset[tag]["syntax"]:
if reg.is_written():
dest_idx = regno
break
Thus, we take the first register that is writtable. Before that, however, we also used to follow an alphabetical order on the register
type: 'd', 'e', 'x', and 'y'. No longer following that makes us select the wrong register index and the HVX store new instruction does not update the memory like expected.
Message-Id: <f548dc1c240819c724245e887f29f918441e9125.1716220379.git.quic_mathbern@quicinc.com>
--- target/hexagon/gen_trans_funcs.py | 9 ++++++--- tests/tcg/hexagon/hvx_misc.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-)
target/hexagon/gen_trans_funcs.py +6 -3
@@ -89,6 +89,7 @@ def gen_trans_funcs(f): new_read_idx = -1 dest_idx = -1 + dest_idx_reg_id = None has_pred_dest = "false" for regno, (reg_type, reg_id, *_) in enumerate(regs): reg = hex_common.get_register(tag, reg_type, reg_id)
@@ -97,9 +98,11 @@ def gen_trans_funcs(f): """)) if reg.is_read() and reg.is_new(): new_read_idx = regno - # dest_idx should be the first destination, so check for -1 - if reg.is_written() and dest_idx == -1: - dest_idx = regno + if reg.is_written(): + # dest_idx should be the first destination alphabetically + if dest_idx_reg_id is None or reg_id < dest_idx_reg_id: + dest_idx = regno + dest_idx_reg_id = reg_id if reg_type == "P" and reg.is_written() and not reg.is_read(): has_pred_dest = "true"
tests/tcg/hexagon/hvx_misc.c +23 -0
@@ -474,6 +474,27 @@ static void test_vcombine(void)check_output_w (__LINE__,BUFSIZE ); } +void test_store_new () +{ + asmvolatile ( +"r0 = #0x12345678\n" +"v0 = vsplat(r0)\n" +"r0 = #0xff00ff00\n" +"v1 = vsplat(r0)\n" +"{\n" +" vdeal(v1,v0,r0)\n" +" vmem(%0) = v0.new\n" +"}\n" + : + :"r" (&output[0 ]) + :"r0" ,"v0" ,"v1" ,"memory" + ); +for (int i =0 ; i <MAX_VEC_SIZE_BYTES /4 ; i++) { + expect[0 ].w[i] =0x12345678 ; + } +check_output_w (__LINE__,1 ); +} +int main () {init_buffers ();
@@ -515,6 +536,8 @@ int main()test_vcombine (); +test_store_new (); +puts (err ?"FAIL" :"PASS" );return err ?1 :0 ; }
Signature · 1 line
2.25.1
[PULL 2/6] Hexagon: add PC alignment check and exception
In reply to Brian CainFrom: Matheus Tavares Bernardino <[email protected]>
The Hexagon Programmer's Reference Manual says that the exception 0x1e should be raised upon an unaligned program counter. Let's implement that and also add some tests.
Message-Id: <277b7aeda2c717a96d4dde936b3ac77707cb6517.1714755107.git.quic_mathbern@quicinc.com>
--- linux-user/hexagon/cpu_loop.c | 4 ++ target/hexagon/cpu.h | 7 ++ target/hexagon/cpu_bits.h | 4 ++ target/hexagon/macros.h | 3 - target/hexagon/op_helper.c | 9 ++- tests/tcg/hexagon/Makefile.target | 2 + tests/tcg/hexagon/unaligned_pc.c | 107 ++++++++++++++++++++++++++++++ 7 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 tests/tcg/hexagon/unaligned_pc.c
linux-user/hexagon/cpu_loop.c +4 -0
@@ -60,6 +60,10 @@ void cpu_loop(CPUHexagonState *env) env->gpr[0 ] = ret; }break ; +case HEX_EXCP_PC_NOT_ALIGNED : +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , + env->gpr[HEX_REG_R31 ]); +break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);break ;
target/hexagon/cpu.h +7 -0
@@ -134,6 +134,10 @@ struct ArchCPU { FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1) +G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, +uint32_t exception, +uintptr_t pc); +static inline void cpu_get_tb_cpu_state (CPUHexagonState *env,vaddr *pc,uint64_t *cs_base,uint32_t *flags) {
@@ -144,6 +148,9 @@ static inline void cpu_get_tb_cpu_state(CPUHexagonState *env, vaddr *pc, hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,IS_TIGHT_LOOP ,1 ); } *flags = hex_flags; +if (*pc &PCALIGN_MASK ) { +hexagon_raise_exception_err (env,HEX_EXCP_PC_NOT_ALIGNED ,0 ); + } }typedef HexagonCPU ArchCPU ;
target/hexagon/cpu_bits.h +4 -0
@@ -20,9 +20,13 @@#include "qemu/bitops.h" +#define PCALIGN 4 +#define PCALIGN_MASK (PCALIGN - 1) +#define HEX_EXCP_FETCH_NO_UPAGE 0x012#define HEX_EXCP_INVALID_PACKET 0x015#define HEX_EXCP_INVALID_OPCODE 0x015 +#define HEX_EXCP_PC_NOT_ALIGNED 0x01e#define HEX_EXCP_PRIV_NO_UREAD 0x024#define HEX_EXCP_PRIV_NO_UWRITE 0x025
target/hexagon/macros.h +0 -3
@@ -22,9 +22,6 @@#include "hex_regs.h" #include "reg_fields.h" -#define PCALIGN 4 -#define PCALIGN_MASK (PCALIGN - 1) -#define GET_FIELD (FIELD ,REGIN ) \ fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \ reg_field_info[FIELD].offset)
target/hexagon/op_helper.c +4 -5
@@ -36,10 +36,9 @@#define SF_MANTBITS 23/* Exceptions processing helpers */ -static G_NORETURN -void do_raise_exception_err(CPUHexagonState *env, -uint32_t exception, -uintptr_t pc) +G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, +uint32_t exception, +uintptr_t pc) {CPUState *cs =env_cpu (env);qemu_log_mask (CPU_LOG_INT ,"%s: %d\n" , __func__, exception);
@@ -49,7 +48,7 @@ void do_raise_exception_err(CPUHexagonState *env, G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp) { -do_raise_exception_err (env, excp,0 ); +hexagon_raise_exception_err (env, excp,0 ); } void log_store32(CPUHexagonState *env, target_ulong addr,
tests/tcg/hexagon/Makefile.target +2 -0
@@ -51,6 +51,7 @@ HEX_TESTS += scatter_gather HEX_TESTS += hvx_misc HEX_TESTS += hvx_histogram HEX_TESTS += invalid-slots +HEX_TESTS += unaligned_pc run-and-check-exception = $(call run-test,$2,$3 2>$2.stderr; \ test $$? -eq 1 && grep -q "exception $(strip $1)" $2.stderr)
@@ -107,6 +108,7 @@ overflow: overflow.c hex_test.h preg_alias: preg_alias.c hex_test.h read_write_overlap: read_write_overlap.c hex_test.h reg_mut: reg_mut.c hex_test.h +unaligned_pc: unaligned_pc.c # This test has to be compiled for the -mv67t target usr: usr.c hex_test.h
tests/tcg/hexagon/unaligned_pc.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.25.1
[PULL 4/6] target/hexagon: idef-parser remove undefined functions
In reply to Brian CainFrom: Anton Johansson <[email protected]>
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/parser-helpers.h | 13 ------------- 1 file changed, 13 deletions(-)
target/hexagon/idef-parser/parser-helpers.h +0 -13
@@ -143,8 +143,6 @@ void commit(Context *c);#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 */
@@ -236,8 +234,6 @@ HexValue gen_extract_op(Context *c, 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,
@@ -274,13 +270,6 @@ 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,
@@ -349,8 +338,6 @@ HexValue gen_rvalue_ternary(Context *c, YYLTYPE *locp, HexValue *cond,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);
Signature · 1 line
2.25.1
[PULL 3/6] target/hexagon: idef-parser remove unused defines
In reply to Brian CainFrom: Anton Johansson <[email protected]>
Before switching to GArray/g_string_printf we used fixed size arrays for output buffers and instructions arguments among other things.
Macros defining the sizes of these buffers were left behind, remove them.
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/idef-parser.h | 10 ---------- 1 file changed, 10 deletions(-)
target/hexagon/idef-parser/idef-parser.h +0 -10
@@ -23,16 +23,6 @@#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 { \
Signature · 1 line
2.25.1
[PULL 6/6] target/hexagon: idef-parser simplify predicate init
In reply to Brian CainFrom: Anton Johansson <[email protected]>
Only predicate instruction arguments need to be initialized by idef-parser. This commit removes registers from the init_list and simplifies gen_inst_init_args() slightly.
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/idef-parser.y | 2 -- target/hexagon/idef-parser/parser-helpers.c | 26 +++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-)
target/hexagon/idef-parser/idef-parser.y +0 -2
@@ -233,8 +233,6 @@ code : '{' statements '}' argument_decl : REG { emit_arg(c, &@1, &$1); - /* Enqueue register into initialization list */ - g_array_append_val(c->inst.init_list, $1); } | PRED {
target/hexagon/idef-parser/parser-helpers.c +14 -12
@@ -1652,26 +1652,28 @@ void gen_inst(Context *c, GString *iname)/* -* Initialize declared but uninitialized registers, but only for -* non-conditional instructions +* Initialize declared but uninitialized instruction arguments. Only needed for +* predicate arguments, initialization of registers is handled by the Hexagon +* frontend. */ void gen_inst_init_args (Context *c,YYLTYPE *locp) { +HexValue *val =NULL ; +char suffix; + +/* If init_list is NULL arguments have already been initialized */ if (!c->inst.init_list) {return ; }for (unsigned i =0 ; i < c->inst.init_list->len; i++) { -HexValue *val = &g_array_index (c->inst.init_list, HexValue, i); -if (val->type ==REGISTER_ARG ) { -/* Nothing to do here */ - }else if (val->type ==PREDICATE ) { -char suffix = val->is_dotnew ?'N' :'V' ; -EMIT_HEAD (c,"tcg_gen_movi_i%u(P%c%c, 0);\n" , val->bit_width, - val->pred.id, suffix); - }else { -yyassert (c, locp, false,"Invalid arg type!" ); - } + val = &g_array_index (c->inst.init_list, HexValue, i); + suffix = val->is_dotnew ?'N' :'V' ; +yyassert (c, locp, val->type ==PREDICATE , +"Only predicates need to be initialized!" ); +yyassert (c, locp, val->bit_width ==32 , +"Predicates should always be 32 bits" ); +EMIT_HEAD (c,"tcg_gen_movi_i32(P%c%c, 0);\n" , val->pred.id, suffix); }/* Free argument init list once we have initialized everything */
Signature · 1 line
2.25.1
[PULL 5/6] target/hexagon: idef-parser fix leak of init_list
In reply to Brian CainFrom: Anton Johansson <[email protected]>
gen_inst_init_args() is called for instructions using a predicate as an rvalue. Upon first call, the list of arguments which might need initialization init_list is freed to indicate that they have been processed. For instructions without an rvalue predicate, gen_inst_init_args() isn't called and init_list will never be freed.
Free init_list from free_instruction() if it hasn't already been freed. A comment in free_instruction is also updated.
Message-Id: <[email protected]>
--- target/hexagon/idef-parser/parser-helpers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
target/hexagon/idef-parser/parser-helpers.c +8 -1
@@ -2121,9 +2121,16 @@ void free_instruction(Context *c) g_string_free(g_array_index(c->inst.strings, GString*, i), TRUE); }g_array_free (c->inst.strings, TRUE); +/* +* Free list of arguments that might need initialization, if they haven't +* already been freed. +*/ +if (c->inst.init_list) { +g_array_free (c->inst.init_list, TRUE); + }/* Free INAME token value */ g_string_free (c->inst.name, TRUE); -/* Free variables and registers */ +/* Free declared TCGv variables */ g_array_free (c->inst.allocated, TRUE);/* Initialize instruction-specific portion of the context */ memset (&(c->inst),0 ,sizeof (Inst));
Signature · 1 line
2.25.1
Richard Henderson
AppliedQuoted 8 lines · Brian Cain
The following changes since commit
3e246da2c3f85298b52f8a1154b832acf36aa656:Merge tag 'for-upstream' ofhttps://gitlab.com/bonzini/qemu into staging (2024-06-08 07:40:08 -0700)are available in the Git repository at:
https://github.com/quic/qemu tags/pull-hex-20240608
Quoted 8 lines
for you to fetch changes up to
1967a1ea985299c090dfd3efc1e5323ce60d75df:target/hexagon: idef-parser simplify predicate init (2024-06-08 17:49:36 -0700)----------------------------------------------------------------
* hexagon: idef-parser cleanup
* hexagon: implement PC alignment exception, tests
* hexagon: fix for HVX new-value store
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.
r~