Sunday 15 February 2015

performance - Wouldn't a "do until" loop be more efficient? -


I'm new to programming, and I'm seeing a pattern that determines how often I'm Loops, for example while (! IsEmpty ())

"Until" "Loop" will not be according to better performance unless a condition is correct is? I know that the registers are rejected and very fast, but still it seems that it can be avoided.

Or maybe there is something about the assembly language that makes it better to use the currently established approach, even if it often requires denial?

The possibility of rejection will not be obviously the way in which at any time.

First of all, the simple "when" implementation looks like this x86

  _loophead: call_isEmpty test eax, eax; The return value is in ex jnz _loopend; If zero is not zero, then exit the loop ...; Loop body here is jmp _loophead _loopend:   

There is no actual prohibition, just a jnz that "jumps if not zero". What is not zero? The last thing that affects the "flag" - the above exam which checks the empty value of () .

A better "until" implementation (because it only takes 1 to a branch repetition)

  jmp _looptest _loopstart: ...; Loop body _looptest: Call _isEmpty exam eax, eax jz _loopstart; If the noise is zero then continue the loop   

Disclaimer, when it is present, does not take any extra time / directions / space, it is also a matter of many other processors.

In addition, if _isEmpty can be inline, the condition will not be the most in a register , this flag will be part of the state (A bit in a special register). "Boolean is one thing that is 0 or 1" Chi stuff is part of conceptual terms and is often optimized in actual implementation. You do not usually need a 0/1 value - the first thing you do most of the time, they register it again so that you can branch over it.

Even very early compilers tried specially to compile it as "used as a condition", more efficient code than making 0/1 integer was made.

No comments:

Post a Comment