Related articles |
---|
Switch statement code generation Pidgeot18@verizon.invalid (Joshua Cranmer) (2009-11-03) |
Re: Switch statement code generation gah@ugcs.caltech.edu (glen herrmannsfeldt) (2009-11-04) |
Re: Switch statement code generation kkylheku@gmail.com (Kaz Kylheku) (2009-11-04) |
Re: Switch statement code generation cr88192@hotmail.com (BGB / cr88192) (2009-11-04) |
Re: Switch statement code generation ian@airs.com (Ian Lance Taylor) (2009-11-03) |
Re: Switch statement code generation gah@ugcs.caltech.edu (glen herrmannsfeldt) (2009-11-04) |
Re: Switch statement code generation anton@mips.complang.tuwien.ac.at (2009-11-04) |
Re: Switch statement code generation Pidgeot18@verizon.invalid (Joshua Cranmer) (2009-11-04) |
Re: Switch statement code generation walter@bytecraft.com (Walter Banks) (2009-11-05) |
[11 later articles] |
From: | Kaz Kylheku <kkylheku@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Wed, 4 Nov 2009 06:08:48 +0000 (UTC) |
Organization: | A noiseless patient Spider |
References: | 09-11-002 |
Keywords: | code |
Posted-Date: | 05 Nov 2009 15:15:15 EST |
On 2009-11-03, Joshua Cranmer <Pidgeot18@verizon.invalid> wrote:
> I'm trying to put together a list of various methods to do code generate
> for switch statements.
>
> This is what I have so far:
> * Successive if/else branches
> * Jump tables
> * branch tables with linear and binary scans
> * Clustering tables (e.g., if you have cases 0-100 and 300-400).
>
> Are there any other methods worth mentioning?
if/else arranged in a binary search tree, rather than linear succession.
Analogous to your branch table with binary scan, but using code
rather than a table to reduce the comparions for N labels to log N.
E.g. cases are:
10 50 90 1000 1200 3000 4000 7500 12345
if (x < 3000) {
if (x < 90) {
if (x == 10) {
...
} else if (x == 50) {
...
}
} else {
if (x == 90) {
...
} else if (x == 1000) {
...
} else if (x == 1200) {
...
}
}
} else {
/* similarly for 3000-12345 range */
}
This can combine with clustering. Binary search to classify an input
value into cluster ranges, then check the range and use the table for that
range, or default out.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.