Bug: Different behaviour with -O1 and -O1 -fregmove

Thomas Schuster Thomas.Schuster@gmx.net
Thu Feb 24 12:59:00 GMT 2000


System: Linux 2.2.10 with glib (AMD K6-2)

Compiler:
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.96/specs
gcc version 2.96 20000221 (experimental)

Bug:
Following source aborts when compiled with "-O1 -fregmove".
No abort with "-O1".
(Complete command line:  gcc -g -O1 -fregmove -o bug bug.c
and:  gcc -g -O1 -o nobug bug.c     ).

Source (condensed from the chess program crafty-V16.08: utility.c).

========== bug.c : begin

typedef unsigned long long BITBOARD;

struct at {
    unsigned char which_attack[8][64];
    BITBOARD      file_attack_bitboards[8][12];
    unsigned char rank_attack_bitboards[8][12];
    unsigned char length8_mobility[8][12];
    unsigned char short_mobility[116];
};

typedef struct {
    BITBOARD *d_attacks;
    unsigned char *d_mobility;
    unsigned char *d_which_attack;
    unsigned char d_shift;
    unsigned char d_mask;
    unsigned char ad_shift;
    unsigned char ad_mask;
    unsigned char *ad_which_attack;
    unsigned char *ad_mobility;
    BITBOARD *ad_attacks;
} DIAG_INFO;

const unsigned char bishop_shift_rl45[64] = {
          59, 57, 54, 50, 45, 39, 32,  0,
          57, 54, 50, 45, 39, 32,  0,  8,
          54, 50, 45, 39, 32,  0,  8, 15,
          50, 45, 39, 32,  0,  8, 15, 21,
          45, 39, 32,  0,  8, 15, 21, 60,
          39, 32,  0,  8, 15, 21, 60, 26,
          32,  0,  8, 15, 21, 60, 26, 29,
           0,  8, 15, 21, 60, 26, 29, 31 };

const unsigned char bishop_shift_rr45[64] = {
            0,  8, 15, 21, 60, 26, 29, 31,
           32,  0,  8, 15, 21, 60, 26, 29,
           39, 32,  0,  8, 15, 21, 60, 26,
           45, 39, 32,  0,  8, 15, 21, 60,
           50, 45, 39, 32,  0,  8, 15, 21,
           54, 50, 45, 39, 32,  0,  8, 15,
           57, 54, 50, 45, 39, 32,  0,  8,
           59, 57, 54, 50, 45, 39, 32,  0 };

const unsigned char n_attacks[9][8] =
{
  {  0 },
  {  1 },
  {  1,  1 },
  {  2,  1,  2 },
  {  3,  2,  2,  3 },
  {  4,  3,  4,  3,  4 },
  {  5,  4,  6,  6,  4,  5 },
  {  6,  5,  8,  9,  8,  5,  6 },
  {  7,  6, 10, 12, 12, 10,  6,  7}
};

static struct gfile_info {
  BITBOARD *bitboard;
  unsigned char length;
  unsigned char *map;
  unsigned char *mobility;
  unsigned char inc;
} gfiles[((7 + 1 + 7) + (7 + 1 + 7) + 1 + 1)];

static unsigned char diag_map [(7 + 1 + 7)] [8];
static unsigned char anti_diag_map [(7 + 1 + 7)] [8];
static DIAG_INFO     diag_info[64];
static struct at at;


static void InitializeMaps(BITBOARD *temp_rank_attack_bitboards) {
  int file, rank;
  int diag;
  int gfile;
  BITBOARD *b;
  unsigned char *m;
  unsigned char *mobility_for_length[9];
  static const unsigned char diag_base [(7 + 1 + 7)] =
    { (((7)<<3) | (0)), (((6)<<3) | (0)), (((5)<<3) | (0)), (((4)<<3)
| (0)), (((3)<<3) | (0)), (((2)<<3) | (0)), (((1)<<3) | (0)),
(((0)<<3) | (0)),
      (((0)<<3) | (1)), (((0)<<3) | (2)), (((0)<<3) | (3)), (((0)<<3)
| (4)), (((0)<<3) | (5)), (((0)<<3) | (6)), (((0)<<3) | (7)) };
  static const unsigned char anti_base[(7 + 1 + 7)] =
    { (((0)<<3) | (0)), (((0)<<3) | (1)), (((0)<<3) | (2)), (((0)<<3)
| (3)), (((0)<<3) | (4)), (((0)<<3) | (5)), (((0)<<3) | (6)),
(((0)<<3) | (7)),
      (((1)<<3) | (7)), (((2)<<3) | (7)), (((3)<<3) | (7)), (((4)<<3)
| (7)), (((5)<<3) | (7)), (((6)<<3) | (7)), (((7)<<3) | (7)) };
  {
    int i;
    for (i = 1; i < 9; i++) {
      mobility_for_length[i] = (void *)i;
    }
  }
  gfile = 0;
  for (diag = 0; diag < (7 + 1 + 7); diag++, gfile++) {
    int sq = diag_base[diag];
    const int len = (8 - ((((sq)>>3)&7) > ((sq)&7) ?
(((sq)>>3)&7) - ((sq)&7) :              ((sq)&7) - (((sq)>>3)&7)));
    const int excess = 8 - len;
    int i;
    gfiles[gfile].length = len;
    gfiles[gfile].map = diag_map[diag];
    gfiles[gfile].bitboard = b;
    gfiles[gfile].mobility = (diag < 7 ? mobility_for_length[len] :
0);
    gfiles[gfile].inc = 0;
    m = mobility_for_length[len];
    for (i = 0; i < len; i++, sq += 9) {
      diag_map[diag][i] = sq;
      diag_info[sq].d_shift = bishop_shift_rr45[sq] + 1 - excess;
      diag_info[sq].d_mask = (~((~0) << ((((len-2) > (0)) ? (len-2) :
(0))))) << excess;
      diag_info[sq].d_which_attack = &at.which_attack[i][0];
      diag_info[sq].d_attacks = 0;
      diag_info[sq].d_mobility = m;
      m += (len == 8 ? 12 : n_attacks[len][i]);
    }
  }
}

int main ()
{
  BITBOARD    	tt;

  memset(&diag_info, 0, sizeof(diag_info));
  memset(&at, 0, sizeof(at));
  InitializeMaps(&tt);

  if (diag_info[56].d_shift != 53)
	abort();

  return 0;
}

========== bug.c : end

Thomas


More information about the Gcc-bugs mailing list