Lines Matching full:ceil

53 u32 __get_random_u32_below(u32 ceil);
56 * Returns a random integer in the interval [0, ceil), with uniform
57 * distribution, suitable for all uses. Fastest when ceil is a constant, but
58 * still fast for variable ceil as well.
60 static inline u32 get_random_u32_below(u32 ceil) in get_random_u32_below() argument
62 if (!__builtin_constant_p(ceil)) in get_random_u32_below()
63 return __get_random_u32_below(ceil); in get_random_u32_below()
66 * For the fast path, below, all operations on ceil are precomputed by in get_random_u32_below()
71 * whose lower half would indicate a range indivisible by ceil. in get_random_u32_below()
73 BUILD_BUG_ON_MSG(!ceil, "get_random_u32_below() must take ceil > 0"); in get_random_u32_below()
74 if (ceil <= 1) in get_random_u32_below()
77 if (ceil <= 1U << 8) { in get_random_u32_below()
78 u32 mult = ceil * get_random_u8(); in get_random_u32_below()
79 if (likely(is_power_of_2(ceil) || (u8)mult >= (1U << 8) % ceil)) in get_random_u32_below()
81 } else if (ceil <= 1U << 16) { in get_random_u32_below()
82 u32 mult = ceil * get_random_u16(); in get_random_u32_below()
83 if (likely(is_power_of_2(ceil) || (u16)mult >= (1U << 16) % ceil)) in get_random_u32_below()
86 u64 mult = (u64)ceil * get_random_u32(); in get_random_u32_below()
87 if (likely(is_power_of_2(ceil) || (u32)mult >= -ceil % ceil)) in get_random_u32_below()
106 * Returns a random integer in the interval [floor, ceil], with uniform
107 * distribution, suitable for all uses. Fastest when floor and ceil are
108 * constant, but still fast for variable floor and ceil as well.
110 static inline u32 get_random_u32_inclusive(u32 floor, u32 ceil) in get_random_u32_inclusive() argument
112 BUILD_BUG_ON_MSG(__builtin_constant_p(floor) && __builtin_constant_p(ceil) && in get_random_u32_inclusive()
113 (floor > ceil || ceil - floor == U32_MAX), in get_random_u32_inclusive()
114 "get_random_u32_inclusive() must take floor <= ceil"); in get_random_u32_inclusive()
115 return floor + get_random_u32_below(ceil - floor + 1); in get_random_u32_inclusive()