Re: while ();




\\\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.

.



Relevant Pages

  • Re: Can this loop be made faster ?
    ... |> Optimisation: maximal 16 iterations for loops which contain one branch, ... |> otherwise the branch-prediction-table will reload (8 clocks penalty ... |> every/after 16 iterations on AMD). ... but if a second Jcc is within the loop then there are more ...
    (alt.lang.asm)
  • Re: Can this loop be made faster ?
    ... increments, of course, the MEMORY at eax ... at least within the loop. ... maximal 16 iterations for loops which contain one branch, ... | routine, and the time is the divided by 100000 after all the calls. ...
    (alt.lang.asm)
  • [Pos] Some quest reward problems identified [Pos]
    ... randart.txt every single time a rand-art is created, ... The tailored reward loop should theoretically trigger a pretty sane ... The number of iterations is fame/5. ... Will look for the rand-art issue later... ...
    (rec.games.roguelike.angband)
  • Re: timeit module: am I missing something obvious?
    ... Why am I passing strings around when functions are ... best of 3 trials: 0.792 usec per loop ... quickly choosing number of iterations. ... - The result from the final pass through the convergence loop ...
    (comp.lang.python)
  • Re: 7.0-CURRENT Hang
    ... The subsequent loop of the following will loop virtually for ever (it t ... doesn't indicate it has the CPUID 0x02 function. ... Do you know what CPUID function 0x00 returns in EAX for your CPU? ... iterations, my guess is that it would take days to loop through this code. ...
    (freebsd-current)