[BACK]Return to bitops.h CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfsprogs / include

File: [Development] / xfs-cmds / xfsprogs / include / bitops.h (download)

Revision 1.1, Mon Sep 8 06:18:43 2008 UTC (9 years, 1 month ago) by bnaujok.longdrop.melbourne.sgi.com
Branch: MAIN
CVS Tags: HEAD

Update xfsprogs to latest kernel headers and functions
Merge of master-melb:xfs-cmds:32070a by kenmcd.

#ifndef __BITOPS_H__
#define __BITOPS_H__

/*
 * fls: find last bit set.
 */

static inline int fls(int x)
{
	int r = 32;

	if (!x)
		return 0;
	if (!(x & 0xffff0000u)) {
		x <<= 16;
		r -= 16;
	}
	if (!(x & 0xff000000u)) {
		x <<= 8;
		r -= 8;
	}
	if (!(x & 0xf0000000u)) {
		x <<= 4;
		r -= 4;
	}
	if (!(x & 0xc0000000u)) {
		x <<= 2;
		r -= 2;
	}
	if (!(x & 0x80000000u)) {
		x <<= 1;
		r -= 1;
	}
	return r;
}

static inline int fls64(__u64 x)
{
	__u32 h = x >> 32;
	if (h)
		return fls(h) + 32;
	return fls(x);
}

static inline unsigned fls_long(unsigned long l)
{
        if (sizeof(l) == 4)
                return fls(l);
        return fls64(l);
}

#endif