@@ -256,12 +256,12 @@ pub const Random = struct {
256
256
// If all 41 bits are zero, generate additional random bits, until a
257
257
// set bit is found, or 126 bits have been generated.
258
258
const rand = r .int (u64 );
259
- var rand_lz = @clz (u64 , rand | 0x7FFFFF );
260
- if (rand_lz = = 41 ) {
259
+ var rand_lz = @clz (u64 , rand );
260
+ if (rand_lz > = 41 ) {
261
261
// TODO: when #5177 or #489 is implemented,
262
262
// tell the compiler it is unlikely (1/2^41) to reach this point.
263
263
// (Same for the if branch and the f64 calculations below.)
264
- rand_lz += @clz (u64 , r .int (u64 ));
264
+ rand_lz = 41 + @clz (u64 , r .int (u64 ));
265
265
if (rand_lz == 41 + 64 ) {
266
266
// It is astronomically unlikely to reach this point.
267
267
rand_lz += @clz (u32 , r .int (u32 ) | 0x7FF );
@@ -276,8 +276,9 @@ pub const Random = struct {
276
276
// If all 12 bits are zero, generate additional random bits, until a
277
277
// set bit is found, or 1022 bits have been generated.
278
278
const rand = r .int (u64 );
279
- var rand_lz : u64 = @clz (u64 , rand | 0xFFFFFFFFFFFFF );
280
- if (rand_lz == 12 ) {
279
+ var rand_lz : u64 = @clz (u64 , rand );
280
+ if (rand_lz >= 12 ) {
281
+ rand_lz = 12 ;
281
282
while (true ) {
282
283
// It is astronomically unlikely for this loop to execute more than once.
283
284
const addl_rand_lz = @clz (u64 , r .int (u64 ));
0 commit comments