Very Strange???

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
LoopList

Very Strange???

Post by LoopList » Fri Jun 01, 2007 8:28 am

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 » Fri Jun 01, 2007 8:30 am

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 » Fri Jun 01, 2007 8:38 am

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 » Fri Jun 01, 2007 8:51 am

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: 2127
Joined: Wed Mar 08, 2006 7:47 pm
Location: Hattingen, Germany

Re: Very Strange???

Post by Gerd Isenberg » Fri Jun 01, 2007 9:23 am

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 » Fri Jun 01, 2007 9:50 am

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

Post Reply