From 80e3cc4d4f2c8a359994e30b14f4143089bcf78a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 22 Jun 2013 23:56:19 +0200 Subject: [PATCH] Gets in sync with tommy library. --- tommytypes.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tommytypes.h b/tommytypes.h index 82f66165..c0e31a41 100644 --- a/tommytypes.h +++ b/tommytypes.h @@ -84,26 +84,13 @@ typedef int tommy_bool_t; /**< Generic boolean type. */ * Definition of the inline keyword if available. */ #if !defined(tommy_inline) -#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) -#define tommy_inline inline -#elif defined(_MSC_VER) || defined(__GNUC__) +#if defined(_MSC_VER) || defined(__GNUC__) #define tommy_inline static __inline #else #define tommy_inline static #endif #endif -/** \internal - * Definition of the always_inline keyword if available. - */ -#if !defined(tommy_always_inline) -#if defined(__GNUC__) -#define tommy_always_inline static __attribute__((always_inline)) __inline -#else -#define tommy_always_inline tommy_inline -#endif -#endif - /** \internal * Definition of the restrict keyword if available. */ @@ -253,7 +240,15 @@ tommy_inline unsigned tommy_ilog2_u32(tommy_uint32_t value) _BitScanReverse(&count, value); return count; #elif defined(__GNUC__) - return 31 - __builtin_clz(value); + /* + * GCC implements __builtin_clz(x) as "__builtin_clz(x) = bsr(x) ^ 31" + * + * Where "x ^ 31 = 31 - x", but gcc does not optimize "31 - __builtin_clz(x)" to bsr(x), + * but generates 31 - (bsr(x) xor 31). + * + * So we write "__builtin_clz(x) ^ 31" instead of "31 - __builtin_clz(x)". + */ + return __builtin_clz(value) ^ 31; #else /* Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup */ /* from http://graphics.stanford.edu/~seander/bithacks.html */