Skip to content

Commit 6faa08f

Browse files
committed
Separate common code
1 parent ed6cf67 commit 6faa08f

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,21 @@ static int zend_jit_hybrid_profile_jit_stub(dasm_State **Dst)
21752175
return 1;
21762176
}
21772177

2178+
static int zend_jit_hybrid_hot_code_stub(dasm_State **Dst)
2179+
{
2180+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2181+
return 1;
2182+
}
2183+
2184+
|->hybrid_hot_code:
2185+
| mov word [r2], ZEND_JIT_COUNTER_INIT
2186+
| mov FCARG1a, FP
2187+
| GET_IP FCARG2a
2188+
| EXT_CALL zend_jit_hot_func, r0
2189+
| JMP_IP
2190+
return 1;
2191+
}
2192+
21782193
/*
21792194
* This code is based Mike Pall's "Hashed profile counters" idea, implemented
21802195
* in LuaJIT. The full description may be found in "LuaJIT 2.0 intellectual
@@ -2199,18 +2214,13 @@ static int zend_jit_hybrid_profile_jit_stub(dasm_State **Dst)
21992214
* }
22002215
*
22012216
*/
2202-
static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
2217+
static int zend_jit_hybrid_hot_counter_stub(dasm_State **Dst, uint32_t cost)
22032218
{
2204-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2205-
return 1;
2206-
}
2207-
2208-
|->hybrid_func_hot_counter:
22092219
| mov r0, EX->func
22102220
| mov r1, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
22112221
| mov r2, aword [r1 + offsetof(zend_jit_op_array_hot_extension, counter)]
2212-
| sub word [r2], ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_func) - 1) / JIT_G(hot_func))
2213-
| jle >1
2222+
| sub word [r2], cost
2223+
| jle ->hybrid_hot_code
22142224
| GET_IP r2
22152225
| sub r2, aword [r0 + offsetof(zend_op_array, opcodes)]
22162226
| // divide by sizeof(zend_op)
@@ -2227,49 +2237,51 @@ static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
22272237
| .else
22282238
| jmp aword [r1+r2*4+offsetof(zend_jit_op_array_hot_extension, orig_handlers)]
22292239
| .endif
2230-
|1:
2231-
| mov word [r2], ZEND_JIT_COUNTER_INIT
2232-
| mov FCARG1a, FP
2233-
| GET_IP FCARG2a
2234-
| EXT_CALL zend_jit_hot_func, r0
2235-
| JMP_IP
22362240
return 1;
22372241
}
22382242

2243+
static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
2244+
{
2245+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2246+
return 1;
2247+
}
2248+
2249+
|->hybrid_func_hot_counter:
2250+
2251+
return zend_jit_hybrid_hot_counter_stub(Dst,
2252+
((ZEND_JIT_COUNTER_INIT + JIT_G(hot_func) - 1) / JIT_G(hot_func)));
2253+
}
2254+
22392255
static int zend_jit_hybrid_loop_hot_counter_stub(dasm_State **Dst)
22402256
{
22412257
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
22422258
return 1;
22432259
}
22442260

22452261
|->hybrid_loop_hot_counter:
2246-
| mov r0, EX->func
2247-
| mov r1, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
2248-
| mov r2, aword [r1 + offsetof(zend_jit_op_array_hot_extension, counter)]
2249-
| sub word [r2], ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_loop) - 1) / JIT_G(hot_loop))
2250-
| jle >1
2251-
| GET_IP r2
2252-
| sub r2, aword [r0 + offsetof(zend_op_array, opcodes)]
2253-
| // divide by sizeof(zend_op)
2254-
| .if X64
2255-
|| ZEND_ASSERT(sizeof(zend_op) == 32);
2256-
| sar r2, 5
2257-
| .else
2258-
|| ZEND_ASSERT(sizeof(zend_op) == 28);
2259-
| sar r2, 2
2260-
| imul r2, 0xb6db6db7
2261-
| .endif
2262-
| .if X64
2263-
| jmp aword [r1+r2*8+offsetof(zend_jit_op_array_hot_extension, orig_handlers)]
2264-
| .else
2265-
| jmp aword [r1+r2*4+offsetof(zend_jit_op_array_hot_extension, orig_handlers)]
2266-
| .endif
2267-
|1:
2262+
2263+
return zend_jit_hybrid_hot_counter_stub(Dst,
2264+
((ZEND_JIT_COUNTER_INIT + JIT_G(hot_loop) - 1) / JIT_G(hot_loop)));
2265+
}
2266+
2267+
static int zend_jit_hybrid_hot_trace_stub(dasm_State **Dst)
2268+
{
2269+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2270+
return 1;
2271+
}
2272+
2273+
|->hybrid_hot_trace:
22682274
| mov word [r2], ZEND_JIT_COUNTER_INIT
22692275
| mov FCARG1a, FP
22702276
| GET_IP FCARG2a
2271-
| EXT_CALL zend_jit_hot_func, r0
2277+
| EXT_CALL zend_jit_trace_hot_root, r0
2278+
| test eax, eax // TODO : remove this check at least for HYBRID VM ???
2279+
| jl >1
2280+
| MEM_OP2_2_ZTS mov, FP, aword, executor_globals, current_execute_data, r0
2281+
| LOAD_OPLINE
22722282
| JMP_IP
2283+
|1:
2284+
| EXT_JMP zend_jit_halt_op->handler, r0
22732285
return 1;
22742286
}
22752287

@@ -2280,20 +2292,8 @@ static int zend_jit_hybrid_trace_counter_stub(dasm_State **Dst, uint32_t cost)
22802292
| mov r1, aword [r1 + offsetof(zend_jit_op_array_trace_extension, offset)]
22812293
| mov r2, aword [IP + r1 + offsetof(zend_op_trace_info, counter)]
22822294
| sub word [r2], cost
2283-
| jle >1
2295+
| jle ->hybrid_hot_trace
22842296
| jmp aword [IP + r1]
2285-
|1:
2286-
| mov word [r2], ZEND_JIT_COUNTER_INIT
2287-
| mov FCARG1a, FP
2288-
| GET_IP FCARG2a
2289-
| EXT_CALL zend_jit_trace_hot_root, r0
2290-
| test eax, eax // TODO : remove this check at least for HYBRID VM ???
2291-
| jl >1
2292-
| MEM_OP2_2_ZTS mov, FP, aword, executor_globals, current_execute_data, r0
2293-
| LOAD_OPLINE
2294-
| JMP_IP
2295-
|1:
2296-
| EXT_JMP zend_jit_halt_op->handler, r0
22972297
return 1;
22982298
}
22992299

@@ -2572,8 +2572,10 @@ static const zend_jit_stub zend_jit_stubs[] = {
25722572
JIT_STUB(trace_escape),
25732573
JIT_STUB(hybrid_runtime_jit),
25742574
JIT_STUB(hybrid_profile_jit),
2575+
JIT_STUB(hybrid_hot_code),
25752576
JIT_STUB(hybrid_func_hot_counter),
25762577
JIT_STUB(hybrid_loop_hot_counter),
2578+
JIT_STUB(hybrid_hot_trace),
25772579
JIT_STUB(hybrid_func_trace_counter),
25782580
JIT_STUB(hybrid_ret_trace_counter),
25792581
JIT_STUB(hybrid_loop_trace_counter),

0 commit comments

Comments
 (0)