File: ffz.h

package info (click to toggle)
fio 2.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,640 kB
  • sloc: ansic: 26,696; makefile: 180; sh: 124
file content (43 lines) | stat: -rw-r--r-- 533 bytes parent folder | download | duplicates (2)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef FIO_FFZ_H
#define FIO_FFZ_H

static inline int __ffs(unsigned long word)
{
	int r = 0;

#if BITS_PER_LONG == 64
	if ((word & 0xffffffff) == 0) {
		r += 32;
		word >>= 32;
	}
#endif
	if (!(word & 0xffff)) {
		word >>= 16;
		r += 16;
	}
	if (!(word & 0xff)) {
		word >>= 8;
		r += 8;
	}
	if (!(word & 0xf)) {
		word >>= 4;
		r += 4;
	}
	if (!(word & 3)) {
		word >>= 2;
		r += 2;
	}
	if (!(word & 1)) {
		word >>= 1;
		r += 1;
	}

	return r;
}

static inline int ffz(unsigned long bitmask)
{
	return __ffs(~bitmask);
}

#endif