commit 82f35c51866826fb71eb6f27d9210bb738d602e9 (tree)
parent a68119f8f1d54b70e713e1e8ce07491ddba0f093
Author: David Rubin <daviru007@icloud.com>
Date: Thu, 12 Dec 2024 18:23:48 -0800
add branchHint to `std.Random.float`
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/std/Random.zig b/lib/std/Random.zig
@@ -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);
}
@@ -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) {