Very Strange???

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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 &#40;file=SQUARE_FILEA; file <= SQUARE_FILEH; file++) &#123;
      if &#40;bitboard & bitboard_from_file_rank&#40;file, rank&#41;)
        printf_s&#40;"x");
      else
        printf_s&#40;"-");
    &#125;
    printf_s&#40;"\n");
  &#125;
  printf_s&#40;"\n");
&#125;

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&#58;

inline uint64 bitboard_from_file_rank&#40;const sintx file, const sintx rank&#41; &#123;
  return uint64&#40;1&#41; << uint64&#40;file + &#40;rank << 3&#41;);
&#125;

pijl

Re: Very Strange???

Post by pijl »

LoopList wrote:

Code: Select all

I call

bitboard_print&#40;0xFF&#41;;

void bitboard_print&#40;const uint64 bitboard&#41; &#123;
  sintx rank;
  sintx file;

  for &#40;rank=SQUARE_RANK8; rank >= SQUARE_RANK1; rank--) &#123;
    for &#40;file=SQUARE_FILEA; file <= SQUARE_FILEH; file++) &#123;
      if &#40;bitboard & bitboard_from_file_rank&#40;file, rank&#41;)
        printf_s&#40;"x");
      else
        printf_s&#40;"-");
    &#125;
    printf_s&#40;"\n");
  &#125;
  printf_s&#40;"\n");
&#125;

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: 2250
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&#58;

inline uint64 bitboard_from_file_rank&#40;const sintx file, const sintx rank&#41; &#123;
  return uint64&#40;1&#41; << uint64&#40;file + &#40;rank << 3&#41;);
&#125;

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&#40;const sintx file, const sintx rank&#41; &#123;
  const uint64 one = 1;
  return one << &#40;file + 8*rank&#41;;
&#125; 
What compiler did you use?

Gerd
LoopList

Re: Very Strange???

Post by LoopList »

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