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

Drop unsafe code from next_u64 #963

Merged
merged 1 commit into from Apr 6, 2020
Merged

Conversation

Shnatsel
Copy link
Contributor

@Shnatsel Shnatsel commented Apr 4, 2020

A better version of #961. This produces identical assembly as the version with the unsafe code, since LLVM is smart enough to optimize this into a single load. I've just disassembled the entire binary with objdump and compared outputs so that I don't end up looking at the wrong function like last time.

Code used for testing:

use rand;
use rand::Rng;
use rand_hc::Hc128Rng;
use rand::SeedableRng;

fn main() {
    let mut rng: Hc128Rng = Hc128Rng::from_entropy();
    let value: u64 = rng.gen();
    println!("{}", value);
}

I have also confirmed that this particular path is exercised by my test code by inserting panic!() in the function and observing that my test code does indeed panic.

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

Thanks @Shnatsel. LGTM and I don't recall why we did this in the first place. It may be that an earlier compiler wasn't so good at optimising?

@Shnatsel
Copy link
Contributor Author

Shnatsel commented Apr 5, 2020

git blame led me to a huge commit moving code around, so I couldn't find the original reasoning. However, I've tested Rust 1.32 (current MSRV) and it does optimize this correctly.

@dhardy
Copy link
Member

dhardy commented Apr 6, 2020

Lets go with this then. Thanks again for the fixes @Shnatsel!

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.

None yet

2 participants