Very Strange???

Discussion of chess software programming and technical issues.

Moderator: Ras

LoopList

Very Strange???

Post by LoopList »

Code: Select all

I call

bitboard_print(0xFF);

void bitboard_print(const uint64 bitboard) {
  sintx rank;
  sintx file;

  for (rank=SQUARE_RANK8; rank >= SQUARE_RANK1; rank--) {
    for (file=SQUARE_FILEA; file <= SQUARE_FILEH; file++) {
      if (bitboard & bitboard_from_file_rank(file, rank))
        printf_s("x");
      else
        printf_s("-");
    }
    printf_s("\n");
  }
  printf_s("\n");
}

and I get

--------
--------
--------
xxxxxxxx
--------
--------
--------
xxxxxxxx

in Release mode. In Debug mode I get the right bitboard?!?!

What is the problem?

LoopList

Re: Very Strange???

Post by LoopList »

Code: Select all

Sorry, I forgot the function:

inline uint64 bitboard_from_file_rank(const sintx file, const sintx rank) {
  return uint64(1) << uint64(file + (rank << 3));
}

pijl

Re: Very Strange???

Post by pijl »

LoopList wrote:

Code: Select all

I call

bitboard_print(0xFF);

void bitboard_print(const uint64 bitboard) {
  sintx rank;
  sintx file;

  for (rank=SQUARE_RANK8; rank >= SQUARE_RANK1; rank--) {
    for (file=SQUARE_FILEA; file <= SQUARE_FILEH; file++) {
      if (bitboard & bitboard_from_file_rank(file, rank))
        printf_s("x");
      else
        printf_s("-");
    }
    printf_s("\n");
  }
  printf_s("\n");
}

and I get

--------
--------
--------
xxxxxxxx
--------
--------
--------
xxxxxxxx

in Release mode. In Debug mode I get the right bitboard?!?!

What is the problem?

perhaps call with bitboard_print(uint64(0xFF));
Richard.
Alessandro Scotti

Re: Very Strange???

Post by Alessandro Scotti »

Your compiler is using the 32 bit version of the left shift, but I can't reproduce this behavior with MS Visual C++, which is the only compiler I can use right now. If using gcc make sure the compiler understand that "1" require a 64-bit shift, e.g. by explicitly using (1 ULL).
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Very Strange???

Post by Gerd Isenberg »

LoopList wrote:

Code: Select all

Sorry, I forgot the function:

inline uint64 bitboard_from_file_rank(const sintx file, const sintx rank) {
  return uint64(1) << uint64(file + (rank << 3));
}

Like Alessandro mentioned, for some weird reason the variable left shift amount is modulo 32. I would try this, note that (file + 8*rank) is only one lea ecx instruction...

Code: Select all

inline uint64 bitboard_from_file_rank(const sintx file, const sintx rank) {
  const uint64 one = 1;
  return one << (file + 8*rank);
} 
What compiler did you use?

Gerd
LoopList

Re: Very Strange???

Post by LoopList »

Thanks Gerd!
I used MS VC9 Beta in x64-mode