summaryrefslogtreecommitdiff
path: root/src/testmove.c
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2026-09-16 08:02:21 -0700
committerScott Gasch <[email protected]>2026-09-16 08:02:21 -0700
commit966a0ef4da9cf3911eb3da0533179199808717b4 (patch)
treee09363b574215ef0d8996155a5ab24314db2dd69 /src/testmove.c
parentb91c8453f3fe21c8ccd3568923d8e39141c9c945 (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/testmove.c')
-rw-r--r--src/testmove.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/testmove.c b/src/testmove.c
index 6711046..9dbee96 100644
--- a/src/testmove.c
+++ b/src/testmove.c
@@ -46,16 +46,33 @@ Return value:
ULONG w;
COOR c;
- if ((TRUE == v) && (pos->uPawnCount[u]))
+ if ((TRUE == v) && (pos->bbPawns[u]))
{
- w = rand() % pos->uPawnCount[u];
- c = pos->cPawns[u][w];
+ BITBOARD bbPawns = pos->bbPawns[u];
+
+ w = rand() % FastCountBits(pos->bbPawns[u]);
+ do
+ {
+ c = CoorFromBitBoardRank8ToRank1(&bbPawns);
+ ASSERT(IS_ON_BOARD(c));
+ }
+ while (w-- > 0);
}
else
{
- ASSERT(pos->uNonPawnCount[u][0]);
- w = rand() % pos->uNonPawnCount[u][0];
- c = pos->cNonPawns[u][w];
+ COOR rgNonPawns[16];
+ ULONG uCount = 0;
+ BITBOARD bb = NON_KING_PIECES_BB(pos, u);
+ COOR cBit;
+
+ rgNonPawns[uCount++] = KingPosition(pos, u);
+ while (IS_ON_BOARD(cBit = CoorFromBitBoardRank8ToRank1(&bb)))
+ {
+ ASSERT(uCount < ARRAY_SIZE(rgNonPawns));
+ rgNonPawns[uCount++] = cBit;
+ }
+ w = rand() % uCount;
+ c = rgNonPawns[w];
}
ASSERT(IS_ON_BOARD(c));
return(c);