Author: Miguel A. Ballicora
Date: 13:05:07 02/26/03
Go up one level in this thread
On February 26, 2003 at 14:04:16, Uri Blass wrote:
>I had the following code in my program
>
>do
>{
>...
>if (info[target]==EMPTA)
> target+=8;
>else
> target=64;
>}
>while (target<64)
I don't know what you are doing in "..." (are you modifying target there?) but
it looks to me that the following should be more readable and less prone to
bugs. Also, I don't know if you really need to execute the core of the loop to
justify using do {} while () rather than while() {}. If that is true, the
following might not be correct.
while (target < 64 && info[target] == EMPTA) {
...
target += 8;
}
I do not think it is a good idea to modify the variable that controls the exit
of the loop, besides an obvious increment, if it can be done differently.
In the way I proposed, if you really think that speed is critical, you can
optimize whatever is inside while (xxxxxxx). You have all the loop control in
one place.
Miguel
>
>I found that changing it to else break did not do my program faster.
>
>I think that with break I have branches and without break the compiler can
>translate it to
>
>target=((info[target]==EMPTA)?target+8:64);
>
>My questions are
>1)How can I write the code as branchless code without target=64 that is a waste
>of time?
>
>2)I understood from previous discussion that for some reason ? is considered
>branchless code.
>What is the reason for it.
>
>It seems to me that using ? is the same as using if.
>If it is not the case then what is the difference?
>
>Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.