Re: while ();
- From: robertwessel2@xxxxxxxxx
- Date: 30 Jan 2006 13:57:31 -0800
\\\o///annabee wrote:
> På 15 Jan 2006 15:17:07 -0800, skrev <spamtrap@xxxxxxxxxx>:
>
> >
> > robertwessel2@xxxxxxxxx wrote:
> >>
> >> One thing to remember is that most CPUs, in the absence of any other
> >> information, will predict a backwards branch as taken, and a forward
> >> branch as not taken. That's why most compilers will generate the test
> >> at the end of the loop (and the form Randy described is quite common).
> >>
> >> If you take many iterations through the loop, it won't matter much (at
> >> least on a CPU with dynamic branch prediction), since the collected
> >> branch history will cause the correct prediction after the first few
> >> iterations. If, OTOH, there were (say) only three iterations, you'd
> >> expect two mispredictions (the first and third iteration) for the
> >> test-at-top form, and only one misprediction (last iteration) in
> >> Randy's version of the test-at-bottom form.
> >
> > Hi Robert and Randy,
> >
> > Thanks for the input... I've updated the compiler to generate the test
> > at the bottom, rather than at the top.
>
> Imo, what you should do is to do nothing.
> (Scrap your compiler as well).
>
> As RobbertWessel says, ( misunderstanding the implications of his own
> words it seems),
> is that it wount matter if many iterations, and it certainly wount matter
> at
> all then, because 3 iterations will be closer to nothing.
Obviously the notion that a loop with few iterations might be inside a
big loop has escaped you. If you have a million iterations around a
small loop of two or three iterations the performance of the small loop
will most certainly matter, and with that few iterations branch
(mis)prediction will be a significant issue.
.
- Follow-Ups:
- Re: while ();
- From: \\\\\\o///annabee
- Re: while ();
- References:
- Re: while ();
- From: \\\\\\o///annabee
- Re: while ();
- Prev by Date: Re: Two Click disassembly/reassembly
- Next by Date: Re: Two Click disassembly/reassembly
- Previous by thread: Re: while ();
- Next by thread: Re: while ();
- Index(es):
Relevant Pages
|