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

Make modint::Barrett (AtomicU32, AtomicU64) #71

Merged
merged 4 commits into from
Oct 18, 2020

Conversation

qryxip
Copy link
Member

@qryxip qryxip commented Oct 5, 2020

Copy link
Collaborator

@koba-e964 koba-e964 left a comment

Choose a reason for hiding this comment

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

I'm not sure this PR is implemented as intended, but getting nearly 2x faster by AtomicXX is something I never dreamed of. Great!

@qryxip
Copy link
Member Author

qryxip commented Oct 8, 2020

In fact I didn't intend performance improvement. Or rather I wanted to know how much it decreases. I was thinking that we should write some document to prevent users from doing this:

use std::{panic, thread};

ModInt::set_modulus(m);

thread::Builder::new()
    .stack_size(16 * 1024 * 1024)
    .spawn(|| {
        todo!();
    })
    .unwrap()
    .join()
    .unwrap_or_else(panic::resume_unwind);

@qryxip
Copy link
Member Author

qryxip commented Oct 8, 2020

I've just found there's almost no overhead compared with this:

pub struct Barrett(UnsafeCell<BarrettInner>);

struct BarrettInner {
    m: u32,
    im: u64,
}

/// # Safety
///
/// Nothing. Do not ever do this.
unsafe impl Sync for Barrett {}

@qryxip qryxip merged commit a8c306d into rust-lang-ja:master Oct 18, 2020
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