Author: Angrim
Date: 14:41:50 02/27/03
Go up one level in this thread
On February 27, 2003 at 07:27:40, Vincent Diepeveen wrote:
>On February 27, 2003 at 07:22:37, Vincent Diepeveen wrote:
>
>>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 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?
>>
>>there is many ways to speed this up. just guessing from head (so without looking
>>to the assembly output it produces):
Before you worry about what assembly code it produces, you should worry
about if your "optimized" version works at all.
>>do {
>> int tempty=info[target]-EMPTA;
>> target += 8;
>>} while( !tempty );
This version didn't work since it ignored the case that the squares were
all empty. The old version checked for this, and terminated when target==64.
>oh i realize you want to scan.
>
>try this with a good compiler (for example visual c++ sp4 processor pack
>or gcc 3.2.x whatever is latest):
>
>do {
> int tempty=info[target]-EMPTA;
> if( !tempty ) // good compilers do this branchless
> target += 8;
>} while( target < 64 );
>
>>// of course target is not 64 now as precondition
>>
<snip>
This version is even worse, since if it hits a non-empty square, it will
not increment target, and will do an infinite loop.
Angrim
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.