xref: /openbsd-src/sys/dev/pci/drm/include/linux/log2.h (revision 4b70baf6e17fc8b27fc1f7fa7929335753fa94c3)
1 /* Public domain. */
2 
3 #ifndef _LINUX_LOG2_H
4 #define _LINUX_LOG2_H
5 
6 #include <sys/types.h>
7 #include <sys/systm.h>
8 
9 #define ilog2(x) ((sizeof(x) <= 4) ? (fls(x) - 1) : (flsl(x) - 1))
10 
11 #define is_power_of_2(x)	(((x) != 0) && (((x) - 1) & (x)) == 0)
12 #define order_base_2(x)		drm_order(x)
13 
14 static inline unsigned long
15 roundup_pow_of_two(unsigned long x)
16 {
17 	return (1UL << flsl(x - 1));
18 }
19 
20 static inline unsigned long
21 rounddown_pow_of_two(unsigned long x)
22 {
23 	return (1UL << (flsl(x) - 1));
24 }
25 
26 #endif
27