Re: ALIGN (Re: [PATCH] Fix get_order())

2007-03-09 Thread Oleg Verych
On Fri, Mar 09, 2007 at 03:15:10PM -0800, Linus Torvalds wrote: > > > On Sat, 10 Mar 2007, Oleg Verych wrote: > > > > OTOH, if i would write it this way > > > > #define BALIGN(x,bits) x) >> (bits)) + 1) << (bits)) > > But that's *wrong*. It aligns something that is *already* aligned t

Re: ALIGN (Re: [PATCH] Fix get_order())

2007-03-09 Thread Linus Torvalds
On Sat, 10 Mar 2007, Oleg Verych wrote: > > OTOH, if i would write it this way > > #define BALIGN(x,bits) x) >> (bits)) + 1) << (bits)) But that's *wrong*. It aligns something that is *already* aligned to something else. So you'd have to do it as something like #define ALIG

Re: ALIGN (Re: [PATCH] Fix get_order())

2007-03-09 Thread Oleg Verych
On Wed, Mar 07, 2007 at 08:38:27AM -0800, Linus Torvalds wrote: > > > On Wed, 7 Mar 2007, Oleg Verych wrote: > > > > Probably it can be used to get rid of gccisms and "type fluff" due to > > bitwise arithmetics in ALIGN? > > Hell no. > > The typeof is there to make sure we have the right type,

Re: ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order())

2007-03-07 Thread Linus Torvalds
On Wed, 7 Mar 2007, Oleg Verych wrote: > > GCC's assembler version of this macro is optimized as needed. Not fora non-constant mask, I bet. > But i wanted to address Al's statement about using typeof(): Well, that doesn't affect ALIGN(), since you can only use ALIGN() on an arithmetic type a

Re: ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order())

2007-03-07 Thread Oleg Verych
On Wed, Mar 07, 2007 at 08:38:27AM -0800, Linus Torvalds wrote: > > > On Wed, 7 Mar 2007, Oleg Verych wrote: > > > > Probably it can be used to get rid of gccisms and "type fluff" due to > > bitwise arithmetics in ALIGN? > > Hell no. > > The typeof is there to make sure we have the right type,

Re: ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order())

2007-03-07 Thread Linus Torvalds
On Wed, 7 Mar 2007, Oleg Verych wrote: > > Probably it can be used to get rid of gccisms and "type fluff" due to > bitwise arithmetics in ALIGN? Hell no. The typeof is there to make sure we have the right type, and it's simple. The current ALIGN() macro is efficient as hell (generating just a

ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order())

2007-03-07 Thread Oleg Verych
> From: David Howells > Newsgroups: gmane.linux.kernel > Subject: Re: [PATCH] Fix get_order() > Date: Wed, 07 Mar 2007 11:43:06 + > [] > Various archs (including i386, x86_64, powerpc and frv) have instructions that > can be used to calculate integer log2(N). > Probab

Re: [PATCH] Fix get_order()

2007-03-07 Thread David Howells
Linus Torvalds <[EMAIL PROTECTED]> wrote: > > +#define ilog2_up(n) ((n) == 1 ? 0 : ilog2((n) - 1) + 1) > > This is wrong. It uses "n" twice, which makes it unsafe as a macro. Damn. I missed that. > Or it could use a "__builtin_constant_p()" (which gcc defines to not have > side effects) to al

Re: [PATCH] Fix get_order()

2007-03-06 Thread Linus Torvalds
On Tue, 6 Mar 2007, David Howells wrote: > /** > + * ilog2_up - rounded up log of base 2 of 32-bit or a 64-bit unsigned value > + * @n - parameter > + * > + * constant-capable log of base 2 calculation > + * - this can be used to initialise global variables from constant data, > hence > + * t

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread David Howells
Alexey Dobriyan <[EMAIL PROTECTED]> wrote: > > #if BITS_PER_LONG == 32 && defined(ARCH_HAS_ILOG2_U32) > > There is no such thing except on FRV, where it's redundant. Redundant in what way? > CONFIG_ARCH_HAS_ILOG2_U32 > ^^^

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread Alexey Dobriyan
On Tue, Mar 06, 2007 at 06:34:26PM +, David Howells wrote: > Provide an ilog2_up() that rounds its result up (ilog2() rounds down). > > Fix get_order() to use ilog2_up() not ilog2() to get the correct rounding. > > Adjust the documentation surrounding ilog2() and co. to indicate what rounding >

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread H. Peter Anvin
David Howells wrote: H. Peter Anvin <[EMAIL PROTECTED]> wrote: Why not just make it ((n) < 1 ? 0 : ...) and make it well-defined for n == 0? Because log2(0) is -INF or mathematically undefined or something isn't it? Yes, but it's a *rounding up* function. In this case, it makes sense to r

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread David Howells
H. Peter Anvin <[EMAIL PROTECTED]> wrote: > Why not just make it ((n) < 1 ? 0 : ...) and make it well-defined for > n == 0? Because log2(0) is -INF or mathematically undefined or something isn't it? David - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a

Re: [PATCH] Fix get_order()

2007-03-06 Thread David Howells
Linus Torvalds <[EMAIL PROTECTED]> wrote: > That seems bogus. "n == 1" should give "0", no? Sigh. No. The comment header says it all: /** * roundup_pow_of_two - round the given value up to nearest power of two * @n - parameter * * round the given val

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread David Howells
H. Peter Anvin <[EMAIL PROTECTED]> wrote: > Eh? roundup_pow_of_two(1) should be 0; 2^0 = 1. Nonono. roundup_pow_of_two(0) => ? roundup_pow_of_two(1) => 1 roundup_pow_of_two(2) => 2 roundup_pow_of_two(3) => 4 roundup_pow_of_two(4) => 4 roundup_

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread H. Peter Anvin
David Howells wrote: /** + * ilog2_up - rounded up log of base 2 of 32-bit or a 64-bit unsigned value + * @n - parameter + * + * constant-capable log of base 2 calculation + * - this can be used to initialise global variables from constant data, hence + * the massive ternary operator constru

Re: [PATCH] Fix get_order()

2007-03-06 Thread Linus Torvalds
On Tue, 6 Mar 2007, David Howells wrote: > @@ -159,8 +175,8 @@ unsigned long __roundup_pow_of_two(unsigned long n) > #define roundup_pow_of_two(n)\ > (\ > __builtin_constant_p(n) ? ( \ > - (n == 1)

Re: [PATCH] Fix get_order() [try #2]

2007-03-06 Thread H. Peter Anvin
David Howells wrote: From: David Howells <[EMAIL PROTECTED]> Provide an ilog2_up() that rounds its result up (ilog2() rounds down). Fix get_order() to use ilog2_up() not ilog2() to get the correct rounding. Adjust the documentation surrounding ilog2() and co. to indicate what rounding they per

[PATCH] Fix get_order() [try #2]

2007-03-06 Thread David Howells
From: David Howells <[EMAIL PROTECTED]> Provide an ilog2_up() that rounds its result up (ilog2() rounds down). Fix get_order() to use ilog2_up() not ilog2() to get the correct rounding. Adjust the documentation surrounding ilog2() and co. to indicate what rounding they perform. Fix roundup_pow_

Re: [PATCH] Fix get_order()

2007-03-06 Thread David Howells
H. Peter Anvin <[EMAIL PROTECTED]> wrote: > if (size <= (1UL << page_shift)) > return 0; > else > return __ilog2_u32(size-1)+1-page_shift; I think you're right. That'll also defend against the result of __ilog2_u32() being less than page_shift-1. I think

Re: [PATCH] Fix get_order()

2007-03-06 Thread H. Peter Anvin
David Howells wrote: From: David Howells <[EMAIL PROTECTED]> Fix get_order() to use ilog2() properly. Signed-Off-By: David Howells <[EMAIL PROTECTED]> --- include/asm-generic/page.h | 14 +++--- include/linux/log2.h | 20 ++-- 2 files changed, 29 insertions(+

[PATCH] Fix get_order()

2007-03-06 Thread David Howells
From: David Howells <[EMAIL PROTECTED]> Fix get_order() to use ilog2() properly. Signed-Off-By: David Howells <[EMAIL PROTECTED]> --- include/asm-generic/page.h | 14 +++--- include/linux/log2.h | 20 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff