Repository navigation
Arbitrary logarithmic-time jumps for the xoshiro generators - #172
Merged
Merged
Conversation
discard() is now computed in time logarithmic in the distance, and the new jump(c, e) advances the generator by c * 2^e steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
The code is a port from the C code at https://prng.di.unimi.it/ authored by Claude Opus 5.5. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #172 +/- ##
===========================================
+ Coverage 96.11% 96.18% +0.07%
===========================================
Files 127 129 +2
Lines 8261 8446 +185
===========================================
+ Hits 7940 8124 +184
- Misses 321 322 +1
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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.
This PR makes
discard(z)of the xoshiro generators logarithmic inz(it currently callsnext()ztimes), and addsjump(c, e), which advances the generator by c · 2^e steps, so that non-overlapping subsequences can be obtained at any distance, not only at those ofjump()andlong_jump(). It is the same interface as the MWCX generators of #171, and the same functions are in the reference C code at https://prng.di.unimi.it (jump_ce()).Advancing a linear generator by n steps is equivalent to multiplying its state by x^n modulo the characteristic polynomial of its transition map;
x^n mod pis computed by square-and-multiply, and it is applied to the state with the same accumulate-and-step loop used byjump()andlong_jump().Notes:
detail/f2x_arithmetic.hppis a translation off2x.cfrom https://prng.di.unimi.it: plain shift-and-xor arithmetic in F₂[x], no carryless-multiply instructions.xoshiro_base.hppgets the characteristic polynomials of the three linear engines (xoshiro128, xoshiro256, xoshiro512: the output scramblers do not matter),jump(c, e), and the newdiscard().jump()andlong_jump()are unchanged, except that their comments now give the distances for each state size (they said 2^128 and 2^192 for all of them).discard()starts jumping, and about 20, 75 and 200 µs for distances close to 2^64. Below a threshold (2048 steps per 64 bits of state)discard()still steps the generator, as it is faster: the threshold is close to the break-even point with GCC and Clang.test/test_xoshiro_jump.cppchecks, for all nine generators,discard()andjump()against states computed with the referencejump_ce(),discard(d)andjump(d, 0)againstdsteps around the threshold,jump(1, 128)andjump(1, 192)againstjump()andlong_jump()(jump(1, 64)/jump(1, 96)andjump(1, 256)/jump(1, 384)for xoshiro128 and xoshiro512),jump(1, n)against a single step for n bits of state (the period is 2^n − 1), and the composition of jumps. Run with GCC 15.2 and Clang 21.1, C++11 and C++20, 64-bit and-m32; the existing xoshiro tests pass. I could not test MSVC.