]> granicus.if.org Git - php/commitdiff
Also try __has_builtin() where builtins are used
authorBob Weinand <bobwei9@hotmail.com>
Mon, 22 Jun 2015 11:24:39 +0000 (13:24 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Mon, 22 Jun 2015 11:24:39 +0000 (13:24 +0200)
Zend/zend_alloc.c
Zend/zend_hash.c
Zend/zend_portability.h

index 2d47b643c3db4b63afef0db9d0d6c851bc5ec2d5..f788737bf48166022cae7e536bc9049f60702eb9 100644 (file)
@@ -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;
index 960a8a92b5dd85fa1e6ab7780e3c613f8eb3d558..0ff506a6f4b9112115d8207c42eaf2f8fb948d7c 100644 (file)
@@ -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;
index 65455ee10f6f17207d9e21a43d02cea67aa308c5..57080ca7b719accce269c57e331c117ab07726ad 100644 (file)
 # 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