dmitry Wed, 11 Aug 2010 15:34:06 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=302110
Log:
Optimization of ASSIGN instruction
Changed paths:
U php/php-src/trunk/Zend/zend_execute.c
U php/php-src/trunk/Zend/zend_vm_def.h
U php/php-src/trunk/Zend/zend_vm_execute.h
Modified: php/php-src/trunk/Zend/zend_execute.c
===================================================================
--- php/php-src/trunk/Zend/zend_execute.c 2010-08-11 15:26:47 UTC (rev 302109)
+++ php/php-src/trunk/Zend/zend_execute.c 2010-08-11 15:34:06 UTC (rev 302110)
@@ -819,6 +819,7 @@
static inline zval* zend_assign_tmp_to_variable(zval **variable_ptr_ptr, zval *value TSRMLS_DC)
{
zval *variable_ptr = *variable_ptr_ptr;
+ zval garbage;
if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
@@ -826,27 +827,64 @@
return variable_ptr;
}
- if (EXPECTED(!PZVAL_IS_REF(variable_ptr))) {
- if (Z_REFCOUNT_P(variable_ptr)==1) {
- zendi_zval_dtor(*variable_ptr);
+ if (UNEXPECTED(Z_REFCOUNT_P(variable_ptr) > 1) &&
+ EXPECTED(!PZVAL_IS_REF(variable_ptr))) {
+ /* we need to split */
+ Z_DELREF_P(variable_ptr);
+ GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr);
+ ALLOC_ZVAL(variable_ptr);
+ INIT_PZVAL_COPY(variable_ptr, value);
+ *variable_ptr_ptr = variable_ptr;
+ return variable_ptr;
+ } else {
+ if (EXPECTED(Z_TYPE_P(variable_ptr) <= IS_BOOL)) {
+ /* nothing to destroy */
ZVAL_COPY_VALUE(variable_ptr, value);
- return variable_ptr;
- } else { /* we need to split */
- Z_DELREF_P(variable_ptr);
- GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr);
- ALLOC_ZVAL(variable_ptr);
- INIT_PZVAL_COPY(variable_ptr, value);
- *variable_ptr_ptr = variable_ptr;
- return variable_ptr;
+ } else {
+ ZVAL_COPY_VALUE(&garbage, variable_ptr);
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ _zval_dtor_func(&garbage ZEND_FILE_LINE_CC);
}
+ return variable_ptr;
+ }
+}
+
+static inline zval* zend_assign_const_to_variable(zval **variable_ptr_ptr, zval *value TSRMLS_DC)
+{
+ zval *variable_ptr = *variable_ptr_ptr;
+ zval garbage;
+
+ if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
+ UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
+ Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr_ptr, value TSRMLS_CC);
+ return variable_ptr;
+ }
+
+ if (UNEXPECTED(Z_REFCOUNT_P(variable_ptr) > 1) &&
+ EXPECTED(!PZVAL_IS_REF(variable_ptr))) {
+ /* we need to split */
+ Z_DELREF_P(variable_ptr);
+ GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr);
+ ALLOC_ZVAL(variable_ptr);
+ INIT_PZVAL_COPY(variable_ptr, value);
+ zval_copy_ctor(variable_ptr);
+ *variable_ptr_ptr = variable_ptr;
+ return variable_ptr;
} else {
- zendi_zval_dtor(*variable_ptr);
- ZVAL_COPY_VALUE(variable_ptr, value);
+ if (EXPECTED(Z_TYPE_P(variable_ptr) <= IS_BOOL)) {
+ /* nothing to destroy */
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ zendi_zval_copy_ctor(*variable_ptr);
+ } else {
+ ZVAL_COPY_VALUE(&garbage, variable_ptr);
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ zendi_zval_copy_ctor(*variable_ptr);
+ _zval_dtor_func(&garbage ZEND_FILE_LINE_CC);
+ }
return variable_ptr;
}
}
-
static inline zval* zend_assign_to_variable(zval **variable_ptr_ptr, zval *value TSRMLS_DC)
{
zval *variable_ptr = *variable_ptr_ptr;
@@ -860,24 +898,21 @@
if (EXPECTED(!PZVAL_IS_REF(variable_ptr))) {
if (Z_REFCOUNT_P(variable_ptr)==1) {
- if (variable_ptr==value) {
+ if (UNEXPECTED(variable_ptr == value)) {
return variable_ptr;
- } else if (PZVAL_IS_REF(value)) {
- ZVAL_COPY_VALUE(&garbage, variable_ptr);
- ZVAL_COPY_VALUE(variable_ptr, value);
- zval_copy_ctor(variable_ptr);
- zendi_zval_dtor(garbage);
- return variable_ptr;
- } else {
- Z_DELREF_P(variable_ptr);
+ } else if (EXPECTED(!PZVAL_IS_REF(value))) {
Z_ADDREF_P(value);
*variable_ptr_ptr = value;
- if (variable_ptr != &EG(uninitialized_zval)) {
+ if (EXPECTED(variable_ptr != &EG(uninitialized_zval))) {
GC_REMOVE_ZVAL_FROM_BUFFER(variable_ptr);
zval_dtor(variable_ptr);
efree(variable_ptr);
+ } else {
+ Z_DELREF_P(variable_ptr);
}
return value;
+ } else {
+ goto copy_value;
}
} else { /* we need to split */
Z_DELREF_P(variable_ptr);
@@ -897,16 +932,22 @@
}
} else {
if (EXPECTED(variable_ptr != value)) {
- ZVAL_COPY_VALUE(&garbage, variable_ptr);
- ZVAL_COPY_VALUE(variable_ptr, value);
- zendi_zval_copy_ctor(*variable_ptr);
- zendi_zval_dtor(garbage);
+copy_value:
+ if (EXPECTED(Z_TYPE_P(variable_ptr) <= IS_BOOL)) {
+ /* nothing to destroy */
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ zendi_zval_copy_ctor(*variable_ptr);
+ } else {
+ ZVAL_COPY_VALUE(&garbage, variable_ptr);
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ zendi_zval_copy_ctor(*variable_ptr);
+ _zval_dtor_func(&garbage ZEND_FILE_LINE_CC);
+ }
}
return variable_ptr;
}
}
-
/* Utility Functions for Extensions */
static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
{
Modified: php/php-src/trunk/Zend/zend_vm_def.h
===================================================================
--- php/php-src/trunk/Zend/zend_vm_def.h 2010-08-11 15:26:47 UTC (rev 302109)
+++ php/php-src/trunk/Zend/zend_vm_def.h 2010-08-11 15:34:06 UTC (rev 302110)
@@ -1685,8 +1685,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -1739,8 +1741,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_OP2_TMP_FREE()) {
+ if (OP2_TYPE == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (OP2_TYPE == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
Modified: php/php-src/trunk/Zend/zend_vm_execute.h
===================================================================
--- php/php-src/trunk/Zend/zend_vm_execute.h 2010-08-11 15:26:47 UTC (rev 302109)
+++ php/php-src/trunk/Zend/zend_vm_execute.h 2010-08-11 15:34:06 UTC (rev 302110)
@@ -12782,8 +12782,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -12836,8 +12838,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_CONST == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_CONST == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -14917,8 +14921,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -14971,8 +14977,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (1) {
+ if (IS_TMP_VAR == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_TMP_VAR == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -16970,8 +16978,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -17024,8 +17034,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_VAR == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_VAR == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -18383,8 +18395,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -20001,8 +20015,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -20055,8 +20071,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_CV == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_CV == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -28290,8 +28308,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -28344,8 +28364,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_CONST == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_CONST == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -30208,8 +30230,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -30262,8 +30286,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (1) {
+ if (IS_TMP_VAR == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_TMP_VAR == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -32135,8 +32161,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -32189,8 +32217,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_VAR == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_VAR == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -33425,8 +33455,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -34924,8 +34956,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (IS_TMP_FREE(free_op_data1)) {
+ if ((opline+1)->op1_type == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if ((opline+1)->op1_type == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
@@ -34978,8 +35012,10 @@
AI_SET_PTR(&EX_T(opline->result.var), &EG(uninitialized_zval));
}
} else {
- if (0) {
+ if (IS_CV == IS_TMP_VAR) {
value = zend_assign_tmp_to_variable(variable_ptr_ptr, value TSRMLS_CC);
+ } else if (IS_CV == IS_CONST) {
+ value = zend_assign_const_to_variable(variable_ptr_ptr, value TSRMLS_CC);
} else {
value = zend_assign_to_variable(variable_ptr_ptr, value TSRMLS_CC);
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php