-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use the least significant beat to determine if int/uint is even #11568
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
Conversation
I'm curious, but have you verified that the generated code is actually better? I would expect LLVM to do proper inlining and figure everything out. Regardless, the documentation shouldn't change, just the implementation, but thanks for the patch! |
I didn't verify the generated code, I could check with Why shouldn't the documentation change? It's not verifying the number is divisible by 2 anymore :/ |
Maybe not the best test. TBH, not sure what the best test is.
use std::num;
fn main() {
2u & 1 == 0;
2u.is_even();
} |
@flaper87 It still checks that the number is divisible by |
Interesting! Then, let me trash this patch! Thanks! 😄 |
I misunderstood @adridu59's comment. He was referring to the documentation. |
@flaper87 It looks like llvm eliminated all of your test since the results were unused. You probably need to print the output or something. |
This is the full output of the emit. http://pastebin.mozilla.org/4022063 And the test use std::num;
fn main() {
let a = 2u & 1 == 0;
let b = 2u.is_even();
println!("{}", a);
println!("{}", b);
} |
Still not convinced that this test is representative of the comparison we're looking for. |
Before: After: |
From the tests it appears they optimize to exactly the same thing, so LLVM is definitely doing its job. When running tests at O0, however, I imagine that and-ing with 1 is faster, so I'm gonna go ahead and r+ this. Thanks for the patch and the good investigation! |
This implementation should be a bit more optimal than calling `self.is_multiple_of(&2)`
ignore lower-camel-case words in `doc_markdown` This fixes rust-lang#11568 by ignoring camelCase words starting with a lower case letter. r? `@blyxyas` --- changelog: none
This implementation should be a bit more optimal than calling
self.is_multiple_of(&2)