diff options
-rw-r--r-- | Zend/zend_alloc.c | 2 | ||||
-rw-r--r-- | Zend/zend_bitset.h | 2 | ||||
-rw-r--r-- | Zend/zend_portability.h | 7 | ||||
-rw-r--r-- | ext/json/json_encoder.c | 2 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_result.c | 4 | ||||
-rw-r--r-- | ext/standard/array.c | 12 |
6 files changed, 18 insertions, 11 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index b5c705610d..30f98ff50c 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -587,7 +587,7 @@ static zend_always_inline int zend_mm_bitset_find_zero_and_set(zend_mm_bitset *b static zend_always_inline int zend_mm_bitset_is_set(zend_mm_bitset *bitset, int bit) { - return (bitset[bit / ZEND_MM_BITSET_LEN] & (Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)))) != 0; + return ZEND_BIT_TEST(bitset, bit); } static zend_always_inline void zend_mm_bitset_set_bit(zend_mm_bitset *bitset, int bit) diff --git a/Zend/zend_bitset.h b/Zend/zend_bitset.h index 65959381d9..eb602800a7 100644 --- a/Zend/zend_bitset.h +++ b/Zend/zend_bitset.h @@ -86,7 +86,7 @@ static inline uint32_t zend_bitset_len(uint32_t n) static inline zend_bool zend_bitset_in(zend_bitset set, uint32_t n) { - return (set[ZEND_BITSET_ELM_NUM(n)] & (Z_UL(1) << ZEND_BITSET_BIT_NUM(n))) != Z_UL(0); + return ZEND_BIT_TEST(set, n); } static inline void zend_bitset_incl(zend_bitset set, uint32_t n) diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 4bbe023bdf..0bef8dd374 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -442,6 +442,13 @@ char *alloca(); #define MAX(a, b) (((a)>(b))?(a):(b)) #define MIN(a, b) (((a)<(b))?(a):(b)) +/* x86 instructions BT, SHL, SHR don't require masking */ +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +# define ZEND_BIT_TEST(bits, bit) (((bits)[(bit) / (sizeof((bits)[0])*8)] >> (bit)) & 1) +#else +# define ZEND_BIT_TEST(bits, bit) (((bits)[(bit) / (sizeof((bits)[0])*8)] >> ((bit) & (sizeof((bits)[0])*8-1))) & 1) +#endif + /* We always define a function, even if there's a macro or expression we could * alias, so that using it in contexts where we can't make function calls * won't fail to compile on some machines and not others. diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 3ec12b8968..f28bfbd4e4 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -350,7 +350,7 @@ static int php_json_escape_string( 0xffffffff, 0x500080c4, 0x10000000, 0x00000000}; pos++; - if (EXPECTED(!((charmap[us >> 5] >> (us & 0x1f)) & 1))) { + if (EXPECTED(!ZEND_BIT_TEST(charmap, us))) { smart_str_appendc(buf, (unsigned char) us); } else { switch (us) { diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c index 653197e302..b436f23ac0 100644 --- a/ext/mysqlnd/mysqlnd_result.c +++ b/ext/mysqlnd/mysqlnd_result.c @@ -108,7 +108,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, initialize_result_set_rest)(MYSQLND_RE for (i = 0; i < result->row_count; i++) { /* (i / 8) & the_bit_for_i*/ - if ((initialized[i >> 3] >> (i & 7)) & 1) { + if (ZEND_BIT_TEST(initialized, i)) { continue; } @@ -1151,7 +1151,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_row)(MYSQLND_RES * result, void if (rc != PASS) { DBG_RETURN(FAIL); } - if (!((set->initialized[set->current_row >> 3] >> (set->current_row & 7)) & 1)) { + if (!ZEND_BIT_TEST(set->initialized, set->current_row)) { set->initialized[set->current_row >> 3] |= (1 << (set->current_row & 7)); /* mark initialized */ ++set->initialized_rows; diff --git a/ext/standard/array.c b/ext/standard/array.c index cfd29378a0..7621b0616a 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1660,14 +1660,14 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va { #if 1 /* first 256 bits for first character, and second 256 bits for the next */ - static const uint32_t charset[16] = { + static const uint32_t charset[8] = { /* 31 0 63 32 95 64 127 96 */ 0x00000000, 0x00000000, 0x87fffffe, 0x07fffffe, - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; + static const uint32_t charset2[8] = { /* 31 0 63 32 95 64 127 96 */ 0x00000000, 0x03ff0000, 0x87fffffe, 0x07fffffe, - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff - }; + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; #endif size_t i; uint32_t ch; @@ -1679,7 +1679,7 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va /* These are allowed as first char: [a-zA-Z_\x7f-\xff] */ ch = (uint32_t)((unsigned char *)var_name)[0]; #if 1 - if (UNEXPECTED(!((charset[ch >> 5] >> (ch & 0x1f)) & 1))) { + if (UNEXPECTED(!ZEND_BIT_TEST(charset, ch))) { #else if (var_name[0] != '_' && (ch < 65 /* A */ || /* Z */ ch > 90) && @@ -1696,7 +1696,7 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va do { ch = (uint32_t)((unsigned char *)var_name)[i]; #if 1 - if (UNEXPECTED(!((charset[8 + (ch >> 5)] >> (ch & 0x1f)) & 1))) { + if (UNEXPECTED(!ZEND_BIT_TEST(charset2, ch))) { #else if (var_name[i] != '_' && (ch < 48 /* 0 */ || /* 9 */ ch > 57) && |