Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: SPEED !!! help a novice chess programmer =)

Author: Dann Corbit

Date: 11:06:47 06/18/02

Go up one level in this thread


On June 18, 2002 at 08:00:19, Adriano Bedeschi de Souza wrote:
[snip]
>Already done! Now i reach 3,5KN/s ! =)
>Now iam having problems with the LSB function (its poorly coded, actually in the
>poorest way =)

Why not show us what you have done?  It is also very important that you show the
exact mapping for your bitboard.  Not everyone chooses the same thing.  So Joe's
firstbit() might be different than Frank's.

Here is one possible solution (which may or may not work for you):

static const unsigned int S_lowbit_lookup[] = {
     0,  1,  2,  6,  3, 11,  7, 16,  4, 14, 12, 21,  8, 23, 17, 26,
    31,  5, 10, 15, 13, 20, 22, 25, 30,  9, 19, 24, 29, 18, 28, 27
};

#define NUMBITS 32
#define LOWBIT(x) S_lowbit_lookup[(((x) & -(x))*0x04653adf >> 27) & 0x1f]

Or this:
static int map[67] =
{
    -1,  0,  1, 39,  2, 15, 40, 23,  3, 12, 16, 59, 41, 19, 24, 54,
     4,  0, 13, 10, 17, 62, 60, 28, 42, 30, 20, 51, 25, 44, 55, 47,
     5, 32,  0, 38, 14, 22, 11, 58, 18, 53, 63,  9, 61, 27, 29, 50,
    43, 46, 31, 37, 21, 57, 52,  8, 26, 49, 45, 36, 56,  7, 48, 35,
     6, 34, 33,
};

/* Returns bit index of top bit of x, or -1 if x = 0. */
static int LastOne( uint64 x )
{
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    x |= x >> 32;
    x ^= x >> 1;
    return map[x % 67];
}

The approach in Pepito is very nice and very efficient -- the C version is
almost indistinguishable from assembly langauge in speed.  There are assembly
versions in Crafty, but I would not recommend them until later.



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.