Re: Switch statements

pardo@cs.washington.edu (David Keppel)
Fri, 28 Feb 92 21:01:41 GMT

          From comp.compilers

Related articles
Re: Switch statements pardo@cs.washington.edu (1992-02-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: pardo@cs.washington.edu (David Keppel)
Keywords: optimize, bibliography
Organization: Computer Science & Engineering, U. of Washington, Seattle
References: <9202220021.AA28153@ucbvax.Berkeley.EDU> 92-02-139
Date: Fri, 28 Feb 92 21:01:41 GMT

glew@pdx007.intel.com (Andy Glew) writes:
>[Optimize switch/loop to:
>
> case FOO:
> foo_case<...>;
> if (loop_test<...>) goto end;
> INDIRECT-BRANCH (switch_value<...>);
> ]


The payoff is when all non-branch costs combined are in the same order of
magnitude as the branch costs. If the number of cases is large then there
may be substantial code explosion. Nonetheless, such code is often faster
[Bedichek 89].


somebody else writes:
>[Optimize switch/loop with costant switch_value<...> to:
>
> case FOO:
> loop <...> {
> foo_case<...>;
> }
> ]


Again, code explosion can be a problem. Still, I did a test with
statically-compiled |bitblt|, which has several layers of this
optimization (done by hand with ugly macros, following [Locanthi 87]).
The code explodes from a few hundred bytes to ~20Kb, but the particular
loop is sucked in to the cache in short order and at moderately low cost
compared to the extra nonoptimized branches times the number of iterations
of the loop.


[Bedichek 89] does it manually (and is not alone in doing so):
%A Robert Bedichek
%T Some Efficient Architecture Simulation Techniques
%J Winter '90 USENIX Conference
%D 26 October, 1989
%P 53-63


%A Bart N. Locanthi
%T Fast BitBlt With asm() and CPP
%J European Unix Users Group Conference Proceedings (EUUG)
%D September 1987


;-D on ( Compile or switch ) Pardo
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.