Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 292704
b: refs/heads/master
c: d66acc3
h: refs/heads/master
v: v3
  • Loading branch information
David Howells authored and H. Peter Anvin committed Feb 20, 2012
1 parent 1d36f1d commit ff3eced
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e0891a9816316b5e05fd5b0453ffe9fd6a56f489
refs/heads/master: d66acc39c7cee323733c8503b9de1821a56dff7e
40 changes: 28 additions & 12 deletions trunk/include/asm-generic/getorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
#ifndef __ASSEMBLY__

#include <linux/compiler.h>
#include <linux/log2.h>

/*
* Runtime evaluation of get_order()
*/
static inline __attribute_const__
int __get_order(unsigned long size)
{
int order;

size--;
size >>= PAGE_SHIFT;
#if BITS_PER_LONG == 32
order = fls(size);
#else
order = fls64(size);
#endif
return order;
}

/**
* get_order - Determine the allocation order of a memory size
Expand All @@ -27,18 +46,15 @@
* This function may be used to initialise variables with compile time
* evaluations of constants.
*/
static inline __attribute_const__ int get_order(unsigned long size)
{
int order;

size = (size - 1) >> (PAGE_SHIFT - 1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}
#define get_order(n) \
( \
__builtin_constant_p(n) ? ( \
(n == 0UL) ? BITS_PER_LONG - PAGE_SHIFT : \
((n < (1UL << PAGE_SHIFT)) ? 0 : \
ilog2((n) - 1) - PAGE_SHIFT + 1) \
) : \
__get_order(n) \
)

#endif /* __ASSEMBLY__ */

Expand Down

0 comments on commit ff3eced

Please sign in to comment.