Re: Optimization of "switch" stmt in C

James Jones <jejones@microware.com>
20 Sep 1999 19:12:42 -0400

          From comp.compilers

Related articles
Optimization of "switch" stmt in C mayur_naik@my-deja.com (1999-09-20)
Re: Optimization of "switch" stmt in C ast@halcyon.com (Andrew Tucker) (1999-09-20)
Re: Optimization of "switch" stmt in C jejones@microware.com (James Jones) (1999-09-20)
Re: Optimization of "switch" stmt in C jcownie@etnus.com (James Cownie) (1999-09-24)
Re: Optimization of "switch" stmt in C ger@informatik.uni-nospam-bremen.de (George Russell) (1999-09-24)
Re: Optimization of "switch" stmt in C vmakarov@cygnus.com (Vladimir Makarov) (1999-09-24)
Re: Optimization of "switch" stmt in C danielv@crt.umontreal.ca (Daniel Villeneuve) (1999-09-27)
Re: Optimization of "switch" stmt in C drh@microsoft.com (Dave Hanson) (1999-09-28)
Re: Optimization of "switch" stmt in C cmilner@virginia.edu (Christopher W. Milner) (1999-10-01)
| List of all articles for this month |
From: James Jones <jejones@microware.com>
Newsgroups: comp.compilers
Date: 20 Sep 1999 19:12:42 -0400
Organization: Microware Systems Corporation
References: 99-09-081
Keywords: C, optimize, practice

Just as C borrowed the fall-through flavored switch from BCPL, I think
the idea for varying code generation came from there as well, so you
might want to track down the Richards/Whitby-Strevens book on BCPL.


The choice will depend on the number and density of the case values
("density" meaning "how close together they are"), and also the target
instruction set. Handwaving heavily, if values are few, one might as
well do linear search; for more cases, high density lends itself to a
jump table, lower to binary search. If one wishes to get more
sophisticated, one might look for cases in which it's worth checking
for a few outliers and then going to a jump table.


James Jones


mayur_naik@my-deja.com wrote:
> Could any one give me references to web-sites / papers / books
> which discuss the optimization of the "switch" stmt in C?





Post a followup to this message

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