Skip to content

Commit

Permalink
add branchHint to std.Random.float
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 authored and alexrp committed Dec 13, 2024
1 parent a68119f commit 82f35c5
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit 82f35c5

Please sign in to comment.