Skip to content

use @branchHint in std.Random.float #22221

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

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/std/Random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,10 @@ pub fn float(r: Random, comptime T: type) T {
const rand = r.int(u64);
var rand_lz = @clz(rand);
if (rand_lz >= 41) {
// TODO: when #5177 or #489 is implemented,
// tell the compiler it is unlikely (1/2^41) to reach this point.
// (Same for the if branch and the f64 calculations below.)
@branchHint(.unlikely);
rand_lz = 41 + @clz(r.int(u64));
if (rand_lz == 41 + 64) {
@branchHint(.unlikely);
// It is astronomically unlikely to reach this point.
rand_lz += @clz(r.int(u32) | 0x7FF);
}
Expand All @@ -297,6 +296,7 @@ pub fn float(r: Random, comptime T: type) T {
const addl_rand_lz = @clz(r.int(u64));
rand_lz += addl_rand_lz;
if (addl_rand_lz != 64) {
@branchHint(.likely);
break;
}
if (rand_lz >= 1022) {
Expand Down
Loading