target/xtensa: add FLIX support
PATCH 13/13 target/xtensa: prioritize load/store in FLIX bundles
In reply to Max FilippovLoad/store opcodes may raise MMU exceptions. Normally exceptions should be checked in priority order before any actual operations, but since MMU exceptions are tightly coupled with actual memory access, there's currently no way to do it.
Approximate this behavior by executing all load, then all store, and then all other opcodes in the FLIX bundles. Use opcode dependency mechanism to express ordering. Mark load/store opcodes with XTENSA_OP_{LOAD,STORE} flags. Newer libisa has classifier functions that can tell whether opcode is a load or store, but this information is not available in the existing overlays.
--- target/xtensa/cpu.h | 4 ++++ target/xtensa/translate.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-)
target/xtensa/cpu.h +4 -0
@@ -390,6 +390,10 @@ enum {XTENSA_OP_NAME_ARRAY =0x8000 ,XTENSA_OP_CONTROL_FLOW =0x10000 , +XTENSA_OP_STORE =0x20000 , +XTENSA_OP_LOAD =0x40000 , +XTENSA_OP_LOAD_STORE = + XTENSA_OP_LOAD | XTENSA_OP_STORE, }; typedef struct XtensaOpcodeOps {
target/xtensa/translate.c +32 -5
@@ -985,6 +985,10 @@ static bool op_depends_on(const struct slot_prop *a,if (a->op_flags &XTENSA_OP_CONTROL_FLOW ) {return true; } +if ((a->op_flags &XTENSA_OP_LOAD_STORE ) < + (b->op_flags &XTENSA_OP_LOAD_STORE )) { +return true; + }while (i < a->n_out && j < b->n_in) {if (a->out[i].resource < b->in[j].resource) { ++i;
@@ -1016,6 +1020,10 @@ static bool break_dependency(struct slot_prop *a,if (a->op_flags &XTENSA_OP_CONTROL_FLOW ) {return false; } +if ((a->op_flags &XTENSA_OP_LOAD_STORE ) < + (b->op_flags &XTENSA_OP_LOAD_STORE )) { +return false; + }while (i < a->n_out && j < b->n_in) {if (a->out[i].resource < b->in[j].resource) { ++i;
@@ -1292,7 +1300,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)if (slots >1 ) { slot_prop[slot].n_in =0 ; slot_prop[slot].n_out =0 ; - slot_prop[slot].op_flags =0 ; + slot_prop[slot].op_flags = ops->op_flags &XTENSA_OP_LOAD_STORE ; opnds =xtensa_opcode_num_operands (isa, opc);
@@ -3222,40 +3230,47 @@ static const XtensaOpcodeOps core_ops[] = { .name = "l16si", .translate = translate_ldst, .par = (const uint32_t[]){MO_TESW, false, false}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "l16ui", .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUW, false, false}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "l32ai", .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUL, true, false}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "l32e", .translate = translate_l32e, - .op_flags = XTENSA_OP_PRIVILEGED, + .op_flags = XTENSA_OP_PRIVILEGED | XTENSA_OP_LOAD, }, { .name = (const char * const[]) { "l32i", "l32i.n", NULL, }, .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUL, false, false}, - .op_flags = XTENSA_OP_NAME_ARRAY, + .op_flags = XTENSA_OP_NAME_ARRAY | XTENSA_OP_LOAD, }, { .name = "l32r", .translate = translate_l32r, + .op_flags = XTENSA_OP_LOAD, }, { .name = "l8ui", .translate = translate_ldst, .par = (const uint32_t[]){MO_UB, false, false}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "lddec", .translate = translate_mac16, .par = (const uint32_t[]){MAC16_NONE, 0, -4}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "ldinc", .translate = translate_mac16, .par = (const uint32_t[]){MAC16_NONE, 0, 4}, + .op_flags = XTENSA_OP_LOAD, }, { .name = "ldpte", .op_flags = XTENSA_OP_ILL,
@@ -4213,28 +4228,32 @@ static const XtensaOpcodeOps core_ops[] = { .name = "s16i", .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUW, false, true}, + .op_flags = XTENSA_OP_STORE, }, { .name = "s32c1i", .translate = translate_s32c1i, + .op_flags = XTENSA_OP_LOAD | XTENSA_OP_STORE, }, { .name = "s32e", .translate = translate_s32e, - .op_flags = XTENSA_OP_PRIVILEGED, + .op_flags = XTENSA_OP_PRIVILEGED | XTENSA_OP_STORE, }, { .name = (const char * const[]) { "s32i", "s32i.n", "s32nb", NULL, }, .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUL, false, true}, - .op_flags = XTENSA_OP_NAME_ARRAY, + .op_flags = XTENSA_OP_NAME_ARRAY | XTENSA_OP_STORE, }, { .name = "s32ri", .translate = translate_ldst, .par = (const uint32_t[]){MO_TEUL, true, true}, + .op_flags = XTENSA_OP_STORE, }, { .name = "s8i", .translate = translate_ldst, .par = (const uint32_t[]){MO_UB, false, true}, + .op_flags = XTENSA_OP_STORE, }, { .name = "salt", .translate = translate_salt,
@@ -5524,21 +5543,25 @@ static const XtensaOpcodeOps fpu2000_ops[] = { .name = "lsi", .translate = translate_ldsti, .par = (const uint32_t[]){false, false}, + .op_flags = XTENSA_OP_LOAD, .coprocessor = 0x1, }, { .name = "lsiu", .translate = translate_ldsti, .par = (const uint32_t[]){false, true}, + .op_flags = XTENSA_OP_LOAD, .coprocessor = 0x1, }, { .name = "lsx", .translate = translate_ldstx, .par = (const uint32_t[]){false, false}, + .op_flags = XTENSA_OP_LOAD, .coprocessor = 0x1, }, { .name = "lsxu", .translate = translate_ldstx, .par = (const uint32_t[]){false, true}, + .op_flags = XTENSA_OP_LOAD, .coprocessor = 0x1, }, { .name = "madd.s",
@@ -5618,21 +5641,25 @@ static const XtensaOpcodeOps fpu2000_ops[] = { .name = "ssi", .translate = translate_ldsti, .par = (const uint32_t[]){true, false}, + .op_flags = XTENSA_OP_STORE, .coprocessor = 0x1, }, { .name = "ssiu", .translate = translate_ldsti, .par = (const uint32_t[]){true, true}, + .op_flags = XTENSA_OP_STORE, .coprocessor = 0x1, }, { .name = "ssx", .translate = translate_ldstx, .par = (const uint32_t[]){true, false}, + .op_flags = XTENSA_OP_STORE, .coprocessor = 0x1, }, { .name = "ssxu", .translate = translate_ldstx, .par = (const uint32_t[]){true, true}, + .op_flags = XTENSA_OP_STORE, .coprocessor = 0x1, }, { .name = "sub.s",
Signature · 1 line
2.11.0
PATCH 11/13 target/xtensa: reorganize access to boolean registers
In reply to Max Filippovlibisa represents boolean registers b0..b16 as a BR register file and as BR4 and BR8 register groups. Add these register files and use OpcodeArg::{in,out} parameters to access boolean registers in translators.
--- target/xtensa/translate.c | 50 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-)
target/xtensa/translate.c +42 -8
@@ -80,6 +80,9 @@ static TCGv_i32 cpu_pc;static TCGv_i32 cpu_R[16 ];static TCGv_i32 cpu_FR[16 ];static TCGv_i32 cpu_MR[4 ]; +static TCGv_i32 cpu_BR[16 ]; +static TCGv_i32 cpu_BR4[4 ]; +static TCGv_i32 cpu_BR8[2 ];static TCGv_i32 cpu_SR[256 ];static TCGv_i32 cpu_UR[256 ];static TCGv_i32 cpu_windowbase_next;
@@ -227,6 +230,12 @@ void xtensa_translate_init(void)static const char *const mregnames[] = {"m0" ,"m1" ,"m2" ,"m3" , }; +static const char *const bregnames[] = { +"b0" ,"b1" ,"b2" ,"b3" , +"b4" ,"b5" ,"b6" ,"b7" , +"b8" ,"b9" ,"b10" ,"b11" , +"b12" ,"b13" ,"b14" ,"b15" , + };int i; cpu_pc = tcg_global_mem_new_i32(cpu_env,
@@ -252,6 +261,25 @@ void xtensa_translate_init(void) mregnames[i]); } +for (i =0 ; i <16 ; i++) { + cpu_BR[i] =tcg_global_mem_new_i32 (cpu_env, + offsetof(CPUXtensaState , + sregs[BR]), + bregnames[i]); +if (i %4 ==0 ) { + cpu_BR4[i /4 ] =tcg_global_mem_new_i32 (cpu_env, + offsetof(CPUXtensaState , + sregs[BR]), + bregnames[i]); + } +if (i %8 ==0 ) { + cpu_BR8[i /8 ] =tcg_global_mem_new_i32 (cpu_env, + offsetof(CPUXtensaState , + sregs[BR]), + bregnames[i]); + } + } +for (i =0 ; i <256 ; ++i) {if (sregnames[i].name) { cpu_SR[i] = tcg_global_mem_new_i32(cpu_env,
@@ -284,6 +312,12 @@ void **xtensa_get_regfile_by_name(const char *name) (void *)"MR", (void *)cpu_MR);g_hash_table_insert (xtensa_regfile_table, (void *)"FR" , (void *)cpu_FR); +g_hash_table_insert (xtensa_regfile_table, + (void *)"BR" , (void *)cpu_BR); +g_hash_table_insert (xtensa_regfile_table, + (void *)"BR4" , (void *)cpu_BR4); +g_hash_table_insert (xtensa_regfile_table, + (void *)"BR8" , (void *)cpu_BR8); }return (void **)g_hash_table_lookup (xtensa_regfile_table, (void *)name); }
@@ -1583,14 +1617,14 @@ static void translate_all(DisasContext *dc, const OpcodeArg arg[],TCGv_i32 mask =tcg_const_i32 (((1 << shift) -1 ) << arg[1 ].imm);TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_and_i32 (tmp, cpu_SR[BR ], mask); +tcg_gen_and_i32 (tmp, arg[1 ].in, mask);if (par[0 ]) {tcg_gen_addi_i32 (tmp, tmp,1 << arg[1 ].imm); }else {tcg_gen_add_i32 (tmp, tmp, mask); }tcg_gen_shri_i32 (tmp, tmp, arg[1 ].imm + shift); -tcg_gen_deposit_i32 (cpu_SR[BR ], cpu_SR[BR ], +tcg_gen_deposit_i32 (arg[0 ].out, arg[0 ].out, tmp, arg[0 ].imm,1 );tcg_temp_free (mask);tcg_temp_free (tmp);
@@ -1694,10 +1728,10 @@ static void translate_boolean(DisasContext *dc, const OpcodeArg arg[],TCGv_i32 tmp1 =tcg_temp_new_i32 ();TCGv_i32 tmp2 =tcg_temp_new_i32 (); -tcg_gen_shri_i32 (tmp1, cpu_SR[BR ], arg[1 ].imm); -tcg_gen_shri_i32 (tmp2, cpu_SR[BR ], arg[2 ].imm); +tcg_gen_shri_i32 (tmp1, arg[1 ].in, arg[1 ].imm); +tcg_gen_shri_i32 (tmp2, arg[2 ].in, arg[2 ].imm); op[par[0 ]](tmp1, tmp1, tmp2); -tcg_gen_deposit_i32 (cpu_SR[BR ], cpu_SR[BR ], tmp1, arg[0 ].imm,1 ); +tcg_gen_deposit_i32 (arg[0 ].out, arg[0 ].out, tmp1, arg[0 ].imm,1 );tcg_temp_free (tmp1);tcg_temp_free (tmp2); }
@@ -1707,7 +1741,7 @@ static void translate_bp(DisasContext *dc, const OpcodeArg arg[], {TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_andi_i32 (tmp, cpu_SR[BR ],1 << arg[0 ].imm); +tcg_gen_andi_i32 (tmp, arg[0 ].in,1 << arg[0 ].imm);gen_brcondi (dc, par[0 ], tmp,0 , arg[1 ].imm);tcg_temp_free (tmp); }
@@ -2074,7 +2108,7 @@ static void translate_movp(DisasContext *dc, const OpcodeArg arg[],TCGv_i32 zero =tcg_const_i32 (0 );TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_andi_i32 (tmp, cpu_SR[BR ],1 << arg[2 ].imm); +tcg_gen_andi_i32 (tmp, arg[2 ].in,1 << arg[2 ].imm);tcg_gen_movcond_i32 (par[0 ], arg[0 ].out, tmp, zero, arg[1 ].in, arg[0 ].in);
@@ -5296,7 +5330,7 @@ static void translate_movp_s(DisasContext *dc, const OpcodeArg arg[],TCGv_i32 zero =tcg_const_i32 (0 );TCGv_i32 tmp =tcg_temp_new_i32 (); -tcg_gen_andi_i32 (tmp, cpu_SR[BR ],1 << arg[2 ].imm); +tcg_gen_andi_i32 (tmp, arg[2 ].in,1 << arg[2 ].imm);tcg_gen_movcond_i32 (par[0 ], arg[0 ].out, tmp, zero, arg[1 ].in, arg[0 ].in);
Signature · 1 line
2.11.0
PATCH 12/13 target/xtensa: break circular register dependencies
In reply to Max FilippovCurrently topologic opcode sorting stops at the first detected dependency loop. Introduce struct opcode_arg_copy that describes temporary register copy. Scan remaining opcodes searching for dependencies that can be broken, break them by introducing temporary register copies and record them in an array. In case of success create local temporaries and initialize them with current register values. Share single temporary copy between all register users. Delete temporaries after translation.
--- target/xtensa/translate.c | 127 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 4 deletions(-)
target/xtensa/translate.c +123 -4
@@ -935,6 +935,12 @@ static int gen_postprocess(DisasContext *dc, int slot)return slot; } +struct opcode_arg_copy { +uint32_t resource; +void *temp; +OpcodeArg *arg; +}; +struct opcode_arg_info {uint32_t resource;int index;
@@ -961,6 +967,11 @@ static uint32_t encode_resource(enum resource_type r, unsigned g, unsigned n)return (r <<24 ) | (g <<16 ) | n; } +static enum resource_type get_resource_type (uint32_t resource) +{ +return resource >>24 ; +} +/* * a depends on b if b must be executed before a, * because a's side effects will destroy b's inputs.
@@ -987,6 +998,49 @@ static bool op_depends_on(const struct slot_prop *a, }/* +* Try to break a dependency on b, append temporary register copy records +* to the end of copy and update n_copy in case of success. +* This is not always possible: e.g. control flow must always be the last, +* load/store must be first and state dependencies are not supported yet. +*/ +static bool break_dependency (struct slot_prop *a, +struct slot_prop *b, +struct opcode_arg_copy *copy, +unsigned *n_copy) +{ +unsigned i =0 ; +unsigned j =0 ; +unsigned n = *n_copy; +bool rv = false; + +if (a->op_flags &XTENSA_OP_CONTROL_FLOW ) { +return false; + } +while (i < a->n_out && j < b->n_in) { +if (a->out[i].resource < b->in[j].resource) { + ++i; + }else if (a->out[i].resource > b->in[j].resource) { + ++j; + }else { +int index = b->in[j].index; + +if (get_resource_type (a->out[i].resource) !=RES_REGFILE || + index <0 ) { +return false; + } + copy[n].resource = b->in[j].resource; + copy[n].arg = b->arg + index; + ++n; + ++i; + ++j; + rv = true; + } + } + *n_copy = n; +return rv; +} + +/* * Calculate evaluation order for slot opcodes. * Build opcode order graph and output its nodes in topological sort order. * An edge a -> b in the graph means that opcode a must be followed by
@@ -994,7 +1048,9 @@ static bool op_depends_on(const struct slot_prop *a,*/ static bool tsort (struct slot_prop *slot,struct slot_prop *sorted[], -unsigned n) +unsigned n, +struct opcode_arg_copy *copy, +unsigned *n_copy) {struct tsnode {unsigned n_in_edge;
@@ -1007,7 +1063,8 @@ static bool tsort(struct slot_prop *slot,unsigned n_in =0 ;unsigned n_out =0 ;unsigned n_edge =0 ; -unsigned in_idx; +unsigned in_idx =0 ; +unsigned node_idx =0 ;for (i =0 ; i < n; ++i) { node[i].n_in_edge =0 ;
@@ -1035,7 +1092,8 @@ static bool tsort(struct slot_prop *slot, } } -for (in_idx =0 ; in_idx < n_in; ++in_idx) { +again: +for (; in_idx < n_in; ++in_idx) { i = in[in_idx]; sorted[n_out] = slot + i; ++n_out;
@@ -1047,6 +1105,29 @@ static bool tsort(struct slot_prop *slot, } } } +if (n_edge) { +for (; node_idx < n; ++node_idx) { +struct tsnode *cnode = node + node_idx; + +if (cnode->n_in_edge) { +for (j =0 ; j < cnode->n_out_edge; ++j) { +unsigned k = cnode->out_edge[j]; + +if (break_dependency (slot + k, slot + node_idx, + copy, n_copy) && + --node[k].n_in_edge ==0 ) { + in[n_in] = k; + ++n_in; + --n_edge; + cnode->out_edge[j] = + cnode->out_edge[cnode->n_out_edge -1 ]; + --cnode->n_out_edge; + goto again; + } + } + } + } + }return n_edge ==0 ; }
@@ -1084,6 +1165,15 @@ static int resource_compare(const void *a, const void *b) -1 : (pa->resource > pb->resource ? 1 : 0); } +static int arg_copy_compare (const void *a,const void *b) +{ +const struct opcode_arg_copy *pa = a; +const struct opcode_arg_copy *pb = b; + +return pa->resource < pb->resource ? +-1 : (pa->resource > pb->resource ?1 :0 ); +} +static void disas_xtensa_insn (CPUXtensaState *env,DisasContext *dc) {xtensa_isa isa = dc->config->isa;
@@ -1095,6 +1185,8 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)uint32_t op_flags =0 ;struct slot_prop slot_prop[MAX_INSN_SLOTS ];struct slot_prop *ordered[MAX_INSN_SLOTS ]; +struct opcode_arg_copy arg_copy[MAX_INSN_SLOTS *MAX_OPCODE_ARGS ]; +unsigned n_arg_copy =0 ;uint32_t debug_cause =0 ;uint32_t windowed_register =0 ;uint32_t coprocessor =0 ;
@@ -1249,7 +1341,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) }if (slots >1 ) { -if (!tsort (slot_prop, ordered, slots)) { +if (!tsort (slot_prop, ordered, slots, arg_copy, &n_arg_copy)) {qemu_log_mask (LOG_UNIMP ,"Circular resource dependencies (pc = %08x)\n" , dc->pc);
@@ -1297,6 +1389,29 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)return ; } +if (n_arg_copy) { +uint32_t resource; +void *temp; +unsigned j; + +qsort (arg_copy, n_arg_copy,sizeof (*arg_copy), arg_copy_compare); +for (i = j =0 ; i < n_arg_copy; ++i) { +if (i ==0 || arg_copy[i].resource != resource) { + resource = arg_copy[i].resource; + temp =tcg_temp_local_new (); +tcg_gen_mov_i32 (temp, arg_copy[i].arg->in); + arg_copy[i].temp = temp; + +if (i != j) { + arg_copy[j] = arg_copy[i]; + } + ++j; + } + arg_copy[i].arg->in = temp; + } + n_arg_copy = j; + } +if (op_flags &XTENSA_OP_DIVIDE_BY_ZERO ) {for (slot =0 ; slot < slots; ++slot) {if (slot_prop[slot].ops->op_flags &XTENSA_OP_DIVIDE_BY_ZERO ) {
@@ -1314,6 +1429,10 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) ops->translate (dc, pslot->arg, ops->par); } +for (i =0 ; i < n_arg_copy; ++i) { +tcg_temp_free (arg_copy[i].temp); + } +if (dc->base.is_jmp ==DISAS_NEXT ) {gen_postprocess (dc,0 ); dc->op_flags =0 ;
Signature · 1 line
2.11.0
PATCH 4/13 target/xtensa: implement wide branches and loops
In reply to Max FilippovFLIX adds branch and loop instruction variants with 15- and 18-bit wide target offset. Implement them as additional names for the ordinary branch/loop opcodes.
--- target/xtensa/translate.c | 129 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 27 deletions(-)
target/xtensa/translate.c +102 -27
@@ -2463,40 +2463,64 @@ static const XtensaOpcodeOps core_ops[] = { .translate = translate_all, .par = (const uint32_t[]){false, 8}, }, { - .name = "ball", + .name = (const char * const[]) { +"ball" ,"ball.w15" ,"ball.w18" ,NULL , + }, .translate = translate_ball, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bany", + .name = (const char *const []) { +"bany" ,"bany.w15" ,"bany.w18" ,NULL , + }, .translate = translate_bany, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bbc", + .name = (const char *const []) { +"bbc" ,"bbc.w15" ,"bbc.w18" ,NULL , + }, .translate = translate_bb, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bbci", + .name = (const char *const []) { +"bbci" ,"bbci.w15" ,"bbci.w18" ,NULL , + }, .translate = translate_bbi, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bbs", + .name = (const char *const []) { +"bbs" ,"bbs.w15" ,"bbs.w18" ,NULL , + }, .translate = translate_bb, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bbsi", + .name = (const char *const []) { +"bbsi" ,"bbsi.w15" ,"bbsi.w18" ,NULL , + }, .translate = translate_bbi, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "beq", + .name = (const char *const []) { +"beq" ,"beq.w15" ,"beq.w18" ,NULL , + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "beqi", + .name = (const char *const []) { +"beqi" ,"beqi.w15" ,"beqi.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { .name = (const char *const []) { - "beqz", "beqz.n", NULL, +"beqz" ,"beqz.n" ,"beqz.w15" ,"beqz.w18" ,NULL , }, .translate = translate_bz, .par = (const uint32_t[]){TCG_COND_EQ},
@@ -2506,68 +2530,110 @@ static const XtensaOpcodeOps core_ops[] = { .translate = translate_bp, .par = (const uint32_t[]){TCG_COND_EQ}, }, { - .name = "bge", + .name = (const char * const[]) { + "bge", "bge.w15", "bge.w18", NULL, + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_GE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bgei", + .name = (const char * const[]) { +"bgei" ,"bgei.w15" ,"bgei.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_GE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bgeu", + .name = (const char *const []) { +"bgeu" ,"bgeu.w15" ,"bgeu.w18" ,NULL , + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_GEU}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bgeui", + .name = (const char *const []) { +"bgeui" ,"bgeui.w15" ,"bgeui.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_GEU}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bgez", + .name = (const char *const []) { +"bgez" ,"bgez.w15" ,"bgez.w18" ,NULL , + }, .translate = translate_bz, .par = (const uint32_t[]){TCG_COND_GE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "blt", + .name = (const char *const []) { +"blt" ,"blt.w15" ,"blt.w18" ,NULL , + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_LT}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "blti", + .name = (const char *const []) { +"blti" ,"blti.w15" ,"blti.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_LT}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bltu", + .name = (const char *const []) { +"bltu" ,"bltu.w15" ,"bltu.w18" ,NULL , + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_LTU}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bltui", + .name = (const char *const []) { +"bltui" ,"bltui.w15" ,"bltui.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_LTU}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bltz", + .name = (const char *const []) { +"bltz" ,"bltz.w15" ,"bltz.w18" ,NULL , + }, .translate = translate_bz, .par = (const uint32_t[]){TCG_COND_LT}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bnall", + .name = (const char *const []) { +"bnall" ,"bnall.w15" ,"bnall.w18" ,NULL , + }, .translate = translate_ball, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bne", + .name = (const char *const []) { +"bne" ,"bne.w15" ,"bne.w18" ,NULL , + }, .translate = translate_b, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bnei", + .name = (const char *const []) { +"bnei" ,"bnei.w15" ,"bnei.w18" ,NULL , + }, .translate = translate_bi, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { .name = (const char *const []) { - "bnez", "bnez.n", NULL, +"bnez" ,"bnez.n" ,"bnez.w15" ,"bnez.w18" ,NULL , }, .translate = translate_bz, .par = (const uint32_t[]){TCG_COND_NE}, .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "bnone", + .name = (const char *const []) { +"bnone" ,"bnone.w15" ,"bnone.w18" ,NULL , + }, .translate = translate_bany, .par = (const uint32_t[]){TCG_COND_EQ}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { .name = "break", .translate = translate_nop,
@@ -2785,17 +2851,26 @@ static const XtensaOpcodeOps core_ops[] = { .name = "ldpte", .op_flags = XTENSA_OP_ILL, }, { - .name = "loop", + .name = (const char * const[]) { + "loop", "loop.w15", NULL, + }, .translate = translate_loop, .par = (const uint32_t[]){TCG_COND_NEVER}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "loopgtz", + .name = (const char * const[]) { + "loopgtz", "loopgtz.w15", NULL, + }, .translate = translate_loop, .par = (const uint32_t[]){TCG_COND_GT}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { - .name = "loopnez", + .name = (const char * const[]) { + "loopnez", "loopnez.w15", NULL, + }, .translate = translate_loop, .par = (const uint32_t[]){TCG_COND_NE}, + .op_flags = XTENSA_OP_NAME_ARRAY, }, { .name = "max", .translate = translate_smax,
Signature · 1 line
2.11.0
PATCH 9/13 target/xtensa: reorganize register handling in translators
In reply to Max FilippovTo support circular register dependencies in FLIX bundles opcode inputs and outputs must be separate and adjustable. Circular dependencies can be broken by making temporary copies of opcode inputs and substituting them into the arguments array instead of the original registers.
E.g. the circular register dependency in the following bundle:
{ mov a2, a3 ; mov a3, a2 }
can be resolved by making copy a2' = a2 and substituting it as input argument of the second opcode:
{ mov a2, a3 ; mov a3, a2' }
Change opcode translator prototype to accept OpcodeArg array as argument. For each register argument initialize OpcodeArg::{in,out} with TCGv_* of the respective register. Don't explicitly use cpu_R in the opcode translators, use OpcodeArg::{in,out} instead.
--- target/xtensa/cpu.h | 15 +- target/xtensa/helper.c | 15 + target/xtensa/translate.c | 700 ++++++++++++++++++++++++---------------------- 3 files changed, 386 insertions(+), 344 deletions(-)
target/xtensa/cpu.h +12 -3
@@ -345,14 +345,21 @@ typedef struct XtensaMemory { } location[MAX_NMEMORY ]; } XtensaMemory; +typedef struct opcode_arg { +uint32_t imm; +uint32_t raw_imm; +void *in; +void *out; +}OpcodeArg ; +typedef struct DisasContext DisasContext ; -typedef void (*XtensaOpcodeOp )(DisasContext *dc,const uint32_t arg[], +typedef void (*XtensaOpcodeOp )(DisasContext *dc,const OpcodeArg arg[],const uint32_t par[]);typedef bool (*XtensaOpcodeBoolTest )(DisasContext *dc, -const uint32_t arg[], +const OpcodeArg arg[],const uint32_t par[]);typedef uint32_t (*XtensaOpcodeUintTest )(DisasContext *dc, -const uint32_t arg[], +const OpcodeArg arg[],const uint32_t par[]);enum {
@@ -450,6 +457,7 @@ struct XtensaConfig {XtensaOpcodeOps **opcode_ops;const XtensaOpcodeTranslators **opcode_translators;xtensa_regfile a_regfile; +void ***regfile;uint32_t clock_freq_khz;
@@ -578,6 +586,7 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,XTENSA_CPU_TYPE_NAME (XTENSA_DEFAULT_CPU_NOMMU_MODEL) void xtensa_translate_init(void); +void **xtensa_get_regfile_by_name (const char *name);void xtensa_breakpoint_handler (CPUState *cs);void xtensa_register_core (XtensaConfigList *node);void xtensa_sim_open_console (Chardev *chr);
target/xtensa/helper.c +15 -0
@@ -91,11 +91,13 @@ static void init_libisa(XtensaConfig *config)unsigned i, j;unsigned opcodes;unsigned formats; +unsigned regfiles; config->isa =xtensa_isa_init (config->isa_internal,NULL ,NULL );assert (xtensa_isa_maxlength (config->isa) <=MAX_INSN_LENGTH ); opcodes =xtensa_isa_num_opcodes (config->isa); formats =xtensa_isa_num_formats (config->isa); + regfiles =xtensa_isa_num_regfiles (config->isa); config->opcode_ops = g_new(XtensaOpcodeOps *, opcodes);for (i =0 ; i < formats; ++i) {
@@ -125,6 +127,19 @@ static void init_libisa(XtensaConfig *config) config->opcode_ops[i] = ops; } config->a_regfile =xtensa_regfile_lookup (config->isa,"AR" ); + + config->regfile = g_new(void **, regfiles); +for (i =0 ; i < regfiles; ++i) { +const char *name =xtensa_regfile_name (config->isa, i); + + config->regfile[i] =xtensa_get_regfile_by_name (name); +#ifdef DEBUG +if (config->regfile[i] ==NULL ) { +fprintf (stderr,"regfile '%s' not found for %s\n" , + name, config->name); + } +#endif + } }static void xtensa_finalize_config (XtensaConfig *config)
target/xtensa/translate.c +359 -341
1,614 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 10/13 target/xtensa: reorganize access to MAC16 registers
In reply to Max Filippovlibisa represents MAC16 registers m0..m3 as an MR register file. Add this register file and reference its registers directly from the translate_mac16. Drop translator parameter that indicates whether opcode argument is in ar or in mr.
--- target/xtensa/translate.c | 186 +++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 94 deletions(-)
target/xtensa/translate.c +92 -94
@@ -79,6 +79,7 @@ struct DisasContext {static TCGv_i32 cpu_pc;static TCGv_i32 cpu_R[16 ];static TCGv_i32 cpu_FR[16 ]; +static TCGv_i32 cpu_MR[4 ];static TCGv_i32 cpu_SR[256 ];static TCGv_i32 cpu_UR[256 ];static TCGv_i32 cpu_windowbase_next;
@@ -223,6 +224,9 @@ void xtensa_translate_init(void)"f8" ,"f9" ,"f10" ,"f11" , "f12", "f13", "f14", "f15", }; +static const char *const mregnames[] = { +"m0" ,"m1" ,"m2" ,"m3" , + };int i; cpu_pc = tcg_global_mem_new_i32(cpu_env,
@@ -230,14 +234,22 @@ void xtensa_translate_init(void)for (i =0 ; i <16 ; i++) { cpu_R[i] =tcg_global_mem_new_i32 (cpu_env, - offsetof(CPUXtensaState, regs[i]), - regnames[i]); + offsetof(CPUXtensaState, regs[i]), + regnames[i]); }for (i =0 ; i <16 ; i++) { cpu_FR[i] =tcg_global_mem_new_i32 (cpu_env, - offsetof(CPUXtensaState, fregs[i].f32[FP_F32_LOW]), - fregnames[i]); + offsetof(CPUXtensaState , + fregs[i].f32[FP_F32_LOW]), + fregnames[i]); + } + +for (i =0 ; i <4 ; i++) { + cpu_MR[i] =tcg_global_mem_new_i32 (cpu_env, + offsetof(CPUXtensaState , + sregs[MR + i]), + mregnames[i]); }for (i =0 ; i <256 ; ++i) {
@@ -269,6 +281,8 @@ void **xtensa_get_regfile_by_name(const char *name)g_hash_table_insert (xtensa_regfile_table, (void *)"AR" , (void *)cpu_R);g_hash_table_insert (xtensa_regfile_table, + (void *)"MR" , (void *)cpu_MR); +g_hash_table_insert (xtensa_regfile_table, (void *)"FR" , (void *)cpu_FR); }return (void **)g_hash_table_lookup (xtensa_regfile_table, (void *)name);
@@ -1943,24 +1957,12 @@ enum { MAC16_XH = 0x2, }; -enum { -MAC16_AA , -MAC16_AD , -MAC16_DA , -MAC16_DD , - -MAC16_XD =0x1 , -MAC16_DX =0x2 , -}; -static void translate_mac16 (DisasContext *dc,const OpcodeArg arg[],const uint32_t par[]) {int op = par[0 ]; -bool is_m1_sr = par[1 ] &MAC16_DX ; -bool is_m2_sr = par[1 ] &MAC16_XD ; -unsigned half = par[2 ]; -uint32_t ld_offset = par[3 ]; +unsigned half = par[1 ]; +uint32_t ld_offset = par[2 ];unsigned off = ld_offset ?2 :0 ;TCGv_i32 vaddr =tcg_temp_new_i32 ();TCGv_i32 mem32 =tcg_temp_new_i32 ();
@@ -1971,13 +1973,9 @@ static void translate_mac16(DisasContext *dc, const OpcodeArg arg[],tcg_gen_qemu_ld32u (mem32, vaddr, dc->cring); }if (op !=MAC16_NONE ) { -TCGv_i32 m1 =gen_mac16_m (is_m1_sr ? - cpu_SR[MR + arg[off].imm] : - arg[off].in, +TCGv_i32 m1 =gen_mac16_m (arg[off].in, half &MAC16_HX , op ==MAC16_UMUL ); -TCGv_i32 m2 =gen_mac16_m (is_m2_sr ? - cpu_SR[MR + arg[off +1 ].imm] : - arg[off +1 ].in, +TCGv_i32 m2 =gen_mac16_m (arg[off +1 ].in, half &MAC16_XH , op ==MAC16_UMUL );if (op ==MAC16_MUL || op ==MAC16_UMUL ) {
@@ -3100,11 +3098,11 @@ static const XtensaOpcodeOps core_ops[] = { }, { .name = "lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_NONE, 0, 0, -4}, + .par = (const uint32_t[]){MAC16_NONE, 0, -4}, }, { .name = "ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_NONE, 0, 0, 4}, + .par = (const uint32_t[]){MAC16_NONE, 0, 4}, }, { .name = "ldpte", .op_flags = XTENSA_OP_ILL,
@@ -3187,67 +3185,67 @@ static const XtensaOpcodeOps core_ops[] = { }, { .name = "mul.aa.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HH, 0}, }, { .name = "mul.aa.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HL, 0}, }, { .name = "mul.aa.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LH, 0}, }, { .name = "mul.aa.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LL, 0}, }, { .name = "mul.ad.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HH, 0}, }, { .name = "mul.ad.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HL, 0}, }, { .name = "mul.ad.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LH, 0}, }, { .name = "mul.ad.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_AD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LL, 0}, }, { .name = "mul.da.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HH, 0}, }, { .name = "mul.da.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HL, 0}, }, { .name = "mul.da.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LH, 0}, }, { .name = "mul.da.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LL, 0}, }, { .name = "mul.dd.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HH, 0}, }, { .name = "mul.dd.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_HL, 0}, }, { .name = "mul.dd.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LH, 0}, }, { .name = "mul.dd.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MUL, MAC16_DD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MUL, MAC16_LL, 0}, }, { .name = "mul16s", .translate = translate_mul16,
@@ -3259,198 +3257,198 @@ static const XtensaOpcodeOps core_ops[] = { }, { .name = "mula.aa.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 0}, }, { .name = "mula.aa.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 0}, }, { .name = "mula.aa.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 0}, }, { .name = "mula.aa.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 0}, }, { .name = "mula.ad.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 0}, }, { .name = "mula.ad.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 0}, }, { .name = "mula.ad.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 0}, }, { .name = "mula.ad.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_AD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 0}, }, { .name = "mula.da.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 0}, }, { .name = "mula.da.hh.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HH, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, -4}, }, { .name = "mula.da.hh.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HH, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 4}, }, { .name = "mula.da.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 0}, }, { .name = "mula.da.hl.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HL, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, -4}, }, { .name = "mula.da.hl.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_HL, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 4}, }, { .name = "mula.da.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 0}, }, { .name = "mula.da.lh.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LH, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, -4}, }, { .name = "mula.da.lh.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LH, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 4}, }, { .name = "mula.da.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 0}, }, { .name = "mula.da.ll.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LL, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, -4}, }, { .name = "mula.da.ll.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DA, MAC16_LL, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 4}, }, { .name = "mula.dd.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 0}, }, { .name = "mula.dd.hh.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HH, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, -4}, }, { .name = "mula.dd.hh.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HH, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HH, 4}, }, { .name = "mula.dd.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 0}, }, { .name = "mula.dd.hl.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HL, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, -4}, }, { .name = "mula.dd.hl.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_HL, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_HL, 4}, }, { .name = "mula.dd.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 0}, }, { .name = "mula.dd.lh.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LH, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, -4}, }, { .name = "mula.dd.lh.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LH, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LH, 4}, }, { .name = "mula.dd.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 0}, }, { .name = "mula.dd.ll.lddec", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LL, -4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, -4}, }, { .name = "mula.dd.ll.ldinc", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULA, MAC16_DD, MAC16_LL, 4}, + .par = (const uint32_t[]){MAC16_MULA, MAC16_LL, 4}, }, { .name = "mull", .translate = translate_mull, }, { .name = "muls.aa.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HH, 0}, }, { .name = "muls.aa.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HL, 0}, }, { .name = "muls.aa.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LH, 0}, }, { .name = "muls.aa.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LL, 0}, }, { .name = "muls.ad.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HH, 0}, }, { .name = "muls.ad.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HL, 0}, }, { .name = "muls.ad.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LH, 0}, }, { .name = "muls.ad.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_AD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LL, 0}, }, { .name = "muls.da.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HH, 0}, }, { .name = "muls.da.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HL, 0}, }, { .name = "muls.da.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LH, 0}, }, { .name = "muls.da.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LL, 0}, }, { .name = "muls.dd.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DD, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HH, 0}, }, { .name = "muls.dd.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DD, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_HL, 0}, }, { .name = "muls.dd.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DD, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LH, 0}, }, { .name = "muls.dd.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_MULS, MAC16_DD, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_MULS, MAC16_LL, 0}, }, { .name = "mulsh", .translate = translate_mulh,
@@ -4160,19 +4158,19 @@ static const XtensaOpcodeOps core_ops[] = { }, { .name = "umul.aa.hh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_UMUL, MAC16_AA, MAC16_HH, 0}, + .par = (const uint32_t[]){MAC16_UMUL, MAC16_HH, 0}, }, { .name = "umul.aa.hl", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_UMUL, MAC16_AA, MAC16_HL, 0}, + .par = (const uint32_t[]){MAC16_UMUL, MAC16_HL, 0}, }, { .name = "umul.aa.lh", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_UMUL, MAC16_AA, MAC16_LH, 0}, + .par = (const uint32_t[]){MAC16_UMUL, MAC16_LH, 0}, }, { .name = "umul.aa.ll", .translate = translate_mac16, - .par = (const uint32_t[]){MAC16_UMUL, MAC16_AA, MAC16_LL, 0}, + .par = (const uint32_t[]){MAC16_UMUL, MAC16_LL, 0}, }, { .name = "waiti", .translate = translate_waiti,
Signature · 1 line
2.11.0
PATCH 1/13 target/xtensa: move xtensa_finalize_config to xtensa_core_class_init
In reply to Max FilippovDon't run xtensa_finalize_config at the time of core registration, instead run it at the CPU class initialization.
--- target/xtensa/cpu.h | 1 - target/xtensa/helper.c | 36 +++++++++++++++++++----------------- target/xtensa/overlay_tool.h | 1 - 3 files changed, 19 insertions(+), 19 deletions(-)
target/xtensa/cpu.h +0 -1
@@ -566,7 +566,6 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,void xtensa_translate_init (void );void xtensa_breakpoint_handler (CPUState *cs); -void xtensa_finalize_config (XtensaConfig *config);void xtensa_register_core (XtensaConfigList *node);void xtensa_sim_open_console (Chardev *chr);void check_interrupts (CPUXtensaState *s);
target/xtensa/helper.c +19 -17
@@ -34,22 +34,6 @@static struct XtensaConfigList *xtensa_cores; -static void xtensa_core_class_init (ObjectClass *oc,void *data) -{ -CPUClass *cc =CPU_CLASS (oc); -XtensaCPUClass *xcc =XTENSA_CPU_CLASS (oc); -const XtensaConfig *config = data; - - xcc->config = config; - -/* Use num_core_regs to see only non-privileged registers in an unmodified -* gdb. Use num_regs to see all registers. gdb modification is required -* for that: reset bit 0 in the 'flags' field of the registers definitions -* in the gdb/xtensa-config.c inside gdb source tree or inside gdb overlay. -*/ - cc->gdb_num_core_regs = config->gdb_regmap.num_regs; -} -static void init_libisa (XtensaConfig *config) {unsigned i, j;
@@ -91,7 +75,7 @@ static void init_libisa(XtensaConfig *config) config->a_regfile =xtensa_regfile_lookup (config->isa,"AR" ); } -void xtensa_finalize_config (XtensaConfig *config) +static void xtensa_finalize_config (XtensaConfig *config) {if (config->isa_internal) {init_libisa (config);
@@ -112,6 +96,24 @@ void xtensa_finalize_config(XtensaConfig *config) } } +static void xtensa_core_class_init (ObjectClass *oc,void *data) +{ +CPUClass *cc =CPU_CLASS (oc); +XtensaCPUClass *xcc =XTENSA_CPU_CLASS (oc); +XtensaConfig *config = data; + +xtensa_finalize_config (config); + xcc->config = config; + +/* +* Use num_core_regs to see only non-privileged registers in an unmodified +* gdb. Use num_regs to see all registers. gdb modification is required +* for that: reset bit 0 in the 'flags' field of the registers definitions +* in the gdb/xtensa-config.c inside gdb source tree or inside gdb overlay. +*/ + cc->gdb_num_core_regs = config->gdb_regmap.num_regs; +} +void xtensa_register_core (XtensaConfigList *node) {TypeInfo type = {
target/xtensa/overlay_tool.h +0 -1
@@ -377,7 +377,6 @@static XtensaConfigList node = { \ .config = &core, \ }; \ -xtensa_finalize_config (&core); \ xtensa_register_core(&node); \ }#else
Signature · 1 line
2.11.0
PATCH 5/13 target/xtensa: sort FLIX instruction opcodes
In reply to Max FilippovOpcodes in different slots may read and write same resources (registers, states). In the absence of resource dependency loops it must be possible to sort opcodes to avoid interference.
Record resources used by each opcode in the bundle. Build opcode dependency graph and use topological sort to order its nodes. In case of success translate opcodes in sort order. In case of failure report and raise invalid opcode exception.
--- target/xtensa/cpu.h | 2 + target/xtensa/translate.c | 226 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 220 insertions(+), 8 deletions(-)
target/xtensa/cpu.h +2 -0
@@ -373,6 +373,8 @@ enum {XTENSA_OP_EXIT_TB_0 =0x800 ,XTENSA_OP_NAME_ARRAY =0x8000 , + + XTENSA_OP_CONTROL_FLOW = 0x10000, }; typedef struct XtensaOpcodeOps {
target/xtensa/translate.c +218 -8
251 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 7/13 target/xtensa: move WINDOW_BASE SR update to postprocessing
In reply to Max FilippovOpcodes that modify WINDOW_BASE SR don't have dependency on opcodes that use windowed registers. If such opcodes are combined in a single instruction they may not be correctly ordered. Instead of adding said dependency use temporary register to store changed WINDOW_BASE value and do actual register window rotation as a postprocessing step. Not all opcodes that change WINDOW_BASE need this: retw, rfwo and rfwu are also jump opcodes, so they are guaranteed to be translated last and thus will not affect other opcodes in the same instruction.
--- target/xtensa/cpu.h | 1 + target/xtensa/helper.h | 3 +-- target/xtensa/translate.c | 30 ++++++++++++++++++++++-------- target/xtensa/win_helper.c | 14 ++++---------- 4 files changed, 28 insertions(+), 20 deletions(-)
target/xtensa/cpu.h +1 -0
@@ -486,6 +486,7 @@ typedef struct CPUXtensaState {float64 f64; } fregs[16 ];float_status fp_status; +uint32_t windowbase_next;#ifndef CONFIG_USER_ONLY xtensa_tlb_entry itlb[7 ][MAX_TLB_WAY_SIZE ];
target/xtensa/helper.h +1 -2
@@ -3,12 +3,11 @@ DEF_HELPER_3(exception_cause, noreturn, env, i32, i32) DEF_HELPER_4(exception_cause_vaddr, noreturn, env, i32, i32, i32) DEF_HELPER_3(debug_exception, noreturn, env, i32, i32) -DEF_HELPER_2(wsr_windowbase, void, env, i32) +DEF_HELPER_1(sync_windowbase, void, env) DEF_HELPER_4(entry, void, env, i32, i32, i32) DEF_HELPER_2(test_ill_retw, void, env, i32) DEF_HELPER_2(test_underflow_retw, void, env, i32) DEF_HELPER_2(retw, i32, env, i32) -DEF_HELPER_2(rotw, void, env, i32) DEF_HELPER_3(window_check, noreturn, env, i32, i32) DEF_HELPER_1(restore_owb, void, env)DEF_HELPER_2 (movsp, void, env, i32)
target/xtensa/translate.c +22 -8
@@ -82,6 +82,7 @@ static TCGv_i32 cpu_R[16];static TCGv_i32 cpu_FR[16 ];static TCGv_i32 cpu_SR[256 ];static TCGv_i32 cpu_UR[256 ]; +static TCGv_i32 cpu_windowbase_next;#include "exec/gen-icount.h"
@@ -253,6 +254,11 @@ void xtensa_translate_init(void) uregnames[i].name); } } + + cpu_windowbase_next = +tcg_global_mem_new_i32 (cpu_env, + offsetof(CPUXtensaState , windowbase_next), +"windowbase_next" ); }static inline bool option_enabled (DisasContext *dc,int opt)
@@ -557,7 +563,7 @@ static void gen_wsr_acchi(DisasContext *dc, uint32_t sr, TCGv_i32 s)#ifndef CONFIG_USER_ONLY static void gen_wsr_windowbase (DisasContext *dc,uint32_t sr,TCGv_i32 v) { -gen_helper_wsr_windowbase (cpu_env, v); +tcg_gen_mov_i32 (cpu_windowbase_next, v); }static void gen_wsr_windowstart (DisasContext *dc,uint32_t sr,TCGv_i32 v)
@@ -859,6 +865,9 @@ static int gen_postprocess(DisasContext *dc, int slot)if (op_flags &XTENSA_OP_CHECK_INTERRUPTS ) {gen_check_interrupts (dc); } +if (op_flags &XTENSA_OP_SYNC_REGISTER_WINDOW ) { +gen_helper_sync_windowbase (cpu_env); + }if (op_flags &XTENSA_OP_EXIT_TB_M1 ) { slot =-1 ; }
@@ -2267,9 +2276,7 @@ static void translate_rfw(DisasContext *dc, const uint32_t arg[],static void translate_rotw (DisasContext *dc,const uint32_t arg[],const uint32_t par[]) { -TCGv_i32 tmp =tcg_const_i32 (arg[0 ]); -gen_helper_rotw (cpu_env, tmp); -tcg_temp_free (tmp); +tcg_gen_addi_i32 (cpu_windowbase_next, cpu_SR[WINDOW_BASE ], arg[0 ]); } static void translate_rsil(DisasContext *dc, const uint32_t arg[],
@@ -2971,7 +2978,8 @@ static const XtensaOpcodeOps core_ops[] = { .translate = translate_entry, .test_ill = test_ill_entry, .test_overflow = test_overflow_entry, - .op_flags = XTENSA_OP_EXIT_TB_M1, + .op_flags = XTENSA_OP_EXIT_TB_M1 | + XTENSA_OP_SYNC_REGISTER_WINDOW, }, { .name = "esync", .translate = translate_nop,
@@ -3553,7 +3561,9 @@ static const XtensaOpcodeOps core_ops[] = { }, { .name = "rotw", .translate = translate_rotw, - .op_flags = XTENSA_OP_PRIVILEGED | XTENSA_OP_EXIT_TB_M1, + .op_flags = XTENSA_OP_PRIVILEGED | + XTENSA_OP_EXIT_TB_M1 | + XTENSA_OP_SYNC_REGISTER_WINDOW, }, { .name = "rsil", .translate = translate_rsil,
@@ -4621,7 +4631,9 @@ static const XtensaOpcodeOps core_ops[] = { .translate = translate_wsr, .test_ill = test_ill_wsr, .par = (const uint32_t[]){WINDOW_BASE}, - .op_flags = XTENSA_OP_PRIVILEGED | XTENSA_OP_EXIT_TB_M1, + .op_flags =XTENSA_OP_PRIVILEGED | +XTENSA_OP_EXIT_TB_M1 | + XTENSA_OP_SYNC_REGISTER_WINDOW, }, { .name = "wsr.windowstart", .translate = translate_wsr,
@@ -5107,7 +5119,9 @@ static const XtensaOpcodeOps core_ops[] = { .translate = translate_xsr, .test_ill = test_ill_xsr, .par = (const uint32_t[]){WINDOW_BASE}, - .op_flags = XTENSA_OP_PRIVILEGED | XTENSA_OP_EXIT_TB_M1, + .op_flags =XTENSA_OP_PRIVILEGED | +XTENSA_OP_EXIT_TB_M1 | + XTENSA_OP_SYNC_REGISTER_WINDOW, }, { .name = "xsr.windowstart", .translate = translate_xsr,
target/xtensa/win_helper.c +4 -10
@@ -96,9 +96,9 @@ void xtensa_rotate_window(CPUXtensaState *env, uint32_t delta)xtensa_rotate_window_abs (env, env->sregs[WINDOW_BASE ] + delta); } -void HELPER (wsr_windowbase )(CPUXtensaState *env,uint32_t v) +void HELPER (sync_windowbase )(CPUXtensaState *env) { -xtensa_rotate_window_abs (env, v); +xtensa_rotate_window_abs (env, env->windowbase_next); }void HELPER (entry )(CPUXtensaState *env,uint32_t pc,uint32_t s,uint32_t imm)
@@ -106,9 +106,8 @@ void HELPER(entry)(CPUXtensaState *env, uint32_t pc, uint32_t s, uint32_t imm)int callinc = (env->sregs[PS ] &PS_CALLINC ) >>PS_CALLINC_SHIFT ; env->regs[(callinc <<2 ) | (s &3 )] = env->regs[s] - imm; -xtensa_rotate_window (env, callinc); - env->sregs[WINDOW_START ] |= -windowstart_bit (env->sregs[WINDOW_BASE ], env); + env->windowbase_next = env->sregs[WINDOW_BASE ] + callinc; + env->sregs[WINDOW_START ] |=windowstart_bit (env->windowbase_next, env); }void HELPER (window_check )(CPUXtensaState *env,uint32_t pc,uint32_t w)
@@ -196,11 +195,6 @@ uint32_t HELPER(retw)(CPUXtensaState *env, uint32_t pc)return ret_pc; } -void HELPER (rotw )(CPUXtensaState *env,uint32_t imm4) -{ -xtensa_rotate_window (env, imm4); -} -void xtensa_restore_owb (CPUXtensaState *env) {xtensa_rotate_window_abs (env, (env->sregs[PS ] &PS_OWB ) >>PS_OWB_SHIFT );
Signature · 1 line
2.11.0
PATCH 8/13 target/xtensa: only rotate window in the retw helper
In reply to Max FilippovMove return address calculation and WINDOW_START adjustment out of the retw helper to simplify logic a bit and avoid using registers directly. Pass a0 as a parameter to the helper.
--- target/xtensa/helper.h | 2 +- target/xtensa/translate.c | 9 +++++++-- target/xtensa/win_helper.c | 8 ++------ 3 files changed, 10 insertions(+), 9 deletions(-)
target/xtensa/helper.h +1 -1
@@ -7,7 +7,7 @@ DEF_HELPER_1(sync_windowbase, void, env) DEF_HELPER_4(entry, void, env, i32, i32, i32) DEF_HELPER_2(test_ill_retw, void, env, i32) DEF_HELPER_2(test_underflow_retw, void, env, i32) -DEF_HELPER_2(retw, i32, env, i32) +DEF_HELPER_2(retw, void, env, i32) DEF_HELPER_3(window_check, noreturn, env, i32, i32) DEF_HELPER_1(restore_owb, void, env)DEF_HELPER_2 (movsp, void, env, i32)
target/xtensa/translate.c +7 -2
@@ -2226,8 +2226,13 @@ static bool test_ill_retw(DisasContext *dc, const uint32_t arg[],static void translate_retw (DisasContext *dc,const uint32_t arg[],const uint32_t par[]) { -TCGv_i32 tmp =tcg_const_i32 (dc->pc); -gen_helper_retw (tmp, cpu_env, tmp); +TCGv_i32 tmp =tcg_const_i32 (1 ); +tcg_gen_shl_i32 (tmp, tmp, cpu_SR[WINDOW_BASE ]); +tcg_gen_andc_i32 (cpu_SR[WINDOW_START ], + cpu_SR[WINDOW_START ], tmp); +tcg_gen_movi_i32 (tmp, dc->pc); +tcg_gen_deposit_i32 (tmp, tmp, cpu_R[0 ],0 ,30 ); +gen_helper_retw (cpu_env, cpu_R[0 ]);gen_jump (dc, tmp);tcg_temp_free (tmp); }
target/xtensa/win_helper.c +2 -6
@@ -184,15 +184,11 @@ void HELPER(test_underflow_retw)(CPUXtensaState *env, uint32_t pc) } } -uint32_t HELPER (retw )(CPUXtensaState *env,uint32_t pc) +void HELPER (retw )(CPUXtensaState *env,uint32_t a0) { -int n = (env->regs[0 ] >>30 ) &0x3 ; -uint32_t windowbase =windowbase_bound (env->sregs[WINDOW_BASE ], env); -uint32_t ret_pc = (pc &0xc0000000 ) | (env->regs[0 ] &0x3fffffff ); +int n = (a0 >>30 ) &0x3 ;xtensa_rotate_window (env, -n); - env->sregs[WINDOW_START ] &= ~windowstart_bit (windowbase, env); -return ret_pc; }void xtensa_restore_owb (CPUXtensaState *env)
Signature · 1 line
2.11.0
cover target/xtensa: add FLIX support
Hello,
this series adds limited support for FLIX instructions. FLIX (flexible length instruction extensions) allows bundling multiple opcodes in a single instruction. Each opcode is executed as if it was the only opcode in the instruction. Opcodes may not simultaneously modify same resource (register or state). Multiple branches, even non-taken, are also not allowed in one instruction.
Instructions with opcodes that have circular dependencies between used resources other than registers (e.g. opcode A uses resource U and modifies resource M, while opcode B uses resource M and modifies resource U) are not supported in this series.
Max Filippov (13):
target/xtensa: move xtensa_finalize_config to xtensa_core_class_init target/xtensa: don't require opcode table sorting target/xtensa: allow multiple names for single opcode target/xtensa: implement wide branches and loops target/xtensa: sort FLIX instruction opcodes target/xtensa: add generic instruction post-processing target/xtensa: move WINDOW_BASE SR update to postprocessing target/xtensa: only rotate window in the retw helper target/xtensa: reorganize register handling in translators target/xtensa: reorganize access to MAC16 registers target/xtensa: reorganize access to boolean registers target/xtensa: break circular register dependencies target/xtensa: prioritize load/store in FLIX bundles
target/xtensa/cpu.h | 37 +- target/xtensa/helper.c | 93 ++- target/xtensa/helper.h | 5 +- target/xtensa/overlay_tool.h | 1 - target/xtensa/translate.c | 1595 +++++++++++++++++++++++++++--------------- target/xtensa/win_helper.c | 22 +- 6 files changed, 1162 insertions(+), 591 deletions(-)
Signature · 1 line
2.11.0
PATCH 2/13 target/xtensa: don't require opcode table sorting
Requirement for alphabetical opcode sorting in opcode tables is awkward and does not allow sharing implementation between multiple opcodes. Use hash tables to find opcodes by name. Move implementation from the translate.c to the helper.c to its only user and remove declaration from the cpu.h
--- target/xtensa/cpu.h | 2 -- target/xtensa/helper.c | 42 ++++++++++++++++++++++++++++++++++++++++++ target/xtensa/translate.c | 14 -------------- 3 files changed, 42 insertions(+), 16 deletions(-)
target/xtensa/cpu.h +0 -2
@@ -587,8 +587,6 @@ static inline void xtensa_select_static_vectors(CPUXtensaState *env, env->static_vectors = n; }void xtensa_runstall (CPUXtensaState *env,bool runstall); -XtensaOpcodeOps *xtensa_find_opcode_ops (const XtensaOpcodeTranslators *t, -const char *opcode);#define XTENSA_OPTION_BIT (opt) (((uint64_t)1) << (opt))#define XTENSA_OPTION_ALL (~(uint64_t)0)
target/xtensa/helper.c +42 -0
52 lines not on this page · raw message
target/xtensa/translate.c +0 -14
@@ -1274,20 +1274,6 @@ void restore_state_to_opc(CPUXtensaState *env, TranslationBlock *tb, env->pc = data[0 ]; } -static int compare_opcode_ops (const void *a,const void *b) -{ -return strcmp ((const char *)a, - ((const XtensaOpcodeOps *)b)->name); -} - -XtensaOpcodeOps * -xtensa_find_opcode_ops (const XtensaOpcodeTranslators *t, -const char *name) -{ -return bsearch (name, t->opcode, t->num_opcodes, -sizeof (XtensaOpcodeOps), compare_opcode_ops); -} -static void translate_abs (DisasContext *dc,const uint32_t arg[],const uint32_t par[]) {
Signature · 1 line
2.11.0
PATCH 3/13 target/xtensa: allow multiple names for single opcode
In reply to Max FilippovThere are opcodes that differ only in encoding or possible range of immediate arguments. Allow multiple names for single opcode translation table entry to reduce code duplication in that case.
--- target/xtensa/cpu.h | 4 +- target/xtensa/helper.c | 16 ++++++-- target/xtensa/translate.c | 100 ++++++++++++++++++++-------------------------- 3 files changed, 60 insertions(+), 60 deletions(-)
target/xtensa/cpu.h +3 -1
@@ -371,10 +371,12 @@ enum {XTENSA_OP_CHECK_INTERRUPTS =0x200 ,XTENSA_OP_EXIT_TB_M1 =0x400 ,XTENSA_OP_EXIT_TB_0 =0x800 , + + XTENSA_OP_NAME_ARRAY = 0x8000, }; typedef struct XtensaOpcodeOps { - const char *name; + const void *name; XtensaOpcodeOp translate; XtensaOpcodeBoolTest test_ill; XtensaOpcodeUintTest test_overflow;
target/xtensa/helper.c +13 -3
@@ -51,9 +51,19 @@ static GHashTable *hash_opcode_translators(const XtensaOpcodeTranslators *t)GHashTable *translator =g_hash_table_new (g_str_hash, g_str_equal);for (i =0 ; i < t->num_opcodes; ++i) { -add_translator_to_hash (translator, - (void *)t->opcode[i].name, - (void *)(t->opcode + i)); +if (t->opcode[i].op_flags &XTENSA_OP_NAME_ARRAY ) { +const char *const *name = t->opcode[i].name; + +for (j =0 ; name[j]; ++j) { +add_translator_to_hash (translator, + (void *)name[j], + (void *)(t->opcode + i)); + } + }else { +add_translator_to_hash (translator, + (void *)t->opcode[i].name, + (void *)(t->opcode + i)); + } }return translator; }
target/xtensa/translate.c +44 -56
171 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 6/13 target/xtensa: add generic instruction post-processing
In reply to Max FilippovSome opcodes may need additional actions at every exit from the translated instruction or may need to amend TB exit slots available to jumps generated for the instruction. Add gen_postprocess function and call it from the gen_jump_slot and from the disas_xtensa_insn.
--- target/xtensa/cpu.h | 8 ++++++++ target/xtensa/translate.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-)
target/xtensa/cpu.h +8 -0
@@ -368,9 +368,17 @@ enum {XTENSA_OP_DIVIDE_BY_ZERO =0x100 , +/* Postprocessing flags */ XTENSA_OP_CHECK_INTERRUPTS =0x200 ,XTENSA_OP_EXIT_TB_M1 =0x400 ,XTENSA_OP_EXIT_TB_0 =0x800 , +XTENSA_OP_SYNC_REGISTER_WINDOW =0x1000 , + +XTENSA_OP_POSTPROCESS = +XTENSA_OP_CHECK_INTERRUPTS | +XTENSA_OP_EXIT_TB_M1 | +XTENSA_OP_EXIT_TB_0 | +XTENSA_OP_SYNC_REGISTER_WINDOW , XTENSA_OP_NAME_ARRAY = 0x8000,
target/xtensa/translate.c +25 -8
@@ -71,6 +71,7 @@ struct DisasContext {unsigned cpenable; +uint32_t op_flags;uint32_t *raw_arg;xtensa_insnbuf insnbuf;xtensa_insnbuf slotbuf;
@@ -363,6 +364,8 @@ static bool gen_check_cpenable(DisasContext *dc, uint32_t cp_mask)return true; } +static int gen_postprocess (DisasContext *dc,int slot); +static void gen_jump_slot (DisasContext *dc,TCGv dest,int slot) {tcg_gen_mov_i32 (cpu_pc, dest);
@@ -372,6 +375,9 @@ static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot)if (dc->base.singlestep_enabled) {gen_exception (dc,EXCP_DEBUG ); }else { +if (dc->op_flags &XTENSA_OP_POSTPROCESS ) { + slot =gen_postprocess (dc, slot); + }if (slot >=0 ) {tcg_gen_goto_tb (slot);tcg_gen_exit_tb (dc->base.tb, slot);
@@ -846,6 +852,19 @@ static inline unsigned xtensa_op0_insn_len(DisasContext *dc, uint8_t op0)return xtensa_isa_length_from_chars (dc->config->isa, &op0); } +static int gen_postprocess (DisasContext *dc,int slot) +{ +uint32_t op_flags = dc->op_flags; + +if (op_flags &XTENSA_OP_CHECK_INTERRUPTS ) { +gen_check_interrupts (dc); + } +if (op_flags &XTENSA_OP_EXIT_TB_M1 ) { + slot =-1 ; + } +return slot; +} +struct opcode_arg_info {uint32_t resource;int index;
@@ -1210,6 +1229,8 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) } } + dc->op_flags = op_flags; +for (slot =0 ; slot < slots; ++slot) {struct slot_prop *pslot = ordered[slot];XtensaOpcodeOps *ops = pslot->ops;
@@ -1219,21 +1240,17 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) }if (dc->base.is_jmp ==DISAS_NEXT ) { -if (op_flags &XTENSA_OP_CHECK_INTERRUPTS ) { -gen_check_interrupts (dc); - } - +gen_postprocess (dc,0 ); + dc->op_flags =0 ;if (op_flags &XTENSA_OP_EXIT_TB_M1 ) {/* Change in mmu index, memory mapping or tb->flags; exit tb */ gen_jumpi_check_loop_end (dc,-1 ); }else if (op_flags &XTENSA_OP_EXIT_TB_0 ) {gen_jumpi_check_loop_end (dc,0 ); + }else { +gen_check_loop_end (dc,0 ); } } - -if (dc->base.is_jmp ==DISAS_NEXT ) { -gen_check_loop_end (dc,0 ); - } dc->pc = dc->base.pc_next; }
Signature · 1 line
2.11.0