aboutsummaryrefslogtreecommitdiff
path: root/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2015-06-17 12:05:04 +0000
committerAndriy Gapon <avg@FreeBSD.org>2015-06-17 12:05:04 +0000
commit1fa1d4a651c15375ccbf3e2ce2e755a3c20e43d2 (patch)
tree837f7499644603fe7a7cc0f771398ee4e82ff1d8 /sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
parent8fe344fa48fc99411291409c0557afd5bc239ccd (diff)
downloadsrc-1fa1d4a651c15375ccbf3e2ce2e755a3c20e43d2.tar.gz
src-1fa1d4a651c15375ccbf3e2ce2e755a3c20e43d2.zip
illumos compat: use flsl/flsll for highbit/highbit64
This is a micro optimization. The upstream code uses the binary search. Differential Revision: https://reviews.freebsd.org/D2839 Reviewed by: delphij, mav MFC after: 15 days
Notes
Notes: svn path=/head/; revision=284511
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h')
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h b/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
index 300351482c10..f1adfd115d51 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
+++ b/sys/cddl/contrib/opensolaris/uts/common/sys/sysmacros.h
@@ -32,6 +32,13 @@
#include <sys/param.h>
#include <sys/isa_defs.h>
+#ifdef __FreeBSD__
+#ifdef _KERNEL
+#include <machine/cpufunc.h>
+#else
+#include <strings.h>
+#endif
+#endif
#ifdef __cplusplus
extern "C" {
@@ -382,6 +389,9 @@ extern unsigned char bcd_to_byte[256];
static __inline int
highbit(ulong_t i)
{
+#ifdef __FreeBSD__
+ return (flsl(i));
+#else
register int h = 1;
if (i == 0)
@@ -407,6 +417,7 @@ highbit(ulong_t i)
h += 1;
}
return (h);
+#endif
}
/*
@@ -416,6 +427,9 @@ highbit(ulong_t i)
static __inline int
highbit64(uint64_t i)
{
+#ifdef __FreeBSD__
+ return (flsll(i));
+#else
int h = 1;
if (i == 0)
@@ -439,6 +453,7 @@ highbit64(uint64_t i)
h += 1;
}
return (h);
+#endif
}
#ifdef __cplusplus