Skip to content

Commit 82f35c5

Browse files
Rexicon226alexrp
authored andcommitted
add branchHint to std.Random.float
1 parent a68119f commit 82f35c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/std/Random.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,10 @@ pub fn float(r: Random, comptime T: type) T {
271271
const rand = r.int(u64);
272272
var rand_lz = @clz(rand);
273273
if (rand_lz >= 41) {
274-
// TODO: when #5177 or #489 is implemented,
275-
// tell the compiler it is unlikely (1/2^41) to reach this point.
276-
// (Same for the if branch and the f64 calculations below.)
274+
@branchHint(.unlikely);
277275
rand_lz = 41 + @clz(r.int(u64));
278276
if (rand_lz == 41 + 64) {
277+
@branchHint(.unlikely);
279278
// It is astronomically unlikely to reach this point.
280279
rand_lz += @clz(r.int(u32) | 0x7FF);
281280
}
@@ -297,6 +296,7 @@ pub fn float(r: Random, comptime T: type) T {
297296
const addl_rand_lz = @clz(r.int(u64));
298297
rand_lz += addl_rand_lz;
299298
if (addl_rand_lz != 64) {
299+
@branchHint(.likely);
300300
break;
301301
}
302302
if (rand_lz >= 1022) {

0 commit comments

Comments
 (0)