mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Micro-optimize pl_move_is_legal()
This L1/L2 optimization has an incredible +4.7% speedup in perft test where this function is the most time consumer. Verified a speed up also in normal bench, although smaller. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
f57d51b7f3
commit
df6ba1fa5c
1 changed files with 9 additions and 7 deletions
|
@ -588,22 +588,18 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
if (move_is_castle(m))
|
if (move_is_castle(m))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Color us = side_to_move();
|
|
||||||
Square from = move_from(m);
|
|
||||||
|
|
||||||
assert(color_of_piece_on(from) == us);
|
|
||||||
assert(piece_on(king_square(us)) == piece_of_color_and_type(us, KING));
|
|
||||||
|
|
||||||
// En passant captures are a tricky special case. Because they are
|
// En passant captures are a tricky special case. Because they are
|
||||||
// rather uncommon, we do it simply by testing whether the king is attacked
|
// rather uncommon, we do it simply by testing whether the king is attacked
|
||||||
// after the move is made
|
// after the move is made
|
||||||
if (move_is_ep(m))
|
if (move_is_ep(m))
|
||||||
{
|
{
|
||||||
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = opposite_color(us);
|
||||||
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
Square capsq = make_square(square_file(to), square_rank(from));
|
Square capsq = make_square(square_file(to), square_rank(from));
|
||||||
Bitboard b = occupied_squares();
|
|
||||||
Square ksq = king_square(us);
|
Square ksq = king_square(us);
|
||||||
|
Bitboard b = occupied_squares();
|
||||||
|
|
||||||
assert(to == ep_square());
|
assert(to == ep_square());
|
||||||
assert(piece_on(from) == piece_of_color_and_type(us, PAWN));
|
assert(piece_on(from) == piece_of_color_and_type(us, PAWN));
|
||||||
|
@ -618,6 +614,12 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
&& !(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, them));
|
&& !(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, them));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color us = side_to_move();
|
||||||
|
Square from = move_from(m);
|
||||||
|
|
||||||
|
assert(color_of_piece_on(from) == us);
|
||||||
|
assert(piece_on(king_square(us)) == piece_of_color_and_type(us, KING));
|
||||||
|
|
||||||
// If the moving piece is a king, check whether the destination
|
// If the moving piece is a king, check whether the destination
|
||||||
// square is attacked by the opponent.
|
// square is attacked by the opponent.
|
||||||
if (type_of_piece_on(from) == KING)
|
if (type_of_piece_on(from) == KING)
|
||||||
|
|
Loading…
Add table
Reference in a new issue