tcg tb_lock removal
v6 cover tcg tb_lock removal
I've fixed two bugs within v5 of Emilio's patch set:
- The step_next_tb patch fixes the "rep movsb" bug that appeared when we included CF_COUNT_MASK into CF_HASH_MASK. We had been relying on magic to single-step the next guest insn.
- The original "allocate optimizer temps with tcg_malloc" patch failed testing on arm32 host. I didn't really look into exactly what was wrong because I had an older patch set that touched the same portion of the optimizer.
Thus, an extra 20 patches in the patch set rearranging how temps are referenced within the TCG backend. Some of them have appeared on the list before, but it would have been last November.
r~
Emilio G. Cota (24):
tcg: define CF_PARALLEL and use it for TB hashing along with
CF_COUNT_MASK
tcg: convert tb->cflags reads to tb_cflags(tb) target/arm: check CF_PARALLEL instead of parallel_cpus target/hppa: check CF_PARALLEL instead of parallel_cpus target/i386: check CF_PARALLEL instead of parallel_cpus target/m68k: check CF_PARALLEL instead of parallel_cpus target/s390x: check CF_PARALLEL instead of parallel_cpus target/sh4: check CF_PARALLEL instead of parallel_cpus target/sparc: check CF_PARALLEL instead of parallel_cpus
tcg: check CF_PARALLEL instead of parallel_cpus
cpu-exec: lookup/generate TB outside exclusive region during
step_atomic
translate-all: use a binary search tree to track TBs in TBContext
exec-all: rename tb_free to tb_remove
translate-all: report correct avg host TB size
tcg: take tb_ctx out of TCGContext
tcg: define tcg_init_ctx and make tcg_ctx a pointer
gen-icount: fold exitreq_label into TCGContext
tcg: introduce **tcg_ctxs to keep track of all TCGContext's
tcg: distribute profiling counters across TCGContext's
tcg: allocate optimizer temps with tcg_malloc
osdep: introduce qemu_mprotect_rwx/none
translate-all: use qemu_protect_rwx/none helpers
tcg: introduce regions to split code_gen_buffer
tcg: enable multiple TCG contexts in softmmu
Richard Henderson (26):
tcg: Merge opcode arguments into TCGOp
tcg: Propagate args to op->args in optimizer
tcg: Propagate args to op->args in tcg.c
tcg: Propagate TCGOp down to allocators
tcg: Introduce arg_temp
tcg: Add temp_global bit to TCGTemp
tcg: Return NULL temp for TCG_CALL_DUMMY_ARG
tcg: Introduce temp_arg
tcg: Use per-temp state data in liveness
tcg: Avoid loops against variable bounds
tcg: Change temp_allocate_frame arg to TCGTemp
tcg: Remove unused TCG_CALL_DUMMY_TCGV
tcg: Export temp_idx
tcg: Use per-temp state data in optimize
tcg: Push tcg_ctx into generator functions
tcg: Push tcg_ctx into tcg_gen_callN
tcg: Introduce index_arg
tcg: Reserve temporary index 0
target/alpha: Avoid translate_init unless tcg_enabled
qom: Introduce CPUClass.tcg_initialize
tcg: Use pointers in TCGOp->args
hack dump tb->flags and tb->cflags
tcg: Add CPUState step_next_tb
tcg: Include CF_COUNT_MASK in CF_HASH_MASK
tcg: Add CF_LAST_IO + CF_USE_ICOUNT to CF_HASH_MASK
tcg: Remove CF_IGNORE_ICOUNT
include/exec/exec-all.h | 41 +- include/exec/gen-icount.h | 25 +- include/exec/helper-gen.h | 12 +- include/exec/tb-context.h | 6 +- include/exec/tb-hash-xx.h | 9 +- include/exec/tb-hash.h | 4 +- include/exec/tb-lookup.h | 6 +- include/qemu/osdep.h | 2 + include/qom/cpu.h | 9 +- target/arm/helper-a64.h | 4 + target/hppa/helper.h | 2 + target/m68k/helper.h | 1 + target/s390x/helper.h | 4 + target/sparc/cpu.h | 2 +- tcg/tcg-op.h | 132 +++--- tcg/tcg.h | 184 +++++--- accel/tcg/cpu-exec.c | 102 ++-- accel/tcg/tcg-runtime.c | 4 +- accel/tcg/translate-all.c | 511 ++++++++++---------- accel/tcg/translator.c | 4 +- bsd-user/main.c | 3 +- cpus.c | 14 + exec.c | 13 +- linux-user/main.c | 9 +- linux-user/syscall.c | 1 + target/alpha/cpu.c | 3 +- target/alpha/translate.c | 12 +- target/arm/cpu.c | 6 +- target/arm/helper-a64.c | 38 +- target/arm/op_helper.c | 7 - target/arm/translate-a64.c | 38 +- target/arm/translate.c | 17 +- target/cris/cpu.c | 16 +- target/cris/translate.c | 8 +- target/cris/translate_v10.c | 2 +- target/hppa/cpu.c | 3 +- target/hppa/op_helper.c | 32 +- target/hppa/translate.c | 22 +- target/i386/cpu.c | 5 +- target/i386/translate.c | 60 ++- target/lm32/cpu.c | 7 +- target/lm32/translate.c | 16 +- target/m68k/cpu.c | 7 +- target/m68k/op_helper.c | 33 +- target/m68k/translate.c | 20 +- target/microblaze/cpu.c | 7 +- target/microblaze/translate.c | 8 +- target/mips/cpu.c | 5 +- target/mips/translate.c | 35 +- target/moxie/cpu.c | 7 +- target/moxie/translate.c | 10 +- target/nios2/cpu.c | 7 +- target/nios2/translate.c | 6 +- target/openrisc/cpu.c | 7 +- target/openrisc/translate.c | 8 +- target/ppc/translate.c | 14 +- target/ppc/translate_init.c | 37 +- target/s390x/cpu.c | 7 +- target/s390x/mem_helper.c | 80 +++- target/s390x/translate.c | 36 +- target/sh4/cpu.c | 5 +- target/sh4/translate.c | 17 +- target/sparc/cpu.c | 5 +- target/sparc/translate.c | 19 +- target/tilegx/cpu.c | 7 +- target/tilegx/translate.c | 4 +- target/tricore/cpu.c | 5 +- target/tricore/translate.c | 9 +- target/unicore32/cpu.c | 7 +- target/unicore32/translate.c | 8 +- target/xtensa/cpu.c | 7 +- target/xtensa/translate.c | 30 +- tcg/optimize.c | 659 ++++++++++++++------------ tcg/tcg-op.c | 186 ++++---- tcg/tcg.c | 1030 ++++++++++++++++++++++++++++------------- tests/qht-bench.c | 2 +- util/osdep.c | 41 ++ 77 files changed, 2194 insertions(+), 1577 deletions(-)
Signature · 1 line
2.13.6
PATCH v6 1/50 tcg: Merge opcode arguments into TCGOp
From: Richard Henderson <[email protected]>
Rather than have a separate buffer of 10*max_ops entries, give each opcode 10 entries. The result is actually a bit smaller and should have slightly more cache locality.
--- tcg/tcg.h | 37 ++++++++++------------ tcg/optimize.c | 6 ++-- tcg/tcg-op.c | 99 +++++++++++++++++++++------------------------------------- tcg/tcg.c | 98 ++++++++++++++++++++++++++------------------------------- 4 files changed, 98 insertions(+), 142 deletions(-)
tcg/tcg.h +16 -21
@@ -51,8 +51,6 @@#define OPC_BUF_SIZE 640#define OPC_MAX_SIZE (OPC_BUF_SIZE - MAX_OP_PER_INSTR) -#define OPPARAM_BUF_SIZE (OPC_BUF_SIZE * MAX_OPC_PARAM) -#define CPU_TEMP_BUF_NLONGS 128/* Default target word size to pointer size. */
@@ -606,33 +604,33 @@ typedef struct TCGTempSet {#define SYNC_ARG 1typedef uint16_t TCGLifeData ; -/* The layout here is designed to avoid crossing of a 32-bit boundary. -If we do so, gcc adds padding, expanding the size to 12. */ +/* The layout here is designed to avoid a bitfield crossing of +a 32-bit boundary, which would cause GCC to add extra padding. */ typedef struct TCGOp {TCGOpcode opc :8 ;/* 8 */ -/* Index of the prev/next op, or 0 for the end of the list. */ -unsigned prev :10 ;/* 18 */ -unsigned next :10 ;/* 28 */ -/* The number of out and in parameter for a call. */ -unsigned calli :4 ;/* 32 */ -unsigned callo :2 ;/* 34 */ +unsigned calli :4 ;/* 12 */ +unsigned callo :2 ;/* 14 */ + unsigned : 2; /* 16 */ -/* Index of the arguments for this op, or 0 for zero-operand ops. */ -unsigned args :14 ;/* 48 */ +/* Index of the prev/next op, or 0 for the end of the list. */ +unsigned prev :16 ;/* 32 */ +unsigned next :16 ;/* 48 */ /* Lifetime data of the operands. */ unsigned life :16 ;/* 64 */ + +/* Arguments for the opcode. */ +TCGArg args[MAX_OPC_PARAM ]; }TCGOp ; +/* Make sure that we don't expand the structure without noticing. */ +QEMU_BUILD_BUG_ON (sizeof (TCGOp) !=8 +sizeof (TCGArg) *MAX_OPC_PARAM ); +/* Make sure operands fit in the bitfields above. */ QEMU_BUILD_BUG_ON (NB_OPS > (1 <<8 )); -QEMU_BUILD_BUG_ON (OPC_BUF_SIZE > (1 <<10 )); -QEMU_BUILD_BUG_ON (OPPARAM_BUF_SIZE > (1 <<14 )); - -/* Make sure that we don't overflow 64 bits without noticing. */ -QEMU_BUILD_BUG_ON (sizeof (TCGOp) >8 ); +QEMU_BUILD_BUG_ON (OPC_BUF_SIZE > (1 <<16 ));struct TCGContext {uint8_t *pool_cur, *pool_end;
@@ -682,7 +680,6 @@ struct TCGContext {#endif int gen_next_op_idx; -int gen_next_parm_idx;/* Code generation. Note that we specifically do not use tcg_insn_unit here, because there's too much arithmetic throughout that relies
@@ -720,7 +717,6 @@ struct TCGContext {TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS ];TCGOp gen_op_buf[OPC_BUF_SIZE ]; -TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE ];uint16_t gen_insn_end_off[TCG_MAX_INSNS ];target_ulong gen_insn_data[TCG_MAX_INSNS ][TARGET_INSN_START_WORDS ];
@@ -731,8 +727,7 @@ extern bool parallel_cpus;static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v) { -int op_argi = tcg_ctx.gen_op_buf[op_idx].args; - tcg_ctx.gen_opparam_buf[op_argi + arg] = v; + tcg_ctx.gen_op_buf[op_idx].args[arg] = v; }/* The number of opcodes emitted so far. */
tcg/optimize.c +3 -3
@@ -576,7 +576,7 @@ void tcg_optimize(TCGContext *s)TCGArg tmp;TCGOp *const op = &s->gen_op_buf[oi]; -TCGArg *const args = &s->gen_opparam_buf[op->args]; +TCGArg *const args = op->args;TCGOpcode opc = op->opc;const TCGOpDef *def = &tcg_op_defs[opc];
@@ -1184,7 +1184,7 @@ void tcg_optimize(TCGContext *s)uint64_t b = ((uint64_t )bh <<32 ) | bl;TCGArg rl, rh;TCGOp *op2 =tcg_op_insert_before (s, op, INDEX_op_movi_i32,2 ); -TCGArg *args2 = &s->gen_opparam_buf[op2->args]; +TCGArg *args2 = op2->args;if (opc == INDEX_op_add2_i32) { a += b;
@@ -1210,7 +1210,7 @@ void tcg_optimize(TCGContext *s)uint64_t r = (uint64_t )a * b;TCGArg rl, rh;TCGOp *op2 =tcg_op_insert_before (s, op, INDEX_op_movi_i32,2 ); -TCGArg *args2 = &s->gen_opparam_buf[op2->args]; +TCGArg *args2 = op2->args; rl = args[0 ]; rh = args[1 ];
tcg/tcg-op.c +35 -64
142 lines not on this page · raw message
tcg/tcg.c +44 -54
240 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 01/50] tcg: Merge opcode arguments into TCGOp
Quoted 7 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Rather than have a separate buffer of 10*max_ops entries, give each opcode 10 entries. The result is actually a bit smaller and should have slightly more cache locality.
Signed-off-by Richard Henderson <[email protected]>
This gives a small yet measurable perf advantage when booting linux:
Performance counter stats for 'taskset -c 0 aarch64-softmmu/qemu-system-aarch64 \ -M virt,gic_version=3 -cpu cortex-a57 -nographic -m 4096 -netdev \ user,id=unet,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=unet \ -drive file=jessie-arm64-die-on-boot.qcow2,id=myblock,index=0,if=none \ -device virtio-blk-device,drive=myblock -kernel \ aarch64-current-linux-kernel-only.img \ -append console=ttyAMA0 root=/dev/vda1 -smp 1' (10 runs):
Before:
7182.556704 task-clock (msec) # 0.999 CPUs utilized ( +- 0.11% )
21,710 context-switches # 0.003 M/sec ( +- 0.12% )
1 cpu-migrations # 0.000 K/sec ( +- 11.11% )
7,929 page-faults # 0.001 M/sec ( +- 1.75% )
30,280,536,799 cycles # 4.216 GHz ( +- 0.11% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
54,481,515,301 instructions # 1.80 insns per cycle ( +- 0.09% )
9,655,822,880 branches # 1344.343 M/sec ( +- 0.10% )
170,594,899 branch-misses # 1.77% of all branches ( +- 0.10% )7.190274755 seconds time elapsed ( +- 0.11% )
After:
7086.254881 task-clock (msec) # 0.999 CPUs utilized ( +- 0.13% )
21,598 context-switches # 0.003 M/sec ( +- 0.07% )
1 cpu-migrations # 0.000 K/sec
8,099 page-faults # 0.001 M/sec ( +- 0.97% )
29,856,727,544 cycles # 4.213 GHz ( +- 0.12% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
53,585,205,542 instructions # 1.79 insns per cycle ( +- 0.10% )
9,638,601,205 branches # 1360.183 M/sec ( +- 0.10% )
169,785,181 branch-misses # 1.76% of all branches ( +- 0.08% )7.094560954 seconds time elapsed
That is, a 1.33% perf improvement.
Emilio
PATCH v6 2/50 tcg: Propagate args to op->args in optimizer
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/optimize.c | 430 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 227 insertions(+), 203 deletions(-)
tcg/optimize.c +227 -203
@@ -166,8 +166,7 @@ static bool temps_are_copies(TCGArg arg1, TCGArg arg2)return false; } -static void tcg_opt_gen_movi (TCGContext *s,TCGOp *op,TCGArg *args, -TCGArg dst,TCGArg val) +static void tcg_opt_gen_movi (TCGContext *s,TCGOp *op,TCGArg dst,TCGArg val) {TCGOpcode new_op =op_to_movi (op->opc);tcg_target_ulong mask;
@@ -184,12 +183,11 @@ static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg *args, } temps[dst].mask = mask; - args[0 ] = dst; - args[1 ] = val; + op->args[0 ] = dst; + op->args[1 ] = val; } -static void tcg_opt_gen_mov (TCGContext *s,TCGOp *op,TCGArg *args, -TCGArg dst,TCGArg src) +static void tcg_opt_gen_mov (TCGContext *s,TCGOp *op,TCGArg dst,TCGArg src) {if (temps_are_copies (dst, src)) {tcg_op_remove (s, op);
@@ -218,8 +216,8 @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg *args, temps[dst].val = temps[src].val; } - args[0 ] = dst; - args[1 ] = src; + op->args[0 ] = dst; + op->args[1 ] = src; }static TCGArg do_constant_folding_2 (TCGOpcode op,TCGArg x,TCGArg y)
@@ -559,7 +557,7 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2)void tcg_optimize (TCGContext *s) {int oi, oi_next, nb_temps, nb_globals; -TCGArg *prev_mb_args =NULL ; +TCGOp *prev_mb =NULL ;/* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element.
@@ -576,7 +574,6 @@ void tcg_optimize(TCGContext *s)TCGArg tmp;TCGOp *const op = &s->gen_op_buf[oi]; -TCGArg *const args = op->args;TCGOpcode opc = op->opc;const TCGOpDef *def = &tcg_op_defs[opc];
@@ -588,7 +585,7 @@ void tcg_optimize(TCGContext *s) nb_oargs = op->callo; nb_iargs = op->calli;for (i =0 ; i < nb_oargs + nb_iargs; i++) { - tmp = args[i]; + tmp = op->args[i];if (tmp !=TCG_CALL_DUMMY_ARG ) {init_temp_info (tmp); }
@@ -597,14 +594,14 @@ void tcg_optimize(TCGContext *s) nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs;for (i =0 ; i < nb_oargs + nb_iargs; i++) { -init_temp_info (args[i]); +init_temp_info (op->args[i]); } }/* Do copy propagation */ for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { -if (temp_is_copy (args[i])) { - args[i] =find_better_copy (s, args[i]); +if (temp_is_copy (op->args[i])) { + op->args[i] =find_better_copy (s, op->args[i]); } }
@@ -620,45 +617,45 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(nor): CASE_OP_32_64(muluh): CASE_OP_32_64(mulsh): - swap_commutative(args[0], &args[1], &args[2]); + swap_commutative(op->args[0], &op->args[1], &op->args[2]); break; CASE_OP_32_64(brcond): - if (swap_commutative(-1, &args[0], &args[1])) { - args[2 ] =tcg_swap_cond (args[2 ]); + if (swap_commutative(-1, &op->args[0], &op->args[1])) { + op->args[2 ] =tcg_swap_cond (op->args[2 ]); }break ; CASE_OP_32_64(setcond): - if (swap_commutative(args[0], &args[1], &args[2])) { - args[3 ] =tcg_swap_cond (args[3 ]); +if (swap_commutative (op->args[0 ], &op->args[1 ], &op->args[2 ])) { + op->args[3 ] =tcg_swap_cond (op->args[3 ]); }break ; CASE_OP_32_64(movcond): -if (swap_commutative (-1 , &args[1 ], &args[2 ])) { - args[5 ] =tcg_swap_cond (args[5 ]); +if (swap_commutative (-1 , &op->args[1 ], &op->args[2 ])) { + op->args[5 ] =tcg_swap_cond (op->args[5 ]); }/* For movcond, we canonicalize the "false" input reg to match the destination reg so that the tcg backend can implement a "move if true" operation. */ -if (swap_commutative (args[0 ], &args[4 ], &args[3 ])) { - args[5 ] =tcg_invert_cond (args[5 ]); +if (swap_commutative (op->args[0 ], &op->args[4 ], &op->args[3 ])) { + op->args[5 ] =tcg_invert_cond (op->args[5 ]); }break ; CASE_OP_32_64(add2): - swap_commutative(args[0], &args[2], &args[4]); -swap_commutative (args[1 ], &args[3 ], &args[5 ]); + swap_commutative(op->args[0], &op->args[2], &op->args[4]); +swap_commutative (op->args[1 ], &op->args[3 ], &op->args[5 ]);break ; CASE_OP_32_64(mulu2): CASE_OP_32_64(muls2): - swap_commutative(args[0], &args[2], &args[3]); + swap_commutative(op->args[0], &op->args[2], &op->args[3]); break; case INDEX_op_brcond2_i32: -if (swap_commutative2 (&args[0 ], &args[2 ])) { - args[4 ] =tcg_swap_cond (args[4 ]); + if (swap_commutative2(&op->args[0], &op->args[2])) { + op->args[4 ] =tcg_swap_cond (op->args[4 ]); }break ;case INDEX_op_setcond2_i32: -if (swap_commutative2 (&args[1 ], &args[3 ])) { - args[5 ] =tcg_swap_cond (args[5 ]); +if (swap_commutative2 (&op->args[1 ], &op->args[3 ])) { + op->args[5 ] =tcg_swap_cond (op->args[5 ]); }break ;default :
@@ -673,8 +670,8 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(sar): CASE_OP_32_64(rotl): CASE_OP_32_64(rotr): - if (temp_is_const(args[1]) && temps[args[1]].val == 0) { - tcg_opt_gen_movi(s, op, args, args[0], 0); + if (temp_is_const(op->args[1]) && temps[op->args[1]].val == 0) { + tcg_opt_gen_movi(s, op, op->args[0], 0); continue; }break ;
@@ -683,7 +680,7 @@ void tcg_optimize(TCGContext *s)TCGOpcode neg_op;bool have_neg; -if (temp_is_const (args[2 ])) { +if (temp_is_const (op->args[2 ])) {/* Proceed with possible constant folding. */ break ; }
@@ -697,40 +694,45 @@ void tcg_optimize(TCGContext *s)if (!have_neg) {break ; } -if (temp_is_const (args[1 ]) && temps[args[1 ]].val ==0 ) { +if (temp_is_const (op->args[1 ]) + && temps[op->args[1 ]].val ==0 ) { op->opc = neg_op; -reset_temp (args[0 ]); - args[1 ] = args[2 ]; +reset_temp (op->args[0 ]); + op->args[1 ] = op->args[2 ];continue ; } }break ; CASE_OP_32_64(xor): CASE_OP_32_64(nand): - if (!temp_is_const(args[1]) - && temp_is_const(args[2]) && temps[args[2]].val == -1) { + if (!temp_is_const(op->args[1]) + && temp_is_const(op->args[2]) + && temps[op->args[2]].val == -1) { i =1 ; goto try_not; }break ; CASE_OP_32_64(nor): -if (!temp_is_const (args[1 ]) - &&temp_is_const (args[2 ]) && temps[args[2 ]].val ==0 ) { +if (!temp_is_const (op->args[1 ]) + &&temp_is_const (op->args[2 ]) + && temps[op->args[2 ]].val ==0 ) { i =1 ; goto try_not; }break ; CASE_OP_32_64(andc): -if (!temp_is_const (args[2 ]) - &&temp_is_const (args[1 ]) && temps[args[1 ]].val ==-1 ) { +if (!temp_is_const (op->args[2 ]) + &&temp_is_const (op->args[1 ]) + && temps[op->args[1 ]].val ==-1 ) { i =2 ; goto try_not; }break ; CASE_OP_32_64(orc): CASE_OP_32_64(eqv): - if (!temp_is_const(args[2]) - && temp_is_const(args[1]) && temps[args[1]].val == 0) { + if (!temp_is_const(op->args[2]) + && temp_is_const(op->args[1]) + && temps[op->args[1]].val == 0) { i =2 ; goto try_not; }
@@ -751,8 +753,8 @@ void tcg_optimize(TCGContext *s)break ; } op->opc = not_op; -reset_temp (args[0 ]); - args[1 ] = args[i]; +reset_temp (op->args[0 ]); + op->args[1 ] = op->args[i];continue ; }default :
@@ -771,18 +773,20 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(or): CASE_OP_32_64(xor): CASE_OP_32_64(andc): - if (!temp_is_const(args[1]) - && temp_is_const(args[2]) && temps[args[2]].val == 0) { - tcg_opt_gen_mov(s, op, args, args[0], args[1]); + if (!temp_is_const(op->args[1]) + && temp_is_const(op->args[2]) + && temps[op->args[2]].val == 0) { + tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); continue; } break; CASE_OP_32_64(and): CASE_OP_32_64(orc): CASE_OP_32_64(eqv): - if (!temp_is_const(args[1]) - && temp_is_const(args[2]) && temps[args[2]].val == -1) { - tcg_opt_gen_mov(s, op, args, args[0], args[1]); + if (!temp_is_const(op->args[1]) + && temp_is_const(op->args[2]) + && temps[op->args[2]].val == -1) { + tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); continue; }break ;
@@ -796,21 +800,21 @@ void tcg_optimize(TCGContext *s) affected =-1 ;switch (opc) { CASE_OP_32_64(ext8s): -if ((temps[args[1 ]].mask &0x80 ) !=0 ) { +if ((temps[op->args[1 ]].mask &0x80 ) !=0 ) {break ; } CASE_OP_32_64(ext8u): mask =0xff ; goto and_const; CASE_OP_32_64(ext16s): -if ((temps[args[1 ]].mask &0x8000 ) !=0 ) { +if ((temps[op->args[1 ]].mask &0x8000 ) !=0 ) {break ; } CASE_OP_32_64(ext16u): mask =0xffff ; goto and_const;case INDEX_op_ext32s_i64: -if ((temps[args[1 ]].mask &0x80000000 ) !=0 ) { +if ((temps[op->args[1 ]].mask &0x80000000 ) !=0 ) {break ; }case INDEX_op_ext32u_i64:
@@ -818,110 +822,111 @@ void tcg_optimize(TCGContext *s) goto and_const; CASE_OP_32_64(and): - mask = temps[args[2 ]].mask; -if (temp_is_const (args[2 ])) { + mask = temps[op->args[2 ]].mask; +if (temp_is_const (op->args[2 ])) { and_const: - affected = temps[args[1 ]].mask & ~mask; + affected = temps[op->args[1 ]].mask & ~mask; } - mask = temps[args[1 ]].mask & mask; + mask = temps[op->args[1 ]].mask & mask;break ;case INDEX_op_ext_i32_i64: -if ((temps[args[1 ]].mask &0x80000000 ) !=0 ) { +if ((temps[op->args[1 ]].mask &0x80000000 ) !=0 ) {break ; }case INDEX_op_extu_i32_i64:/* We do not compute affected as it is a size changing op. */ - mask = (uint32_t )temps[args[1 ]].mask; + mask = (uint32_t )temps[op->args[1 ]].mask;break ; CASE_OP_32_64(andc):/* Known-zeros does not imply known-ones. Therefore unless -args[2] is constant, we can't infer anything from it. */ -if (temp_is_const (args[2 ])) { - mask = ~temps[args[2 ]].mask; +op->args[2] is constant, we can't infer anything from it. */ +if (temp_is_const (op->args[2 ])) { + mask = ~temps[op->args[2 ]].mask; goto and_const; } -/* But we certainly know nothing outside args[1] may be set. */ - mask = temps[args[1 ]].mask; +/* But we certainly know nothing outside op->args[1] may be set. */ + mask = temps[op->args[1 ]].mask;break ;case INDEX_op_sar_i32: -if (temp_is_const (args[2 ])) { - tmp = temps[args[2 ]].val &31 ; - mask = (int32_t )temps[args[1 ]].mask >> tmp; +if (temp_is_const (op->args[2 ])) { + tmp = temps[op->args[2 ]].val &31 ; + mask = (int32_t )temps[op->args[1 ]].mask >> tmp; }break ;case INDEX_op_sar_i64: -if (temp_is_const (args[2 ])) { - tmp = temps[args[2 ]].val &63 ; - mask = (int64_t )temps[args[1 ]].mask >> tmp; +if (temp_is_const (op->args[2 ])) { + tmp = temps[op->args[2 ]].val &63 ; + mask = (int64_t )temps[op->args[1 ]].mask >> tmp; }break ;case INDEX_op_shr_i32: -if (temp_is_const (args[2 ])) { - tmp = temps[args[2 ]].val &31 ; - mask = (uint32_t )temps[args[1 ]].mask >> tmp; +if (temp_is_const (op->args[2 ])) { + tmp = temps[op->args[2 ]].val &31 ; + mask = (uint32_t )temps[op->args[1 ]].mask >> tmp; }break ;case INDEX_op_shr_i64: -if (temp_is_const (args[2 ])) { - tmp = temps[args[2 ]].val &63 ; - mask = (uint64_t )temps[args[1 ]].mask >> tmp; +if (temp_is_const (op->args[2 ])) { + tmp = temps[op->args[2 ]].val &63 ; + mask = (uint64_t )temps[op->args[1 ]].mask >> tmp; }break ;case INDEX_op_extrl_i64_i32: - mask = (uint32_t )temps[args[1 ]].mask; + mask = (uint32_t )temps[op->args[1 ]].mask;break ;case INDEX_op_extrh_i64_i32: - mask = (uint64_t )temps[args[1 ]].mask >>32 ; + mask = (uint64_t )temps[op->args[1 ]].mask >>32 ;break ; CASE_OP_32_64(shl): -if (temp_is_const (args[2 ])) { - tmp = temps[args[2 ]].val & (TCG_TARGET_REG_BITS -1 ); - mask = temps[args[1 ]].mask << tmp; +if (temp_is_const (op->args[2 ])) { + tmp = temps[op->args[2 ]].val & (TCG_TARGET_REG_BITS -1 ); + mask = temps[op->args[1 ]].mask << tmp; }break ; CASE_OP_32_64(neg):/* Set to 1 all bits to the left of the rightmost. */ - mask = -(temps[args[1 ]].mask & -temps[args[1 ]].mask); + mask = -(temps[op->args[1 ]].mask & -temps[op->args[1 ]].mask);break ; CASE_OP_32_64(deposit): - mask =deposit64 (temps[args[1 ]].mask, args[3 ], args[4 ], - temps[args[2 ]].mask); + mask =deposit64 (temps[op->args[1 ]].mask, op->args[3 ], + op->args[4 ], temps[op->args[2 ]].mask);break ; CASE_OP_32_64(extract): - mask =extract64 (temps[args[1 ]].mask, args[2 ], args[3 ]); -if (args[2 ] ==0 ) { - affected = temps[args[1 ]].mask & ~mask; + mask =extract64 (temps[op->args[1 ]].mask, op->args[2 ], op->args[3 ]); +if (op->args[2 ] ==0 ) { + affected = temps[op->args[1 ]].mask & ~mask; }break ; CASE_OP_32_64(sextract): - mask =sextract64 (temps[args[1 ]].mask, args[2 ], args[3 ]); -if (args[2 ] ==0 && (tcg_target_long )mask >=0 ) { - affected = temps[args[1 ]].mask & ~mask; + mask =sextract64 (temps[op->args[1 ]].mask, + op->args[2 ], op->args[3 ]); +if (op->args[2 ] ==0 && (tcg_target_long )mask >=0 ) { + affected = temps[op->args[1 ]].mask & ~mask; }break ; CASE_OP_32_64(or): CASE_OP_32_64(xor): - mask = temps[args[1 ]].mask | temps[args[2 ]].mask; + mask = temps[op->args[1 ]].mask | temps[op->args[2 ]].mask;break ;case INDEX_op_clz_i32:case INDEX_op_ctz_i32: - mask = temps[args[2 ]].mask |31 ; + mask = temps[op->args[2 ]].mask |31 ;break ;case INDEX_op_clz_i64:case INDEX_op_ctz_i64: - mask = temps[args[2 ]].mask |63 ; + mask = temps[op->args[2 ]].mask |63 ;break ;case INDEX_op_ctpop_i32:
@@ -937,7 +942,7 @@ void tcg_optimize(TCGContext *s)break ; CASE_OP_32_64(movcond): - mask = temps[args[3 ]].mask | temps[args[4 ]].mask; + mask = temps[op->args[3 ]].mask | temps[op->args[4 ]].mask;break ; CASE_OP_32_64(ld8u):
@@ -952,7 +957,7 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(qemu_ld): { -TCGMemOpIdx oi = args[nb_oargs + nb_iargs]; +TCGMemOpIdx oi = op->args[nb_oargs + nb_iargs];TCGMemOp mop =get_memop (oi);if (!(mop &MO_SIGN )) { mask = (2ULL << ((8 << (mop &MO_SIZE )) -1 )) -1 ;
@@ -976,12 +981,12 @@ void tcg_optimize(TCGContext *s)if (partmask ==0 ) {tcg_debug_assert (nb_oargs ==1 ); -tcg_opt_gen_movi (s, op, args, args[0 ],0 ); +tcg_opt_gen_movi (s, op, op->args[0 ],0 );continue ; }if (affected ==0 ) {tcg_debug_assert (nb_oargs ==1 ); -tcg_opt_gen_mov (s, op, args, args[0 ], args[1 ]); +tcg_opt_gen_mov (s, op, op->args[0 ], op->args[1 ]);continue ; }
@@ -991,8 +996,8 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(mul): CASE_OP_32_64(muluh): CASE_OP_32_64(mulsh): - if ((temp_is_const(args[2]) && temps[args[2]].val == 0)) { - tcg_opt_gen_movi(s, op, args, args[0], 0); + if ((temp_is_const(op->args[2]) && temps[op->args[2]].val == 0)) { + tcg_opt_gen_movi(s, op, op->args[0], 0); continue; }break ;
@@ -1004,8 +1009,8 @@ void tcg_optimize(TCGContext *s)switch (opc) { CASE_OP_32_64(or): CASE_OP_32_64(and): - if (temps_are_copies(args[1], args[2])) { -tcg_opt_gen_mov (s, op, args, args[0 ], args[1 ]); + if (temps_are_copies(op->args[1], op->args[2])) { +tcg_opt_gen_mov (s, op, op->args[0 ], op->args[1 ]);continue ; }break ;
@@ -1018,8 +1023,8 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(andc): CASE_OP_32_64(sub): CASE_OP_32_64(xor): - if (temps_are_copies(args[1], args[2])) { - tcg_opt_gen_movi(s, op, args, args[0], 0); + if (temps_are_copies(op->args[1], op->args[2])) { + tcg_opt_gen_movi(s, op, op->args[0], 0); continue; }break ;
@@ -1032,10 +1037,10 @@ void tcg_optimize(TCGContext *s)allocator where needed and possible. Also detect copies. */ switch (opc) { CASE_OP_32_64(mov): -tcg_opt_gen_mov (s ,op ,args ,args [0 ],args [1 ]); + tcg_opt_gen_mov(s, op, op->args[0], op->args[1]);break ; CASE_OP_32_64(movi): -tcg_opt_gen_movi (s ,op ,args ,args [0 ],args [1 ]); + tcg_opt_gen_movi(s, op, op->args[0], op->args[1]);break ; CASE_OP_32_64(not):
@@ -1051,9 +1056,9 @@ void tcg_optimize(TCGContext *s)case INDEX_op_extu_i32_i64:case INDEX_op_extrl_i64_i32:case INDEX_op_extrh_i64_i32: -if (temp_is_const (args[1 ])) { - tmp =do_constant_folding (opc, temps[args[1 ]].val,0 ); -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +if (temp_is_const (op->args[1 ])) { + tmp =do_constant_folding (opc, temps[op->args[1 ]].val,0 ); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp);break ; } goto do_default;
@@ -1080,68 +1085,72 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(divu): CASE_OP_32_64(rem): CASE_OP_32_64(remu): - if (temp_is_const(args[1]) && temp_is_const(args[2])) { - tmp = do_constant_folding(opc, temps[args[1]].val, - temps[args[2 ]].val); - tcg_opt_gen_movi(s, op, args, args[0], tmp); + if (temp_is_const(op->args[1]) && temp_is_const(op->args[2])) { + tmp = do_constant_folding(opc, temps[op->args[1]].val, + temps[op->args[2 ]].val); + tcg_opt_gen_movi(s, op, op->args[0], tmp); break; } goto do_default; CASE_OP_32_64(clz): CASE_OP_32_64(ctz): - if (temp_is_const(args[1])) { -TCGArg v = temps[args[1 ]].val; + if (temp_is_const(op->args[1])) { +TCGArg v = temps[op->args[1 ]].val;if (v !=0 ) { tmp =do_constant_folding (opc, v,0 ); -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp); }else { -tcg_opt_gen_mov (s, op, args, args[0 ], args[2 ]); +tcg_opt_gen_mov (s, op, op->args[0 ], op->args[2 ]); }break ; } goto do_default; CASE_OP_32_64(deposit): -if (temp_is_const (args[1 ]) &&temp_is_const (args[2 ])) { - tmp =deposit64 (temps[args[1 ]].val, args[3 ], args[4 ], - temps[args[2 ]].val); -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +if (temp_is_const (op->args[1 ]) &&temp_is_const (op->args[2 ])) { + tmp =deposit64 (temps[op->args[1 ]].val, op->args[3 ], + op->args[4 ], temps[op->args[2 ]].val); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp);break ; } goto do_default; CASE_OP_32_64(extract): - if (temp_is_const(args[1])) { - tmp =extract64 (temps[args[1 ]].val, args[2 ], args[3 ]); -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +if (temp_is_const (op->args[1 ])) { + tmp =extract64 (temps[op->args[1 ]].val, + op->args[2 ], op->args[3 ]); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp);break ; } goto do_default; CASE_OP_32_64(sextract): - if (temp_is_const(args[1])) { - tmp =sextract64 (temps[args[1 ]].val, args[2 ], args[3 ]); -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +if (temp_is_const (op->args[1 ])) { + tmp =sextract64 (temps[op->args[1 ]].val, + op->args[2 ], op->args[3 ]); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp);break ; } goto do_default; CASE_OP_32_64(setcond): - tmp =do_constant_folding_cond (opc, args[1 ], args[2 ], args[3 ]); + tmp =do_constant_folding_cond (opc, op->args[1 ], + op->args[2 ], op->args[3 ]);if (tmp !=2 ) { -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +tcg_opt_gen_movi (s, op, op->args[0 ], tmp);break ; } goto do_default; CASE_OP_32_64(brcond): - tmp =do_constant_folding_cond (opc, args[0 ], args[1 ], args[2 ]); + tmp =do_constant_folding_cond (opc, op->args[0 ], + op->args[1 ], op->args[2 ]);if (tmp !=2 ) {if (tmp) {reset_all_temps (nb_temps); op->opc = INDEX_op_br; - args[0 ] = args[3 ]; + op->args[0 ] = op->args[3 ]; }else {tcg_op_remove (s, op); }
@@ -1150,21 +1159,22 @@ void tcg_optimize(TCGContext *s) goto do_default; CASE_OP_32_64(movcond): - tmp =do_constant_folding_cond (opc, args[1 ], args[2 ], args[5 ]); + tmp =do_constant_folding_cond (opc, op->args[1 ], + op->args[2 ], op->args[5 ]);if (tmp !=2 ) { -tcg_opt_gen_mov (s, op, args, args[0 ], args[4 -tmp]); +tcg_opt_gen_mov (s, op, op->args[0 ], op->args[4 -tmp]);break ; } -if (temp_is_const (args[3 ]) &&temp_is_const (args[4 ])) { -tcg_target_ulong tv = temps[args[3 ]].val; -tcg_target_ulong fv = temps[args[4 ]].val; -TCGCond cond = args[5 ]; +if (temp_is_const (op->args[3 ]) &&temp_is_const (op->args[4 ])) { +tcg_target_ulong tv = temps[op->args[3 ]].val; +tcg_target_ulong fv = temps[op->args[4 ]].val; +TCGCond cond = op->args[5 ];if (fv ==1 && tv ==0 ) { cond =tcg_invert_cond (cond); }else if (!(tv ==1 && fv ==0 )) { goto do_default; } - args[3 ] = cond; + op->args[3 ] = cond; op->opc = opc = (opc == INDEX_op_movcond_i32 ? INDEX_op_setcond_i32 : INDEX_op_setcond_i64);
@@ -1174,17 +1184,16 @@ void tcg_optimize(TCGContext *s)case INDEX_op_add2_i32:case INDEX_op_sub2_i32: -if (temp_is_const (args[2 ]) &&temp_is_const (args[3 ]) - &&temp_is_const (args[4 ]) &&temp_is_const (args[5 ])) { -uint32_t al = temps[args[2 ]].val; -uint32_t ah = temps[args[3 ]].val; -uint32_t bl = temps[args[4 ]].val; -uint32_t bh = temps[args[5 ]].val; +if (temp_is_const (op->args[2 ]) &&temp_is_const (op->args[3 ]) + &&temp_is_const (op->args[4 ]) &&temp_is_const (op->args[5 ])) { +uint32_t al = temps[op->args[2 ]].val; +uint32_t ah = temps[op->args[3 ]].val; +uint32_t bl = temps[op->args[4 ]].val; +uint32_t bh = temps[op->args[5 ]].val;uint64_t a = ((uint64_t )ah <<32 ) | al;uint64_t b = ((uint64_t )bh <<32 ) | bl;TCGArg rl, rh;TCGOp *op2 =tcg_op_insert_before (s, op, INDEX_op_movi_i32,2 ); -TCGArg *args2 = op2->args;if (opc == INDEX_op_add2_i32) { a += b;
@@ -1192,10 +1201,10 @@ void tcg_optimize(TCGContext *s) a -= b; } - rl = args[0 ]; - rh = args[1 ]; -tcg_opt_gen_movi (s, op, args, rl, (int32_t )a); -tcg_opt_gen_movi (s, op2, args2, rh, (int32_t )(a >>32 )); + rl = op->args[0 ]; + rh = op->args[1 ]; +tcg_opt_gen_movi (s, op, rl, (int32_t )a); +tcg_opt_gen_movi (s, op2, rh, (int32_t )(a >>32 ));/* We've done all we need to do with the movi. Skip it. */ oi_next = op2->next;
@@ -1204,18 +1213,17 @@ void tcg_optimize(TCGContext *s) goto do_default;case INDEX_op_mulu2_i32: -if (temp_is_const (args[2 ]) &&temp_is_const (args[3 ])) { -uint32_t a = temps[args[2 ]].val; -uint32_t b = temps[args[3 ]].val; +if (temp_is_const (op->args[2 ]) &&temp_is_const (op->args[3 ])) { +uint32_t a = temps[op->args[2 ]].val; +uint32_t b = temps[op->args[3 ]].val;uint64_t r = (uint64_t )a * b;TCGArg rl, rh;TCGOp *op2 =tcg_op_insert_before (s, op, INDEX_op_movi_i32,2 ); -TCGArg *args2 = op2->args; - rl = args[0 ]; - rh = args[1 ]; -tcg_opt_gen_movi (s, op, args, rl, (int32_t )r); -tcg_opt_gen_movi (s, op2, args2, rh, (int32_t )(r >>32 )); + rl = op->args[0 ]; + rh = op->args[1 ]; +tcg_opt_gen_movi (s, op, rl, (int32_t )r); +tcg_opt_gen_movi (s, op2, rh, (int32_t )(r >>32 ));/* We've done all we need to do with the movi. Skip it. */ oi_next = op2->next;
@@ -1224,41 +1232,47 @@ void tcg_optimize(TCGContext *s) goto do_default;case INDEX_op_brcond2_i32: - tmp =do_constant_folding_cond2 (&args[0 ], &args[2 ], args[4 ]); + tmp =do_constant_folding_cond2 (&op->args[0 ], &op->args[2 ], + op->args[4 ]);if (tmp !=2 ) {if (tmp) { do_brcond_true:reset_all_temps (nb_temps); op->opc = INDEX_op_br; - args[0 ] = args[5 ]; + op->args[0 ] = op->args[5 ]; }else { do_brcond_false:tcg_op_remove (s, op); } - }else if ((args[4 ] ==TCG_COND_LT || args[4 ] ==TCG_COND_GE ) - &&temp_is_const (args[2 ]) && temps[args[2 ]].val ==0 - &&temp_is_const (args[3 ]) && temps[args[3 ]].val ==0 ) { + }else if ((op->args[4 ] ==TCG_COND_LT + || op->args[4 ] ==TCG_COND_GE ) + &&temp_is_const (op->args[2 ]) + && temps[op->args[2 ]].val ==0 + &&temp_is_const (op->args[3 ]) + && temps[op->args[3 ]].val ==0 ) {/* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ do_brcond_high:reset_all_temps (nb_temps); op->opc = INDEX_op_brcond_i32; - args[0 ] = args[1 ]; - args[1 ] = args[3 ]; - args[2 ] = args[4 ]; - args[3 ] = args[5 ]; - }else if (args[4 ] ==TCG_COND_EQ ) { + op->args[0 ] = op->args[1 ]; + op->args[1 ] = op->args[3 ]; + op->args[2 ] = op->args[4 ]; + op->args[3 ] = op->args[5 ]; + }else if (op->args[4 ] ==TCG_COND_EQ ) {/* Simplify EQ comparisons where one of the pairs can be simplified. */ tmp =do_constant_folding_cond (INDEX_op_brcond_i32, - args[0 ], args[2 ],TCG_COND_EQ ); + op->args[0 ], op->args[2 ], +TCG_COND_EQ );if (tmp ==0 ) { goto do_brcond_false; }else if (tmp ==1 ) { goto do_brcond_high; } tmp =do_constant_folding_cond (INDEX_op_brcond_i32, - args[1 ], args[3 ],TCG_COND_EQ ); + op->args[1 ], op->args[3 ], +TCG_COND_EQ );if (tmp ==0 ) { goto do_brcond_false; }else if (tmp !=1 ) {
@@ -1267,21 +1281,23 @@ void tcg_optimize(TCGContext *s) do_brcond_low:reset_all_temps (nb_temps); op->opc = INDEX_op_brcond_i32; - args[1 ] = args[2 ]; - args[2 ] = args[4 ]; - args[3 ] = args[5 ]; - }else if (args[4 ] ==TCG_COND_NE ) { + op->args[1 ] = op->args[2 ]; + op->args[2 ] = op->args[4 ]; + op->args[3 ] = op->args[5 ]; + }else if (op->args[4 ] ==TCG_COND_NE ) {/* Simplify NE comparisons where one of the pairs can be simplified. */ tmp =do_constant_folding_cond (INDEX_op_brcond_i32, - args[0 ], args[2 ],TCG_COND_NE ); + op->args[0 ], op->args[2 ], +TCG_COND_NE );if (tmp ==0 ) { goto do_brcond_high; }else if (tmp ==1 ) { goto do_brcond_true; } tmp =do_constant_folding_cond (INDEX_op_brcond_i32, - args[1 ], args[3 ],TCG_COND_NE ); + op->args[1 ], op->args[3 ], +TCG_COND_NE );if (tmp ==0 ) { goto do_brcond_low; }else if (tmp ==1 ) {
@@ -1294,57 +1310,65 @@ void tcg_optimize(TCGContext *s)break ;case INDEX_op_setcond2_i32: - tmp =do_constant_folding_cond2 (&args[1 ], &args[3 ], args[5 ]); + tmp =do_constant_folding_cond2 (&op->args[1 ], &op->args[3 ], + op->args[5 ]);if (tmp !=2 ) { do_setcond_const: -tcg_opt_gen_movi (s, op, args, args[0 ], tmp); - }else if ((args[5 ] ==TCG_COND_LT || args[5 ] ==TCG_COND_GE ) - &&temp_is_const (args[3 ]) && temps[args[3 ]].val ==0 - &&temp_is_const (args[4 ]) && temps[args[4 ]].val ==0 ) { +tcg_opt_gen_movi (s, op, op->args[0 ], tmp); + }else if ((op->args[5 ] ==TCG_COND_LT + || op->args[5 ] ==TCG_COND_GE ) + &&temp_is_const (op->args[3 ]) + && temps[op->args[3 ]].val ==0 + &&temp_is_const (op->args[4 ]) + && temps[op->args[4 ]].val ==0 ) {/* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ do_setcond_high: -reset_temp (args[0 ]); - temps[args[0 ]].mask =1 ; +reset_temp (op->args[0 ]); + temps[op->args[0 ]].mask =1 ; op->opc = INDEX_op_setcond_i32; - args[1 ] = args[2 ]; - args[2 ] = args[4 ]; - args[3 ] = args[5 ]; - }else if (args[5 ] ==TCG_COND_EQ ) { + op->args[1 ] = op->args[2 ]; + op->args[2 ] = op->args[4 ]; + op->args[3 ] = op->args[5 ]; + }else if (op->args[5 ] ==TCG_COND_EQ ) {/* Simplify EQ comparisons where one of the pairs can be simplified. */ tmp =do_constant_folding_cond (INDEX_op_setcond_i32, - args[1 ], args[3 ],TCG_COND_EQ ); + op->args[1 ], op->args[3 ], +TCG_COND_EQ );if (tmp ==0 ) { goto do_setcond_const; }else if (tmp ==1 ) { goto do_setcond_high; } tmp =do_constant_folding_cond (INDEX_op_setcond_i32, - args[2 ], args[4 ],TCG_COND_EQ ); + op->args[2 ], op->args[4 ], +TCG_COND_EQ );if (tmp ==0 ) { goto do_setcond_high; }else if (tmp !=1 ) { goto do_default; } do_setcond_low: -reset_temp (args[0 ]); - temps[args[0 ]].mask =1 ; +reset_temp (op->args[0 ]); + temps[op->args[0 ]].mask =1 ; op->opc = INDEX_op_setcond_i32; - args[2 ] = args[3 ]; - args[3 ] = args[5 ]; - }else if (args[5 ] ==TCG_COND_NE ) { + op->args[2 ] = op->args[3 ]; + op->args[3 ] = op->args[5 ]; + }else if (op->args[5 ] ==TCG_COND_NE ) {/* Simplify NE comparisons where one of the pairs can be simplified. */ tmp =do_constant_folding_cond (INDEX_op_setcond_i32, - args[1 ], args[3 ],TCG_COND_NE ); + op->args[1 ], op->args[3 ], +TCG_COND_NE );if (tmp ==0 ) { goto do_setcond_high; }else if (tmp ==1 ) { goto do_setcond_const; } tmp =do_constant_folding_cond (INDEX_op_setcond_i32, - args[2 ], args[4 ],TCG_COND_NE ); + op->args[2 ], op->args[4 ], +TCG_COND_NE );if (tmp ==0 ) { goto do_setcond_low; }else if (tmp ==1 ) {
@@ -1357,7 +1381,7 @@ void tcg_optimize(TCGContext *s)break ;case INDEX_op_call: -if (!(args[nb_oargs + nb_iargs +1 ] +if (!(op->args[nb_oargs + nb_iargs +1 ] & (TCG_CALL_NO_READ_GLOBALS |TCG_CALL_NO_WRITE_GLOBALS ))) {for (i =0 ; i < nb_globals; i++) {if (test_bit (i, temps_used.l)) {
@@ -1379,11 +1403,11 @@ void tcg_optimize(TCGContext *s) }else { do_reset_output:for (i =0 ; i < nb_oargs; i++) { -reset_temp (args[i]); +reset_temp (op->args[i]);/* Save the corresponding known-zero bits mask for the first output argument (only one supported so far). */ if (i ==0 ) { - temps[args[i]].mask = mask; + temps[op->args[i]].mask = mask; } } }
@@ -1391,7 +1415,7 @@ void tcg_optimize(TCGContext *s) }/* Eliminate duplicate and redundant fence instructions. */ -if (prev_mb_args) { +if (prev_mb) {switch (opc) {case INDEX_op_mb:/* Merge two barriers of the same type into one,
@@ -1405,7 +1429,7 @@ void tcg_optimize(TCGContext *s)* barrier. This is stricter than specified but for * the purposes of TCG is better than not optimizing. */ - prev_mb_args[0 ] |= args[0 ]; + prev_mb->args[0 ] |= op->args[0 ];tcg_op_remove (s, op);break ;
@@ -1421,11 +1445,11 @@ void tcg_optimize(TCGContext *s)case INDEX_op_qemu_st_i64:case INDEX_op_call:/* Opcodes that touch guest memory stop the optimization. */ - prev_mb_args =NULL ; + prev_mb =NULL ;break ; } }else if (opc == INDEX_op_mb) { - prev_mb_args = args; + prev_mb = op; } } }
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 02/50] tcg: Propagate args to op->args in optimizer
Quoted 6 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tcg/optimize.c | 430 ++++++++++++++++++++++++++++++---------------------------
(snip)
Quoted 10 lines
tcg/optimize.c +1
-1@@ -559,7 +557,7 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2)void tcg_optimize (TCGContext *s) {int oi, oi_next, nb_temps, nb_globals; -TCGArg *prev_mb_args =NULL ; +TCGOp *prev_mb =NULL ;/* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element.
tcg/optimize.c void tcg_optimize(TCGContext *s) · line 579
Quoted 4 lines
tcg/optimize.c +0
-1@@ -576,7 +574,6 @@ void tcg_optimize(TCGContext *s)TCGArg tmp;TCGOp *const op = &s->gen_op_buf[oi]; -TCGArg *const args = op->args;
Just for my own education: why doesn't gcc generate the same code when leaving 'args' as above? I thought we could simplify the diff without any side effects, but it turns out that more code is generated.
Thanks,
E.
Re: [Qemu-devel] [PATCH v6 02/50] tcg: Propagate args to op->args in optimizer
Quoted 7 lines · Emilio G. Cota
Quoted 1 line
- TCGArg * const args =
op->args;Reviewed-by Emilio G. Cota <[email protected]>Just for my own education: why doesn't gcc generate the same code when leaving 'args' as above? I thought we could simplify the diff without any side effects, but it turns out that more code is generated.
Um... this patch was intended to be code cleanup only. It should have generated the same code. I admit I didn't check.
That there is a code difference is surprising and probably reportable as a compiler bug.
r~
PATCH v6 3/50 tcg: Propagate args to op->args in tcg.c
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.c | 121 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 63 deletions(-)
tcg/tcg.c +58 -63
@@ -1277,14 +1277,12 @@ void tcg_dump_ops(TCGContext *s)for (oi = s->gen_op_buf[0 ].next; oi !=0 ; oi = op->next) {int i, k, nb_oargs, nb_iargs, nb_cargs;const TCGOpDef *def; -const TCGArg *args;TCGOpcode c;int col =0 ; op = &s->gen_op_buf[oi]; c = op->opc; def = &tcg_op_defs[c]; - args = op->args;if (c == INDEX_op_insn_start) { col +=qemu_log ("%s ----" , oi != s->gen_op_buf[0 ].next ?"\n" :"" );
@@ -1292,9 +1290,9 @@ void tcg_dump_ops(TCGContext *s)for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) {target_ulong a;#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS - a = ((target_ulong )args[i *2 +1 ] <<32 ) | args[i *2 ]; + a =deposit64 (op->args[i *2 ],32 ,32 , op->args[i *2 +1 ]);#else - a = args[i]; + a = op->args[i];#endif col +=qemu_log (" " TARGET_FMT_lx, a); }
@@ -1306,14 +1304,14 @@ void tcg_dump_ops(TCGContext *s)/* function name, flags, out args */ col +=qemu_log (" %s %s,$0x%" TCG_PRIlx",$%d" , def->name, -tcg_find_helper (s, args[nb_oargs + nb_iargs]), - args[nb_oargs + nb_iargs +1 ], nb_oargs); +tcg_find_helper (s, op->args[nb_oargs + nb_iargs]), + op->args[nb_oargs + nb_iargs +1 ], nb_oargs);for (i =0 ; i < nb_oargs; i++) { col +=qemu_log (",%s" ,tcg_get_arg_str_idx (s, buf,sizeof (buf), - args[i])); + op->args[i])); }for (i =0 ; i < nb_iargs; i++) { -TCGArg arg = args[nb_oargs + i]; +TCGArg arg = op->args[nb_oargs + i];const char *t ="<dummy>" ;if (arg !=TCG_CALL_DUMMY_ARG ) { t =tcg_get_arg_str_idx (s, buf,sizeof (buf), arg);
@@ -1333,14 +1331,14 @@ void tcg_dump_ops(TCGContext *s) col +=qemu_log ("," ); } col +=qemu_log ("%s" ,tcg_get_arg_str_idx (s, buf,sizeof (buf), - args[k++])); + op->args[k++])); }for (i =0 ; i < nb_iargs; i++) {if (k !=0 ) { col +=qemu_log ("," ); } col +=qemu_log ("%s" ,tcg_get_arg_str_idx (s, buf,sizeof (buf), - args[k++])); + op->args[k++])); }switch (c) {case INDEX_op_brcond_i32:
@@ -1351,10 +1349,11 @@ void tcg_dump_ops(TCGContext *s)case INDEX_op_brcond_i64:case INDEX_op_setcond_i64:case INDEX_op_movcond_i64: -if (args[k] <ARRAY_SIZE (cond_name) && cond_name[args[k]]) { - col +=qemu_log (",%s" , cond_name[args[k++]]); +if (op->args[k] <ARRAY_SIZE (cond_name) + && cond_name[op->args[k]]) { + col +=qemu_log (",%s" , cond_name[op->args[k++]]); }else { - col +=qemu_log (",$0x%" TCG_PRIlx, args[k++]); + col +=qemu_log (",$0x%" TCG_PRIlx, op->args[k++]); } i =1 ;break ;
@@ -1363,7 +1362,7 @@ void tcg_dump_ops(TCGContext *s)case INDEX_op_qemu_ld_i64:case INDEX_op_qemu_st_i64: { -TCGMemOpIdx oi = args[k++]; +TCGMemOpIdx oi = op->args[k++];TCGMemOp op =get_memop (oi);unsigned ix =get_mmuidx (oi);
@@ -1388,14 +1387,15 @@ void tcg_dump_ops(TCGContext *s)case INDEX_op_brcond_i32:case INDEX_op_brcond_i64:case INDEX_op_brcond2_i32: - col +=qemu_log ("%s$L%d" , k ?"," :"" ,arg_label (args[k])->id); + col +=qemu_log ("%s$L%d" , k ?"," :"" , +arg_label (op->args[k])->id); i++, k++;break ;default :break ; }for (; i < nb_cargs; i++, k++) { - col +=qemu_log ("%s$0x%" TCG_PRIlx, k ?"," :"" , args[k]); + col +=qemu_log ("%s$0x%" TCG_PRIlx, k ?"," :"" , op->args[k]); } }if (op->life) {
@@ -1656,7 +1656,6 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)TCGArg arg;TCGOp *const op = &s->gen_op_buf[oi]; -TCGArg *const args = op->args;TCGOpcode opc = op->opc;const TCGOpDef *def = &tcg_op_defs[opc];
@@ -1669,12 +1668,12 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state) nb_oargs = op->callo; nb_iargs = op->calli; - call_flags = args[nb_oargs + nb_iargs +1 ]; + call_flags = op->args[nb_oargs + nb_iargs +1 ];/* pure functions can be removed if their result is unused */ if (call_flags &TCG_CALL_NO_SIDE_EFFECTS ) {for (i =0 ; i < nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (temp_state[arg] !=TS_DEAD ) { goto do_not_remove_call; }
@@ -1685,7 +1684,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)/* output args are dead */ for (i =0 ; i < nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (temp_state[arg] &TS_DEAD ) { arg_life |=DEAD_ARG << i; }
@@ -1708,7 +1707,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)/* record arguments that die in this helper */ for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (arg !=TCG_CALL_DUMMY_ARG ) {if (temp_state[arg] &TS_DEAD ) { arg_life |=DEAD_ARG << i;
@@ -1717,7 +1716,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state) }/* input arguments are live for preceding opcodes */ for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (arg !=TCG_CALL_DUMMY_ARG ) { temp_state[arg] &= ~TS_DEAD ; }
@@ -1729,7 +1728,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)break ;case INDEX_op_discard:/* mark the temporary as dead */ - temp_state[args[0 ]] =TS_DEAD ; + temp_state[op->args[0 ]] =TS_DEAD ;break ;case INDEX_op_add2_i32:
@@ -1750,15 +1749,15 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)the low part. The result can be optimized to a simple add or sub. This happens often for x86_64 guest when the cpu mode is set to 32 bit. */ -if (temp_state[args[1 ]] ==TS_DEAD ) { -if (temp_state[args[0 ]] ==TS_DEAD ) { +if (temp_state[op->args[1 ]] ==TS_DEAD ) { +if (temp_state[op->args[0 ]] ==TS_DEAD ) { goto do_remove; }/* Replace the opcode and adjust the args in place, leaving 3 unused args at the end. */ op->opc = opc = opc_new; - args[1 ] = args[2 ]; - args[2 ] = args[4 ]; + op->args[1 ] = op->args[2 ]; + op->args[2 ] = op->args[4 ];/* Fall through and mark the single-word operation live. */ nb_iargs =2 ; nb_oargs =1 ;
@@ -1788,21 +1787,21 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state) do_mul2: nb_iargs =2 ; nb_oargs =2 ; -if (temp_state[args[1 ]] ==TS_DEAD ) { -if (temp_state[args[0 ]] ==TS_DEAD ) { +if (temp_state[op->args[1 ]] ==TS_DEAD ) { +if (temp_state[op->args[0 ]] ==TS_DEAD ) {/* Both parts of the operation are dead. */ goto do_remove; }/* The high part of the operation is dead; generate the low. */ op->opc = opc = opc_new; - args[1 ] = args[2 ]; - args[2 ] = args[3 ]; - }else if (temp_state[args[0 ]] ==TS_DEAD && have_opc_new2) { + op->args[1 ] = op->args[2 ]; + op->args[2 ] = op->args[3 ]; + }else if (temp_state[op->args[0 ]] ==TS_DEAD && have_opc_new2) {/* The low part of the operation is dead; generate the high. */ op->opc = opc = opc_new2; - args[0 ] = args[1 ]; - args[1 ] = args[2 ]; - args[2 ] = args[3 ]; + op->args[0 ] = op->args[1 ]; + op->args[1 ] = op->args[2 ]; + op->args[2 ] = op->args[3 ]; }else { goto do_not_remove; }
@@ -1820,7 +1819,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)implies side effects */ if (!(def->flags &TCG_OPF_SIDE_EFFECTS ) && nb_oargs !=0 ) {for (i =0 ; i < nb_oargs; i++) { -if (temp_state[args[i]] !=TS_DEAD ) { +if (temp_state[op->args[i]] !=TS_DEAD ) { goto do_not_remove; } }
@@ -1830,7 +1829,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state) do_not_remove:/* output args are dead */ for (i =0 ; i < nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (temp_state[arg] &TS_DEAD ) { arg_life |=DEAD_ARG << i; }
@@ -1852,14 +1851,14 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)/* record arguments that die in this opcode */ for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { - arg = args[i]; + arg = op->args[i];if (temp_state[arg] &TS_DEAD ) { arg_life |=DEAD_ARG << i; } }/* input arguments are live for preceding opcodes */ for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { - temp_state[args[i]] &= ~TS_DEAD ; + temp_state[op->args[i]] &= ~TS_DEAD ; } }break ;
@@ -1894,7 +1893,6 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)for (oi = s->gen_op_buf[0 ].next; oi !=0 ; oi = oi_next) {TCGOp *op = &s->gen_op_buf[oi]; -TCGArg *args = op->args;TCGOpcode opc = op->opc;const TCGOpDef *def = &tcg_op_defs[opc];TCGLifeData arg_life = op->life;
@@ -1906,7 +1904,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)if (opc == INDEX_op_call) { nb_oargs = op->callo; nb_iargs = op->calli; - call_flags = args[nb_oargs + nb_iargs +1 ]; + call_flags = op->args[nb_oargs + nb_iargs +1 ]; }else { nb_iargs = def->nb_iargs; nb_oargs = def->nb_oargs;
@@ -1927,7 +1925,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)/* Make sure that input arguments are available. */ for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];/* Note this unsigned test catches TCG_CALL_ARG_DUMMY too. */ if (arg < nb_globals) { dir = dir_temps[arg];
@@ -1937,11 +1935,10 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state) ? INDEX_op_ld_i32 : INDEX_op_ld_i64);TCGOp *lop =tcg_op_insert_before (s, op, lopc,3 ); -TCGArg *largs = lop->args; - largs[0 ] = dir; - largs[1 ] =temp_idx (s, its->mem_base); - largs[2 ] = its->mem_offset; + lop->args[0 ] = dir; + lop->args[1 ] =temp_idx (s, its->mem_base); + lop->args[2 ] = its->mem_offset;/* Loaded, but synced with memory. */ temp_state[arg] =TS_MEM ;
@@ -1953,11 +1950,11 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)No action is required except keeping temp_state up to date so that we reload when needed. */ for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (arg < nb_globals) { dir = dir_temps[arg];if (dir !=0 ) { - args[i] = dir; + op->args[i] = dir; changes = true;if (IS_DEAD_ARG (i)) { temp_state[arg] =TS_DEAD ;
@@ -1988,7 +1985,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)/* Outputs become available. */ for (i =0 ; i < nb_oargs; i++) { - arg = args[i]; + arg = op->args[i];if (arg >= nb_globals) {continue ; }
@@ -1996,7 +1993,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)if (dir ==0 ) {continue ; } - args[i] = dir; + op->args[i] = dir; changes = true;/* The output is now live and modified. */
@@ -2009,11 +2006,10 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state) ? INDEX_op_st_i32 : INDEX_op_st_i64);TCGOp *sop =tcg_op_insert_after (s, op, sopc,3 ); -TCGArg *sargs = sop->args; - sargs[0 ] = dir; - sargs[1 ] =temp_idx (s, its->mem_base); - sargs[2 ] = its->mem_offset; + sop->args[0 ] = dir; + sop->args[1 ] =temp_idx (s, its->mem_base); + sop->args[2 ] = its->mem_offset; temp_state[arg] =TS_MEM ; }
@@ -2841,7 +2837,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) num_insns =-1 ;for (oi = s->gen_op_buf[0 ].next; oi !=0 ; oi = oi_next) {TCGOp *const op = &s->gen_op_buf[oi]; -TCGArg *const args = op->args;TCGOpcode opc = op->opc;const TCGOpDef *def = &tcg_op_defs[opc];TCGLifeData arg_life = op->life;
@@ -2854,11 +2849,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)switch (opc) {case INDEX_op_mov_i32:case INDEX_op_mov_i64: -tcg_reg_alloc_mov (s, def, args, arg_life); +tcg_reg_alloc_mov (s, def, op->args, arg_life);break ;case INDEX_op_movi_i32:case INDEX_op_movi_i64: -tcg_reg_alloc_movi (s, args, arg_life); +tcg_reg_alloc_movi (s, op->args, arg_life);break ;case INDEX_op_insn_start:if (num_insns >=0 ) {
@@ -2868,22 +2863,22 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) {target_ulong a;#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS - a = ((target_ulong )args[i *2 +1 ] <<32 ) | args[i *2 ]; + a =deposit64 (op->args[i *2 ],32 ,32 , op->args[i *2 +1 ]);#else - a = args[i]; + a = op->args[i];#endif s->gen_insn_data[num_insns][i] = a; }break ;case INDEX_op_discard: -temp_dead (s, &s->temps[args[0 ]]); +temp_dead (s, &s->temps[op->args[0 ]]);break ;case INDEX_op_set_label:tcg_reg_alloc_bb_end (s, s->reserved_regs); -tcg_out_label (s,arg_label (args[0 ]), s->code_ptr); +tcg_out_label (s,arg_label (op->args[0 ]), s->code_ptr);break ;case INDEX_op_call: -tcg_reg_alloc_call (s, op->callo, op->calli, args, arg_life); +tcg_reg_alloc_call (s, op->callo, op->calli, op->args, arg_life);break ;default :/* Sanity check that we've not introduced any unhandled opcodes. */
@@ -2891,7 +2886,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)/* Note: in order to speed up the code, it would be much faster to have specialized register allocator functions for some common argument patterns */ -tcg_reg_alloc_op (s, def, opc, args, arg_life); +tcg_reg_alloc_op (s, def, opc, op->args, arg_life);break ; }#ifdef CONFIG_DEBUG_TCG
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 03/50] tcg: Propagate args to op->args in tcg.c
Quoted 4 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 4/50 tcg: Propagate TCGOp down to allocators
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.c | 78 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 38 deletions(-)
tcg/tcg.c +40 -38
@@ -2334,25 +2334,24 @@ static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots, } } -static void tcg_reg_alloc_movi (TCGContext *s,const TCGArg *args, -TCGLifeData arg_life) +static void tcg_reg_alloc_movi (TCGContext *s,const TCGOp *op) { -TCGTemp *ots = &s->temps[args[0 ]]; -tcg_target_ulong val = args[1 ]; +TCGTemp *ots = &s->temps[op->args[0 ]]; +tcg_target_ulong val = op->args[1 ]; -tcg_reg_alloc_do_movi (s, ots, val, arg_life); +tcg_reg_alloc_do_movi (s, ots, val, op->life); } -static void tcg_reg_alloc_mov (TCGContext *s,const TCGOpDef *def, -const TCGArg *args,TCGLifeData arg_life) +static void tcg_reg_alloc_mov (TCGContext *s,const TCGOp *op) { +const TCGLifeData arg_life = op->life;TCGRegSet allocated_regs;TCGTemp *ts, *ots;TCGType otype, itype; allocated_regs = s->reserved_regs; - ots = &s->temps[args[0 ]]; - ts = &s->temps[args[1 ]]; + ots = &s->temps[op->args[0 ]]; + ts = &s->temps[op->args[1 ]];/* Note that otype != itype for no-op truncation. */ otype = ots->type;
@@ -2382,7 +2381,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,liveness analysis disabled). */ tcg_debug_assert (NEED_SYNC_ARG (0 ));if (!ots->mem_allocated) { -temp_allocate_frame (s, args[0 ]); +temp_allocate_frame (s, op->args[0 ]); }tcg_out_st (s, otype, ts->reg, ots->mem_base->reg, ots->mem_offset);if (IS_DEAD_ARG (1 )) {
@@ -2416,10 +2415,10 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, } } -static void tcg_reg_alloc_op (TCGContext *s, -const TCGOpDef *def,TCGOpcode opc, -const TCGArg *args,TCGLifeData arg_life) +static void tcg_reg_alloc_op (TCGContext *s,const TCGOp *op) { +const TCGLifeData arg_life = op->life; +const TCGOpDef *const def = &tcg_op_defs[op->opc];TCGRegSet i_allocated_regs;TCGRegSet o_allocated_regs;int i, k, nb_iargs, nb_oargs;
@@ -2430,21 +2429,24 @@ static void tcg_reg_alloc_op(TCGContext *s,TCGArg new_args[TCG_MAX_OP_ARGS ];int const_args[TCG_MAX_OP_ARGS ]; +/* Sanity check that we've not introduced any unhandled opcodes. */ +tcg_debug_assert (!(def->flags &TCG_OPF_NOT_PRESENT )); + nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs;/* copy constants */ memcpy (new_args + nb_oargs + nb_iargs, - args + nb_oargs + nb_iargs, + op->args + nb_oargs + nb_iargs,sizeof (TCGArg) * def->nb_cargs); i_allocated_regs = s->reserved_regs; o_allocated_regs = s->reserved_regs;/* satisfy input constraints */ -for (k =0 ; k < nb_iargs; k++) { +for (k =0 ; k < nb_iargs; k++) { i = def->sorted_args[nb_oargs + k]; - arg = args[i]; + arg = op->args[i]; arg_ct = &def->args_ct[i]; ts = &s->temps[arg];
@@ -2462,7 +2464,7 @@ static void tcg_reg_alloc_op(TCGContext *s,if (ts->fixed_reg) {/* if fixed register, we must allocate a new register if the alias is not the same register */ -if (arg != args[arg_ct->alias_index]) +if (arg != op->args[arg_ct->alias_index]) goto allocate_in_reg; }else {/* if the input is aliased to an output and if it is
@@ -2503,7 +2505,7 @@ static void tcg_reg_alloc_op(TCGContext *s,/* mark dead temporaries and free the associated registers */ for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {if (IS_DEAD_ARG (i)) { -temp_dead (s, &s->temps[args[i]]); +temp_dead (s, &s->temps[op->args[i]]); } }
@@ -2527,7 +2529,7 @@ static void tcg_reg_alloc_op(TCGContext *s,/* satisfy the output constraints */ for (k =0 ; k < nb_oargs; k++) { i = def->sorted_args[k]; - arg = args[i]; + arg = op->args[i]; arg_ct = &def->args_ct[i]; ts = &s->temps[arg]; if ((arg_ct->ct & TCG_CT_ALIAS)
@@ -2566,11 +2568,11 @@ static void tcg_reg_alloc_op(TCGContext *s, }/* emit instruction */ -tcg_out_op (s, opc, new_args, const_args); +tcg_out_op (s, op->opc, new_args, const_args);/* move the outputs in the correct register if needed */ for (i =0 ; i < nb_oargs; i++) { - ts = &s->temps[args[i]]; + ts = &s->temps[op->args[i]]; reg = new_args[i];if (ts->fixed_reg && ts->reg != reg) {tcg_out_mov (s, ts->type, ts->reg, reg);
@@ -2589,9 +2591,11 @@ static void tcg_reg_alloc_op(TCGContext *s,#define STACK_DIR (x) (x)#endif -static void tcg_reg_alloc_call (TCGContext *s,int nb_oargs,int nb_iargs, -const TCGArg *const args,TCGLifeData arg_life) +static void tcg_reg_alloc_call (TCGContext *s,TCGOp *op) { +const int nb_oargs = op->callo; +const int nb_iargs = op->calli; +const TCGLifeData arg_life = op->life;int flags, nb_regs, i;TCGReg reg;TCGArg arg;
@@ -2602,8 +2606,8 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs,int allocate_args;TCGRegSet allocated_regs; - func_addr = (tcg_insn_unit *)(intptr_t )args[nb_oargs + nb_iargs]; - flags = args[nb_oargs + nb_iargs +1 ]; + func_addr = (tcg_insn_unit *)(intptr_t )op->args[nb_oargs + nb_iargs]; + flags = op->args[nb_oargs + nb_iargs +1 ]; nb_regs =ARRAY_SIZE (tcg_target_call_iarg_regs);if (nb_regs > nb_iargs) {
@@ -2622,8 +2626,8 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs, } stack_offset =TCG_TARGET_CALL_STACK_OFFSET ; -for (i = nb_regs; i < nb_iargs; i++) { - arg = args[nb_oargs + i]; +for (i = nb_regs; i < nb_iargs; i++) { + arg = op->args[nb_oargs + i];#ifdef TCG_TARGET_STACK_GROWSUP stack_offset -=sizeof (tcg_target_long);#endif
@@ -2640,8 +2644,8 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs,/* assign input registers */ allocated_regs = s->reserved_regs; -for (i =0 ; i < nb_regs; i++) { - arg = args[nb_oargs + i]; +for (i =0 ; i < nb_regs; i++) { + arg = op->args[nb_oargs + i];if (arg !=TCG_CALL_DUMMY_ARG ) { ts = &s->temps[arg]; reg = tcg_target_call_iarg_regs[i];
@@ -2663,9 +2667,9 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs, }/* mark dead temporaries and free the associated registers */ -for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { +for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) {if (IS_DEAD_ARG (i)) { -temp_dead (s, &s->temps[args[i]]); +temp_dead (s, &s->temps[op->args[i]]); } }
@@ -2690,7 +2694,7 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs,/* assign output registers and emit moves if needed */ for (i =0 ; i < nb_oargs; i++) { - arg = args[i]; + arg = op->args[i]; ts = &s->temps[arg]; reg = tcg_target_call_oarg_regs[i];tcg_debug_assert (s->reg_to_temp[reg] ==NULL );
@@ -2838,8 +2842,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)for (oi = s->gen_op_buf[0 ].next; oi !=0 ; oi = oi_next) {TCGOp *const op = &s->gen_op_buf[oi];TCGOpcode opc = op->opc; -const TCGOpDef *def = &tcg_op_defs[opc]; -TCGLifeData arg_life = op->life; oi_next = op->next;#ifdef CONFIG_PROFILER
@@ -2849,11 +2851,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)switch (opc) {case INDEX_op_mov_i32:case INDEX_op_mov_i64: -tcg_reg_alloc_mov (s, def, op->args, arg_life); +tcg_reg_alloc_mov (s, op);break ;case INDEX_op_movi_i32:case INDEX_op_movi_i64: -tcg_reg_alloc_movi (s, op->args, arg_life); +tcg_reg_alloc_movi (s, op);break ;case INDEX_op_insn_start:if (num_insns >=0 ) {
@@ -2878,7 +2880,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)tcg_out_label (s,arg_label (op->args[0 ]), s->code_ptr);break ;case INDEX_op_call: -tcg_reg_alloc_call (s, op->callo, op->calli, op->args, arg_life); +tcg_reg_alloc_call (s, op);break ;default :/* Sanity check that we've not introduced any unhandled opcodes. */
@@ -2886,7 +2888,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)/* Note: in order to speed up the code, it would be much faster to have specialized register allocator functions for some common argument patterns */ -tcg_reg_alloc_op (s, def, opc, op->args, arg_life); +tcg_reg_alloc_op (s, op);break ; }#ifdef CONFIG_DEBUG_TCG
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 04/50] tcg: Propagate TCGOp down to allocators
Quoted 4 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 5/50 tcg: Introduce arg_temp
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.h | 5 +++++ tcg/optimize.c | 4 ++-- tcg/tcg.c | 51 +++++++++++++++++++++++++-------------------------- 3 files changed, 32 insertions(+), 28 deletions(-)
tcg/tcg.h +5 -0
@@ -725,6 +725,11 @@ struct TCGContext {extern TCGContext tcg_ctx;extern bool parallel_cpus; +static inline TCGTemp *arg_temp (TCGArg a) +{ +return &tcg_ctx.temps[a]; +} +static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v) { tcg_ctx.gen_op_buf[op_idx].args[arg] = v;
tcg/optimize.c +2 -2
@@ -133,7 +133,7 @@ static TCGArg find_better_copy(TCGContext *s, TCGArg temp) }/* If it is a temp, search for a temp local. */ -if (!s->temps[temp].temp_local) { +if (!arg_temp (temp)->temp_local) {for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) {if (s->temps[i].temp_local) {return i;
@@ -207,7 +207,7 @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) } temps[dst].mask = mask; -if (s->temps[src].type == s->temps[dst].type) { +if (arg_temp (src)->type ==arg_temp (dst)->type) { temps[dst].next_copy = temps[src].next_copy; temps[dst].prev_copy = src; temps[temps[dst].next_copy].prev_copy = dst;
tcg/tcg.c +25 -26
164 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 05/50] tcg: Introduce arg_temp
Quoted 4 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 6/50 tcg: Add temp_global bit to TCGTemp
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
This avoids needing to test the index of a temp against nb_globals.
--- tcg/tcg.h | 12 ++++++++---- tcg/optimize.c | 15 ++++++++------- tcg/tcg.c | 11 ++++++++--- 3 files changed, 24 insertions(+), 14 deletions(-)
tcg/tcg.h +8 -4
@@ -579,10 +579,14 @@ typedef struct TCGTemp { unsigned int indirect_base:1; unsigned int mem_coherent:1; unsigned int mem_allocated:1; - unsigned int temp_local:1; /* If true, the temp is saved across -basic blocks. Otherwise, it is not -preserved across basic blocks. */ - unsigned int temp_allocated:1; /* never used for code gen */ +/* If true, the temp is saved across both basic blocks and +translation blocks. */ + unsigned int temp_global:1; +/* If true, the temp is saved across basic blocks but dead +at the end of translation blocks. If false, the temp is +dead at the end of basic blocks. */ + unsigned int temp_local:1; + unsigned int temp_allocated:1;tcg_target_long val;struct TCGTemp *mem_base;
tcg/optimize.c +8 -7
@@ -116,25 +116,26 @@ static TCGOpcode op_to_movi(TCGOpcode op) } } -static TCGArg find_better_copy (TCGContext *s,TCGArg temp) +static TCGArg find_better_copy (TCGContext *s,TCGArg arg) { +TCGTemp *ts =arg_temp (arg);TCGArg i;/* If this is already a global, we can't do better. */ -if (temp < s->nb_globals) { -return temp; +if (ts->temp_global) { +return arg; }/* Search for a global first. */ -for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) { +for (i = temps[arg].next_copy ; i != arg; i = temps[i].next_copy) {if (i < s->nb_globals) {return i; } }/* If it is a temp, search for a temp local. */ -if (!arg_temp (temp)->temp_local) { -for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) { +if (!ts->temp_local) { +for (i = temps[arg].next_copy ; i != arg; i = temps[i].next_copy) {if (s->temps[i].temp_local) {return i; }
@@ -142,7 +143,7 @@ static TCGArg find_better_copy(TCGContext *s, TCGArg temp) }/* Failure to find a better representation, return the same temp. */ -return temp; +return arg; }static bool temps_are_copies (TCGArg arg1,TCGArg arg2)
tcg/tcg.c +8 -3
@@ -489,9 +489,14 @@ static inline TCGTemp *tcg_temp_alloc(TCGContext *s)static inline TCGTemp *tcg_global_alloc (TCGContext *s) { +TCGTemp *ts; +tcg_debug_assert (s->nb_globals == s->nb_temps); s->nb_globals++; -return tcg_temp_alloc (s); + ts =tcg_temp_alloc (s); + ts->temp_global =1 ; + +return ts; } static int tcg_global_reg_new_internal(TCGContext *s, TCGType type,
@@ -1190,7 +1195,7 @@ static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size, {int idx =temp_idx (s, ts); -if (idx < s->nb_globals) { +if (ts->temp_global) {pstrcpy (buf, buf_size, ts->name); }else if (ts->temp_local) {snprintf (buf, buf_size,"loc%d" , idx - s->nb_globals);
@@ -2128,7 +2133,7 @@ static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead) } ts->val_type = (free_or_dead <0 || ts->temp_local - ||temp_idx (s, ts) < s->nb_globals + || ts->temp_global ?TEMP_VAL_MEM :TEMP_VAL_DEAD ); }
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 06/50] tcg: Add temp_global bit to TCGTemp
Quoted 5 lines · Richard Henderson
From: Richard Henderson <[email protected]>
This avoids needing to test the index of a temp against
nb_globals.Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 7/50 tcg: Return NULL temp for TCG_CALL_DUMMY_ARG
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/tcg.h +1 -1
@@ -731,7 +731,7 @@ extern bool parallel_cpus;static inline TCGTemp *arg_temp (TCGArg a) { -return &tcg_ctx.temps[a]; +return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a]; }static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v)
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 07/50] tcg: Return NULL temp for TCG_CALL_DUMMY_ARG
Quoted 12 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tcg/tcg.h +0
-0
tcg/tcg.h extern bool parallel_cpus; · line 735
Quoted 6 lines
tcg/tcg.h +1
-1@@ -731,7 +731,7 @@ extern bool parallel_cpus;static inline TCGTemp *arg_temp (TCGArg a) { -return &tcg_ctx.temps[a]; +return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a]; }
E.
PATCH v6 8/50 tcg: Introduce temp_arg
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.h | 7 +++++++ tcg/tcg.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-)
tcg/tcg.h +7 -0
@@ -729,6 +729,13 @@ struct TCGContext {extern TCGContext tcg_ctx;extern bool parallel_cpus; +static inline TCGArg temp_arg (TCGTemp *ts) +{ +ptrdiff_t n = ts - tcg_ctx.temps; +tcg_debug_assert (n >=0 && n < tcg_ctx.nb_temps); +return n; +} +static inline TCGTemp *arg_temp (TCGArg a) {return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a];
tcg/tcg.c +2 -2
@@ -1941,7 +1941,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)TCGOp *lop =tcg_op_insert_before (s, op, lopc,3 ); lop->args[0 ] = dir; - lop->args[1 ] =temp_idx (s, its->mem_base); + lop->args[1 ] =temp_arg (its->mem_base); lop->args[2 ] = its->mem_offset;/* Loaded, but synced with memory. */
@@ -2012,7 +2012,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)TCGOp *sop =tcg_op_insert_after (s, op, sopc,3 ); sop->args[0 ] = dir; - sop->args[1 ] =temp_idx (s, its->mem_base); + sop->args[1 ] =temp_arg (its->mem_base); sop->args[2 ] = its->mem_offset; temp_state[arg] =TS_MEM ;
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 08/50] tcg: Introduce temp_arg
Quoted 3 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Signed-off-by Richard Henderson <[email protected]>
I'd consider combining this patch with the "Export temp_idx" one.
E.
PATCH v6 9/50 tcg: Use per-temp state data in liveness
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
This avoids having to allocate external memory for each temporary.
--- tcg/tcg.h | 6 ++ tcg/tcg.c | 225 ++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 122 insertions(+), 109 deletions(-)
tcg/tcg.h +6 -0
@@ -592,6 +592,12 @@ typedef struct TCGTemp {struct TCGTemp *mem_base;intptr_t mem_offset;const char *name; + +/* Pass-specific information that can be stored for a temporary. +One word worth of integer data, and one pointer to data +allocated separately. */ +uintptr_t state; +void *state_ptr; } TCGTemp;typedef struct TCGContext TCGContext ;
tcg/tcg.c +116 -109
429 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 09/50] tcg: Use per-temp state data in liveness
Quoted 6 lines · Richard Henderson
From: Richard Henderson <[email protected]>
This avoids having to allocate external memory for each temporary.
Signed-off-by Richard Henderson <[email protected]>---
Unfortunately, this patch undoes the small perf gains we made so far in this series.
We end up running more instructions, I guess due to the loops in setting the per-temp states (whereas earlier we just had a memset). Same aarch64 boot benchmark, 10 runs:
Before:
7125.400889 task-clock (msec) # 0.998 CPUs utilized ( +- 0.15% )
21,654 context-switches # 0.003 M/sec ( +- 0.12% )
1 cpu-migrations # 0.000 K/sec
8,034 page-faults # 0.001 M/sec ( +- 1.22% )
30,050,759,263 cycles # 4.217 GHz ( +- 0.15% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
53,764,201,351 instructions # 1.79 insns per cycle ( +- 0.09% )
9,677,042,191 branches # 1358.105 M/sec ( +- 0.09% )
170,903,903 branch-misses # 1.77% of all branches ( +- 0.16% )7.136617151 seconds time elapsed ( +- 0.17% )
After:
7326.945822 task-clock (msec) # 0.999 CPUs utilized ( +- 0.24% )
21,997 context-switches # 0.003 M/sec ( +- 0.16% )
1 cpu-migrations # 0.000 K/sec
8,400 page-faults # 0.001 M/sec ( +- 4.63% )
30,900,509,346 cycles # 4.217 GHz ( +- 0.23% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
55,736,672,258 instructions # 1.80 insns per cycle ( +- 0.16% )
9,989,723,969 branches # 1363.423 M/sec ( +- 0.16% )
179,662,782 branch-misses # 1.80% of all branches ( +- 0.16% )7.335805286 seconds time elapsed ( +- 0.24% )
I tried merging .state into the bitfield, but that didn't help (the dcache isn't the issue here).
Anyway we use .state_ptr later in this series, so:
E.
PATCH v6 10/50 tcg: Avoid loops against variable bounds
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
Copy s->nb_globals or s->nb_temps to a local variable for the purposes of iteration. This should allow the compiler to use low-overhead looping constructs on some hosts.
--- tcg/tcg.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
tcg/tcg.c +10 -17
@@ -1166,23 +1166,16 @@ void tcg_gen_callN(TCGContext *s, void *func, TCGArg ret,static void tcg_reg_alloc_start (TCGContext *s) { -int i; +int i, n;TCGTemp *ts; -for (i =0 ; i < s->nb_globals; i++) { + +for (i =0 , n = s->nb_globals; i < n; i++) { ts = &s->temps[i]; -if (ts->fixed_reg) { - ts->val_type =TEMP_VAL_REG ; - }else { - ts->val_type =TEMP_VAL_MEM ; - } + ts->val_type = (ts->fixed_reg ?TEMP_VAL_REG :TEMP_VAL_MEM ); } -for (i = s->nb_globals; i < s->nb_temps; i++) { +for (n = s->nb_temps; i < n; i++) { ts = &s->temps[i]; -if (ts->temp_local) { - ts->val_type =TEMP_VAL_MEM ; - }else { - ts->val_type =TEMP_VAL_DEAD ; - } + ts->val_type = (ts->temp_local ?TEMP_VAL_MEM :TEMP_VAL_DEAD ); ts->mem_allocated =0 ; ts->fixed_reg =0 ; }
@@ -2284,9 +2277,9 @@ static void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs)temporary registers needs to be allocated to store a constant. */ static void save_globals (TCGContext *s,TCGRegSet allocated_regs) { -int i; +int i, n; -for (i =0 ; i < s->nb_globals; i++) { +for (i =0 , n = s->nb_globals; i < n; i++) {temp_save (s, &s->temps[i], allocated_regs); } }
@@ -2296,9 +2289,9 @@ static void save_globals(TCGContext *s, TCGRegSet allocated_regs)temporary registers needs to be allocated to store a constant. */ static void sync_globals (TCGContext *s,TCGRegSet allocated_regs) { -int i; +int i, n; -for (i =0 ; i < s->nb_globals; i++) { +for (i =0 , n = s->nb_globals; i < n; i++) {TCGTemp *ts = &s->temps[i];tcg_debug_assert (ts->val_type !=TEMP_VAL_REG || ts->fixed_reg
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 10/50] tcg: Avoid loops against variable bounds
Quoted 8 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Copy
s->nb_globalsors->nb_tempsto a local variable for the purposes of iteration. This should allow the compiler to use low-overhead looping constructs on some hosts.Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
FWIW on a Skylake host I couldn't measure a difference. However, the generated code is indeed slightly different.
E.
Re: [Qemu-devel] [PATCH v6 10/50] tcg: Avoid loops against variable bounds
Quoted 7 lines · Emilio G. Cota
Quoted 6 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Copy
s->nb_globalsors->nb_tempsto a local variable for the purposes of iteration. This should allow the compiler to use low-overhead looping constructs on some hosts.
Quoted 7 lines
Quoted 2 lines
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>Reviewed-by Emilio G. Cota <[email protected]>FWIW on a Skylake host I couldn't measure a difference. However, the generated code is indeed slightly different.
I wouldn't expect so. Low-overhead loops are more of a ppc thing.
r~
PATCH v6 11/50 tcg: Change temp_allocate_frame arg to TCGTemp
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
tcg/tcg.c +3 -5
@@ -2103,10 +2103,8 @@ static void check_regs(TCGContext *s) }#endif -static void temp_allocate_frame (TCGContext *s,int temp) +static void temp_allocate_frame (TCGContext *s,TCGTemp *ts) { -TCGTemp *ts; - ts = &s->temps[temp];#if !(defined(__sparc__) &&TCG_TARGET_REG_BITS ==64 )/* Sparc64 stack is accessed with offset of 2047 */ s->current_frame_offset = (s->current_frame_offset +
@@ -2159,7 +2157,7 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, }if (!ts->mem_coherent) {if (!ts->mem_allocated) { -temp_allocate_frame (s,temp_idx (s, ts)); +temp_allocate_frame (s, ts); }switch (ts->val_type) {case TEMP_VAL_CONST :
@@ -2389,7 +2387,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)liveness analysis disabled). */ tcg_debug_assert (NEED_SYNC_ARG (0 ));if (!ots->mem_allocated) { -temp_allocate_frame (s, op->args[0 ]); +temp_allocate_frame (s, ots); }tcg_out_st (s, otype, ts->reg, ots->mem_base->reg, ots->mem_offset);if (IS_DEAD_ARG (1 )) {
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 11/50] tcg: Change temp_allocate_frame arg to TCGTemp
Quoted 3 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 12/50 tcg: Remove unused TCG_CALL_DUMMY_TCGV
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- tcg/tcg.h | 1 - 1 file changed, 1 deletion(-)
tcg/tcg.h +0 -1
@@ -496,7 +496,6 @@ static inline intptr_t QEMU_ARTIFICIAL GET_TCGV_PTR(TCGv_ptr t)#define TCG_CALL_NO_WG_SE (TCG_CALL_NO_WG | TCG_CALL_NO_SE)/* used to align parameters */ -#define TCG_CALL_DUMMY_TCGV MAKE_TCGV_I32(-1)#define TCG_CALL_DUMMY_ARG ((TCGArg)(-1))/* Conditions. Note that these are laid out for easy manipulation by
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 12/50] tcg: Remove unused TCG_CALL_DUMMY_TCGV
Quoted 4 lines · Richard Henderson
From: Richard Henderson <[email protected]>
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 13/50 tcg: Export temp_idx
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
At the same time, drop the TCGContext argument and use tcg_ctx instead.
--- tcg/tcg.h | 7 ++++++- tcg/tcg.c | 15 ++++----------- 2 files changed, 10 insertions(+), 12 deletions(-)
tcg/tcg.h +6 -1
@@ -734,13 +734,18 @@ struct TCGContext {extern TCGContext tcg_ctx;extern bool parallel_cpus; -static inline TCGArg temp_arg (TCGTemp *ts) +static inline size_t temp_idx (TCGTemp *ts) {ptrdiff_t n = ts - tcg_ctx.temps;tcg_debug_assert (n >=0 && n < tcg_ctx.nb_temps);return n; } +static inline TCGArg temp_arg (TCGTemp *ts) +{ +return temp_idx (ts); +} +static inline TCGTemp *arg_temp (TCGArg a) {return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a];
tcg/tcg.c +4 -11
@@ -473,13 +473,6 @@ void tcg_func_start(TCGContext *s) s->gen_next_op_idx =1 ; } -static inline int temp_idx (TCGContext *s,TCGTemp *ts) -{ -ptrdiff_t n = ts - s->temps; -tcg_debug_assert (n >=0 && n < s->nb_temps); -return n; -} -static inline TCGTemp *tcg_temp_alloc (TCGContext *s) {int n = s->nb_temps++;
@@ -516,7 +509,7 @@ static int tcg_global_reg_new_internal(TCGContext *s, TCGType type, ts->name = name;tcg_regset_set_reg (s->reserved_regs, reg); -return temp_idx (s, ts); +return temp_idx (ts); }void tcg_set_frame (TCGContext *s,TCGReg reg,intptr_t start,intptr_t size)
@@ -605,7 +598,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, ts->mem_offset = offset; ts->name = name; } -return temp_idx (s, ts); +return temp_idx (ts); }static int tcg_temp_new_internal (TCGType type,int temp_local)
@@ -645,7 +638,7 @@ static int tcg_temp_new_internal(TCGType type, int temp_local) ts->temp_allocated =1 ; ts->temp_local = temp_local; } - idx =temp_idx (s, ts); + idx =temp_idx (ts); }#if defined(CONFIG_DEBUG_TCG )
@@ -1186,7 +1179,7 @@ static void tcg_reg_alloc_start(TCGContext *s)static char *tcg_get_arg_str_ptr (TCGContext *s,char *buf,int buf_size,TCGTemp *ts) { -int idx =temp_idx (s, ts); +int idx =temp_idx (ts);if (ts->temp_global) {pstrcpy (buf, buf_size, ts->name);
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 13/50] tcg: Export temp_idx
Quoted 5 lines · Richard Henderson
From: Richard Henderson <[email protected]>
At the same time, drop the TCGContext argument and use
tcg_ctxinstead.Signed-off-by Richard Henderson <[email protected]>
As I said earlier I'd combine this with the temp_arg patch. But even without that change:
E.
PATCH v6 14/50 tcg: Use per-temp state data in optimize
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
While we're touching many of the lines anyway, adjust the naming of the functions to better distinguish when "TCGArg" vs "TCGTemp" should be used.
--- tcg/tcg.h | 5 + tcg/optimize.c | 430 +++++++++++++++++++++++++++++++++------------------------ 2 files changed, 252 insertions(+), 183 deletions(-)
tcg/tcg.h +5 -0
@@ -751,6 +751,11 @@ static inline TCGTemp *arg_temp(TCGArg a)return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a]; } +static inline size_t arg_index (TCGArg a) +{ +return a; +} +static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v) { tcg_ctx.gen_op_buf[op_idx].args[arg] = v;
tcg/optimize.c +247 -183
843 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 14/50] tcg: Use per-temp state data in optimize
Quoted 7 lines · Richard Henderson
From: Richard Henderson <[email protected]>
While we're touching many of the lines anyway, adjust the naming of the functions to better distinguish when "TCGArg" vs "TCGTemp" should be used.
Signed-off-by Richard Henderson <[email protected]>
(snip)
tcg/optimize.c line 43
Quoted 2 lines
tcg/optimize.c +1
-1-static struct tcg_temp_info temps[TCG_MAX_TEMPS ]; +static struct tcg_temp_info temps_[TCG_MAX_TEMPS ];
Is this rename really necessary?
The rest looks good:
E.
Re: [Qemu-devel] [PATCH v6 14/50] tcg: Use per-temp state data in optimize
Quoted 7 lines · Emilio G. Cota
Quoted 6 lines · Richard Henderson
From: Richard Henderson <[email protected]>
While we're touching many of the lines anyway, adjust the naming of the functions to better distinguish when "TCGArg" vs "TCGTemp" should be used.
Quoted 6 lines
Quoted 1 line
Signed-off-by Richard Henderson <[email protected]>(snip)
tcg/optimize.c line 43
Quoted 2 lines
tcg/optimize.c +1
-1-static struct tcg_temp_info temps[TCG_MAX_TEMPS ]; +static struct tcg_temp_info temps_[TCG_MAX_TEMPS ];Is this rename really necessary?
It was a temp rename to ensure that all changes were made. The variable disappears later.
r~
PATCH v6 15/50 tcg: Push tcg_ctx into generator functions
In reply to Richard Henderson--- tcg/tcg-op.h | 100 +++++++++++++++++++++++++++-------------------------------- tcg/tcg-op.c | 47 ++++++++++++++-------------- 2 files changed, 69 insertions(+), 78 deletions(-)
tcg/tcg-op.h +46 -54
@@ -28,173 +28,166 @@/* Basic output routines. Not for general consumption. */ -void tcg_gen_op1 (TCGContext *,TCGOpcode ,TCGArg ); -void tcg_gen_op2 (TCGContext *,TCGOpcode ,TCGArg ,TCGArg ); -void tcg_gen_op3 (TCGContext *,TCGOpcode ,TCGArg ,TCGArg ,TCGArg ); -void tcg_gen_op4 (TCGContext *,TCGOpcode ,TCGArg ,TCGArg ,TCGArg ,TCGArg ); -void tcg_gen_op5 (TCGContext *,TCGOpcode ,TCGArg ,TCGArg ,TCGArg , -TCGArg ,TCGArg ); -void tcg_gen_op6 (TCGContext *,TCGOpcode ,TCGArg ,TCGArg ,TCGArg , -TCGArg ,TCGArg ,TCGArg ); - +void tcg_gen_op1 (TCGOpcode ,TCGArg ); +void tcg_gen_op2 (TCGOpcode ,TCGArg ,TCGArg ); +void tcg_gen_op3 (TCGOpcode ,TCGArg ,TCGArg ,TCGArg ); +void tcg_gen_op4 (TCGOpcode ,TCGArg ,TCGArg ,TCGArg ,TCGArg ); +void tcg_gen_op5 (TCGOpcode ,TCGArg ,TCGArg ,TCGArg ,TCGArg ,TCGArg ); +void tcg_gen_op6 (TCGOpcode ,TCGArg ,TCGArg ,TCGArg ,TCGArg ,TCGArg ,TCGArg );static inline void tcg_gen_op1_i32 (TCGOpcode opc,TCGv_i32 a1) { -tcg_gen_op1 (&tcg_ctx, opc,GET_TCGV_I32 (a1)); +tcg_gen_op1 (opc,GET_TCGV_I32 (a1)); }static inline void tcg_gen_op1_i64 (TCGOpcode opc,TCGv_i64 a1) { -tcg_gen_op1 (&tcg_ctx, opc,GET_TCGV_I64 (a1)); +tcg_gen_op1 (opc,GET_TCGV_I64 (a1)); }static inline void tcg_gen_op1i (TCGOpcode opc,TCGArg a1) { -tcg_gen_op1 (&tcg_ctx, opc, a1); +tcg_gen_op1 (opc, a1); }static inline void tcg_gen_op2_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2) { -tcg_gen_op2 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2)); +tcg_gen_op2 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2)); }static inline void tcg_gen_op2_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2) { -tcg_gen_op2 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2)); +tcg_gen_op2 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2)); }static inline void tcg_gen_op2i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGArg a2) { -tcg_gen_op2 (&tcg_ctx, opc,GET_TCGV_I32 (a1), a2); +tcg_gen_op2 (opc,GET_TCGV_I32 (a1), a2); }static inline void tcg_gen_op2i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGArg a2) { -tcg_gen_op2 (&tcg_ctx, opc,GET_TCGV_I64 (a1), a2); +tcg_gen_op2 (opc,GET_TCGV_I64 (a1), a2); }static inline void tcg_gen_op2ii (TCGOpcode opc,TCGArg a1,TCGArg a2) { -tcg_gen_op2 (&tcg_ctx, opc, a1, a2); +tcg_gen_op2 (opc, a1, a2); }static inline void tcg_gen_op3_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I32 (a1), -GET_TCGV_I32 (a2),GET_TCGV_I32 (a3)); +tcg_gen_op3 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3)); }static inline void tcg_gen_op3_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I64 (a1), -GET_TCGV_I64 (a2),GET_TCGV_I64 (a3)); +tcg_gen_op3 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3)); }static inline void tcg_gen_op3i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGArg a3) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3); +tcg_gen_op3 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3); }static inline void tcg_gen_op3i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGArg a3) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3); +tcg_gen_op3 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3); }static inline void tcg_gen_ldst_op_i32 (TCGOpcode opc,TCGv_i32 val,TCGv_ptr base,TCGArg offset) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I32 (val),GET_TCGV_PTR (base), offset); +tcg_gen_op3 (opc,GET_TCGV_I32 (val),GET_TCGV_PTR (base), offset); }static inline void tcg_gen_ldst_op_i64 (TCGOpcode opc,TCGv_i64 val,TCGv_ptr base,TCGArg offset) { -tcg_gen_op3 (&tcg_ctx, opc,GET_TCGV_I64 (val),GET_TCGV_PTR (base), offset); +tcg_gen_op3 (opc,GET_TCGV_I64 (val),GET_TCGV_PTR (base), offset); }static inline void tcg_gen_op4_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), +tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3),GET_TCGV_I32 (a4)); }static inline void tcg_gen_op4_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), +tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3),GET_TCGV_I64 (a4)); }static inline void tcg_gen_op4i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGArg a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3), a4); +tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3), a4); }static inline void tcg_gen_op4i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGArg a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3), a4); +tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3), a4); }static inline void tcg_gen_op4ii_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGArg a3,TCGArg a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3, a4); +tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3, a4); }static inline void tcg_gen_op4ii_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGArg a3,TCGArg a4) { -tcg_gen_op4 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3, a4); +tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3, a4); }static inline void tcg_gen_op5_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGv_i32 a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), +tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3),GET_TCGV_I32 (a4),GET_TCGV_I32 (a5)); }static inline void tcg_gen_op5_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGv_i64 a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), +tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3),GET_TCGV_I64 (a4),GET_TCGV_I64 (a5)); }static inline void tcg_gen_op5i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGArg a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), +tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3),GET_TCGV_I32 (a4), a5); }static inline void tcg_gen_op5i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGArg a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), +tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3),GET_TCGV_I64 (a4), a5); }static inline void tcg_gen_op5ii_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGArg a4,TCGArg a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), +tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3), a4, a5); }static inline void tcg_gen_op5ii_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGArg a4,TCGArg a5) { -tcg_gen_op5 (&tcg_ctx, opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), +tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3), a4, a5); }
@@ -202,7 +195,7 @@ static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2, TCGv_i32 a3, TCGv_i32 a4, TCGv_i32 a5, TCGv_i32 a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I32(a1), GET_TCGV_I32(a2), +tcg_gen_op6 (opc ,GET_TCGV_I32 (a1 ),GET_TCGV_I32 (a2 ),GET_TCGV_I32 (a3 ),GET_TCGV_I32 (a4 ),GET_TCGV_I32 (a5 ),GET_TCGV_I32 (a6 )); }
@@ -211,7 +204,7 @@ static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2, TCGv_i64 a3, TCGv_i64 a4, TCGv_i64 a5, TCGv_i64 a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I64(a1), GET_TCGV_I64(a2), +tcg_gen_op6 (opc ,GET_TCGV_I64 (a1 ),GET_TCGV_I64 (a2 ),GET_TCGV_I64 (a3 ),GET_TCGV_I64 (a4 ),GET_TCGV_I64 (a5 ),GET_TCGV_I64 (a6 )); }
@@ -220,7 +213,7 @@ static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2, TCGv_i32 a3, TCGv_i32 a4, TCGv_i32 a5, TCGArg a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I32(a1), GET_TCGV_I32(a2), +tcg_gen_op6 (opc ,GET_TCGV_I32 (a1 ),GET_TCGV_I32 (a2 ),GET_TCGV_I32 (a3 ),GET_TCGV_I32 (a4 ),GET_TCGV_I32 (a5 ),a6 ); }
@@ -228,7 +221,7 @@ static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2, TCGv_i64 a3, TCGv_i64 a4, TCGv_i64 a5, TCGArg a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I64(a1), GET_TCGV_I64(a2), +tcg_gen_op6 (opc ,GET_TCGV_I64 (a1 ),GET_TCGV_I64 (a2 ),GET_TCGV_I64 (a3 ),GET_TCGV_I64 (a4 ),GET_TCGV_I64 (a5 ),a6 ); }
@@ -236,7 +229,7 @@ static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2, TCGv_i32 a3, TCGv_i32 a4, TCGArg a5, TCGArg a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I32(a1), GET_TCGV_I32(a2), +tcg_gen_op6 (opc ,GET_TCGV_I32 (a1 ),GET_TCGV_I32 (a2 ),GET_TCGV_I32 (a3 ),GET_TCGV_I32 (a4 ),a5 ,a6 ); }
@@ -244,7 +237,7 @@ static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2, TCGv_i64 a3, TCGv_i64 a4, TCGArg a5, TCGArg a6) { - tcg_gen_op6(&tcg_ctx, opc, GET_TCGV_I64(a1), GET_TCGV_I64(a2), +tcg_gen_op6 (opc ,GET_TCGV_I64 (a1 ),GET_TCGV_I64 (a2 ),GET_TCGV_I64 (a3 ),GET_TCGV_I64 (a4 ),a5 ,a6 ); }
@@ -253,12 +246,12 @@ static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,static inline void gen_set_label (TCGLabel *l) { -tcg_gen_op1 (&tcg_ctx, INDEX_op_set_label,label_arg (l)); +tcg_gen_op1 (INDEX_op_set_label,label_arg (l)); }static inline void tcg_gen_br (TCGLabel *l) { -tcg_gen_op1 (&tcg_ctx, INDEX_op_br,label_arg (l)); +tcg_gen_op1 (INDEX_op_br,label_arg (l)); }void tcg_gen_mb (TCGBar );
@@ -732,25 +725,24 @@ static inline void tcg_gen_concat32_i64(TCGv_i64 ret, TCGv_i64 lo, TCGv_i64 hi)# if TARGET_LONG_BITS <=TCG_TARGET_REG_BITS static inline void tcg_gen_insn_start (target_ulong pc) { -tcg_gen_op1 (&tcg_ctx, INDEX_op_insn_start, pc); +tcg_gen_op1 (INDEX_op_insn_start, pc); }# else static inline void tcg_gen_insn_start (target_ulong pc) { -tcg_gen_op2 (&tcg_ctx, INDEX_op_insn_start, - (uint32_t )pc, (uint32_t )(pc >>32 )); +tcg_gen_op2 (INDEX_op_insn_start, (uint32_t )pc, (uint32_t )(pc >>32 )); }# endif #elif TARGET_INSN_START_WORDS ==2 # if TARGET_LONG_BITS <=TCG_TARGET_REG_BITS static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1) { -tcg_gen_op2 (&tcg_ctx, INDEX_op_insn_start, pc, a1); +tcg_gen_op2 (INDEX_op_insn_start, pc, a1); }# else static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1) { -tcg_gen_op4 (&tcg_ctx, INDEX_op_insn_start, +tcg_gen_op4 (INDEX_op_insn_start, (uint32_t )pc, (uint32_t )(pc >>32 ), (uint32_t )a1, (uint32_t )(a1 >>32 )); }
@@ -760,13 +752,13 @@ static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1)static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1,target_ulong a2) { -tcg_gen_op3 (&tcg_ctx, INDEX_op_insn_start, pc, a1, a2); +tcg_gen_op3 (INDEX_op_insn_start, pc, a1, a2); }# else static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1,target_ulong a2) { -tcg_gen_op6 (&tcg_ctx, INDEX_op_insn_start, +tcg_gen_op6 (INDEX_op_insn_start, (uint32_t )pc, (uint32_t )(pc >>32 ), (uint32_t )a1, (uint32_t )(a1 >>32 ), (uint32_t )a2, (uint32_t )(a2 >>32 ));
tcg/tcg-op.c +23 -24
132 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 15/50] tcg: Push tcg_ctx into generator functions
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 16/50 tcg: Push tcg_ctx into tcg_gen_callN
In reply to Richard Henderson--- include/exec/helper-gen.h | 12 ++++++------ tcg/tcg.h | 3 +-- tcg/tcg.c | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-)
include/exec/helper-gen.h +6 -6
@@ -9,7 +9,7 @@#define DEF_HELPER_FLAGS_0 (name, flags, ret) \ static inline void glue(gen_helper_, name)(dh_retvar_decl0(ret)) \ { \ - tcg_gen_callN(&tcg_ctx, HELPER(name), dh_retvar(ret), 0, NULL); \ + tcg_gen_callN(HELPER(name), dh_retvar(ret), 0, NULL); \ }#define DEF_HELPER_FLAGS_1 (name, flags, ret, t1) \
@@ -17,7 +17,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1)) \ { \TCGArg args[1 ] = {dh_arg (t1,1 ) }; \ -tcg_gen_callN (&tcg_ctx,HELPER (name),dh_retvar (ret),1 , args); \ +tcg_gen_callN (HELPER (name),dh_retvar (ret),1 , args); \ }#define DEF_HELPER_FLAGS_2 (name, flags, ret, t1, t2) \
@@ -25,7 +25,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2)) \ { \TCGArg args[2 ] = {dh_arg (t1,1 ),dh_arg (t2,2 ) }; \ -tcg_gen_callN (&tcg_ctx,HELPER (name),dh_retvar (ret),2 , args); \ +tcg_gen_callN (HELPER (name),dh_retvar (ret),2 , args); \ }#define DEF_HELPER_FLAGS_3 (name, flags, ret, t1, t2, t3) \
@@ -33,7 +33,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3)) \ { \TCGArg args[3 ] = {dh_arg (t1,1 ),dh_arg (t2,2 ),dh_arg (t3,3 ) }; \ -tcg_gen_callN (&tcg_ctx,HELPER (name),dh_retvar (ret),3 , args); \ +tcg_gen_callN (HELPER (name),dh_retvar (ret),3 , args); \ }#define DEF_HELPER_FLAGS_4 (name, flags, ret, t1, t2, t3, t4) \
@@ -43,7 +43,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ { \TCGArg args[4 ] = {dh_arg (t1,1 ),dh_arg (t2,2 ), \dh_arg (t3,3 ),dh_arg (t4,4 ) }; \ -tcg_gen_callN (&tcg_ctx,HELPER (name),dh_retvar (ret),4 , args); \ +tcg_gen_callN (HELPER (name),dh_retvar (ret),4 , args); \ }#define DEF_HELPER_FLAGS_5 (name, flags, ret, t1, t2, t3, t4, t5) \
@@ -53,7 +53,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ { \TCGArg args[5 ] = {dh_arg (t1,1 ),dh_arg (t2,2 ),dh_arg (t3,3 ), \dh_arg (t4,4 ),dh_arg (t5,5 ) }; \ -tcg_gen_callN (&tcg_ctx,HELPER (name),dh_retvar (ret),5 , args); \ +tcg_gen_callN (HELPER (name),dh_retvar (ret),5 , args); \ }#include "helper.h"
tcg/tcg.h +1 -2
@@ -951,8 +951,7 @@ do {\bool tcg_op_supported (TCGOpcode op); -void tcg_gen_callN (TCGContext *s,void *func, -TCGArg ret,int nargs,TCGArg *args); +void tcg_gen_callN (void *func,TCGArg ret,int nargs,TCGArg *args);void tcg_op_remove (TCGContext *s,TCGOp *op);TCGOp *tcg_op_insert_before (TCGContext *s,TCGOp *op,TCGOpcode opc,int narg);
tcg/tcg.c +2 -2
@@ -974,9 +974,9 @@ bool tcg_op_supported(TCGOpcode op)/* Note: we convert the 64 bit args to 32 bit and do some alignment and endian swap. Maybe it would be better to do the alignment and endian swap in tcg_reg_alloc_call(). */ -void tcg_gen_callN (TCGContext *s,void *func,TCGArg ret, -int nargs,TCGArg *args) +void tcg_gen_callN (void *func,TCGArg ret,int nargs,TCGArg *args) { +TCGContext *s = &tcg_ctx;int i, real_args, nb_rets, pi;unsigned sizemask, flags;TCGHelperInfo *info;
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 16/50] tcg: Push tcg_ctx into tcg_gen_callN
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 17/50 tcg: Introduce index_arg
In reply to Richard HendersonFor multi-threaded tcg we have one TCGContext per thread. With that, plus static cpu_* variables, we need the translators to handle indicies. We transform those to "arguments" at opcode generating time.
For now, that transformation is a no-op.
--- tcg/tcg-op.h | 92 ++++++++++++++++++++++++++++++------------------------------ tcg/tcg.h | 20 +++++++++++++ tcg/tcg-op.c | 14 ++++----- tcg/tcg.c | 26 ++++++++--------- 4 files changed, 86 insertions(+), 66 deletions(-)
tcg/tcg-op.h +46 -46
@@ -37,12 +37,12 @@ void tcg_gen_op6(TCGOpcode, TCGArg, TCGArg, TCGArg, TCGArg, TCGArg, TCGArg);static inline void tcg_gen_op1_i32 (TCGOpcode opc,TCGv_i32 a1) { -tcg_gen_op1 (opc,GET_TCGV_I32 (a1)); +tcg_gen_op1 (opc,tcgv_i32_arg (a1)); }static inline void tcg_gen_op1_i64 (TCGOpcode opc,TCGv_i64 a1) { -tcg_gen_op1 (opc,GET_TCGV_I64 (a1)); +tcg_gen_op1 (opc,tcgv_i64_arg (a1)); }static inline void tcg_gen_op1i (TCGOpcode opc,TCGArg a1)
@@ -52,22 +52,22 @@ static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg a1)static inline void tcg_gen_op2_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2) { -tcg_gen_op2 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2)); +tcg_gen_op2 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2)); }static inline void tcg_gen_op2_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2) { -tcg_gen_op2 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2)); +tcg_gen_op2 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2)); }static inline void tcg_gen_op2i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGArg a2) { -tcg_gen_op2 (opc,GET_TCGV_I32 (a1), a2); +tcg_gen_op2 (opc,tcgv_i32_arg (a1), a2); }static inline void tcg_gen_op2i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGArg a2) { -tcg_gen_op2 (opc,GET_TCGV_I64 (a1), a2); +tcg_gen_op2 (opc,tcgv_i64_arg (a1), a2); }static inline void tcg_gen_op2ii (TCGOpcode opc,TCGArg a1,TCGArg a2)
@@ -78,167 +78,167 @@ static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg a1, TCGArg a2)static inline void tcg_gen_op3_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3) { -tcg_gen_op3 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3)); +tcg_gen_op3 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2),tcgv_i32_arg (a3)); }static inline void tcg_gen_op3_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3) { -tcg_gen_op3 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3)); +tcg_gen_op3 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2),tcgv_i64_arg (a3)); }static inline void tcg_gen_op3i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGArg a3) { -tcg_gen_op3 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3); +tcg_gen_op3 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), a3); }static inline void tcg_gen_op3i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGArg a3) { -tcg_gen_op3 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3); +tcg_gen_op3 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), a3); }static inline void tcg_gen_ldst_op_i32 (TCGOpcode opc,TCGv_i32 val,TCGv_ptr base,TCGArg offset) { -tcg_gen_op3 (opc,GET_TCGV_I32 (val),GET_TCGV_PTR (base), offset); +tcg_gen_op3 (opc,tcgv_i32_arg (val),tcgv_ptr_arg (base), offset); }static inline void tcg_gen_ldst_op_i64 (TCGOpcode opc,TCGv_i64 val,TCGv_ptr base,TCGArg offset) { -tcg_gen_op3 (opc,GET_TCGV_I64 (val),GET_TCGV_PTR (base), offset); +tcg_gen_op3 (opc,tcgv_i64_arg (val),tcgv_ptr_arg (base), offset); }static inline void tcg_gen_op4_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4) { -tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4)); +tcg_gen_op4 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4)); }static inline void tcg_gen_op4_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4) { -tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4)); +tcg_gen_op4 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4)); }static inline void tcg_gen_op4i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGArg a4) { -tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2),GET_TCGV_I32 (a3), a4); +tcg_gen_op4 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2),tcgv_i32_arg (a3), a4); }static inline void tcg_gen_op4i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGArg a4) { -tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2),GET_TCGV_I64 (a3), a4); +tcg_gen_op4 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2),tcgv_i64_arg (a3), a4); }static inline void tcg_gen_op4ii_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGArg a3,TCGArg a4) { -tcg_gen_op4 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), a3, a4); +tcg_gen_op4 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), a3, a4); }static inline void tcg_gen_op4ii_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGArg a3,TCGArg a4) { -tcg_gen_op4 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), a3, a4); +tcg_gen_op4 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), a3, a4); }static inline void tcg_gen_op5_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGv_i32 a5) { -tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4),GET_TCGV_I32 (a5)); +tcg_gen_op5 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4),tcgv_i32_arg (a5)); }static inline void tcg_gen_op5_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGv_i64 a5) { -tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4),GET_TCGV_I64 (a5)); +tcg_gen_op5 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4),tcgv_i64_arg (a5)); }static inline void tcg_gen_op5i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGArg a5) { -tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4), a5); +tcg_gen_op5 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4), a5); }static inline void tcg_gen_op5i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGArg a5) { -tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4), a5); +tcg_gen_op5 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4), a5); }static inline void tcg_gen_op5ii_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGArg a4,TCGArg a5) { -tcg_gen_op5 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3), a4, a5); +tcg_gen_op5 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3), a4, a5); }static inline void tcg_gen_op5ii_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGArg a4,TCGArg a5) { -tcg_gen_op5 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3), a4, a5); +tcg_gen_op5 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3), a4, a5); }static inline void tcg_gen_op6_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGv_i32 a5,TCGv_i32 a6) { -tcg_gen_op6 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4),GET_TCGV_I32 (a5), -GET_TCGV_I32 (a6)); +tcg_gen_op6 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4),tcgv_i32_arg (a5), +tcgv_i32_arg (a6)); }static inline void tcg_gen_op6_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGv_i64 a5,TCGv_i64 a6) { -tcg_gen_op6 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4),GET_TCGV_I64 (a5), -GET_TCGV_I64 (a6)); +tcg_gen_op6 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4),tcgv_i64_arg (a5), +tcgv_i64_arg (a6)); }static inline void tcg_gen_op6i_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGv_i32 a5,TCGArg a6) { -tcg_gen_op6 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4),GET_TCGV_I32 (a5), a6); +tcg_gen_op6 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4),tcgv_i32_arg (a5), a6); }static inline void tcg_gen_op6i_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGv_i64 a5,TCGArg a6) { -tcg_gen_op6 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4),GET_TCGV_I64 (a5), a6); +tcg_gen_op6 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4),tcgv_i64_arg (a5), a6); }static inline void tcg_gen_op6ii_i32 (TCGOpcode opc,TCGv_i32 a1,TCGv_i32 a2,TCGv_i32 a3,TCGv_i32 a4,TCGArg a5,TCGArg a6) { -tcg_gen_op6 (opc,GET_TCGV_I32 (a1),GET_TCGV_I32 (a2), -GET_TCGV_I32 (a3),GET_TCGV_I32 (a4), a5, a6); +tcg_gen_op6 (opc,tcgv_i32_arg (a1),tcgv_i32_arg (a2), +tcgv_i32_arg (a3),tcgv_i32_arg (a4), a5, a6); }static inline void tcg_gen_op6ii_i64 (TCGOpcode opc,TCGv_i64 a1,TCGv_i64 a2,TCGv_i64 a3,TCGv_i64 a4,TCGArg a5,TCGArg a6) { -tcg_gen_op6 (opc,GET_TCGV_I64 (a1),GET_TCGV_I64 (a2), -GET_TCGV_I64 (a3),GET_TCGV_I64 (a4), a5, a6); +tcg_gen_op6 (opc,tcgv_i64_arg (a1),tcgv_i64_arg (a2), +tcgv_i64_arg (a3),tcgv_i64_arg (a4), a5, a6); }
tcg/tcg.h +20 -0
@@ -756,6 +756,26 @@ static inline size_t arg_index(TCGArg a)return a; } +static inline TCGArg index_arg (size_t n) +{ +return n; +} + +static inline TCGArg tcgv_i32_arg (TCGv_i32 t) +{ +return index_arg (GET_TCGV_I32 (t)); +} + +static inline TCGArg tcgv_i64_arg (TCGv_i64 t) +{ +return index_arg (GET_TCGV_I64 (t)); +} + +static inline TCGArg tcgv_ptr_arg (TCGv_ptr t) +{ +return index_arg (GET_TCGV_PTR (t)); +} +static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v) { tcg_ctx.gen_op_buf[op_idx].args[arg] = v;
tcg/tcg-op.c +7 -7
@@ -2458,7 +2458,7 @@ void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)tcg_gen_mov_i32 (ret,TCGV_LOW (arg)); }else if (TCG_TARGET_HAS_extrl_i64_i32) {tcg_gen_op2 (INDEX_op_extrl_i64_i32, -GET_TCGV_I32 (ret),GET_TCGV_I64 (arg)); +tcgv_i32_arg (ret),tcgv_i64_arg (arg)); }else {tcg_gen_mov_i32 (ret,MAKE_TCGV_I32 (GET_TCGV_I64 (arg))); }
@@ -2470,7 +2470,7 @@ void tcg_gen_extrh_i64_i32(TCGv_i32 ret, TCGv_i64 arg)tcg_gen_mov_i32 (ret,TCGV_HIGH (arg)); }else if (TCG_TARGET_HAS_extrh_i64_i32) {tcg_gen_op2 (INDEX_op_extrh_i64_i32, -GET_TCGV_I32 (ret),GET_TCGV_I64 (arg)); +tcgv_i32_arg (ret),tcgv_i64_arg (arg)); }else {TCGv_i64 t =tcg_temp_new_i64 ();tcg_gen_shri_i64 (t, arg,32 );
@@ -2486,7 +2486,7 @@ void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)tcg_gen_movi_i32 (TCGV_HIGH (ret),0 ); }else {tcg_gen_op2 (INDEX_op_extu_i32_i64, -GET_TCGV_I64 (ret),GET_TCGV_I32 (arg)); +tcgv_i64_arg (ret),tcgv_i32_arg (arg)); } }
@@ -2497,7 +2497,7 @@ void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)tcg_gen_sari_i32 (TCGV_HIGH (ret),TCGV_LOW (ret),31 ); }else {tcg_gen_op2 (INDEX_op_ext_i32_i64, -GET_TCGV_I64 (ret),GET_TCGV_I32 (arg)); +tcgv_i64_arg (ret),tcgv_i32_arg (arg)); } }
@@ -2563,7 +2563,7 @@ void tcg_gen_lookup_and_goto_ptr(void)if (TCG_TARGET_HAS_goto_ptr && !qemu_loglevel_mask (CPU_LOG_TB_NOCHAIN )) {TCGv_ptr ptr =tcg_temp_new_ptr ();gen_helper_lookup_tb_ptr (ptr, tcg_ctx.tcg_env); -tcg_gen_op1i (INDEX_op_goto_ptr,GET_TCGV_PTR (ptr)); +tcg_gen_op1i (INDEX_op_goto_ptr,tcgv_ptr_arg (ptr));tcg_temp_free_ptr (ptr); }else {tcg_gen_exit_tb (0 );
@@ -2608,7 +2608,7 @@ static void gen_ldst_i32(TCGOpcode opc, TCGv_i32 val, TCGv addr,if (TCG_TARGET_REG_BITS ==32 ) {tcg_gen_op4i_i32 (opc, val,TCGV_LOW (addr),TCGV_HIGH (addr), oi); }else { -tcg_gen_op3 (opc,GET_TCGV_I32 (val),GET_TCGV_I64 (addr), oi); +tcg_gen_op3 (opc,tcgv_i32_arg (val),tcgv_i64_arg (addr), oi); }#endif }
@@ -2621,7 +2621,7 @@ static void gen_ldst_i64(TCGOpcode opc, TCGv_i64 val, TCGv addr,if (TCG_TARGET_REG_BITS ==32 ) {tcg_gen_op4i_i32 (opc,TCGV_LOW (val),TCGV_HIGH (val), addr, oi); }else { -tcg_gen_op3 (opc,GET_TCGV_I64 (val),GET_TCGV_I32 (addr), oi); +tcg_gen_op3 (opc,tcgv_i64_arg (val),tcgv_i32_arg (addr), oi); }#else if (TCG_TARGET_REG_BITS ==32 ) {
tcg/tcg.c +13 -13
@@ -1054,25 +1054,25 @@ void tcg_gen_callN(void *func, TCGArg ret, int nargs, TCGArg *args)two return temporaries, and reassemble below. */ retl =tcg_temp_new_i64 (); reth =tcg_temp_new_i64 (); - op->args[pi++] =GET_TCGV_I64 (reth); - op->args[pi++] =GET_TCGV_I64 (retl); + op->args[pi++] =tcgv_i64_arg (reth); + op->args[pi++] =tcgv_i64_arg (retl); nb_rets = 2; }else { - op->args[pi++] = ret; + op->args[pi++] =index_arg (ret); nb_rets =1 ; }#else if (TCG_TARGET_REG_BITS <64 && (sizemask &1 )) {#ifdef HOST_WORDS_BIGENDIAN - op->args[pi++] = ret +1 ; - op->args[pi++] = ret; + op->args[pi++] =index_arg (ret +1 ); + op->args[pi++] =index_arg (ret);#else - op->args[pi++] = ret; - op->args[pi++] = ret +1 ; + op->args[pi++] =index_arg (ret); + op->args[pi++] =index_arg (ret +1 );#endif nb_rets =2 ; }else { - op->args[pi++] = ret; + op->args[pi++] =index_arg (ret); nb_rets =1 ; }#endif
@@ -1103,17 +1103,17 @@ void tcg_gen_callN(void *func, TCGArg ret, int nargs, TCGArg *args)have to get more complicated to differentiate between stack arguments and register arguments. */ #if defined(HOST_WORDS_BIGENDIAN ) != defined(TCG_TARGET_STACK_GROWSUP ) - op->args[pi++] = args[i] +1 ; - op->args[pi++] = args[i]; + op->args[pi++] =index_arg (args[i] +1 ); + op->args[pi++] =index_arg (args[i]);#else - op->args[pi++] = args[i]; - op->args[pi++] = args[i] +1 ; + op->args[pi++] =index_arg (args[i]); + op->args[pi++] =index_arg (args[i] +1 );#endif real_args +=2 ;continue ; } - op->args[pi++] = args[i]; + op->args[pi++] =index_arg (args[i]); real_args++; } op->args[pi++] = (uintptr_t )func;
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 17/50] tcg: Introduce index_arg
Quoted 2 lines · Richard Henderson
For multi-threaded tcg we have one TCGContext per thread. With that, plus static cpu_* variables, we need the translators to handle indicies.
s/indicies/indices/
Quoted 5 lines
We transform those to "arguments" at opcode generating time.
For now, that transformation is a no-op.
Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 18/50 tcg: Reserve temporary index 0
In reply to Richard HendersonSince we cast indicies to pointers, reserving 0 allows us to use NULL for unused/dummy instead of (T *)-1.
--- tcg/tcg.h | 16 ++++++++-------- tcg/tcg.c | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-)
tcg/tcg.h +8 -8
@@ -471,13 +471,13 @@ static inline intptr_t QEMU_ARTIFICIAL GET_TCGV_PTR(TCGv_ptr t)#define TCGV_EQUAL_PTR (a, b) (GET_TCGV_PTR(a) == GET_TCGV_PTR(b))/* Dummy definition to avoid compiler warnings. */ -#define TCGV_UNUSED_I32 (x) x = MAKE_TCGV_I32(-1) -#define TCGV_UNUSED_I64 (x) x = MAKE_TCGV_I64(-1) -#define TCGV_UNUSED_PTR (x) x = MAKE_TCGV_PTR(-1) +#define TCGV_UNUSED_I32 (x) ((x) = NULL) +#define TCGV_UNUSED_I64 (x) ((x) = NULL) +#define TCGV_UNUSED_PTR (x) ((x) = NULL) -#define TCGV_IS_UNUSED_I32 (x) (GET_TCGV_I32(x) == -1) -#define TCGV_IS_UNUSED_I64 (x) (GET_TCGV_I64(x) == -1) -#define TCGV_IS_UNUSED_PTR (x) (GET_TCGV_PTR(x) == -1) +#define TCGV_IS_UNUSED_I32 (x) (GET_TCGV_I32(x) == 0) +#define TCGV_IS_UNUSED_I64 (x) (GET_TCGV_I64(x) == 0) +#define TCGV_IS_UNUSED_PTR (x) (GET_TCGV_PTR(x) == 0)/* call flags */ /* Helper does not read globals (either directly or through an exception). It
@@ -496,7 +496,7 @@ static inline intptr_t QEMU_ARTIFICIAL GET_TCGV_PTR(TCGv_ptr t)#define TCG_CALL_NO_WG_SE (TCG_CALL_NO_WG | TCG_CALL_NO_SE)/* used to align parameters */ -#define TCG_CALL_DUMMY_ARG ((TCGArg)(-1)) +#define TCG_CALL_DUMMY_ARG ((TCGArg)0)/* Conditions. Note that these are laid out for easy manipulation by the functions below:
@@ -737,7 +737,7 @@ extern bool parallel_cpus;static inline size_t temp_idx (TCGTemp *ts) {ptrdiff_t n = ts - tcg_ctx.temps; -tcg_debug_assert (n >=0 && n < tcg_ctx.nb_temps); +tcg_debug_assert (n >0 && n < tcg_ctx.nb_temps);return n; }
tcg/tcg.c +4 -1
@@ -333,7 +333,10 @@ void tcg_context_init(TCGContext *s)int *sorted_args;memset (s,0 ,sizeof (*s)); - s->nb_globals =0 ; +/* Reserve temp index 0 so that, with the funny casting that we do, +the first one doesn't look like NULL. */ + s->nb_globals =1 ; + s->nb_temps =1 ;/* Count total number of arguments and allocate the corresponding space */
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 18/50] tcg: Reserve temporary index 0
Quoted 1 line · Richard Henderson
Since we cast indicies to pointers, reserving 0 allows
s/indicies/indices/
Quoted 4 lines
us to use NULL for unused/dummy instead of (T *)-1.
Signed-off-by Richard Henderson <[email protected]>---
(snip)
Quoted 15 lines
(quoted diff) +1
-1@@ -737,7 +737,7 @@ extern bool parallel_cpus; static inline size_t temp_idx(TCGTemp *ts) { ptrdiff_t n = ts - tcg_ctx.temps; - tcg_debug_assert(n >= 0 && n < tcg_ctx.nb_temps); + tcg_debug_assert(n > 0 && n < tcg_ctx.nb_temps); return n; }tcg/tcg.c +0
-0@@ -333,7 +333,10 @@ void tcg_context_init(TCGContext *s)int *sorted_args;
tcg/tcg.c void tcg_context_init(TCGContext *s) · line 342
Quoted 10 lines
tcg/tcg.c +4
-1memset (s,0 ,sizeof (*s)); - s->nb_globals =0 ; +/* Reserve temp index 0 so that, with the funny casting that we do, +the first one doesn't look like NULL. */ + s->nb_globals =1 ; + s->nb_temps =1 ;/* Count total number of arguments and allocate the corresponding space */
I like this change, although operating on the 0th element makes me uneasy.
For instance, I managed to trigger the above assert by manually calling dump_regs (it is otherwise called before aborting, which is why you missed it.) This fixes it:
tcg/tcg.c +1 -1
@@ -2034,7 +2034,7 @@ static void dump_regs(TCGContext *s)int i;char buf[64 ]; -for (i =0 ; i < s->nb_temps; i++) { +for (i =1 ; i < s->nb_temps; i++) { ts = &s->temps[i];printf (" %10s: " ,tcg_get_arg_str_ptr (s, buf,sizeof (buf), ts));switch (ts->val_type) {
Is it worth changing other [0, nb_temps/globals) loops to start from 1?
Thanks,
E.
PATCH v6 19/50 target/alpha: Avoid translate_init unless tcg_enabled
In reply to Richard Henderson--- target/alpha/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/alpha/cpu.c +3 -1
@@ -260,7 +260,9 @@ static void alpha_cpu_initfn(Object *obj) cs->env_ptr = env;tlb_flush (cs); -alpha_translate_init (); +if (tcg_enabled ()) { +alpha_translate_init (); + } env->lock_addr =-1 ;#if defined(CONFIG_USER_ONLY )
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 19/50] target/alpha: Avoid translate_init unless tcg_enabled
Quoted 10 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/alpha/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)target/alpha/cpu.c +0
-0
target/alpha/cpu.c static void alpha_cpu_initfn(Object *obj) · line 265
Quoted 7 lines
target/alpha/cpu.c +3
-1@@ -260,7 +260,9 @@ static void alpha_cpu_initfn(Object *obj) cs->env_ptr = env;tlb_flush (cs); -alpha_translate_init (); +if (tcg_enabled ()) { +alpha_translate_init (); + }
This change is undone/superseded by the next patch (patch 20).
I'd just drop it.
E.
PATCH v6 20/50 qom: Introduce CPUClass.tcg_initialize
In reply to Richard HendersonMove target cpu tcg initialization to common code, called from cpu_exec_realizefn.
--- include/qom/cpu.h | 8 ++++++-- target/sparc/cpu.h | 2 +- exec.c | 7 ++++++- target/alpha/cpu.c | 5 +---- target/alpha/translate.c | 6 ------ target/arm/cpu.c | 6 +----- target/cris/cpu.c | 16 ++++++---------- target/hppa/cpu.c | 3 +-- target/hppa/translate.c | 6 ------ target/i386/cpu.c | 5 +---- target/i386/translate.c | 6 ------ target/lm32/cpu.c | 7 +------ target/m68k/cpu.c | 7 +------ target/microblaze/cpu.c | 7 +------ target/mips/cpu.c | 5 +---- target/mips/translate.c | 7 ------- target/moxie/cpu.c | 7 +------ target/moxie/translate.c | 6 ------ target/nios2/cpu.c | 7 +------ target/openrisc/cpu.c | 7 +------ target/ppc/translate.c | 6 ------ target/ppc/translate_init.c | 5 +---- target/s390x/cpu.c | 7 +------ target/sh4/cpu.c | 5 +---- target/sh4/translate.c | 7 ------- target/sparc/cpu.c | 5 +---- target/sparc/translate.c | 9 +-------- target/tilegx/cpu.c | 7 +------ target/tricore/cpu.c | 5 +---- target/tricore/translate.c | 5 +---- target/unicore32/cpu.c | 7 +------ target/xtensa/cpu.c | 7 +------ 32 files changed, 40 insertions(+), 165 deletions(-)
include/qom/cpu.h +6 -2
@@ -195,10 +195,8 @@ typedef struct CPUClass { void *opaque);const struct VMStateDescription *vmsd; -int gdb_num_core_regs;const char *gdb_core_xml_file; gchar * (*gdb_arch_name)(CPUState *cpu); -bool gdb_stop_before_watchpoint;void (*cpu_exec_enter)(CPUState *cpu);void (*cpu_exec_exit)(CPUState *cpu);
@@ -206,6 +204,12 @@ typedef struct CPUClass {void (*disas_set_info)(CPUState *cpu,disassemble_info *info);vaddr (*adjust_watchpoint_address)(CPUState *cpu,vaddr addr,int len); +void (*tcg_initialize)(void ); + +/* Keep non-pointer data at the end to minimize holes. */ +int gdb_num_core_regs; +bool gdb_stop_before_watchpoint; +bool tcg_initialized; } CPUClass;#ifdef HOST_WORDS_BIGENDIAN
target/sparc/cpu.h +1 -1
@@ -594,7 +594,7 @@ int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,/* translate.c */ -void gen_intermediate_code_init (CPUSPARCState *env); +void sparc_tcg_init (void );/* cpu-exec.c */
exec.c +6 -1
@@ -763,10 +763,15 @@ void cpu_exec_initfn(CPUState *cpu)void cpu_exec_realizefn (CPUState *cpu,Error **errp) { - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); +CPUClass *cc =CPU_GET_CLASS (cpu);cpu_list_add (cpu); +if (tcg_enabled () && !cc->tcg_initialized) { + cc->tcg_initialized = true; + cc->tcg_initialize (); + } +#ifndef CONFIG_USER_ONLY if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu);
target/alpha/cpu.c +1 -4
@@ -260,10 +260,6 @@ static void alpha_cpu_initfn(Object *obj) cs->env_ptr = env;tlb_flush (cs); -if (tcg_enabled ()) { -alpha_translate_init (); - } - env->lock_addr =-1 ;#if defined(CONFIG_USER_ONLY ) env->flags =ENV_FLAG_PS_USER |ENV_FLAG_FEN ;
@@ -301,6 +297,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) dc->vmsd = &vmstate_alpha_cpu;#endif cc->disas_set_info = alpha_cpu_disas_set_info; + cc->tcg_initialize = alpha_translate_init; cc->gdb_num_core_regs =67 ; }
target/alpha/translate.c +0 -6
@@ -124,14 +124,8 @@ void alpha_translate_init(void) };#endif -static bool done_init =0 ;int i; -if (done_init) { -return ; - } - done_init =1 ; - cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
target/arm/cpu.c +1 -5
@@ -534,7 +534,6 @@ static void arm_cpu_initfn(Object *obj) {CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj); -static bool inited; cs->env_ptr = &cpu->env; cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
@@ -578,10 +577,6 @@ static void arm_cpu_initfn(Object *obj)if (tcg_enabled ()) { cpu->psci_version =2 ;/* TCG implements PSCI 0.2 */ -if (!inited) { - inited = true; -arm_translate_init (); - } } }
@@ -1765,6 +1760,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)#endif cc->disas_set_info = arm_disas_set_info; + cc->tcg_initialize = arm_translate_init; }static void cpu_register (const ARMCPUInfo *info)
target/cris/cpu.c +6 -10
@@ -181,7 +181,6 @@ static void cris_cpu_initfn(Object *obj)CRISCPU *cpu =CRIS_CPU (obj);CRISCPUClass *ccc =CRIS_CPU_GET_CLASS (obj);CPUCRISState *env = &cpu->env; -static bool tcg_initialized; cs->env_ptr = env;
@@ -191,15 +190,6 @@ static void cris_cpu_initfn(Object *obj)/* IRQ and NMI lines. */ qdev_init_gpio_in (DEVICE (cpu), cris_cpu_set_irq,2 );#endif - -if (tcg_enabled () && !tcg_initialized) { - tcg_initialized = true; -if (env->pregs[PR_VR ] <32 ) { -cris_initialize_crisv10_tcg (); - }else { -cris_initialize_tcg (); - } - } }static void crisv8_cpu_class_init (ObjectClass *oc,void *data)
@@ -210,6 +200,7 @@ static void crisv8_cpu_class_init(ObjectClass *oc, void *data) ccc->vr =8 ; cc->do_interrupt = crisv10_cpu_do_interrupt; cc->gdb_read_register = crisv10_cpu_gdb_read_register; + cc->tcg_initialize = cris_initialize_crisv10_tcg; }static void crisv9_cpu_class_init (ObjectClass *oc,void *data)
@@ -220,6 +211,7 @@ static void crisv9_cpu_class_init(ObjectClass *oc, void *data) ccc->vr =9 ; cc->do_interrupt = crisv10_cpu_do_interrupt; cc->gdb_read_register = crisv10_cpu_gdb_read_register; + cc->tcg_initialize = cris_initialize_crisv10_tcg; }static void crisv10_cpu_class_init (ObjectClass *oc,void *data)
@@ -230,6 +222,7 @@ static void crisv10_cpu_class_init(ObjectClass *oc, void *data) ccc->vr =10 ; cc->do_interrupt = crisv10_cpu_do_interrupt; cc->gdb_read_register = crisv10_cpu_gdb_read_register; + cc->tcg_initialize = cris_initialize_crisv10_tcg; }static void crisv11_cpu_class_init (ObjectClass *oc,void *data)
@@ -240,6 +233,7 @@ static void crisv11_cpu_class_init(ObjectClass *oc, void *data) ccc->vr =11 ; cc->do_interrupt = crisv10_cpu_do_interrupt; cc->gdb_read_register = crisv10_cpu_gdb_read_register; + cc->tcg_initialize = cris_initialize_crisv10_tcg; }static void crisv17_cpu_class_init (ObjectClass *oc,void *data)
@@ -250,6 +244,7 @@ static void crisv17_cpu_class_init(ObjectClass *oc, void *data) ccc->vr =17 ; cc->do_interrupt = crisv10_cpu_do_interrupt; cc->gdb_read_register = crisv10_cpu_gdb_read_register; + cc->tcg_initialize = cris_initialize_crisv10_tcg; }static void crisv32_cpu_class_init (ObjectClass *oc,void *data)
@@ -322,6 +317,7 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = cris_disas_set_info; + cc->tcg_initialize = cris_initialize_tcg; }static const TypeInfo cris_cpu_type_info = {
target/hppa/cpu.c +1 -2
@@ -108,8 +108,6 @@ static void hppa_cpu_initfn(Object *obj) cs->env_ptr = env;cpu_hppa_loaded_fr0 (env);set_snan_bit_is_one (true, &env->fp_status); - -hppa_translate_init (); }static ObjectClass *hppa_cpu_class_by_name (const char *cpu_model)
@@ -136,6 +134,7 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_write_register = hppa_cpu_gdb_write_register; cc->handle_mmu_fault = hppa_cpu_handle_mmu_fault; cc->disas_set_info = hppa_cpu_disas_set_info; + cc->tcg_initialize = hppa_translate_init; cc->gdb_num_core_regs =128 ; }
target/hppa/translate.c +0 -6
@@ -124,14 +124,8 @@ void hppa_translate_init(void) "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" }; -static bool done_init =0 ;int i; -if (done_init) { -return ; - } - done_init =1 ; - cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
target/i386/cpu.c +1 -4
@@ -3719,10 +3719,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -if (tcg_enabled ()) { -tcg_x86_init (); - } -#ifndef CONFIG_USER_ONLY qemu_register_reset (x86_cpu_machine_reset_cb, cpu);
@@ -4216,6 +4212,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)#endif cc->cpu_exec_enter = x86_cpu_exec_enter; cc->cpu_exec_exit = x86_cpu_exec_exit; + cc->tcg_initialize = tcg_x86_init; dc->user_creatable = true; }
target/i386/translate.c +0 -6
@@ -8329,12 +8329,6 @@ void tcg_x86_init(void) "bnd0_ub", "bnd1_ub", "bnd2_ub", "bnd3_ub" };int i; -static bool initialized; - -if (initialized) { -return ; - } - initialized = true; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
target/lm32/cpu.c +1 -6
@@ -163,16 +163,10 @@ static void lm32_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);LM32CPU *cpu =LM32_CPU (obj);CPULM32State *env = &cpu->env; -static bool tcg_initialized; cs->env_ptr = env; env->flags =0 ; - -if (tcg_enabled () && !tcg_initialized) { - tcg_initialized = true; -lm32_translate_init (); - } }static void lm32_basic_cpu_initfn (Object *obj)
@@ -286,6 +280,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_stop_before_watchpoint = true; cc->debug_excp_handler = lm32_debug_excp_handler; cc->disas_set_info = lm32_cpu_disas_set_info; + cc->tcg_initialize = lm32_translate_init; }static void lm32_register_cpu_type (const LM32CPUInfo *info)
target/m68k/cpu.c +1 -6
@@ -247,14 +247,8 @@ static void m68k_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);M68kCPU *cpu =M68K_CPU (obj);CPUM68KState *env = &cpu->env; -static bool inited; cs->env_ptr = env; - -if (tcg_enabled () && !inited) { - inited = true; -m68k_tcg_init (); - } }static const VMStateDescription vmstate_m68k_cpu = {
@@ -288,6 +282,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;#endif cc->disas_set_info = m68k_cpu_disas_set_info; + cc->tcg_initialize = m68k_tcg_init; cc->gdb_num_core_regs =18 ; cc->gdb_core_xml_file ="cf-core.xml" ;
target/microblaze/cpu.c +1 -6
@@ -205,7 +205,6 @@ static void mb_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);MicroBlazeCPU *cpu =MICROBLAZE_CPU (obj);CPUMBState *env = &cpu->env; -static bool tcg_initialized; cs->env_ptr = env;
@@ -215,11 +214,6 @@ static void mb_cpu_initfn(Object *obj)/* Inbound IRQ and FIR lines */ qdev_init_gpio_in (DEVICE (cpu), microblaze_cpu_set_irq,2 );#endif - -if (tcg_enabled () && !tcg_initialized) { - tcg_initialized = true; -mb_tcg_init (); - } }static const VMStateDescription vmstate_mb_cpu = {
@@ -289,6 +283,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_num_core_regs =32 +5 ; cc->disas_set_info = mb_disas_set_info; + cc->tcg_initialize = mb_tcg_init; }static const TypeInfo mb_cpu_type_info = {
target/mips/cpu.c +1 -4
@@ -150,10 +150,6 @@ static void mips_cpu_initfn(Object *obj) cs->env_ptr = env; env->cpu_model = mcc->cpu_def; - -if (tcg_enabled ()) { -mips_tcg_init (); - } }static char *mips_cpu_type_name (const char *cpu_model)
@@ -202,6 +198,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->vmsd = &vmstate_mips_cpu;#endif cc->disas_set_info = mips_cpu_disas_set_info; + cc->tcg_initialize = mips_tcg_init; cc->gdb_num_core_regs =73 ; cc->gdb_stop_before_watchpoint = true;
target/mips/translate.c +0 -7
@@ -20453,11 +20453,6 @@ void mips_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,void mips_tcg_init (void ) {int i; -static int inited; - -/* Initialize various static tables. */ -if (inited) -return ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
@@ -20506,8 +20501,6 @@ void mips_tcg_init(void) fpu_fcr31 =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUMIPSState, active_fpu.fcr31),"fcr31" ); - - inited =1 ; }#include "translate_init.c"
target/moxie/cpu.c +1 -6
@@ -77,14 +77,8 @@ static void moxie_cpu_initfn(Object *obj) {CPUState *cs =CPU (obj);MoxieCPU *cpu =MOXIE_CPU (obj); -static int inited; cs->env_ptr = &cpu->env; - -if (tcg_enabled () && !inited) { - inited =1 ; -moxie_translate_init (); - } }static ObjectClass *moxie_cpu_class_by_name (const char *cpu_model)
@@ -122,6 +116,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) cc->vmsd = &vmstate_moxie_cpu;#endif cc->disas_set_info = moxie_cpu_disas_set_info; + cc->tcg_initialize = moxie_translate_init; }static void moxielite_initfn (Object *obj)
target/moxie/translate.c +0 -6
@@ -94,7 +94,6 @@ void moxie_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,void moxie_translate_init (void ) {int i; -static int done_init;static const char *const gregnames[16 ] = {"$fp" ,"$sp" ,"$r0" ,"$r1" ,"$r2" ,"$r3" ,"$r4" ,"$r5" ,
@@ -102,9 +101,6 @@ void moxie_translate_init(void)"$r10" ,"$r11" ,"$r12" ,"$r13" }; -if (done_init) { -return ; - } cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env; cpu_pc = tcg_global_mem_new_i32(cpu_env,
@@ -118,8 +114,6 @@ void moxie_translate_init(void) offsetof(CPUMoxieState, cc_a), "cc_a"); cc_b =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUMoxieState , cc_b),"cc_b" ); - - done_init =1 ; }static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest)
target/nios2/cpu.c +1 -6
@@ -69,18 +69,12 @@ static void nios2_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);Nios2CPU *cpu =NIOS2_CPU (obj);CPUNios2State *env = &cpu->env; -static bool tcg_initialized; cs->env_ptr = env;#if !defined(CONFIG_USER_ONLY )mmu_init (env);#endif - -if (tcg_enabled () && !tcg_initialized) { - tcg_initialized = true; -nios2_tcg_init (); - } }static ObjectClass *nios2_cpu_class_by_name (const char *cpu_model)
@@ -215,6 +209,7 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = nios2_cpu_gdb_read_register; cc->gdb_write_register = nios2_cpu_gdb_write_register; cc->gdb_num_core_regs =49 ; + cc->tcg_initialize = nios2_tcg_init; }static const TypeInfo nios2_cpu_type_info = {
target/openrisc/cpu.c +1 -6
@@ -87,18 +87,12 @@ static void openrisc_cpu_initfn(Object *obj) {CPUState *cs =CPU (obj);OpenRISCCPU *cpu =OPENRISC_CPU (obj); -static int inited; cs->env_ptr = &cpu->env;#ifndef CONFIG_USER_ONLY cpu_openrisc_mmu_init (cpu);#endif - -if (tcg_enabled () && !inited) { - inited =1 ; -openrisc_translate_init (); - } }/* CPU models */
@@ -170,6 +164,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) dc->vmsd = &vmstate_openrisc_cpu;#endif cc->gdb_num_core_regs =32 +3 ; + cc->tcg_initialize = openrisc_translate_init; }static void cpu_register (const OpenRISCCPUInfo *info)
target/ppc/translate.c +0 -6
@@ -84,10 +84,6 @@ void ppc_translate_init(void)int i;char * p;size_t cpu_reg_names_size; -static int done_init =0 ; - -if (done_init) -return ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
@@ -191,8 +187,6 @@ void ppc_translate_init(void) cpu_access_type =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUPPCState , access_type),"access_type" ); - - done_init =1 ; }/* internal defines */
target/ppc/translate_init.c +1 -4
@@ -10661,10 +10661,6 @@ static void ppc_cpu_initfn(Object *obj) env->sps = (env->mmu_model & POWERPC_MMU_64K) ? defsps_64k : defsps_4k; }#endif /* defined(TARGET_PPC64) */ - -if (tcg_enabled ()) { -ppc_translate_init (); - } }static bool ppc_pvr_match_default (PowerPCCPUClass *pcc,uint32_t pvr)
@@ -10742,6 +10738,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)#ifndef CONFIG_USER_ONLY cc->virtio_is_big_endian = ppc_cpu_is_big_endian;#endif + cc->tcg_initialize = ppc_translate_init; dc->fw_name ="PowerPC,UNKNOWN" ; }
target/s390x/cpu.c +1 -6
@@ -235,7 +235,6 @@ static void s390_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);S390CPU *cpu =S390_CPU (obj);CPUS390XState *env = &cpu->env; -static bool inited;#if !defined(CONFIG_USER_ONLY )struct tm tm;#endif
@@ -253,11 +252,6 @@ static void s390_cpu_initfn(Object *obj) env->cpu_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , s390x_cpu_timer, cpu);s390_cpu_set_state (CPU_STATE_STOPPED , cpu);#endif - -if (tcg_enabled () && !inited) { - inited = true; -s390x_translate_init (); - } }static void s390_cpu_finalize (Object *obj)
@@ -498,6 +492,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)#endif #endif cc->disas_set_info = s390_cpu_disas_set_info; + cc->tcg_initialize = s390x_translate_init; cc->gdb_num_core_regs =S390_NUM_CORE_REGS ; cc->gdb_core_xml_file ="s390x-core64.xml" ;
target/sh4/cpu.c +1 -4
@@ -258,10 +258,6 @@ static void superh_cpu_initfn(Object *obj) cs->env_ptr = env; env->movcal_backup_tail = &(env->movcal_backup); - -if (tcg_enabled ()) { -sh4_translate_init (); - } }static const VMStateDescription vmstate_sh_cpu = {
@@ -297,6 +293,7 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) cc->get_phys_page_debug = superh_cpu_get_phys_page_debug;#endif cc->disas_set_info = superh_cpu_disas_set_info; + cc->tcg_initialize = sh4_translate_init; cc->gdb_num_core_regs =59 ;
target/sh4/translate.c +0 -7
@@ -81,7 +81,6 @@ static TCGv cpu_flags, cpu_delayed_pc, cpu_delayed_cond;void sh4_translate_init (void ) {int i; -static int done_init =0 ;static const char *const gregnames[24 ] = {"R0_BANK0" ,"R1_BANK0" ,"R2_BANK0" ,"R3_BANK0" ,"R4_BANK0" ,"R5_BANK0" ,"R6_BANK0" ,"R7_BANK0" ,
@@ -100,10 +99,6 @@ void sh4_translate_init(void)"FPR12_BANK1" ,"FPR13_BANK1" ,"FPR14_BANK1" ,"FPR15_BANK1" , }; -if (done_init) { -return ; - } - cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
@@ -163,8 +158,6 @@ void sh4_translate_init(void) cpu_fregs[i] =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUSH4State, fregs[i]), fregnames[i]); - - done_init =1 ; } void superh_cpu_dump_state(CPUState *cs, FILE *f,
target/sparc/cpu.c +1 -4
@@ -784,10 +784,6 @@ static void sparc_cpu_initfn(Object *obj) cs->env_ptr = env; -if (tcg_enabled ()) { -gen_intermediate_code_init (env); - } -if (scc->cpu_def) { env->def = *scc->cpu_def; }
@@ -891,6 +887,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) cc->vmsd = &vmstate_sparc_cpu;#endif cc->disas_set_info = cpu_sparc_disas_set_info; + cc->tcg_initialize = sparc_tcg_init;#if defined(TARGET_SPARC64 ) && !defined(TARGET_ABI32 ) cc->gdb_num_core_regs =86 ;
target/sparc/translate.c +1 -8
@@ -5862,9 +5862,8 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock * tb)#endif } -void gen_intermediate_code_init (CPUSPARCState *env) +void sparc_tcg_init (void ) { -static int inited;static const char gregnames[32 ][4 ] = {"g0" ,"g1" ,"g2" ,"g3" ,"g4" ,"g5" ,"g6" ,"g7" ,"o0" ,"o1" ,"o2" ,"o3" ,"o4" ,"o5" ,"o6" ,"o7" ,
@@ -5917,12 +5916,6 @@ void gen_intermediate_code_init(CPUSPARCState *env)unsigned int i; -/* init various static tables */ -if (inited) { -return ; - } - inited =1 ; - cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;
target/tilegx/cpu.c +1 -6
@@ -103,14 +103,8 @@ static void tilegx_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);TileGXCPU *cpu =TILEGX_CPU (obj);CPUTLGState *env = &cpu->env; -static bool tcg_initialized; cs->env_ptr = env; - -if (tcg_enabled () && !tcg_initialized) { - tcg_initialized = true; -tilegx_tcg_init (); - } }static void tilegx_cpu_do_interrupt (CPUState *cs)
@@ -161,6 +155,7 @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = tilegx_cpu_set_pc; cc->handle_mmu_fault = tilegx_cpu_handle_mmu_fault; cc->gdb_num_core_regs =0 ; + cc->tcg_initialize = tilegx_tcg_init; }static const TypeInfo tilegx_cpu_type_info = {
target/tricore/cpu.c +1 -4
@@ -109,10 +109,6 @@ static void tricore_cpu_initfn(Object *obj)CPUTriCoreState *env = &cpu->env; cs->env_ptr = env; - -if (tcg_enabled ()) { -tricore_tcg_init (); - } }static ObjectClass *tricore_cpu_class_by_name (const char *cpu_model)
@@ -182,6 +178,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) cc->set_pc = tricore_cpu_set_pc; cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; cc->get_phys_page_attrs_debug = tricore_cpu_get_phys_page_attrs_debug; + cc->tcg_initialize = tricore_tcg_init; }static void cpu_register (const TriCoreCPUInfo *info)
target/tricore/translate.c +1 -4
@@ -8880,10 +8880,7 @@ static void tricore_tcg_init_csfr(void)void tricore_tcg_init (void ) {int i; -static int inited; -if (inited) { -return ; - } + cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); tcg_ctx.tcg_env = cpu_env;/* reg init */
target/unicore32/cpu.c +1 -6
@@ -117,7 +117,6 @@ static void uc32_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);UniCore32CPU *cpu =UNICORE32_CPU (obj);CPUUniCore32State *env = &cpu->env; -static bool inited; cs->env_ptr = env;
@@ -130,11 +129,6 @@ static void uc32_cpu_initfn(Object *obj)#endif tlb_flush (cs); - -if (tcg_enabled () && !inited) { - inited = true; -uc32_translate_init (); - } }static const VMStateDescription vmstate_uc32_cpu = {
@@ -162,6 +156,7 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)#else cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;#endif + cc->tcg_initialize = uc32_translate_init; dc->vmsd = &vmstate_uc32_cpu; }
target/xtensa/cpu.c +1 -6
@@ -121,7 +121,6 @@ static void xtensa_cpu_initfn(Object *obj)XtensaCPU *cpu =XTENSA_CPU (obj);XtensaCPUClass *xcc =XTENSA_CPU_GET_CLASS (obj);CPUXtensaState *env = &cpu->env; -static bool tcg_inited; cs->env_ptr = env; env->config = xcc->config;
@@ -131,11 +130,6 @@ static void xtensa_cpu_initfn(Object *obj)memory_region_init_io (env->system_er,NULL ,NULL , env,"er" ,UINT64_C (0x100000000 ));address_space_init (env->address_space_er, env->system_er,"ER" ); - -if (tcg_enabled () && !tcg_inited) { - tcg_inited = true; -xtensa_translate_init (); - } }static const VMStateDescription vmstate_xtensa_cpu = {
@@ -170,6 +164,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) cc->do_unassigned_access = xtensa_cpu_do_unassigned_access;#endif cc->debug_excp_handler = xtensa_breakpoint_handler; + cc->tcg_initialize = xtensa_translate_init; dc->vmsd = &vmstate_xtensa_cpu; }
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 20/50] qom: Introduce CPUClass.tcg_initialize
Quoted 5 lines · Richard Henderson
Move target cpu tcg initialization to common code, called from
cpu_exec_realizefn.Cc Andreas Färber <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Much cleaner!
E.
Andreas Färber
Acked-byRe: [Qemu-devel] [PATCH v6 20/50] qom: Introduce CPUClass.tcg_initialize
Am 18.10.2017 um 01:53 schrieb Emilio G. Cota:
Quoted 10 lines · Richard Henderson
Quoted 5 lines
Move target cpu tcg initialization to common code, called from
cpu_exec_realizefn.Cc Andreas Färber <[email protected]>Signed-off-by Richard Henderson <[email protected]>Much cleaner!
Reviewed-by Emilio G. Cota <[email protected]>
Looks like a good approach,
Thanks,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v6 20/50] qom: Introduce CPUClass.tcg_initialize
In reply to Richard HendersonQuoted 5 lines · Richard Henderson
Move target cpu tcg initialization to common code, called from
cpu_exec_realizefn.Cc Andreas Färber <[email protected]>Signed-off-by Richard Henderson <[email protected]>
much cleaner, esp. the CRIS part.
Quoted 34 lines
--- include/qom/cpu.h | 8 ++++++-- target/sparc/cpu.h | 2 +- exec.c | 7 ++++++- target/alpha/cpu.c | 5 +---- target/alpha/translate.c | 6 ------ target/arm/cpu.c | 6 +----- target/cris/cpu.c | 16 ++++++---------- target/hppa/cpu.c | 3 +-- target/hppa/translate.c | 6 ------ target/i386/cpu.c | 5 +---- target/i386/translate.c | 6 ------ target/lm32/cpu.c | 7 +------ target/m68k/cpu.c | 7 +------ target/microblaze/cpu.c | 7 +------ target/mips/cpu.c | 5 +---- target/mips/translate.c | 7 ------- target/moxie/cpu.c | 7 +------ target/moxie/translate.c | 6 ------ target/nios2/cpu.c | 7 +------ target/openrisc/cpu.c | 7 +------ target/ppc/translate.c | 6 ------ target/ppc/translate_init.c | 5 +---- target/s390x/cpu.c | 7 +------ target/sh4/cpu.c | 5 +---- target/sh4/translate.c | 7 ------- target/sparc/cpu.c | 5 +---- target/sparc/translate.c | 9 +-------- target/tilegx/cpu.c | 7 +------ target/tricore/cpu.c | 5 +---- target/tricore/translate.c | 5 +---- target/unicore32/cpu.c | 7 +------ target/xtensa/cpu.c | 7 +------ 32 files changed, 40 insertions(+), 165 deletions(-)
PATCH v6 21/50 tcg: Use pointers in TCGOp->args
In reply to Richard HendersonThis limits the indexing into tcg_ctx.temps to initial opcode generation time.
--- tcg/tcg.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
tcg/tcg.h +9 -4
@@ -741,24 +741,29 @@ static inline size_t temp_idx(TCGTemp *ts)return n; } +static inline TCGTemp *idx_temp (size_t n) +{ +return n ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[n]; +} +static inline TCGArg temp_arg (TCGTemp *ts) { -return temp_idx (ts); +return (uintptr_t )ts; }static inline TCGTemp *arg_temp (TCGArg a) { -return a ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[a]; +return (TCGTemp *)a; }static inline size_t arg_index (TCGArg a) { -return a; +return temp_idx (arg_temp (a)); }static inline TCGArg index_arg (size_t n) { -return n; +return temp_arg (idx_temp (n)); }static inline TCGArg tcgv_i32_arg (TCGv_i32 t)
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 21/50] tcg: Use pointers in TCGOp->args
Quoted 4 lines · Richard Henderson
This limits the indexing into tcg_ctx.temps to initial opcode generation time.
Signed-off-by Richard Henderson <[email protected]>
E.
PATCH v6 22/50 tcg: define CF_PARALLEL and use it for TB hashing along with CF_COUNT_MASK
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
This will enable us to decouple code translation from the value of parallel_cpus at any given time. It will also help us minimize TB flushes when generating code via EXCP_ATOMIC.
Note that the declaration of parallel_cpus is brought to exec-all.h to be able to define there the "curr_cflags" inline.
--- include/exec/exec-all.h | 20 +++++++++++++++++++- include/exec/tb-hash-xx.h | 9 ++++++--- include/exec/tb-hash.h | 4 ++-- include/exec/tb-lookup.h | 6 +++--- tcg/tcg.h | 1 - accel/tcg/cpu-exec.c | 45 +++++++++++++++++++++++---------------------- accel/tcg/tcg-runtime.c | 2 +- accel/tcg/translate-all.c | 13 +++++++++---- exec.c | 2 +- tests/qht-bench.c | 2 +- 10 files changed, 65 insertions(+), 39 deletions(-)
include/exec/exec-all.h +19 -1
@@ -325,6 +325,9 @@ struct TranslationBlock {#define CF_USE_ICOUNT 0x20000#define CF_IGNORE_ICOUNT 0x40000/* Do not generate icount code */ #define CF_INVALID 0x80000/* TB is stale. Setters must acquire tb_lock */ +#define CF_PARALLEL 0x100000/* Generate code for a parallel context */ +/* cflags' mask for hashing/comparison */ +#define CF_HASH_MASK (CF_PARALLEL)/* Per-vCPU dynamic tracing state used to generate this TB */ uint32_t trace_vcpu_dstate;
@@ -365,11 +368,26 @@ struct TranslationBlock {uintptr_t jmp_list_first; }; +extern bool parallel_cpus; + +/* Hide the atomic_read to make code a little easier on the eyes */ +static inline uint32_t tb_cflags (const TranslationBlock *tb) +{ +return atomic_read (&tb->cflags); +} + +/* current cflags for hashing/comparison */ +static inline uint32_t curr_cflags (void ) +{ +return parallel_cpus ?CF_PARALLEL :0 ; +} +void tb_free (TranslationBlock *tb);void tb_flush (CPUState *cpu);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr);TranslationBlock *tb_htable_lookup (CPUState *cpu,target_ulong pc, -target_ulong cs_base,uint32_t flags); +target_ulong cs_base,uint32_t flags, +uint32_t cf_mask);void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr);/* GETPC is the true target of the return instruction that we'll execute. */
include/exec/tb-hash-xx.h +6 -3
@@ -48,8 +48,8 @@* xxhash32, customized for input variables that are not guaranteed to be * contiguous in memory. */ -static inline -uint32_t tb_hash_func6 (uint64_t a0,uint64_t b0,uint32_t e,uint32_t f) +static inline uint32_t +tb_hash_func7 (uint64_t a0,uint64_t b0,uint32_t e,uint32_t f,uint32_t g) {uint32_t v1 =TB_HASH_XX_SEED +PRIME32_1 +PRIME32_2 ;uint32_t v2 =TB_HASH_XX_SEED +PRIME32_2 ;
@@ -78,7 +78,7 @@ uint32_t tb_hash_func6(uint64_t a0, uint64_t b0, uint32_t e, uint32_t f) v4 *=PRIME32_1 ; h32 =rol32 (v1,1 ) +rol32 (v2,7 ) +rol32 (v3,12 ) +rol32 (v4,18 ); - h32 +=24 ; + h32 +=28 ; h32 += e *PRIME32_3 ; h32 =rol32 (h32,17 ) *PRIME32_4 ;
@@ -86,6 +86,9 @@ uint32_t tb_hash_func6(uint64_t a0, uint64_t b0, uint32_t e, uint32_t f) h32 += f *PRIME32_3 ; h32 =rol32 (h32,17 ) *PRIME32_4 ; + h32 += g *PRIME32_3 ; + h32 =rol32 (h32,17 ) *PRIME32_4 ; + h32 ^= h32 >>15 ; h32 *=PRIME32_2 ; h32 ^= h32 >>13 ;
include/exec/tb-hash.h +2 -2
@@ -59,9 +59,9 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)static inline uint32_t tb_hash_func (tb_page_addr_t phys_pc,target_ulong pc,uint32_t flags, -uint32_t trace_vcpu_dstate) +uint32_t cf_mask,uint32_t trace_vcpu_dstate) { -return tb_hash_func6 (phys_pc, pc, flags, trace_vcpu_dstate); +return tb_hash_func7 (phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); }#endif
include/exec/tb-lookup.h +3 -3
@@ -21,7 +21,7 @@/* Might cause an exception, so have a longjmp destination ready */ static inline TranslationBlock *tb_lookup__cpu_state (CPUState *cpu,target_ulong *pc,target_ulong *cs_base, -uint32_t *flags) +uint32_t *flags,uint32_t cf_mask) {CPUArchState *env = (CPUArchState *)cpu->env_ptr;TranslationBlock *tb;
@@ -35,10 +35,10 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base, tb->cs_base == *cs_base && tb->flags == *flags && tb->trace_vcpu_dstate == *cpu->trace_dstate && - !(atomic_read(&tb->cflags) & CF_INVALID))) { + (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == cf_mask)) { return tb; } - tb =tb_htable_lookup (cpu, *pc, *cs_base, *flags); + tb =tb_htable_lookup (cpu, *pc, *cs_base, *flags, cf_mask);if (tb ==NULL ) {return NULL ; }
tcg/tcg.h +0 -1
@@ -732,7 +732,6 @@ struct TCGContext { };extern TCGContext tcg_ctx; -extern bool parallel_cpus;static inline size_t temp_idx (TCGTemp *ts) {
accel/tcg/cpu-exec.c +23 -22
110 lines not on this page · raw message
accel/tcg/tcg-runtime.c +1 -1
@@ -151,7 +151,7 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env)target_ulong cs_base, pc;uint32_t flags; - tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags); + tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags,curr_cflags ());if (tb ==NULL ) {return tcg_ctx.code_gen_epilogue; }
accel/tcg/translate-all.c +9 -4
@@ -1101,7 +1101,8 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr)/* remove the TB from the hash list */ phys_pc = tb->page_addr[0 ] + (tb->pc & ~TARGET_PAGE_MASK ); - h =tb_hash_func (phys_pc, tb->pc, tb->flags, tb->trace_vcpu_dstate); + h =tb_hash_func (phys_pc, tb->pc, tb->flags, tb->cflags &CF_HASH_MASK , + tb->trace_vcpu_dstate);qht_remove (&tcg_ctx.tb_ctx.htable, tb, h);/* remove the TB from the page list */
@@ -1245,7 +1246,8 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, }/* add in the hash table */ - h =tb_hash_func (phys_pc, tb->pc, tb->flags, tb->trace_vcpu_dstate); + h =tb_hash_func (phys_pc, tb->pc, tb->flags, tb->cflags &CF_HASH_MASK , + tb->trace_vcpu_dstate);qht_insert (&tcg_ctx.tb_ctx.htable, tb, h);#ifdef CONFIG_USER_ONLY
@@ -1548,7 +1550,8 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,/* we generate a block containing just the instruction modifying the memory. It will ensure that it cannot modify itself */ -tb_gen_code (cpu, current_pc, current_cs_base, current_flags,1 ); +tb_gen_code (cpu, current_pc, current_cs_base, current_flags, +1 |curr_cflags ()); cpu_loop_exit_noexc(cpu); }#endif
@@ -1666,7 +1669,8 @@ static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)/* we generate a block containing just the instruction modifying the memory. It will ensure that it cannot modify itself */ -tb_gen_code (cpu, current_pc, current_cs_base, current_flags,1 ); +tb_gen_code (cpu, current_pc, current_cs_base, current_flags, +1 |curr_cflags ());/* tb_lock will be reset after cpu_loop_exit_noexc longjmps * back into the cpu_exec loop. */ return true;
@@ -1810,6 +1814,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) } cflags = n |CF_LAST_IO ; + cflags |=curr_cflags (); pc = tb->pc; cs_base = tb->cs_base; flags = tb->flags;
exec.c +1 -1
@@ -2435,7 +2435,7 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags)cpu_loop_exit (cpu); }else {cpu_get_tb_cpu_state (env, &pc, &cs_base, &cpu_flags); -tb_gen_code (cpu, pc, cs_base, cpu_flags,1 ); +tb_gen_code (cpu, pc, cs_base, cpu_flags,1 |curr_cflags ());cpu_loop_exit_noexc (cpu); } }
tests/qht-bench.c +1 -1
@@ -103,7 +103,7 @@ static bool is_equal(const void *obj, const void *userp)static inline uint32_t h (unsigned long v) { -return tb_hash_func6 (v,0 ,0 ,0 ); +return tb_hash_func7 (v,0 ,0 ,0 ,0 ); }/*
Signature · 1 line
2.13.6
PATCH v6 23/50 hack dump tb->flags and tb->cflags
In reply to Richard Henderson--- accel/tcg/cpu-exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/cpu-exec.c +2 -2
@@ -146,9 +146,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)uint8_t *tb_ptr = itb->tc.ptr;qemu_log_mask_and_addr (CPU_LOG_EXEC , itb->pc, -"Trace %p [%d: " TARGET_FMT_lx"] %s\n" , +"Trace %p [%d: " TARGET_FMT_lx", %x, %x] %s\n" , itb->tc.ptr, cpu->cpu_index, itb->pc, -lookup_symbol (itb->pc)); + itb->flags, itb->cflags,lookup_symbol (itb->pc));#if defined(DEBUG_DISAS ) if (qemu_loglevel_mask(CPU_LOG_TB_CPU)
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 23/50] hack dump tb->flags and tb->cflags
Quoted 9 lines · Richard Henderson
--- accel/tcg/cpu-exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)accel/tcg/cpu-exec.c +0
-0
accel/tcg/cpu-exec.c static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) · line 151
Quoted 8 lines
accel/tcg/cpu-exec.c +2
-2@@ -146,9 +146,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)uint8_t *tb_ptr = itb->tc.ptr;qemu_log_mask_and_addr (CPU_LOG_EXEC , itb->pc, -"Trace %p [%d: " TARGET_FMT_lx"] %s\n" , +"Trace %p [%d: " TARGET_FMT_lx", %x, %x] %s\n" , itb->tc.ptr, cpu->cpu_index, itb->pc, -lookup_symbol (itb->pc)); + itb->flags, itb->cflags,lookup_symbol (itb->pc));
Given the title, did you indent to submit this patch in the series, or it was just a private patch for debugging?
E.
Re: [Qemu-devel] [PATCH v6 23/50] hack dump tb->flags and tb->cflags
Quoted 12 lines · Emilio G. Cota
Quoted 11 lines · Richard Henderson
--- accel/tcg/cpu-exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)accel/tcg/cpu-exec.c +0
-0@@ -146,9 +146,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)uint8_t *tb_ptr = itb->tc.ptr;
Quoted 9 lines
accel/tcg/cpu-exec.c static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) · line 151
Quoted 6 lines
accel/tcg/cpu-exec.c +2
-2qemu_log_mask_and_addr (CPU_LOG_EXEC , itb->pc, -"Trace %p [%d: " TARGET_FMT_lx"] %s\n" , +"Trace %p [%d: " TARGET_FMT_lx", %x, %x] %s\n" , itb->tc.ptr, cpu->cpu_index, itb->pc, -lookup_symbol (itb->pc)); + itb->flags, itb->cflags,lookup_symbol (itb->pc));Given the title, did you indent to submit this patch in the series, or it was just a private patch for debugging?
It was supposed to be private. Oops.
r~
PATCH v6 24/50 tcg: Add CPUState step_next_tb
In reply to Richard HendersonWe were generating code during tb_invalidate_phys_page_range and check_watchpoint, and (seemingly) discarding the TB, assuming that it would magically be picked up during the next iteration through the cpu_exec loop.
Instead, set a flag in CPUState so that we set cflags to properly request a TB with a single guest insn so that there is no more magic.
--- include/qom/cpu.h | 1 + accel/tcg/cpu-exec.c | 19 +++++++++++++++---- accel/tcg/translate-all.c | 18 ++++-------------- exec.c | 6 +----- 4 files changed, 21 insertions(+), 23 deletions(-)
include/qom/cpu.h +1 -0
@@ -344,6 +344,7 @@ struct CPUState {bool unplug;bool crash_occurred;bool exit_request; +bool step_next_tb;/* updates protected by BQL */ uint32_t interrupt_request;int singlestep_enabled;
accel/tcg/cpu-exec.c +15 -4
@@ -367,13 +367,12 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,static inline TranslationBlock *tb_find (CPUState *cpu,TranslationBlock *last_tb, -int tb_exit) +int tb_exit,uint32_t cf_mask) {TranslationBlock *tb;target_ulong cs_base, pc;uint32_t flags;bool acquired_tb_lock = false; -uint32_t cf_mask =curr_cflags (); tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags, cf_mask);if (tb ==NULL ) {
@@ -501,7 +500,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) } else if (replay_has_exception() && cpu->icount_decr.u16.low + cpu->icount_extra ==0 ) {/* try to cause an exception pending in the log */ -cpu_exec_nocache (cpu,1 ,tb_find (cpu,NULL ,0 ), true); +cpu_exec_nocache (cpu,1 ,tb_find (cpu,NULL ,0 ,curr_cflags ()), true); *ret =-1 ;return true;#endif
@@ -697,7 +696,19 @@ int cpu_exec(CPUState *cpu)int tb_exit =0 ;while (!cpu_handle_interrupt (cpu, &last_tb)) { -TranslationBlock *tb =tb_find (cpu, last_tb, tb_exit); +uint32_t cf_mask =curr_cflags (); +TranslationBlock *tb; + +/* For precise smc, we generate a block containing just the +instruction modifying the memory, ensuring that it cannot +modify itself. We also need to single-step past a +stop-after-access watchpoint. */ +if (cpu->step_next_tb) { + cf_mask |=1 ; + cpu->step_next_tb = false; + } + + tb =tb_find (cpu, last_tb, tb_exit, cf_mask);cpu_loop_exec_tb (cpu, tb, &last_tb, &tb_exit);/* Try to align the host and virtual clocks if the guest is in advance */
accel/tcg/translate-all.c +4 -14
@@ -1463,14 +1463,12 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, int is_cpu_write_access) {TranslationBlock *tb, *tb_next; -#if defined(TARGET_HAS_PRECISE_SMC ) -CPUState *cpu = current_cpu; -CPUArchState *env =NULL ; -#endif tb_page_addr_t tb_start, tb_end;PageDesc *p;int n;#ifdef TARGET_HAS_PRECISE_SMC +CPUState *cpu = current_cpu; +CPUArchState *env =NULL ;int current_tb_not_found = is_cpu_write_access;TranslationBlock *current_tb =NULL ;int current_tb_modified =0 ;
@@ -1547,11 +1545,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,#endif #ifdef TARGET_HAS_PRECISE_SMC if (current_tb_modified) { -/* we generate a block containing just the instruction -modifying the memory. It will ensure that it cannot modify -itself */ -tb_gen_code (cpu, current_pc, current_cs_base, current_flags, -1 |curr_cflags ()); + cpu->step_next_tb = true;cpu_loop_exit_noexc (cpu); }#endif
@@ -1666,11 +1660,7 @@ static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc) p->first_tb =NULL ;#ifdef TARGET_HAS_PRECISE_SMC if (current_tb_modified) { -/* we generate a block containing just the instruction -modifying the memory. It will ensure that it cannot modify -itself */ -tb_gen_code (cpu, current_pc, current_cs_base, current_flags, -1 |curr_cflags ()); + cpu->step_next_tb = true;/* tb_lock will be reset after cpu_loop_exit_noexc longjmps * back into the cpu_exec loop. */ return true;
exec.c +1 -5
@@ -2390,11 +2390,8 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) {CPUState *cpu = current_cpu;CPUClass *cc =CPU_GET_CLASS (cpu); -CPUArchState *env = cpu->env_ptr; -target_ulong pc, cs_base;target_ulong vaddr;CPUWatchpoint *wp; -uint32_t cpu_flags;assert (tcg_enabled ());if (cpu->watchpoint_hit) {
@@ -2434,8 +2431,7 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) cpu->exception_index =EXCP_DEBUG ;cpu_loop_exit (cpu); }else { -cpu_get_tb_cpu_state (env, &pc, &cs_base, &cpu_flags); -tb_gen_code (cpu, pc, cs_base, cpu_flags,1 |curr_cflags ()); + cpu->step_next_tb = true;cpu_loop_exit_noexc (cpu); } }
Signature · 1 line
2.13.6
PATCH v6 25/50 tcg: Include CF_COUNT_MASK in CF_HASH_MASK
In reply to Richard Henderson--- include/exec/exec-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/exec-all.h +1 -1
@@ -327,7 +327,7 @@ struct TranslationBlock {#define CF_INVALID 0x80000/* TB is stale. Setters must acquire tb_lock */ #define CF_PARALLEL 0x100000/* Generate code for a parallel context */ /* cflags' mask for hashing/comparison */ -#define CF_HASH_MASK (CF_PARALLEL) +#define CF_HASH_MASK (CF_COUNT_MASK | CF_PARALLEL)/* Per-vCPU dynamic tracing state used to generate this TB */ uint32_t trace_vcpu_dstate;
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 25/50] tcg: Include CF_COUNT_MASK in CF_HASH_MASK
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Does this patch work with icount for you? On my end, aarch64 stops booting with -icount 1.
E.
Re: [Qemu-devel] [PATCH v6 25/50] tcg: Include CF_COUNT_MASK in CF_HASH_MASK
Quoted 5 lines · Emilio G. Cota
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>Does this patch work with icount for you? On my end, aarch64 stops booting with -icount 1.
Found it -- cpu_io_recompile needs the same sort of fix as in patch 24. I'll post a v7 shortly.
r~
PATCH v6 26/50 tcg: convert tb->cflags reads to tb_cflags(tb)
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Convert all existing readers of tb->cflags to tb_cflags, so that we use atomic_read and therefore avoid undefined behaviour in C11.
Note that the remaining setters/getters of the field are protected by tb_lock, and therefore do not need conversion.
Luckily all readers access the field via 'tb->cflags' (so no foo.cflags, bar->cflags in the code base), which makes the conversion easily scriptable:
FILES=$(git grep 'tb->cflags' target include/exec/gen-icount.h \
accel/tcg/translator.c | cut -f1 -d':' | sort | uniq)
perl -pi -e 's/([^.>])tb->cflags/$1tb_cflags(tb)/g' $FILES perl -pi -e 's/([a-z->.]*)(->|\.)tb->cflags/tb_cflags($1$2tb)/g' $FILES
Then manually fixed the few errors that checkpatch reported.
Compile-tested for all targets.
--- include/exec/gen-icount.h | 8 ++++---- accel/tcg/translator.c | 4 ++-- target/alpha/translate.c | 4 ++-- target/arm/translate-a64.c | 7 ++++--- target/arm/translate.c | 6 +++--- target/cris/translate.c | 6 +++--- target/hppa/translate.c | 2 +- target/i386/translate.c | 48 +++++++++++++++++++++---------------------- target/lm32/translate.c | 14 ++++++------- target/m68k/translate.c | 6 +++--- target/microblaze/translate.c | 6 +++--- target/mips/translate.c | 26 +++++++++++------------ target/moxie/translate.c | 2 +- target/nios2/translate.c | 6 +++--- target/openrisc/translate.c | 6 +++--- target/ppc/translate.c | 6 +++--- target/ppc/translate_init.c | 32 ++++++++++++++--------------- target/s390x/translate.c | 8 ++++---- target/sh4/translate.c | 6 +++--- target/sparc/translate.c | 6 +++--- target/tilegx/translate.c | 2 +- target/tricore/translate.c | 2 +- target/unicore32/translate.c | 6 +++--- target/xtensa/translate.c | 28 ++++++++++++------------- 24 files changed, 124 insertions(+), 123 deletions(-)
include/exec/gen-icount.h +4 -4
@@ -13,7 +13,7 @@ static inline void gen_tb_start(TranslationBlock *tb)TCGv_i32 count, imm; exitreq_label =gen_new_label (); -if (tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (tb) &CF_USE_ICOUNT ) { count =tcg_temp_local_new_i32 (); }else { count =tcg_temp_new_i32 ();
@@ -22,7 +22,7 @@ static inline void gen_tb_start(TranslationBlock *tb)tcg_gen_ld_i32 (count, tcg_ctx.tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u32)); -if (tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (tb) &CF_USE_ICOUNT ) { imm =tcg_temp_new_i32 ();/* We emit a movi with a dummy immediate argument. Keep the insn index * of the movi so that we later (when we know the actual insn count)
@@ -36,7 +36,7 @@ static inline void gen_tb_start(TranslationBlock *tb)tcg_gen_brcondi_i32 (TCG_COND_LT , count,0 , exitreq_label); -if (tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (tb) &CF_USE_ICOUNT ) {tcg_gen_st16_i32 (count, tcg_ctx.tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low)); }
@@ -46,7 +46,7 @@ static inline void gen_tb_start(TranslationBlock *tb)static inline void gen_tb_end (TranslationBlock *tb,int num_insns) { -if (tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (tb) &CF_USE_ICOUNT ) {/* Update the num_insn immediate parameter now that we know * the actual insn count. */ tcg_set_insn_param (icount_start_insn_idx,1 , num_insns);
accel/tcg/translator.c +2 -2
@@ -45,7 +45,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, db->singlestep_enabled = cpu->singlestep_enabled;/* Instruction counting */ - max_insns = db->tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (db->tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -95,7 +95,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,update db->pc_next and db->is_jmp to indicate what should be done next -- either exiting this loop or locate the start of the next instruction. */ -if (db->num_insns == max_insns && (db->tb->cflags &CF_LAST_IO )) { +if (db->num_insns == max_insns && (tb_cflags (db->tb) &CF_LAST_IO )) {/* Accept I/O on the last instruction. */ gen_io_start (); ops->translate_insn (db, cpu);
target/alpha/translate.c +2 -2
@@ -455,7 +455,7 @@ static bool in_superpage(DisasContext *ctx, int64_t addr)static bool use_exit_tb (DisasContext *ctx) { -return ((ctx->base.tb->cflags &CF_LAST_IO ) +return ((tb_cflags (ctx->base.tb) &CF_LAST_IO ) || ctx->base.singlestep_enabled || singlestep); }
@@ -2399,7 +2399,7 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)case 0xC000 :/* RPCC */ va =dest_gpr (ctx, ra); -if (ctx->base.tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->base.tb) &CF_USE_ICOUNT ) {gen_io_start ();gen_helper_load_pcc (va, cpu_env);gen_io_end ();
target/arm/translate-a64.c +4 -3
@@ -348,7 +348,8 @@ static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)/* No direct tb linking with singlestep (either QEMU's or the ARM * debug architecture kind) or deterministic io */ -if (s->base.singlestep_enabled || s->ss_active || (s->base.tb->cflags &CF_LAST_IO )) { +if (s->base.singlestep_enabled || s->ss_active || + (tb_cflags (s->base.tb) &CF_LAST_IO )) {return false; }
@@ -1561,7 +1562,7 @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread,break ; } -if ((s->base.tb->cflags &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) { +if ((tb_cflags (s->base.tb) &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) {gen_io_start (); }
@@ -1592,7 +1593,7 @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, } } -if ((s->base.tb->cflags &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) { +if ((tb_cflags (s->base.tb) &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) {/* I/O operations must end the TB here (whether read or write) */ gen_io_end (); s->base.is_jmp =DISAS_UPDATE ;
target/arm/translate.c +3 -3
@@ -7704,7 +7704,7 @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn)break ; } -if ((s->base.tb->cflags &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) { +if ((tb_cflags (s->base.tb) &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) {gen_io_start (); }
@@ -7795,7 +7795,7 @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn) } } -if ((s->base.tb->cflags &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) { +if ((tb_cflags (s->base.tb) &CF_USE_ICOUNT ) && (ri->type &ARM_CP_IO )) {/* I/O operations must end the TB here (whether read or write) */ gen_io_end ();gen_lookup_tb (s);
@@ -12253,7 +12253,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *dc =container_of (dcbase, DisasContext, base); -if (dc->base.tb->cflags &CF_LAST_IO && dc->condjmp) { +if (tb_cflags (dc->base.tb) &CF_LAST_IO && dc->condjmp) {/* FIXME: This can theoretically happen with self-modifying code. */ cpu_abort (cpu,"IO on conditional branch instruction" ); }
target/cris/translate.c +3 -3
@@ -3141,7 +3141,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -3171,7 +3171,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); } dc->clear_x =1 ;
@@ -3244,7 +3244,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) npc = dc->pc; -if (tb->cflags &CF_LAST_IO ) +if (tb_cflags (tb) &CF_LAST_IO )gen_io_end ();/* Force an update if the per-tb cpu state has changed. */ if (dc->is_jmp == DISAS_NEXT
target/hppa/translate.c +1 -1
@@ -469,7 +469,7 @@ static DisasJumpType gen_illegal(DisasContext *ctx)static bool use_goto_tb (DisasContext *ctx,target_ulong dest) {/* Suppress goto_tb in the case of single-steping and IO. */ -if ((ctx->base.tb->cflags &CF_LAST_IO ) || ctx->base.singlestep_enabled) { +if ((tb_cflags (ctx->base.tb) &CF_LAST_IO ) || ctx->base.singlestep_enabled) {return false; }return true;
target/i386/translate.c +24 -24
182 lines not on this page · raw message
target/lm32/translate.c +7 -7
@@ -880,24 +880,24 @@ static void dec_wcsr(DisasContext *dc)break ;case CSR_IM :/* mark as an io operation because it could cause an interrupt */ -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_wcsr_im (cpu_env, cpu_R[dc->r1]);tcg_gen_movi_tl (cpu_pc, dc->pc +4 ); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end (); } dc->is_jmp =DISAS_UPDATE ;break ;case CSR_IP :/* mark as an io operation because it could cause an interrupt */ -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_wcsr_ip (cpu_env, cpu_R[dc->r1]);tcg_gen_movi_tl (cpu_pc, dc->pc +4 ); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end (); } dc->is_jmp =DISAS_UPDATE ;
@@ -1078,7 +1078,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -1106,7 +1106,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -1119,7 +1119,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) && (dc->pc < next_page_start) && num_insns < max_insns); -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
target/m68k/translate.c +3 -3
@@ -5547,7 +5547,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) dc->done_mac =0 ; dc->writeback_mask =0 ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -5573,7 +5573,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)break ; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -5585,7 +5585,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) (pc_offset) < (TARGET_PAGE_SIZE -32 ) && num_insns < max_insns); -if (tb->cflags &CF_LAST_IO ) +if (tb_cflags (tb) &CF_LAST_IO )gen_io_end ();if (unlikely (cs->singlestep_enabled)) {/* Make sure the pc is updated, and raise a debug exception. */
target/microblaze/translate.c +3 -3
@@ -1666,7 +1666,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -1701,7 +1701,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -1763,7 +1763,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) npc = dc->jmp_pc; } -if (tb->cflags &CF_LAST_IO ) +if (tb_cflags (tb) &CF_LAST_IO )gen_io_end ();/* Force an update if the per-tb cpu state has changed. */ if (dc->is_jmp == DISAS_NEXT
target/mips/translate.c +13 -13
@@ -5327,11 +5327,11 @@ static void gen_mfc0(DisasContext *ctx, TCGv arg, int reg, int sel)switch (sel) {case 0 :/* Mark as an IO operation because we read the time. */ -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_mfc0_count (arg, cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end (); }/* Break the TB to be able to take timer interrupts immediately
@@ -5734,7 +5734,7 @@ static void gen_mtc0(DisasContext *ctx, TCGv arg, int reg, int sel)if (sel !=0 )check_insn (ctx,ISA_MIPS32 ); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }
@@ -6401,7 +6401,7 @@ static void gen_mtc0(DisasContext *ctx, TCGv arg, int reg, int sel)trace_mips_translate_c0 ("mtc0" , rn, reg, sel);/* For simplicity assume that all writes can cause interrupts. */ -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();/* BS_STOP isn't sufficient, we need to ensure we break out of * translated code to check for pending interrupts. */
@@ -6679,11 +6679,11 @@ static void gen_dmfc0(DisasContext *ctx, TCGv arg, int reg, int sel)switch (sel) {case 0 :/* Mark as an IO operation because we read the time. */ -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_mfc0_count (arg, cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end (); }/* Break the TB to be able to take timer interrupts immediately
@@ -7072,7 +7072,7 @@ static void gen_dmtc0(DisasContext *ctx, TCGv arg, int reg, int sel)if (sel !=0 )check_insn (ctx,ISA_MIPS64 ); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }
@@ -7727,7 +7727,7 @@ static void gen_dmtc0(DisasContext *ctx, TCGv arg, int reg, int sel)trace_mips_translate_c0 ("dmtc0" , rn, reg, sel);/* For simplicity assume that all writes can cause interrupts. */ -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();/* BS_STOP isn't sufficient, we need to ensure we break out of * translated code to check for pending interrupts. */
@@ -10756,11 +10756,11 @@ static void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel)gen_store_gpr (t0, rt);break ;case 2 : -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_rdhwr_cc (t0, cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end (); }gen_store_gpr (t0, rt);
@@ -20248,7 +20248,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) ctx.default_tcg_memop_mask = (ctx.insn_flags &ISA_MIPS32R6 ) ?MO_UNALN :MO_ALIGN ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -20274,7 +20274,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) goto done_generating; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -20335,7 +20335,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)if (singlestep)break ; } -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }if (cs->singlestep_enabled && ctx.bstate !=BS_BRANCH ) {
target/moxie/translate.c +1 -1
@@ -832,7 +832,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) ctx.singlestep_enabled =0 ; ctx.bstate =BS_NONE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
target/nios2/translate.c +3 -3
@@ -827,7 +827,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) max_insns =1 ; }else {int page_insns = (TARGET_PAGE_SIZE - (tb->pc &TARGET_PAGE_MASK )) /4 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -854,7 +854,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)break ; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -871,7 +871,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) !tcg_op_buf_full () && num_insns < max_insns); -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
target/openrisc/translate.c +3 -3
@@ -1546,7 +1546,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ;
@@ -1589,7 +1589,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)break ; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }disas_openrisc_insn (dc, cpu);
@@ -1612,7 +1612,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) && (dc->pc < next_page_start) && num_insns < max_insns); -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
target/ppc/translate.c +3 -3
@@ -7261,7 +7261,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) msr_se =1 ;#endif num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -7289,7 +7289,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)LOG_DISAS ("----------------\n" );LOG_DISAS ("nip=" TARGET_FMT_lx" super=%d ir=%d\n" , ctx.nip, ctx.mem_idx, (int )msr_ir); -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO ))gen_io_start ();if (unlikely (need_byteswap (&ctx))) { ctx.opcode =bswap32 (cpu_ldl_code (env, ctx.nip));
@@ -7370,7 +7370,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)exit (1 ); } } -if (tb->cflags &CF_LAST_IO ) +if (tb_cflags (tb) &CF_LAST_IO )gen_io_end ();if (ctx.exception ==POWERPC_EXCP_NONE ) {gen_goto_tb (&ctx,0 , ctx.nip);
target/ppc/translate_init.c +16 -16
@@ -176,11 +176,11 @@ static void spr_write_ureg(DisasContext *ctx, int sprn, int gprn)#if !defined(CONFIG_USER_ONLY )static void spr_read_decr (DisasContext *ctx,int gprn,int sprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_load_decr (cpu_gpr[gprn], cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -188,11 +188,11 @@ static void spr_read_decr(DisasContext *ctx, int gprn, int sprn)static void spr_write_decr (DisasContext *ctx,int sprn,int gprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_store_decr (cpu_env, cpu_gpr[gprn]); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -203,11 +203,11 @@ static void spr_write_decr(DisasContext *ctx, int sprn, int gprn)/* Time base */ static void spr_read_tbl (DisasContext *ctx,int gprn,int sprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_load_tbl (cpu_gpr[gprn], cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -215,11 +215,11 @@ static void spr_read_tbl(DisasContext *ctx, int gprn, int sprn)static void spr_read_tbu (DisasContext *ctx,int gprn,int sprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_load_tbu (cpu_gpr[gprn], cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -240,11 +240,11 @@ static void spr_read_atbu(DisasContext *ctx, int gprn, int sprn)#if !defined(CONFIG_USER_ONLY )static void spr_write_tbl (DisasContext *ctx,int sprn,int gprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_store_tbl (cpu_env, cpu_gpr[gprn]); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -252,11 +252,11 @@ static void spr_write_tbl(DisasContext *ctx, int sprn, int gprn)static void spr_write_tbu (DisasContext *ctx,int sprn,int gprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_store_tbu (cpu_env, cpu_gpr[gprn]); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -284,11 +284,11 @@ static void spr_read_purr(DisasContext *ctx, int gprn, int sprn)/* HDECR */ static void spr_read_hdecr (DisasContext *ctx,int gprn,int sprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_load_hdecr (cpu_gpr[gprn], cpu_env); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
@@ -296,11 +296,11 @@ static void spr_read_hdecr(DisasContext *ctx, int gprn, int sprn)static void spr_write_hdecr (DisasContext *ctx,int sprn,int gprn) { -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_store_hdecr (cpu_env, cpu_gpr[gprn]); -if (ctx->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (ctx->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_stop_exception (ctx); }
target/s390x/translate.c +4 -4
@@ -554,7 +554,7 @@ static void gen_op_calc_cc(DisasContext *s)static bool use_exit_tb (DisasContext *s) {return (s->singlestep_enabled || - (s->tb->cflags &CF_LAST_IO ) || + (tb_cflags (s->tb) &CF_LAST_IO ) || (s->tb->flags &FLAG_MASK_PER )); }
@@ -5881,7 +5881,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -5906,7 +5906,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)break ; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -5925,7 +5925,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) } }while (status ==NO_EXIT ); -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
target/sh4/translate.c +3 -3
@@ -2248,7 +2248,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) (ctx.tbflags & (1 << SR_RB))) * 0x10; ctx.fbank = ctx.tbflags &FPSCR_FR ?0x10 :0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -2292,7 +2292,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)break ; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -2300,7 +2300,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)decode_opc (&ctx); ctx.pc +=2 ; } -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
target/sparc/translate.c +3 -3
@@ -5772,7 +5772,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock * tb)#endif num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -5801,7 +5801,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock * tb) goto exit_gen_loop; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -5828,7 +5828,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock * tb) num_insns < max_insns); exit_gen_loop: -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }if (!dc->is_br) {
target/tilegx/translate.c +1 -1
@@ -2378,7 +2378,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)uint64_t pc_start = tb->pc;uint64_t next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ;int num_insns =0 ; -int max_insns = tb->cflags &CF_COUNT_MASK ; +int max_insns =tb_cflags (tb) &CF_COUNT_MASK ; dc->pc = pc_start; dc->mmuidx =0 ;
target/tricore/translate.c +1 -1
@@ -8790,7 +8790,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)int num_insns, max_insns; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
target/unicore32/translate.c +3 -3
@@ -1900,7 +1900,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) cpu_F1d =tcg_temp_new_i64 (); next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; num_insns =0 ; - max_insns = tb->cflags &CF_COUNT_MASK ; + max_insns =tb_cflags (tb) &CF_COUNT_MASK ;if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; }
@@ -1933,7 +1933,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) goto done_generating; } -if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -1958,7 +1958,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) dc->pc < next_page_start && num_insns < max_insns); -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {if (dc->condjmp) {/* FIXME: This can theoretically happen with self-modifying code. */
target/xtensa/translate.c +14 -14
@@ -517,12 +517,12 @@ static bool gen_check_sr(DisasContext *dc, uint32_t sr, unsigned access)static bool gen_rsr_ccount (DisasContext *dc,TCGv_i32 d,uint32_t sr) { -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_update_ccount (cpu_env);tcg_gen_mov_i32 (d, cpu_SR[sr]); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end ();return true; }
@@ -702,11 +702,11 @@ static bool gen_wsr_cpenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)static void gen_check_interrupts (DisasContext *dc) { -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_check_interrupts (cpu_env); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end (); } }
@@ -760,11 +760,11 @@ static bool gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)static bool gen_wsr_ccount (DisasContext *dc,uint32_t sr,TCGv_i32 v) { -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_wsr_ccount (cpu_env, v); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_jumpi_check_loop_end (dc,0 );return true;
@@ -801,11 +801,11 @@ static bool gen_wsr_ccompare(DisasContext *dc, uint32_t sr, TCGv_i32 v)tcg_gen_mov_i32 (cpu_SR[sr], v);tcg_gen_andi_i32 (cpu_SR[INTSET ], cpu_SR[INTSET ], ~int_bit); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_update_ccompare (cpu_env, tmp); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end ();gen_jumpi_check_loop_end (dc,0 ); ret = true;
@@ -900,11 +900,11 @@ static void gen_waiti(DisasContext *dc, uint32_t imm4)TCGv_i32 pc =tcg_const_i32 (dc->next_pc);TCGv_i32 intlevel =tcg_const_i32 (imm4); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_start (); }gen_helper_waiti (cpu_env, pc, intlevel); -if (dc->tb->cflags &CF_USE_ICOUNT ) { +if (tb_cflags (dc->tb) &CF_USE_ICOUNT ) {gen_io_end (); }tcg_temp_free (pc);
@@ -3126,7 +3126,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)CPUXtensaState *env = cs->env_ptr;DisasContext dc;int insn_count =0 ; -int max_insns = tb->cflags &CF_COUNT_MASK ; +int max_insns =tb_cflags (tb) &CF_COUNT_MASK ;uint32_t pc_start = tb->pc;uint32_t next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ;
@@ -3162,7 +3162,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)gen_tb_start (tb); -if ((tb->cflags &CF_USE_ICOUNT ) && +if ((tb_cflags (tb) &CF_USE_ICOUNT ) && (tb->flags &XTENSA_TBFLAG_YIELD )) {tcg_gen_insn_start (dc.pc); ++insn_count;
@@ -3194,7 +3194,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)break ; } -if (insn_count == max_insns && (tb->cflags &CF_LAST_IO )) { +if (insn_count == max_insns && (tb_cflags (tb) &CF_LAST_IO )) {gen_io_start (); }
@@ -3235,7 +3235,7 @@ done:tcg_temp_free (dc.next_icount); } -if (tb->cflags &CF_LAST_IO ) { +if (tb_cflags (tb) &CF_LAST_IO ) {gen_io_end (); }
Signature · 1 line
2.13.6
PATCH v6 27/50 target/arm: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/arm/helper-a64.h | 4 ++++ target/arm/helper-a64.c | 38 ++++++++++++++++++++++++++++++++------ target/arm/op_helper.c | 7 ------- target/arm/translate-a64.c | 31 +++++++++++++++++++++++++------ target/arm/translate.c | 9 +++++++-- 5 files changed, 68 insertions(+), 21 deletions(-)
target/arm/helper-a64.h +4 -0
@@ -43,4 +43,8 @@ DEF_HELPER_FLAGS_2(fcvtx_f64_to_f32, TCG_CALL_NO_RWG, f32, f64, env) DEF_HELPER_FLAGS_3(crc32_64, TCG_CALL_NO_RWG_SE, i64, i64, i64, i32) DEF_HELPER_FLAGS_3(crc32c_64, TCG_CALL_NO_RWG_SE, i64, i64, i64, i32) DEF_HELPER_FLAGS_4(paired_cmpxchg64_le, TCG_CALL_NO_WG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4 (paired_cmpxchg64_le_parallel,TCG_CALL_NO_WG , + i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(paired_cmpxchg64_be, TCG_CALL_NO_WG, i64, env, i64, i64, i64) +DEF_HELPER_FLAGS_4 (paired_cmpxchg64_be_parallel,TCG_CALL_NO_WG , + i64, env, i64, i64, i64)
target/arm/helper-a64.c +32 -6
@@ -430,8 +430,9 @@ uint64_t HELPER(crc32c_64)(uint64_t acc, uint64_t val, uint32_t bytes) }/* Returns 0 on success; 1 otherwise. */ -uint64_t HELPER (paired_cmpxchg64_le )(CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi) +static uint64_t do_paired_cmpxchg64_le (CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi, +bool parallel) {uintptr_t ra =GETPC ();Int128 oldv, cmpv, newv;
@@ -440,7 +441,7 @@ uint64_t HELPER(paired_cmpxchg64_le)(CPUARMState *env, uint64_t addr, cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); newv =int128_make128 (new_lo, new_hi); -if (parallel_cpus) { +if (parallel) {#ifndef CONFIG_ATOMIC128 cpu_loop_exit_atomic (ENV_GET_CPU (env), ra);#else
@@ -484,8 +485,21 @@ uint64_t HELPER(paired_cmpxchg64_le)(CPUARMState *env, uint64_t addr,return !success; } -uint64_t HELPER (paired_cmpxchg64_be )(CPUARMState *env,uint64_t addr, -uint64_t new_lo,uint64_t new_hi) +uint64_t HELPER (paired_cmpxchg64_le )(CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi) +{ +return do_paired_cmpxchg64_le (env, addr, new_lo, new_hi, false); +} + +uint64_t HELPER (paired_cmpxchg64_le_parallel )(CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi) +{ +return do_paired_cmpxchg64_le (env, addr, new_lo, new_hi, true); +} + +static uint64_t do_paired_cmpxchg64_be (CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi, +bool parallel) {uintptr_t ra =GETPC ();Int128 oldv, cmpv, newv;
@@ -494,7 +508,7 @@ uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr, cmpv =int128_make128 (env->exclusive_val, env->exclusive_high); newv =int128_make128 (new_lo, new_hi); -if (parallel_cpus) { +if (parallel) {#ifndef CONFIG_ATOMIC128 cpu_loop_exit_atomic (ENV_GET_CPU (env), ra);#else
@@ -537,3 +551,15 @@ uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr,return !success; } + +uint64_t HELPER (paired_cmpxchg64_be )(CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi) +{ +return do_paired_cmpxchg64_be (env, addr, new_lo, new_hi, false); +} + +uint64_t HELPER (paired_cmpxchg64_be_parallel )(CPUARMState *env,uint64_t addr, +uint64_t new_lo,uint64_t new_hi) +{ +return do_paired_cmpxchg64_be (env, addr, new_lo, new_hi, true); +}
target/arm/op_helper.c +0 -7
@@ -502,13 +502,6 @@ void HELPER(yield)(CPUARMState *env)ARMCPU *cpu =arm_env_get_cpu (env);CPUState *cs =CPU (cpu); -/* When running in MTTCG we don't generate jumps to the yield and -* WFE helpers as it won't affect the scheduling of other vCPUs. -* If we wanted to more completely model WFE/SEV so we don't busy -* spin unnecessarily we would need to do something more involved. -*/ -g_assert (!parallel_cpus); -/* This is a non-trappable hint instruction that generally indicates * that the guest is currently busy-looping. Yield control back to the * top level loop so that a more deserving VCPU has a chance to run.
target/arm/translate-a64.c +25 -6
@@ -1336,13 +1336,18 @@ static void handle_hint(DisasContext *s, uint32_t insn,case 3 :/* WFI */ s->base.is_jmp =DISAS_WFI ;return ; +/* When running in MTTCG we don't generate jumps to the yield and +* WFE helpers as it won't affect the scheduling of other vCPUs. +* If we wanted to more completely model WFE/SEV so we don't busy +* spin unnecessarily we would need to do something more involved. +*/ case 1 :/* YIELD */ -if (!parallel_cpus) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { s->base.is_jmp =DISAS_YIELD ; }return ;case 2 :/* WFE */ -if (!parallel_cpus) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) { s->base.is_jmp =DISAS_WFE ; }return ;
@@ -1931,11 +1936,25 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2, MO_64 | MO_ALIGN | s->be_data);tcg_gen_setcond_i64 (TCG_COND_NE , tmp, tmp, cpu_exclusive_val); }else if (s->be_data ==MO_LE ) { -gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); +if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +gen_helper_paired_cmpxchg64_le_parallel (tmp, cpu_env, + cpu_exclusive_addr, +cpu_reg (s, rt), +cpu_reg (s, rt2)); + }else { +gen_helper_paired_cmpxchg64_le (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); + } }else { -gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, -cpu_reg (s, rt),cpu_reg (s, rt2)); +if (tb_cflags (s->base.tb) &CF_PARALLEL ) { +gen_helper_paired_cmpxchg64_be_parallel (tmp, cpu_env, + cpu_exclusive_addr, +cpu_reg (s, rt), +cpu_reg (s, rt2)); + }else { +gen_helper_paired_cmpxchg64_be (tmp, cpu_env, cpu_exclusive_addr, +cpu_reg (s, rt),cpu_reg (s, rt2)); + } } }else { tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,
target/arm/translate.c +7 -2
@@ -4546,8 +4546,13 @@ static void gen_exception_return(DisasContext *s, TCGv_i32 pc)static void gen_nop_hint (DisasContext *s,int val) {switch (val) { +/* When running in MTTCG we don't generate jumps to the yield and +* WFE helpers as it won't affect the scheduling of other vCPUs. +* If we wanted to more completely model WFE/SEV so we don't busy +* spin unnecessarily we would need to do something more involved. +*/ case 1 :/* yield */ -if (!parallel_cpus) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) {gen_set_pc_im (s, s->pc); s->base.is_jmp =DISAS_YIELD ; }
@@ -4557,7 +4562,7 @@ static void gen_nop_hint(DisasContext *s, int val) s->base.is_jmp =DISAS_WFI ;break ;case 2 :/* wfe */ -if (!parallel_cpus) { +if (!(tb_cflags (s->base.tb) &CF_PARALLEL )) {gen_set_pc_im (s, s->pc); s->base.is_jmp =DISAS_WFE ; }
Signature · 1 line
2.13.6
PATCH v6 28/50 target/hppa: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/hppa/helper.h | 2 ++ target/hppa/op_helper.c | 32 ++++++++++++++++++++++++++++---- target/hppa/translate.c | 12 ++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-)
target/hppa/helper.h +2 -0
@@ -3,7 +3,9 @@ DEF_HELPER_FLAGS_2(tsv, TCG_CALL_NO_WG, void, env, tl) DEF_HELPER_FLAGS_2(tcond, TCG_CALL_NO_WG, void, env, tl) DEF_HELPER_FLAGS_3(stby_b, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3(stby_b_parallel, TCG_CALL_NO_WG, void, env, tl, tl) DEF_HELPER_FLAGS_3(stby_e, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3(stby_e_parallel, TCG_CALL_NO_WG, void, env, tl, tl) DEF_HELPER_FLAGS_1(probe_r, TCG_CALL_NO_RWG_SE, tl, tl)DEF_HELPER_FLAGS_1 (probe_w,TCG_CALL_NO_RWG_SE , tl, tl)
target/hppa/op_helper.c +28 -4
@@ -76,7 +76,8 @@ static void atomic_store_3(CPUHPPAState *env, target_ulong addr, uint32_t val,#endif } -void HELPER (stby_b )(CPUHPPAState *env,target_ulong addr,target_ulong val) +static void do_stby_b (CPUHPPAState *env,target_ulong addr,target_ulong val, +bool parallel) {uintptr_t ra =GETPC ();
@@ -89,7 +90,7 @@ void HELPER(stby_b)(CPUHPPAState *env, target_ulong addr, target_ulong val)break ;case 1 :/* The 3 byte store must appear atomic. */ -if (parallel_cpus) { +if (parallel) {atomic_store_3 (env, addr, val,0x00ffffffu , ra); }else {cpu_stb_data_ra (env, addr, val >>16 , ra);
@@ -102,14 +103,26 @@ void HELPER(stby_b)(CPUHPPAState *env, target_ulong addr, target_ulong val) } } -void HELPER (stby_e )(CPUHPPAState *env,target_ulong addr,target_ulong val) +void HELPER (stby_b )(CPUHPPAState *env,target_ulong addr,target_ulong val) +{ +do_stby_b (env, addr, val, false); +} + +void HELPER (stby_b_parallel )(CPUHPPAState *env,target_ulong addr, +target_ulong val) +{ +do_stby_b (env, addr, val, true); +} + +static void do_stby_e (CPUHPPAState *env,target_ulong addr,target_ulong val, +bool parallel) {uintptr_t ra =GETPC ();switch (addr &3 ) {case 3 :/* The 3 byte store must appear atomic. */ -if (parallel_cpus) { +if (parallel) {atomic_store_3 (env, addr -3 , val,0xffffff00u , ra); }else {cpu_stw_data_ra (env, addr -3 , val >>16 , ra);
@@ -132,6 +145,17 @@ void HELPER(stby_e)(CPUHPPAState *env, target_ulong addr, target_ulong val) } } +void HELPER (stby_e )(CPUHPPAState *env,target_ulong addr,target_ulong val) +{ +do_stby_e (env, addr, val, false); +} + +void HELPER (stby_e_parallel )(CPUHPPAState *env,target_ulong addr, +target_ulong val) +{ +do_stby_e (env, addr, val, true); +} +target_ulong HELPER (probe_r )(target_ulong addr) {return page_check_range (addr,1 ,PAGE_READ );
target/hppa/translate.c +10 -2
@@ -2291,9 +2291,17 @@ static DisasJumpType trans_stby(DisasContext *ctx, uint32_t insn, val =load_gpr (ctx, rt);if (a) { -gen_helper_stby_e (cpu_env, addr, val); +if (tb_cflags (ctx->base.tb) &CF_PARALLEL ) { +gen_helper_stby_e_parallel (cpu_env, addr, val); + }else { +gen_helper_stby_e (cpu_env, addr, val); + } }else { -gen_helper_stby_b (cpu_env, addr, val); +if (tb_cflags (ctx->base.tb) &CF_PARALLEL ) { +gen_helper_stby_b_parallel (cpu_env, addr, val); + }else { +gen_helper_stby_b (cpu_env, addr, val); + } }if (m) {
Signature · 1 line
2.13.6
PATCH v6 29/50 target/i386: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/i386/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/translate.c +2 -2
@@ -5265,7 +5265,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)if (!(s->cpuid_ext_features &CPUID_EXT_CX16 )) goto illegal_op;gen_lea_modrm (env, s, modrm); -if ((s->prefix &PREFIX_LOCK ) && parallel_cpus) { +if ((s->prefix &PREFIX_LOCK ) && (tb_cflags (s->base.tb) &CF_PARALLEL )) {gen_helper_cmpxchg16b (cpu_env, cpu_A0); }else {gen_helper_cmpxchg16b_unlocked (cpu_env, cpu_A0);
@@ -5276,7 +5276,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)if (!(s->cpuid_features &CPUID_CX8 )) goto illegal_op;gen_lea_modrm (env, s, modrm); -if ((s->prefix &PREFIX_LOCK ) && parallel_cpus) { +if ((s->prefix &PREFIX_LOCK ) && (tb_cflags (s->base.tb) &CF_PARALLEL )) {gen_helper_cmpxchg8b (cpu_env, cpu_A0); }else {gen_helper_cmpxchg8b_unlocked (cpu_env, cpu_A0);
Signature · 1 line
2.13.6
PATCH v6 30/50 target/m68k: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/m68k/helper.h | 1 + target/m68k/op_helper.c | 33 ++++++++++++++++++++------------- target/m68k/translate.c | 12 ++++++++++-- 3 files changed, 31 insertions(+), 15 deletions(-)
target/m68k/helper.h +1 -0
@@ -11,6 +11,7 @@ DEF_HELPER_2(set_sr, void, env, i32) DEF_HELPER_3(movec, void, env, i32, i32) DEF_HELPER_4(cas2w, void, env, i32, i32, i32) DEF_HELPER_4(cas2l, void, env, i32, i32, i32) +DEF_HELPER_4(cas2l_parallel, void, env, i32, i32, i32)#define dh_alias_fp ptr#define dh_ctype_fp FPReg *
target/m68k/op_helper.c +20 -13
@@ -361,6 +361,7 @@ void HELPER(divsll)(CPUM68KState *env, int numr, int regr, int32_t den) env->dregs[numr] = quot; } +/* We're executing in a serial context -- no need to be atomic. */ void HELPER (cas2w )(CPUM68KState *env,uint32_t regs,uint32_t a1,uint32_t a2) {uint32_t Dc1 =extract32 (regs,9 ,3 );
@@ -374,17 +375,11 @@ void HELPER(cas2w)(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2)int16_t l1, l2;uintptr_t ra =GETPC (); -if (parallel_cpus) { -/* Tell the main loop we need to serialize this insn. */ -cpu_loop_exit_atomic (ENV_GET_CPU (env), ra); - }else { -/* We're executing in a serial context -- no need to be atomic. */ - l1 =cpu_lduw_data_ra (env, a1, ra); - l2 =cpu_lduw_data_ra (env, a2, ra); -if (l1 == c1 && l2 == c2) { -cpu_stw_data_ra (env, a1, u1, ra); -cpu_stw_data_ra (env, a2, u2, ra); - } + l1 =cpu_lduw_data_ra (env, a1, ra); + l2 =cpu_lduw_data_ra (env, a2, ra); +if (l1 == c1 && l2 == c2) { +cpu_stw_data_ra (env, a1, u1, ra); +cpu_stw_data_ra (env, a2, u2, ra); }if (c1 != l1) {
@@ -399,7 +394,8 @@ void HELPER(cas2w)(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2) env->dregs[Dc2] =deposit32 (env->dregs[Dc2],0 ,16 , l2); } -void HELPER (cas2l )(CPUM68KState *env,uint32_t regs,uint32_t a1,uint32_t a2) +static void do_cas2l (CPUM68KState *env,uint32_t regs,uint32_t a1,uint32_t a2, +bool parallel) {uint32_t Dc1 =extract32 (regs,9 ,3 );uint32_t Dc2 =extract32 (regs,6 ,3 );
@@ -416,7 +412,7 @@ void HELPER(cas2l)(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2)TCGMemOpIdx oi;#endif -if (parallel_cpus) { +if (parallel) {/* We're executing in a parallel context -- must be atomic. */ #ifdef CONFIG_ATOMIC64 uint64_t c, u, l;
@@ -470,6 +466,17 @@ void HELPER(cas2l)(CPUM68KState *env, uint32_t regs, uint32_t a1, uint32_t a2) env->dregs[Dc2] = l2; } +void HELPER (cas2l )(CPUM68KState *env,uint32_t regs,uint32_t a1,uint32_t a2) +{ +do_cas2l (env, regs, a1, a2, false); +} + +void HELPER (cas2l_parallel )(CPUM68KState *env,uint32_t regs,uint32_t a1, +uint32_t a2) +{ +do_cas2l (env, regs, a1, a2, true); +} +struct bf_data {uint32_t addr;uint32_t bofs;
target/m68k/translate.c +10 -2
@@ -2312,7 +2312,11 @@ DISAS_INSN(cas2w) (REG (ext1,6 ) <<3 ) | (REG (ext2,0 ) <<6 ) | (REG(ext1, 0) << 9)); -gen_helper_cas2w (cpu_env, regs, addr1, addr2); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_exit_atomic (cpu_env); + }else { +gen_helper_cas2w (cpu_env, regs, addr1, addr2); + }tcg_temp_free (regs);/* Note that cas2w also assigned to env->cc_op. */
@@ -2358,7 +2362,11 @@ DISAS_INSN(cas2l) (REG (ext1,6 ) <<3 ) | (REG (ext2,0 ) <<6 ) | (REG(ext1, 0) << 9)); -gen_helper_cas2l (cpu_env, regs, addr1, addr2); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_cas2l_parallel (cpu_env, regs, addr1, addr2); + }else { +gen_helper_cas2l (cpu_env, regs, addr1, addr2); + }tcg_temp_free (regs);/* Note that cas2l also assigned to env->cc_op. */
Signature · 1 line
2.13.6
PATCH v6 31/50 target/s390x: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/s390x/helper.h | 4 +++ target/s390x/mem_helper.c | 80 +++++++++++++++++++++++++++++++++++++---------- target/s390x/translate.c | 26 ++++++++++++--- 3 files changed, 88 insertions(+), 22 deletions(-)
target/s390x/helper.h +4 -0
@@ -34,7 +34,9 @@ DEF_HELPER_3(celgb, i64, env, i64, i32) DEF_HELPER_3(cdlgb, i64, env, i64, i32) DEF_HELPER_3(cxlgb, i64, env, i64, i32) DEF_HELPER_4(cdsg, void, env, i64, i32, i32) +DEF_HELPER_4(cdsg_parallel, void, env, i64, i32, i32) DEF_HELPER_4(csst, i32, env, i32, i64, i64) +DEF_HELPER_4(csst_parallel, i32, env, i32, i64, i64) DEF_HELPER_FLAGS_3(aeb, TCG_CALL_NO_WG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(adb, TCG_CALL_NO_WG, i64, env, i64, i64)DEF_HELPER_FLAGS_5 (axb,TCG_CALL_NO_WG , i64, env, i64, i64, i64, i64)
@@ -106,7 +108,9 @@ DEF_HELPER_FLAGS_2(sfas, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_1(popcnt, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_2(stfle, i32, env, i64) DEF_HELPER_FLAGS_2(lpq, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(lpq_parallel, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_4(stpq, TCG_CALL_NO_WG, void, env, i64, i64, i64) +DEF_HELPER_FLAGS_4(stpq_parallel, TCG_CALL_NO_WG, void, env, i64, i64, i64) DEF_HELPER_4(mvcos, i32, env, i64, i64, i64) DEF_HELPER_4(cu12, i32, env, i32, i32, i32)DEF_HELPER_4 (cu14, i32, env, i32, i32, i32)
target/s390x/mem_helper.c +63 -17
176 lines not on this page · raw message
target/s390x/translate.c +21 -5
@@ -1966,7 +1966,11 @@ static ExitStatus op_cdsg(DisasContext *s, DisasOps *o) addr =get_address (s,0 , b2, d2); t_r1 =tcg_const_i32 (r1); t_r3 =tcg_const_i32 (r3); -gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_cdsg_parallel (cpu_env, addr, t_r1, t_r3); + }else { +gen_helper_cdsg (cpu_env, addr, t_r1, t_r3); + }tcg_temp_free_i64 (addr);tcg_temp_free_i32 (t_r1);tcg_temp_free_i32 (t_r3);
@@ -1980,7 +1984,11 @@ static ExitStatus op_csst(DisasContext *s, DisasOps *o)int r3 =get_field (s->fields, r3);TCGv_i32 t_r3 =tcg_const_i32 (r3); -gen_helper_csst (cc_op, cpu_env, t_r3, o->in1, o->in2); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_csst_parallel (cc_op, cpu_env, t_r3, o->in1, o->in2); + }else { +gen_helper_csst (cc_op, cpu_env, t_r3, o->in1, o->in2); + }tcg_temp_free_i32 (t_r3);set_cc_static (s);
@@ -2937,7 +2945,7 @@ static ExitStatus op_lpd(DisasContext *s, DisasOps *o)TCGMemOp mop = s->insn->data;/* In a parallel context, stop the world and single step. */ -if (parallel_cpus) { +if (tb_cflags (s->tb) &CF_PARALLEL ) {potential_page_fault (s);gen_exception (EXCP_ATOMIC );return EXIT_NORETURN ;
@@ -2958,7 +2966,11 @@ static ExitStatus op_lpd(DisasContext *s, DisasOps *o)static ExitStatus op_lpq (DisasContext *s,DisasOps *o) { -gen_helper_lpq (o->out, cpu_env, o->in2); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_lpq_parallel (o->out, cpu_env, o->in2); + }else { +gen_helper_lpq (o->out, cpu_env, o->in2); + }return_low128 (o->out2);return NO_EXIT ; }
@@ -4279,7 +4291,11 @@ static ExitStatus op_stmh(DisasContext *s, DisasOps *o)static ExitStatus op_stpq (DisasContext *s,DisasOps *o) { -gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); +if (tb_cflags (s->tb) &CF_PARALLEL ) { +gen_helper_stpq_parallel (cpu_env, o->in2, o->out2, o->out); + }else { +gen_helper_stpq (cpu_env, o->in2, o->out2, o->out); + }return NO_EXIT ; }
Signature · 1 line
2.13.6
PATCH v6 32/50 target/sh4: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/sh4/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/sh4/translate.c +1 -1
@@ -521,7 +521,7 @@ static void _decode_opc(DisasContext * ctx)/* Detect the start of a gUSA region. If so, update envflags and end the TB. This will allow us to see the end of the region (stored in R0) in the next TB. */ -if (B11_8 ==15 && B7_0s <0 && parallel_cpus) { +if (B11_8 ==15 && B7_0s <0 && (tb_cflags (ctx->tb) &CF_PARALLEL )) { ctx->envflags =deposit32 (ctx->envflags,GUSA_SHIFT ,8 , B7_0s); ctx->bstate =BS_STOP ; }
Signature · 1 line
2.13.6
PATCH v6 33/50 target/sparc: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
--- target/sparc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/sparc/translate.c +1 -1
@@ -2442,7 +2442,7 @@ static void gen_ldstub_asi(DisasContext *dc, TCGv dst, TCGv addr, int insn)default :/* ??? In theory, this should be raise DAE_invalid_asi. But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ -if (parallel_cpus) { +if (tb_cflags (dc->tb) &CF_PARALLEL ) {gen_helper_exit_atomic (cpu_env); }else {TCGv_i32 r_asi =tcg_const_i32 (da.asi);
Signature · 1 line
2.13.6
PATCH v6 34/50 tcg: check CF_PARALLEL instead of parallel_cpus
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Thereby decoupling the resulting translated code from the current state of the system.
The tb->cflags field is not passed to tcg generation functions. So we add a field to TCGContext, storing there a copy of tb->cflags.
Most architectures have <= 32 registers, which results in a 4-byte hole in TCGContext. Use this hole for the new field.
--- tcg/tcg.h | 1 + accel/tcg/translate-all.c | 1 + tcg/tcg-op.c | 10 +++++----- 3 files changed, 7 insertions(+), 5 deletions(-)
tcg/tcg.h +1 -0
@@ -656,6 +656,7 @@ struct TCGContext {uintptr_t *tb_jmp_target_addr;/* tb->jmp_target_arg if !direct_jump */ TCGRegSet reserved_regs; +uint32_t tb_cflags;/* cflags of the current TB */ intptr_t current_frame_offset;intptr_t frame_start;intptr_t frame_end;
accel/tcg/translate-all.c +1 -0
@@ -1296,6 +1296,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->flags = flags; tb->cflags = cflags; tb->trace_vcpu_dstate = *cpu->trace_dstate; + tcg_ctx.tb_cflags = cflags;#ifdef CONFIG_PROFILER tcg_ctx.tb_count1++;/* includes aborted translations because of
tcg/tcg-op.c +5 -5
@@ -121,7 +121,7 @@ void tcg_gen_op6(TCGOpcode opc, TCGArg a1, TCGArg a2, TCGArg a3,void tcg_gen_mb (TCGBar mb_type) { -if (parallel_cpus) { +if (tcg_ctx.tb_cflags &CF_PARALLEL ) {tcg_gen_op1 (INDEX_op_mb, mb_type); } }
@@ -2780,7 +2780,7 @@ void tcg_gen_atomic_cmpxchg_i32(TCGv_i32 retv, TCGv addr, TCGv_i32 cmpv, { memop =tcg_canonicalize_memop (memop,0 ,0 ); -if (!parallel_cpus) { +if (!(tcg_ctx.tb_cflags &CF_PARALLEL )) {TCGv_i32 t1 =tcg_temp_new_i32 ();TCGv_i32 t2 =tcg_temp_new_i32 ();
@@ -2824,7 +2824,7 @@ void tcg_gen_atomic_cmpxchg_i64(TCGv_i64 retv, TCGv addr, TCGv_i64 cmpv, { memop =tcg_canonicalize_memop (memop,1 ,0 ); -if (!parallel_cpus) { +if (!(tcg_ctx.tb_cflags &CF_PARALLEL )) {TCGv_i64 t1 =tcg_temp_new_i64 ();TCGv_i64 t2 =tcg_temp_new_i64 ();
@@ -3001,7 +3001,7 @@ static void * const table_##NAME[16] = { \ void tcg_gen_atomic_##NAME##_i32 \ (TCGv_i32 ret, TCGv addr, TCGv_i32 val, TCGArg idx, TCGMemOp memop) \ { \ - if (parallel_cpus) { \ + if (tcg_ctx.tb_cflags & CF_PARALLEL) { \ do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \ } else { \ do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
@@ -3011,7 +3011,7 @@ void tcg_gen_atomic_##NAME##_i32 \ void tcg_gen_atomic_##NAME##_i64 \ (TCGv_i64 ret, TCGv addr, TCGv_i64 val, TCGArg idx, TCGMemOp memop) \ { \ - if (parallel_cpus) { \ + if (tcg_ctx.tb_cflags & CF_PARALLEL) { \ do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \ } else { \ do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
Signature · 1 line
2.13.6
PATCH v6 35/50 cpu-exec: lookup/generate TB outside exclusive region during step_atomic
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Now that all code generation has been converted to check CF_PARALLEL, we can generate !CF_PARALLEL code without having yet set !parallel_cpus -- and therefore without having to be in the exclusive region during cpu_exec_step_atomic.
While at it, merge cpu_exec_step into cpu_exec_step_atomic.
--- accel/tcg/cpu-exec.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
accel/tcg/cpu-exec.c +14 -16
@@ -223,30 +223,40 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, }#endif -static void cpu_exec_step (CPUState *cpu) +void cpu_exec_step_atomic (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu);TranslationBlock *tb;target_ulong cs_base, pc;uint32_t flags;uint32_t cflags =1 |CF_IGNORE_ICOUNT ; +uint32_t cf_mask = cflags &CF_HASH_MASK ;if (sigsetjmp (cpu->jmp_env,0 ) ==0 ) { - tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags, - cflags &CF_HASH_MASK ); + tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags, cf_mask);if (tb ==NULL ) {mmap_lock ();tb_lock (); - tb =tb_gen_code (cpu, pc, cs_base, flags, cflags); + tb =tb_htable_lookup (cpu, pc, cs_base, flags, cf_mask); +if (likely (tb ==NULL )) { + tb =tb_gen_code (cpu, pc, cs_base, flags, cflags); + }tb_unlock ();mmap_unlock (); } +start_exclusive (); + +/* Since we got here, we know that parallel_cpus must be true. */ + parallel_cpus = false; cc->cpu_exec_enter (cpu);/* execute the generated code */ trace_exec_tb (tb, pc);cpu_tb_exec (cpu, tb); cc->cpu_exec_exit (cpu); + parallel_cpus = true; + +end_exclusive (); }else {/* We may have exited due to another problem here, so we need * to reset any tb_locks we may have taken but didn't release.
@@ -260,18 +270,6 @@ static void cpu_exec_step(CPUState *cpu) } } -void cpu_exec_step_atomic (CPUState *cpu) -{ -start_exclusive (); - -/* Since we got here, we know that parallel_cpus must be true. */ - parallel_cpus = false; -cpu_exec_step (cpu); - parallel_cpus = true; - -end_exclusive (); -} -struct tb_desc {target_ulong pc;target_ulong cs_base;
Signature · 1 line
2.13.6
PATCH v6 36/50 tcg: Add CF_LAST_IO + CF_USE_ICOUNT to CF_HASH_MASK
In reply to Richard HendersonThese flags are used by target/*/translate.c,
and affect code generation.
--- include/exec/exec-all.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/exec/exec-all.h +2 -1
@@ -327,7 +327,8 @@ struct TranslationBlock {#define CF_INVALID 0x80000/* TB is stale. Setters must acquire tb_lock */ #define CF_PARALLEL 0x100000/* Generate code for a parallel context */ /* cflags' mask for hashing/comparison */ -#define CF_HASH_MASK (CF_COUNT_MASK | CF_PARALLEL) +#define CF_HASH_MASK \ + (CF_COUNT_MASK | CF_LAST_IO | CF_USE_ICOUNT | CF_PARALLEL)/* Per-vCPU dynamic tracing state used to generate this TB */ uint32_t trace_vcpu_dstate;
Signature · 1 line
2.13.6
PATCH v6 37/50 tcg: Remove CF_IGNORE_ICOUNT
In reply to Richard HendersonNow that we have curr_cflags, we can include CF_USE_ICOUNT early and then remove it as necessary.
--- include/exec/exec-all.h | 17 +++++++++-------- accel/tcg/cpu-exec.c | 16 +++++++++------- accel/tcg/translate-all.c | 3 --- 3 files changed, 18 insertions(+), 18 deletions(-)
include/exec/exec-all.h +9 -8
@@ -22,6 +22,7 @@#include "qemu-common.h" #include "exec/tb-context.h" +#include "sysemu/cpus.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */ #define DEBUG_DISAS
@@ -319,13 +320,12 @@ struct TranslationBlock {size <= TARGET_PAGE_SIZE) */ uint16_t icount;uint32_t cflags;/* compile flags */ -#define CF_COUNT_MASK 0x7fff -#define CF_LAST_IO 0x8000/* Last insn may be an IO access. */ -#define CF_NOCACHE 0x10000/* To be freed after execution */ -#define CF_USE_ICOUNT 0x20000 -#define CF_IGNORE_ICOUNT 0x40000/* Do not generate icount code */ -#define CF_INVALID 0x80000/* TB is stale. Setters must acquire tb_lock */ -#define CF_PARALLEL 0x100000/* Generate code for a parallel context */ +#define CF_COUNT_MASK 0x00007fff +#define CF_LAST_IO 0x00008000/* Last insn may be an IO access. */ +#define CF_NOCACHE 0x00010000/* To be freed after execution */ +#define CF_USE_ICOUNT 0x00020000 +#define CF_INVALID 0x00040000/* TB is stale. Setters need tb_lock */ +#define CF_PARALLEL 0x00080000/* Generate code for a parallel context */ /* cflags' mask for hashing/comparison */ #define CF_HASH_MASK \ (CF_COUNT_MASK | CF_LAST_IO | CF_USE_ICOUNT | CF_PARALLEL)
@@ -380,7 +380,8 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb)/* current cflags for hashing/comparison */ static inline uint32_t curr_cflags (void ) { -return parallel_cpus ?CF_PARALLEL :0 ; +return (parallel_cpus ?CF_PARALLEL :0 ) + | (use_icount ?CF_USE_ICOUNT :0 ); }void tb_free (TranslationBlock *tb);
accel/tcg/cpu-exec.c +9 -7
@@ -198,17 +198,19 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, TranslationBlock *orig_tb, bool ignore_icount) {TranslationBlock *tb; +uint32_t cflags =curr_cflags () |CF_NOCACHE ; + +if (ignore_icount) { + cflags &= ~CF_USE_ICOUNT ; + }/* Should never happen. We only end up here when an existing TB is too long. */ -if (max_cycles >CF_COUNT_MASK ) - max_cycles =CF_COUNT_MASK ; + cflags |=MIN (max_cycles,CF_COUNT_MASK );tb_lock (); - tb =tb_gen_code (cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags, - max_cycles |CF_NOCACHE - | (ignore_icount ?CF_IGNORE_ICOUNT :0 ) - |curr_cflags ()); + tb =tb_gen_code (cpu, orig_tb->pc, orig_tb->cs_base, + orig_tb->flags, cflags); tb->orig_tb = orig_tb;tb_unlock ();
@@ -229,7 +231,7 @@ void cpu_exec_step_atomic(CPUState *cpu)TranslationBlock *tb;target_ulong cs_base, pc;uint32_t flags; -uint32_t cflags =1 |CF_IGNORE_ICOUNT ; +uint32_t cflags =1 ;uint32_t cf_mask = cflags &CF_HASH_MASK ;if (sigsetjmp (cpu->jmp_env,0 ) ==0 ) {
accel/tcg/translate-all.c +0 -3
@@ -1274,9 +1274,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,assert_memory_lock (); phys_pc =get_page_addr_code (env, pc); -if (use_icount && !(cflags &CF_IGNORE_ICOUNT )) { - cflags |=CF_USE_ICOUNT ; - } tb =tb_alloc (pc);if (unlikely (!tb)) {
Signature · 1 line
2.13.6
PATCH v6 38/50 translate-all: use a binary search tree to track TBs in TBContext
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
This is a prerequisite for supporting multiple TCG contexts, since we will have threads generating code in separate regions of code_gen_buffer.
For this we need a new field (.size) in struct tb_tc to keep track of the size of the translated code. This field uses a size_t to avoid adding a hole to the struct, although really an unsigned int would have been enough.
The comparison function we use is optimized for the common case:
insertions. Profiling shows that upon booting debian-arm, 98% of comparisons are between existing tb's (i.e. a->size and b->size are both !0), which happens during insertions (and removals, but those are rare). The remaining cases are lookups. From reading the glib sources we see that the first key is always the lookup key. However, the code does not assume this to always be the case because this behaviour is not guaranteed in the glib docs. However, we embed this knowledge in the code as a branch hint for the compiler.
Note that tb_free does not free space in the code_gen_buffer anymore, since we cannot easily know whether the tb is the last one inserted in code_gen_buffer. The next patch in this series renames tb_free to tb_remove to reflect this.
Performance-wise, lookups in tb_find_pc are the same as before:
O(log n). However, insertions are O(log n) instead of O(1), which results in a small slowdown when booting debian-arm:
Performance counter stats for 'build/arm-softmmu/qemu-system-arm \ -machine type=virt -nographic -smp 1 -m 4096 \ -netdev user,id=unet,hostfwd=tcp::2222-:22 \ -device virtio-net-device,netdev=unet \ -drive file=img/arm/jessie-arm32.qcow2,id=myblock,index=0,if=none \ -device virtio-blk-device,drive=myblock \ -kernel img/arm/aarch32-current-linux-kernel-only.img \ -append console=ttyAMA0 root=/dev/vda1 \ -name arm,debug-threads=on -smp 1' (10 runs):
- Before:
8048.598422 task-clock (msec) # 0.931 CPUs utilized ( +- 0.28% )
16,974 context-switches # 0.002 M/sec ( +- 0.12% )
0 cpu-migrations # 0.000 K/sec
10,125 page-faults # 0.001 M/sec ( +- 1.23% )
35,144,901,879 cycles # 4.367 GHz ( +- 0.14% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
65,758,252,643 instructions # 1.87 insns per cycle ( +- 0.33% )
10,871,298,668 branches # 1350.707 M/sec ( +- 0.41% )
192,322,212 branch-misses # 1.77% of all branches ( +- 0.32% )8.640869419 seconds time elapsed ( +- 0.57% )
- After:
8146.242027 task-clock (msec) # 0.923 CPUs utilized ( +- 1.23% )
17,016 context-switches # 0.002 M/sec ( +- 0.40% )
0 cpu-migrations # 0.000 K/sec
18,769 page-faults # 0.002 M/sec ( +- 0.45% )
35,660,956,120 cycles # 4.378 GHz ( +- 1.22% )
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
65,095,366,607 instructions # 1.83 insns per cycle ( +- 1.73% )
10,803,480,261 branches # 1326.192 M/sec ( +- 1.95% )
195,601,289 branch-misses # 1.81% of all branches ( +- 0.39% )8.828660235 seconds time elapsed ( +- 0.38% )
--- include/exec/exec-all.h | 5 ++ include/exec/tb-context.h | 4 +- accel/tcg/translate-all.c | 217 ++++++++++++++++++++++++---------------------- 3 files changed, 118 insertions(+), 108 deletions(-)
include/exec/exec-all.h +5 -0
@@ -306,10 +306,15 @@ static inline void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr)/* * Translation Cache-related fields of a TB. +* This struct exists just for convenience; we keep track of TB's in a binary +* search tree, and the only fields needed to compare TB's in the tree are +* @ptr and @size. @search is brought here for consistency, since it is also +* a TC-related field. */ struct tb_tc {void *ptr;/* pointer to the translated code */ uint8_t *search;/* pointer to search data */ +size_t size; };struct TranslationBlock {
include/exec/tb-context.h +1 -3
@@ -31,10 +31,8 @@ typedef struct TBContext TBContext;struct TBContext { -TranslationBlock **tbs; +GTree *tb_tree;struct qht htable; -size_t tbs_size; -int nb_tbs;/* any access to the tbs or the page table must use this lock */ QemuMutex tb_lock;
accel/tcg/translate-all.c +112 -105
298 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 38/50] translate-all: use a binary search tree to track TBs in TBContext
Quoted 11 lines · Richard Henderson
* Translation Cache-related fields of a TB.
+ * This struct exists just for convenience; we keep track of TB's in a binary
+ * search tree, and the only fields needed to compare TB's in the tree are
+ * @ptr and @size. @search is brought here for consistency, since it is also
+ * a TC-related field.
*/
structtb_tc{
void *ptr; /* pointer to the translated code */
uint8_t*search; /* pointer to search data */
+size_tsize;
};
Isn't search equal to ptr + size, or something like that?
Paolo
Re: [Qemu-devel] [PATCH v6 38/50] translate-all: use a binary search tree to track TBs in TBContext
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Richard Henderson
* Translation Cache-related fields of a TB.
+ * This struct exists just for convenience; we keep track of TB's in a binary
+ * search tree, and the only fields needed to compare TB's in the tree are
+ * @ptr and @size. @search is brought here for consistency, since it is also
+ * a TC-related field.
*/
structtb_tc{
void *ptr; /* pointer to the translated code */
uint8_t*search; /* pointer to search data */
+size_tsize;
};
Quoted 1 line
Isn't search equal to ptr + size, or something like that?
It is indeed! Fixup below.
The change shrinks TranslationBlock, but it leaves performance unchanged (recall that we add padding after TranslationBlock to avoid cache line overlap between the struct and translated code).
Thanks,
Emilio
-- >8 --
Subject: [PATCH] fixup
--- accel/tcg/translate-all.c | 4 +--- include/exec/exec-all.h | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-)
accel/tcg/translate-all.c +1 -3
@@ -272,8 +272,6 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)uint8_t *p = block;int i, j, n; - tb->tc.search = block; -for (i =0 , n = tb->icount; i < n; ++i) {target_ulong prev;
@@ -309,7 +307,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,target_ulong data[TARGET_INSN_START_WORDS ] = { tb->pc };uintptr_t host_pc = (uintptr_t )tb->tc.ptr;CPUArchState *env = cpu->env_ptr; -uint8_t *p = tb->tc.search; +uint8_t *p = tb->tc.ptr + tb->tc.size;int i, j, num_insns = tb->icount;#ifdef CONFIG_PROFILER TCGProfile *prof = &tcg_ctx->prof;
include/exec/exec-all.h +2 -3
@@ -308,12 +308,11 @@ static inline void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr)* Translation Cache-related fields of a TB. * This struct exists just for convenience; we keep track of TB's in a binary * search tree, and the only fields needed to compare TB's in the tree are -* @ptr and @size. @search is brought here for consistency, since it is also -* a TC-related field. +* @ptr and @size. +* Note: the address of search data can be obtained by adding @size to @ptr. */ struct tb_tc {void *ptr;/* pointer to the translated code */ -uint8_t *search;/* pointer to search data */ size_t size; };
Signature · 1 line
2.7.4
Richard Henderson
AppliedRe: [Qemu-devel] [PATCH v6 38/50] translate-all: use a binary search tree to track TBs in TBContext
Quoted 22 lines · Emilio G. Cota
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Richard Henderson
* Translation Cache-related fields of a TB.
+ * This struct exists just for convenience; we keep track of TB's in a binary
+ * search tree, and the only fields needed to compare TB's in the tree are
+ * @ptr and @size. @search is brought here for consistency, since it is also
+ * a TC-related field.
*/
structtb_tc{
void *ptr; /* pointer to the translated code */
uint8_t*search; /* pointer to search data */
+size_tsize;
};Quoted 1 line
Isn't search equal to ptr + size, or something like that?
It is indeed! Fixup below.
The change shrinks TranslationBlock, but it leaves performance unchanged (recall that we add padding after TranslationBlock to avoid cache line overlap between the struct and translated code).
Quoted 6 lines
Thanks,
Emilio
-- >8 --
Subject: [PATCH] fixup
Merged, thanks.
r~
PATCH v6 39/50 exec-all: rename tb_free to tb_remove
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
We don't really free anything in this function anymore; we just remove the TB from the binary search tree.
--- include/exec/exec-all.h | 2 +- accel/tcg/cpu-exec.c | 2 +- accel/tcg/translate-all.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
include/exec/exec-all.h +1 -1
@@ -389,7 +389,7 @@ static inline uint32_t curr_cflags(void) | (use_icount ? CF_USE_ICOUNT : 0); } -void tb_free (TranslationBlock *tb); +void tb_remove (TranslationBlock *tb);void tb_flush (CPUState *cpu);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr); TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
accel/tcg/cpu-exec.c +1 -1
@@ -220,7 +220,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,tb_lock ();tb_phys_invalidate (tb,-1 ); -tb_free (tb); +tb_remove (tb); tb_unlock(); }#endif
accel/tcg/translate-all.c +3 -3
@@ -375,7 +375,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)if (tb->cflags &CF_NOCACHE ) {/* one-shot translation, invalidate it immediately */ tb_phys_invalidate (tb,-1 ); -tb_free (tb); +tb_remove (tb); } r = true; }
@@ -874,7 +874,7 @@ static TranslationBlock *tb_alloc(target_ulong pc) }/* Called with tb_lock held. */ -void tb_free (TranslationBlock *tb) +void tb_remove (TranslationBlock *tb) {assert_tb_locked ();
@@ -1816,7 +1816,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)* cpu_exec_nocache() */ tb_phys_invalidate (tb->orig_tb,-1 ); } -tb_free (tb); +tb_remove (tb); }/* FIXME: In theory this could raise an exception. In practice we have already translated the block once so it's probably ok. */
Signature · 1 line
2.13.6
PATCH v6 40/50 translate-all: report correct avg host TB size
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Since commit 6e3b2bfd6 ("tcg: allocate TB structs before the corresponding translated code") we are not fully utilizing code_gen_buffer for translated code, and therefore are incorrectly reporting the amount of translated code as well as the average host TB size. Address this by:
- Making the conscious choice of misreporting the total translated code; doing otherwise would mislead users into thinking "-tb-size" is not honoured.
- Expanding tb_tree_stats to accurately count the bytes of translated code on the host, and using this for reporting the average tb host size, as well as the expansion ratio.
In the future we might want to consider reporting the accurate numbers for the total translated code, together with a "bookkeeping/overhead" field to account for the TB structs.
--- accel/tcg/translate-all.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
accel/tcg/translate-all.c +23 -9
@@ -923,6 +923,15 @@ static void page_flush_tb(void) } } +static gboolean tb_host_size_iter (gpointer key,gpointer value,gpointer data) +{ +const TranslationBlock *tb = value; +size_t *size = data; + + *size += tb->tc.size; +return false; +} +/* flush all the translation blocks */ static void do_tb_flush (CPUState *cpu,run_on_cpu_data tb_flush_count) {
@@ -937,11 +946,12 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)if (DEBUG_TB_FLUSH_GATE ) {size_t nb_tbs =g_tree_nnodes (tcg_ctx.tb_ctx.tb_tree); +size_t host_size =0 ; -printf ("qemu: flush code_size=%td nb_tbs=%zu avg_tb_size=%td\n" , +g_tree_foreach (tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_size); +printf ("qemu: flush code_size=%td nb_tbs=%zu avg_tb_size=%zu\n" , tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, nb_tbs, - nb_tbs >0 ? - (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) / nb_tbs :0 ); + nb_tbs >0 ? host_size / nb_tbs :0 ); }if ((unsigned long )(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) > tcg_ctx.code_gen_buffer_size) {
@@ -1890,6 +1900,7 @@ static void print_qht_statistics(FILE *f, fprintf_function cpu_fprintf, }struct tb_tree_stats { +size_t host_size;size_t target_size;size_t max_target_size;size_t direct_jmp_count;
@@ -1902,6 +1913,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data)const TranslationBlock *tb = value;struct tb_tree_stats *tst = data; + tst->host_size += tb->tc.size; tst->target_size += tb->size;if (tb->size > tst->max_target_size) { tst->max_target_size = tb->size;
@@ -1930,6 +1942,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)g_tree_foreach (tcg_ctx.tb_ctx.tb_tree, tb_tree_stats_iter, &tst);/* XXX: avoid using doubles ? */ cpu_fprintf (f,"Translation buffer state:\n" ); +/* +* Report total code size including the padding and TB structs; +* otherwise users might think "-tb-size" is not honoured. +* For avg host size we use the precise numbers from tb_tree_stats though. +*/ cpu_fprintf (f,"gen code size %td/%zd\n" , tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer);
@@ -1937,12 +1954,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)cpu_fprintf (f,"TB avg target size %zu max=%zu bytes\n" , nb_tbs ? tst.target_size / nb_tbs :0 , tst.max_target_size); -cpu_fprintf (f,"TB avg host size %td bytes (expansion ratio: %0.1f)\n" , - nb_tbs ? (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / nb_tbs :0 , - tst.target_size ? (double ) (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / - tst.target_size :0 ); +cpu_fprintf (f,"TB avg host size %zu bytes (expansion ratio: %0.1f)\n" , + nb_tbs ? tst.host_size / nb_tbs :0 , + tst.target_size ? (double )tst.host_size / tst.target_size :0 );cpu_fprintf (f,"cross page TB count %zu (%zu%%)\n" , tst.cross_page, nb_tbs ? (tst.cross_page *100 ) / nb_tbs :0 ); cpu_fprintf(f, "direct jump count %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
Signature · 1 line
2.13.6
PATCH v6 41/50 tcg: take tb_ctx out of TCGContext
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Groundwork for supporting multiple TCG contexts.
--- include/exec/tb-context.h | 2 ++ tcg/tcg.h | 2 -- accel/tcg/cpu-exec.c | 2 +- accel/tcg/translate-all.c | 57 +++++++++++++++++++++++------------------------ linux-user/main.c | 6 ++--- 5 files changed, 34 insertions(+), 35 deletions(-)
include/exec/tb-context.h +2 -0
@@ -41,4 +41,6 @@ struct TBContext { int tb_phys_invalidate_count; }; +extern TBContext tb_ctx; +#endif
tcg/tcg.h +0 -2
@@ -705,8 +705,6 @@ struct TCGContext {/* Threshold to flush the translated code buffer. */ void *code_gen_highwater; -TBContext tb_ctx; -/* Track which vCPU triggers events */ CPUState *cpu;/* *_trans */ TCGv_env tcg_env;/* *_exec */
accel/tcg/cpu-exec.c +1 -1
@@ -327,7 +327,7 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, phys_pc =get_page_addr_code (desc.env, pc); desc.phys_page1 = phys_pc &TARGET_PAGE_MASK ; h =tb_hash_func (phys_pc, pc, flags, cf_mask, *cpu->trace_dstate); -return qht_lookup (&tcg_ctx.tb_ctx.htable, tb_cmp, &desc, h); +return qht_lookup (&tb_ctx.htable, tb_cmp, &desc, h); }void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr)
accel/tcg/translate-all.c +28 -29
187 lines not on this page · raw message
linux-user/main.c +3 -3
@@ -114,7 +114,7 @@ int cpu_get_pic_interrupt(CPUX86State *env)void fork_start (void ) {cpu_list_lock (); -qemu_mutex_lock (&tcg_ctx.tb_ctx.tb_lock); +qemu_mutex_lock (&tb_ctx.tb_lock);mmap_fork_start (); }
@@ -130,11 +130,11 @@ void fork_end(int child)QTAILQ_REMOVE (&cpus, cpu, node); } } -qemu_mutex_init (&tcg_ctx.tb_ctx.tb_lock); +qemu_mutex_init (&tb_ctx.tb_lock);qemu_init_cpu_list ();gdbserver_fork (thread_cpu); }else { -qemu_mutex_unlock (&tcg_ctx.tb_ctx.tb_lock); +qemu_mutex_unlock (&tb_ctx.tb_lock);cpu_list_unlock (); } }
Signature · 1 line
2.13.6
PATCH v6 42/50 tcg: define tcg_init_ctx and make tcg_ctx a pointer
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Groundwork for supporting multiple TCG contexts.
The core of this patch is this change to tcg/tcg.h:
Review
Quoted 3 lines
(quoted diff) +2
-1-extern TCGContext tcg_ctx; +extern TCGContext tcg_init_ctx; +extern TCGContext *tcg_ctx;
Note that for now we set *tcg_ctx to whatever TCGContext is passed to tcg_context_init -- in this case &tcg_init_ctx.
--- include/exec/gen-icount.h | 10 ++-- tcg/tcg.h | 19 ++++---- accel/tcg/tcg-runtime.c | 2 +- accel/tcg/translate-all.c | 109 +++++++++++++++++++++--------------------- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- target/alpha/translate.c | 2 +- target/arm/translate.c | 2 +- target/cris/translate.c | 2 +- target/cris/translate_v10.c | 2 +- target/hppa/translate.c | 2 +- target/i386/translate.c | 2 +- target/lm32/translate.c | 2 +- target/m68k/translate.c | 2 +- target/microblaze/translate.c | 2 +- target/mips/translate.c | 2 +- target/moxie/translate.c | 2 +- target/openrisc/translate.c | 2 +- target/ppc/translate.c | 2 +- target/s390x/translate.c | 2 +- target/sh4/translate.c | 2 +- target/sparc/translate.c | 2 +- target/tilegx/translate.c | 2 +- target/tricore/translate.c | 2 +- target/unicore32/translate.c | 2 +- target/xtensa/translate.c | 2 +- tcg/tcg-op.c | 46 +++++++++--------- tcg/tcg.c | 22 +++++---- 28 files changed, 128 insertions(+), 124 deletions(-)
include/exec/gen-icount.h +5 -5
@@ -19,7 +19,7 @@ static inline void gen_tb_start(TranslationBlock *tb) count =tcg_temp_new_i32 (); } -tcg_gen_ld_i32 (count, tcg_ctx.tcg_env, +tcg_gen_ld_i32 (count, tcg_ctx->tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u32));if (tb_cflags (tb) &CF_USE_ICOUNT ) {
@@ -37,7 +37,7 @@ static inline void gen_tb_start(TranslationBlock *tb)tcg_gen_brcondi_i32 (TCG_COND_LT , count,0 , exitreq_label);if (tb_cflags (tb) &CF_USE_ICOUNT ) { -tcg_gen_st16_i32 (count, tcg_ctx.tcg_env, +tcg_gen_st16_i32 (count, tcg_ctx->tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low)); }
@@ -56,13 +56,13 @@ static inline void gen_tb_end(TranslationBlock *tb, int num_insns)tcg_gen_exit_tb ((uintptr_t )tb +TB_EXIT_REQUESTED );/* Terminate the linked list. */ - tcg_ctx.gen_op_buf[tcg_ctx.gen_op_buf[0 ].prev].next =0 ; + tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0 ].prev].next =0 ; }static inline void gen_io_start (void ) {TCGv_i32 tmp =tcg_const_i32 (1 ); -tcg_gen_st_i32 (tmp, tcg_ctx.tcg_env, +tcg_gen_st_i32 (tmp, tcg_ctx->tcg_env, -ENV_OFFSET + offsetof(CPUState , can_do_io));tcg_temp_free_i32 (tmp); }
@@ -70,7 +70,7 @@ static inline void gen_io_start(void)static inline void gen_io_end (void ) {TCGv_i32 tmp =tcg_const_i32 (0 ); -tcg_gen_st_i32 (tmp, tcg_ctx.tcg_env, +tcg_gen_st_i32 (tmp, tcg_ctx->tcg_env, -ENV_OFFSET + offsetof(CPUState , can_do_io));tcg_temp_free_i32 (tmp); }
tcg/tcg.h +10 -9
@@ -730,18 +730,19 @@ struct TCGContext {target_ulong gen_insn_data[TCG_MAX_INSNS ][TARGET_INSN_START_WORDS ]; }; -extern TCGContext tcg_ctx; +extern TCGContext tcg_init_ctx; +extern TCGContext *tcg_ctx;static inline size_t temp_idx (TCGTemp *ts) { -ptrdiff_t n = ts - tcg_ctx.temps; -tcg_debug_assert (n >0 && n < tcg_ctx.nb_temps); +ptrdiff_t n = ts - tcg_ctx->temps; +tcg_debug_assert (n >0 && n < tcg_ctx->nb_temps);return n; }static inline TCGTemp *idx_temp (size_t n) { -return n ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx.temps[n]; +return n ==TCG_CALL_DUMMY_ARG ?NULL : &tcg_ctx->temps[n]; }static inline TCGArg temp_arg (TCGTemp *ts)
@@ -781,13 +782,13 @@ static inline TCGArg tcgv_ptr_arg(TCGv_ptr t)static inline void tcg_set_insn_param (int op_idx,int arg,TCGArg v) { - tcg_ctx.gen_op_buf[op_idx].args[arg] = v; + tcg_ctx->gen_op_buf[op_idx].args[arg] = v; }/* The number of opcodes emitted so far. */ static inline int tcg_op_buf_count (void ) { -return tcg_ctx.gen_next_op_idx; +return tcg_ctx->gen_next_op_idx; }/* Test for whether to terminate the TB for using too many opcodes. */
@@ -806,7 +807,7 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s);/* Called with tb_lock held. */ static inline void *tcg_malloc (int size) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;uint8_t *ptr, *ptr_end;/* ??? This is a weak placeholder for minimum malloc alignment. */
@@ -815,7 +816,7 @@ static inline void *tcg_malloc(int size) ptr = s->pool_cur; ptr_end = ptr + size;if (unlikely (ptr_end > s->pool_end)) { -return tcg_malloc_internal (&tcg_ctx, size); +return tcg_malloc_internal (tcg_ctx, size); }else { s->pool_cur = ptr_end;return ptr;
@@ -1154,7 +1155,7 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)uintptr_t tcg_qemu_tb_exec (CPUArchState *env,uint8_t *tb_ptr);#else # define tcg_qemu_tb_exec (env, tb_ptr) \ - ((uintptr_t (*)(void *, void *))tcg_ctx.code_gen_prologue)(env, tb_ptr) + ((uintptr_t (*)(void *, void *))tcg_ctx->code_gen_prologue)(env, tb_ptr)#endif void tcg_register_jit (void *buf,size_t buf_size);
accel/tcg/tcg-runtime.c +1 -1
@@ -153,7 +153,7 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env) tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags,curr_cflags ());if (tb ==NULL ) { -return tcg_ctx.code_gen_epilogue; +return tcg_ctx->code_gen_epilogue; } qemu_log_mask_and_addr(CPU_LOG_EXEC, pc, "Chain %p [%d: " TARGET_FMT_lx "] %s\n",
accel/tcg/translate-all.c +55 -54
284 lines not on this page · raw message
bsd-user/main.c +1 -1
@@ -977,7 +977,7 @@ int main(int argc, char **argv)/* Now that we've loaded the binary, GUEST_BASE is fixed. Delay generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ -tcg_prologue_init (&tcg_ctx); +tcg_prologue_init (tcg_ctx);/* build Task State */ memset (ts,0 ,sizeof (TaskState));
linux-user/main.c +1 -1
@@ -4457,7 +4457,7 @@ int main(int argc, char **argv, char **envp)/* Now that we've loaded the binary, GUEST_BASE is fixed. Delay generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ -tcg_prologue_init (&tcg_ctx); +tcg_prologue_init (tcg_ctx);#if defined(TARGET_I386 ) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ;
target/alpha/translate.c +1 -1
@@ -127,7 +127,7 @@ void alpha_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;for (i =0 ; i <31 ; i++) { cpu_std_ir[i] = tcg_global_mem_new_i64(cpu_env,
target/arm/translate.c +1 -1
@@ -82,7 +82,7 @@ void arm_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;for (i =0 ; i <16 ; i++) { cpu_R[i] = tcg_global_mem_new_i32(cpu_env,
target/cris/translate.c +1 -1
@@ -3369,7 +3369,7 @@ void cris_initialize_tcg(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cc_x =tcg_global_mem_new (cpu_env, offsetof(CPUCRISState , cc_x),"cc_x" ); cc_src = tcg_global_mem_new(cpu_env,
target/cris/translate_v10.c +1 -1
@@ -1273,7 +1273,7 @@ void cris_initialize_crisv10_tcg(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cc_x =tcg_global_mem_new (cpu_env, offsetof(CPUCRISState , cc_x),"cc_x" ); cc_src = tcg_global_mem_new(cpu_env,
target/hppa/translate.c +1 -1
@@ -127,7 +127,7 @@ void hppa_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;TCGV_UNUSED (cpu_gr[0 ]);for (i =1 ; i <32 ; i++) {
target/i386/translate.c +1 -1
@@ -8331,7 +8331,7 @@ void tcg_x86_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_cc_op =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUX86State , cc_op),"cc_op" ); cpu_cc_dst = tcg_global_mem_new(cpu_env, offsetof(CPUX86State, cc_dst),
target/lm32/translate.c +1 -1
@@ -1209,7 +1209,7 @@ void lm32_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;for (i =0 ; i <ARRAY_SIZE (cpu_R); i++) { cpu_R[i] = tcg_global_mem_new(cpu_env,
target/m68k/translate.c +1 -1
@@ -70,7 +70,7 @@ void m68k_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;#define DEFO32 (name, offset) \ QREG_##name = tcg_global_mem_new_i32(cpu_env, \
target/microblaze/translate.c +1 -1
@@ -1856,7 +1856,7 @@ void mb_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; env_debug = tcg_global_mem_new(cpu_env, offsetof(CPUMBState, debug),
target/mips/translate.c +1 -1
@@ -20455,7 +20455,7 @@ void mips_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;TCGV_UNUSED (cpu_gpr[0 ]);for (i =1 ; i <32 ; i++)
target/moxie/translate.c +1 -1
@@ -102,7 +102,7 @@ void moxie_translate_init(void) }; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUMoxieState , pc),"$pc" );for (i =0 ; i <16 ; i++)
target/openrisc/translate.c +1 -1
@@ -81,7 +81,7 @@ void openrisc_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_sr =tcg_global_mem_new (cpu_env, offsetof(CPUOpenRISCState , sr),"sr" ); cpu_dflag = tcg_global_mem_new_i32(cpu_env,
target/ppc/translate.c +1 -1
@@ -86,7 +86,7 @@ void ppc_translate_init(void)size_t cpu_reg_names_size; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; p = cpu_reg_names; cpu_reg_names_size =sizeof (cpu_reg_names);
target/s390x/translate.c +1 -1
@@ -113,7 +113,7 @@ void s390x_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; psw_addr =tcg_global_mem_new_i64 (cpu_env, offsetof(CPUS390XState, psw.addr),"psw_addr" );
target/sh4/translate.c +1 -1
@@ -100,7 +100,7 @@ void sh4_translate_init(void) }; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;for (i =0 ; i <24 ; i++) { cpu_gregs[i] = tcg_global_mem_new_i32(cpu_env,
target/sparc/translate.c +1 -1
@@ -5917,7 +5917,7 @@ void sparc_tcg_init(void)unsigned int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_regwptr = tcg_global_mem_new_ptr(cpu_env, offsetof(CPUSPARCState, regwptr),
target/tilegx/translate.c +1 -1
@@ -2446,7 +2446,7 @@ void tilegx_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i64 (cpu_env, offsetof(CPUTLGState , pc),"pc" );for (i =0 ; i <TILEGX_R_COUNT ; i++) { cpu_regs[i] = tcg_global_mem_new_i64(cpu_env,
target/tricore/translate.c +1 -1
@@ -8882,7 +8882,7 @@ void tricore_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;/* reg init */ for (i =0 ; i <16 ; i++) { cpu_gpr_a[i] = tcg_global_mem_new(cpu_env,
target/unicore32/translate.c +1 -1
@@ -75,7 +75,7 @@ void uc32_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env;for (i =0 ; i <32 ; i++) { cpu_R[i] = tcg_global_mem_new_i32(cpu_env,
target/xtensa/translate.c +1 -1
@@ -222,7 +222,7 @@ void xtensa_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); - tcg_ctx.tcg_env = cpu_env; + tcg_ctx->tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i32 (cpu_env, offsetof(CPUXtensaState , pc),"pc" );
tcg/tcg-op.c +23 -23
158 lines not on this page · raw message
tcg/tcg.c +12 -10
@@ -243,7 +243,7 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)TCGLabel *gen_new_label (void ) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;TCGLabel *l =tcg_malloc (sizeof (TCGLabel)); *l = (TCGLabel ){
@@ -385,6 +385,8 @@ void tcg_context_init(TCGContext *s)for (; i <ARRAY_SIZE (tcg_target_reg_alloc_order); ++i) { indirect_reg_alloc_order[i] = tcg_target_reg_alloc_order[i]; } + + tcg_ctx = s; }/*
@@ -526,7 +528,7 @@ void tcg_set_frame(TCGContext *s, TCGReg reg, intptr_t start, intptr_t size)TCGv_i32 tcg_global_reg_new_i32 (TCGReg reg,const char *name) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;int idx;if (tcg_regset_test_reg (s->reserved_regs, reg)) {
@@ -538,7 +540,7 @@ TCGv_i32 tcg_global_reg_new_i32(TCGReg reg, const char *name)TCGv_i64 tcg_global_reg_new_i64 (TCGReg reg,const char *name) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;int idx;if (tcg_regset_test_reg (s->reserved_regs, reg)) {
@@ -551,7 +553,7 @@ TCGv_i64 tcg_global_reg_new_i64(TCGReg reg, const char *name)int tcg_global_mem_new_internal (TCGType type,TCGv_ptr base,intptr_t offset,const char *name) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;TCGTemp *base_ts = &s->temps[GET_TCGV_PTR (base)];TCGTemp *ts =tcg_global_alloc (s);int indirect_reg =0 , bigendian =0 ;
@@ -606,7 +608,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,static int tcg_temp_new_internal (TCGType type,int temp_local) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;TCGTemp *ts;int idx, k;
@@ -668,7 +670,7 @@ TCGv_i64 tcg_temp_new_internal_i64(int temp_local)static void tcg_temp_free_internal (int idx) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;TCGTemp *ts;int k;
@@ -733,13 +735,13 @@ TCGv_i64 tcg_const_local_i64(int64_t val)#if defined(CONFIG_DEBUG_TCG )void tcg_clear_temp_count (void ) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx; s->temps_in_use =0 ; }int tcg_check_temp_count (void ) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;if (s->temps_in_use) {/* Clear the count so that we don't give another * warning immediately next time around.
@@ -979,7 +981,7 @@ bool tcg_op_supported(TCGOpcode op)and endian swap in tcg_reg_alloc_call(). */ void tcg_gen_callN (void *func,TCGArg ret,int nargs,TCGArg *args) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;int i, real_args, nb_rets, pi;unsigned sizemask, flags;TCGHelperInfo *info;
@@ -2924,7 +2926,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)#ifdef CONFIG_PROFILER void tcg_dump_info (FILE *f,fprintf_function cpu_fprintf) { -TCGContext *s = &tcg_ctx; +TCGContext *s = tcg_ctx;int64_t tb_count = s->tb_count;int64_t tb_div_count = tb_count ? tb_count :1 ;int64_t tot = s->interm_time + s->code_time;
Signature · 1 line
2.13.6
PATCH v6 43/50 gen-icount: fold exitreq_label into TCGContext
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Groundwork for supporting multiple TCG contexts.
--- include/exec/gen-icount.h | 7 +++---- tcg/tcg.h | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-)
include/exec/gen-icount.h +3 -4
@@ -6,13 +6,12 @@/* Helpers for instruction counting code generation. */ static int icount_start_insn_idx; -static TCGLabel *exitreq_label;static inline void gen_tb_start (TranslationBlock *tb) {TCGv_i32 count, imm; - exitreq_label =gen_new_label (); + tcg_ctx->exitreq_label =gen_new_label ();if (tb_cflags (tb) &CF_USE_ICOUNT ) { count =tcg_temp_local_new_i32 (); }else {
@@ -34,7 +33,7 @@ static inline void gen_tb_start(TranslationBlock *tb)tcg_temp_free_i32 (imm); } -tcg_gen_brcondi_i32 (TCG_COND_LT , count,0 , exitreq_label); +tcg_gen_brcondi_i32 (TCG_COND_LT , count,0 , tcg_ctx->exitreq_label);if (tb_cflags (tb) &CF_USE_ICOUNT ) { tcg_gen_st16_i32(count, tcg_ctx->tcg_env,
@@ -52,7 +51,7 @@ static inline void gen_tb_end(TranslationBlock *tb, int num_insns)tcg_set_insn_param (icount_start_insn_idx,1 , num_insns); } -gen_set_label (exitreq_label); +gen_set_label (tcg_ctx->exitreq_label);tcg_gen_exit_tb ((uintptr_t )tb +TB_EXIT_REQUESTED );/* Terminate the linked list. */
tcg/tcg.h +2 -0
@@ -717,6 +717,8 @@ struct TCGContext {struct TCGLabelPoolData *pool_labels;#endif +TCGLabel *exitreq_label; +TCGTempSet free_temps[TCG_TYPE_COUNT *2 ];TCGTemp temps[TCG_MAX_TEMPS ];/* globals first, temps after */
Signature · 1 line
2.13.6
PATCH v6 44/50 tcg: introduce **tcg_ctxs to keep track of all TCGContext's
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Groundwork for supporting multiple TCG contexts.
Note that having n_tcg_ctxs is unnecessary. However, it is convenient to have it, since it will simplify iterating over the
array: we'll have just a for loop instead of having to iterate over a NULL-terminated array (which would require n+1 elems) or having to check with ifdef's for usermode/softmmu.
--- tcg/tcg.c | 5 +++++ 1 file changed, 5 insertions(+)
tcg/tcg.c +5 -0
@@ -118,6 +118,9 @@ static bool tcg_out_ldst_finalize(TCGContext *s);#define TCG_HIGHWATER 1024 +static TCGContext **tcg_ctxs; +static unsigned int n_tcg_ctxs; +static TCGRegSet tcg_target_available_regs[2 ];static TCGRegSet tcg_target_call_clobber_regs;
@@ -387,6 +390,8 @@ void tcg_context_init(TCGContext *s) } tcg_ctx = s; + tcg_ctxs = &tcg_ctx; + n_tcg_ctxs =1 ; }/*
Signature · 1 line
2.13.6
PATCH v6 45/50 tcg: distribute profiling counters across TCGContext's
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
This is groundwork for supporting multiple TCG contexts.
To avoid scalability issues when profiling info is enabled, this patch makes the profiling info counters distributed via the following changes:
1) Consolidate profile info into its own struct, TCGProfile, which TCGContext also includes. Note that tcg_table_op_count is brought into TCGProfile after dropping the tcg_ prefix.
2) Iterate over the TCG contexts in the system to obtain the total counts.
This change also requires updating the accessors to TCGProfile fields to use atomic_read/set whenever there may be conflicting accesses (as defined in C11) to them.
--- tcg/tcg.h | 38 +++++++++------- accel/tcg/translate-all.c | 23 +++++----- tcg/tcg.c | 110 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 126 insertions(+), 45 deletions(-)
tcg/tcg.h +21 -17
@@ -641,6 +641,26 @@ QEMU_BUILD_BUG_ON(sizeof(TCGOp) != 8 + sizeof(TCGArg) * MAX_OPC_PARAM);QEMU_BUILD_BUG_ON (NB_OPS > (1 <<8 ));QEMU_BUILD_BUG_ON (OPC_BUF_SIZE > (1 <<16 )); +typedef struct TCGProfile { +int64_t tb_count1; +int64_t tb_count; +int64_t op_count;/* total insn count */ +int op_count_max;/* max insn per TB */ +int64_t temp_count; +int temp_count_max; +int64_t del_op_count; +int64_t code_in_len; +int64_t code_out_len; +int64_t search_out_len; +int64_t interm_time; +int64_t code_time; +int64_t la_time; +int64_t opt_time; +int64_t restore_count; +int64_t restore_time; +int64_t table_op_count[NB_OPS ]; +}TCGProfile ; +struct TCGContext {uint8_t *pool_cur, *pool_end;TCGPool *pool_first, *pool_current, *pool_first_large;
@@ -665,23 +685,7 @@ struct TCGContext {tcg_insn_unit *code_ptr;#ifdef CONFIG_PROFILER -/* profiling info */ -int64_t tb_count1; -int64_t tb_count; -int64_t op_count;/* total insn count */ -int op_count_max;/* max insn per TB */ -int64_t temp_count; -int temp_count_max; -int64_t del_op_count; -int64_t code_in_len; -int64_t code_out_len; -int64_t search_out_len; -int64_t interm_time; -int64_t code_time; -int64_t la_time; -int64_t opt_time; -int64_t restore_count; -int64_t restore_time; +TCGProfile prof;#endif #ifdef CONFIG_DEBUG_TCG
accel/tcg/translate-all.c +13 -10
@@ -312,6 +312,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,uint8_t *p = tb->tc.search;int i, j, num_insns = tb->icount;#ifdef CONFIG_PROFILER +TCGProfile *prof = &tcg_ctx->prof;int64_t ti =profile_getclock ();#endif
@@ -346,8 +347,9 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,restore_state_to_opc (env, tb, data);#ifdef CONFIG_PROFILER - tcg_ctx->restore_time +=profile_getclock () - ti; - tcg_ctx->restore_count++; +atomic_set (&prof->restore_time, + prof->restore_time +profile_getclock () - ti); +atomic_set (&prof->restore_count, prof->restore_count +1 );#endif return 0 ; }
@@ -1302,6 +1304,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size;#ifdef CONFIG_PROFILER +TCGProfile *prof = &tcg_ctx->prof;int64_t ti;#endif assert_memory_lock ();
@@ -1329,8 +1332,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_ctx->tb_cflags = cflags;#ifdef CONFIG_PROFILER - tcg_ctx->tb_count1++;/* includes aborted translations because of -exceptions */ +/* includes aborted translations because of exceptions */ +atomic_set (&prof->tb_count1, prof->tb_count1 +1 ); ti =profile_getclock ();#endif
@@ -1355,8 +1358,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, }#ifdef CONFIG_PROFILER - tcg_ctx->tb_count++; - tcg_ctx->interm_time +=profile_getclock () - ti; +atomic_set (&prof->tb_count, prof->tb_count +1 ); +atomic_set (&prof->interm_time, prof->interm_time +profile_getclock () - ti); ti =profile_getclock ();#endif
@@ -1376,10 +1379,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tc.size = gen_code_size;#ifdef CONFIG_PROFILER - tcg_ctx->code_time +=profile_getclock () - ti; - tcg_ctx->code_in_len += tb->size; - tcg_ctx->code_out_len += gen_code_size; - tcg_ctx->search_out_len += search_size; +atomic_set (&prof->code_time, prof->code_time +profile_getclock () - ti); +atomic_set (&prof->code_in_len, prof->code_in_len + tb->size); +atomic_set (&prof->code_out_len, prof->code_out_len + gen_code_size); +atomic_set (&prof->search_out_len, prof->search_out_len + search_size);#endif #ifdef DEBUG_DISAS
tcg/tcg.c +92 -18
174 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v6 46/50 tcg: allocate optimizer temps with tcg_malloc
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
Groundwork for supporting multiple TCG contexts.
While at it, also allocate temps_used directly as a bitmap of the required size, instead of using a bitmap of TCG_MAX_TEMPS via TCGTempSet.
Performance-wise we lose about 1.12% in a translation-heavy workload such as booting+shutting down debian-arm:
Performance counter stats for 'taskset -c 0 arm-softmmu/qemu-system-arm \
-machine type=virt -nographic -smp 1 -m 4096 \
-netdev user,id=unet,hostfwd=tcp::2222-:22 \
-device virtio-net-device,netdev=unet \
-drive file=die-on-boot.qcow2,id=myblock,index=0,if=none \
-device virtio-blk-device,drive=myblock \
-kernel kernel.img -append console=ttyAMA0 root=/dev/vda1 \
-name arm,debug-threads=on -smp 1' (10 runs):
exec time (s) Relative slowdown wrt original (%)
---------------------------------------------------------------
original 20.213321616 0.
tcg_malloc 20.441130078 1.1270214
TCGContext 20.477846517 1.3086662
g_malloc 20.780527895 2.8061013The other two alternatives shown in the table are:
- TCGContext: embed temps[TCG_MAX_TEMPS] and TCGTempSet used_temps in TCGContext. This is simple enough but it isn't faster than using tcg_malloc; moreover, it wastes memory.
- g_malloc: allocate/deallocate both temps and used_temps every time tcg_optimize is executed.
--- tcg/optimize.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
tcg/optimize.c +19 -23
@@ -40,9 +40,6 @@ struct tcg_temp_info {tcg_target_ulong mask; }; -static struct tcg_temp_info temps_[TCG_MAX_TEMPS ]; -static TCGTempSet temps_used; -static inline struct tcg_temp_info *ts_info (TCGTemp *ts) {return ts->state_ptr;
@@ -93,31 +90,27 @@ static void reset_temp(TCGArg arg)reset_ts (arg_temp (arg)); } -/* Reset all temporaries, given that there are NB_TEMPS of them. */ -static void reset_all_temps (int nb_temps) -{ -bitmap_zero (temps_used.l, nb_temps); -} -/* Initialize and activate a temporary. */ -static void init_ts_info (TCGTemp *ts) +static void init_ts_info (struct tcg_temp_info *infos, +TCGTempSet *temps_used,TCGTemp *ts) {size_t idx =temp_idx (ts); -if (!test_bit (idx, temps_used.l)) { -struct tcg_temp_info *ti = &temps_[idx]; +if (!test_bit (idx, temps_used->l)) { +struct tcg_temp_info *ti = &infos[idx]; ts->state_ptr = ti; ti->next_copy = ts; ti->prev_copy = ts; ti->is_const = false; ti->mask =-1 ; -set_bit (idx, temps_used.l); +set_bit (idx, temps_used->l); } } -static void init_arg_info (TCGArg arg) +static void init_arg_info (struct tcg_temp_info *infos, +TCGTempSet *temps_used,TCGArg arg) { -init_ts_info (arg_temp (arg)); +init_ts_info (infos, temps_used,arg_temp (arg)); }static int op_bits (TCGOpcode op)
@@ -616,6 +609,8 @@ void tcg_optimize(TCGContext *s) {int oi, oi_next, nb_temps, nb_globals;TCGOp *prev_mb =NULL ; +struct tcg_temp_info *infos; +TCGTempSet temps_used;/* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element.
@@ -624,7 +619,8 @@ void tcg_optimize(TCGContext *s) nb_temps = s->nb_temps; nb_globals = s->nb_globals; -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); + infos =tcg_malloc (sizeof (struct tcg_temp_info ) * nb_temps);for (oi = s->gen_op_buf[0 ].next; oi !=0 ; oi = oi_next) {tcg_target_ulong mask, partmask, affected;
@@ -645,14 +641,14 @@ void tcg_optimize(TCGContext *s)for (i =0 ; i < nb_oargs + nb_iargs; i++) {TCGTemp *ts =arg_temp (op->args[i]);if (ts) { -init_ts_info (ts); +init_ts_info (infos, &temps_used, ts); } } }else { nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs;for (i =0 ; i < nb_oargs + nb_iargs; i++) { -init_arg_info (op->args[i]); +init_arg_info (infos, &temps_used, op->args[i]); } }
@@ -1213,7 +1209,7 @@ void tcg_optimize(TCGContext *s) op->args[1], op->args[2]);if (tmp !=2 ) {if (tmp) { -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); op->opc = INDEX_op_br; op->args[0 ] = op->args[3 ]; }else {
@@ -1302,7 +1298,7 @@ void tcg_optimize(TCGContext *s)if (tmp !=2 ) {if (tmp) { do_brcond_true: -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); op->opc = INDEX_op_br; op->args[0 ] = op->args[5 ]; }else {
@@ -1318,7 +1314,7 @@ void tcg_optimize(TCGContext *s)/* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ do_brcond_high: -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); op->opc = INDEX_op_brcond_i32; op->args[0 ] = op->args[1 ]; op->args[1 ] = op->args[3 ];
@@ -1344,7 +1340,7 @@ void tcg_optimize(TCGContext *s) goto do_default; } do_brcond_low: -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); op->opc = INDEX_op_brcond_i32; op->args[1 ] = op->args[2 ]; op->args[2 ] = op->args[4 ];
@@ -1464,7 +1460,7 @@ void tcg_optimize(TCGContext *s)block, otherwise we only trash the output args. "mask" is the non-zero bits mask for the first output arg. */ if (def->flags &TCG_OPF_BB_END ) { -reset_all_temps (nb_temps); +bitmap_zero (temps_used.l, nb_temps); }else { do_reset_output:for (i =0 ; i < nb_oargs; i++) {
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v6 46/50] tcg: allocate optimizer temps with tcg_malloc
Quoted 1 line · Richard Henderson
From: "Emilio G. Cota" <[email protected]>
(snip)
Quoted 6 lines
Suggested-by Richard Henderson <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Note the double Sob tag.
Also, does this still break aarch32, or somehow the cleanups plus this got rid of the problem?
E.
Re: [Qemu-devel] [PATCH v6 46/50] tcg: allocate optimizer temps with tcg_malloc
Quoted 7 lines · Emilio G. Cota
Quoted 1 line · Richard Henderson
From: "Emilio G. Cota" <[email protected]>
(snip)
Quoted 3 lines
Suggested-by Richard Henderson <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>
Quoted 8 lines
Quoted 3 lines
Signed-off-by Richard Henderson <[email protected]>Signed-off-by Richard Henderson <[email protected]>Note the double Sob tag.
Also, does this still break aarch32, or somehow the cleanups plus this got rid of the problem?
This got rid of the problem.
r~
PATCH v6 47/50 osdep: introduce qemu_mprotect_rwx/none
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
--- include/qemu/osdep.h | 2 ++ util/osdep.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
include/qemu/osdep.h +2 -0
@@ -371,6 +371,8 @@ void sigaction_invoke(struct sigaction *action,#endif int qemu_madvise (void *addr,size_t len,int advice); +int qemu_mprotect_rwx (void *addr,size_t size); +int qemu_mprotect_none (void *addr,size_t size);int qemu_open (const char *name,int flags, ...);int qemu_close (int fd);
util/osdep.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v6 48/50 translate-all: use qemu_protect_rwx/none helpers
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
The helpers require the address and size to be page-aligned, so do that before calling them.
--- accel/tcg/translate-all.c | 61 ++++++++++------------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-)
accel/tcg/translate-all.c +13 -48
@@ -604,63 +604,24 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -# ifdef _WIN32 -static inline void do_protect (void *addr,long size,int prot) -{ -DWORD old_protect; -VirtualProtect (addr, size, prot, &old_protect); -} - -static inline void map_exec (void *addr,long size) -{ -do_protect (addr, size,PAGE_EXECUTE_READWRITE ); -} - -static inline void map_none (void *addr,long size) -{ -do_protect (addr, size,PAGE_NOACCESS ); -} -# else -static inline void do_protect (void *addr,long size,int prot) -{ -uintptr_t start, end; - - start = (uintptr_t )addr; - start &= qemu_real_host_page_mask; - - end = (uintptr_t )addr + size; - end =ROUND_UP (end, qemu_real_host_page_size); - -mprotect ((void *)start, end - start, prot); -} - -static inline void map_exec (void *addr,long size) -{ -do_protect (addr, size,PROT_READ |PROT_WRITE |PROT_EXEC ); -} - -static inline void map_none (void *addr,long size) -{ -do_protect (addr, size,PROT_NONE ); -} -# endif /* WIN32 */ -static inline void *alloc_code_gen_buffer (void ) {void *buf = static_code_gen_buffer; +void *end = static_code_gen_buffer +sizeof (static_code_gen_buffer);size_t full_size, size; -/* The size of the buffer, rounded down to end on a page boundary. */ - full_size = (((uintptr_t )buf +sizeof (static_code_gen_buffer)) - & qemu_real_host_page_mask) - (uintptr_t )buf; +/* page-align the beginning and end of the buffer */ + buf =QEMU_ALIGN_PTR_UP (buf, qemu_real_host_page_size); + end =QEMU_ALIGN_PTR_DOWN (end, qemu_real_host_page_size);/* Reserve a guard page. */ + full_size = end - buf; size = full_size - qemu_real_host_page_size;/* Honor a command-line option limiting the size of the buffer. */ if (size > tcg_ctx->code_gen_buffer_size) { - size = (((uintptr_t )buf + tcg_ctx->code_gen_buffer_size) - & qemu_real_host_page_mask) - (uintptr_t )buf; + size =QEMU_ALIGN_DOWN (tcg_ctx->code_gen_buffer_size, + qemu_real_host_page_size); } tcg_ctx->code_gen_buffer_size = size;
@@ -671,8 +632,12 @@ static inline void *alloc_code_gen_buffer(void) }#endif -map_exec (buf, size); -map_none (buf + size, qemu_real_host_page_size); +if (qemu_mprotect_rwx (buf, size)) { +abort (); + } +if (qemu_mprotect_none (buf + size, qemu_real_host_page_size)) { +abort (); + }qemu_madvise (buf, size,QEMU_MADV_HUGEPAGE );return buf;
Signature · 1 line
2.13.6
PATCH v6 49/50 tcg: introduce regions to split code_gen_buffer
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
This is groundwork for supporting multiple TCG contexts.
The naive solution here is to split code_gen_buffer statically among the TCG threads; this however results in poor utilization if translation needs are different across TCG threads.
What we do here is to add an extra layer of indirection, assigning regions that act just like pages do in virtual memory allocation. (BTW if you are wondering about the chosen naming, I did not want to use blocks or pages because those are already heavily used in QEMU).
We use a global lock to serialize allocations as well as statistics reporting (we now export the size of the used code_gen_buffer with tcg_code_size()). Note that for the allocator we could just use a counter and atomic_inc; however, that would complicate the gathering of tcg_code_size()-like stats. So given that the region operations are not a fast path, a lock seems the most reasonable choice.
The effectiveness of this approach is clear after seeing some numbers. I used the bootup+shutdown of debian-arm with '-tb-size 80' as a benchmark. Note that I'm evaluating this after enabling per-thread TCG (which is done by a subsequent commit).
* -smp 1, 1 region (entire buffer):
qemu: flush code_size=83885014 nb_tbs=154739 avg_tb_size=357
qemu: flush code_size=83884902 nb_tbs=153136 avg_tb_size=363
qemu: flush code_size=83885014 nb_tbs=152777 avg_tb_size=364
qemu: flush code_size=83884950 nb_tbs=150057 avg_tb_size=373
qemu: flush code_size=83884998 nb_tbs=150234 avg_tb_size=373
qemu: flush code_size=83885014 nb_tbs=154009 avg_tb_size=360
qemu: flush code_size=83885014 nb_tbs=151007 avg_tb_size=370
qemu: flush code_size=83885014 nb_tbs=151816 avg_tb_size=367That is, 8 flushes.
* -smp 8, 32 regions (80/32 MB per region) [i.e. this patch]:
qemu: flush code_size=76328008 nb_tbs=141040 avg_tb_size=356
qemu: flush code_size=75366534 nb_tbs=138000 avg_tb_size=361
qemu: flush code_size=76864546 nb_tbs=140653 avg_tb_size=361
qemu: flush code_size=76309084 nb_tbs=135945 avg_tb_size=375
qemu: flush code_size=74581856 nb_tbs=132909 avg_tb_size=375
qemu: flush code_size=73927256 nb_tbs=135616 avg_tb_size=360
qemu: flush code_size=78629426 nb_tbs=142896 avg_tb_size=365
qemu: flush code_size=76667052 nb_tbs=138508 avg_tb_size=368Again, 8 flushes. Note how buffer utilization is not 100%, but it is close. Smaller region sizes would yield higher utilization, but we want region allocation to be rare (it acquires a lock), so we do not want to go too small.
* -smp 8, static partitioning of 8 regions (10 MB per region):
qemu: flush code_size=21936504 nb_tbs=40570 avg_tb_size=354
qemu: flush code_size=11472174 nb_tbs=20633 avg_tb_size=370
qemu: flush code_size=11603976 nb_tbs=21059 avg_tb_size=365
qemu: flush code_size=23254872 nb_tbs=41243 avg_tb_size=377
qemu: flush code_size=28289496 nb_tbs=52057 avg_tb_size=358
qemu: flush code_size=43605160 nb_tbs=78896 avg_tb_size=367
qemu: flush code_size=45166552 nb_tbs=82158 avg_tb_size=364
qemu: flush code_size=63289640 nb_tbs=116494 avg_tb_size=358
qemu: flush code_size=51389960 nb_tbs=93937 avg_tb_size=362
qemu: flush code_size=59665928 nb_tbs=107063 avg_tb_size=372
qemu: flush code_size=38380824 nb_tbs=68597 avg_tb_size=374
qemu: flush code_size=44884568 nb_tbs=79901 avg_tb_size=376
qemu: flush code_size=50782632 nb_tbs=90681 avg_tb_size=374
qemu: flush code_size=39848888 nb_tbs=71433 avg_tb_size=372
qemu: flush code_size=64708840 nb_tbs=119052 avg_tb_size=359
qemu: flush code_size=49830008 nb_tbs=90992 avg_tb_size=362
qemu: flush code_size=68372408 nb_tbs=123442 avg_tb_size=368
qemu: flush code_size=33555560 nb_tbs=59514 avg_tb_size=378
qemu: flush code_size=44748344 nb_tbs=80974 avg_tb_size=367
qemu: flush code_size=37104248 nb_tbs=67609 avg_tb_size=364That is, 20 flushes. Note how a static partitioning approach uses the code buffer poorly, leading to many unnecessary flushes.
--- tcg/tcg.h | 6 ++ accel/tcg/translate-all.c | 63 +++++-------- bsd-user/main.c | 1 + cpus.c | 12 +++ linux-user/main.c | 1 + tcg/tcg.c | 222 +++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 260 insertions(+), 45 deletions(-)
tcg/tcg.h +6 -0
@@ -810,6 +810,12 @@ void *tcg_malloc_internal(TCGContext *s, int size);void tcg_pool_reset (TCGContext *s);TranslationBlock *tcg_tb_alloc (TCGContext *s); +void tcg_region_init (void ); +void tcg_region_reset_all (void ); + +size_t tcg_code_size (void ); +size_t tcg_code_capacity (void ); +/* Called with tb_lock held. */ static inline void *tcg_malloc (int size) {
accel/tcg/translate-all.c +20 -43
155 lines not on this page · raw message
bsd-user/main.c +1 -0
@@ -978,6 +978,7 @@ int main(int argc, char **argv)generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init (tcg_ctx); +tcg_region_init ();/* build Task State */ memset (ts,0 ,sizeof (TaskState));
cpus.c +12 -0
@@ -1664,6 +1664,18 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)char thread_name[VCPU_THREAD_NAME_SIZE ];static QemuCond *single_tcg_halt_cond;static QemuThread *single_tcg_cpu_thread; +static int tcg_region_inited; + +/* +* Initialize TCG regions--once. Now is a good time, because: +* (1) TCG's init context, prologue and target globals have been set up. +* (2) qemu_tcg_mttcg_enabled() works now (TCG init code runs before the +* -accel flag is processed, so the check doesn't work then). +*/ +if (!tcg_region_inited) { + tcg_region_inited =1 ; +tcg_region_init (); + }if (qemu_tcg_mttcg_enabled () || !single_tcg_cpu_thread) { cpu->thread =g_malloc0 (sizeof (QemuThread));
linux-user/main.c +1 -0
@@ -4458,6 +4458,7 @@ int main(int argc, char **argv, char **envp)generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init (tcg_ctx); +tcg_region_init ();#if defined(TARGET_I386 ) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ;
tcg/tcg.c +220 -2
245 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v6 50/50 tcg: enable multiple TCG contexts in softmmu
In reply to Richard HendersonFrom: "Emilio G. Cota" <[email protected]>
This enables parallel TCG code generation. However, we do not take advantage of it yet since tb_lock is still held during tb_gen_code.
In user-mode we use a single TCG context; see the documentation added to tcg_region_init for the rationale.
Note that targets do not need any conversion: targets initialize a TCGContext (e.g. defining TCG globals), and after this initialization has finished, the context is cloned by the vCPU threads, each of them keeping a separate copy.
TCG threads claim one entry in tcg_ctxs[] by atomically increasing n_tcg_ctxs. Do not be too annoyed by the subsequent atomic_read's of that variable and tcg_ctxs; they are there just to play nice with analysis tools such as thread sanitizer.
Note that we do not allocate an array of contexts (we allocate an array of pointers instead) because when tcg_context_init is called, we do not know yet how many contexts we'll use since the bool behind qemu_tcg_mttcg_enabled() isn't set yet.
Previous patches folded some TCG globals into TCGContext. The non-const globals remaining are only set at init time, i.e. before the TCG threads are spawned. Here is a list of these set-at-init-time globals under tcg/:
Only written by tcg_context_init:
- indirect_reg_alloc_order
- tcg_op_defs
Only written by tcg_target_init (called from tcg_context_init):
- tcg_target_available_regs
- tcg_target_call_clobber_regs
- arm: arm_arch, use_idiv_instructions
- i386: have_cmov, have_bmi1, have_bmi2, have_lzcnt, have_movbe, have_popcnt
- mips: use_movnz_instructions, use_mips32_instructions, use_mips32r2_instructions, got_sigill (tcg_target_detect_isa)
- ppc: have_isa_2_06, have_isa_3_00, tb_ret_addr
- s390: tb_ret_addr, s390_facilities
- sparc: qemu_ld_trampoline, qemu_st_trampoline (build_trampolines), use_vis3_instructions
Only written by tcg_prologue_init:
- 'struct jit_code_entry one_entry'
- aarch64: tb_ret_addr
- arm: tb_ret_addr
- i386: tb_ret_addr, guest_base_flags
- ia64: tb_ret_addr
- mips: tb_ret_addr, bswap32_addr, bswap32u_addr, bswap64_addr
--- tcg/tcg.h | 7 ++- accel/tcg/translate-all.c | 2 +- cpus.c | 2 + linux-user/syscall.c | 1 + tcg/tcg.c | 146 +++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 145 insertions(+), 13 deletions(-)
tcg/tcg.h +4 -3
@@ -737,7 +737,7 @@ struct TCGContext { };extern TCGContext tcg_init_ctx; -extern TCGContext *tcg_ctx; +extern __threadTCGContext *tcg_ctx;static inline size_t temp_idx (TCGTemp *ts) {
@@ -805,7 +805,7 @@ static inline bool tcg_op_buf_full(void)/* pool based memory allocation */ -/* tb_lock must be held for tcg_malloc_internal. */ +/* user-mode: tb_lock must be held for tcg_malloc_internal. */ void *tcg_malloc_internal (TCGContext *s,int size);void tcg_pool_reset (TCGContext *s);TranslationBlock *tcg_tb_alloc (TCGContext *s);
@@ -816,7 +816,7 @@ void tcg_region_reset_all(void);size_t tcg_code_size (void );size_t tcg_code_capacity (void ); -/* Called with tb_lock held. */ +/* user-mode: Called with tb_lock held. */ static inline void *tcg_malloc (int size) {TCGContext *s = tcg_ctx;
@@ -836,6 +836,7 @@ static inline void *tcg_malloc(int size) }void tcg_context_init (TCGContext *s); +void tcg_register_thread (void );void tcg_prologue_init (TCGContext *s);void tcg_func_start (TCGContext *s);
accel/tcg/translate-all.c +1 -1
@@ -154,7 +154,7 @@ static void *l1_map[V_L1_MAX_SIZE];/* code generation context */ TCGContext tcg_init_ctx; -TCGContext *tcg_ctx; +__threadTCGContext *tcg_ctx;TBContext tb_ctx;bool parallel_cpus;
cpus.c +2 -0
@@ -1307,6 +1307,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)CPUState *cpu = arg;rcu_register_thread (); +tcg_register_thread ();qemu_mutex_lock_iothread ();qemu_thread_get_self (cpu->thread);
@@ -1454,6 +1455,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)g_assert (!use_icount);rcu_register_thread (); +tcg_register_thread ();qemu_mutex_lock_iothread ();qemu_thread_get_self (cpu->thread);
linux-user/syscall.c +1 -0
@@ -6215,6 +6215,7 @@ static void *clone_func(void *arg)TaskState *ts;rcu_register_thread (); +tcg_register_thread (); env = info->env; cpu =ENV_GET_CPU (env); thread_cpu = cpu;
tcg/tcg.c +137 -9
220 lines not on this page · raw message
Signature · 1 line
2.13.6
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v6 00/50] tcg tb_lock removal
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'a7a80a1761 tcg: enable multiple TCG contexts in softmmu45b2d9096d tcg: introduce regions to split code_gen_buffercc99683553 translate-all: use qemu_protect_rwx/none helpers98da101651 osdep: introduce qemu_mprotect_rwx/none15f78c7e81 tcg: allocate optimizer temps with tcg_malloceef9b06948 tcg: distribute profiling counters across TCGContext's 0407851577 tcg: introduce **tcg_ctxs to keep track of all TCGContext's e77580ec19 gen-icount: fold exitreq_label into TCGContexta42271eb2a tcg: define tcg_init_ctx and make tcg_ctx a pointer e90bedf9c9 tcg: take tb_ctx out of TCGContextaa32e035a4 translate-all: report correct avg host TB size75b3259505 exec-all: rename tb_free to tb_remove146f8837fa translate-all: use a binary search tree to track TBs in TBContext aa80b9aab0 tcg: Remove CF_IGNORE_ICOUNTa666027577 tcg: Add CF_LAST_IO + CF_USE_ICOUNT to CF_HASH_MASK ff25a4de38 cpu-exec: lookup/generate TB outside exclusive region during step_atomic fabf792f62 tcg: check CF_PARALLEL instead of parallel_cpusa420a291f1 target/sparc: check CF_PARALLEL instead of parallel_cpus 590acd9365 target/sh4: check CF_PARALLEL instead of parallel_cpus 65f026c3d9 target/s390x: check CF_PARALLEL instead of parallel_cpus 04ed7cef2f target/m68k: check CF_PARALLEL instead of parallel_cpus bc5868d322 target/i386: check CF_PARALLEL instead of parallel_cpus 80c379d85a target/hppa: check CF_PARALLEL instead of parallel_cpus b81fc08b40 target/arm: check CF_PARALLEL instead of parallel_cpus 8a82d2d8c5 tcg: convert tb->cflags reads to tb_cflags(tb)e72fce1f10 tcg: Include CF_COUNT_MASK in CF_HASH_MASK4b93cb71c0 tcg: Add CPUState step_next_tbf8ad2e06db hack dump tb->flags and tb->cflagsfb77430355 tcg: define CF_PARALLEL and use it for TB hashing along with CF_COUNT_MASK 4015ca53aa tcg: Use pointers in TCGOp->argsfb2e994a9e qom: Introduce CPUClass.tcg_initialized38b346bc8 target/alpha: Avoid translate_init unless tcg_enabled 4dc76582d0 tcg: Reserve temporary index 00b0397a863 tcg: Introduce index_arg5aedea1076 tcg: Push tcg_ctx into tcg_gen_callNc70aed7e09 tcg: Push tcg_ctx into generator functionse086b91868 tcg: Use per-temp state data in optimize180e36d249 tcg: Export temp_idx0367cc88b5 tcg: Remove unused TCG_CALL_DUMMY_TCGVa84f9e98c9 tcg: Change temp_allocate_frame arg to TCGTempff6a503bf4 tcg: Avoid loops against variable bounds66ce744e70 tcg: Use per-temp state data in liveness6fded83e78 tcg: Introduce temp_arg6ca9011a8f tcg: Return NULL temp for TCG_CALL_DUMMY_ARG1a61746e2c tcg: Add temp_global bit to TCGTemp838e08d353 tcg: Introduce arg_temp7458bf1177 tcg: Propagate TCGOp down to allocators41bd25c6cf tcg: Propagate args to op->args in tcg.c9622f2d4f7 tcg: Propagate args to op->args in optimizerbb243a992e tcg: Merge opcode arguments into TCGOp
=== OUTPUT BEGIN ===
Checking PATCH 1/50: tcg: Merge opcode arguments into TCGOp...
ERROR: spaces prohibited around that ':' (ctx:WxW) #481: FILE: tcg/tcg.h:613:
+ unsigned calli : 4; /* 12 */
^
ERROR: spaces prohibited around that ':' (ctx:WxW) #482: FILE: tcg/tcg.h:614:
+ unsigned callo : 2; /* 14 */
^
ERROR: space prohibited before that ':' (ctx:WxW)
#483: FILE: tcg/tcg.h:615:
+ unsigned : 2; /* 16 */
^
ERROR: spaces prohibited around that ':' (ctx:WxW) #488: FILE: tcg/tcg.h:618:
+ unsigned prev : 16; /* 32 */
^
ERROR: spaces prohibited around that ':' (ctx:WxW) #489: FILE: tcg/tcg.h:619:
+ unsigned next : 16; /* 48 */
^
total: 5 errors, 0 warnings, 485 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 2/50: tcg: Propagate args to op->args in optimizer...
ERROR: spaces required around that '-' (ctx:VxV)
#648: FILE: tcg/optimize.c:1165:
+ tcg_opt_gen_mov(s, op, op->args[0], op->args[4-tmp]);
^total: 1 errors, 0 warnings, 912 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 3/50: tcg: Propagate args to op->args in tcg.c... Checking PATCH 4/50: tcg: Propagate TCGOp down to allocators... Checking PATCH 5/50: tcg: Introduce arg_temp...
Checking PATCH 6/50: tcg: Add temp_global bit to TCGTemp... Checking PATCH 7/50: tcg: Return NULL temp for TCG_CALL_DUMMY_ARG... Checking PATCH 8/50: tcg: Introduce temp_arg...
Checking PATCH 9/50: tcg: Use per-temp state data in liveness...
WARNING: line over 80 characters
#186: FILE: tcg/tcg.c:1815:
+ } else if (arg_temp(op->args[0])->state == TS_DEAD && have_opc_new2) {
total: 0 errors, 1 warnings, 441 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 10/50: tcg: Avoid loops against variable bounds...
Checking PATCH 11/50: tcg: Change temp_allocate_frame arg to TCGTemp...
Checking PATCH 12/50: tcg: Remove unused TCG_CALL_DUMMY_TCGV...
Checking PATCH 13/50: tcg: Export temp_idx...
Checking PATCH 14/50: tcg: Use per-temp state data in optimize...
Checking PATCH 15/50: tcg: Push tcg_ctx into generator functions...
Checking PATCH 16/50: tcg: Push tcg_ctx into tcg_gen_callN...
Checking PATCH 17/50: tcg: Introduce index_arg...
Checking PATCH 18/50: tcg: Reserve temporary index 0...
Checking PATCH 19/50: target/alpha: Avoid translate_init unless tcg_enabled... Checking PATCH 20/50: qom: Introduce CPUClass.tcg_initialize...
Checking PATCH 21/50: tcg: Use pointers in TCGOp->args...
Checking PATCH 22/50: tcg: define CF_PARALLEL and use it for TB hashing along with CF_COUNT_MASK... Checking PATCH 23/50: hack dump tb->flags and tb->cflags...
Checking PATCH 24/50: tcg: Add CPUState step_next_tb...
Checking PATCH 25/50: tcg: Include CF_COUNT_MASK in CF_HASH_MASK...
Checking PATCH 26/50: tcg: convert tb->cflags reads to tb_cflags(tb)...
ERROR: return is not a function, parentheses are not required
#102: FILE: target/alpha/translate.c:458:
+ return ((tb_cflags(ctx->base.tb) & CF_LAST_IO)
WARNING: line over 80 characters
#218: FILE: target/hppa/translate.c:472:
+ if ((tb_cflags(ctx->base.tb) & CF_LAST_IO) || ctx->base.singlestep_enabled) {
total: 1 errors, 1 warnings, 924 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 27/50: target/arm: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 28/50: target/hppa: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 29/50: target/i386: check CF_PARALLEL instead of parallel_cpus...
WARNING: line over 80 characters
#22: FILE: target/i386/translate.c:5268:
+ if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) {
WARNING: line over 80 characters
#31: FILE: target/i386/translate.c:5279:
+ if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) {
total: 0 errors, 2 warnings, 16 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 30/50: target/m68k: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 31/50: target/s390x: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 32/50: target/sh4: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 33/50: target/sparc: check CF_PARALLEL instead of parallel_cpus... Checking PATCH 34/50: tcg: check CF_PARALLEL instead of parallel_cpus...
Checking PATCH 35/50: cpu-exec: lookup/generate TB outside exclusive region during step_atomic... Checking PATCH 36/50: tcg: Add CF_LAST_IO + CF_USE_ICOUNT to CF_HASH_MASK... Checking PATCH 37/50: tcg: Remove CF_IGNORE_ICOUNT...
Checking PATCH 38/50: translate-all: use a binary search tree to track TBs in TBContext... Checking PATCH 39/50: exec-all: rename tb_free to tb_remove...
Checking PATCH 40/50: translate-all: report correct avg host TB size...
Checking PATCH 41/50: tcg: take tb_ctx out of TCGContext...
Checking PATCH 42/50: tcg: define tcg_init_ctx and make tcg_ctx a pointer... Checking PATCH 43/50: gen-icount: fold exitreq_label into TCGContext...
Checking PATCH 44/50: tcg: introduce **tcg_ctxs to keep track of all TCGContext's... Checking PATCH 45/50: tcg: distribute profiling counters across TCGContext's... Checking PATCH 46/50: tcg: allocate optimizer temps with tcg_malloc...
Checking PATCH 47/50: osdep: introduce qemu_mprotect_rwx/none...
Checking PATCH 48/50: translate-all: use qemu_protect_rwx/none helpers... Checking PATCH 49/50: tcg: introduce regions to split code_gen_buffer...
Checking PATCH 50/50: tcg: enable multiple TCG contexts in softmmu...
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 3 lines · Richard Henderson
Thus, an extra 20 patches in the patch set rearranging how temps are referenced within the TCG backend. Some of them have appeared on the list before, but it would have been last November.
I remember seeing these on the list before -- in June'17:
https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg04596.html
FWIW with these 20 patches we no longer get a code reduction:
text data bss dec hex filename
6850654 2144032 4420896 13415582 ccb49e alpha-softmmu/qemu-system-alpha (before)
6874086 2144032 4437248 13455366 cd5006 alpha-softmmu/qemu-system-alpha (after)
but we've got to keep in mind that the patches aren't exactly the same.
E.
Quoted 10 lines · Richard Henderson
I've fixed two bugs within v5 of Emilio's patch set:
- The
step_next_tbpatch fixes the "rep movsb" bug that appeared when we includedCF_COUNT_MASKintoCF_HASH_MASK. We had been relying on magic to single-step the next guest insn.- The original "allocate optimizer temps with
tcg_malloc" patch failed testing on arm32 host. I didn't really look into exactly what was wrong because I had an older patch set that touched the same portion of the optimizer.
Thanks a lot for fixing these issues and respinning the series.
I have just pushed a branch on top of this series that includes 10 patches that further pave the way for the removal of tb_lock:
https://github.com/cota/qemu/tree/multi-tcg-v6-plus
These patches are a subset of the ones that I posted on the tb_lock removal patchset [1]. In particular, these patches are groundwork that doesn't change anything fundamental wrt locking, which does get tricky.
Given how close we are to the soft freeze for 2.11 [2], do you want me to post these patches on the list for review? Otherwise I can wait for the 2.12 dev cycle to post them with the complete tb_lock removal work.
That said, I think we should at least cherry-pick "translate-all: exit from tb_phys_invalidate if qht_remove fails" for 2.11, since it fixes a real bug. Stable should also get it.
Thanks,
Emilio
[1] https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg01199.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg02217.html
Quoted 12 lines · Emilio G. Cota
Quoted 10 lines · Richard Henderson
I've fixed two bugs within v5 of Emilio's patch set:
- The
step_next_tbpatch fixes the "rep movsb" bug that appeared when we includedCF_COUNT_MASKintoCF_HASH_MASK. We had been relying on magic to single-step the next guest insn.- The original "allocate optimizer temps with
tcg_malloc" patch failed testing on arm32 host. I didn't really look into exactly what was wrong because I had an older patch set that touched the same portion of the optimizer.
Quoted 6 lines
Thanks a lot for fixing these issues and respinning the series.
I have just pushed a branch on top of this series that includes 10 patches that further pave the way for the removal of
tb_lock:
I started reviewing those, I have a few questions:
1) why is tcg_region_tree separate from tcg_region_state? Would it make sense to prepare a linked list of tcg_region_state structs, and reuse the region lock for the region tree?
2) in tb_for_each_tagged_safe, could the "prev" argument instead be "next", like
+ for (n = (head) & 1, \ + tb = (TranslationBlock *)((head) & ~1); \ + tb && ((next = (TranslationBlock *)tb->field[n]), 1); \ + n = (uintptr_t)next & 1, \
+ tb = (TranslationBlock *)((uintptr_t)next & ~1))
(also please make the iterator macros UPPERCASE)
3) "translate-all: exit from tb_phys_invalidate if qht_remove fails" may be worth posting now?
Paolo
Quoted 22 lines
These patches are a subset of the ones that I posted on the
tb_lockremoval patchset [1]. In particular, these patches are groundwork that doesn't change anything fundamental wrt locking, which does get tricky.Given how close we are to the soft freeze for 2.11 [2], do you want me to post these patches on the list for review? Otherwise I can wait for the 2.12 dev cycle to post them with the complete
tb_lockremoval work.That said, I think we should at least cherry-pick "translate-all: exit from
tb_phys_invalidateifqht_removefails" for 2.11, since it fixes a real bug. Stable should also get it.Thanks,
Emilio
[1] https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg01199.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg02217.html
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Emilio G. Cota
I have just pushed a branch on top of this series that includes 10 patches that further pave the way for the removal of
tb_lock:I started reviewing those,
Nice, thanks!
Quoted 5 lines
I have a few questions:
1) why is
tcg_region_treeseparate fromtcg_region_state? Would it make sense to prepare a linked list oftcg_region_statestructs, and reuse the region lock for the region tree?
I think the naming here might be confusing; "tcg_region_state" should be understood as "tcg_region_global_state". IOW, there is no per-region struct.
That said, the array of per-region trees could be embedded in this global struct. I was hesitant to do so because then one could think that region_state.lock and rt.lock are somehow related; they are not.
Review
Quoted 9 lines
2) in
tb_for_each_tagged_safe, could the "prev" argument instead be "next", like(quoted diff) +5
-0+ for (n = (head) & 1, \ + tb = (TranslationBlock *)((head) & ~1); \ + tb && ((next = (TranslationBlock *)tb->field[n]), 1); \ + n = (uintptr_t)next & 1, \ + tb = (TranslationBlock *)((uintptr_t)next & ~1))
Is this just to make them closer to the macros in queue.h?
In this case tracking *prev in the loop (rather than next) is useful because it makes removing the "current" element very simple:
static inline void tb_page_remove(PageDesc *pd, TranslationBlock *tb)
{
TranslationBlock *tb1;
uintptr_t *prev;
unsigned int n1;
page_for_each_tb_safe(pd, tb1, n1, prev) {
if (tb1 == tb) {
*prev = tb1->page_next[n1];
return;
}
}
g_assert_not_reached();
}If we wanted to use something similar to QSLIST_REMOVE_AFTER, we'd have to track three pointers instead of two: prev (tracked by the caller), current and next (these two as part of the for loop).
Quoted 1 line
(also please make the iterator macros UPPERCASE)
Will do.
Quoted 2 lines
3) "translate-all: exit from
tb_phys_invalidateifqht_removefails" may be worth posting now?
I'll post it to be included in the next iteration of this series.
Thanks,
Emilio
Quoted 17 lines · Emilio G. Cota
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Emilio G. Cota
I have just pushed a branch on top of this series that includes 10 patches that further pave the way for the removal of
tb_lock:I started reviewing those,
Nice, thanks!
Quoted 5 lines
I have a few questions:
1) why is
tcg_region_treeseparate fromtcg_region_state? Would it make sense to prepare a linked list oftcg_region_statestructs, and reuse the region lock for the region tree?
Quoted 6 lines
I think the naming here might be confusing; "
tcg_region_state" should be understood as "tcg_region_global_state". IOW, there is no per-region struct.That said, the array of per-region trees could be embedded in this global struct. I was hesitant to do so because then one could think that region_state.lock and rt.lock are somehow related; they are not.
Ok, this is clearer now.
Quoted 7 lines
Quoted 2 lines
2) in
tb_for_each_tagged_safe, could the "prev" argument instead be "next", likeIs this just to make them closer to the macros in
queue.h?In this case tracking *prev in the loop (rather than next) is useful because it makes removing the "current" element very simple:
This actually makes a lot of sense. Maybe we should change queue.h the other way. ;)
Can you rename "prev" to "pprev" though?
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines
Quoted 2 lines
2) in
tb_for_each_tagged_safe, could the "prev" argument instead be "next", likeIs this just to make them closer to the macros in
queue.h?In this case tracking *prev in the loop (rather than next) is useful because it makes removing the "current" element very simple:
This actually makes a lot of sense. Maybe we should change
queue.hthe other way. ;)
Turns out this works here but it isn't as general-purpose as it might look. In this case it works because we don't free the tb. If we did, then we'd either need a branch in the iterator or a third *next pointer.
In fact, the macro wouldn't be safe even if it tracked *next, since on a removal *pprev must not be updated to the removed item. IOW, the caller must be the one keeping track of *pprev, for otherwise things break after the first removal. (Again, this doesn't affect this particular instance, because its only caller stops iterating after a removal.)
I have therefore given up on the macro and changed its only caller to update *pprev. IMO it's less pretty, but more robust.
The updated branch with the changes you suggested (plus the above) is available at:
https://github.com/cota/qemu/tree/multi-tcg-v6-plus2
Thanks,
Emilio
I have given a respin to the tb_lock branch on top of master. Turns out the freezes I was getting were due to the magic we used to rely on (e.g. for icount). Works now!
The branch is here:
https://github.com/cota/qemu/tree/tb-lock
Boot-tested on ppc64, aarch64 and alpha smp guests (<=64) with MTTCG.
A couple of questions:
- Does anyone remember what work remains to be done to safely enable MTTCG for i386? I just forced it on: without the tb lock removal I booted an 8-core guest, but without tb_lock the guest kernel dies pretty quickly. So I guess there's still work to do.
- In user-mode without tb_lock, should I worry about fork happening while any of the newly-introduced locks are held? For instance, tb->jmp_lock (introduced in "translate-all: protect TB jumps with a per-destination-TB lock"), or tcg_region_tree's lock.
Thanks,
Emilio