X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Filog%2Filog.c;h=22275d2a9e02d12cf983a2b4195787349af6cea6;hp=ed39d1922aeda5ae675c5824aa52c3d00c6df97a;hb=6a8d296f9383dd25ec381e2ab136a33823d140e5;hpb=a5f9a8fbcea19f50aa3594ce2dbf5a13c5455ecc;ds=sidebyside diff --git a/ccan/ilog/ilog.c b/ccan/ilog/ilog.c index ed39d192..22275d2a 100644 --- a/ccan/ilog/ilog.c +++ b/ccan/ilog/ilog.c @@ -1,4 +1,5 @@ -/*(C) Timothy B. Terriberry (tterribe@xiph.org) 2001-2009 LGPL (v2 or later).*/ +/*(C) Timothy B. Terriberry (tterribe@xiph.org) 2001-2009 LGPL (v2 or later). + * See LICENSE file for details. */ #include "ilog.h" #include @@ -16,18 +17,18 @@ year=1998, note="\url{http://supertech.csail.mit.edu/papers/debruijn.pdf}" }*/ -#if !defined(ILOG_NODEBRUIJN)&& \ - !defined(CLZ32)||!defined(CLZ64)&&LONG_MAX<9223372036854775807LL -static const unsigned char DEBRUIJN_IDX32[32]={ +static UNNEEDED const unsigned char DEBRUIJN_IDX32[32]={ 0, 1,28, 2,29,14,24, 3,30,22,20,15,25,17, 4, 8, 31,27,13,23,21,19,16, 7,26,12,18, 6,11, 5,10, 9 }; -#endif + +/* We always compile these in, in case someone takes address of function. */ +#undef ilog32_nz +#undef ilog32 +#undef ilog64_nz +#undef ilog64 int ilog32(uint32_t _v){ -#if defined(CLZ32) - return (CLZ32_OFFS-CLZ32(_v))&-!!_v; -#else /*On a Pentium M, this branchless version tested as the fastest version without multiplications on 1,000,000,000 random 32-bit integers, edging out a similar version with branches, and a 256-entry LUT version.*/ @@ -62,13 +63,14 @@ int ilog32(uint32_t _v){ ret+=DEBRUIJN_IDX32[_v*0x77CB531U>>27&0x1F]; return ret; # endif -#endif +} + +int ilog32_nz(uint32_t _v) +{ + return ilog32(_v); } int ilog64(uint64_t _v){ -#if defined(CLZ64) - return (CLZ64_OFFS-CLZ64(_v))&-!!_v; -#else # if defined(ILOG_NODEBRUIJN) uint32_t v; int ret; @@ -130,5 +132,10 @@ int ilog64(uint64_t _v){ return ret; # endif # endif -#endif } + +int ilog64_nz(uint64_t _v) +{ + return ilog64(_v); +} +