Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-09 Thread Hannes Frederic Sowa
Thanks for your detailed explanation! On Sun, Jun 8, 2014, at 13:48, George Spelvin wrote: > Thank you for your comments! > > > Have you checked assembler output if this helps anything at all? Constant > > propagation in the compiler should be able to figure that out all by > > itself. The only p

Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-08 Thread George Spelvin
Daniel Borkmann wrote: > On 06/08/2014 07:34 PM, Hannes Frederic Sowa wrote: >> Please check this as it makes the code more complicated and I doubt it is >> worth it. > > Agreed. Just to clarify, the goal is to be able to replace "prandom_u32() % range" all over the kernel with "prandom_u32_max(r

Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-08 Thread George Spelvin
Thank you for your comments! > Have you checked assembler output if this helps anything at all? Constant > propagation in the compiler should be able to figure that out all by > itself. The only places I use __builtin_constant_p today are where I > also make use of inline assembler. Yes, I did.

Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-08 Thread Daniel Borkmann
On 06/08/2014 07:34 PM, Hannes Frederic Sowa wrote: ... Please check this as it makes the code more complicated and I doubt it is worth it. Agreed. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo in

Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-08 Thread Hannes Frederic Sowa
On Sat, Jun 7, 2014, at 1:28, George Spelvin wrote: > diff --git a/include/linux/random.h b/include/linux/random.h > index 57fbbffd..e1f3ec9a 100644 > --- a/include/linux/random.h > +++ b/include/linux/random.h > @@ -47,11 +47,23 @@ void prandom_bytes_state(struct rnd_state *state, void > *buf, in

Re: [PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-08 Thread Daniel Borkmann
On 06/07/2014 10:28 AM, George Spelvin wrote: The multiply-and-shift is efficient in the general case, but slower than a simple bitwise AND if the range is a power of 2. Make the function handle this case so callers don't have to worry about micro-optimizing it. Signed-off-by: George Spelvin -

[PATCH 5/7] lib/random32.c: Make prandom_u32_max efficient for powers of 2

2014-06-07 Thread George Spelvin
The multiply-and-shift is efficient in the general case, but slower than a simple bitwise AND if the range is a power of 2. Make the function handle this case so callers don't have to worry about micro-optimizing it. Signed-off-by: George Spelvin --- include/linux/random.h | 14 +-