mirror of
https://github.com/sockspls/badfish
synced 2025-07-12 03:59:15 +00:00
Micro-optimize color_of()
In almost all cases we already know in advance that color_of() argument is different from NO_PIECE. So avoid the check for NO_PIECE in color_of() and test at caller site in the very few places where this case could occur. As a nice side effect, this patch fixes a (bogus) warning under some versions of gcc. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
6a93488291
commit
22c557ca7c
2 changed files with 6 additions and 4 deletions
|
@ -561,7 +561,7 @@ bool Position::is_pseudo_legal(const Move m) const {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// The destination square cannot be occupied by a friendly piece
|
// The destination square cannot be occupied by a friendly piece
|
||||||
if (color_of(piece_on(to)) == us)
|
if (piece_on(to) != NO_PIECE && color_of(piece_on(to)) == us)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Handle the special case of a pawn move
|
// Handle the special case of a pawn move
|
||||||
|
@ -587,7 +587,7 @@ bool Position::is_pseudo_legal(const Move m) const {
|
||||||
case DELTA_SE:
|
case DELTA_SE:
|
||||||
// Capture. The destination square must be occupied by an enemy
|
// Capture. The destination square must be occupied by an enemy
|
||||||
// piece (en passant captures was handled earlier).
|
// piece (en passant captures was handled earlier).
|
||||||
if (color_of(piece_on(to)) != them)
|
if (piece_on(to) == NO_PIECE || color_of(piece_on(to)) != them)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// From and to files must be one file apart, avoids a7h5
|
// From and to files must be one file apart, avoids a7h5
|
||||||
|
@ -772,7 +772,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
PieceType capture = type_of(m) == ENPASSANT ? PAWN : type_of(piece_on(to));
|
PieceType capture = type_of(m) == ENPASSANT ? PAWN : type_of(piece_on(to));
|
||||||
|
|
||||||
assert(color_of(piece) == us);
|
assert(color_of(piece) == us);
|
||||||
assert(color_of(piece_on(to)) != us);
|
assert(piece_on(to) == NO_PIECE || color_of(piece_on(to)) == them);
|
||||||
assert(capture != KING);
|
assert(capture != KING);
|
||||||
|
|
||||||
if (capture)
|
if (capture)
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
/// | only in 64-bit mode. For compiling requires hardware with
|
/// | only in 64-bit mode. For compiling requires hardware with
|
||||||
/// | popcnt support.
|
/// | popcnt support.
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -391,7 +392,8 @@ inline PieceType type_of(Piece p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color color_of(Piece p) {
|
inline Color color_of(Piece p) {
|
||||||
return p == NO_PIECE ? NO_COLOR : Color(p >> 3);
|
assert(p != NO_PIECE);
|
||||||
|
return Color(p >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_ok(Square s) {
|
inline bool is_ok(Square s) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue