Uh oh!
There was an error while loading. Please reload this page.
Make some std::intrinsics const fns - #51171
Conversation
rust-highfive
commented
May 29, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
leonardo-m
commented
May 29, 2018
Eventually I'd like log/sin/cos too const. |
oli-obk
left a comment
There was a problem hiding this comment.
These are inherently unstable, so there's nothing wrong with making these const except if they were somehow exposed by macros.
There was a problem hiding this comment.
@eddyb I know you dislike these kinds of matches. We could probably do all the ops on u128 and modify the result depending on the type's bitwidth, but that feels fragile
There was a problem hiding this comment.
let extra = 128 - bits;
ctpop(x) = x.count_ones()ctlz(x) = x.leading_zeros() - extracttz(x) = (x << extra).trailing_zeros() - extrabswap(x) = (x << extra).swap_bytes()
There was a problem hiding this comment.
I agree the code can probably be written a bit nicer. Looking into it. Will push as soon as I have the time.
oli-obk
commented
May 29, 2018
@leonardo-m I suggest you open a PR for those intrinsics then ;) |
eddyb
commented
May 29, 2018
We can't do that because we don't have an soft-float ( |
oli-obk
commented
May 31, 2018
@bors r+ |
bors
commented
May 31, 2018
📌 Commit 3fefa96 has been approved by |
bors
commented
May 31, 2018
🔒 Merge conflict |
There was a problem hiding this comment.
If anything, I'd call these bits, not bytes.
There was a problem hiding this comment.
Ok. I agree. Matches better with the field same in Scalar as well. Pushed a rename.
3fefa96 to
0d7d5e9Comparefaern
commented
May 31, 2018
Fixed the merge conflict by rebasing. |
oli-obk
commented
May 31, 2018
@bors r+ |
bors
commented
May 31, 2018
📌 Commit 97a0d46 has been approved by |
bors
commented
Jun 1, 2018
Make some std::intrinsics `const fn`s Making some rustc intrinsics (`ctpop`, `cttz`, `ctlz` and `bswap`) `const fn`s. This is a pre-step to being able to make `swap_bytes`, `to_be` and `from_be` constant functions. That in itself could be ergonomic and useful. But even better is that it would allow `Ipv4Addr::new` etc becoming `const fn`s as well. Which might be really useful since I find it quite common to want to define them as constants. r? @oli-obk
bors
commented
Jun 1, 2018
☀️ Test successful - status-appveyor, status-travis |
const fn integer operations A follow up to rust-lang#51171Fixesrust-lang#51267 Makes a lot of the integer methods (`swap_bytes`, `count_ones` etc) `const fn`s. See rust-lang#51267 for a discussion about why this is wanted and the solution used.
Making some rustc intrinsics (
ctpop,cttz,ctlzandbswap)const fns.This is a pre-step to being able to make
swap_bytes,to_beandfrom_beconstant functions. That in itself could be ergonomic and useful. But even better is that it would allowIpv4Addr::newetc becomingconst fns as well. Which might be really useful since I find it quite common to want to define them as constants.r? @oli-obk