Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: algorithm question

Author: h.g.muller

Date: 04:07:23 02/28/06

Go up one level in this thread


On February 28, 2006 at 02:57:37, Reinhard Scharnagl wrote:

>
>When I had been working with a 0x88 structure I used to iterate by:
>
>coor = ((coor | ~0x77) + 1) & 0x77;
>
>thus handling the coordinate bit combinations of 0x77;
>
>But your method above is indeed simpler and faster.
>
>Reinhard.

In my minimalistic engine micro-Max I use indeed

while(x=(x+9)&~0x88)

to scan the board. There are all kind of tricks to exploit the fact that the ALU
in your CPU has special harware to do fast carry propagation, like isolating the
least-significant '1' bit in a word:

x = y & ~(y-1);

The y-1 changes something like 010010011010000000
into                           010010011001111111, (here the carry does the
work)
and the bit-clear makes this   000000000010000000.

If you want to count the number of '1' bits in a long word where the '1's are
very sparse, getting them one by one through this expression and then clearing
them with

y &= ~x;

before isolating the next is the fastest way.



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.