From: Paolo Bonzini <pbonzini@redhat.com>
To: "Sergey Fedorov" <serge.fdrv@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
sergey.fedorov@linaro.org
Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>,
qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH 2/5] tcg: reorganize tb_find_physical loop
Date: Tue, 29 Mar 2016 15:26:50 +0200 [thread overview]
Message-ID: <56FA829A.3040903@redhat.com> (raw)
In-Reply-To: <56FA80D0.5020606@gmail.com>
On 29/03/2016 15:19, Sergey Fedorov wrote:
> On 22/03/16 17:59, Alex Bennée wrote:
>> sergey.fedorov@linaro.org writes:
>>
>>> From: Paolo Bonzini <pbonzini@redhat.com>
>>>
>>> Use a continue statement.
>>>
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>> [Sergey Fedorov: Fix moving to list head in case of no TB]
>>> Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org>
>>> ---
>>> cpu-exec.c | 50 +++++++++++++++++++++++++-------------------------
>>> 1 file changed, 25 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/cpu-exec.c b/cpu-exec.c
>>> index fd92452f16f6..f90482eff778 100644
>>> --- a/cpu-exec.c
>>> +++ b/cpu-exec.c
>>> @@ -225,37 +225,37 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
>>> phys_pc = get_page_addr_code(env, pc);
>>> phys_page1 = phys_pc & TARGET_PAGE_MASK;
>>> h = tb_phys_hash_func(phys_pc);
>>> - ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h];
>>> - for(;;) {
>>> - tb = *ptb1;
>>> - if (!tb) {
>>> - return NULL;
>>> + for (ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h];
>>> + (tb = *ptb1) != NULL;
>>> + ptb1 = &tb->phys_hash_next) {
>> I'm not sure I'm keen on the assignment in the for condition clause. I
>> appreciate the cleansing of the if !tb return exit though. Could we be
>> cleaner maybe? Here is my attempt:
>>
>> static TranslationBlock *tb_find_physical(CPUState *cpu,
>> target_ulong pc,
>> target_ulong cs_base,
>> uint64_t flags)
>> {
>> CPUArchState *env = (CPUArchState *)cpu->env_ptr;
>> TranslationBlock *tb, **tb_hash_head, **ptb1;
>> unsigned int h;
>> tb_page_addr_t phys_pc, phys_page1;
>>
>> /* find translated block using physical mappings */
>> phys_pc = get_page_addr_code(env, pc);
>> phys_page1 = phys_pc & TARGET_PAGE_MASK;
>> h = tb_phys_hash_func(phys_pc);
>>
>> /* Start at head of the hash entry */
>> ptb1 = tb_hash_head = &tcg_ctx.tb_ctx.tb_phys_hash[h];
>> tb = *ptb1;
>>
>> while (tb) {
>>
>> if (tb->pc == pc &&
>> tb->page_addr[0] == phys_page1 &&
>> tb->cs_base == cs_base &&
>> tb->flags == flags) {
>>
>> 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;
>> tb_page_addr_t phys_page2 = get_page_addr_code(env, virt_page2);
>>
>> if (tb->page_addr[1] == phys_page2) {
>> break;
>> }
>> }
>> }
>>
>> ptb1 = &tb->phys_hash_next;
>> tb = *ptb1;
>> }
>>
>> if (tb) {
>> /* Move the TB to the head of the list */
>> *ptb1 = tb->phys_hash_next;
>> tb->phys_hash_next = *tb_hash_head;
>> *tb_hash_head = tb;
>> }
>> return tb;
>> }
>>
>> FWIW the compiled code is 9 bytes shorter on my machine.
>
> Looks like another attempt to rewrite it. I am wondering whom to
> attribute as an author, then? :)
I don't really care. :)
Paolo
next prev parent reply other threads:[~2016-03-29 13:26 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-17 13:46 [Qemu-devel] [PATCH 0/5] tcg: Misc clean-up patches from Paolo sergey.fedorov
2016-03-17 13:46 ` [Qemu-devel] [PATCH 1/5] tcg: code_bitmap is not used by user-mode emulation sergey.fedorov
2016-03-17 14:56 ` Peter Maydell
2016-03-17 15:03 ` Sergey Fedorov
2016-03-17 13:46 ` [Qemu-devel] [PATCH 2/5] tcg: reorganize tb_find_physical loop sergey.fedorov
2016-03-17 14:59 ` Peter Maydell
2016-03-22 14:59 ` Alex Bennée
2016-03-22 15:00 ` Paolo Bonzini
2016-03-29 13:19 ` Sergey Fedorov
2016-03-29 13:26 ` Paolo Bonzini [this message]
2016-03-29 14:05 ` Sergey Fedorov
2016-03-29 14:26 ` Alex Bennée
2016-03-29 14:37 ` Sergey Fedorov
2016-03-17 13:46 ` [Qemu-devel] [PATCH 3/5] tcg: always keep jump target and tb->jmp_next consistent sergey.fedorov
2016-03-17 17:57 ` Richard Henderson
2016-03-17 19:31 ` Paolo Bonzini
2016-03-17 20:45 ` Sergey Fedorov
2016-03-17 20:46 ` Richard Henderson
2016-03-18 10:29 ` Sergey Fedorov
2016-03-18 10:32 ` Sergey Fedorov
2016-03-17 13:46 ` [Qemu-devel] [PATCH 4/5] tcg: reorder removal from lists in tb_phys_invalidate sergey.fedorov
2016-03-17 15:09 ` Paolo Bonzini
2016-03-17 15:14 ` Sergey Fedorov
2016-03-28 15:18 ` Sergey Fedorov
2016-03-28 21:21 ` Paolo Bonzini
2016-03-29 10:03 ` Sergey Fedorov
2016-03-29 10:37 ` Paolo Bonzini
2016-03-29 12:31 ` Sergey Fedorov
2016-03-29 13:43 ` Alex Bennée
2016-04-14 14:45 ` Sergey Fedorov
2016-04-14 15:13 ` Paolo Bonzini
2016-04-14 15:36 ` Sergey Fedorov
2016-04-14 17:27 ` Paolo Bonzini
2016-04-14 18:29 ` Sergey Fedorov
2016-04-14 18:37 ` Sergey Fedorov
2016-03-28 18:42 ` Sergey Fedorov
2016-03-28 20:58 ` Paolo Bonzini
2016-03-29 0:17 ` Richard Henderson
2016-03-17 13:46 ` [Qemu-devel] [PATCH 5/5] tcg: move tb_invalidated_flag to CPUState sergey.fedorov
2016-03-22 15:07 ` Alex Bennée
2016-03-22 15:11 ` Sergey Fedorov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56FA829A.3040903@redhat.com \
--to=pbonzini@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=crosthwaite.peter@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=serge.fdrv@gmail.com \
--cc=sergey.fedorov@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).