Re: while loop code generation

gclind01@spd.louisville.edu (George C. Lindauer)
15 Dec 1997 21:48:34 -0500

          From comp.compilers

Related articles
while loop code generation ast@halcyon.com (1997-12-14)
Re: while loop code generation gclind01@spd.louisville.edu (1997-12-15)
Re: while loop code generation burley@cygnus.com (Craig Burley) (1997-12-15)
Re: while loop code generation tgl@netcom.com (Tom Lane) (1997-12-15)
Re: while loop code generation n8tm@aol.com (1997-12-15)
Re: while loop code generation tim@franck.Princeton.EDU.composers (1997-12-29)
Re: while loop code generation preston@tera.tera.com (1998-01-03)
| List of all articles for this month |
From: gclind01@spd.louisville.edu (George C. Lindauer)
Newsgroups: comp.compilers
Date: 15 Dec 1997 21:48:34 -0500
Organization: University of Louisville
References: 97-12-112
Keywords: code, optimize

Andrew Tucker (ast@halcyon.com) wrote:
> On page 227 of Fraser and Hanson's _A Retargetable C Compiler_,
> they claim that the code


> goto L+1
> L: statement
> L+1: if expression != 0 goto L
> L+2:


> generates n+2 goto's for a loop executing statement n times while
> the code


> L:
> L+1: if expression == 0 goto L+2
> statement
> goto L
> L+2:


This is processor dependent, and depends on such things as how well
the processor supports pipelining and branch prediction. But if you
take a simple architecture that does neither, then the time it takes
to fall through a conditional jump is not insignificant compared to
the time it takes to take the branch. On many processors the times
are approximately equal. On a processor where such is the case, the
extra jump that has to be executed for the second case costs time, and
the first is preferable to optimize that extra branch out.


Even on later processors that do simple pipelineing, the processor may
not be up to predicting an unconditional branch and in that case the
first case is preferable as well. Even on some of the latest
processors that do hefty branch predictions and pipelining there is a
little bit of time lost when the jumps are fectched from the pipeline
and executed, but of course it won't be nearly as much on such
processors.


David




--


Post a followup to this message

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