Lines Matching defs: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)
62 if (!__builtin_constant_p(ceil))
63 return __get_random_u32_below(ceil);
66 * For the fast path, below, all operations on ceil are precomputed by
71 * whose lower half would indicate a range indivisible by ceil.
73 BUILD_BUG_ON_MSG(!ceil, "get_random_u32_below() must take ceil > 0");
74 if (ceil <= 1)
77 if (ceil <= 1U << 8) {
78 u32 mult = ceil * get_random_u8();
79 if (likely(is_power_of_2(ceil) || (u8)mult >= (1U << 8) % ceil))
81 } else if (ceil <= 1U << 16) {
82 u32 mult = ceil * get_random_u16();
83 if (likely(is_power_of_2(ceil) || (u16)mult >= (1U << 16) % ceil))
86 u64 mult = (u64)ceil * get_random_u32();
87 if (likely(is_power_of_2(ceil) || (u32)mult >= -ceil % ceil))
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)
112 BUILD_BUG_ON_MSG(__builtin_constant_p(floor) && __builtin_constant_p(ceil) &&
113 (floor > ceil || ceil - floor == U32_MAX),
114 "get_random_u32_inclusive() must take floor <= ceil");
115 return floor + get_random_u32_below(ceil - floor + 1);