public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Maksym Planeta <mcsim.planeta@gmail.com>
To: mingo@redhat.com
Cc: kernel-janitors@vger.kernel.org, namhyung@gmail.com,
	linux-kernel@vger.kernel.org,
	Maksym Planeta <mcsim.planeta@gmail.com>
Subject: [PATCH v2] x86: page: get_order() optimization
Date: Sun, 27 Mar 2011 08:45:56 +0000	[thread overview]
Message-ID: <1301215556-8898-1-git-send-email-mcsim.planeta@gmail.com> (raw)

For x86 architecture get_order function can be optimized due to
assembler instruction bsr.

This is second version of patch where for constants gcc precompute the
result.

Signed-off-by: Maksym Planeta <mcsim.planeta@gmail.com>
---
 arch/x86/include/asm/getorder.h |   48 +++++++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/page.h     |    2 +-
 2 files changed, 49 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/include/asm/getorder.h

diff --git a/arch/x86/include/asm/getorder.h b/arch/x86/include/asm/getorder.h
new file mode 100644
index 0000000..b0c6f57
--- /dev/null
+++ b/arch/x86/include/asm/getorder.h
@@ -0,0 +1,48 @@
+#ifndef __ASM_GENERIC_GETORDER_H
+#define __ASM_GENERIC_GETORDER_H
+
+#ifndef __ASSEMBLY__
+
+#include <linux/compiler.h>
+
+#ifdef CONFIG_X86_CMOV
+#define ASM_CMOVZ(op, dest) \
+		"cmovzl %" #op ",%" #dest ";\n\t"
+#else
+#define ASM_CMOVZ(op, dest) \
+		"jnz 1f;\n\t" \
+		"movl %" #op ", %" #dest ";\n\t" \
+		"1: "
+#endif
+
+static __always_inline int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size - 1) >> (PAGE_SHIFT - 1);
+	asm("bsr %1, %0\n\t"
+		ASM_CMOVZ(2, 0)
+		: "=&r" (order) : "rm" (size), "rm" (0));
+	return order;
+}
+
+/* Pure 2^n version of get_order */
+static inline __attribute_const__  int get_order(unsigned long size)
+{
+	int order;
+
+	if (__builtin_constant_p(size)) {
+		size = (size - 1) >> (PAGE_SHIFT - 1);
+		order = -1;
+		do {
+			size >>= 1;
+			order++;
+		} while (size);
+		return order;
+	}
+	return __get_order(size);
+}
+
+#endif	/* __ASSEMBLY__ */
+
+#endif	/* __ASM_GENERIC_GETORDER_H */
diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
index 8ca8283..10e4c45 100644
--- a/arch/x86/include/asm/page.h
+++ b/arch/x86/include/asm/page.h
@@ -63,7 +63,7 @@ extern bool __virt_addr_valid(unsigned long kaddr);
 #endif	/* __ASSEMBLY__ */
 
 #include <asm-generic/memory_model.h>
-#include <asm-generic/getorder.h>
+#include <asm/getorder.h>
 
 #define __HAVE_ARCH_GATE_AREA 1
 
-- 
1.7.2.3


             reply	other threads:[~2011-03-27  8:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-27  8:45 Maksym Planeta [this message]
2011-03-27 11:33 ` [PATCH v2] x86: page: get_order() optimization Ingo Molnar
2011-03-27 16:22   ` Peter Hüwe
2011-03-27 17:15   ` Maksym Planeta
2011-03-28  5:08     ` Ingo Molnar
2011-03-28 19:33       ` Maksym Planeta
2011-03-28 19:44         ` H. Peter Anvin
2011-04-01 14:08           ` Maksym Planeta
2011-03-28 19:47 ` H. Peter Anvin
2011-03-29  7:27   ` Ingo Molnar

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=1301215556-8898-1-git-send-email-mcsim.planeta@gmail.com \
    --to=mcsim.planeta@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@gmail.com \
    /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