diff options
| author | Scott Gasch <[email protected]> | 2026-09-16 08:02:21 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-09-16 08:02:21 -0700 |
| commit | 966a0ef4da9cf3911eb3da0533179199808717b4 (patch) | |
| tree | e09363b574215ef0d8996155a5ab24314db2dd69 /src/searchsup.c | |
| parent | b91c8453f3fe21c8ccd3568923d8e39141c9c945 (diff) | |
Retire cPawns/cNonPawns piece-location lists in favor of bbPawns/bbPieces/cKingSq, and hoist two redundant TotalNonPawnCount POPCNT calls out of per-node hot loops.
POSITION no longer stores cPawns[2][8], cNonPawns[2][16], uPawnCount[2],
uNonPawnCount[2][8], or uWhiteSqBishopCount[2] -- every reader now goes
through PawnMaterial/TotalNonPawnCount/WhiteSqBishopCount/KingPosition
(chess.h), computed from the already-incrementally-maintained bbPawns/
bbPieces/cKingSq bitboards via a single -mpopcnt POPCNT instead of a
stored counter. move.c's make/unmake loses the list-swap-on-removal
bookkeeping entirely. GNUmakefile now passes -mpopcnt so the popcount
builtins actually compile to one instruction instead of clang's ~15-op
SWAR fallback.
Measured a small but real nps regression from the naive swap (search.c's
QSearch move-filter and eval.c's _EvalKing were each recomputing the same
TotalNonPawnCount sum on every candidate move / twice per node); hoisted
both to a single call per node instead. Net result across a same-code
self-play match: ~1541.5 knps candidate vs ~1505.7 knps head_reference.
A third hoist (FindEnprisePiece out of SelectBestWithHistory) was tried
and reverted -- its cache isn't actually loop-invariant within a node
(populated from inside Eval(), which doesn't run before every selection
call), caught by a DEBUG-build ASSERT before it landed.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Diffstat (limited to 'src/searchsup.c')
| -rw-r--r-- | src/searchsup.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/searchsup.c b/src/searchsup.c index 7ab8695..2ec001f 100644 --- a/src/searchsup.c +++ b/src/searchsup.c @@ -614,7 +614,7 @@ Return value: *piExtend += HALF_PLY; if (!fIsLeftoverMove || ((g_KingAttacksBB[mv.cTo] & - COOR_TO_BB(pos->cNonPawns[uPawnColor][0])) || + COOR_TO_BB(KingPosition(pos, uPawnColor))) || (_RookAttacksBB(mv.cTo, pos->bbOccupied) & (pos->bbPieces[uPawnColor][ROOK] | pos->bbPieces[uPawnColor][QUEEN])) || @@ -669,8 +669,8 @@ Return value: { // Endgame extension if ((ctx->sPlyInfo[1].uTotalNonPawns > 2) && - ((pos->uNonPawnCount[BLACK][0] + - pos->uNonPawnCount[WHITE][0]) == 2)) + ((TotalNonPawnCount(pos, BLACK) + + TotalNonPawnCount(pos, WHITE)) == 2)) { if ((mv.pCaptured && !IS_PAWN(mv.pCaptured)) || (mvLast.pCaptured && !IS_PAWN(mvLast.pCaptured))) @@ -1334,8 +1334,8 @@ SelectNullmoveRFactor(SEARCHER_THREAD_CONTEXT *ctx, INT uDepth) { ULONG u = TWO_PLY; - ULONG uMaxPiecesPerSide = MAXU(ctx->sPosition.uNonPawnCount[WHITE][0], - ctx->sPosition.uNonPawnCount[BLACK][0]); + ULONG uMaxPiecesPerSide = MAXU(TotalNonPawnCount(&ctx->sPosition, WHITE), + TotalNonPawnCount(&ctx->sPosition, BLACK)); ASSERT(uMaxPiecesPerSide <= 16); if ((uDepth > 8 * ONE_PLY) || @@ -1369,7 +1369,7 @@ FLAG WeShouldTryNullmovePruning(SEARCHER_THREAD_CONTEXT *ctx, ASSERT(uNullDepth < MAX_PLY_PER_SEARCH * ONE_PLY); if ((FALSE == pf->fAvoidNullmove) && - (pos->uNonPawnCount[pos->uToMove][0] > 2) && + (TotalNonPawnCount(pos, pos->uToMove) > 2) && (FALSE == pi->fInCheck) && (iBeta != +INFINITY) && (NODE_PV != pi->eNodeType)) @@ -1440,7 +1440,7 @@ TryNullmovePruning(SEARCHER_THREAD_CONTEXT *ctx, // If there are very few pieces on the board, launch a // separate "verification search". - if ((pos->uNonPawnCount[pos->uToMove][0] < 4) && + if ((TotalNonPawnCount(pos, pos->uToMove) < 4) && (pf->fVerifyNullmove == TRUE)) { ASSERT(pf->fAvoidNullmove == FALSE); |
