xref: /openbsd/sys/dev/pci/drm/include/linux/log2.h (revision c349dbc7)
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 int	drm_order(unsigned long);
12 
13 #define is_power_of_2(x)	(((x) != 0) && (((x) - 1) & (x)) == 0)
14 #define order_base_2(x)		drm_order(x)
15 
16 static inline unsigned long
roundup_pow_of_two(unsigned long x)17 roundup_pow_of_two(unsigned long x)
18 {
19 	return (1UL << flsl(x - 1));
20 }
21 
22 static inline unsigned long
rounddown_pow_of_two(unsigned long x)23 rounddown_pow_of_two(unsigned long x)
24 {
25 	return (1UL << (flsl(x) - 1));
26 }
27 
28 #endif
29