cvs: ZendEngine2(PHP_5_3) / zend_execute.c

[email protected] ("Dmitry Stogov") Wed, 11 Mar 2009 12:14:35 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1236773675@cvsserver>
dmitry		Wed Mar 11 12:14:35 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /ZendEngine2	zend_execute.c 
  Log:
  Fixed speed degradation on gcc-4.3 because of less agressive inlining 
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute.c?r1=1.716.2.12.2.24.2.38&r2=1.716.2.12.2.24.2.39&diff_format=u
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.716.2.12.2.24.2.38 ZendEngine2/zend_execute.c:1.716.2.12.2.24.2.39
--- ZendEngine2/zend_execute.c:1.716.2.12.2.24.2.38	Mon Jan  5 20:31:51 2009
+++ ZendEngine2/zend_execute.c	Wed Mar 11 12:14:34 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute.c,v 1.716.2.12.2.24.2.38 2009/01/05 20:31:51 felipe Exp $ */
+/* $Id: zend_execute.c,v 1.716.2.12.2.24.2.39 2009/03/11 12:14:34 dmitry Exp $ */
 
 #define ZEND_INTENSIVE_DEBUGGING 0
 
@@ -172,73 +172,86 @@
 	return execute_data_ptr->CVs[var];
 }
 
-static inline zval *_get_zval_ptr_tmp(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
+static zend_always_inline zval *_get_zval_ptr_tmp(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
 {
 	return should_free->var = &T(node->u.var).tmp_var;
 }
 
-static inline zval *_get_zval_ptr_var(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
+static inline zval *_get_zval_ptr_var_string_offset(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
+{
+	temp_variable *T = &T(node->u.var);
+	zval *str = T->str_offset.str;
+	zval *ptr;
+
+	/* string offset */
+	ALLOC_ZVAL(ptr);
+	T->str_offset.ptr = ptr;
+	should_free->var = ptr;
+
+	if (T->str_offset.str->type != IS_STRING
+		|| ((int)T->str_offset.offset < 0)
+		|| (T->str_offset.str->value.str.len <= (int)T->str_offset.offset)) {
+		ptr->value.str.val = STR_EMPTY_ALLOC();
+		ptr->value.str.len = 0;
+	} else {
+		ptr->value.str.val = estrndup(str->value.str.val + T->str_offset.offset, 1);
+		ptr->value.str.len = 1;
+	}
+	PZVAL_UNLOCK_FREE(str);
+	Z_SET_REFCOUNT_P(ptr, 1);
+	Z_SET_ISREF_P(ptr);
+	ptr->type = IS_STRING;
+	return ptr;
+}
+
+static zend_always_inline zval *_get_zval_ptr_var(const znode *node, const temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
 {
 	zval *ptr = T(node->u.var).var.ptr;
-	if (ptr) {
+	if (EXPECTED(ptr != NULL)) {
 		PZVAL_UNLOCK(ptr, should_free);
 		return ptr;
 	} else {
-		temp_variable *T = &T(node->u.var);
-		zval *str = T->str_offset.str;
+		return _get_zval_ptr_var_string_offset(node, Ts, should_free TSRMLS_CC);
+	}
+}
 
-		/* string offset */
-		ALLOC_ZVAL(ptr);
-		T->str_offset.ptr = ptr;
-		should_free->var = ptr;
-
-		if (T->str_offset.str->type != IS_STRING
-			|| ((int)T->str_offset.offset < 0)
-			|| (T->str_offset.str->value.str.len <= (int)T->str_offset.offset)) {
-			ptr->value.str.val = STR_EMPTY_ALLOC();
-			ptr->value.str.len = 0;
-		} else {
-			ptr->value.str.val = estrndup(str->value.str.val + T->str_offset.offset, 1);
-			ptr->value.str.len = 1;
+static inline zval **_get_zval_cv_lookup(zval ***ptr, zend_uint var, int type TSRMLS_DC)
+{
+	zend_compiled_variable *cv = &CV_DEF_OF(var);
+
+	if (!EG(active_symbol_table) ||
+	    zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
+		switch (type) {
+			case BP_VAR_R:
+			case BP_VAR_UNSET:
+				zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
+				/* break missing intentionally */
+			case BP_VAR_IS:
+				return &EG(uninitialized_zval_ptr);
+				break;
+			case BP_VAR_RW:
+				zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
+				/* break missing intentionally */
+			case BP_VAR_W:
+				Z_ADDREF(EG(uninitialized_zval));
+				if (!EG(active_symbol_table)) {
+					*ptr = (zval**)EG(current_execute_data)->CVs + (EG(active_op_array)->last_var + var);
+					**ptr = &EG(uninitialized_zval);
+				} else {
+					zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &EG(uninitialized_zval_ptr), sizeof(zval *), (void **)ptr);
+				}
+				break;
 		}
-		PZVAL_UNLOCK_FREE(str);
-		Z_SET_REFCOUNT_P(ptr, 1);
-		Z_SET_ISREF_P(ptr);
-		ptr->type = IS_STRING;
-		return ptr;
 	}
+	return *ptr;
 }
 
-static inline zval *_get_zval_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
+static zend_always_inline zval *_get_zval_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
 {
 	zval ***ptr = &CV_OF(node->u.var);
 
-	if (!*ptr) {
-		zend_compiled_variable *cv = &CV_DEF_OF(node->u.var);
-		if (!EG(active_symbol_table) ||
-		    zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
-			switch (type) {
-				case BP_VAR_R:
-				case BP_VAR_UNSET:
-					zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
-					/* break missing intentionally */
-				case BP_VAR_IS:
-					return &EG(uninitialized_zval);
-					break;
-				case BP_VAR_RW:
-					zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
-					/* break missing intentionally */
-				case BP_VAR_W:
-					Z_ADDREF(EG(uninitialized_zval));
-					if (!EG(active_symbol_table)) {
-						*ptr = (zval**)EG(current_execute_data)->CVs + (EG(active_op_array)->last_var + node->u.var);
-						**ptr = &EG(uninitialized_zval);
-					} else {
-						zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &EG(uninitialized_zval_ptr), sizeof(zval *), (void **)ptr);
-					}
-					break;
-			}
-		}
+	if (UNEXPECTED(*ptr == NULL)) {
+		return *_get_zval_cv_lookup(ptr, node->u.var, type TSRMLS_CC);
 	}
 	return **ptr;
 }
@@ -275,7 +288,7 @@
 {
 	zval** ptr_ptr = T(node->u.var).var.ptr_ptr;
 
-	if (ptr_ptr) {
+	if (EXPECTED(ptr_ptr != NULL)) {
 		PZVAL_UNLOCK(*ptr_ptr, should_free);
 	} else {
 		/* string offset */
@@ -284,37 +297,12 @@
 	return ptr_ptr;
 }
 
-static inline zval **_get_zval_ptr_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
+static zend_always_inline zval **_get_zval_ptr_ptr_cv(const znode *node, const temp_variable *Ts, int type TSRMLS_DC)
 {
 	zval ***ptr = &CV_OF(node->u.var);
 
-	if (!*ptr) {
-		zend_compiled_variable *cv = &CV_DEF_OF(node->u.var);
-
-		if (!EG(active_symbol_table) ||
-		    zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
-			switch (type) {
-				case BP_VAR_R:
-				case BP_VAR_UNSET:
-					zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
-					/* break missing intentionally */
-				case BP_VAR_IS:
-					return &EG(uninitialized_zval_ptr);
-					break;
-				case BP_VAR_RW:
-					zend_error(E_NOTICE, "Undefined variable: %s", cv->name);
-					/* break missing intentionally */
-				case BP_VAR_W:
-					Z_ADDREF(EG(uninitialized_zval));
-					if (!EG(active_symbol_table)) {
-						*ptr = (zval**)EG(current_execute_data)->CVs + (EG(active_op_array)->last_var + node->u.var);
-						**ptr = &EG(uninitialized_zval);
-					} else {
-						zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &EG(uninitialized_zval_ptr), sizeof(zval *), (void **)ptr);
-					}
-					break;
-			}
-		}
+	if (UNEXPECTED(*ptr == NULL)) {
+		return _get_zval_cv_lookup(ptr, node->u.var, type TSRMLS_CC);
 	}
 	return *ptr;
 }