Compute checkers from scratch

This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):

stat        test     master    diff
mean   2,403,118  2,390,904  12,214
stdev     12,043     10,620   3,677

speedup       0.51%
P(speedup>0) 100.0%

No functional change.
This commit is contained in:
lucasart
2015-02-15 15:49:20 +08:00
committed by Marco Costalba
parent 901bfb1f55
commit dc13004283
4 changed files with 17 additions and 41 deletions

View File

@@ -687,10 +687,10 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
void Position::do_move(Move m, StateInfo& newSt) {
CheckInfo ci(*this);
do_move(m, newSt, ci, gives_check(m, ci));
do_move(m, newSt, gives_check(m, ci));
}
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool givesCheck) {
void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
assert(is_ok(m));
assert(&newSt != st);
@@ -848,32 +848,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool gives
// Update the key with the final value
st->key = k;
// Update checkers bitboard: piece must be already moved due to attacks_from()
st->checkersBB = 0;
if (givesCheck)
{
if (type_of(m) != NORMAL)
st->checkersBB = attackers_to(king_square(them)) & pieces(us);
else
{
// Direct checks
if (ci.checkSq[pt] & to)
st->checkersBB |= to;
// Discovered checks
if (ci.dcCandidates && (ci.dcCandidates & from))
{
assert(pt != QUEEN);
if (pt != ROOK)
st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK);
if (pt != BISHOP)
st->checkersBB |= attacks_from<BISHOP>(king_square(them)) & pieces(us, QUEEN, BISHOP);
}
}
}
// Calculate checkers bitboard (if move is check)
st->checkersBB = givesCheck ? attackers_to(king_square(them)) & pieces(us) : 0;
sideToMove = ~sideToMove;