public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Godmar Back" <godmar@gmail.com>
To: "Ian Lance Taylor" <iant@google.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: optimization of switch statements on i386
Date: Sat, 09 Feb 2008 03:02:00 -0000	[thread overview]
Message-ID: <719dced30802081901j4db41c18wbb930be9d9791e4c@mail.gmail.com> (raw)
In-Reply-To: <m3odaqubq0.fsf@localhost.localdomain>

On 08 Feb 2008 18:04:23 -0800, Ian Lance Taylor <iant@google.com> wrote:
>
> Look at expand_case in gcc/stmt.c.
>

Thanks. So I did that, and that explains why my example with 4 cases
does not use a table.
gcc/expr.c says:

/* If the machine does not have a case insn that compares the bounds,
   this means extra overhead for dispatch tables, which raises the
   threshold for using them.  */
#ifndef CASE_VALUES_THRESHOLD
#define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
#endif /* CASE_VALUES_THRESHOLD */

and a binary search is used if #arms < CASE_VALUES_THRESHOLD.
This leads to my next question.

I increased the number of arms to 5, and retained the "default:
gcc_unreachable()".
Now gcc generates a bounds check, followed by a table jump. Good. Now
how do I get rid of the bounds checks?

Is there a way to inform gcc that the default branch is never taken?
(Something along the lines of MSVC's __assert(0)?   I had thought
gcc_unreachable() would do that - but I may be misinformed here.)

Thanks,

 - Godmar

  parent reply	other threads:[~2008-02-09  3:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <719dced30802081629g19f67f6fi76dfaa0ede35b7aa@mail.gmail.com>
2008-02-09  0:31 ` Godmar Back
2008-02-09  2:05   ` Ian Lance Taylor
2008-02-09  2:43     ` Godmar Back
2008-02-09  2:52       ` Ian Lance Taylor
2008-02-09  3:02     ` Godmar Back [this message]
2008-02-11 17:55       ` Ian Lance Taylor
2008-02-11 18:13         ` Godmar Back
2008-02-11 19:31           ` Ian Lance Taylor
2008-02-11 18:47         ` Diego Novillo
2008-02-11 19:52           ` Godmar Back
2008-02-11 20:01             ` Ian Lance Taylor

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=719dced30802081901j4db41c18wbb930be9d9791e4c@mail.gmail.com \
    --to=godmar@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    /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).