mirror of https://github.com/xemu-project/xemu.git
target-arm: use tcg_global_mem_new_i32 to allocate registers
Currently each read/write of ARM register involves a LD/ST TCG operation. This patch uses TCG memory-backed registers to represent the ARM register set. With memory-backed registers the LD/ST operations are transparently generated by TCG and host registers could be used to optimize the generated code. Signed-off-by: Filip Navara <filip.navara@gmail.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
5afe3f042a
commit
155c3eacd2
|
@ -75,6 +75,7 @@ typedef struct DisasContext {
|
||||||
static TCGv_ptr cpu_env;
|
static TCGv_ptr cpu_env;
|
||||||
/* We reuse the same 64-bit temporaries for efficiency. */
|
/* We reuse the same 64-bit temporaries for efficiency. */
|
||||||
static TCGv_i64 cpu_V0, cpu_V1, cpu_M0;
|
static TCGv_i64 cpu_V0, cpu_V1, cpu_M0;
|
||||||
|
static TCGv_i32 cpu_R[16];
|
||||||
|
|
||||||
/* FIXME: These should be removed. */
|
/* FIXME: These should be removed. */
|
||||||
static TCGv cpu_T[2];
|
static TCGv cpu_T[2];
|
||||||
|
@ -84,14 +85,26 @@ static TCGv_i64 cpu_F0d, cpu_F1d;
|
||||||
#define ICOUNT_TEMP cpu_T[0]
|
#define ICOUNT_TEMP cpu_T[0]
|
||||||
#include "gen-icount.h"
|
#include "gen-icount.h"
|
||||||
|
|
||||||
|
static const char *regnames[] =
|
||||||
|
{ "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
||||||
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };
|
||||||
|
|
||||||
/* initialize TCG globals. */
|
/* initialize TCG globals. */
|
||||||
void arm_translate_init(void)
|
void arm_translate_init(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
||||||
|
|
||||||
cpu_T[0] = tcg_global_reg_new_i32(TCG_AREG1, "T0");
|
cpu_T[0] = tcg_global_reg_new_i32(TCG_AREG1, "T0");
|
||||||
cpu_T[1] = tcg_global_reg_new_i32(TCG_AREG2, "T1");
|
cpu_T[1] = tcg_global_reg_new_i32(TCG_AREG2, "T1");
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
|
||||||
|
offsetof(CPUState, regs[i]),
|
||||||
|
regnames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
#define GEN_HELPER 2
|
#define GEN_HELPER 2
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
}
|
}
|
||||||
|
@ -166,7 +179,7 @@ static void load_reg_var(DisasContext *s, TCGv var, int reg)
|
||||||
addr = (long)s->pc + 4;
|
addr = (long)s->pc + 4;
|
||||||
tcg_gen_movi_i32(var, addr);
|
tcg_gen_movi_i32(var, addr);
|
||||||
} else {
|
} else {
|
||||||
tcg_gen_ld_i32(var, cpu_env, offsetof(CPUState, regs[reg]));
|
tcg_gen_mov_i32(var, cpu_R[reg]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +199,7 @@ static void store_reg(DisasContext *s, int reg, TCGv var)
|
||||||
tcg_gen_andi_i32(var, var, ~1);
|
tcg_gen_andi_i32(var, var, ~1);
|
||||||
s->is_jmp = DISAS_JUMP;
|
s->is_jmp = DISAS_JUMP;
|
||||||
}
|
}
|
||||||
tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, regs[reg]));
|
tcg_gen_mov_i32(cpu_R[reg], var);
|
||||||
dead_tmp(var);
|
dead_tmp(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,27 +801,22 @@ static inline void gen_bx_im(DisasContext *s, uint32_t addr)
|
||||||
TCGv tmp;
|
TCGv tmp;
|
||||||
|
|
||||||
s->is_jmp = DISAS_UPDATE;
|
s->is_jmp = DISAS_UPDATE;
|
||||||
tmp = new_tmp();
|
|
||||||
if (s->thumb != (addr & 1)) {
|
if (s->thumb != (addr & 1)) {
|
||||||
|
tmp = new_tmp();
|
||||||
tcg_gen_movi_i32(tmp, addr & 1);
|
tcg_gen_movi_i32(tmp, addr & 1);
|
||||||
tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, thumb));
|
tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, thumb));
|
||||||
|
dead_tmp(tmp);
|
||||||
}
|
}
|
||||||
tcg_gen_movi_i32(tmp, addr & ~1);
|
tcg_gen_movi_i32(cpu_R[15], addr & ~1);
|
||||||
tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, regs[15]));
|
|
||||||
dead_tmp(tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set PC and Thumb state from var. var is marked as dead. */
|
/* Set PC and Thumb state from var. var is marked as dead. */
|
||||||
static inline void gen_bx(DisasContext *s, TCGv var)
|
static inline void gen_bx(DisasContext *s, TCGv var)
|
||||||
{
|
{
|
||||||
TCGv tmp;
|
|
||||||
|
|
||||||
s->is_jmp = DISAS_UPDATE;
|
s->is_jmp = DISAS_UPDATE;
|
||||||
tmp = new_tmp();
|
tcg_gen_andi_i32(cpu_R[15], var, ~1);
|
||||||
tcg_gen_andi_i32(tmp, var, 1);
|
tcg_gen_andi_i32(var, var, 1);
|
||||||
store_cpu_field(tmp, thumb);
|
store_cpu_field(var, thumb);
|
||||||
tcg_gen_andi_i32(var, var, ~1);
|
|
||||||
store_cpu_field(var, regs[15]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Variant of store_reg which uses branch&exchange logic when storing
|
/* Variant of store_reg which uses branch&exchange logic when storing
|
||||||
|
@ -887,9 +895,7 @@ static inline void gen_movl_T2_reg(DisasContext *s, int reg)
|
||||||
|
|
||||||
static inline void gen_set_pc_im(uint32_t val)
|
static inline void gen_set_pc_im(uint32_t val)
|
||||||
{
|
{
|
||||||
TCGv tmp = new_tmp();
|
tcg_gen_movi_i32(cpu_R[15], val);
|
||||||
tcg_gen_movi_i32(tmp, val);
|
|
||||||
store_cpu_field(tmp, regs[15]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_movl_reg_TN(DisasContext *s, int reg, int t)
|
static inline void gen_movl_reg_TN(DisasContext *s, int reg, int t)
|
||||||
|
@ -901,7 +907,7 @@ static inline void gen_movl_reg_TN(DisasContext *s, int reg, int t)
|
||||||
} else {
|
} else {
|
||||||
tmp = cpu_T[t];
|
tmp = cpu_T[t];
|
||||||
}
|
}
|
||||||
tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, regs[reg]));
|
tcg_gen_mov_i32(cpu_R[reg], tmp);
|
||||||
if (reg == 15) {
|
if (reg == 15) {
|
||||||
dead_tmp(tmp);
|
dead_tmp(tmp);
|
||||||
s->is_jmp = DISAS_JUMP;
|
s->is_jmp = DISAS_JUMP;
|
||||||
|
|
Loading…
Reference in New Issue