mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Indirectly prefetch board[from]
One of the most time critical functions is move_is_check() and in particular the call to type_of_piece_on(from) in the switch statement. This call lookups in board[] array and can be slow if board[from] is not already cached. Few instructions before in the execution stream, we check the move for legality with pl_move_is_legal(). This patch changes pl_move_is_legal() to use type_of_piece_on(from) for checking for a king move so that board[from] is automatically cached in L1 and ready to be used by the near follower move_is_check() Another advantage is that the call to king_square(us) in pl_move_is_legal() is avoided most of the times. Speed up of this nice and tricky patch is 0.7% ! No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
f205fe1fe5
commit
3863cd191c
1 changed files with 4 additions and 4 deletions
|
@ -479,10 +479,9 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
|||
|
||||
Color us = side_to_move();
|
||||
Square from = move_from(m);
|
||||
Square ksq = king_square(us);
|
||||
|
||||
assert(color_of_piece_on(from) == us);
|
||||
assert(piece_on(ksq) == piece_of_color_and_type(us, KING));
|
||||
assert(piece_on(king_square(us)) == piece_of_color_and_type(us, KING));
|
||||
|
||||
// En passant captures are a tricky special case. Because they are
|
||||
// rather uncommon, we do it simply by testing whether the king is attacked
|
||||
|
@ -493,6 +492,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
|||
Square to = move_to(m);
|
||||
Square capsq = make_square(square_file(to), square_rank(from));
|
||||
Bitboard b = occupied_squares();
|
||||
Square ksq = king_square(us);
|
||||
|
||||
assert(to == ep_square());
|
||||
assert(piece_on(from) == piece_of_color_and_type(us, PAWN));
|
||||
|
@ -509,14 +509,14 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
|||
|
||||
// If the moving piece is a king, check whether the destination
|
||||
// square is attacked by the opponent.
|
||||
if (from == ksq)
|
||||
if (type_of_piece_on(from) == KING)
|
||||
return !(square_is_attacked(move_to(m), opposite_color(us)));
|
||||
|
||||
// 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
|
||||
|| !bit_is_set(pinned, from)
|
||||
|| (direction_between_squares(from, ksq) == direction_between_squares(move_to(m), ksq)));
|
||||
|| (direction_between_squares(from, king_square(us)) == direction_between_squares(move_to(m), king_square(us))));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue