aboutsummaryrefslogtreecommitdiff
path: root/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h')
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h b/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
index 22f9fe36601d..18f20908191f 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
+++ b/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
@@ -31,6 +31,7 @@
#define _SYS_SYSMACROS_H
#include <sys/param.h>
+#include <sys/isa_defs.h>
#ifdef __cplusplus
extern "C" {
@@ -57,6 +58,9 @@ extern "C" {
#ifndef ABS
#define ABS(a) ((a) < 0 ? -(a) : (a))
#endif
+#ifndef SIGNOF
+#define SIGNOF(a) ((a) < 0 ? -1 : (a) > 0)
+#endif
#ifdef _KERNEL
@@ -108,7 +112,7 @@ extern unsigned char bcd_to_byte[256];
#define L_MAXMIN L_MAXMIN32
#endif
-#if defined(sun)
+#ifdef sun
#ifdef _KERNEL
/* major part of a device internal to the kernel */
@@ -168,7 +172,6 @@ extern unsigned char bcd_to_byte[256];
#define getemajor(x) (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
#define geteminor(x) (minor_t)((x) & L_MAXMIN)
-
#endif /* sun */
/*
@@ -371,6 +374,41 @@ extern unsigned char bcd_to_byte[256];
#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
#endif
+/*
+ * Find highest one bit set.
+ * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
+ * High order bit is 31 (or 63 in _LP64 kernel).
+ */
+static __inline int
+highbit(ulong_t i)
+{
+ register int h = 1;
+
+ if (i == 0)
+ return (0);
+#ifdef _LP64
+ if (i & 0xffffffff00000000ul) {
+ h += 32; i >>= 32;
+ }
+#endif
+ if (i & 0xffff0000) {
+ h += 16; i >>= 16;
+ }
+ if (i & 0xff00) {
+ h += 8; i >>= 8;
+ }
+ if (i & 0xf0) {
+ h += 4; i >>= 4;
+ }
+ if (i & 0xc) {
+ h += 2; i >>= 2;
+ }
+ if (i & 0x2) {
+ h += 1;
+ }
+ return (h);
+}
+
#ifdef __cplusplus
}
#endif