ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compiler Problem
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
LoopList
Guest





PostPost subject: Compiler Problem    Posted: Tue Jun 29, 2010 6:48 pm Reply to topic Reply with quote

Hi

The following code seems to work correct. The code does not make sense, but has an interesting behaviour in Microsoft Visual Studio 2010 as x64 Release with the flag Ob1 or Ob2 (perhaps full optimization).

The variables current->value and temp should have the value 50100, but with x64 Release Ob2 in VC2010 the output is 50000.

I don't know the reason?

Perhaps you can copy the code and see yourself!

Console output:
Code:

value...........50000
temp............50000


Regards
Fritz

Code:

#include <stdio.h>

typedef unsigned __int64 bitboard_t;  // long long

const int IS_ENPASSANT = 1 << 15;

struct move_info_c {
  int move;
  int value;
};

struct board_c {
  int color_on[64];
  int piece_on[64];
  bitboard_t piece_bb[6];
  bitboard_t color_bb[2];
};

class sort_c {
public:
  sort_c();
  move_info_c * last_move;
  move_info_c move_list[256];
};

static bitboard_t pawn_attack_bb[2][64];
static board_c B;

static void initialize_fen_position(const char * position, const char * to_move, const char * castle, const char * enpassant);
static move_info_c * generate_evasions(move_info_c * move_list);
static int static_exchange_evaluation(int move);
static void initialize_bitboards();

inline int move_to(int move) {
  return move & 63;
}

inline int move_from(int move) {
  return (move >> 6) & 63;
}

inline int move_is_enpassant(int move) {
  return (move & IS_ENPASSANT) != 0;
}

inline int make_enpassant(int from, int to) {
  return to | (from << 6) | IS_ENPASSANT;
}

inline int square_to_file(int square) {
  return square & 7;
}

inline int square_to_rank(int square) {
  return square >> 3;
}

inline int file_and_rank_to_square(int file, int rank) {
  return file + (rank << 3);
}

inline int piece_value_midgame(int piece) {
  int piece_value_mg[7] = {100, 300, 400, 500, 900, 1000, 0};
  return piece_value_mg[piece];
}

inline bitboard_t file_and_rank_to_bitboard(int file, int rank) {
  return static_cast<bitboard_t>(1) << static_cast<bitboard_t>(file_and_rank_to_square(file, rank));
}

inline bitboard_t pawn_attack_bitboard(int color, int square) {
  return pawn_attack_bb[color][square];
}

inline int color_on_square(int square) {
  return B.color_on[square];
}

inline int piece_on_square(int square) {
  return B.piece_on[square];
}

inline bitboard_t pawn_bitboard(int color) {
  return B.piece_bb[0] & B.color_bb[color];
}

inline int move_is_capture(int move) {
  return (piece_on_square(move_to(move)) != 6) || move_is_enpassant(move);
}

inline int move_piece(int move) {
  return piece_on_square(move_from(move));
}

inline int move_piece_captured(int move) {
  return move_is_enpassant(move) ? 0 : piece_on_square(move_to(move));
}

void initialize_bitboards() {
  for (int square = 0; square < 64; square++) {
    int file = square_to_file(square);
    int rank = square_to_rank(square);

    pawn_attack_bb[0][square] = 0;
    pawn_attack_bb[1][square] = 0;

    if (file - 1 >= 0 && rank + 1 <= 7) pawn_attack_bb[0][square] |= file_and_rank_to_bitboard(file - 1, rank + 1);
    if (file + 1 <= 7 && rank + 1 <= 7) pawn_attack_bb[0][square] |= file_and_rank_to_bitboard(file + 1, rank + 1);
    if (file - 1 >= 0 && rank - 1 >= 0) pawn_attack_bb[1][square] |= file_and_rank_to_bitboard(file - 1, rank - 1);
    if (file + 1 <= 7 && rank - 1 >= 0) pawn_attack_bb[1][square] |= file_and_rank_to_bitboard(file + 1, rank - 1);
  }
}

void initialize_fen_position() {
  for (int square = 0; square < 64; square++) {
    B.color_on[square] = 2;
    B.piece_on[square] = 6;
  }
  B.color_on[28] = 1;
  B.piece_on[28] = 0;
  B.color_on[29] = 0;
  B.piece_on[29] = 0;
}

move_info_c * generate_evasions(move_info_c * move_list) {
  (move_list++)->move = make_enpassant(28, 21);
  return move_list;
}

int static_exchange_evaluation(int move) {
  int from = move_from(move);
  int to = move_to(move);
  int me = color_on_square(from);
  int you = me ^ 1;
  int piece = piece_on_square(from);
  int piece_captured = move_piece_captured(move);

  if (   (pawn_attack_bitboard(me, to) & pawn_bitboard(you))
      && (piece_value_midgame(piece) > piece_value_midgame(piece_captured))
      && (piece_value_midgame(piece) > 100)) {
    return piece_value_midgame(piece_captured) - piece_value_midgame(piece);
  }
  return 0;
}

sort_c::sort_c() {
  int temp = 0;

  last_move = generate_evasions(move_list);

  move_info_c * current = move_list;

  int move = current->move;
  int value = static_exchange_evaluation(move);

  if (value < 0) {
    current->value = value;
  }
  else if (move_is_capture(move)) {
    temp = 50000 + piece_value_midgame(move_piece_captured(move)) - move_piece(move);
    current->value = temp;
  }
  else {
    current->value = 0;
  }

  printf_s("value...........%d\n", current->value);
  printf_s("temp............%d\n", temp);
}

int main() {
  initialize_bitboards();
  initialize_fen_position();
  sort_c s;
  return 0;
}
Back to top
Display posts from previous:   
Subject Author Date/Time
Compiler Problem LoopList Tue Jun 29, 2010 6:48 pm
      Re: Compiler Problem Dann Corbit Tue Jun 29, 2010 7:22 pm
            Re: Compiler Problem Mincho Georgiev Tue Jun 29, 2010 8:39 pm
            Re: Compiler Problem Robert Hyatt Tue Jun 29, 2010 9:20 pm
                  Re: Compiler Problem LoopList Wed Jun 30, 2010 5:26 am
                        Re: Compiler Problem Dann Corbit Wed Jun 30, 2010 5:38 am
                              Re: Compiler Problem LoopList Wed Jun 30, 2010 5:51 am
      Re: Compiler Problem Gian-Carlo Pascutto Wed Jun 30, 2010 9:42 am
            Re: Compiler Problem LoopList Wed Jun 30, 2010 10:43 am
                  Re: Compiler Problem Gian-Carlo Pascutto Wed Jun 30, 2010 11:23 am
                        Re: Compiler Problem LoopList Wed Jun 30, 2010 11:50 am
                              Re: Compiler Problem Wylie Garvin Wed Jun 30, 2010 4:28 pm
                              Re: Compiler Problem Robert Hyatt Wed Jun 30, 2010 5:20 pm
                                    Re: Compiler Problem LoopList Wed Jun 30, 2010 5:46 pm
                                          Re: Compiler Problem Robert Hyatt Wed Jun 30, 2010 7:31 pm
                                                Re: Compiler Problem Mincho Georgiev Thu Jul 01, 2010 8:11 am
                                                      Re: Compiler Problem LoopList Thu Jul 01, 2010 10:30 am
                                          Re: Compiler Problem Sven Schüle Mon Jul 12, 2010 1:08 pm
                                    Re: Compiler Problem Ricardo Barreira Thu Jul 01, 2010 8:47 am
                                          Re: Compiler Problem Wylie Garvin Thu Jul 01, 2010 1:25 pm
                                                Re: Compiler Problem Wylie Garvin Thu Jul 01, 2010 2:40 pm
                                          Re: Compiler Problem Robert Hyatt Thu Jul 01, 2010 4:30 pm
                                                Re: Compiler Problem Ricardo Barreira Thu Jul 01, 2010 10:53 pm
                                                      Re: Compiler Problem Robert Hyatt Thu Jul 01, 2010 11:46 pm
                                                            Re: Compiler Problem Ricardo Barreira Fri Jul 02, 2010 8:37 am
                                                                  Re: Compiler Problem Gian-Carlo Pascutto Fri Jul 02, 2010 9:01 am
                                                                        Re: Compiler Problem LoopList Fri Jul 02, 2010 9:15 am
                                                            Re: Compiler Problem Wylie Garvin Fri Jul 02, 2010 1:28 pm
                                                                  Re: Compiler Problem Robert Hyatt Fri Jul 02, 2010 8:33 pm
            Re: Compiler Problem Jon Dart Wed Jul 14, 2010 4:31 pm
                  Re: Compiler Problem Wylie Garvin Thu Jul 15, 2010 3:13 am
                        Re: Compiler Problem Wylie Garvin Thu Jul 15, 2010 4:00 am
                              Re: Compiler Problem Bo Persson Thu Jul 15, 2010 7:16 pm
                                    Re: Compiler Problem Gian-Carlo Pascutto Thu Jul 15, 2010 7:27 pm
                                          Re: Compiler Problem Dann Corbit Thu Jul 15, 2010 7:30 pm
                                                Re: Compiler Problem Dann Corbit Thu Jul 15, 2010 7:36 pm
                                                      Re: Compiler Problem Robert Hyatt Thu Jul 15, 2010 9:11 pm
                                    Re: Compiler Problem Wylie Garvin Fri Jul 16, 2010 3:30 am
                                          Re: Compiler Problem Bo Persson Fri Jul 16, 2010 7:54 pm
                                                Re: Compiler Problem Wylie Garvin Sat Jul 17, 2010 2:16 pm
                                                      Re: Compiler Problem Ron Murawski Tue Jul 20, 2010 6:18 am
                                                            Re: Compiler Problem Wylie Garvin Tue Jul 20, 2010 2:26 pm
      Re: Compiler Problem Pablo Vazquez Wed Jun 30, 2010 11:33 am
            Re: Compiler Problem Gian-Carlo Pascutto Wed Jun 30, 2010 12:14 pm
            Re: Compiler Problem LoopList Wed Jun 30, 2010 1:04 pm
      Re: Compiler Problem svchbe Wed Jun 30, 2010 1:14 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads