public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, akpm@osdl.org, benh@kernel.crashing.org,
	linux-kernel@vger.kernel.org, johannes@sipsolutions.net
Subject: Re: [PATCH] Fix get_order()
Date: Tue, 06 Mar 2007 09:58:32 -0800	[thread overview]
Message-ID: <45EDABC8.8040901@zytor.com> (raw)
In-Reply-To: <20070306173929.2708.37191.stgit@warthog.cambridge.redhat.com>

David Howells wrote:
> From: David Howells <dhowells@redhat.com>
> 
> Fix get_order() to use ilog2() properly.
> 
> Signed-Off-By: David Howells <dhowells@redhat.com>
> ---
> 
>  include/asm-generic/page.h |   14 +++++++++++---
>  include/linux/log2.h       |   20 ++++++++++++++++++--
>  2 files changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
> index b55052c..c37571d 100644
> --- a/include/asm-generic/page.h
> +++ b/include/asm-generic/page.h
> @@ -17,10 +17,18 @@ static inline __attribute__((const))
>  int __get_order(unsigned long size, int page_shift)
>  {
>  #if BITS_PER_LONG == 32 && defined(ARCH_HAS_ILOG2_U32)
> -	int order = __ilog2_u32(size) - page_shift;
> +	int order;
> +	if (size <= 1)
> +		order = 0;
> +	else
> +		order = __ilog2_u32(size - 1) + 1 - page_shift;
>  	return order >= 0 ? order : 0;

This seems a lot more complex than it should be.

Assuming page_shift is usually constant, it would seem to make more 
sense to do:

	if (size <= (1UL << page_shift))
		return 0;
	else
		return __ilog2_u32(size-1)+1-page_shift;

... instead of having *two* conditionals...

	-hpa

  reply	other threads:[~2007-03-06 18:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-06 17:39 [PATCH] Fix get_order() David Howells
2007-03-06 17:58 ` H. Peter Anvin [this message]
2007-03-06 18:21   ` David Howells
2007-03-06 18:41 ` Linus Torvalds
2007-03-06 18:51   ` David Howells
2007-03-07  3:28 ` Linus Torvalds
2007-03-07 11:43   ` David Howells
2007-03-07 16:02     ` ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order()) Oleg Verych
2007-03-07 16:38       ` Linus Torvalds
2007-03-07 17:24         ` Oleg Verych
2007-03-07 18:05           ` Linus Torvalds
2007-03-09 23:13         ` ALIGN " Oleg Verych
2007-03-09 23:15           ` Linus Torvalds
2007-03-10  0:31             ` Oleg Verych
2007-03-10  8:01         ` ALIGN Oleg Verych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45EDABC8.8040901@zytor.com \
    --to=hpa@zytor.com \
    --cc=akpm@osdl.org \
    --cc=benh@kernel.crashing.org \
    --cc=dhowells@redhat.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox