Skip to content

Move lists in inplace vectors and range-based move picking - #66

Merged
nook0110 merged 5 commits into
deploy-elofrom
inplace-move-lists
Nov 12, 2026
Merged

nook0110 merged 5 commits into
deploy-elofrom
inplace-move-lists

Conversation

@nook0110

@nook0110 nook0110 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Replaces the Stockfish-style move list plumbing with standard-library idioms, with no change in search or speed.

Move generation (d34eecb)

  • InplaceVector<T, N> (Chess/InplaceVector.h): a fixed-capacity vector with the subset of the std::inplace_vector interface the engine uses. std::inplace_vector itself needs libstdc++ 16, and GCC 16 currently builds this engine about 10% slower (under investigation).
  • GeneratePseudoLegalMoves / GenerateLegalMoves return PseudoLegalMoves / LegalMoves by value instead of writing through PseudoLegalMove*& cursors into caller-owned arrays.
  • Helpers append with unchecked_push_back.
  • The en passant filter is erase_if.
  • Callers use range-for, std::ranges::contains and views::concat instead of pointer loops.
  • The duplicate GenerateMoves is gone.
  • The principal variation gets its own type bounded by the deepest depth.
  • Move generation and PV extraction no longer allocate.

Move picker (1fc4ead)

  • PartialInsertionSort(begin, end, INT64_MIN) becomes SortByScore(ScoredRange), an iterator-based insertion sort.
  • The killer lookup uses std::ranges::find with a &ScoredMove::move projection.
  • ScoredRange is a subrange of std::array iterators rather than a std::span: GCC 15 adds one instruction per shifted element in loops over span iterators.

Verification (GCC 15, gate build with -flto-partition=one, CPU 19, three alternating runs each)

  • Identical nodes and best moves on 30 positions (7,274,560 nodes).

  • Perft: startpos d5 = 4,865,609; kiwipete d4 = 4,085,603.

  • Instructions per node:

    build instructions/node
    Track move legality in the type system #63 11,708–11,719
    after d34eecb 11,710–11,721
    after 1fc4ead 11,712–11,716
  • Cycles within noise; 1fc4ead shows 0.8% fewer.

  • Machine code:

    • push loops keep the list size in a register;
    • returned lists are built in place without copies;
    • the sort's inner loop is instruction-for-instruction the same as before.
  • Tests: 206/206 pass in Release.

Stacked on #63.

🤖 Generated with Claude Code

nook0110 and others added 2 commits November 9, 2026 05:12
Move generation wrote through PseudoLegalMove*& cursors into
caller-owned std::array buffers, and legal moves came back in a
heap-allocated std::vector.

Add InplaceVector<T, N>, a fixed-capacity vector with the subset of the
std::inplace_vector interface the engine needs. std::inplace_vector
itself needs libstdc++ 16, and GCC 16 currently builds this engine
slower. GeneratePseudoLegalMoves and GenerateLegalMoves return
PseudoLegalMoves and LegalMoves by value, the helpers append with
unchecked_push_back, the en passant filter is erase_if, and callers use
range-for, std::ranges::contains and views::concat instead of pointer
loops. GenerateMoves duplicated GenerateLegalMoves and is gone. The
principal variation gets its own type bounded by the deepest depth, so
move generation and PV extraction no longer allocate.

Search is unchanged: identical nodes and best moves on 30 positions,
perft startpos d5 4865609 and kiwipete d4 4085603. The push loops keep
the size in a register and store it once, and the returned lists are
built in place without copies. Instructions per node +0.04%
(11708-11719 vs 11714-11721), cycles within noise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PartialInsertionSort took raw begin/end pointers and a limit that was
always INT64_MIN, so the partial part never applied. It becomes
SortByScore over a ScoredRange, a std::ranges::subrange of the scored
move array, written with iterators and std::prev. The killer lookup in
bad captures uses std::ranges::find with a &ScoredMove::move projection
instead of find_if over data() pointers.

The range is a subrange of std::array iterators rather than a std::span:
GCC 15 keeps an extra pointer copy per shifted element in loops over
span iterators, while array iterators compile to the same 7-instruction
inner loop as before. Search is unchanged (identical nodes and best
moves on 30 positions); instructions per node 11712-11716 vs
11710-11713, cycles per node 13468-13524 vs 13590-13602.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nook0110
nook0110 changed the base branch from move-legality-types to deploy-elo November 12, 2026 00:11
nook0110 and others added 2 commits November 12, 2026 04:34
@nook0110
nook0110 merged commit 13235ba into deploy-elo Nov 12, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant