summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci/drm/include/linux/log2.h
blob: 8351b473b1f6386fcecd14f12fdb74e2ee15bca8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Public domain. */

#ifndef _LINUX_LOG2_H
#define _LINUX_LOG2_H

#include <sys/types.h>
#include <sys/systm.h>

#define ilog2(x) ((sizeof(x) <= 4) ? (fls(x) - 1) : (flsl(x) - 1))

#define is_power_of_2(x)	(((x) != 0) && (((x) - 1) & (x)) == 0)
#define order_base_2(x)		drm_order(x)

static inline unsigned long
roundup_pow_of_two(unsigned long x)
{
	return (1UL << flsl(x - 1));
}

static inline unsigned long
rounddown_pow_of_two(unsigned long x)
{
	return (1UL << (flsl(x) - 1));
}

#endif