-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Update documentation for cold_path, likely, and unlikely
#151612
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
Other hints have a note recommending benchmarks to ensure they actually do what is intended. This is also applicable for `cold_path`, so add a note here.
bea3ff7 to
bdf5790
Compare
cold_pathcold_path, likely, and unlikely
|
@bors r+ rollup |
| /// #[inline(always)] | ||
| /// pub const fn likely(b: bool) -> bool { | ||
| /// if b { | ||
| /// true | ||
| /// } else { | ||
| /// cold_path(); | ||
| /// false | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// #[inline(always)] | ||
| /// pub const fn unlikely(b: bool) -> bool { | ||
| /// if b { | ||
| /// cold_path(); | ||
| /// true | ||
| /// } else { | ||
| /// false | ||
| /// } | ||
| /// } |
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.
| /// #[inline(always)] | |
| /// pub const fn likely(b: bool) -> bool { | |
| /// if b { | |
| /// true | |
| /// } else { | |
| /// cold_path(); | |
| /// false | |
| /// } | |
| /// } | |
| /// | |
| /// #[inline(always)] | |
| /// pub const fn unlikely(b: bool) -> bool { | |
| /// if b { | |
| /// cold_path(); | |
| /// true | |
| /// } else { | |
| /// false | |
| /// } | |
| /// } | |
| /// #[inline(always)] | |
| /// pub const fn likely(b: bool) -> bool { | |
| /// if !b { | |
| /// cold_path(); | |
| /// } | |
| /// b | |
| /// } | |
| /// | |
| /// #[inline(always)] | |
| /// pub const fn unlikely(b: bool) -> bool { | |
| /// if b { | |
| /// cold_path(); | |
| /// } | |
| /// b | |
| /// } |
Or is there a reason to prefer the less-tight factoring?
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.
Nope, this is just our implementation in intrinsics. I’ll apply this.
|
@bors r- For a chance to apply TC’s suggestion |
|
Commit bdf5790 has been unapproved. |
These were split from the `cold_path` tracking issue.
bdf5790 to
6c0ae93
Compare
Update documentation for `cold_path`, `likely`, and `unlikely` * Add a note recommending benchmarks to `cold_path`, as other hints have * Note that `cold_path` can be used to implement `likely` and `unlikely` * Update the tracking issue for the `likely_unlikely` feature Tracking issue: rust-lang#136873 Tracking issue: rust-lang#151619
Rollup merge of #151612 - tgross35:cold-path-doc, r=scottmcm Update documentation for `cold_path`, `likely`, and `unlikely` * Add a note recommending benchmarks to `cold_path`, as other hints have * Note that `cold_path` can be used to implement `likely` and `unlikely` * Update the tracking issue for the `likely_unlikely` feature Tracking issue: #136873 Tracking issue: #151619
cold_path, as other hints havecold_pathcan be used to implementlikelyandunlikelylikely_unlikelyfeatureTracking issue: #136873
Tracking issue: #151619