Re: Help needed: Code generation for CASE/SWITCH statements

conway@mundook.cs.mu.OZ.AU (Thomas Charles CONWAY)
5 Dec 1997 01:22:38 -0500

          From comp.compilers

Related articles
Re: Help needed: Code generation for CASE/SWITCH statements johnmce@world.std.com (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements srw@pspf47.ih.lucent.com (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements dwight@pentasoft.com (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements preston@cs.rice.edu (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements dlmoore@ix.netcom.com (David L Moore) (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements drh@microsoft.com (Dave Hanson) (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements wilson@marker.cs.utah.edu (Wilson C Hsieh) (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements conway@mundook.cs.mu.OZ.AU (1997-12-05)
Re: Help needed: Code generation for CASE/SWITCH statements gclind01@spd.louisville.edu (1997-12-07)
Re: Help needed: Code generation for CASE/SWITCH statements wi534@victoria.tc.ca (William A. Barath) (1997-12-07)
Re: Help needed: Code generation for CASE/SWITCH statements sethml@ugcs.caltech.edu (1997-12-07)
Re: Help needed: Code generation for CASE/SWITCH statements henry@zoo.toronto.edu (Henry Spencer) (1997-12-10)
Re: Help needed: Code generation for CASE/SWITCH statements a_s_t_o_r@guardian.no (Alexander Kjeldaas) (1997-12-10)
Re: Help needed: Code generation for CASE/SWITCH statements vonbrand@inf.utfsm.cl (Horst von Brand) (1997-12-12)
[6 later articles]
| List of all articles for this month |

From: conway@mundook.cs.mu.OZ.AU (Thomas Charles CONWAY)
Newsgroups: comp.compilers,comp.lang.c.moderated
Date: 5 Dec 1997 01:22:38 -0500
Organization: Comp Sci, University of Melbourne
References: <clcm-19971204-0012@plethora.net>
Keywords: code

jakob@iar_.se (Jakob) writes:


>I have a number of different tactics for implementing a switch (among
>them a simple jump table and a series of conditional branches), and
>would like the compiler to make a semi-intelligent decision as to
>which to use for a particular switch.


We had much the same issue for implementing switches in Mercury. We
use both the implementations that you suggest, and we have simple
threshold (which can be altered from the commandline) based on the
number of cases. I think with 8 or more cases we use a jump table, and
use if-then-elses with fewer. We just did some experements to
determine the threshold. This seems to work pretty well.


Of greater impact to performance is the fact that Mercury is stongly
typed (as opposed to C), so most switchs don't need a range check.
Eliminating range checks buys more than getting an optimum threshold.


No doubt if we were being really fussy, we could make our configure
script run some tests so that the threshold gets set at an optimum
for each platform. Currently we're not that fussy.


Thomas
(for more information about the Mercury compiler see
http://www.cs.mu.oz.au/mercury)
--
Thomas Conway conway@cs.mu.oz.au
--


Post a followup to this message

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