qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Karl Magdsick <kmagnum@gmail.com>
To: "André Braga" <meianoite@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Profiling Qemu for speed?
Date: Mon, 18 Apr 2005 00:31:25 -0400	[thread overview]
Message-ID: <cd8ecdef05041721314e1a15d3@mail.gmail.com> (raw)
In-Reply-To: <2ad73a0504171939154235f5@mail.gmail.com>

Ideally, we could force gcc to implement switch statements as indirect
jumps with jump tables inline with the code.  However, this may not be
possible.

I think Nathaniel was just saying that gcc is likely generating
several hundred sequential if-else blocks for large switch statements.
 This gives you O(n) runtime, whereas a function pointer array gives
you O(1) runtime.  (This assumes each case ends with a break... I
haven't looked at the code to which Nathaniel is referring.) 
Therefore, for sufficiently large switch statements, sequential
if-else statements will be slower than a function pointer array.  The
question is: is n=~ 200 sufficiently large?  I think only empirical
testing has a chance of answering this question in everyone's mind.

If you smartly nest your if-else statements, you can at least get
O(log n) runtime, with negligible difference in the leading constant
as compared to the sequential if-else statements.

There's also the possibility of (at startup) dynamically generating an
indirect jump along with a jump table inline with the code (in order
to minimize page faults, and perhaps utilize the prefectch to get the
first few jump addresses in the L2 cache).

Of course, as pointed out elsewhere, the dynamic code generator is
hopefully only invoked rarely, so speeding up the switch statements
may not have a noticeable effect on emulation speed.


-Karl

On 4/17/05, André Braga <meianoite@gmail.com> wrote:
> The problem with table lookups (I'm assuming you're talking about
> function pointer vectors) is that they *destroy* spatial locality of
> reference that you could otherwise attain by having series of
> if-then-else instructions and some clever instruction prefetching
> mechanism on modern processors... Not to mention the function call
> overhead.

  reply	other threads:[~2005-04-18  4:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-17  5:58 [Qemu-devel] Profiling Qemu for speed? Joe Luser
2005-04-17  8:21 ` John R. Hogerhuis
2005-04-17  8:59   ` Jonas Maebe
2005-04-17 10:27     ` Paul Brook
2005-04-17 10:46       ` Jonas Maebe
2005-04-18  1:36         ` Nathaniel G H
2005-04-18  2:11           ` John R. Hogerhuis
2005-04-18  2:39           ` André Braga
2005-04-18  4:31             ` Karl Magdsick [this message]
2005-04-17 10:36 ` Paul Brook
  -- strict thread matches above, loose matches on Subject: below --
2005-04-18  8:35 Daniel J Guinan
2005-04-18  9:51 ` Ian Rogers
2005-04-18 13:44   ` Daniel Egger
2005-04-18 14:12     ` Christian MICHON
2005-04-18 14:29       ` Ian Rogers
2005-04-18 14:19     ` Ian Rogers
2005-04-18 14:40     ` Paul Brook
2005-04-18 11:24 Daniel J Guinan

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=cd8ecdef05041721314e1a15d3@mail.gmail.com \
    --to=kmagnum@gmail.com \
    --cc=meianoite@gmail.com \
    --cc=qemu-devel@nongnu.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).