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)


--- Robert Dewar <dewar@gnat.com> wrote:
> <<But I don't know of any way to tell the compiler to _not_ generate
> a bounds check on the switch variable 'byte'.  All of the target
> space is covered.
> 
> To solve this, could we add an attribute to switch?
> 
>   switch (byte) __attribute (( no-bounds-check )) {
>     ...
>     }
> >>
> 
> Surely this is NOT the solution in a case when it is obvious that no
> check is needed. We have noticed this junk check being a problem in
> GNAT, and what we do is to turn the last case into a default, but this
> of course is definitely not optimial.


It may not always be easy for the compiler to know.  If GCC
could eliminate the unnecessary check for the obvious cases,
that'd be great.

But such an attribute (or whatever method you propose) is needed
when the programmer knows more about the data flow than the
compiler.  Which for high performance programs, tends to be
quite a few.

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.

-Kevin

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


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