Speedup and simplify pinners and blockers

To compute dicovered check or pinned pieces we use some bitwise
operators that are not really needed because already accounted for
at the caller site.

For instance in evaluation we compute:

     pos.pinned_pieces(Us) & s

Where pinned_pieces() is:

     st->blockersForKing[c] & pieces(c)

So in this case the & operator with pieces(c) is useless,
given the outer '& s'.

There are many places where we can use the naked blockersForKing[]
instead of the full pinned_pieces() or discovered_check_candidates().

This path is simpler than original and gives around 1% speed up for me.
Also tested for speed by mstembera and snicolet (neutral in both cases).

No functional change.
This commit is contained in:
Marco Costalba
2018-02-27 01:18:33 +01:00
committed by Stéphane Nicolet
parent d438720a1c
commit ad2a0e356e
5 changed files with 30 additions and 31 deletions

View File

@@ -464,7 +464,7 @@ const string Position::fen() const {
Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const {
Bitboard result = 0;
Bitboard blockers = 0;
pinners = 0;
// Snipers are sliders that attack 's' when a piece is removed
@@ -476,14 +476,14 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners
Square sniperSq = pop_lsb(&snipers);
Bitboard b = between_bb(s, sniperSq) & pieces();
if (!more_than_one(b))
if (b && !more_than_one(b))
{
result |= b;
blockers |= b;
if (b & pieces(color_of(piece_on(s))))
pinners |= sniperSq;
}
}
return result;
return blockers;
}
@@ -540,7 +540,7 @@ bool Position::legal(Move m) const {
// A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king.
return !(pinned_pieces(us) & from)
return !(blockers_for_king(us) & from)
|| aligned(from, to_sq(m), square<KING>(us));
}
@@ -632,7 +632,7 @@ bool Position::gives_check(Move m) const {
return true;
// Is there a discovered check?
if ( (discovered_check_candidates() & from)
if ( (st->blockersForKing[~sideToMove] & from)
&& !aligned(from, to, square<KING>(~sideToMove)))
return true;