public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joern RENNECKE <joern.rennecke@st.com>
To: Ben Elliston <bje@au1.ibm.com>
Cc: Christian Hildner <christian.hildner@hob.de>,
	        gcc mailing list <gcc@gcc.gnu.org>
Subject: Re: Switch statement optimization
Date: Mon, 10 Jul 2006 14:48:00 -0000	[thread overview]
Message-ID: <44B2687E.6050701@st.com> (raw)

In http://gcc.gnu.org/ml/gcc/2006-07/msg00156.html, your wrote:

> A paper at this year's GCC Summit talked about this:
>   http://www.gccsummit.org/2006/view_abstract.php?content_key=18
> You might like to follow up with Edmar (the author of the paper).

But that was about optimizing the trees for an uneven probability distribution which could be found by profiling.
This does not address the issue what to do when the distribution is mostly uniform or unknown.

We could use a cheap hash and base start compare / branch trees in every hash bin.
Say we have a 16 k range, 200 nodes, and want to keep the hash bin/node ratio between 2 and 4.
Let i be the switch argument.  Then we can calculate a 9 bit hash as
(i ^ (x << n)) & 0x3fffffff, where n is a value between 5 and 9.  We can pick the one which produces the flattest
average search trees.
Note that we no longer need to check that i is in range, as for ordinary switch dispatch tables.

Moreover, on a target that can do effectively multi-way compares like the x86, in order
to increase ILP, we can put into the table entry for each hash bin, in addition to the
jump address, a value to compare i against before the dispatch jump takes place.
If a cheap hash can be chosen so that there is no more than one entry per hash bin, we
can even do a single compare in the dispatch code, go to the default case for non-match,
and dispatch right to the handling code if we have a match.


             reply	other threads:[~2006-07-10 14:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-10 14:48 Joern RENNECKE [this message]
2006-07-11 10:03 ` Christian Hildner
  -- strict thread matches above, loose matches on Subject: below --
2022-04-18 14:41 Paul Koning
2022-04-19 14:33 ` Martin Liška
2006-07-10  9:39 Christian Hildner
2006-07-10 11:06 ` Ben Elliston

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=44B2687E.6050701@st.com \
    --to=joern.rennecke@st.com \
    --cc=bje@au1.ibm.com \
    --cc=christian.hildner@hob.de \
    --cc=gcc@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).