aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--target-arm/translate.c35
-rw-r--r--target-i386/translate.c53
-rw-r--r--target-mips/translate.c38
-rw-r--r--target-sparc/translate.c56
4 files changed, 110 insertions, 72 deletions
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 96e7fd2919..afb9b57c89 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -903,16 +903,26 @@ static int disas_vfp_insn(CPUState * env, DisasContext *s, uint32_t insn)
return 0;
}
-static inline void gen_jmp_tb(long tb, int n, uint32_t dest)
+static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
{
- if (n == 0)
- gen_op_goto_tb0(TBPARAM(tb));
- else
- gen_op_goto_tb1(TBPARAM(tb));
- gen_op_movl_T0_im(dest);
- gen_op_movl_r15_T0();
- gen_op_movl_T0_im(tb + n);
- gen_op_exit_tb();
+ TranslationBlock *tb;
+
+ tb = s->tb;
+ if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
+ if (n == 0)
+ gen_op_goto_tb0(TBPARAM(tb));
+ else
+ gen_op_goto_tb1(TBPARAM(tb));
+ gen_op_movl_T0_im(dest);
+ gen_op_movl_r15_T0();
+ gen_op_movl_T0_im((long)tb + n);
+ gen_op_exit_tb();
+ } else {
+ gen_op_movl_T0_im(dest);
+ gen_op_movl_r15_T0();
+ gen_op_movl_T0_0();
+ gen_op_exit_tb();
+ }
}
static inline void gen_jmp (DisasContext *s, uint32_t dest)
@@ -924,8 +934,7 @@ static inline void gen_jmp (DisasContext *s, uint32_t dest)
gen_op_movl_T0_im(dest);
gen_bx(s);
} else {
- long tb = (long)s->tb;
- gen_jmp_tb(tb, 0, dest);
+ gen_goto_tb(s, 0, dest);
s->is_jmp = DISAS_TB_JUMP;
}
}
@@ -2137,7 +2146,7 @@ static inline int gen_intermediate_code_internal(CPUState *env,
} else {
switch(dc->is_jmp) {
case DISAS_NEXT:
- gen_jmp_tb((long)dc->tb, 1, dc->pc);
+ gen_goto_tb(dc, 1, dc->pc);
break;
default:
case DISAS_JUMP:
@@ -2152,7 +2161,7 @@ static inline int gen_intermediate_code_internal(CPUState *env,
}
if (dc->condjmp) {
gen_set_label(dc->condlabel);
- gen_jmp_tb((long)dc->tb, 1, dc->pc);
+ gen_goto_tb(dc, 1, dc->pc);
dc->condjmp = 0;
}
}
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 0f6b0eb7c6..dab0378079 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -1700,6 +1700,31 @@ static inline int insn_const_size(unsigned int ot)
return 4;
}
+static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong eip)
+{
+ TranslationBlock *tb;
+ target_ulong pc;
+
+ pc = s->cs_base + eip;
+ tb = s->tb;
+ /* NOTE: we handle the case where the TB spans two pages here */
+ if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) ||
+ (pc & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) {
+ /* jump to same page: we can use a direct jump */
+ if (tb_num == 0)
+ gen_op_goto_tb0(TBPARAM(tb));
+ else
+ gen_op_goto_tb1(TBPARAM(tb));
+ gen_jmp_im(eip);
+ gen_op_movl_T0_im((long)tb + tb_num);
+ gen_op_exit_tb();
+ } else {
+ /* jump to another page: currently not optimized */
+ gen_jmp_im(eip);
+ gen_eob(s);
+ }
+}
+
static inline void gen_jcc(DisasContext *s, int b,
target_ulong val, target_ulong next_eip)
{
@@ -1779,8 +1804,10 @@ static inline void gen_jcc(DisasContext *s, int b,
break;
}
- if (s->cc_op != CC_OP_DYNAMIC)
+ if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
+ s->cc_op = CC_OP_DYNAMIC;
+ }
if (!func) {
gen_setcc_slow[jcc_op]();
@@ -1797,16 +1824,10 @@ static inline void gen_jcc(DisasContext *s, int b,
l1 = gen_new_label();
func(l1);
- gen_op_goto_tb0(TBPARAM(tb));
- gen_jmp_im(next_eip);
- gen_op_movl_T0_im((long)tb + 0);
- gen_op_exit_tb();
+ gen_goto_tb(s, 0, next_eip);
gen_set_label(l1);
- gen_op_goto_tb1(TBPARAM(tb));
- gen_jmp_im(val);
- gen_op_movl_T0_im((long)tb + 1);
- gen_op_exit_tb();
+ gen_goto_tb(s, 1, val);
s->is_jmp = 3;
} else {
@@ -2217,18 +2238,12 @@ static void gen_eob(DisasContext *s)
direct call to the next block may occur */
static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num)
{
- TranslationBlock *tb = s->tb;
-
if (s->jmp_opt) {
- if (s->cc_op != CC_OP_DYNAMIC)
+ if (s->cc_op != CC_OP_DYNAMIC) {
gen_op_set_cc_op(s->cc_op);
- if (tb_num)
- gen_op_goto_tb1(TBPARAM(tb));
- else
- gen_op_goto_tb0(TBPARAM(tb));
- gen_jmp_im(eip);
- gen_op_movl_T0_im((long)tb + tb_num);
- gen_op_exit_tb();
+ s->cc_op = CC_OP_DYNAMIC;
+ }
+ gen_goto_tb(s, tb_num, eip);
s->is_jmp = 3;
} else {
gen_jmp_im(eip);
diff --git a/target-mips/translate.c b/target-mips/translate.c
index 5e54dd84bf..2dc33af728 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -928,15 +928,23 @@ static void gen_trap (DisasContext *ctx, uint16_t opc,
ctx->bstate = BS_STOP;
}
-static inline void gen_jmp_tb(long tb, int n, uint32_t dest)
+static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
{
- if (n == 0)
- gen_op_goto_tb0(TBPARAM(tb));
- else
- gen_op_goto_tb1(TBPARAM(tb));
- gen_op_save_pc(dest);
- gen_op_set_T0(tb + n);
- gen_op_exit_tb();
+ TranslationBlock *tb;
+ tb = ctx->tb;
+ if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
+ if (n == 0)
+ gen_op_goto_tb0(TBPARAM(tb));
+ else
+ gen_op_goto_tb1(TBPARAM(tb));
+ gen_op_save_pc(dest);
+ gen_op_set_T0((long)tb + n);
+ gen_op_exit_tb();
+ } else {
+ gen_op_save_pc(dest);
+ gen_op_set_T0(0);
+ gen_op_exit_tb();
+ }
}
/* Branches (before delay slot) */
@@ -1035,7 +1043,7 @@ static void gen_compute_branch (DisasContext *ctx, uint16_t opc,
case OPC_BLTZL: /* 0 < 0 likely */
/* Skip the instruction in the delay slot */
MIPS_DEBUG("bnever and skip");
- gen_jmp_tb((long)ctx->tb, 0, ctx->pc + 4);
+ gen_goto_tb(ctx, 0, ctx->pc + 4);
return;
case OPC_J:
ctx->hflags |= MIPS_HFLAG_DS | MIPS_HFLAG_B;
@@ -1278,7 +1286,7 @@ static void gen_blikely(DisasContext *ctx)
l1 = gen_new_label();
gen_op_jnz_T2(l1);
gen_op_save_state(ctx->hflags & ~(MIPS_HFLAG_BMASK | MIPS_HFLAG_DS));
- gen_jmp_tb((long)ctx->tb, 1, ctx->pc + 4);
+ gen_goto_tb(ctx, 1, ctx->pc + 4);
}
static void decode_opc (DisasContext *ctx)
@@ -1502,12 +1510,12 @@ static void decode_opc (DisasContext *ctx)
case MIPS_HFLAG_B:
/* unconditional branch */
MIPS_DEBUG("unconditional branch");
- gen_jmp_tb((long)ctx->tb, 0, ctx->btarget);
+ gen_goto_tb(ctx, 0, ctx->btarget);
break;
case MIPS_HFLAG_BL:
/* blikely taken case */
MIPS_DEBUG("blikely branch taken");
- gen_jmp_tb((long)ctx->tb, 0, ctx->btarget);
+ gen_goto_tb(ctx, 0, ctx->btarget);
break;
case MIPS_HFLAG_BC:
/* Conditional branch */
@@ -1516,9 +1524,9 @@ static void decode_opc (DisasContext *ctx)
int l1;
l1 = gen_new_label();
gen_op_jnz_T2(l1);
- gen_jmp_tb((long)ctx->tb, 0, ctx->btarget);
+ gen_goto_tb(ctx, 0, ctx->btarget);
gen_set_label(l1);
- gen_jmp_tb((long)ctx->tb, 1, ctx->pc + 4);
+ gen_goto_tb(ctx, 1, ctx->pc + 4);
}
break;
case MIPS_HFLAG_BR:
@@ -1603,7 +1611,7 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
}
if (ctx.bstate != BS_BRANCH && ctx.bstate != BS_EXCP) {
save_cpu_state(ctxp, 0);
- gen_jmp_tb((long)ctx.tb, 0, ctx.pc);
+ gen_goto_tb(&ctx, 0, ctx.pc);
}
gen_op_reset_T0();
/* Generate the return instruction */
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index 9abcedda73..6340e15225 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -561,6 +561,32 @@ static inline void gen_movl_npc_im(target_ulong npc)
#endif
}
+static inline void gen_goto_tb(DisasContext *s, int tb_num,
+ target_ulong pc, target_ulong npc)
+{
+ TranslationBlock *tb;
+
+ tb = s->tb;
+ if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
+ (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
+ /* jump to same page: we can use a direct jump */
+ if (tb_num == 0)
+ gen_op_goto_tb0(TBPARAM(tb));
+ else
+ gen_op_goto_tb1(TBPARAM(tb));
+ gen_jmp_im(pc);
+ gen_movl_npc_im(npc);
+ gen_op_movl_T0_im((long)tb + tb_num);
+ gen_op_exit_tb();
+ } else {
+ /* jump to another page: currently not optimized */
+ gen_jmp_im(pc);
+ gen_movl_npc_im(npc);
+ gen_op_movl_T0_0();
+ gen_op_exit_tb();
+ }
+}
+
static inline void gen_branch2(DisasContext *dc, long tb, target_ulong pc1, target_ulong pc2)
{
int l1;
@@ -569,18 +595,10 @@ static inline void gen_branch2(DisasContext *dc, long tb, target_ulong pc1, targ
gen_op_jz_T2_label(l1);
- gen_op_goto_tb0(TBPARAM(tb));
- gen_jmp_im(pc1);
- gen_movl_npc_im(pc1 + 4);
- gen_op_movl_T0_im((long)tb + 0);
- gen_op_exit_tb();
+ gen_goto_tb(dc, 0, pc1, pc1 + 4);
gen_set_label(l1);
- gen_op_goto_tb1(TBPARAM(tb));
- gen_jmp_im(pc2);
- gen_movl_npc_im(pc2 + 4);
- gen_op_movl_T0_im((long)tb + 1);
- gen_op_exit_tb();
+ gen_goto_tb(dc, 1, pc2, pc2 + 4);
}
static inline void gen_branch_a(DisasContext *dc, long tb, target_ulong pc1, target_ulong pc2)
@@ -591,27 +609,15 @@ static inline void gen_branch_a(DisasContext *dc, long tb, target_ulong pc1, tar
gen_op_jz_T2_label(l1);
- gen_op_goto_tb0(TBPARAM(tb));
- gen_jmp_im(pc2);
- gen_movl_npc_im(pc1);
- gen_op_movl_T0_im((long)tb + 0);
- gen_op_exit_tb();
+ gen_goto_tb(dc, 0, pc2, pc1);
gen_set_label(l1);
- gen_op_goto_tb1(TBPARAM(tb));
- gen_jmp_im(pc2 + 4);
- gen_movl_npc_im(pc2 + 8);
- gen_op_movl_T0_im((long)tb + 1);
- gen_op_exit_tb();
+ gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
}
static inline void gen_branch(DisasContext *dc, long tb, target_ulong pc, target_ulong npc)
{
- gen_op_goto_tb0(TBPARAM(tb));
- gen_jmp_im(pc);
- gen_movl_npc_im(npc);
- gen_op_movl_T0_im((long)tb + 0);
- gen_op_exit_tb();
+ gen_goto_tb(dc, 0, pc, npc);
}
static inline void gen_generic_branch(DisasContext *dc, target_ulong npc1, target_ulong npc2)