Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about using firstone in bitboard

Author: Russell Reagan

Date: 11:34:23 01/20/03

Go up one level in this thread


On January 20, 2003 at 14:06:15, Uri Blass wrote:

>I find in crafty 2 functions for firstone
>
>The first function is something has some function cntlzw that I am unable to
>understand.
>
>int 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);
>}

Hi Uri,

You will notice that the code actually is this:

#if defined(MACOS)

int 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);
}

int 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);
}

int PopCnt(register BITBOARD a) {
  register int c=0;

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

#else

Take notice of the #if defined(MACOS) and #else. These are preprocessors. They
run before the compiler starts compiling, and they only let in the code that
should be there. So if you were compiling Crafty on a PC, then MACOS would not
be defined, and that code would get sent to the compiler. If you were compiling
on a Mac, then MACOS would be defined, and the above code would get sent to the
compiler instead of the stuff after #else. I guess __cntlzw are functions that
the compilers on a Mac use.

Russell



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.