Re: Switch statement code generation

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Wed, 4 Nov 2009 08:51:49 +0000 (UTC)

          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)
[8 later articles]
| List of all articles for this month |
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Wed, 4 Nov 2009 08:51:49 +0000 (UTC)
Organization: California Institute of Technology, Pasadena
References: 09-11-002 09-11-003
Keywords: code
Posted-Date: 05 Nov 2009 15:17:09 EST

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
(snip, someone wrote)


> [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]


I once saw in a Fortran book the suggestion that one use arithmetic
IF in place of computed GOTO with three labels.


            IF(N-2) 1,2,3


instead of


            GOTO (1,2,3),N


For modern processors depending on branch prediction logic,
either a branch table or address table will likely foil any
prediction system. Complicated conditional branching is likely
faster in that case.


-- glen
[Hey, it worked great on the 709. -John]



Post a followup to this message

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