[gray-matter] r1620 committed - saves a few more instructions.

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 2, 2010, 11:51:05 PM8/2/10
to gray-matter-...@googlegroups.com
Revision: 1620
Author: protonspring
Date: Mon Aug 2 20:50:11 2010
Log: saves a few more instructions.


http://code.google.com/p/gray-matter/source/detail?r=1620

Modified:
/trunk/inc/board_base.h
/trunk/src/board_base.cpp
/trunk/src/board_heuristic.cpp

=======================================
--- /trunk/inc/board_base.h Mon Aug 2 20:21:16 2010
+++ /trunk/inc/board_base.h Mon Aug 2 20:50:11 2010
@@ -38,10 +38,9 @@
/// This class represents the board and generates moves.
class board_base
{
- //precomputed single bit masks
- static bitboard_t BIT_MSK[8][8];
-
public:
+ static bitboard_t BIT_MSK[8][8];
+ static bitboard_t ROW_MSK[8];
inline static int BIT_IDX(int x, int y) {return ((y) << 3 |
(x));}
inline static bool BIT_GET(bitboard_t b, int x, int y) {return
((b) >> BIT_IDX(x, y) & 1);}
inline static void BIT_CLR(bitboard_t& b, unsigned x, unsigned y)
{(b) &= ~BIT_MSK[x][y];}
@@ -51,9 +50,18 @@
inline static int ROW_NUM(int x,int y,int a){return ((a) ==
ZERO ? (y) : (x));}
inline static int ROW_LOC(int x,int y,int a){return ((a) ==
ZERO ? (x) : 7 - (y));}
inline static int ROW_IDX(int n){return (BIT_IDX(0, n));}
- inline static bitboard_t ROW_MSK(int n){return (0xFFULL << ROW_IDX(n));}
+/*
+ inline static bitboard_t ROW_MSK(int n)
+ {
+ bitboard_t rm1 = 0xFFULL << ROW_IDX(n);
+ bitboard_t rm2 = ROW_MSK2[n];
+ if (rm1 != rm2)
+ std::cout << std::hex << rm1 << "," << rm2 << std::endl;
+ return (0xFFULL << ROW_IDX(n));
+ }
+*/
inline static bitrow_t ROW_GET(bitboard_t b, int n){return
((bitrow_t)((b) >> ROW_IDX(n) & 0xFF));}
- inline static bitboard_t ROW_CLR(bitboard_t& b, int n){return ((b) &=
~ROW_MSK(n));}
+ inline static bitboard_t ROW_CLR(bitboard_t& b, int n){return ((b) &=
~ROW_MSK[n]);}
inline static bitboard_t ROW_SET(bitboard_t& b, int n, bitrow_t
r){return ((b) |= (bitboard_t) (r) << ROW_IDX(n));}

// These macros manipulate columns in 0° rotated BitBoards and rows in
90°
=======================================
--- /trunk/src/board_base.cpp Mon Aug 2 20:21:16 2010
+++ /trunk/src/board_base.cpp Mon Aug 2 20:50:11 2010
@@ -161,6 +161,7 @@
bitboard_t board_base::key_on_move;

uint64_t board_base::BIT_MSK[8][8];
+bitboard_t board_base::ROW_MSK[8];


/*----------------------------------------------------------------------------*\
|
board_base() |
@@ -173,8 +174,11 @@

//compute single bit masks
for (int i=0;i<8;++i)
+ {
+ ROW_MSK[i] = 0xFFULL << i*8;
for (int j=0;j<8;++j)
BIT_MSK[j][i] = 1ULL << (i*8+j);
+ }

if (!precomputed_board_base)
{
@@ -1511,8 +1515,8 @@
// For its first move, a pawn can advance two squares.
if (!only_captures)
{
- b = state.piece[ON_MOVE][PAWN] & ROW_MSK(ON_MOVE ? 6 : 1);
- //bitboard_t rowMsk = ROW_MSK(ON_MOVE ? 6: 1);
+ b = state.piece[ON_MOVE][PAWN] & ROW_MSK[ON_MOVE ? 6 : 1];
+ //bitboard_t rowMsk = ROW_MSK[ON_MOVE ? 6: 1];
if (b) //only do this stuff if there are pawns there
{
for (int y = 1; y <= 2; y++)
@@ -1714,7 +1718,7 @@
squares_pawn_attacks[color][x][y] = 0;
else
{
- bitboard_t row = ROW_MSK(y + (!color ? -1 : 1));
+ bitboard_t row = ROW_MSK[y + (!color ? -1 : 1)];
bitboard_t cols = squares_adj_cols[x];
squares_pawn_attacks[color][x][y] = row & cols;
}
=======================================
--- /trunk/src/board_heuristic.cpp Wed Jul 28 22:54:14 2010
+++ /trunk/src/board_heuristic.cpp Mon Aug 2 20:50:11 2010
@@ -461,11 +461,11 @@
if (!is_rook_on_7th)
goto no_rook_on_7th;
enemy_pawns = state.piece[!color][PAWN];
- seventh_row = ROW_MSK(seventh);
+ seventh_row = ROW_MSK[seventh];
is_enemy_pawn_on_7th = (enemy_pawns & seventh_row)?true:false;
enemy_king = state.piece[!color][KING];
eighth = color == WHITE ? 7 : 0;
- eighth_row = ROW_MSK(eighth);
+ eighth_row = ROW_MSK[eighth];
is_enemy_king_on_8th = (enemy_king & eighth_row)?true:false;
if (!is_enemy_pawn_on_7th && !is_enemy_king_on_8th)
goto no_rook_on_7th;
@@ -518,11 +518,11 @@
if (!is_queen_on_7th)
goto no_queen_on_7th;
enemy_pawns = state.piece[!color][PAWN];
- seventh_row = ROW_MSK(seventh);
+ seventh_row = ROW_MSK[seventh];
is_enemy_pawn_on_7th = (enemy_pawns & seventh_row)?true:false;
enemy_king = state.piece[!color][KING];
eighth = color == WHITE ? 7 : 0;
- eighth_row = ROW_MSK(eighth);
+ eighth_row = ROW_MSK[eighth];
is_enemy_king_on_8th = (enemy_king & eighth_row)?true:false;
if (!is_enemy_pawn_on_7th && !is_enemy_king_on_8th)
goto no_queen_on_7th;
@@ -623,7 +623,7 @@
// There can never be any pawn (of either color) on rank 1 or
rank
// 7.
continue;
- squares_pawn_duo[x][y] = squares_adj_cols[x] & ROW_MSK(y);
+ squares_pawn_duo[x][y] = squares_adj_cols[x] & ROW_MSK[y];
}

for (int color = WHITE; color <= BLACK; color++)
@@ -637,7 +637,7 @@
squares_pawn_potential_attacks[color][x][y] = 0;
for (int k = y + sign; k >= 1 && k <= 6; k += sign)
squares_pawn_potential_attacks[color][x][y] |=
- squares_adj_cols[x] & ROW_MSK(k);
+ squares_adj_cols[x] & ROW_MSK[k];
}
}
}
Reply all
Reply to author
Forward
0 new messages