Skybuck Flying schrieb:

This hereby indicates problems with the while loop: it makes little sense to 
put the exiting
conditions at the top.


Why?

     ...
     dec     rcx
     jbe     1f
   0:some
     code
     to
     perform
     ...
     jmp     0b

     p2align 5,,31
   1:continue
     with
     something
     else
     ...

This code triggers one penalty if RCX was zero or negative (it jumps directly
to label 1 after the penalty for the wrong assumption "not taken" passed by),
or two penalties if RCX was positive - one for the 2nd assumption is "taken",
one for the finally taken conditional jump.

The same applies if you moved the condition check to the end of the loop, but
you could not catch negative numbers / zero without executing the code in the
loop at least once.

There is no general rule which construct should be preferred. In the end, the
one suiting your needs might be the best choice. On the other hand, no one is
able to predict which code might be generated by a specific HLL-compiler.


Greetings from Augsburg

Bernhard Schornak

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to