From 939395729c78dd43816826ffdb0a61f33a833e9f Mon Sep 17 00:00:00 2001 From: bmc4 Date: Tue, 16 Mar 2021 20:51:31 +0100 Subject: [PATCH] Introduce least_significant_square_bb() Introducing least_significant_square_bb(). It is a function that returns a value equal to square_bb(lsb(bb)), but it uses fewer instruction. It should speed up more on older processors like armv7-a Clang. Passed STC: LLR: 2.93 (-2.94,2.94) {-0.25,1.25} Total: 213200 W: 19171 L: 18753 D: 175276 Ptnml(0-2): 680, 14513, 75831, 14861, 715 https://tests.stockfishchess.org/tests/view/604bc7632433018de7a38982 Closes https://github.com/official-stockfish/Stockfish/pull/3391 No functional change --- src/bitboard.h | 7 +++++++ src/position.cpp | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/bitboard.h b/src/bitboard.h index e14fe0df..1b6af3ea 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -414,6 +414,13 @@ inline Square msb(Bitboard b) { #endif +/// least_significant_square_bb() returns the bitboard of the least significant +/// square of a non-zero bitboard. It is equivalent to square_bb(lsb(bb)). + +inline Bitboard least_significant_square_bb(Bitboard b) { + assert(b); + return b & -b; +} /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard diff --git a/src/position.cpp b/src/position.cpp index 17b165b9..f4739413 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1109,7 +1109,7 @@ bool Position::see_ge(Move m, Value threshold) const { if ((swap = PawnValueMg - swap) < res) break; - occupied ^= lsb(bb); + occupied ^= least_significant_square_bb(bb); attackers |= attacks_bb(to, occupied) & pieces(BISHOP, QUEEN); } @@ -1118,7 +1118,7 @@ bool Position::see_ge(Move m, Value threshold) const { if ((swap = KnightValueMg - swap) < res) break; - occupied ^= lsb(bb); + occupied ^= least_significant_square_bb(bb); } else if ((bb = stmAttackers & pieces(BISHOP))) @@ -1126,7 +1126,7 @@ bool Position::see_ge(Move m, Value threshold) const { if ((swap = BishopValueMg - swap) < res) break; - occupied ^= lsb(bb); + occupied ^= least_significant_square_bb(bb); attackers |= attacks_bb(to, occupied) & pieces(BISHOP, QUEEN); } @@ -1135,7 +1135,7 @@ bool Position::see_ge(Move m, Value threshold) const { if ((swap = RookValueMg - swap) < res) break; - occupied ^= lsb(bb); + occupied ^= least_significant_square_bb(bb); attackers |= attacks_bb(to, occupied) & pieces(ROOK, QUEEN); } @@ -1144,7 +1144,7 @@ bool Position::see_ge(Move m, Value threshold) const { if ((swap = QueenValueMg - swap) < res) break; - occupied ^= lsb(bb); + occupied ^= least_significant_square_bb(bb); attackers |= (attacks_bb(to, occupied) & pieces(BISHOP, QUEEN)) | (attacks_bb(to, occupied) & pieces(ROOK , QUEEN)); } -- 2.39.2