Skip to content

Commit 9232af9

Browse files
committed
JIT for STRLEN
1 parent 3958d5b commit 9232af9

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,15 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
28032803
goto jit_failure;
28042804
}
28052805
goto done;
2806+
case ZEND_STRLEN:
2807+
op1_info = OP1_INFO();
2808+
if ((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_STRING) {
2809+
break;
2810+
}
2811+
if (!zend_jit_strlen(&dasm_state, opline, op_array, op1_info)) {
2812+
goto jit_failure;
2813+
}
2814+
goto done;
28062815
case ZEND_SWITCH_LONG:
28072816
case ZEND_SWITCH_STRING:
28082817
if (!zend_jit_switch(&dasm_state, opline, op_array, ssa)) {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12431243
case ZEND_JMPZ_EX:
12441244
case ZEND_JMPNZ_EX:
12451245
case ZEND_ECHO:
1246+
case ZEND_STRLEN:
12461247
if (tssa->ops[idx].op1_use >= 0 && op1_type != IS_UNKNOWN) {
12471248
zend_ssa_var_info *info = &ssa_var_info[ssa_ops[idx].op1_use];
12481249
if ((info->type & (MAY_BE_ANY|MAY_BE_UNDEF)) != (1 << op1_type)) {
@@ -2634,6 +2635,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
26342635
goto jit_failure;
26352636
}
26362637
goto done;
2638+
case ZEND_STRLEN:
2639+
op1_info = OP1_INFO();
2640+
CHECK_OP1_TRACE_TYPE();
2641+
if ((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_STRING) {
2642+
break;
2643+
}
2644+
if (!zend_jit_strlen(&dasm_state, opline, op_array, op1_info)) {
2645+
goto jit_failure;
2646+
}
2647+
goto done;
26372648
#if 0
26382649
case ZEND_SWITCH_LONG:
26392650
case ZEND_SWITCH_STRING:

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10461,10 +10461,10 @@ static int zend_jit_free(dasm_State **Dst, const zend_op *opline, const zend_op_
1046110461

1046210462
static int zend_jit_echo(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info)
1046310463
{
10464-
zval *zv;
10465-
size_t len;
10466-
1046710464
if (opline->op1_type == IS_CONST) {
10465+
zval *zv;
10466+
size_t len;
10467+
1046810468
zv = RT_CONSTANT(opline, opline->op1);
1046910469
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
1047010470
len = Z_STRLEN_P(zv);
@@ -10517,6 +10517,36 @@ static int zend_jit_echo(dasm_State **Dst, const zend_op *opline, const zend_op_
1051710517
return 1;
1051810518
}
1051910519

10520+
static int zend_jit_strlen(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info)
10521+
{
10522+
zend_jit_addr res_addr = RES_ADDR();
10523+
10524+
if (opline->op1_type == IS_CONST) {
10525+
zval *zv;
10526+
size_t len;
10527+
10528+
zv = RT_CONSTANT(opline, opline->op1);
10529+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
10530+
len = Z_STRLEN_P(zv);
10531+
10532+
| SET_ZVAL_LVAL res_addr, len
10533+
| SET_ZVAL_TYPE_INFO res_addr, IS_LONG
10534+
} else {
10535+
zend_jit_addr op1_addr = OP1_ADDR();
10536+
10537+
ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_STRING);
10538+
10539+
| GET_ZVAL_PTR r0, op1_addr
10540+
| mov r0, aword [r0 + offsetof(zend_string, len)]
10541+
| SET_ZVAL_LVAL res_addr, r0
10542+
| SET_ZVAL_TYPE_INFO res_addr, IS_LONG
10543+
if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
10544+
| ZVAL_PTR_DTOR op1_addr, op1_info, 0, 0, opline
10545+
}
10546+
}
10547+
return 1;
10548+
}
10549+
1052010550
static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, zend_ssa *ssa)
1052110551
{
1052210552
HashTable *jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2));

0 commit comments

Comments
 (0)