This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Request of new __attribute__ for switch statements (elimination of the bounds check)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]