Re: optimization of switch statements on i386

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Godmar Back" <godmar@xxxxxxxxx> writes:

> Thanks. I did see that gcc_unreachable() showed up as a symbol in the
> assembly (consistent with it not meaning anything special); I suppose
> I was misled by this comment in the gcc coding conventions at
> http://gcc.gnu.org/codingconventions.html
> 
> "Use gcc_unreachable() to mark places that should never be reachable
> (such as an unreachable default case of a switch). Do not use
> gcc_assert(0) for such purposes, as gcc_unreachable gives the compiler
> more information."
> 
> Apparently, this discussion refers to the (currently executing)
> compiler, not the compiler used to compile the gcc code.

Those coding convention are for people working on gcc itself, not for
people using gcc.


> I assume a corollary of that statement is that there is no way to
> trick the compiler into omitting the default branch without incurring
> runtime checks (or is there a clever way I'm not realizing)?

In general, yes.

There has been some discussion of implementing __builtin_unreachable()
which would direct the optimizers to assume that the code path was
never taken.  Howver, as far as I know no actual woek has been done on
this.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux