Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: how to "tell" a compiler to suppress jumps by RCL (optimizing question)

Author: Gerd Isenberg

Date: 16:17:09 06/01/04

Go up one level in this thread


<snip>
>>Hi Volker,
>>
>>Not sure, i guess current compiler are not aware of the RCL trick.
>>So you may still use (inline) assembler for best perfomance.
>>
>>Something like this in C may be result in a chain of cmp, setnz and lea
>>instructions:
>>
>>bitfield  = (q8 != 0);
>>bitfield <<= 1;
>>bitfield += (q7 != 0);
>>bitfield <<= 1;
>>...
>>bitfield += (q0 != 0);
>>
>>or more compact:
>>
>>bitfield = ...((((((q8!=0)<<1)+(q7!=0))<<1)+(q6!=0))<<1)...
>>
>>Btw. have you considered using bitboards?
>>
>>Cheers,
>>Gerd
>
>No I use 0x88. Seems best to me to build incremental attack tables. Thanks for
>the answer, yes adding a boolean may work ... testing ...
>
>Volker

If you introduce more of that stuff from packing square metrics to setwise
metrics, you may consider bitboards one time ;-)

Anyway, even if you avoid (difficult or easy to predict?) branches with
cmp-setCC/rcl/adc instructions the problem is a kind of stall, because setCC
needs to wait for the flag outcome of cmp.

Therefore to break dependencies it may be smarter to build "boolean" {-1,0}
values inside a register instead of {true,false} carry flag. That makes the code
much more able to work simultaniuosly.

assuming 32-bit int, signed shift and positive q values:

bitfield = ((-q8>>31) & 128)
         | ((-q7>>31) &  64)
         | ((-q6>>31) &  32)
         | ((-q5>>31) &  16)
         | ((-q4>>31) &   8)
         | ((-q3>>31) &   4)
         | ((-q2>>31) &   2)
         | ((-q1>>31) &   1);

OTOH if the conditional jumps are most often predicted correctly...

Cheers,
Gerd



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.