1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Microptimize pawns info access

Avoid indirect calling of piece_of_color_and_type(c, PAWN) and its
alias pawns(c) in the pawn evaluation loop, but use the pawns
bitboards accessed only once before entering the loop.

Also explicitly mark functions as static to better self-document.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-07-03 12:28:11 +02:00
parent 5d79af9e0d
commit 48b0d41220
2 changed files with 24 additions and 19 deletions

View file

@ -193,7 +193,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
// Initialize pawn storm scores by giving bonuses for open files // Initialize pawn storm scores by giving bonuses for open files
for (File f = FILE_A; f <= FILE_H; f++) for (File f = FILE_A; f <= FILE_H; f++)
if (pos.file_is_half_open(us, f)) if (Position::file_is_half_open(ourPawns, f))
{ {
pi->ksStormValue[us] += KStormOpenFileBonus[f]; pi->ksStormValue[us] += KStormOpenFileBonus[f];
pi->qsStormValue[us] += QStormOpenFileBonus[f]; pi->qsStormValue[us] += QStormOpenFileBonus[f];
@ -213,9 +213,9 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
pi->halfOpenFiles[us] &= ~(1 << f); pi->halfOpenFiles[us] &= ~(1 << f);
// Passed, isolated or doubled pawn? // Passed, isolated or doubled pawn?
passed = pos.pawn_is_passed(us, s); passed = Position::pawn_is_passed(theirPawns, us, s);
isolated = pos.pawn_is_isolated(us, s); isolated = Position::pawn_is_isolated(ourPawns, s);
doubled = pos.pawn_is_doubled(us, s); doubled = Position::pawn_is_doubled(ourPawns, us, s);
// We calculate kingside and queenside pawn storm // We calculate kingside and queenside pawn storm
// scores for both colors. These are used when evaluating // scores for both colors. These are used when evaluating
@ -319,7 +319,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
// Test for candidate passed pawn // Test for candidate passed pawn
candidate = !passed candidate = !passed
&& pos.file_is_half_open(them, f) && Position::file_is_half_open(theirPawns, f)
&& ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns) && ( count_1s_max_15(neighboring_files_bb(f) & (behind_bb(us, r) | rank_bb(r)) & ourPawns)
- count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns) - count_1s_max_15(neighboring_files_bb(f) & in_front_bb(us, r) & theirPawns)
>= 0); >= 0);
@ -339,7 +339,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
{ {
mv -= IsolatedPawnMidgamePenalty[f]; mv -= IsolatedPawnMidgamePenalty[f];
ev -= IsolatedPawnEndgamePenalty[f]; ev -= IsolatedPawnEndgamePenalty[f];
if (pos.file_is_half_open(them, f)) if (Position::file_is_half_open(theirPawns, f))
{ {
mv -= IsolatedPawnMidgamePenalty[f] / 2; mv -= IsolatedPawnMidgamePenalty[f] / 2;
ev -= IsolatedPawnEndgamePenalty[f] / 2; ev -= IsolatedPawnEndgamePenalty[f] / 2;
@ -354,7 +354,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
{ {
mv -= BackwardPawnMidgamePenalty[f]; mv -= BackwardPawnMidgamePenalty[f];
ev -= BackwardPawnEndgamePenalty[f]; ev -= BackwardPawnEndgamePenalty[f];
if (pos.file_is_half_open(them, f)) if (Position::file_is_half_open(theirPawns, f))
{ {
mv -= BackwardPawnMidgamePenalty[f] / 2; mv -= BackwardPawnMidgamePenalty[f] / 2;
ev -= BackwardPawnEndgamePenalty[f] / 2; ev -= BackwardPawnEndgamePenalty[f] / 2;

View file

@ -244,12 +244,13 @@ public:
// Information about pawns // Information about pawns
bool pawn_is_passed(Color c, Square s) const; bool pawn_is_passed(Color c, Square s) const;
bool pawn_is_isolated(Color c, Square s) const; static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s);
bool pawn_is_doubled(Color c, Square s) const; static bool pawn_is_isolated(Bitboard ourPawns, Square s);
static bool pawn_is_doubled(Bitboard ourPawns, Color c, Square s);
// Open and half-open files // Open and half-open files
bool file_is_open(File f) const; static bool file_is_open(Bitboard pawns, File f);
bool file_is_half_open(Color c, File f) const; static bool file_is_half_open(Bitboard pawns, File f);
// Weak squares // Weak squares
bool square_is_weak(Square s, Color c) const; bool square_is_weak(Square s, Color c) const;
@ -591,20 +592,24 @@ inline bool Position::pawn_is_passed(Color c, Square s) const {
return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s)); return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
} }
inline bool Position::pawn_is_isolated(Color c, Square s) const { inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) {
return !(pawns(c) & neighboring_files_bb(s)); return !(theirPawns & passed_pawn_mask(c, s));
} }
inline bool Position::pawn_is_doubled(Color c, Square s) const { inline bool Position::pawn_is_isolated(Bitboard ourPawns, Square s) {
return pawns(c) & squares_behind(c, s); return !(ourPawns & neighboring_files_bb(s));
} }
inline bool Position::file_is_open(File f) const { inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) {
return !(pawns() & file_bb(f)); return ourPawns & squares_behind(c, s);
} }
inline bool Position::file_is_half_open(Color c, File f) const { inline bool Position::file_is_open(Bitboard pawns, File f) {
return !(pawns(c) & file_bb(f)); return !(pawns & file_bb(f));
}
inline bool Position::file_is_half_open(Bitboard pawns, File f) {
return !(pawns & file_bb(f));
} }
inline bool Position::square_is_weak(Square s, Color c) const { inline bool Position::square_is_weak(Square s, Color c) const {