Changeset View
Changeset View
Standalone View
Standalone View
head/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
Show All 26 Lines | |||||
* Use is subject to license terms. | * Use is subject to license terms. | ||||
*/ | */ | ||||
#ifndef _SYS_SYSMACROS_H | #ifndef _SYS_SYSMACROS_H | ||||
#define _SYS_SYSMACROS_H | #define _SYS_SYSMACROS_H | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/isa_defs.h> | #include <sys/isa_defs.h> | ||||
#ifdef __FreeBSD__ | |||||
#ifdef _KERNEL | |||||
#include <machine/cpufunc.h> | |||||
#else | |||||
#include <strings.h> | |||||
#endif | |||||
#endif | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { | ||||
#endif | #endif | ||||
/* | /* | ||||
* Some macros for units conversion | * Some macros for units conversion | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Find highest one bit set. | * Find highest one bit set. | ||||
* Returns bit number + 1 of highest bit that is set, otherwise returns 0. | * Returns bit number + 1 of highest bit that is set, otherwise returns 0. | ||||
* High order bit is 31 (or 63 in _LP64 kernel). | * High order bit is 31 (or 63 in _LP64 kernel). | ||||
*/ | */ | ||||
static __inline int | static __inline int | ||||
highbit(ulong_t i) | highbit(ulong_t i) | ||||
{ | { | ||||
#ifdef __FreeBSD__ | |||||
return (flsl(i)); | |||||
#else | |||||
register int h = 1; | register int h = 1; | ||||
if (i == 0) | if (i == 0) | ||||
return (0); | return (0); | ||||
#ifdef _LP64 | #ifdef _LP64 | ||||
if (i & 0xffffffff00000000ul) { | if (i & 0xffffffff00000000ul) { | ||||
h += 32; i >>= 32; | h += 32; i >>= 32; | ||||
} | } | ||||
Show All 9 Lines | #endif | ||||
} | } | ||||
if (i & 0xc) { | if (i & 0xc) { | ||||
h += 2; i >>= 2; | h += 2; i >>= 2; | ||||
} | } | ||||
if (i & 0x2) { | if (i & 0x2) { | ||||
h += 1; | h += 1; | ||||
} | } | ||||
return (h); | return (h); | ||||
#endif | |||||
} | } | ||||
/* | /* | ||||
* Find highest one bit set. | * Find highest one bit set. | ||||
* Returns bit number + 1 of highest bit that is set, otherwise returns 0. | * Returns bit number + 1 of highest bit that is set, otherwise returns 0. | ||||
*/ | */ | ||||
static __inline int | static __inline int | ||||
highbit64(uint64_t i) | highbit64(uint64_t i) | ||||
{ | { | ||||
#ifdef __FreeBSD__ | |||||
return (flsll(i)); | |||||
#else | |||||
int h = 1; | int h = 1; | ||||
if (i == 0) | if (i == 0) | ||||
return (0); | return (0); | ||||
if (i & 0xffffffff00000000ULL) { | if (i & 0xffffffff00000000ULL) { | ||||
h += 32; i >>= 32; | h += 32; i >>= 32; | ||||
} | } | ||||
if (i & 0xffff0000) { | if (i & 0xffff0000) { | ||||
h += 16; i >>= 16; | h += 16; i >>= 16; | ||||
} | } | ||||
if (i & 0xff00) { | if (i & 0xff00) { | ||||
h += 8; i >>= 8; | h += 8; i >>= 8; | ||||
} | } | ||||
if (i & 0xf0) { | if (i & 0xf0) { | ||||
h += 4; i >>= 4; | h += 4; i >>= 4; | ||||
} | } | ||||
if (i & 0xc) { | if (i & 0xc) { | ||||
h += 2; i >>= 2; | h += 2; i >>= 2; | ||||
} | } | ||||
if (i & 0x2) { | if (i & 0x2) { | ||||
h += 1; | h += 1; | ||||
} | } | ||||
return (h); | return (h); | ||||
#endif | |||||
} | } | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
#endif /* _SYS_SYSMACROS_H */ | #endif /* _SYS_SYSMACROS_H */ |