public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
@ 2002-10-15 22:40 Robert Dewar
  2002-10-15 23:57 ` Zack Weinberg
  0 siblings, 1 reply; 32+ messages in thread
From: Robert Dewar @ 2002-10-15 22:40 UTC (permalink / raw)
  To: kevinlawton2001, matz, zack; +Cc: egcs, gcc

> > It's just that I see removing the bounds checks on a switch statement
> > as a marginal optimization compared to the risk.  I've never seen a
> > switch be the bottleneck in anything.

I find this a remkarable attitude for a C compiler :-)

Even Ada allows the programmer to remove all checks if that is what the
programmer wants!

After all in a safety critical program, such checks would not be permitted,
because you simply cannot have a check that always succeeds, and whose
failure branch is therefore deactivated code.

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
@ 2002-10-16  9:19 Robert Dewar
  0 siblings, 0 replies; 32+ messages in thread
From: Robert Dewar @ 2002-10-16  9:19 UTC (permalink / raw)
  To: fjh, jsm28; +Cc: gcc, zack

> FWIW, Mercury and Ocaml both have debuggers that support backwards execution.
> It is certainly a very useful feature.

The ideal form of this is hardware emulators that store the last n-thousand
bus cycles and allow reverse execution based on this trace.

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
@ 2002-10-15  6:43 Mattias Engdegård
  0 siblings, 0 replies; 32+ messages in thread
From: Mattias Engdegård @ 2002-10-15  6:43 UTC (permalink / raw)
  To: gcc

>There is a value-range-propagation branch that will do it.  Comes at a
>considerable cost in compile time though.

VRP, while definitely desirable for other reasons, should not be needed just
for determining that the range test for a fully populated switch can be
skipped. Even stuff like 

    switch (x & 127) { case 0: ... case 127: ... }

should not need full VRP, or am I mistaken?

Both Sun WorkShop C and Intel C understand this code right away with no extra
hints. Microsoft Visual C needs the hint __assume(0) in the default: branch,
but at least it's possible to eliminate the range test that way.

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: Request of new __attribute__ for switch statements (elimination of the bounds check)
@ 2002-10-11 13:22 Robert Dewar
  2002-10-11 15:12 ` Kevin Lawton
  0 siblings, 1 reply; 32+ messages in thread
From: Robert Dewar @ 2002-10-11 13:22 UTC (permalink / raw)
  To: gcc, kevinlawton2001

<<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.

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Request of new __attribute__ for switch statements (elimination of the bounds check)
@ 2002-10-11 13:20 Kevin Lawton
  2002-10-12  4:18 ` Ralph Loader
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Kevin Lawton @ 2002-10-11 13:20 UTC (permalink / raw)
  To: gcc

All,

For implementation of machine simulators, it's quite common
to have completely populated switch statements on byte values:

  unsigned char byte;

  switch (byte) {
    case 0:
    case 1:
    ...
    case 255:
    }

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 )) {
    ...
    }

This would also be useful for cases, where it is known that
all possible targets are covered with case statements, yet
they don't appear to be fully populated to the compiler
(it's known only to the programmer that the logic prevents
certain values).

Thanks,
-Kevin

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

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2002-10-16 20:27 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 22:40 Request of new __attribute__ for switch statements (elimination of the bounds check) Robert Dewar
2002-10-15 23:57 ` Zack Weinberg
  -- strict thread matches above, loose matches on Subject: below --
2002-10-16  9:19 Robert Dewar
2002-10-15  6:43 Mattias Engdegård
2002-10-11 13:22 Robert Dewar
2002-10-11 15:12 ` Kevin Lawton
2002-10-12 10:43   ` Alexandre Oliva
2002-10-11 13:20 Kevin Lawton
2002-10-12  4:18 ` Ralph Loader
2002-10-14  8:31 ` Richard Zidlicky
2002-10-14 10:09   ` Dale Johannesen
2002-10-14 21:11 ` Jamie Lokier
2002-10-14 22:01   ` Zack Weinberg
2002-10-15  8:12     ` Michael Matz
2002-10-15 19:15       ` Zack Weinberg
2002-10-15 19:18         ` Dale Johannesen
2002-10-16 14:07           ` Richard Henderson
2002-10-15 21:16         ` Kevin Lawton
2002-10-15 23:40           ` Tim Hollebeek
2002-10-16  3:40             ` Michael Matz
2002-10-16 13:38               ` Tim Hollebeek
2002-10-16 14:23                 ` Michael Matz
2002-10-16 13:27             ` Hartmut Schirmer
2002-10-16  3:25         ` Joseph S. Myers
2002-10-16  7:57           ` Fergus Henderson
2002-10-16 11:19           ` Daniel Jacobowitz
2002-10-15  7:54   ` Michael Matz
2002-10-15 13:29     ` Jamie Lokier
2002-10-15 14:06       ` Kevin Lawton
2002-10-15 15:32         ` Jamie Lokier
2002-10-15 14:28       ` Michael Matz
2002-10-15 15:19         ` Jamie Lokier

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).