Author: Gerd Isenberg
Date: 13:44:14 05/28/04
Go up one level in this thread
On May 28, 2004 at 15:49:05, Dieter Buerssner wrote:
>On May 28, 2004 at 13:22:05, Gerd Isenberg wrote:
>
>>You are almost right, but one additional "and" 0x0f0f0f0f is necessary ;-)
>
>Yes. Sorry, I forgot to mention it (actually I was too lazy, to think about it,
>in the code I gave in the URL it is there).
>
>Your trick with the maj() and odd() can make my head spin ...
>
>Can you easily compare it to my try pc_10bb() (population count of 10
>bitboards). It seems to work at least. Code follows.
Nice, is it faster?
One has to compare it with an optimized four time popcount and those additional
34 bitwise 64-bit instructions. I'm not sure whether it is really applicable for
chess, even for extreme bitboarders. Because i like to keep disjoint
intermedeate results, eg. oneOrThree, atLeastTwo for all attacks of pawns, light
pieces, rooks, queen/king. Those results may be further combined by successively
supplying the five instruction trick or counted independently.
For pawns, rooks, queen/king one may use polymorph odd- and majority overloads
with two parameters, only bishops (normally disjoint due to one is on light
squares and the other on dark) and two knights may require the three parameter
functions.
__forceinline
BitBoard odd(BitBoard x, BitBoard y) { return x^y;}
__forceinline
BitBoard maj(BitBoard x, BitBoard y) { return x&y;}
Cheers,
Gerd
>
>Cheers,
>Dieter
>
>int pc_10bb(BitBoard x[])
>{
> unsigned int a, b, c, d, i;
> unsigned int *xw = (unsigned int *)x; // Of course not really portable
> unsigned int aa[7], *aap=aa;
>
> /* Process first 18 words, do it in triples, because after the
> 2nd stage, we can combine 3 words without overflow */
> i = 6;
> do
> {
> a = *xw++;
> a = a - ((a>>1) & 0x55555555);
> b = *xw++;
> b = b - ((b>>1) & 0x55555555);
> c = *xw++;
> c = c - ((c>>1) & 0x55555555);
>
> a = (a & 0x33333333) + ((a>>2) & 0x33333333);
> b = (b & 0x33333333) + ((b>>2) & 0x33333333);
> c = (c & 0x33333333) + ((c>>2) & 0x33333333);
> *aap++ = a+b+c;
> /* Now we have 4 bit counters with max 12 */
> }
> while (--i);
> /* And the remaining 2 words */
> a = *xw++;
> a = a - ((a>>1) & 0x55555555);
> b = *xw++;
> b = b - ((b>>1) & 0x55555555);
>
> a = (a & 0x33333333) + ((a>>2) & 0x33333333);
> b = (b & 0x33333333) + ((b>>2) & 0x33333333);
> aa[6] = a+b;
>
> /* process the 4 bit counters in aa[] */
> a = aa[0];
> b = aa[1];
> c = aa[2];
> d = aa[3];
>
> a = (a & 0x0f0f0f0f) + ((a>>4) & 0x0f0f0f0f);
> b = (b & 0x0f0f0f0f) + ((b>>4) & 0x0f0f0f0f);
> c = (c & 0x0f0f0f0f) + ((c>>4) & 0x0f0f0f0f);
> d = (d & 0x0f0f0f0f) + ((d>>4) & 0x0f0f0f0f);
> /* 8-bit counters now have a max of 24. We can add 8 such counters together */
> d += a+b+c;
>
> a = aa[4];
> b = aa[5];
> c = aa[6];
>
> a = (a & 0x0f0f0f0f) + ((a>>4) & 0x0f0f0f0f);
> b = (b & 0x0f0f0f0f) + ((b>>4) & 0x0f0f0f0f);
> c = (c & 0x0f0f0f0f) + ((c>>4) & 0x0f0f0f0f);
>
> d+=a+b+c;
>
> /* Maybe, it is possible to save some masks in the last 2 steps
> but it won't really matter */
> d = (d & 0x00ff00ff) + ((d>>8) & 0x00ff00ff);
> d = (d & 0x0000ffff) + ((d>>16) & 0x0000ffff);
> return d;
>}
>
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.