From 48b0d41220c35ce50f5fc26c77b2879a75d104d2 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 3 Jul 2009 12:28:11 +0200 Subject: [PATCH] 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 --- src/pawns.cpp | 14 +++++++------- src/position.h | 29 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/pawns.cpp b/src/pawns.cpp index 8d29185e..d0523ab6 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -193,7 +193,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) { // Initialize pawn storm scores by giving bonuses for open files 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->qsStormValue[us] += QStormOpenFileBonus[f]; @@ -213,9 +213,9 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) { pi->halfOpenFiles[us] &= ~(1 << f); // Passed, isolated or doubled pawn? - passed = pos.pawn_is_passed(us, s); - isolated = pos.pawn_is_isolated(us, s); - doubled = pos.pawn_is_doubled(us, s); + passed = Position::pawn_is_passed(theirPawns, us, s); + isolated = Position::pawn_is_isolated(ourPawns, s); + doubled = Position::pawn_is_doubled(ourPawns, us, s); // We calculate kingside and queenside pawn storm // 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 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) & in_front_bb(us, r) & theirPawns) >= 0); @@ -339,7 +339,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) { { mv -= IsolatedPawnMidgamePenalty[f]; ev -= IsolatedPawnEndgamePenalty[f]; - if (pos.file_is_half_open(them, f)) + if (Position::file_is_half_open(theirPawns, f)) { mv -= IsolatedPawnMidgamePenalty[f] / 2; ev -= IsolatedPawnEndgamePenalty[f] / 2; @@ -354,7 +354,7 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) { { mv -= BackwardPawnMidgamePenalty[f]; ev -= BackwardPawnEndgamePenalty[f]; - if (pos.file_is_half_open(them, f)) + if (Position::file_is_half_open(theirPawns, f)) { mv -= BackwardPawnMidgamePenalty[f] / 2; ev -= BackwardPawnEndgamePenalty[f] / 2; diff --git a/src/position.h b/src/position.h index 9730d3dc..2762d2f8 100644 --- a/src/position.h +++ b/src/position.h @@ -244,12 +244,13 @@ public: // Information about pawns bool pawn_is_passed(Color c, Square s) const; - bool pawn_is_isolated(Color c, Square s) const; - bool pawn_is_doubled(Color c, Square s) const; + static bool pawn_is_passed(Bitboard theirPawns, Color c, Square s); + 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 - bool file_is_open(File f) const; - bool file_is_half_open(Color c, File f) const; + static bool file_is_open(Bitboard pawns, File f); + static bool file_is_half_open(Bitboard pawns, File f); // Weak squares 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)); } -inline bool Position::pawn_is_isolated(Color c, Square s) const { - return !(pawns(c) & neighboring_files_bb(s)); +inline bool Position::pawn_is_passed(Bitboard theirPawns, Color c, Square s) { + return !(theirPawns & passed_pawn_mask(c, s)); } -inline bool Position::pawn_is_doubled(Color c, Square s) const { - return pawns(c) & squares_behind(c, s); +inline bool Position::pawn_is_isolated(Bitboard ourPawns, Square s) { + return !(ourPawns & neighboring_files_bb(s)); } -inline bool Position::file_is_open(File f) const { - return !(pawns() & file_bb(f)); +inline bool Position::pawn_is_doubled(Bitboard ourPawns, Color c, Square s) { + return ourPawns & squares_behind(c, s); } -inline bool Position::file_is_half_open(Color c, File f) const { - return !(pawns(c) & file_bb(f)); +inline bool Position::file_is_open(Bitboard pawns, File 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 { -- 2.39.2