-
Notifications
You must be signed in to change notification settings - Fork 3
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
Use reverse_bits intrinsic when supported #16
Conversation
Does this provide a noticeable speed-up? |
Thinking about this a bit more: assuming this does give a useful speed-up (which I imagine it does, but we need to see numbers to be sure), wouldn't it be easier to use this automatically if |
6e6772b
to
0ff2269
Compare
There is a slight speed-up on my system, but it should be more noticeable on e.g. ARMv8 where there is CPU support.
Unfortunately, I don't know of a way to detect if a feature is available in 'normal' rust. There's ways to set a feature flag using a See also https://internals.rust-lang.org/t/setting-cfg-nightly-on-nightly-by-default/1893 |
What sort of speed-up did you see? And, assuming it's an improvement, why would we want to make this an opt-in feature? It feels like it should be something the user doesn't know about: it just makes their code go faster. |
4k ns to 3k or something. It's not that I wouldn't want to, it's just that I can't figure out how to do it (without 50 extra lines of code). |
1d653ae
to
f615b80
Compare
I must admit, for the complexity involved, I'm still wondering if we should just wait for this to stabilise. Admittedly, I'm not sure when it will stabilise. |
88d8c8f
to
7c1913b
Compare
7c1913b
to
e94b1bd
Compare
In the interests of not letting things languish without a decision forever I think we should say that we won't merge this unless it can be detected automatically (with |
That makes sense. Let's mark it WIP for now. |
OK, I'll close this, but of course you can reopen it if/when automatic detection works. |
Ok, I had some procrastination from writing on my master's thesis to do, so I implemented detection of nightly on top of the feature flags that are available. There's now a The The By the way, I recommend switching on the The number of builds is something we can talk about 😛. |
build.rs
Outdated
); | ||
|
||
// Set features depending on channel | ||
match version_meta().unwrap().channel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this better be if let Channel::Nightly = version_meta().unwrap().channel { ... } else { ... }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, especially relevant since we no longer handle the feature settings.
Cargo.toml
Outdated
@@ -20,3 +23,4 @@ rand = "0.5" | |||
[features] | |||
unsafe_internals = [] | |||
reverse_bits = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need reverse_bits
and no_reverse_bits
. Personally I'd delete both, and just silently use reverse bits; but if we really, really want an option I think no_reverse_bits
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted the features.
Are we not able to query rustc directly for whether the |
AFAIK, no. You could perhaps trail-compile something, but that seems way too much. That's why I included the |
@vext01 Do you know if you can query rustc for a feature directly? @thomwiggers If not, I agree your approach is reasonable. |
You mean like:
? https://doc.rust-lang.org/1.26.0/book/first-edition/conditional-compilation.html |
Not exactly. We'd like to detect when this feature https://doc.rust-lang.org/std/primitive.isize.html#method.reverse_bits is available or not (at the moment we assume "if we're on nightly, it's available", which might be a bit fragile). |
What do you want to do if it's not available? |
If it's not available, we have a fallback (slower) route that doesn't involve using the feature. |
OK, so it would look like this I think:
|
That only works for |
Ugh. That being the case, no idea then. Sorry. |
(I reckon that is a bug in rustc, why should compiler features be special?) |
The only other thing you can do is make a feature check in a build.rs, but that's horrible too. |
OK, then I think Thom's suggestion is as good as it gets. We can live with it. There are still a couple of other comments for @thomwiggers though :) |
.travis.yml
Outdated
@@ -1,13 +1,27 @@ | |||
language: rust | |||
|
|||
rust: | |||
- stable | |||
- beta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit, I'm not very sure it's useful for us to test on beta
. I know it doesn't hurt, but I feel a bit bad for using electricity for something that's probably never going to show an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good way to eliminate a lot of builds as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Cargo.toml
Outdated
@@ -19,3 +22,5 @@ rand = "0.5" | |||
|
|||
[features] | |||
unsafe_internals = [] | |||
reverse_bits = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these two lines supposed to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm somehow I missed them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you might be testing me :p
OK, I think this is ready to be squashed. |
b6ad9f8
to
fe810e8
Compare
It's been squashed by the way |
build.rs
Outdated
|
||
fn main() { | ||
assert!( | ||
!(env::var("CARGO_FEATURE_REVERSE_BITS").is_ok() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, this needs to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
fe810e8
to
7844496
Compare
Detect nightly and auto-enable reverse_bits
7844496
to
ef0d020
Compare
Thanks! |
This adds a new feature that allows to conditionally use the new
reverse_bits feature in Rust.