lkml.org 
[lkml]   [2022]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 3/3] treewide: use get_random_u32_between() when possible
On Thu, Nov 17, 2022 at 12:55:47AM +0100, Jason A. Donenfeld wrote:
> 1) How/whether to make f(0, UR2_MAX) safe,
> - without additional 64-bit arithmetic,
> - minimizing the number of branches.
> I have a few ideas I'll code golf for a bit.
> I think I can make progress with (1) alone by fiddling around with
> godbolt enough, like usual.

The code gen is definitely worse.

Original half-open interval:

return floor + get_random_u32_below(ceil - floor);

Suggested fully closed interval:

ceil = ceil - floor + 1;
return likely(ceil) ? floor + get_random_u32_below(ceil) : get_random_u32();

Is the worse code gen actually worth it? Options:

a) Decide worse codegen is worth it.
b) Declare f(0, U32_MAX) undefined and just not handle it.
c) Stick with original half-open interval that doesn't have this problem.

Jason

\
 
 \ /
  Last update: 2022-11-17 03:06    [W:0.233 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site