* [PATCH][RFC] move get_order() out of the page.h
@ 2002-04-29 10:47 Andrey Panin
0 siblings, 0 replies; only message in thread
From: Andrey Panin @ 2002-04-29 10:47 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 431 bytes --]
Hi all,
currently (2.5.10) every arch specific asm-*/page.h file includes inline
get_order() function. All of them (except IA64 one) are identical.
Attached patch moves get_order() into separate include file and adds
microoptimisation for get_order() calls with immediate argument.
Best regards.
--
Andrey Panin | Embedded systems software engineer
pazke@orbita1.ru | PGP key: wwwkeys.eu.pgp.net
[-- Attachment #1.2: patch-get-order --]
[-- Type: text/plain, Size: 10939 bytes --]
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-alpha/page.h linux/include/asm-alpha/page.h
--- linux.vanilla/include/asm-alpha/page.h Mon Mar 4 19:33:18 2002
+++ linux/include/asm-alpha/page.h Mon Apr 29 00:43:31 2002
@@ -67,19 +67,7 @@
#define PAGE_BUG(page) BUG()
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* !__ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-arm/page.h linux/include/asm-arm/page.h
--- linux.vanilla/include/asm-arm/page.h Wed Mar 20 22:14:41 2002
+++ linux/include/asm-arm/page.h Mon Apr 29 00:44:08 2002
@@ -111,19 +111,7 @@
#endif
-/* Pure 2^n version of get_order */
-static inline int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* !__ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-generic/get_order.h linux/include/asm-generic/get_order.h
--- linux.vanilla/include/asm-generic/get_order.h Thu Jan 1 03:00:00 1970
+++ linux/include/asm-generic/get_order.h Mon Apr 29 00:45:36 2002
@@ -0,0 +1,53 @@
+#ifndef _GET_ORDER_H_
+#define _GET_ORDER_H_
+
+/* Pure 2^n version of get_order */
+#define get_order(size) \
+ (__builtin_constant_p(size) ? \
+ __constant_get_order(size) : \
+ __get_order(size))
+
+#ifndef __HAVE_ARCH_GET_ORDER
+static inline int __get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+#endif
+
+#define CASE_ORDER(order) \
+ case (PAGE_SIZE << ((order) - 1)) + 1 ... PAGE_SIZE << (order): \
+ return (order)
+
+static inline int __constant_get_order(unsigned long size)
+{
+ switch (size) {
+ case 1 ... PAGE_SIZE:
+ return 0;
+ CASE_ORDER(1);
+ CASE_ORDER(2);
+ CASE_ORDER(3);
+ CASE_ORDER(4);
+ CASE_ORDER(5);
+ CASE_ORDER(6);
+ CASE_ORDER(7);
+ CASE_ORDER(8);
+ CASE_ORDER(9);
+ CASE_ORDER(10);
+ CASE_ORDER(11);
+ CASE_ORDER(12);
+ CASE_ORDER(13);
+ CASE_ORDER(14);
+ CASE_ORDER(15);
+ }
+ return __get_order(size);
+}
+
+#endif
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-i386/page.h linux/include/asm-i386/page.h
--- linux.vanilla/include/asm-i386/page.h Mon Mar 4 19:33:18 2002
+++ linux/include/asm-i386/page.h Mon Apr 29 00:36:47 2002
@@ -109,19 +109,7 @@
BUG(); \
} while (0)
-/* Pure 2^n version of get_order */
-static __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* __ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-ia64/page.h linux/include/asm-ia64/page.h
--- linux.vanilla/include/asm-ia64/page.h Wed Mar 20 22:14:41 2002
+++ linux/include/asm-ia64/page.h Mon Apr 29 00:45:15 2002
@@ -110,6 +110,7 @@
#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); *(int *)0=0; } while (0)
#define PAGE_BUG(page) do { BUG(); } while (0)
+#define __HAVE_ARCH_GET_ORDER
static __inline__ int
get_order (unsigned long size)
{
@@ -122,6 +123,8 @@
order = 0;
return order;
}
+
+#include <asm-generic/get_order.h>
# endif /* __KERNEL__ */
#endif /* !__ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-m68k/page.h linux/include/asm-m68k/page.h
--- linux.vanilla/include/asm-m68k/page.h Mon Mar 4 19:33:19 2002
+++ linux/include/asm-m68k/page.h Mon Apr 29 00:43:37 2002
@@ -100,19 +100,7 @@
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* !__ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-mips/page.h linux/include/asm-mips/page.h
--- linux.vanilla/include/asm-mips/page.h Mon Mar 4 19:33:19 2002
+++ linux/include/asm-mips/page.h Mon Apr 29 00:43:25 2002
@@ -49,19 +49,7 @@
#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x) ((pgprot_t) { (x) } )
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* _LANGUAGE_ASSEMBLY */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-parisc/page.h linux/include/asm-parisc/page.h
--- linux.vanilla/include/asm-parisc/page.h Mon Mar 4 19:33:19 2002
+++ linux/include/asm-parisc/page.h Mon Apr 29 00:46:19 2002
@@ -33,19 +33,7 @@
#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x) ((pgprot_t) { (x) } )
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* !__ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-ppc/page.h linux/include/asm-ppc/page.h
--- linux.vanilla/include/asm-ppc/page.h Mon Mar 4 19:33:19 2002
+++ linux/include/asm-ppc/page.h Mon Apr 29 00:43:53 2002
@@ -142,19 +142,7 @@
extern unsigned long get_zero_page_fast(void);
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* __ASSEMBLY__ */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-ppc64/page.h linux/include/asm-ppc64/page.h
--- linux.vanilla/include/asm-ppc64/page.h Tue Apr 23 19:06:36 2002
+++ linux/include/asm-ppc64/page.h Mon Apr 29 00:41:49 2002
@@ -137,19 +137,7 @@
*/
#define WANT_PAGE_VIRTUAL 1
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-s390/page.h linux/include/asm-s390/page.h
--- linux.vanilla/include/asm-s390/page.h Mon Mar 4 19:33:20 2002
+++ linux/include/asm-s390/page.h Mon Apr 29 00:46:11 2002
@@ -71,19 +71,7 @@
BUG(); \
} while (0)
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
/*
* These are used to make use of C type-checking..
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-s390x/page.h linux/include/asm-s390x/page.h
--- linux.vanilla/include/asm-s390x/page.h Mon Mar 4 19:33:20 2002
+++ linux/include/asm-s390x/page.h Mon Apr 29 00:46:30 2002
@@ -69,19 +69,7 @@
BUG(); \
} while (0)
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
/*
* These are used to make use of C type-checking..
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-sh/page.h linux/include/asm-sh/page.h
--- linux.vanilla/include/asm-sh/page.h Tue Dec 4 12:40:37 2001
+++ linux/include/asm-sh/page.h Mon Apr 29 00:44:14 2002
@@ -102,19 +102,7 @@
BUG(); \
} while (0)
-/* Pure 2^n version of get_order */
-static __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-sparc/page.h linux/include/asm-sparc/page.h
--- linux.vanilla/include/asm-sparc/page.h Mon Mar 4 19:33:20 2002
+++ linux/include/asm-sparc/page.h Mon Apr 29 00:43:47 2002
@@ -150,19 +150,7 @@
#define TASK_UNMAPPED_BASE BTFIXUP_SETHI(sparc_unmapped_base)
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#else /* !(__ASSEMBLY__) */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-sparc64/page.h linux/include/asm-sparc64/page.h
--- linux.vanilla/include/asm-sparc64/page.h Wed Mar 20 22:15:35 2002
+++ linux/include/asm-sparc64/page.h Mon Apr 29 00:44:00 2002
@@ -138,19 +138,7 @@
extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS];
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* !(__ASSEMBLY__) */
diff -urN -X /usr/share/dontdiff linux.vanilla/include/asm-x86_64/page.h linux/include/asm-x86_64/page.h
--- linux.vanilla/include/asm-x86_64/page.h Tue Apr 23 19:08:02 2002
+++ linux/include/asm-x86_64/page.h Mon Apr 29 00:41:37 2002
@@ -74,19 +74,7 @@
#define PAGE_BUG(page) BUG()
void out_of_line_bug(void);
-/* Pure 2^n version of get_order */
-extern __inline__ int get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
+#include <asm-generic/get_order.h>
#endif /* __ASSEMBLY__ */
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-04-29 10:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-29 10:47 [PATCH][RFC] move get_order() out of the page.h Andrey Panin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox