summaryrefslogtreecommitdiff
path: root/Zend/zend_alloc.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-05-17 22:17:22 +0200
committerNikita Popov <nikic@php.net>2016-05-17 22:23:43 +0200
commit14023d39c1ae2fc48bb9ab2c87ea7136c58c2401 (patch)
treec1dcadaf8b7a09d9c53693a8883f9e76322d7d1f /Zend/zend_alloc.c
parent0d77222473bd25734134d63896e3d09b422f739d (diff)
downloadphp-git-14023d39c1ae2fc48bb9ab2c87ea7136c58c2401.tar.gz
Move builtin_ctzl portability into zend_bitset.h
Use this function in both zend_mm_bitset_find_one and zend_bitset_first. Maybe zend_bitset.h is not quite the right place for it, but I did not want to include this in a globally included header like zend_long.h or zend_portability.h.
Diffstat (limited to 'Zend/zend_alloc.c')
-rw-r--r--Zend/zend_alloc.c46
1 files changed, 4 insertions, 42 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index e7a8e0d2a5..a7e3808e7c 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -58,6 +58,7 @@
#include "zend_globals.h"
#include "zend_operators.h"
#include "zend_multiply.h"
+#include "zend_bitset.h"
#ifdef HAVE_SIGNAL_H
# include <signal.h>
@@ -546,45 +547,6 @@ static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset)
#endif
}
-/* 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__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
- return __builtin_ctzl(bitset);
-#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzll)) && defined(PHP_HAVE_BUILTIN_CTZLL)
- return __builtin_ctzll(bitset);
-#elif defined(_WIN32)
- unsigned long index;
-
-#if defined(_WIN64)
- if (!BitScanForward64(&index, bitset)) {
-#else
- if (!BitScanForward(&index, bitset)) {
-#endif
- /* undefined behavior */
- return 32;
- }
-
- return (int)index;
-#else
- int n;
-
- if (bitset == (zend_mm_bitset)0) return ZEND_MM_BITSET_LEN;
-
- n = 1;
-#if SIZEOF_ZEND_LONG == 8
- if (sizeof(zend_mm_bitset) == 8) {
- if ((bitset & 0xffffffff) == 0) {n += 32; bitset = bitset >> Z_UL(32);}
- }
-#endif
- if ((bitset & 0x0000ffff) == 0) {n += 16; bitset = bitset >> 16;}
- if ((bitset & 0x000000ff) == 0) {n += 8; bitset = bitset >> 8;}
- if ((bitset & 0x0000000f) == 0) {n += 4; bitset = bitset >> 4;}
- if ((bitset & 0x00000003) == 0) {n += 2; bitset = bitset >> 2;}
- return n - (bitset & 1);
-#endif
-}
-
static zend_always_inline int zend_mm_bitset_find_zero(zend_mm_bitset *bitset, int size)
{
int i = 0;
@@ -606,7 +568,7 @@ static zend_always_inline int zend_mm_bitset_find_one(zend_mm_bitset *bitset, in
do {
zend_mm_bitset tmp = bitset[i];
if (tmp != 0) {
- return i * ZEND_MM_BITSET_LEN + zend_mm_bitset_ntz(tmp);
+ return i * ZEND_MM_BITSET_LEN + zend_ulong_ntz(tmp);
}
i++;
} while (i < size);
@@ -941,7 +903,7 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, int pages_count ZEND_FILE_L
tmp = *(bitset++);
}
/* find first 1 bit */
- len = (i + zend_mm_bitset_ntz(tmp)) - page_num;
+ len = (i + zend_ulong_ntz(tmp)) - page_num;
if (len >= pages_count) {
goto found;
}
@@ -998,7 +960,7 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, int pages_count ZEND_FILE_L
tmp = *(bitset++);
}
/* find first 1 bit */
- len = i + zend_mm_bitset_ntz(tmp) - page_num;
+ len = i + zend_ulong_ntz(tmp) - page_num;
if (len >= pages_count) {
if (len == pages_count) {
goto found;