From ae9e956ef901ca3f93fd74a412c468bed12a2391 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 18 Dec 2018 23:23:44 +0300 Subject: [PATCH] Reorder conditions --- Zend/zend_vm_execute.h | 29 ++++++++++++++----------- Zend/zend_vm_gen.php | 49 +++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index fca8e30279f..d72de2b7494 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -64460,10 +64460,22 @@ static const void* ZEND_FASTCALL zend_vm_get_opcode_handler_ex(uint32_t spec, co if (spec & SPEC_RULE_OP1) offset = offset * 5 + zend_vm_decode[op->op1_type]; if (spec & SPEC_RULE_OP2) offset = offset * 5 + zend_vm_decode[op->op2_type]; if (spec & SPEC_EXTRA_MASK) { - if (spec & SPEC_RULE_OP_DATA) offset = offset * 5 + zend_vm_decode[(op + 1)->op1_type]; - else if (spec & SPEC_RULE_RETVAL) offset = offset * 2 + (op->result_type != IS_UNUSED); - else if (spec & SPEC_RULE_QUICK_ARG) offset = offset * 2 + (op->op2.num <= MAX_ARG_FLAG_NUM); - else if (spec & SPEC_RULE_SMART_BRANCH) { + if (spec & SPEC_RULE_RETVAL) { + offset = offset * 2 + (op->result_type != IS_UNUSED); + } else if (spec & SPEC_RULE_QUICK_ARG) { + offset = offset * 2 + (op->op2.num <= MAX_ARG_FLAG_NUM); + } else if (spec & SPEC_RULE_OP_DATA) { + offset = offset * 5 + zend_vm_decode[(op + 1)->op1_type]; + } else if (spec & SPEC_RULE_DIM_OBJ) { + offset = offset * 3; + if (op->extended_value == ZEND_ASSIGN_DIM) { + offset += 1; + } else if (op->extended_value == ZEND_ASSIGN_OBJ) { + offset += 2; + } + } else if (spec & SPEC_RULE_ISSET) { + offset = offset * 2 + (op->extended_value & ZEND_ISEMPTY); + } else if (spec & SPEC_RULE_SMART_BRANCH) { offset = offset * 3; if ((op+1)->opcode == ZEND_JMPZ) { offset += 1; @@ -64471,15 +64483,6 @@ static const void* ZEND_FASTCALL zend_vm_get_opcode_handler_ex(uint32_t spec, co offset += 2; } } - else if (spec & SPEC_RULE_DIM_OBJ) { - offset = offset * 3; - if (op->extended_value == ZEND_ASSIGN_DIM) { - offset += 1; - } else if (op->extended_value == ZEND_ASSIGN_OBJ) { - offset += 2; - } - } - else if (spec & SPEC_RULE_ISSET) offset = offset * 2 + (op->extended_value & ZEND_ISEMPTY); } return zend_opcode_handlers[(spec & SPEC_START_MASK) + offset]; } diff --git a/Zend/zend_vm_gen.php b/Zend/zend_vm_gen.php index e3187d74962..e396fe5d919 100755 --- a/Zend/zend_vm_gen.php +++ b/Zend/zend_vm_gen.php @@ -2705,28 +2705,20 @@ function gen_vm($def, $skel) { $else = ""; out($f, "\tif (spec & SPEC_EXTRA_MASK) {\n"); - if (isset($used_extra_spec["OP_DATA"])) { - out($f, "\t\t{$else}if (spec & SPEC_RULE_OP_DATA) offset = offset * 5 + zend_vm_decode[(op + 1)->op1_type];\n"); - $else = "else "; - } if (isset($used_extra_spec["RETVAL"])) { - out($f, "\t\t{$else}if (spec & SPEC_RULE_RETVAL) offset = offset * 2 + (op->result_type != IS_UNUSED);\n"); - $else = "else "; + out($f, "\t\t{$else}if (spec & SPEC_RULE_RETVAL) {\n"); + out($f, "\t\t\toffset = offset * 2 + (op->result_type != IS_UNUSED);\n"); + $else = "} else "; } if (isset($used_extra_spec["QUICK_ARG"])) { - out($f, "\t\t{$else}if (spec & SPEC_RULE_QUICK_ARG) offset = offset * 2 + (op->op2.num <= MAX_ARG_FLAG_NUM);\n"); - $else = "else "; + out($f, "\t\t{$else}if (spec & SPEC_RULE_QUICK_ARG) {\n"); + out($f, "\t\t\toffset = offset * 2 + (op->op2.num <= MAX_ARG_FLAG_NUM);\n"); + $else = "} else "; } - if (isset($used_extra_spec["SMART_BRANCH"])) { - out($f, "\t\t{$else}if (spec & SPEC_RULE_SMART_BRANCH) {\n"); - out($f, "\t\t\toffset = offset * 3;\n"); - out($f, "\t\t\tif ((op+1)->opcode == ZEND_JMPZ) {\n"); - out($f, "\t\t\t\toffset += 1;\n"); - out($f, "\t\t\t} else if ((op+1)->opcode == ZEND_JMPNZ) {\n"); - out($f, "\t\t\t\toffset += 2;\n"); - out($f, "\t\t\t}\n"); - out($f, "\t\t}\n"); - $else = "else "; + if (isset($used_extra_spec["OP_DATA"])) { + out($f, "\t\t{$else}if (spec & SPEC_RULE_OP_DATA) {\n"); + out($f, "\t\t\toffset = offset * 5 + zend_vm_decode[(op + 1)->op1_type];\n"); + $else = "} else "; } if (isset($used_extra_spec["DIM_OBJ"])) { out($f, "\t\t{$else}if (spec & SPEC_RULE_DIM_OBJ) {\n"); @@ -2736,12 +2728,25 @@ function gen_vm($def, $skel) { out($f, "\t\t\t} else if (op->extended_value == ZEND_ASSIGN_OBJ) {\n"); out($f, "\t\t\t\toffset += 2;\n"); out($f, "\t\t\t}\n"); - out($f, "\t\t}\n"); - $else = "else "; + $else = "} else "; } if (isset($used_extra_spec["ISSET"])) { - out($f, "\t\t{$else}if (spec & SPEC_RULE_ISSET) offset = offset * 2 + (op->extended_value & ZEND_ISEMPTY);\n"); - $else = "else "; + out($f, "\t\t{$else}if (spec & SPEC_RULE_ISSET) {\n"); + out($f, "\t\t\toffset = offset * 2 + (op->extended_value & ZEND_ISEMPTY);\n"); + $else = "} else "; + } + if (isset($used_extra_spec["SMART_BRANCH"])) { + out($f, "\t\t{$else}if (spec & SPEC_RULE_SMART_BRANCH) {\n"); + out($f, "\t\t\toffset = offset * 3;\n"); + out($f, "\t\t\tif ((op+1)->opcode == ZEND_JMPZ) {\n"); + out($f, "\t\t\t\toffset += 1;\n"); + out($f, "\t\t\t} else if ((op+1)->opcode == ZEND_JMPNZ) {\n"); + out($f, "\t\t\t\toffset += 2;\n"); + out($f, "\t\t\t}\n"); + $else = "} else "; + } + if ($else !== "") { + out($f, "\t\t}\n"); } out($f, "\t}\n"); }