From: Bob Weinand Date: Mon, 22 Jun 2015 11:24:39 +0000 (+0200) Subject: Also try __has_builtin() where builtins are used X-Git-Tag: php-7.0.0alpha2~2^2~16^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70e86b876691e4bf1377f9bf1e25a7158d33805d;p=php Also try __has_builtin() where builtins are used --- diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 2d47b643c3..f788737bf4 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -478,12 +478,10 @@ static void zend_mm_munmap(void *addr, size_t size) /* number of trailing set (1) bits */ static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset) { -#if defined(__GNUC__) -# if SIZEOF_ZEND_LONG == SIZEOF_LONG +#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG return __builtin_ctzl(~bitset); -# else +#elif defined(__GNUC__) || __has_builtin(__builtin_ctzll) return __builtin_ctzll(~bitset); -# endif #elif defined(_WIN32) unsigned long index; @@ -519,12 +517,10 @@ static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset) /* number of trailing zero bits (0x01 -> 1; 0x40 -> 6; 0x00 -> LEN) */ static zend_always_inline int zend_mm_bitset_ntz(zend_mm_bitset bitset) { -#if defined(__GNUC__) -# if SIZEOF_ZEND_LONG == SIZEOF_LONG +#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG return __builtin_ctzl(bitset); -# else +#elif defined(__GNUC__) || __has_builtin(__builtin_ctzll) return __builtin_ctzll(bitset); -# endif #elif defined(_WIN32) unsigned long index; @@ -1120,7 +1116,7 @@ static zend_always_inline void zend_mm_free_large(zend_mm_heap *heap, zend_mm_ch /* higher set bit number (0->N/A, 1->1, 2->2, 4->3, 8->4, 127->7, 128->8 etc) */ static zend_always_inline int zend_mm_small_size_to_bit(int size) { -#if defined(__GNUC__) +#if defined(__GNUC__) || __has_builtin(__builtin_clz) return (__builtin_clz(size) ^ 0x1f) + 1; #elif defined(_WIN32) unsigned long index; diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 960a8a92b5..0ff506a6f4 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -107,7 +107,7 @@ static uint32_t zend_always_inline zend_hash_check_size(uint32_t nSize) rather than using an undefined bis scan result. */ return nSize; } -#elif defined(__GNUC__) +#elif defined(__GNUC__) || __has_builtin(__builtin_clz) return 0x2 << (__builtin_clz(nSize - 1) ^ 0x1f); #else nSize -= 1; diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 65455ee10f..57080ca7b7 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -85,9 +85,17 @@ # define ZEND_GCC_VERSION 0 #endif +/* Compatibility with non-clang compilers */ +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + #if defined(ZEND_WIN32) # define ZEND_ASSUME(c) __assume(c) -#elif defined(__GNUC__) && PHP_HAVE_BUILTIN_EXPECT && ZEND_GCC_VERSION >= 4005 +#elif ((defined(__GNUC__) && ZEND_GCC_VERSION >= 4005) || __has_builtin(__builtin_unreachable)) && PHP_HAVE_BUILTIN_EXPECT # define ZEND_ASSUME(c) do { \ if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \ } while (0) @@ -161,11 +169,6 @@ char *alloca(); # endif #endif -/* Compatibility with non-clang compilers */ -#ifndef __has_attribute -# define __has_attribute(x) 0 -#endif - #if ZEND_GCC_VERSION >= 2096 # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) #else