rt: pull upstream ISAAC code for consistency between 32/64 bit platforms#6058
Closed
huonw wants to merge 2 commits into
Closed
rt: pull upstream ISAAC code for consistency between 32/64 bit platforms#6058huonw wants to merge 2 commits into
huonw wants to merge 2 commits into
Conversation
The "unsigned 4 byte" `ub4`s are actually 8 bytes on 64-bit platforms which mean that some bits > 2**32 were retained in calculations, these would then "reappear" after a shift and so the stream of random numbers would differ on 32 bit vs 64 bit platforms.
Contributor
|
@graydon: r? |
Contributor
|
Nice catch. |
This means that `ub4`s are always 4 bytes, rather than being 8 bytes on x64. (Suggested but not implemented by upstream: "Porting it to a 64-bit machine [...] may just need an adjustment of the definition of ub4")
Contributor
Author
|
@graydon: I just read the source web page in more detail and it suggests:
So I added a commit that does this change (while retaining the old one). Without it, half the seed was unused. |
bors
added a commit
that referenced
this pull request
Apr 27, 2013
The "unsigned 4 byte" `ub4`s are actually 8 bytes on 64-bit platforms which mean that some bits > 2**32 were retained in calculations, these would then "reappear" after a right shift and so the stream of random numbers would differ on 32 bit vs 64 bit platforms. http://burtleburtle.net/bob/c/randport.c
bors
added a commit
that referenced
this pull request
Apr 30, 2013
This replaces the wrapper around the runtime RNG with a pure Rust implementation of the same algorithm. This is much faster (up to 5x), and is hopefully safer. There is still (a little) room for optimisation: testing by summing 100,000,000 random `u32`s indicates this is about ~~40-50%~~ 10% slower than the pure C implementation (running as standalone executable, not in the runtime). (Only 6d50d55 is part of this PR, the first two are from #6058, but are required for the rt rng to be correct to compare against in the tests.)
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.
The "unsigned 4 byte"
ub4s are actually 8 bytes on 64-bit platformswhich mean that some bits > 2**32 were retained in calculations, these
would then "reappear" after a right shift and so the stream of random numbers
would differ on 32 bit vs 64 bit platforms.
http://burtleburtle.net/bob/c/randport.c