mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Optimized JMPZNZ to avoid multiplication at runtime (may be it makes sense to use relative addresses everywere it'll lead to Position Independent Code)
This commit is contained in:
parent
8a8df2ce68
commit
6a911e833f
@ -1731,6 +1731,10 @@ static zend_always_inline zval *zend_vm_stack_push_args(int count TSRMLS_DC) /*
|
||||
CHECK_SYMBOL_TABLES() \
|
||||
OPLINE = new_op
|
||||
|
||||
#define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \
|
||||
CHECK_SYMBOL_TABLES() \
|
||||
OPLINE = ((zend_op*)(((char*)opline)+(offset)))
|
||||
|
||||
#define ZEND_VM_JMP(new_op) \
|
||||
if (EXPECTED(!EG(exception))) { \
|
||||
ZEND_VM_SET_OPCODE(new_op); \
|
||||
|
@ -1301,6 +1301,10 @@ void execute_new_code(TSRMLS_D) /* {{{ */
|
||||
case ZEND_JMP:
|
||||
opline->op1.jmp_addr = &CG(active_op_array)->opcodes[opline->op1.opline_num];
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* absolute index to relative offset */
|
||||
opline->extended_value = (char*)(CG(active_op_array)->opcodes + opline->extended_value) - (char*)opline;
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
|
@ -683,6 +683,10 @@ ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC)
|
||||
case ZEND_FAST_CALL:
|
||||
opline->op1.jmp_addr = &op_array->opcodes[opline->op1.opline_num];
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* absolute index to relative offset */
|
||||
opline->extended_value = (char*)(op_array->opcodes + opline->extended_value) - (char*)opline;
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
|
@ -2180,13 +2180,13 @@ ZEND_VM_HANDLER(45, ZEND_JMPZNZ, CONST|TMP|VAR|CV, ANY)
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on true to %d\n", opline->extended_value);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]);
|
||||
ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
} else {
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on false to %d\n", opline->op2.opline_num);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->op2.opline_num]);
|
||||
ZEND_VM_SET_OPCODE(opline->op2.jmp_addr);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
}
|
||||
}
|
||||
|
@ -2464,13 +2464,13 @@ static int ZEND_FASTCALL ZEND_JMPZNZ_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on true to %d\n", opline->extended_value);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]);
|
||||
ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
} else {
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on false to %d\n", opline->op2.opline_num);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->op2.opline_num]);
|
||||
ZEND_VM_SET_OPCODE(opline->op2.jmp_addr);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
}
|
||||
}
|
||||
@ -7564,13 +7564,13 @@ static int ZEND_FASTCALL ZEND_JMPZNZ_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on true to %d\n", opline->extended_value);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]);
|
||||
ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
} else {
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on false to %d\n", opline->op2.opline_num);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->op2.opline_num]);
|
||||
ZEND_VM_SET_OPCODE(opline->op2.jmp_addr);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
}
|
||||
}
|
||||
@ -12603,13 +12603,13 @@ static int ZEND_FASTCALL ZEND_JMPZNZ_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on true to %d\n", opline->extended_value);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]);
|
||||
ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
} else {
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on false to %d\n", opline->op2.opline_num);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->op2.opline_num]);
|
||||
ZEND_VM_SET_OPCODE(opline->op2.jmp_addr);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
}
|
||||
}
|
||||
@ -29533,13 +29533,13 @@ static int ZEND_FASTCALL ZEND_JMPZNZ_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on true to %d\n", opline->extended_value);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]);
|
||||
ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
} else {
|
||||
#if DEBUG_ZEND>=2
|
||||
printf("Conditional jmp on false to %d\n", opline->op2.opline_num);
|
||||
#endif
|
||||
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->op2.opline_num]);
|
||||
ZEND_VM_SET_OPCODE(opline->op2.jmp_addr);
|
||||
ZEND_VM_CONTINUE(); /* CHECK_ME */
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +497,10 @@ static void zend_accel_optimize(zend_op_array *op_array,
|
||||
#endif
|
||||
ZEND_OP1(opline).opline_num = ZEND_OP1(opline).jmp_addr - op_array->opcodes;
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* relative offset into absolute index */
|
||||
opline->extended_value = (zend_op*)(((char*)opline) + opline->extended_value) - op_array->opcodes;
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
@ -538,6 +542,10 @@ static void zend_accel_optimize(zend_op_array *op_array,
|
||||
#endif
|
||||
ZEND_OP1(opline).jmp_addr = &op_array->opcodes[ZEND_OP1(opline).opline_num];
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* absolute index to relative offset */
|
||||
opline->extended_value = (char*)(op_array->opcodes + opline->extended_value) - (char*)opline;
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
|
@ -275,6 +275,9 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
|
||||
ZEND_OP1(opline).jmp_addr = &new_opcodes[ZEND_OP1(opline).jmp_addr - op_array->opcodes];
|
||||
}
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* relative extended_value don't have to be changed */
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
@ -284,7 +287,6 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
|
||||
ZEND_OP2(opline).jmp_addr = &new_opcodes[ZEND_OP2(opline).jmp_addr - op_array->opcodes];
|
||||
}
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
case ZEND_BRK:
|
||||
case ZEND_CONT:
|
||||
has_jmp = 1;
|
||||
@ -323,6 +325,9 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
|
||||
#endif
|
||||
ZEND_OP1(opline).jmp_addr = &new_opcodes[ZEND_OP1(opline).jmp_addr - op_array->opcodes];
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
/* relative extended_value don't have to be changed */
|
||||
/* break omitted intentionally */
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
case ZEND_JMPZ_EX:
|
||||
|
Loading…
Reference in New Issue
Block a user