Re: while ();



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.


We saw, some time back Randall Hyde posted some while loop, which was written by an "expert",
but turned out to be slower then a loop written in 2 secs, by a assembly beginner.
It was not at all significantly slower, but it was slower.


If doing windows programming, doing a windows app, scrap any other tool than RosASM.
If you need to use another assembler, because of other requirements, develop and test as much of
the logic in RosASM and port that. You will save time in the 10x department.


If you took time to do assembly with RosAsm, over some time, past the initial learning curve you would never ask this question, because you would know that the answer is not important.

The only important thing is the USER perception of time. If it is not closer to instant, it is too slow. If it takes then 2 minutes, because there simply isnt any other way, and you can make it 1 minute and 50 seconds, this will be useless investment of energy on your part.
The user will have returned elsewhere long before the first 10 seconds have passed. And when he comes back, it might have took 3 minutes and he would have probably not noticed.


The better way to test some code is to see it run. And the only useful optimization is the Strategy optimization. Sometimes, on the later processors, you can _add_ a lot of code and end up with a FASTER running app ... True, I have seen this.

I refer to [BU_ASM / 32Bit_Assembly_tutorials / Optimizations / Strategy_Optimizations ] for more info.

Get RosAsm here
< http://betov.free.fr/RosAsm.html >


--
Darran (aka Chewy509) brought to you by Google Groups!
.



Relevant Pages

  • Re: trolls food (python vs lisp)
    ... > The problem often seems to be that I know before the start of a loop ... > how many iterations it will go through, ... I then need to convince the compiler that something like: ... > will make a remain much smaller than a fixnum. ...
    (comp.lang.lisp)
  • Re: spinoza programming language and big numbers
    ... Seed7 - The extensible programming language: ... ## Compiling the compiler ... ... the number of odd iterations is ... var bigInteger: bigONE is 1_; ...
    (comp.programming)
  • 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: spinoza programming language and big numbers
    ... ## Compiling the compiler ... ... the number of odd iterations is ... var bigInteger: bigONE is 1_; ... bits Seed7 interpreter Seed7 compiler ...
    (comp.programming)
  • 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)