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
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.