|switch statement generation email@example.com (1994-04-06)|
|Re: switch statement generation firstname.lastname@example.org (1994-04-07)|
|switch statement generation email@example.com (1994-04-07)|
|Re: switch statement generation firstname.lastname@example.org (1994-04-10)|
|Re: switch statement generation email@example.com (1994-04-11)|
|Re: switch statement generation firstname.lastname@example.org (1994-04-13)|
|Re: switch statement generation email@example.com (1994-04-14)|
|Re: switch statement generation chase@Think.COM (1994-04-15)|
|From:||chase@Think.COM (David Chase)|
|Organization:||Thinking Machines Corporation, Cambridge MA, USA|
|Date:||Fri, 15 Apr 1994 15:59:36 GMT|
Richard A. O'Keefe (firstname.lastname@example.org) wrote:
: We don't _need_ another keyword. The construction
: default: abort();
email@example.com (Larry Drebes) writes:
|> This misses the point of the thread. The above example doesn't nothing to
|> help the compiler unless abort() is recognized as something "special".
Ah, but it is relatively easy to recognize "abort", and if all you do is
bias your estimated execution weights against it, the transformation is
entirely standard-conforming. "Relatively easy" means "not much harder
than falling off a log".
|> On the same issue, you can get the optimization of the suggested
|> nodefault: by using the computed goto's extension in the gcc compiler.
|> The problem of optimizing the C switch statement is one of reasons that
|> cfront is losing ground to native compilers.
Ah, but the computed goto extension is (1) not standard-conforming, and
(2) not necessarily so easy to implement and (3) not necessarily as
efficient as you would like it to be, especially on modern machines. If
there really is no default, I recall that the break-even number of cases
for binary-search versus computed branch for a SuperSparc was something
like 15 cases. If you have a (known, perhaps by profiling feedback)
non-uniform distribution of case frequencies, the binary search can be
biased to favor the common cases, and computed branch performs relatively
worse. (There is an idiom for computed branch that has better
performance, where the target is a direct function of the case argument,
instead of loaded from memory, but that has its own annoying problems.)
For a uniform nodefault distribution, I think that the breakeven for
linear search is something like 7 or 8.
Things are not always as obvious as they seem.
David Chase, speaking for myself
Thinking Machines Corp.
Return to the
Search the comp.compilers archives again.