Repository navigation
Keep move-list counters in locals while generating moves - #457
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 13, 2026 22:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zzcgumn
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MoveGen0andMoveGen123build the move list by writingintfields throughmplywhile incrementing the membersnumMoves,lastNumMovesandsuit. The compiler has to assume those writes can alias the members, so it storednumMovesback 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,lastNumMovesandsuitonce after each loop. The heuristics already receive these values throughHeuristicContext, which is built before the loop, so nothing observes the members mid-loop.Results
verify_lists.shpasses in all five solver modes on list100 and list1000.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, andnumMoves,lastNumMovesandsuit. 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
developbefore this change, and the tests pass on both. Each of these breakages fails the test for its path:last_num_movesornum_movesto the heuristicremoved_ranksfor the wrong suit🤖 Generated with Claude Code