Conversation
Dice keeps a std::mt19937 as a member, 624 words of state, and seeds it from a std::seed_seq in the constructor. That seeding call alone needs a 2504 byte stack frame, and the constructor runs on the display task, which has 3200 bytes in total. A dice roll does not need a Mersenne twister. xorshift32 holds four bytes of state, the constructor frame drops from 2504 to 88 bytes, and the build comes out 832 bytes smaller. Checked on the host: 600000 d6 rolls stay within 0.7 % of even, a d99 reaches both 1 and 99, different seeds give different sequences, a zero seed does not lock the generator, and the sequence does not repeat within two million values. Rolling in the simulator gives varying results.
|
Build size and comparison to main:
|
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.
Dicekeeps astd::mt19937as a member. That is 624 words of state, and seeding it from astd::seed_seqin the constructor needs a 2504 byte stack frame, measured with-fstack-usage. The constructor runs on the display task, which is created with 800 words, so 3200 bytes for the whole call chain. It fits, but not by much.A dice roll does not need a Mersenne twister. This swaps it for xorshift32, which holds four bytes of state.
What it buys:
std::uniform_int_distributionstill does the range mapping, so the roll logic is unchanged.Checked on the host, since a broken generator still compiles: 600000 d6 rolls stay within 0.7 % of even, a d99 reaches both 1 and 99, two different seeds give different sequences, a zero seed does not lock the generator into its fixed point, and the sequence does not repeat within two million values. Rolling in the simulator gives varying results and colours.
PaddleandTwosalready use plainrand(), soDicewas the only screen carrying a heavyweight generator.