From: Roy Marples Date: Fri, 29 Jan 2016 11:31:54 +0000 (+0000) Subject: Remove our internal ffs32 and just use bitops.h X-Git-Tag: v6.10.2~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0134e29ea10ee059fbf912f08943f4cb8e0bd316;p=thirdparty%2Fdhcpcd.git Remove our internal ffs32 and just use bitops.h --- diff --git a/compat/ffs64.h b/compat/bitops.h similarity index 54% rename from compat/ffs64.h rename to compat/bitops.h index a00fd766..ac0efc80 100644 --- a/compat/ffs64.h +++ b/compat/bitops.h @@ -1,4 +1,4 @@ -/* $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. @@ -29,12 +29,51 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef COMPAT_FFS64 -#define COMPAT_FFS64 +#ifndef COMPAT_BITOPS_H +#define COMPAT_BITOPS_H -#include +#include +#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; @@ -69,5 +108,81 @@ ffs64(uint64_t _n) } 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_ */ diff --git a/configure b/configure index 0ad1f77b..24cac8f0 100755 --- a/configure +++ b/configure @@ -1002,9 +1002,7 @@ EOF rm -f _ffs64.c _ffs64 fi if [ "$FFS64" = yes ]; then - echo "CPPFLAGS+= -DHAVE_SYS_BITOPS_H" >>$CONFIG_MK -else - echo "#include \"compat/ffs64.h\"" >>$CONFIG_H + echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H fi if [ -z "$MD5" ]; then diff --git a/dhcp6.c b/dhcp6.c index 9abe78e7..66781516 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -54,6 +54,12 @@ #include "ipv6nd.h" #include "script.h" +#ifdef HAVE_SYS_BITOPS_H +#include +#else +#include "compat/bitops.h" +#endif + #ifndef __UNCONST #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) #endif @@ -374,40 +380,6 @@ dhcp6_findselfsla(struct interface *ifp, const uint8_t *iaid) 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) diff --git a/ipv6.c b/ipv6.c index 7e77b966..b381df32 100644 --- a/ipv6.c +++ b/ipv6.c @@ -39,6 +39,8 @@ #ifdef HAVE_SYS_BITOPS_H #include +#else +#include "compat/bitops.h" #endif #ifdef BSD