-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Tracking Issue for bool::select_unpredictable
#133962
Comments
Reading through the ACP it seems like the justification for having this on If there is objection to (sorry for the nonsensical email, accidentally submitted before I was done writing) |
I would prefer a builtin branch_hint function as the first statement in a branch like in Zig. |
For likely/unlikely, such intrinsic(s) are under discussion at rust-lang/libs-team#510. In contrast, the motivation for |
…oss35 core: implement `bool::select_unpredictable` Tracking issue: rust-lang#133962 ACP: rust-lang/libs-team#468
Rollup merge of rust-lang#133964 - joboet:select_unpredictable, r=tgross35 core: implement `bool::select_unpredictable` Tracking issue: rust-lang#133962 ACP: rust-lang/libs-team#468
I'm personally inclined to move this to |
This is a good point. It would also be inconsistent with a "non-unpredictable" |
…oss35 core: implement `bool::select_unpredictable` Tracking issue: rust-lang#133962 ACP: rust-lang/libs-team#468
In #139726 I argue for moving this to |
… r=dtolnay Move `select_unpredictable` to the `hint` module There has been considerable discussion in both the ACP (rust-lang/libs-team#468) and tracking issue (rust-lang#133962) about whether the `bool::select_unpredictable` method should be in `core::hint` instead. I believe this is the right move for the following reasons: - The documentation explicitly says that it is a hint, not a codegen guarantee. - `bool` doesn't have a corresponding `select` method, and I don't think we should be adding one. - This shouldn't be something that people reach for with auto-completion unless they specifically understand the interactions with branch prediction. Using conditional moves can easily make code *slower* by preventing the CPU from speculating past the condition due to the data dependency. - Although currently `core::hint` only contains no-ops, this isn't a hard rule (for example `unreachable_unchecked` is a bit of a gray area). The documentation only status that the module contains "hints to compiler that affects how code should be emitted or optimized". This is consistent with what `select_unpredictable` does.
… r=dtolnay Move `select_unpredictable` to the `hint` module There has been considerable discussion in both the ACP (rust-lang/libs-team#468) and tracking issue (rust-lang#133962) about whether the `bool::select_unpredictable` method should be in `core::hint` instead. I believe this is the right move for the following reasons: - The documentation explicitly says that it is a hint, not a codegen guarantee. - `bool` doesn't have a corresponding `select` method, and I don't think we should be adding one. - This shouldn't be something that people reach for with auto-completion unless they specifically understand the interactions with branch prediction. Using conditional moves can easily make code *slower* by preventing the CPU from speculating past the condition due to the data dependency. - Although currently `core::hint` only contains no-ops, this isn't a hard rule (for example `unreachable_unchecked` is a bit of a gray area). The documentation only status that the module contains "hints to compiler that affects how code should be emitted or optimized". This is consistent with what `select_unpredictable` does.
Rollup merge of rust-lang#139726 - Amanieu:select_unpredictable_hint, r=dtolnay Move `select_unpredictable` to the `hint` module There has been considerable discussion in both the ACP (rust-lang/libs-team#468) and tracking issue (rust-lang#133962) about whether the `bool::select_unpredictable` method should be in `core::hint` instead. I believe this is the right move for the following reasons: - The documentation explicitly says that it is a hint, not a codegen guarantee. - `bool` doesn't have a corresponding `select` method, and I don't think we should be adding one. - This shouldn't be something that people reach for with auto-completion unless they specifically understand the interactions with branch prediction. Using conditional moves can easily make code *slower* by preventing the CPU from speculating past the condition due to the data dependency. - Although currently `core::hint` only contains no-ops, this isn't a hard rule (for example `unreachable_unchecked` is a bit of a gray area). The documentation only status that the module contains "hints to compiler that affects how code should be emitted or optimized". This is consistent with what `select_unpredictable` does.
Feature gate:
#![feature(select_unpredictable)]
This is a tracking issue for
bool::select_unpredictable
, which selects between two values and hints to the optimizer that it should try to generate branchless code.Public API
Steps / History
bool::select_unpredictable
#133964Unresolved Questions
const
, right?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: