4 #include "exec/exec-all.h"
5 #include "qemu/timer.h"
7 /* Helpers for instruction counting code generation. */
9 static TCGOp
*icount_start_insn
;
11 static inline void gen_io_start(void)
13 TCGv_i32 tmp
= tcg_const_i32(1);
14 tcg_gen_st_i32(tmp
, cpu_env
,
15 offsetof(ArchCPU
, parent_obj
.can_do_io
) -
16 offsetof(ArchCPU
, env
));
17 tcg_temp_free_i32(tmp
);
21 * cpu->can_do_io is cleared automatically at the beginning of
22 * each translation block. The cost is minimal and only paid
23 * for -icount, plus it would be very easy to forget doing it
24 * in the translator. Therefore, backends only need to call
27 static inline void gen_io_end(void)
29 TCGv_i32 tmp
= tcg_const_i32(0);
30 tcg_gen_st_i32(tmp
, cpu_env
,
31 offsetof(ArchCPU
, parent_obj
.can_do_io
) -
32 offsetof(ArchCPU
, env
));
33 tcg_temp_free_i32(tmp
);
36 static inline void gen_tb_start(const TranslationBlock
*tb
)
40 tcg_ctx
->exitreq_label
= gen_new_label();
41 if (tb_cflags(tb
) & CF_USE_ICOUNT
) {
42 count
= tcg_temp_local_new_i32();
44 count
= tcg_temp_new_i32();
47 tcg_gen_ld_i32(count
, cpu_env
,
48 offsetof(ArchCPU
, neg
.icount_decr
.u32
) -
49 offsetof(ArchCPU
, env
));
51 if (tb_cflags(tb
) & CF_USE_ICOUNT
) {
53 * We emit a sub with a dummy immediate argument. Keep the insn index
54 * of the sub so that we later (when we know the actual insn count)
55 * can update the argument with the actual insn count.
57 tcg_gen_sub_i32(count
, count
, tcg_constant_i32(0));
58 icount_start_insn
= tcg_last_op();
61 tcg_gen_brcondi_i32(TCG_COND_LT
, count
, 0, tcg_ctx
->exitreq_label
);
63 if (tb_cflags(tb
) & CF_USE_ICOUNT
) {
64 tcg_gen_st16_i32(count
, cpu_env
,
65 offsetof(ArchCPU
, neg
.icount_decr
.u16
.low
) -
66 offsetof(ArchCPU
, env
));
70 tcg_temp_free_i32(count
);
73 static inline void gen_tb_end(const TranslationBlock
*tb
, int num_insns
)
75 if (tb_cflags(tb
) & CF_USE_ICOUNT
) {
77 * Update the num_insn immediate parameter now that we know
78 * the actual insn count.
80 tcg_set_insn_param(icount_start_insn
, 2,
81 tcgv_i32_arg(tcg_constant_i32(num_insns
)));
84 gen_set_label(tcg_ctx
->exitreq_label
);
85 tcg_gen_exit_tb(tb
, TB_EXIT_REQUESTED
);