Skip to content

rand_xoshiro: Shrink all-zero-seed fallback via shared rodata constant#111

Merged
dhardy merged 2 commits into
masterfrom
rodata-fallback
May 16, 2026
Merged

rand_xoshiro: Shrink all-zero-seed fallback via shared rodata constant#111
dhardy merged 2 commits into
masterfrom
rodata-fallback

Conversation

@vks

@vks vks commented May 11, 2026

Copy link
Copy Markdown
Contributor

Replace the per-RNG SplitMix64::seed_from_u64(0) cold call with a single 64-byte ZERO_SEED_FALLBACK static.

Reduces combined .text + .rodata by 496 B on a small binary that exercises every from_seed, and shrinks each call site by 8 B. The all-zero-seed output is byte-identical to the previous behavior; a new zero_seed_fallback_matches_splitmix test derives the static at runtime and asserts equality, and each RNG has a new zero_seed_maps_to_seed_from_u64_zero test pinning the remap.

Removing the check entirely would save 51 B at the call site, and 592 B in .text + .rodata (see #107).

Replace the per-RNG `SplitMix64::seed_from_u64(0)` cold call with a
single 64-byte `ZERO_SEED_FALLBACK` static.

Reduces combined `.text + .rodata` by 496 B on a small binary that
exercises every `from_seed`, and shrinks each call site by 8 B. The
all-zero-seed output is byte-identical to the previous behavior; a new
`zero_seed_fallback_matches_splitmix` test derives the static at
runtime and asserts equality, and each RNG has a new
`zero_seed_maps_to_seed_from_u64_zero` test pinning the remap.

Removing the check entirely would save 51 B at the call site, and 592 B
in `.text + .rodata` (see #107).
@vks vks force-pushed the rodata-fallback branch from 34530b5 to 46dbe92 Compare May 12, 2026 23:27

@dhardy dhardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly fine.

Comment thread rand_xoshiro/src/common.rs Outdated
Comment thread rand_xoshiro/src/common.rs Outdated
@vks vks requested a review from dhardy May 14, 2026 16:00
@dhardy dhardy merged commit 8f59889 into master May 16, 2026
14 checks passed
@vks vks deleted the rodata-fallback branch May 16, 2026 13:40
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