tcg: reorganize tb_find_physical loop

Put some comments and improve code structure. This should help reading
the code.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
[Sergey Fedorov: provide commit message; bring back resetting of
tb_invalidated_flag]
Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org>
Reviewed-by: Richard Henderson  <rth@twiddle.net>
Signed-off-by: Richard Henderson <rth@twiddle.net>
This commit is contained in:
Alex Bennée 2016-03-22 14:59:20 +00:00 committed by Richard Henderson
parent 6fad459c91
commit 1279f323d6

View File

@ -223,10 +223,9 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
uint32_t flags) uint32_t flags)
{ {
CPUArchState *env = (CPUArchState *)cpu->env_ptr; CPUArchState *env = (CPUArchState *)cpu->env_ptr;
TranslationBlock *tb, **ptb1; TranslationBlock *tb, **tb_hash_head, **ptb1;
unsigned int h; unsigned int h;
tb_page_addr_t phys_pc, phys_page1; tb_page_addr_t phys_pc, phys_page1;
target_ulong virt_page2;
tcg_ctx.tb_ctx.tb_invalidated_flag = 0; tcg_ctx.tb_ctx.tb_invalidated_flag = 0;
@ -234,37 +233,42 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
phys_pc = get_page_addr_code(env, pc); phys_pc = get_page_addr_code(env, pc);
phys_page1 = phys_pc & TARGET_PAGE_MASK; phys_page1 = phys_pc & TARGET_PAGE_MASK;
h = tb_phys_hash_func(phys_pc); h = tb_phys_hash_func(phys_pc);
ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h];
for(;;) { /* Start at head of the hash entry */
ptb1 = tb_hash_head = &tcg_ctx.tb_ctx.tb_phys_hash[h];
tb = *ptb1; tb = *ptb1;
if (!tb) {
return NULL; while (tb) {
}
if (tb->pc == pc && if (tb->pc == pc &&
tb->page_addr[0] == phys_page1 && tb->page_addr[0] == phys_page1 &&
tb->cs_base == cs_base && tb->cs_base == cs_base &&
tb->flags == flags) { tb->flags == flags) {
/* check next page if needed */
if (tb->page_addr[1] != -1) {
tb_page_addr_t phys_page2;
virt_page2 = (pc & TARGET_PAGE_MASK) + if (tb->page_addr[1] == -1) {
/* done, we have a match */
break;
} else {
/* check next page if needed */
target_ulong virt_page2 = (pc & TARGET_PAGE_MASK) +
TARGET_PAGE_SIZE; TARGET_PAGE_SIZE;
phys_page2 = get_page_addr_code(env, virt_page2); tb_page_addr_t phys_page2 = get_page_addr_code(env, virt_page2);
if (tb->page_addr[1] == phys_page2) { if (tb->page_addr[1] == phys_page2) {
break; break;
} }
} else {
break;
} }
} }
ptb1 = &tb->phys_hash_next;
}
ptb1 = &tb->phys_hash_next;
tb = *ptb1;
}
if (tb) {
/* Move the TB to the head of the list */ /* Move the TB to the head of the list */
*ptb1 = tb->phys_hash_next; *ptb1 = tb->phys_hash_next;
tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[h]; tb->phys_hash_next = *tb_hash_head;
tcg_ctx.tb_ctx.tb_phys_hash[h] = tb; *tb_hash_head = tb;
}
return tb; return tb;
} }