Computer Chess Club Archives


Search

Terms

Messages

Subject: Code for Joshua and Andredas

Author: William Bryant

Date: 17:14:20 07/01/04

Go up one level in this thread


I am currently working on a chess variant with a small board.
Therefore I use only a 32 bit - bitboard.

I have posted the codewarrior code for a 64 bit bitmap below (which breakes it
up into a 32 bit call to cntlzw).  A 64 bit processor would be sweet.

Below that is an example of the XCode wrapper for the function call which is
built into codewarrior.
 I took this from source code on the apple site and it works well with XCode.
You may have to shift the result to get the bit order correct.

Hope this helps

William

-----the Code-----

unsigned long FirstOne(register BitBoard a) {
  register unsigned long i;

  if (i = a >> 32)
    return(__cntlzw(i));
  if (i = (unsigned int) a)
    return(__cntlzw(i) + 32);
  return(64);
}

unsigned long LastOne(register BitBoard a) {
  register unsigned long i;

  if (i = (unsigned int) a)
    return(__cntlzw(i ^ (i - 1)) + 32);
  if (i = a >> 32)
    return(__cntlzw(i ^ (i - 1)));
  return(64);
}

unsigned long NextOne(register BitBoard& a) {
  register unsigned long i;
  register unsigned long value;

 if (i = a >> 32) {
    value = __cntlzw(i);
    a^=SquareMask[value];
    return value;
    }
 if (i = (unsigned int) a) {
  	value = __cntlzw(i) + 32;
  	a^=SquareMask[value];
  	return value;
  	}
  return(64);
}

long PopCnt(register BitBoard a) {
  register long c=0;

  while(a) {
    c++;
    a &= a - 1;
  }
  return(c);
}

NOTE: for the XCode code below, tBitBoard is defined as an unsigned long not an
unsigned long long

#define  __cntlzw(a) ({ \
    tBitBoard r; \
    asm("cntlzw %0,%1" : "=r"(r) : "r"(a)); \
    r;\
})

//this chage switches the count distace from the MSB to the LSB
//  still starting from the MSB side when multiple bits are present
#define cntlzwR(a)  (31 - (__cntlzw(a)))



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.