Skip to content

Keep move-list counters in locals while generating moves - #457

Merged
zzcgumn merged 3 commits into
dds-bridge:developfrom
randalburns:lift-movegen
Nov 16, 2026
Merged

zzcgumn merged 3 commits into
dds-bridge:developfrom
randalburns:lift-movegen

Conversation

@randalburns

@randalburns randalburns commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

MoveGen0 and MoveGen123 build the move list by writing int fields through mply while incrementing the members numMoves, lastNumMoves and suit. The compiler has to assume those writes can alias the members, so it stored numMoves back to memory for every move and reloads the members on each pass.

This change counts moves in a local, writes through a local pointer, uses a local suit index, and sets numMoves, lastNumMoves and suit once after each loop. The heuristics already receive these values through HeuristicContext, which is built before the loop, so nothing observes the members mid-loop.

Results

  • Output is unchanged: verify_lists.sh passes in all five solver modes on list100 and list1000.
  • On 100 deals (dtest -s calc, one thread), the change retires 1.2% fewer instructions, the same in every run.

Tests
The existing MoveGen tests compare only weights between configurations, so they would not catch a change in the generated moves or in the counter members. The second commit pins the full output of each generation path: the moves in final order with suit, rank, sequence and weight, list.current/list.last, and numMoves, lastNumMoves and suit. The paths are lead (MoveGen0), void, follow with several moves, and follow with a single move (MoveGen123). The test deal covers a void suit, card groups split by other hands, and two groups merged through removed ranks.

The expected values were captured from develop before this change, and the tests pass on both. Each of these breakages fails the test for its path:

  • dropping any of the final member assignments
  • passing a wrong last_num_moves or num_moves to the heuristic
  • reading removed_ranks for the wrong suit

🤖 Generated with Claude Code

randalburns and others added 2 commits November 13, 2026 16:51
MoveGen0 and MoveGen123 build the move list by writing int fields through
mply while incrementing the members numMoves, lastNumMoves and suit. The
compiler must assume those writes can alias the members, so it stored
numMoves back to memory for every move and reloaded members each pass.

Count moves in a local, write through a local pointer, use a local suit
index, and set numMoves, lastNumMoves and suit once after each loop, with
the same final values as before (and before make_heuristic_context copies
them).

Output is unchanged: verify_lists.sh passes in all five solver modes on
list100 and list1000. On 100 deals (dtest -s calc, one thread) the change
retires 1.2% fewer instructions, the same in every run; the cycle saving
is within run-to-run noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The existing MoveGen tests compare only weights between configurations,
so they would not notice a change in the moves generated or in the
numMoves, lastNumMoves and suit members left behind. Add a deal that
covers a void suit, split card groups and groups merged through removed
ranks, and pin the full output (moves in order with weights, list bounds
and counter members) for the lead, void, follow and single-follow paths.
The expected values were captured from the code before the move
generators kept their counters in locals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randalburns
randalburns marked this pull request as ready for review November 13, 2026 22:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzcgumn
zzcgumn merged commit af16924 into dds-bridge:develop Nov 16, 2026
15 checks passed
@randalburns
randalburns deleted the lift-movegen branch November 16, 2026 21:07
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.

2 participants