X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Filog%2Filog.h;h=ed91f4eaf830de7192cf27c84a51b145eb899f2c;hb=ab43c3d0de45ba1012b4e3ff669517f78cac6092;hp=29689f5f5ff69825bf3bca6c1d215ac8ac983315;hpb=2037a903729fea95d76ad7baa7c1e2cd3ce38f04;p=ccan diff --git a/ccan/ilog/ilog.h b/ccan/ilog/ilog.h index 29689f5f..ed91f4ea 100644 --- a/ccan/ilog/ilog.h +++ b/ccan/ilog/ilog.h @@ -1,41 +1,28 @@ #if !defined(_ilog_H) # define _ilog_H (1) +# include "config.h" # include - -# ifdef __GNUC_PREREQ -/*Tag our functions as idempotent to aid optimization, if possible.*/ -# if __GNUC_PREREQ(2,5) -# define IDEMPOTENT __attribute__((const)) -# endif -# if __GNUC_PREREQ(3,4) -# include +# include +# include /*Note the casts to (int) below: this prevents CLZ{32|64}_OFFS from "upgrading" the type of an entire expression to an (unsigned) size_t.*/ -# if INT_MAX>=2147483647 -# define CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT) -# define CLZ32(_x) (__builtin_clz(_x)) -# elif LONG_MAX>=2147483647L -# define CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) -# define CLZ32(_x) (__builtin_clzl(_x)) -# endif -# if INT_MAX>=9223372036854775807LL -# define CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT) -# define CLZ64(_x) (__builtin_clz(_x)) -# elif LONG_MAX>=9223372036854775807LL -# define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) -# define CLZ64(_x) (__builtin_clzl(_x)) -# else /* long long must be >= 64 bits according to ISO C */ -# define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT) -# define CLZ64(_x) (__builtin_clzll(_x)) -# endif -# endif +# if HAVE_BUILTIN_CLZ && INT_MAX>=2147483647 +# define CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT) +# define CLZ32(_x) (__builtin_clz(_x)) +# elif HAVE_BUILTIN_CLZL && LONG_MAX>=2147483647L +# define CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) +# define CLZ32(_x) (__builtin_clzl(_x)) # endif -/*If you have some other compiler which defines its own clz-style builtin, - implement a check for it here.*/ - -# if !defined(IDEMPOTENT) -# define IDEMPOTENT +# if HAVE_BUILTIN_CLZ && INT_MAX>=9223372036854775807LL +# define CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT) +# define CLZ64(_x) (__builtin_clz(_x)) +# elif HAVE_BUILTIN_CLZL && LONG_MAX>=9223372036854775807LL +# define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT) +# define CLZ64(_x) (__builtin_clzl(_x)) +# elif HAVE_BUILTIN_CLZLL /* long long must be >= 64 bits according to ISO C */ +# define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT) +# define CLZ64(_x) (__builtin_clzll(_x)) # endif @@ -49,7 +36,7 @@ * The ILOG_32() or ILOGNZ_32() macros may be able to use a builtin function * instead, which should be faster. */ -int ilog32(uint32_t _v)IDEMPOTENT; +int ilog32(uint32_t _v) IDEMPOTENT_ATTRIBUTE; /** * ilog64 - Integer binary logarithm of a 64-bit value. * @_v: A 64-bit value. @@ -59,9 +46,7 @@ int ilog32(uint32_t _v)IDEMPOTENT; * The ILOG_64() or ILOGNZ_64() macros may be able to use a builtin function * instead, which should be faster. */ -int ilog64(uint64_t _v)IDEMPOTENT; - -# undef IDEMPOTENT +int ilog64(uint64_t _v) IDEMPOTENT_ATTRIBUTE; # if defined(CLZ32)