From c73706243672bf36b0fef58e817f843cb341d8ca Mon Sep 17 00:00:00 2001 From: DU-jdto Date: Thu, 21 Apr 2016 14:23:40 +1000 Subject: [PATCH] Remove some pointless micro-optimizations Seems to give around 1% speed-up for CPUs with popcnt support. Seems to give a very minor speed-up for CPUs without popcnt. No functional change Resolves #646 --- src/evaluate.cpp | 22 ++++++---------------- src/movegen.cpp | 2 +- src/position.cpp | 6 ++---- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 9739a001..0f2744d9 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -234,7 +234,7 @@ namespace { { ei.kingRing[Them] = b | shift_bb(b); b &= ei.attackedBy[Us][PAWN]; - ei.kingAttackersCount[Us] = b ? popcount(b) : 0; + ei.kingAttackersCount[Us] = popcount(b); ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0; } else @@ -276,9 +276,7 @@ namespace { { ei.kingAttackersCount[Us]++; ei.kingAttackersWeight[Us] += KingAttackWeights[Pt]; - bb = b & ei.attackedBy[Them][KING]; - if (bb) - ei.kingAdjacentZoneAttacksCount[Us] += popcount(bb); + ei.kingAdjacentZoneAttacksCount[Us] += popcount(b & ei.attackedBy[Them][KING]); } if (Pt == QUEEN) @@ -331,11 +329,7 @@ namespace { { // Bonus for aligning with enemy pawns on the same rank/file if (relative_rank(Us, s) >= RANK_5) - { - Bitboard alignedPawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]; - if (alignedPawns) - score += RookOnPawn * popcount(alignedPawns); - } + score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]); // Bonus when on an open or semi-open file if (ei.pi->semiopen_file(Us, file_of(s))) @@ -417,8 +411,7 @@ namespace { | ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK] | ei.attackedBy[Them][KING]; - if (b) - attackUnits += QueenContactCheck * popcount(b); + attackUnits += QueenContactCheck * popcount(b); } // Analyse the enemy's safe distance checks for sliders and knights @@ -514,9 +507,7 @@ namespace { while (b) score += Threat[Rook ][type_of(pos.piece_on(pop_lsb(&b)))]; - b = weak & ~ei.attackedBy[Them][ALL_PIECES]; - if (b) - score += Hanging * popcount(b); + score += Hanging * popcount(weak & ~ei.attackedBy[Them][ALL_PIECES]); b = weak & ei.attackedBy[Us][KING]; if (b) @@ -535,8 +526,7 @@ namespace { & pos.pieces(Them) & ~ei.attackedBy[Us][PAWN]; - if (b) - score += ThreatByPawnPush * popcount(b); + score += ThreatByPawnPush * popcount(b); if (DoTrace) Trace::add(THREAT, Us, score); diff --git a/src/movegen.cpp b/src/movegen.cpp index 6ef4be4f..3622f18e 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -239,7 +239,7 @@ namespace { && !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt])) continue; - if (ci->dcCandidates && (ci->dcCandidates & from)) + if (ci->dcCandidates & from) continue; } diff --git a/src/position.cpp b/src/position.cpp index 6e8b03d1..cd91b07f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -501,8 +501,7 @@ bool Position::legal(Move m, Bitboard pinned) 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 - || !(pinned & from) + return !(pinned & from) || aligned(from, to_sq(m), square(us)); } @@ -595,8 +594,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const { return true; // Is there a discovered check? - if ( ci.dcCandidates - && (ci.dcCandidates & from) + if ( (ci.dcCandidates & from) && !aligned(from, to, ci.ksq)) return true; -- 2.39.2