Re: [PATCH] Fix get_order()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: <akpm@...>, <benh@...>, <linux-kernel@...>, <hpa@...>, <johannes@...>
Date: Wednesday, March 7, 2007 - 7:43 am

Linus Torvalds <torvalds@linux-foundation.org> wrote:


Damn.  I missed that.


I should have, yes.


I'd rather not do that as the inline assembly variants then have to special
case ilog2(0) rather than just having an undefined result.


Unfortunately, I can't disagree.


It was tested...  I've just re-examined my test program and I've realised I've
only tested power-of-2 parameters.  Sigh.


Well, that should be CONFIG_ARCH_HAS_ILOG2_U?? macros, and powerpc defines
those too.


True, for N being a non-power-of-two, unfortunately; and also where evaluating
N has side-effects.


Not true, just that my userspace test program isn't sufficiently exhaustive.


Unfortunately so.


Not true.

Various archs (including i386, x86_64, powerpc and frv) have instructions that
can be used to calculate integer log2(N).  The fallback position is to use a
loop:

	size = (size - 1) >> (PAGE_SHIFT - 1);
	order = -1;
	do {
		size >>= 1;
		order++;
	} while (size);


Probably a good idea.  I'll work on it some more and improve my test program
(which is actually quite simple to do).

David
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Fix get_order(), David Howells, (Tue Mar 6, 1:39 pm)
Re: [PATCH] Fix get_order(), Linus Torvalds, (Tue Mar 6, 11:28 pm)
Re: [PATCH] Fix get_order() , David Howells, (Wed Mar 7, 7:43 am)
Re: ALIGN, Oleg Verych, (Sat Mar 10, 4:01 am)
Re: ALIGN (Re: [PATCH] Fix get_order()), Oleg Verych, (Fri Mar 9, 7:13 pm)
Re: ALIGN (Re: [PATCH] Fix get_order()), Linus Torvalds, (Fri Mar 9, 7:15 pm)
Re: ALIGN (Re: [PATCH] Fix get_order()), Oleg Verych, (Fri Mar 9, 8:31 pm)
Re: [PATCH] Fix get_order(), Linus Torvalds, (Tue Mar 6, 2:41 pm)
Re: [PATCH] Fix get_order() , David Howells, (Tue Mar 6, 2:51 pm)
Re: [PATCH] Fix get_order(), H. Peter Anvin, (Tue Mar 6, 1:58 pm)
Re: [PATCH] Fix get_order() , David Howells, (Tue Mar 6, 2:21 pm)