1/*
2 * @TAG(OTHER_GPL)
3 */
4
5#ifndef _LINUX_BITOPS_H
6#define _LINUX_BITOPS_H
7
8#include "../unimplemented.h"
9
10/*
11 * ffs: find first bit set. This is defined the same way as
12 * the libc and compiler builtin ffs routines, therefore
13 * differs in spirit from the above ffz (man ffs).
14 */
15
16static inline int generic_ffs(int x)
17{
18	int r = 1;
19
20	if (!x)
21		return 0;
22	if (!(x & 0xffff)) {
23		x >>= 16;
24		r += 16;
25	}
26	if (!(x & 0xff)) {
27		x >>= 8;
28		r += 8;
29	}
30	if (!(x & 0xf)) {
31		x >>= 4;
32		r += 4;
33	}
34	if (!(x & 3)) {
35		x >>= 2;
36		r += 2;
37	}
38	if (!(x & 1)) {
39		x >>= 1;
40		r += 1;
41	}
42	return r;
43}
44
45#ifndef PLATFORM_FFS
46# define ffs generic_ffs
47#endif
48#endif
49