Revert "ALSA: hda: Flush interrupts on disabling"
[linux/fpc-iii.git] / include / asm-generic / getorder.h
blob52fbf236a90eaa63c7934d8bb2c1f09b3421d028
1 #ifndef __ASM_GENERIC_GETORDER_H
2 #define __ASM_GENERIC_GETORDER_H
4 #ifndef __ASSEMBLY__
6 #include <linux/compiler.h>
7 #include <linux/log2.h>
9 /**
10 * get_order - Determine the allocation order of a memory size
11 * @size: The size for which to get the order
13 * Determine the allocation order of a particular sized block of memory. This
14 * is on a logarithmic scale, where:
16 * 0 -> 2^0 * PAGE_SIZE and below
17 * 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
18 * 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
19 * 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
20 * 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
21 * ...
23 * The order returned is used to find the smallest allocation granule required
24 * to hold an object of the specified size.
26 * The result is undefined if the size is 0.
28 static inline __attribute_const__ int get_order(unsigned long size)
30 if (__builtin_constant_p(size)) {
31 if (!size)
32 return BITS_PER_LONG - PAGE_SHIFT;
34 if (size < (1UL << PAGE_SHIFT))
35 return 0;
37 return ilog2((size) - 1) - PAGE_SHIFT + 1;
40 size--;
41 size >>= PAGE_SHIFT;
42 #if BITS_PER_LONG == 32
43 return fls(size);
44 #else
45 return fls64(size);
46 #endif
49 #endif /* __ASSEMBLY__ */
51 #endif /* __ASM_GENERIC_GETORDER_H */