PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_operators.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 144 150 96.0 %
Date: 2015-09-02 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #ifndef ZEND_OPERATORS_H
      24             : #define ZEND_OPERATORS_H
      25             : 
      26             : #include <errno.h>
      27             : #include <math.h>
      28             : #include <assert.h>
      29             : 
      30             : #ifdef __GNUC__
      31             : #include <stddef.h>
      32             : #endif
      33             : 
      34             : #ifdef HAVE_IEEEFP_H
      35             : #include <ieeefp.h>
      36             : #endif
      37             : 
      38             : #include "zend_strtod.h"
      39             : #include "zend_multiply.h"
      40             : 
      41             : #if 0&&HAVE_BCMATH
      42             : #include "ext/bcmath/libbcmath/src/bcmath.h"
      43             : #endif
      44             : 
      45             : #define LONG_SIGN_MASK (((zend_long)1) << (8*sizeof(zend_long)-1))
      46             : 
      47             : BEGIN_EXTERN_C()
      48             : ZEND_API int ZEND_FASTCALL add_function(zval *result, zval *op1, zval *op2);
      49             : ZEND_API int ZEND_FASTCALL sub_function(zval *result, zval *op1, zval *op2);
      50             : ZEND_API int ZEND_FASTCALL mul_function(zval *result, zval *op1, zval *op2);
      51             : ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2);
      52             : ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2);
      53             : ZEND_API int ZEND_FASTCALL mod_function(zval *result, zval *op1, zval *op2);
      54             : ZEND_API int ZEND_FASTCALL boolean_xor_function(zval *result, zval *op1, zval *op2);
      55             : ZEND_API int ZEND_FASTCALL boolean_not_function(zval *result, zval *op1);
      56             : ZEND_API int ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1);
      57             : ZEND_API int ZEND_FASTCALL bitwise_or_function(zval *result, zval *op1, zval *op2);
      58             : ZEND_API int ZEND_FASTCALL bitwise_and_function(zval *result, zval *op1, zval *op2);
      59             : ZEND_API int ZEND_FASTCALL bitwise_xor_function(zval *result, zval *op1, zval *op2);
      60             : ZEND_API int ZEND_FASTCALL shift_left_function(zval *result, zval *op1, zval *op2);
      61             : ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *op2);
      62             : ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2);
      63             : 
      64             : ZEND_API int ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2);
      65             : 
      66             : ZEND_API int ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2);
      67             : ZEND_API int ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2);
      68             : ZEND_API int ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zval *op2);
      69             : ZEND_API int ZEND_FASTCALL is_not_equal_function(zval *result, zval *op1, zval *op2);
      70             : ZEND_API int ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op2);
      71             : ZEND_API int ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval *op1, zval *op2);
      72             : 
      73             : ZEND_API zend_bool ZEND_FASTCALL instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only);
      74             : ZEND_API zend_bool ZEND_FASTCALL instanceof_function(const zend_class_entry *instance_ce, const zend_class_entry *ce);
      75             : 
      76             : /**
      77             :  * Checks whether the string "str" with length "length" is numeric. The value
      78             :  * of allow_errors determines whether it's required to be entirely numeric, or
      79             :  * just its prefix. Leading whitespace is allowed.
      80             :  *
      81             :  * The function returns 0 if the string did not contain a valid number; IS_LONG
      82             :  * if it contained a number that fits within the range of a long; or IS_DOUBLE
      83             :  * if the number was out of long range or contained a decimal point/exponent.
      84             :  * The number's value is returned into the respective pointer, *lval or *dval,
      85             :  * if that pointer is not NULL.
      86             :  *
      87             :  * This variant also gives information if a string that represents an integer
      88             :  * could not be represented as such due to overflow. It writes 1 to oflow_info
      89             :  * if the integer is larger than ZEND_LONG_MAX and -1 if it's smaller than ZEND_LONG_MIN.
      90             :  */
      91             : ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors, int *oflow_info);
      92             : 
      93             : ZEND_API const char* ZEND_FASTCALL zend_memnstr_ex(const char *haystack, const char *needle, size_t needle_len, const char *end);
      94             : ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const char *needle, size_t needle_len, const char *end);
      95             : 
      96             : #if SIZEOF_ZEND_LONG == 4
      97             : #       define ZEND_DOUBLE_FITS_LONG(d) (!((d) > ZEND_LONG_MAX || (d) < ZEND_LONG_MIN))
      98             : #else
      99             :         /* >= as (double)ZEND_LONG_MAX is outside signed range */
     100             : #       define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= ZEND_LONG_MAX || (d) < ZEND_LONG_MIN))
     101             : #endif
     102             : 
     103             : #if ZEND_DVAL_TO_LVAL_CAST_OK
     104             : static zend_always_inline zend_long zend_dval_to_lval(double d)
     105             : {
     106             :     if (EXPECTED(zend_finite(d)) && EXPECTED(!zend_isnan(d))) {
     107             :         return (zend_long)d;
     108             :     } else {
     109             :         return 0;
     110             :     }
     111             : }
     112             : #else
     113             : ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d);
     114             : 
     115             : static zend_always_inline zend_long zend_dval_to_lval(double d)
     116             : {
     117       28379 :         if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
     118           7 :                 return 0;
     119       28372 :         } else if (!ZEND_DOUBLE_FITS_LONG(d)) {
     120         140 :                 return zend_dval_to_lval_slow(d);
     121             :         }
     122       28232 :         return (zend_long)d;
     123             : }
     124             : #endif
     125             : /* }}} */
     126             : 
     127             : #define ZEND_IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
     128             : #define ZEND_IS_XDIGIT(c) (((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
     129             : 
     130             : static zend_always_inline zend_uchar is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors, int *oflow_info)
     131             : {
     132     1101171 :         if (*str > '9') {
     133      138140 :                 return 0;
     134             :         }
     135      963031 :         return _is_numeric_string_ex(str, length, lval, dval, allow_errors, oflow_info);
     136             : }
     137             : 
     138             : static zend_always_inline zend_uchar is_numeric_string(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors) {
     139      157383 :     return is_numeric_string_ex(str, length, lval, dval, allow_errors, NULL);
     140             : }
     141             : 
     142             : ZEND_API zend_uchar ZEND_FASTCALL is_numeric_str_function(const zend_string *str, zend_long *lval, double *dval);
     143             : 
     144             : static zend_always_inline const char *
     145             : zend_memnstr(const char *haystack, const char *needle, size_t needle_len, const char *end)
     146             : {
     147     2755269 :         const char *p = haystack;
     148     2755269 :         const char ne = needle[needle_len-1];
     149             :         ptrdiff_t off_p;
     150             :         size_t off_s;
     151             : 
     152     2755269 :         if (needle_len == 1) {
     153     1914009 :                 return (const char *)memchr(p, *needle, (end-p));
     154             :         }
     155             : 
     156      841260 :         off_p = end - haystack;
     157      841260 :         off_s = (off_p > 0) ? (size_t)off_p : 0;
     158             : 
     159      841260 :         if (needle_len > off_s) {
     160       10638 :                 return NULL;
     161             :         }
     162             : 
     163      830622 :         if (EXPECTED(off_s < 1024 || needle_len < 3)) {
     164      815675 :                 end -= needle_len;
     165             : 
     166     3696687 :                 while (p <= end) {
     167     3618976 :                         if ((p = (const char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
     168      562928 :                                 if (!memcmp(needle, p, needle_len-1)) {
     169      212675 :                                         return p;
     170             :                                 }
     171             :                         }
     172             : 
     173     3406301 :                         if (p == NULL) {
     174      525289 :                                 return NULL;
     175             :                         }
     176             : 
     177     2881012 :                         p++;
     178             :                 }
     179             : 
     180       77711 :                 return NULL;
     181             :         } else {
     182       14947 :                 return zend_memnstr_ex(haystack, needle, needle_len, end);
     183             :         }
     184             : }
     185             : 
     186             : static zend_always_inline const void *zend_memrchr(const void *s, int c, size_t n)
     187             : {
     188             :         register const unsigned char *e;
     189     3551742 :         if (n <= 0) {
     190         443 :                 return NULL;
     191             :         }
     192             : 
     193    62343685 :         for (e = (const unsigned char *)s + n - 1; e >= (const unsigned char *)s; e--) {
     194    58830176 :                 if (*e == (const unsigned char)c) {
     195       37790 :                         return (const void *)e;
     196             :                 }
     197             :         }
     198     3513509 :         return NULL;
     199             : }
     200             : 
     201             : 
     202             : static zend_always_inline const char *
     203             : zend_memnrstr(const char *haystack, const char *needle, size_t needle_len, char *end)
     204             : {
     205         575 :     const char *p = end;
     206         575 :     const char ne = needle[needle_len-1];
     207             :     ptrdiff_t off_p;
     208             :     size_t off_s;
     209             : 
     210         575 :     if (needle_len == 1) {
     211         480 :         return (const char *)zend_memrchr(haystack, *needle, (p - haystack));
     212             :     }
     213             : 
     214         335 :     off_p = end - haystack;
     215         335 :     off_s = (off_p > 0) ? (size_t)off_p : 0;
     216             : 
     217         335 :     if (needle_len > off_s) {
     218          29 :         return NULL;
     219             :     }
     220             : 
     221         306 :         if (EXPECTED(off_s < 1024 || needle_len < 3)) {
     222         306 :                 p -= needle_len;
     223             : 
     224             :                 do {
     225        1180 :                         if ((p = (const char *)zend_memrchr(haystack, *needle, (p - haystack) + 1)) && ne == p[needle_len-1]) {
     226         236 :                                 if (!memcmp(needle, p, needle_len - 1)) {
     227         208 :                                         return p;
     228             :                                 }
     229             :                         }
     230         382 :                 } while (p-- >= haystack);
     231             : 
     232          98 :                 return NULL;
     233             :         } else {
     234           0 :                 return zend_memnrstr_ex(haystack, needle, needle_len, end);
     235             :         }
     236             : }
     237             : 
     238             : ZEND_API int ZEND_FASTCALL increment_function(zval *op1);
     239             : ZEND_API int ZEND_FASTCALL decrement_function(zval *op2);
     240             : 
     241             : ZEND_API void ZEND_FASTCALL convert_scalar_to_number(zval *op);
     242             : ZEND_API void ZEND_FASTCALL _convert_to_cstring(zval *op ZEND_FILE_LINE_DC);
     243             : ZEND_API void ZEND_FASTCALL _convert_to_string(zval *op ZEND_FILE_LINE_DC);
     244             : ZEND_API void ZEND_FASTCALL convert_to_long(zval *op);
     245             : ZEND_API void ZEND_FASTCALL convert_to_double(zval *op);
     246             : ZEND_API void ZEND_FASTCALL convert_to_long_base(zval *op, int base);
     247             : ZEND_API void ZEND_FASTCALL convert_to_null(zval *op);
     248             : ZEND_API void ZEND_FASTCALL convert_to_boolean(zval *op);
     249             : ZEND_API void ZEND_FASTCALL convert_to_array(zval *op);
     250             : ZEND_API void ZEND_FASTCALL convert_to_object(zval *op);
     251             : ZEND_API void multi_convert_to_long_ex(int argc, ...);
     252             : ZEND_API void multi_convert_to_double_ex(int argc, ...);
     253             : ZEND_API void multi_convert_to_string_ex(int argc, ...);
     254             : 
     255             : ZEND_API zend_long    ZEND_FASTCALL _zval_get_long_func(zval *op);
     256             : ZEND_API double       ZEND_FASTCALL _zval_get_double_func(zval *op);
     257             : ZEND_API zend_string* ZEND_FASTCALL _zval_get_string_func(zval *op);
     258             : 
     259             : static zend_always_inline zend_long _zval_get_long(zval *op) {
     260      346623 :         return Z_TYPE_P(op) == IS_LONG ? Z_LVAL_P(op) : _zval_get_long_func(op);
     261             : }
     262             : static zend_always_inline double _zval_get_double(zval *op) {
     263      207424 :         return Z_TYPE_P(op) == IS_DOUBLE ? Z_DVAL_P(op) : _zval_get_double_func(op);
     264             : }
     265             : static zend_always_inline zend_string *_zval_get_string(zval *op) {
     266     6701117 :         return Z_TYPE_P(op) == IS_STRING ? zend_string_copy(Z_STR_P(op)) : _zval_get_string_func(op);
     267             : }
     268             : 
     269             : #define zval_get_long(op) _zval_get_long((op))
     270             : #define zval_get_double(op) _zval_get_double((op))
     271             : #define zval_get_string(op) _zval_get_string((op))
     272             : 
     273             : #define convert_to_cstring(op) if (Z_TYPE_P(op) != IS_STRING) { _convert_to_cstring((op) ZEND_FILE_LINE_CC); }
     274             : #define convert_to_string(op) if (Z_TYPE_P(op) != IS_STRING) { _convert_to_string((op) ZEND_FILE_LINE_CC); }
     275             : 
     276             : 
     277             : ZEND_API int ZEND_FASTCALL zend_is_true(zval *op);
     278             : ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op);
     279             : 
     280             : #define zval_is_true(op) \
     281             :         zend_is_true(op)
     282             : 
     283             : static zend_always_inline int i_zend_is_true(zval *op)
     284             : {
     285             :         int result;
     286             : 
     287             : again:
     288     2843651 :         switch (Z_TYPE_P(op)) {
     289             :                 case IS_UNDEF:
     290             :                 case IS_NULL:
     291             :                 case IS_FALSE:
     292      124644 :                         result = 0;
     293             :                         break;
     294             :                 case IS_TRUE:
     295      170802 :                         result = 1;
     296             :                         break;
     297             :                 case IS_LONG:
     298     1996709 :                         result = (Z_LVAL_P(op)?1:0);
     299             :                         break;
     300             :                 case IS_RESOURCE:
     301       42920 :                         result = (Z_RES_HANDLE_P(op)?1:0);
     302             :                         break;
     303             :                 case IS_DOUBLE:
     304         265 :                         result = (Z_DVAL_P(op) ? 1 : 0);
     305             :                         break;
     306             :                 case IS_STRING:
     307      237949 :                         if (Z_STRLEN_P(op) == 0
     308      142656 :                                 || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
     309       48530 :                                 result = 0;
     310             :                         } else {
     311       46763 :                                 result = 1;
     312             :                         }
     313             :                         break;
     314             :                 case IS_ARRAY:
     315      100120 :                         result = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
     316             :                         break;
     317             :                 case IS_OBJECT:
     318       92396 :                         result = zend_object_is_true(op);
     319             :                         break;
     320             :                 case IS_REFERENCE:
     321      220502 :                         op = Z_REFVAL_P(op);
     322             :                         goto again;
     323             :                         break;
     324             :                 default:
     325           0 :                         result = 0;
     326             :                         break;
     327             :         }
     328     2623148 :         return result;
     329             : }
     330             : 
     331             : ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2);
     332             : ZEND_API int zval_compare_function(zval *result, zval *op1, zval *op2);
     333             : ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2);
     334             : ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive);
     335             : ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2);
     336             : ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2);
     337             : #if HAVE_STRCOLL
     338             : ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2);
     339             : #endif
     340             : 
     341             : ZEND_API void         ZEND_FASTCALL zend_str_tolower(char *str, size_t length);
     342             : ZEND_API char*        ZEND_FASTCALL zend_str_tolower_copy(char *dest, const char *source, size_t length);
     343             : ZEND_API char*        ZEND_FASTCALL zend_str_tolower_dup(const char *source, size_t length);
     344             : ZEND_API char*        ZEND_FASTCALL zend_str_tolower_dup_ex(const char *source, size_t length);
     345             : ZEND_API zend_string* ZEND_FASTCALL zend_string_tolower(zend_string *str);
     346             : 
     347             : ZEND_API int ZEND_FASTCALL zend_binary_zval_strcmp(zval *s1, zval *s2);
     348             : ZEND_API int ZEND_FASTCALL zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
     349             : ZEND_API int ZEND_FASTCALL zend_binary_zval_strcasecmp(zval *s1, zval *s2);
     350             : ZEND_API int ZEND_FASTCALL zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
     351             : ZEND_API int ZEND_FASTCALL zend_binary_strcmp(const char *s1, size_t len1, const char *s2, size_t len2);
     352             : ZEND_API int ZEND_FASTCALL zend_binary_strncmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
     353             : ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp(const char *s1, size_t len1, const char *s2, size_t len2);
     354             : ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
     355             : ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2);
     356             : ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
     357             : 
     358             : ZEND_API zend_long ZEND_FASTCALL zendi_smart_strcmp(zval *s1, zval *s2);
     359             : ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2);
     360             : ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2);
     361             : ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2);
     362             : 
     363             : ZEND_API int ZEND_FASTCALL zend_atoi(const char *str, int str_len);
     364             : ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, int str_len);
     365             : 
     366             : ZEND_API void ZEND_FASTCALL zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC);
     367             : 
     368             : #define convert_to_ex_master(pzv, lower_type, upper_type)       \
     369             :         if (Z_TYPE_P(pzv)!=upper_type) {                                        \
     370             :                 convert_to_##lower_type(pzv);                                           \
     371             :         }
     372             : 
     373             : #define convert_to_explicit_type(pzv, type)             \
     374             :         do {                                                                            \
     375             :                 switch (type) {                                                 \
     376             :                         case IS_NULL:                                           \
     377             :                                 convert_to_null(pzv);                   \
     378             :                                 break;                                                  \
     379             :                         case IS_LONG:                                           \
     380             :                                 convert_to_long(pzv);                   \
     381             :                                 break;                                                  \
     382             :                         case IS_DOUBLE:                                         \
     383             :                                 convert_to_double(pzv);                 \
     384             :                                 break;                                                  \
     385             :                         case _IS_BOOL:                                          \
     386             :                                 convert_to_boolean(pzv);                \
     387             :                                 break;                                                  \
     388             :                         case IS_ARRAY:                                          \
     389             :                                 convert_to_array(pzv);                  \
     390             :                                 break;                                                  \
     391             :                         case IS_OBJECT:                                         \
     392             :                                 convert_to_object(pzv);                 \
     393             :                                 break;                                                  \
     394             :                         case IS_STRING:                                         \
     395             :                                 convert_to_string(pzv);                 \
     396             :                                 break;                                                  \
     397             :                         default:                                                        \
     398             :                                 assert(0);                                              \
     399             :                                 break;                                                  \
     400             :                 }                                                                               \
     401             :         } while (0);
     402             : 
     403             : #define convert_to_explicit_type_ex(pzv, str_type)      \
     404             :         if (Z_TYPE_P(pzv) != str_type) {                                \
     405             :                 convert_to_explicit_type(pzv, str_type);        \
     406             :         }
     407             : 
     408             : #define convert_to_boolean_ex(pzv)      convert_to_ex_master(pzv, boolean, _IS_BOOL)
     409             : #define convert_to_long_ex(pzv)         convert_to_ex_master(pzv, long, IS_LONG)
     410             : #define convert_to_double_ex(pzv)       convert_to_ex_master(pzv, double, IS_DOUBLE)
     411             : #define convert_to_string_ex(pzv)       convert_to_ex_master(pzv, string, IS_STRING)
     412             : #define convert_to_array_ex(pzv)        convert_to_ex_master(pzv, array, IS_ARRAY)
     413             : #define convert_to_object_ex(pzv)       convert_to_ex_master(pzv, object, IS_OBJECT)
     414             : #define convert_to_null_ex(pzv)         convert_to_ex_master(pzv, null, IS_NULL)
     415             : 
     416             : #define convert_scalar_to_number_ex(pzv)                                                        \
     417             :         if (Z_TYPE_P(pzv)!=IS_LONG && Z_TYPE_P(pzv)!=IS_DOUBLE) {               \
     418             :                 convert_scalar_to_number(pzv);                                  \
     419             :         }
     420             : 
     421             : #if HAVE_SETLOCALE && defined(ZEND_WIN32) && !defined(ZTS) && defined(_MSC_VER)
     422             : /* This performance improvement of tolower() on Windows gives 10-18% on bench.php */
     423             : #define ZEND_USE_TOLOWER_L 1
     424             : #endif
     425             : 
     426             : #ifdef ZEND_USE_TOLOWER_L
     427             : ZEND_API void zend_update_current_locale(void);
     428             : #else
     429             : #define zend_update_current_locale()
     430             : #endif
     431             : 
     432             : /* The offset in bytes between the value and type fields of a zval */
     433             : #define ZVAL_OFFSETOF_TYPE      \
     434             :         (offsetof(zval, u1.type_info) - offsetof(zval, value))
     435             : 
     436             : static zend_always_inline void fast_long_increment_function(zval *op1)
     437             : {
     438             : #if defined(__GNUC__) && defined(__i386__)
     439             :         __asm__(
     440             :                 "incl (%0)\n\t"
     441             :                 "jno  0f\n\t"
     442             :                 "movl $0x0, (%0)\n\t"
     443             :                 "movl $0x41e00000, 0x4(%0)\n\t"
     444             :                 "movl %1, %c2(%0)\n"
     445             :                 "0:"
     446             :                 :
     447             :                 : "r"(&op1->value),
     448             :                   "n"(IS_DOUBLE),
     449             :                   "n"(ZVAL_OFFSETOF_TYPE)
     450             :                 : "cc");
     451             : #elif defined(__GNUC__) && defined(__x86_64__)
     452     7255395 :         __asm__(
     453             :                 "incq (%0)\n\t"
     454             :                 "jno  0f\n\t"
     455             :                 "movl $0x0, (%0)\n\t"
     456             :                 "movl $0x43e00000, 0x4(%0)\n\t"
     457             :                 "movl %1, %c2(%0)\n"
     458             :                 "0:"
     459             :                 :
     460     7255395 :                 : "r"(&op1->value),
     461             :                   "n"(IS_DOUBLE),
     462             :                   "n"(ZVAL_OFFSETOF_TYPE)
     463             :                 : "cc");
     464             : #else
     465             :         if (UNEXPECTED(Z_LVAL_P(op1) == ZEND_LONG_MAX)) {
     466             :                 /* switch to double */
     467             :                 ZVAL_DOUBLE(op1, (double)ZEND_LONG_MAX + 1.0);
     468             :         } else {
     469             :                 Z_LVAL_P(op1)++;
     470             :         }
     471             : #endif
     472             : }
     473             : 
     474             : static zend_always_inline void fast_long_decrement_function(zval *op1)
     475             : {
     476             : #if defined(__GNUC__) && defined(__i386__)
     477             :         __asm__(
     478             :                 "decl (%0)\n\t"
     479             :                 "jno  0f\n\t"
     480             :                 "movl $0x00200000, (%0)\n\t"
     481             :                 "movl $0xc1e00000, 0x4(%0)\n\t"
     482             :                 "movl %1,%c2(%0)\n"
     483             :                 "0:"
     484             :                 :
     485             :                 : "r"(&op1->value),
     486             :                   "n"(IS_DOUBLE),
     487             :                   "n"(ZVAL_OFFSETOF_TYPE)
     488             :                 : "cc");
     489             : #elif defined(__GNUC__) && defined(__x86_64__)
     490      237762 :         __asm__(
     491             :                 "decq (%0)\n\t"
     492             :                 "jno  0f\n\t"
     493             :                 "movl $0x00000000, (%0)\n\t"
     494             :                 "movl $0xc3e00000, 0x4(%0)\n\t"
     495             :                 "movl %1,%c2(%0)\n"
     496             :                 "0:"
     497             :                 :
     498      237762 :                 : "r"(&op1->value),
     499             :                   "n"(IS_DOUBLE),
     500             :                   "n"(ZVAL_OFFSETOF_TYPE)
     501             :                 : "cc");
     502             : #else
     503             :         if (UNEXPECTED(Z_LVAL_P(op1) == ZEND_LONG_MIN)) {
     504             :                 /* switch to double */
     505             :                 ZVAL_DOUBLE(op1, (double)ZEND_LONG_MIN - 1.0);
     506             :         } else {
     507             :                 Z_LVAL_P(op1)--;
     508             :         }
     509             : #endif
     510             : }
     511             : 
     512             : static zend_always_inline void fast_long_add_function(zval *result, zval *op1, zval *op2)
     513             : {
     514             : #if defined(__GNUC__) && defined(__i386__) && !(4 == __GNUC__ && 8 == __GNUC_MINOR__)
     515             :         __asm__(
     516             :                 "movl      (%1), %%eax\n\t"
     517             :                 "addl   (%2), %%eax\n\t"
     518             :                 "jo     0f\n\t"
     519             :                 "movl   %%eax, (%0)\n\t"
     520             :                 "movl   %3, %c5(%0)\n\t"
     521             :                 "jmp    1f\n"
     522             :                 "0:\n\t"
     523             :                 "fildl     (%1)\n\t"
     524             :                 "fildl     (%2)\n\t"
     525             :                 "faddp     %%st, %%st(1)\n\t"
     526             :                 "movl   %4, %c5(%0)\n\t"
     527             :                 "fstpl     (%0)\n"
     528             :                 "1:"
     529             :                 :
     530             :                 : "r"(&result->value),
     531             :                   "r"(&op1->value),
     532             :                   "r"(&op2->value),
     533             :                   "n"(IS_LONG),
     534             :                   "n"(IS_DOUBLE),
     535             :                   "n"(ZVAL_OFFSETOF_TYPE)
     536             :                 : "eax","cc");
     537             : #elif defined(__GNUC__) && defined(__x86_64__)
     538      699833 :         __asm__(
     539             :                 "movq      (%1), %%rax\n\t"
     540             :                 "addq   (%2), %%rax\n\t"
     541             :                 "jo     0f\n\t"
     542             :                 "movq   %%rax, (%0)\n\t"
     543             :                 "movl   %3, %c5(%0)\n\t"
     544             :                 "jmp    1f\n"
     545             :                 "0:\n\t"
     546             :                 "fildq     (%1)\n\t"
     547             :                 "fildq     (%2)\n\t"
     548             :                 "faddp     %%st, %%st(1)\n\t"
     549             :                 "movl   %4, %c5(%0)\n\t"
     550             :                 "fstpl     (%0)\n"
     551             :                 "1:"
     552             :                 :
     553      699833 :                 : "r"(&result->value),
     554      699833 :                   "r"(&op1->value),
     555      699833 :                   "r"(&op2->value),
     556             :                   "n"(IS_LONG),
     557             :                   "n"(IS_DOUBLE),
     558             :                   "n"(ZVAL_OFFSETOF_TYPE)
     559             :                 : "rax","cc");
     560             : #else
     561             :         /*
     562             :          * 'result' may alias with op1 or op2, so we need to
     563             :          * ensure that 'result' is not updated until after we
     564             :          * have read the values of op1 and op2.
     565             :          */
     566             : 
     567             :         if (UNEXPECTED((Z_LVAL_P(op1) & LONG_SIGN_MASK) == (Z_LVAL_P(op2) & LONG_SIGN_MASK)
     568             :                 && (Z_LVAL_P(op1) & LONG_SIGN_MASK) != ((Z_LVAL_P(op1) + Z_LVAL_P(op2)) & LONG_SIGN_MASK))) {
     569             :                 ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
     570             :         } else {
     571             :                 ZVAL_LONG(result, Z_LVAL_P(op1) + Z_LVAL_P(op2));
     572             :         }
     573             : #endif
     574             : }
     575             : 
     576             : static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *op2)
     577             : {
     578      202150 :         if (EXPECTED(Z_TYPE_P(op1) == IS_LONG)) {
     579      202106 :                 if (EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
     580             :                         fast_long_add_function(result, op1, op2);
     581      202097 :                         return SUCCESS;
     582           9 :                 } else if (EXPECTED(Z_TYPE_P(op2) == IS_DOUBLE)) {
     583           9 :                         ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) + Z_DVAL_P(op2));
     584           9 :                         return SUCCESS;
     585             :                 }
     586          44 :         } else if (EXPECTED(Z_TYPE_P(op1) == IS_DOUBLE)) {
     587          44 :                 if (EXPECTED(Z_TYPE_P(op2) == IS_DOUBLE)) {
     588          35 :                         ZVAL_DOUBLE(result, Z_DVAL_P(op1) + Z_DVAL_P(op2));
     589          35 :                         return SUCCESS;
     590           9 :                 } else if (EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
     591           9 :                         ZVAL_DOUBLE(result, Z_DVAL_P(op1) + ((double)Z_LVAL_P(op2)));
     592           9 :                         return SUCCESS;
     593             :                 }
     594             :         }
     595           0 :         return add_function(result, op1, op2);
     596             : }
     597             : 
     598             : static zend_always_inline void fast_long_sub_function(zval *result, zval *op1, zval *op2)
     599             : {
     600             : #if defined(__GNUC__) && defined(__i386__) && !(4 == __GNUC__ && 8 == __GNUC_MINOR__)
     601             :         __asm__(
     602             :                 "movl      (%1), %%eax\n\t"
     603             :                 "subl   (%2), %%eax\n\t"
     604             :                 "jo     0f\n\t"
     605             :                 "movl   %%eax, (%0)\n\t"
     606             :                 "movl   %3, %c5(%0)\n\t"
     607             :                 "jmp    1f\n"
     608             :                 "0:\n\t"
     609             :                 "fildl     (%2)\n\t"
     610             :                 "fildl     (%1)\n\t"
     611             : #if defined(__clang__) && (__clang_major__ < 2 || (__clang_major__ == 2 && __clang_minor__ < 10))
     612             :                 "fsubp  %%st(1), %%st\n\t"  /* LLVM bug #9164 */
     613             : #else
     614             :                 "fsubp     %%st, %%st(1)\n\t"
     615             : #endif
     616             :                 "movl   %4, %c5(%0)\n\t"
     617             :                 "fstpl     (%0)\n"
     618             :                 "1:"
     619             :                 :
     620             :                 : "r"(&result->value),
     621             :                   "r"(&op1->value),
     622             :                   "r"(&op2->value),
     623             :                   "n"(IS_LONG),
     624             :                   "n"(IS_DOUBLE),
     625             :                   "n"(ZVAL_OFFSETOF_TYPE)
     626             :                 : "eax","cc");
     627             : #elif defined(__GNUC__) && defined(__x86_64__)
     628      317555 :         __asm__(
     629             :                 "movq      (%1), %%rax\n\t"
     630             :                 "subq   (%2), %%rax\n\t"
     631             :                 "jo     0f\n\t"
     632             :                 "movq   %%rax, (%0)\n\t"
     633             :                 "movl   %3, %c5(%0)\n\t"
     634             :                 "jmp    1f\n"
     635             :                 "0:\n\t"
     636             :                 "fildq     (%2)\n\t"
     637             :                 "fildq     (%1)\n\t"
     638             : #if defined(__clang__) && (__clang_major__ < 2 || (__clang_major__ == 2 && __clang_minor__ < 10))
     639             :                 "fsubp  %%st(1), %%st\n\t"  /* LLVM bug #9164 */
     640             : #else
     641             :                 "fsubp     %%st, %%st(1)\n\t"
     642             : #endif
     643             :                 "movl   %4, %c5(%0)\n\t"
     644             :                 "fstpl     (%0)\n"
     645             :                 "1:"
     646             :                 :
     647      317555 :                 : "r"(&result->value),
     648      317555 :                   "r"(&op1->value),
     649      317555 :                   "r"(&op2->value),
     650             :                   "n"(IS_LONG),
     651             :                   "n"(IS_DOUBLE),
     652             :                   "n"(ZVAL_OFFSETOF_TYPE)
     653             :                 : "rax","cc");
     654             : #else
     655             :         ZVAL_LONG(result, Z_LVAL_P(op1) - Z_LVAL_P(op2));
     656             : 
     657             :         if (UNEXPECTED((Z_LVAL_P(op1) & LONG_SIGN_MASK) != (Z_LVAL_P(op2) & LONG_SIGN_MASK)
     658             :                 && (Z_LVAL_P(op1) & LONG_SIGN_MASK) != (Z_LVAL_P(result) & LONG_SIGN_MASK))) {
     659             :                 ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
     660             :         }
     661             : #endif
     662             : }
     663             : 
     664             : static zend_always_inline int fast_div_function(zval *result, zval *op1, zval *op2)
     665             : {
     666      124645 :         return div_function(result, op1, op2);
     667             : }
     668             : 
     669             : static zend_always_inline int fast_equal_check_function(zval *op1, zval *op2)
     670             : {
     671             :         zval result;
     672       14403 :         if (EXPECTED(Z_TYPE_P(op1) == IS_LONG)) {
     673          21 :                 if (EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
     674           0 :                         return Z_LVAL_P(op1) == Z_LVAL_P(op2);
     675          21 :                 } else if (EXPECTED(Z_TYPE_P(op2) == IS_DOUBLE)) {
     676           0 :                         return ((double)Z_LVAL_P(op1)) == Z_DVAL_P(op2);
     677             :                 }
     678       14382 :         } else if (EXPECTED(Z_TYPE_P(op1) == IS_DOUBLE)) {
     679         316 :                 if (EXPECTED(Z_TYPE_P(op2) == IS_DOUBLE)) {
     680          16 :                         return Z_DVAL_P(op1) == Z_DVAL_P(op2);
     681         300 :                 } else if (EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
     682         128 :                         return Z_DVAL_P(op1) == ((double)Z_LVAL_P(op2));
     683             :                 }
     684       14066 :         } else if (EXPECTED(Z_TYPE_P(op1) == IS_STRING)) {
     685          35 :                 if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
     686          25 :                         if (Z_STR_P(op1) == Z_STR_P(op2)) {
     687           0 :                                 return 1;
     688          25 :                         } else if (Z_STRVAL_P(op1)[0] > '9' || Z_STRVAL_P(op2)[0] > '9') {
     689           9 :                                 if (Z_STRLEN_P(op1) != Z_STRLEN_P(op2)) {
     690           8 :                                         return 0;
     691             :                                 } else {
     692           1 :                                         return memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0;
     693             :                                 }
     694             :                         } else {
     695          16 :                                 return zendi_smart_strcmp(op1, op2) == 0;
     696             :                         }
     697             :                 }
     698             :         }
     699       14234 :         compare_function(&result, op1, op2);
     700       14234 :         return Z_LVAL(result) == 0;
     701             : }
     702             : 
     703             : static zend_always_inline int fast_equal_check_long(zval *op1, zval *op2)
     704             : {
     705             :         zval result;
     706        8063 :         if (EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
     707        7862 :                 return Z_LVAL_P(op1) == Z_LVAL_P(op2);
     708             :         }
     709         201 :         compare_function(&result, op1, op2);
     710         201 :         return Z_LVAL(result) == 0;
     711             : }
     712             : 
     713             : static zend_always_inline int fast_equal_check_string(zval *op1, zval *op2)
     714             : {
     715             :         zval result;
     716      477605 :         if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
     717      476954 :                 if (Z_STR_P(op1) == Z_STR_P(op2)) {
     718          46 :                         return 1;
     719      476908 :                 } else if (Z_STRVAL_P(op1)[0] > '9' || Z_STRVAL_P(op2)[0] > '9') {
     720      472962 :                         if (Z_STRLEN_P(op1) != Z_STRLEN_P(op2)) {
     721      431518 :                                 return 0;
     722             :                         } else {
     723       41444 :                                 return memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1)) == 0;
     724             :                         }
     725             :                 } else {
     726        3946 :                         return zendi_smart_strcmp(op1, op2) == 0;
     727             :                 }
     728             :         }
     729         651 :         compare_function(&result, op1, op2);
     730         651 :         return Z_LVAL(result) == 0;
     731             : }
     732             : 
     733             : static zend_always_inline int fast_is_identical_function(zval *op1, zval *op2)
     734             : {
     735     3442744 :         if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
     736     2421071 :                 return 0;
     737     1021673 :         } else if (Z_TYPE_P(op1) <= IS_TRUE) {
     738       36882 :                 return 1;
     739             :         }
     740      984791 :         return zend_is_identical(op1, op2);
     741             : }
     742             : 
     743             : static zend_always_inline int fast_is_not_identical_function(zval *op1, zval *op2)
     744             : {
     745      559849 :         if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
     746      501353 :                 return 1;
     747       58496 :         } else if (Z_TYPE_P(op1) <= IS_TRUE) {
     748       18956 :                 return 0;
     749             :         }
     750       39540 :         return !zend_is_identical(op1, op2);
     751             : }
     752             : 
     753             : #define ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(opcode, binary_op)                                            \
     754             :         if (UNEXPECTED(Z_TYPE_P(op1) == IS_OBJECT)                                                             \
     755             :                 && op1 == result                                                                                   \
     756             :                 && UNEXPECTED(Z_OBJ_HANDLER_P(op1, get))                                                           \
     757             :                 && EXPECTED(Z_OBJ_HANDLER_P(op1, set))) {                                                          \
     758             :                 int ret;                                                                                           \
     759             :                 zval rv;                                                                                           \
     760             :                 zval *objval = Z_OBJ_HANDLER_P(op1, get)(op1, &rv);                                      \
     761             :                 Z_ADDREF_P(objval);                                                                                \
     762             :                 ret = binary_op(objval, objval, op2);                                                    \
     763             :                 Z_OBJ_HANDLER_P(op1, set)(op1, objval);                                                  \
     764             :                 zval_ptr_dtor(objval);                                                                             \
     765             :                 return ret;                                                                                        \
     766             :         } else if (UNEXPECTED(Z_TYPE_P(op1) == IS_OBJECT)                                                      \
     767             :                 && UNEXPECTED(Z_OBJ_HANDLER_P(op1, do_operation))) {                                               \
     768             :                 if (EXPECTED(SUCCESS == Z_OBJ_HANDLER_P(op1, do_operation)(opcode, result, op1, op2))) { \
     769             :                         return SUCCESS;                                                                                \
     770             :                 }                                                                                                  \
     771             :         }
     772             : 
     773             : #define ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(opcode)                                                       \
     774             :         if (UNEXPECTED(Z_TYPE_P(op2) == IS_OBJECT)                                                             \
     775             :                 && UNEXPECTED(Z_OBJ_HANDLER_P(op2, do_operation))                                                  \
     776             :                 && EXPECTED(SUCCESS == Z_OBJ_HANDLER_P(op2, do_operation)(opcode, result, op1, op2))) {  \
     777             :                 return SUCCESS;                                                                                    \
     778             :         }
     779             : 
     780             : #define ZEND_TRY_BINARY_OBJECT_OPERATION(opcode, binary_op)                                                \
     781             :         ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(opcode, binary_op)                                                \
     782             :         else                                                                                                   \
     783             :         ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(opcode)
     784             : 
     785             : #define ZEND_TRY_UNARY_OBJECT_OPERATION(opcode)                                                            \
     786             :         if (UNEXPECTED(Z_TYPE_P(op1) == IS_OBJECT)                                                             \
     787             :                 && UNEXPECTED(Z_OBJ_HANDLER_P(op1, do_operation))                                                  \
     788             :                 && EXPECTED(SUCCESS == Z_OBJ_HANDLER_P(op1, do_operation)(opcode, result, op1, NULL))) { \
     789             :                 return SUCCESS;                                                                                    \
     790             :         }
     791             : 
     792             : /* buf points to the END of the buffer */
     793             : static zend_always_inline char *zend_print_ulong_to_buf(char *buf, zend_ulong num) {
     794     1323258 :         *buf = '\0';
     795             :         do {
     796     2290267 :                 *--buf = (char) (num % 10) + '0';
     797     2290267 :                 num /= 10;
     798     2290267 :         } while (num > 0);
     799     1323258 :         return buf;
     800             : }
     801             : 
     802             : /* buf points to the END of the buffer */
     803             : static zend_always_inline char *zend_print_long_to_buf(char *buf, zend_long num) {
     804      918093 :         if (num < 0) {
     805        8296 :             char *result = zend_print_ulong_to_buf(buf, ~((zend_ulong) num) + 1);
     806        4148 :             *--result = '-';
     807        4148 :                 return result;
     808             :         } else {
     809     1827890 :             return zend_print_ulong_to_buf(buf, num);
     810             :         }
     811             : }
     812             : 
     813             : ZEND_API zend_string* ZEND_FASTCALL zend_long_to_str(zend_long num);
     814             : 
     815             : END_EXTERN_C()
     816             : 
     817             : #endif
     818             : 
     819             : /*
     820             :  * Local variables:
     821             :  * tab-width: 4
     822             :  * c-basic-offset: 4
     823             :  * indent-tabs-mode: t
     824             :  * End:
     825             :  */

Generated by: LCOV version 1.10

Generated at Wed, 02 Sep 2015 17:19:06 +0000 (23 hours ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.