Skip to content

Commit a459799

Browse files
committed
Improved JIT for ZVAL_COPY_DEREF
1 parent c260613 commit a459799

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

ext/opcache/jit/zend_jit_disasm_x86.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ static int zend_jit_disasm_init(void)
426426
REGISTER_HELPER(zend_jit_fast_concat_helper);
427427
REGISTER_HELPER(zend_jit_isset_dim_helper);
428428
REGISTER_HELPER(zend_jit_free_call_frame);
429-
REGISTER_HELPER(zend_jit_zval_copy_deref_helper)
430429
REGISTER_HELPER(zend_jit_fetch_global_helper);
431430
REGISTER_HELPER(zend_jit_verify_arg_slow);
432431
REGISTER_HELPER(zend_jit_fetch_obj_r_slow);

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,12 +1241,6 @@ static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_a
12411241
}
12421242
}
12431243

1244-
static void ZEND_FASTCALL zend_jit_zval_copy_deref_helper(zval *dst, zval *src)
1245-
{
1246-
ZVAL_DEREF(src);
1247-
ZVAL_COPY(dst, src);
1248-
}
1249-
12501244
static void ZEND_FASTCALL zend_jit_fetch_obj_r_slow(zend_object *zobj, zval *offset, zval *result, uint32_t cache_slot)
12511245
{
12521246
zval *retval;

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ static void* dasm_labels[zend_lb_MAX];
494494
| mov aword [zv], val
495495
|.endmacro
496496

497+
|.macro GET_Z_W2, reg, zv
498+
| mov reg, dword [zv+4]
499+
|.endmacro
500+
501+
|.macro SET_Z_W2, zv, reg
502+
| mov dword [zv+4], reg
503+
|.endmacro
504+
497505
|.macro GET_ZVAL_PTR, reg, addr
498506
|| ZEND_ASSERT(Z_MODE(addr) == IS_MEM_ZVAL);
499507
| mov reg, aword [Ra(Z_REG(addr))+Z_OFFSET(addr)]
@@ -10006,6 +10014,41 @@ static int zend_jit_return(dasm_State **Dst, const zend_op *opline, const zend_o
1000610014
return 1;
1000710015
}
1000810016

10017+
static int zend_jit_zval_copy_deref(dasm_State **Dst, zend_jit_addr res_addr, zend_jit_addr val_addr, zend_reg type_reg)
10018+
{
10019+
ZEND_ASSERT(type_reg == ZREG_R2);
10020+
10021+
|.if not(X64)
10022+
|| if (Z_REG(val_addr) == ZREG_R1) {
10023+
| GET_ZVAL_W2 r0, val_addr
10024+
|| }
10025+
|.endif
10026+
| GET_ZVAL_PTR r1, val_addr
10027+
|.if not(X64)
10028+
|| if (Z_REG(val_addr) != ZREG_R1) {
10029+
| GET_ZVAL_W2 r0, val_addr
10030+
|| }
10031+
|.endif
10032+
| IF_NOT_REFCOUNTED dh, >2
10033+
| IF_NOT_TYPE dl, IS_REFERENCE, >1
10034+
| GET_Z_TYPE_INFO edx, r1+offsetof(zend_reference, val)
10035+
|.if not(X64)
10036+
| GET_Z_W2 r0, r1+offsetof(zend_reference, val)
10037+
|.endif
10038+
| GET_Z_PTR r1, r1+offsetof(zend_reference, val)
10039+
| IF_NOT_REFCOUNTED dh, >2
10040+
|1:
10041+
| GC_ADDREF r1
10042+
|2:
10043+
| SET_ZVAL_PTR res_addr, r1
10044+
|.if not(X64)
10045+
| SET_ZVAL_W2 res_addr, r0
10046+
|.endif
10047+
| SET_ZVAL_TYPE_INFO res_addr, edx
10048+
10049+
return 1;
10050+
}
10051+
1000910052
static int zend_jit_fetch_dim_read(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info, uint32_t op2_info, uint32_t res_info, int may_throw)
1001010053
{
1001110054
zend_jit_addr op1_addr, orig_op1_addr, op2_addr, res_addr;
@@ -10174,16 +10217,10 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst, const zend_op *opline, cons
1017410217
|8:
1017510218
if (op1_info & MAY_BE_ARRAY_OF_REF) {
1017610219
| // ZVAL_COPY_DEREF
10177-
| GET_Z_PTR r2, r0
10178-
| IF_NOT_ZVAL_REFCOUNTED val_addr, >2
10179-
| IF_NOT_ZVAL_TYPE val_addr, IS_REFERENCE, >1
10180-
| lea r0, [r2 + offsetof(zend_reference, val)]
10181-
| GET_Z_PTR r2, r0
10182-
| IF_NOT_ZVAL_REFCOUNTED val_addr, >2
10183-
|1:
10184-
| GC_ADDREF r2
10185-
|2:
10186-
| ZVAL_COPY_VALUE res_addr, -1, val_addr, MAY_BE_ANY, ZREG_R1, ZREG_R2, 1
10220+
| GET_ZVAL_TYPE_INFO Rd(ZREG_R2), val_addr
10221+
if (!zend_jit_zval_copy_deref(Dst, res_addr, val_addr, ZREG_R2)) {
10222+
return 0;
10223+
}
1018710224
} else {
1018810225
| // ZVAL_COPY
1018910226
| ZVAL_COPY_VALUE res_addr, -1, val_addr, MAY_BE_ANY, ZREG_R1, ZREG_R2, 0
@@ -10805,20 +10842,9 @@ static int zend_jit_fetch_obj_read(dasm_State **Dst, const zend_op *opline, cons
1080510842
| IF_UNDEF dl, >5
1080610843
}
1080710844
}
10808-
| GET_ZVAL_PTR r0, prop_addr
10809-
| IF_NOT_REFCOUNTED dh, >2
10810-
| IF_TYPE dl, IS_REFERENCE, >6
10811-
|1:
10812-
| GC_ADDREF r0
10813-
|2:
10814-
|.if X64
10815-
| SET_ZVAL_PTR res_addr, r0
10816-
|.else
10817-
| SET_ZVAL_PTR res_addr, r0
10818-
| GET_ZVAL_W2 r0, prop_addr
10819-
| SET_ZVAL_W2 res_addr, r0
10820-
|.endif
10821-
| SET_ZVAL_TYPE_INFO res_addr, edx
10845+
if (!zend_jit_zval_copy_deref(Dst, res_addr, prop_addr, ZREG_R2)) {
10846+
return 0;
10847+
}
1082210848

1082310849
|.cold_code
1082410850

@@ -10845,16 +10871,6 @@ static int zend_jit_fetch_obj_read(dasm_State **Dst, const zend_op *opline, cons
1084510871
| jmp >9
1084610872
}
1084710873

10848-
|6:
10849-
if (offset == ZEND_WRONG_PROPERTY_OFFSET) {
10850-
| mov FCARG2a, FCARG1a
10851-
} else {
10852-
| lea FCARG2a, [FCARG1a + offset]
10853-
}
10854-
| LOAD_ZVAL_ADDR FCARG1a, res_addr
10855-
| EXT_CALL zend_jit_zval_copy_deref_helper, r0
10856-
| jmp >9
10857-
1085810874
if ((op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)- MAY_BE_OBJECT)) && JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) {
1085910875
|7:
1086010876
if (opline->opcode != ZEND_FETCH_OBJ_IS) {

0 commit comments

Comments
 (0)