-/* $NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $ */
+/* $NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $ */
/*-
* Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef COMPAT_FFS64
-#define COMPAT_FFS64
+#ifndef COMPAT_BITOPS_H
+#define COMPAT_BITOPS_H
-#include <stdint.h>
+#include <sys/stdint.h>
+#include "../common.h"
-inline static int
+/*
+ * Find First Set functions
+ */
+#ifndef ffs32
+static inline int __unused
+ffs32(uint32_t _n)
+{
+ int _v;
+
+ if (!_n)
+ return 0;
+
+ _v = 1;
+ if ((_n & 0x0000FFFFU) == 0) {
+ _n >>= 16;
+ _v += 16;
+ }
+ if ((_n & 0x000000FFU) == 0) {
+ _n >>= 8;
+ _v += 8;
+ }
+ if ((_n & 0x0000000FU) == 0) {
+ _n >>= 4;
+ _v += 4;
+ }
+ if ((_n & 0x00000003U) == 0) {
+ _n >>= 2;
+ _v += 2;
+ }
+ if ((_n & 0x00000001U) == 0) {
+ _n >>= 1;
+ _v += 1;
+ }
+ return _v;
+}
+#endif
+
+#ifndef ffs64
+static inline int __unused
ffs64(uint64_t _n)
{
int _v;
}
return _v;
}
+#endif
+/*
+ * Find Last Set functions
+ */
+#ifndef fls32
+static __inline int __unused
+fls32(uint32_t _n)
+{
+ int _v;
+
+ if (!_n)
+ return 0;
+
+ _v = 32;
+ if ((_n & 0xFFFF0000U) == 0) {
+ _n <<= 16;
+ _v -= 16;
+ }
+ if ((_n & 0xFF000000U) == 0) {
+ _n <<= 8;
+ _v -= 8;
+ }
+ if ((_n & 0xF0000000U) == 0) {
+ _n <<= 4;
+ _v -= 4;
+ }
+ if ((_n & 0xC0000000U) == 0) {
+ _n <<= 2;
+ _v -= 2;
+ }
+ if ((_n & 0x80000000U) == 0) {
+ _n <<= 1;
+ _v -= 1;
+ }
+ return _v;
+}
#endif
+
+#ifndef fls64
+static int __unused
+fls64(uint64_t _n)
+{
+ int _v;
+
+ if (!_n)
+ return 0;
+
+ _v = 64;
+ if ((_n & 0xFFFFFFFF00000000ULL) == 0) {
+ _n <<= 32;
+ _v -= 32;
+ }
+ if ((_n & 0xFFFF000000000000ULL) == 0) {
+ _n <<= 16;
+ _v -= 16;
+ }
+ if ((_n & 0xFF00000000000000ULL) == 0) {
+ _n <<= 8;
+ _v -= 8;
+ }
+ if ((_n & 0xF000000000000000ULL) == 0) {
+ _n <<= 4;
+ _v -= 4;
+ }
+ if ((_n & 0xC000000000000000ULL) == 0) {
+ _n <<= 2;
+ _v -= 2;
+ }
+ if ((_n & 0x8000000000000000ULL) == 0) {
+ _n <<= 1;
+ _v -= 1;
+ }
+ return _v;
+}
+#endif
+
+#endif /* COMPAT_BITOPS_H_ */
#include "ipv6nd.h"
#include "script.h"
+#ifdef HAVE_SYS_BITOPS_H
+#include <sys/bitops.h>
+#else
+#include "compat/bitops.h"
+#endif
+
#ifndef __UNCONST
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#endif
return NULL;
}
-
-#ifndef ffs32
-static int
-ffs32(uint32_t n)
-{
- int v;
-
- if (!n)
- return 0;
-
- v = 1;
- if ((n & 0x0000FFFFU) == 0) {
- n >>= 16;
- v += 16;
- }
- if ((n & 0x000000FFU) == 0) {
- n >>= 8;
- v += 8;
- }
- if ((n & 0x0000000FU) == 0) {
- n >>= 4;
- v += 4;
- }
- if ((n & 0x00000003U) == 0) {
- n >>= 2;
- v += 2;
- }
- if ((n & 0x00000001U) == 0)
- v += 1;
-
- return v;
-}
-#endif
-
static int
dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
const struct ipv6_addr *prefix, const struct if_sla *sla, struct if_ia *ia)