Re: Switch statement code generation

Joshua Cranmer <Pidgeot18@verizon.invalid>
Wed, 04 Nov 2009 07:38:43 -0500

          From comp.compilers

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)
Re: Switch statement code generation bartc@freeuk.com (bartc) (2009-11-05)
Re: Switch statement code generation nathan.mccauley@gmail.com (nathan.mccauley@gmail.com) (2009-11-07)
Re: Switch statement code generation DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-11-08)
Re: Switch statement code generation bear@sonic.net (Ray) (2009-11-09)
Re: Switch statement code generation DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-11-11)
[6 later articles]
| List of all articles for this month |

From: Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups: comp.compilers
Date: Wed, 04 Nov 2009 07:38:43 -0500
Organization: Georgia Institute of Technology
References: 09-11-002 09-11-003
Keywords: code
Posted-Date: 05 Nov 2009 15:17:44 EST

On 11/04/2009 12:27 AM, glen herrmannsfeldt wrote:
> I believe that JVM also has a special instruction for this
> operation, as the above likely don't work there.


Actually two special bytecodes, lookupswitch and tableswitch. These are
the linear scan and the jump table methods, respectively. The upcoming
string switch appears to use a hash routine.


> [On machines with condition codes, I've seen binary searches expanded
> into code with compare and branch instructions; after the comparison
> you can do a three way branch on less, equal, or greater. -John]


It seems both gcc and llvm emit code like this; I've added it to my list
already.


--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth



Post a followup to this message

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