提交 797d780b 编写于 作者: M Max Filippov 提交者: Blue Swirl

target-xtensa: implement loop option

See ISA, 4.3.2 for details.

Operations that change LEND SR value invalidate TBs at the old and at
the new LEND. LEND value at TB compilation time is considered constant
and loop instruction is generated based on this value.

Invalidation may be avoided for the TB at the old LEND address, since
looping code verifies actual LEND value.

Invalidation may be avoided for the TB at the new LEND address if
there's a way to associate LEND address with TB at compilation time and
later verify that it doesn't change.
Signed-off-by: NMax Filippov <jcmvbkbc@gmail.com>
Signed-off-by: NBlue Swirl <blauwirbel@gmail.com>
上级 553e44f9
...@@ -106,6 +106,9 @@ enum { ...@@ -106,6 +106,9 @@ enum {
}; };
enum { enum {
LBEG = 0,
LEND = 1,
LCOUNT = 2,
SAR = 3, SAR = 3,
SCOMPARE1 = 12, SCOMPARE1 = 12,
WINDOW_BASE = 72, WINDOW_BASE = 72,
......
...@@ -12,6 +12,8 @@ DEF_HELPER_1(rotw, void, i32) ...@@ -12,6 +12,8 @@ DEF_HELPER_1(rotw, void, i32)
DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_2(window_check, void, i32, i32)
DEF_HELPER_0(restore_owb, void) DEF_HELPER_0(restore_owb, void)
DEF_HELPER_1(movsp, void, i32) DEF_HELPER_1(movsp, void, i32)
DEF_HELPER_1(wsr_lbeg, void, i32)
DEF_HELPER_1(wsr_lend, void, i32)
DEF_HELPER_0(dump_state, void) DEF_HELPER_0(dump_state, void)
#include "def-helper.h" #include "def-helper.h"
...@@ -288,6 +288,26 @@ void HELPER(movsp)(uint32_t pc) ...@@ -288,6 +288,26 @@ void HELPER(movsp)(uint32_t pc)
} }
} }
void HELPER(wsr_lbeg)(uint32_t v)
{
if (env->sregs[LBEG] != v) {
tb_invalidate_phys_page_range(
env->sregs[LEND] - 1, env->sregs[LEND], 0);
env->sregs[LBEG] = v;
}
}
void HELPER(wsr_lend)(uint32_t v)
{
if (env->sregs[LEND] != v) {
tb_invalidate_phys_page_range(
env->sregs[LEND] - 1, env->sregs[LEND], 0);
env->sregs[LEND] = v;
tb_invalidate_phys_page_range(
env->sregs[LEND] - 1, env->sregs[LEND], 0);
}
}
void HELPER(dump_state)(void) void HELPER(dump_state)(void)
{ {
cpu_dump_state(env, stderr, fprintf, 0); cpu_dump_state(env, stderr, fprintf, 0);
......
...@@ -47,6 +47,8 @@ typedef struct DisasContext { ...@@ -47,6 +47,8 @@ typedef struct DisasContext {
uint32_t next_pc; uint32_t next_pc;
int cring; int cring;
int ring; int ring;
uint32_t lbeg;
uint32_t lend;
int is_jmp; int is_jmp;
int singlestep_enabled; int singlestep_enabled;
...@@ -65,6 +67,9 @@ static TCGv_i32 cpu_UR[256]; ...@@ -65,6 +67,9 @@ static TCGv_i32 cpu_UR[256];
#include "gen-icount.h" #include "gen-icount.h"
static const char * const sregnames[256] = { static const char * const sregnames[256] = {
[LBEG] = "LBEG",
[LEND] = "LEND",
[LCOUNT] = "LCOUNT",
[SAR] = "SAR", [SAR] = "SAR",
[SCOMPARE1] = "SCOMPARE1", [SCOMPARE1] = "SCOMPARE1",
[WINDOW_BASE] = "WINDOW_BASE", [WINDOW_BASE] = "WINDOW_BASE",
...@@ -247,13 +252,37 @@ static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) ...@@ -247,13 +252,37 @@ static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot)
tcg_temp_free(tmp); tcg_temp_free(tmp);
} }
static bool gen_check_loop_end(DisasContext *dc, int slot)
{
if (option_enabled(dc, XTENSA_OPTION_LOOP) &&
!(dc->tb->flags & XTENSA_TBFLAG_EXCM) &&
dc->next_pc == dc->lend) {
int label = gen_new_label();
tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label);
tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1);
gen_jumpi(dc, dc->lbeg, slot);
gen_set_label(label);
gen_jumpi(dc, dc->next_pc, -1);
return true;
}
return false;
}
static void gen_jumpi_check_loop_end(DisasContext *dc, int slot)
{
if (!gen_check_loop_end(dc, slot)) {
gen_jumpi(dc, dc->next_pc, slot);
}
}
static void gen_brcond(DisasContext *dc, TCGCond cond, static void gen_brcond(DisasContext *dc, TCGCond cond,
TCGv_i32 t0, TCGv_i32 t1, uint32_t offset) TCGv_i32 t0, TCGv_i32 t1, uint32_t offset)
{ {
int label = gen_new_label(); int label = gen_new_label();
tcg_gen_brcond_i32(cond, t0, t1, label); tcg_gen_brcond_i32(cond, t0, t1, label);
gen_jumpi(dc, dc->next_pc, 0); gen_jumpi_check_loop_end(dc, 0);
gen_set_label(label); gen_set_label(label);
gen_jumpi(dc, dc->pc + offset, 1); gen_jumpi(dc, dc->pc + offset, 1);
} }
...@@ -283,6 +312,16 @@ static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr) ...@@ -283,6 +312,16 @@ static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr)
} }
} }
static void gen_wsr_lbeg(DisasContext *dc, uint32_t sr, TCGv_i32 s)
{
gen_helper_wsr_lbeg(s);
}
static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 s)
{
gen_helper_wsr_lend(s);
}
static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s)
{ {
tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f); tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f);
...@@ -308,13 +347,15 @@ static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v) ...@@ -308,13 +347,15 @@ static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)
} }
tcg_gen_andi_i32(cpu_SR[sr], v, mask); tcg_gen_andi_i32(cpu_SR[sr], v, mask);
/* This can change mmu index, so exit tb */ /* This can change mmu index, so exit tb */
gen_jumpi(dc, dc->next_pc, -1); gen_jumpi_check_loop_end(dc, -1);
} }
static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s)
{ {
static void (* const wsr_handler[256])(DisasContext *dc, static void (* const wsr_handler[256])(DisasContext *dc,
uint32_t sr, TCGv_i32 v) = { uint32_t sr, TCGv_i32 v) = {
[LBEG] = gen_wsr_lbeg,
[LEND] = gen_wsr_lend,
[SAR] = gen_wsr_sar, [SAR] = gen_wsr_sar,
[WINDOW_BASE] = gen_wsr_windowbase, [WINDOW_BASE] = gen_wsr_windowbase,
[PS] = gen_wsr_ps, [PS] = gen_wsr_ps,
...@@ -1542,15 +1583,29 @@ static void disas_xtensa_insn(DisasContext *dc) ...@@ -1542,15 +1583,29 @@ static void disas_xtensa_insn(DisasContext *dc)
break; break;
case 8: /*LOOP*/ case 8: /*LOOP*/
TBD();
break;
case 9: /*LOOPNEZ*/ case 9: /*LOOPNEZ*/
TBD();
break;
case 10: /*LOOPGTZ*/ case 10: /*LOOPGTZ*/
TBD(); HAS_OPTION(XTENSA_OPTION_LOOP);
{
uint32_t lend = dc->pc + RRI8_IMM8 + 4;
TCGv_i32 tmp = tcg_const_i32(lend);
tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_R[RRI8_S], 1);
tcg_gen_movi_i32(cpu_SR[LBEG], dc->next_pc);
gen_wsr_lend(dc, LEND, tmp);
tcg_temp_free(tmp);
if (BRI8_R > 8) {
int label = gen_new_label();
tcg_gen_brcondi_i32(
BRI8_R == 9 ? TCG_COND_NE : TCG_COND_GT,
cpu_R[RRI8_S], 0, label);
gen_jumpi(dc, lend, 1);
gen_set_label(label);
}
gen_jumpi(dc, dc->next_pc, 0);
}
break; break;
default: /*reserved*/ default: /*reserved*/
...@@ -1727,7 +1782,9 @@ static void disas_xtensa_insn(DisasContext *dc) ...@@ -1727,7 +1782,9 @@ static void disas_xtensa_insn(DisasContext *dc)
break; break;
} }
gen_check_loop_end(dc, 0);
dc->pc = dc->next_pc; dc->pc = dc->next_pc;
return; return;
invalid_opcode: invalid_opcode:
...@@ -1773,6 +1830,8 @@ static void gen_intermediate_code_internal( ...@@ -1773,6 +1830,8 @@ static void gen_intermediate_code_internal(
dc.pc = pc_start; dc.pc = pc_start;
dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK; dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK;
dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring; dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring;
dc.lbeg = env->sregs[LBEG];
dc.lend = env->sregs[LEND];
dc.is_jmp = DISAS_NEXT; dc.is_jmp = DISAS_NEXT;
init_sar_tracker(&dc); init_sar_tracker(&dc);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册