This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Kevin Lawton <kevinlawton2001 at yahoo dot com>
- Cc: Robert Dewar <dewar at gnat dot com>, gcc at gcc dot gnu dot org
- Date: 12 Oct 2002 01:23:23 -0300
- Subject: Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
- Organization: GCC Team, Red Hat
- References: <20021011202232.85226.qmail@web80303.mail.yahoo.com>
On Oct 11, 2002, Kevin Lawton <kevinlawton2001@yahoo.com> wrote:
> I haven't tried turning the last case into the default, but I
> can't see how that eliminates a check, so I'm not clear on the
> win there.
it (kind of) turns:
if (x == 255) goto case_255;
...
else if (x == 0) goto case_0;
else /* do nothing */;
into
if ((unsigned)x >= 255) goto case_255;
...
else if (x == 0) goto case_0;
Admittedly, this is still not as efficient as the compiler knowing
that x is in [0,255] and just loading the jump from a jump table, but
it's already some improvement.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist Professional serial bug killer