Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.random.unpredictableSeed: on x86/x86-64 try using RDRAND when there is no arc4random #7436

Merged
merged 1 commit into from Apr 16, 2020

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Apr 7, 2020

This enhancement is now possible (without being DMD-only) because LDC version 1.20.0 added support for data directives in DMD-style inline asm.

@n8sh n8sh requested a review from wilzbach as a code owner April 7, 2020 00:28
@dlang-bot
Copy link
Contributor

dlang-bot commented Apr 7, 2020

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
20723 enhancement std.random.unpredictableSeed: on x86/x86-64 try using RDRAND when there is no arc4random

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7436"

std/random.d Outdated
Comment on lines 1695 to 1697
// If we don't have arc4random and we don't have RDSEED fall back to this.
private ulong fallbackSeed() @nogc nothrow
{
Copy link
Member Author

Choose a reason for hiding this comment

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

This code was moved out of unpredictableSeed into its own function.

@n8sh
Copy link
Member Author

n8sh commented Apr 7, 2020

It might make sense to use RDRAND instead since it suffers less from contention. RDRAND is similar to macOS arc4random: it's an AES-based CPRNG that periodically reseeds itself. EDIT: RDRAND is also available on more machines than RDSEED.

@n8sh n8sh changed the title std.random.unpredictableSeed: on x86/x86-64 try using RDSEED when there is no arc4random std.random.unpredictableSeed: on x86/x86-64 try using RDRAND when there is no arc4random Apr 7, 2020
@n8sh n8sh force-pushed the issue-20723 branch 4 times, most recently from b23ae87 to 25da0cd Compare April 7, 2020 04:54
…ng RDRAND when there is no arc4random

This code works in both DMD and LDC because LDC version 1.20.0
added support for data directives in DMD-style inline asm.
@n8sh n8sh added 72h no objection -> merge The PR will be merged if there are no objections raised. auto-merge labels Apr 12, 2020
@dlang-bot dlang-bot merged commit be16aba into dlang:master Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
72h no objection -> merge The PR will be merged if there are no objections raised. auto-merge Enhancement
Projects
None yet
3 participants