Skip to content

Commit 00270c6

Browse files
committed
Use better code for prologue and fix code generaion for "return -1".
1 parent 3014cf4 commit 00270c6

File tree

1 file changed

+50
-56
lines changed

1 file changed

+50
-56
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
|.define FCARG1w, w0
4444
|.define FCARG2x, x1
4545
|.define FCARG2w, w1
46-
|.define SPAD, #0x20 // padding for CPU stack alignment
47-
|.define NR_SPAD, #0x30 // padding for CPU stack alignment
46+
|.define SPAD, 0x20 // padding for CPU stack alignment
47+
|.define NR_SPAD, 0x30 // padding for CPU stack alignment
4848
|.define T3, [sp, #0x28] // Used to store old value of IP (CALL VM only)
4949
|.define T2, [sp, #0x20] // Used to store old value of FP (CALL VM only)
5050
|.define T1, [sp, #0x10]
@@ -88,8 +88,6 @@
8888

8989
|.define HYBRID_SPAD, #32 // padding for stack alignment
9090

91-
#define SPAD 0x20
92-
#define NR_SPAD 0x30
9391
#define TMP_ZVAL_OFFSET 16
9492
#define DASM_ALIGNMENT 16
9593

@@ -1724,11 +1722,11 @@ static int zend_jit_interrupt_handler_stub(dasm_State **Dst)
17241722
| ADD_HYBRID_SPAD
17251723
| JMP_IP TMP1
17261724
} else if (GCC_GLOBAL_REGS) {
1727-
| ldp x29, x30, [sp], #SPAD // stack alignment
1725+
| ldp x29, x30, [sp], # SPAD // stack alignment
17281726
| JMP_IP TMP1
17291727
} else {
1730-
| ldp FP, RX, T2 // retore FP and IP
1731-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
1728+
| ldp FP, RX, T2 // retore FP and IP
1729+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
17321730
| mov RETVALx, #1 // ZEND_VM_ENTER
17331731
| ret
17341732
}
@@ -1749,22 +1747,22 @@ static int zend_jit_exception_handler_stub(dasm_State **Dst)
17491747
const void *handler = EG(exception_op)->handler;
17501748

17511749
if (GCC_GLOBAL_REGS) {
1752-
| ldp x29, x30, [sp], #SPAD // stack alignment
1750+
| ldp x29, x30, [sp], # SPAD // stack alignment
17531751
| EXT_JMP handler, REG0
17541752
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
17551753
| mov FCARG1x, FP
17561754
| EXT_CALL handler, REG0
1757-
| ldp FP, RX, T2 // retore FP and IP
1758-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
1755+
| ldp FP, RX, T2 // retore FP and IP
1756+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
17591757
| tst RETVALw, RETVALw
17601758
| blt >1
17611759
| mov RETVALw, #1 // ZEND_VM_ENTER
17621760
|1:
17631761
| ret
17641762
} else {
17651763
| mov FCARG1x, FP
1766-
| ldp FP, RX, T2 // retore FP and IP
1767-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
1764+
| ldp FP, RX, T2 // retore FP and IP
1765+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
17681766
| EXT_JMP handler, REG0
17691767
}
17701768
}
@@ -1803,11 +1801,11 @@ static int zend_jit_leave_function_stub(dasm_State **Dst)
18031801
| JMP_IP TMP1
18041802
} else {
18051803
if (GCC_GLOBAL_REGS) {
1806-
| ldp x29, x30, [sp], #SPAD // stack alignment
1804+
| ldp x29, x30, [sp], # SPAD // stack alignment
18071805
} else {
18081806
| mov FCARG2x, FP
1809-
| ldp FP, RX, T2 // retore FP and IP
1810-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
1807+
| ldp FP, RX, T2 // retore FP and IP
1808+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
18111809
}
18121810
| TST_32_WITH_CONST FCARG1w, ZEND_CALL_TOP, TMP1w
18131811
| bne >1
@@ -1844,8 +1842,8 @@ static int zend_jit_leave_throw_stub(dasm_State **Dst)
18441842
|5:
18451843
| // opline = EG(exception_op);
18461844
| LOAD_IP_ADDR_ZTS executor_globals, exception_op, TMP2
1847-
| ldp FP, RX, T2 // retore FP and IP
1848-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
1845+
| ldp FP, RX, T2 // retore FP and IP
1846+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
18491847
| mov RETVALx, #2 // ZEND_VM_LEAVE
18501848
| ret
18511849
}
@@ -2286,12 +2284,12 @@ static int zend_jit_trace_halt_stub(dasm_State **Dst)
22862284
| ADD_HYBRID_SPAD
22872285
| EXT_JMP zend_jit_halt_op->handler, REG0
22882286
} else if (GCC_GLOBAL_REGS) {
2289-
| ldp x29, x30, [sp], #SPAD // stack alignment
2287+
| ldp x29, x30, [sp], # SPAD // stack alignment
22902288
| ret // PC must be zero
22912289
} else {
2292-
| ldp FP, RX, T2 // retore FP and IP
2293-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
2294-
| sub RETVALx, xzr, #1 // ZEND_VM_RETURN (-1)
2290+
| ldp FP, RX, T2 // retore FP and IP
2291+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
2292+
| movn RETVALx, #0 // ZEND_VM_RETURN (-1)
22952293
| ret
22962294
}
22972295
return 1;
@@ -2360,11 +2358,11 @@ static int zend_jit_trace_exit_stub(dasm_State **Dst)
23602358
| ADD_HYBRID_SPAD
23612359
| JMP_IP TMP1
23622360
} else if (GCC_GLOBAL_REGS) {
2363-
| ldp x29, x30, [sp], #SPAD // stack alignment
2361+
| ldp x29, x30, [sp], # SPAD // stack alignment
23642362
| JMP_IP TMP1
23652363
} else {
2366-
| ldp FP, RX, T2 // retore FP and IP
2367-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
2364+
| ldp FP, RX, T2 // retore FP and IP
2365+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
23682366
| mov RETVALx, #1 // ZEND_VM_ENTER
23692367
| ret
23702368
}
@@ -2390,7 +2388,7 @@ static int zend_jit_trace_exit_stub(dasm_State **Dst)
23902388
| ldr REG0, [REG0]
23912389
| br REG0
23922390
} else if (GCC_GLOBAL_REGS) {
2393-
| ldp x29, x30, [sp], #SPAD // stack alignment
2391+
| ldp x29, x30, [sp], # SPAD // stack alignment
23942392
| ldr REG0, EX->func
23952393
| ldr REG0, [REG0, #offsetof(zend_op_array, reserved[zend_func_info_rid])]
23962394
| ldr REG0, [REG0, #offsetof(zend_jit_op_array_trace_extension, offset)]
@@ -2410,9 +2408,9 @@ static int zend_jit_trace_exit_stub(dasm_State **Dst)
24102408
| tst RETVALw, RETVALw
24112409
| blt ->trace_halt
24122410
|
2413-
| ldp FP, RX, T2 // retore FP and IP
2414-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
2415-
| mov RETVALx, #1 // ZEND_VM_ENTER
2411+
| ldp FP, RX, T2 // retore FP and IP
2412+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
2413+
| mov RETVALx, #1 // ZEND_VM_ENTER
24162414
| ret
24172415
}
24182416

@@ -2427,11 +2425,11 @@ static int zend_jit_trace_escape_stub(dasm_State **Dst)
24272425
| ADD_HYBRID_SPAD
24282426
| JMP_IP, TMP1
24292427
} else if (GCC_GLOBAL_REGS) {
2430-
| ldp x29, x30, [sp], #SPAD // stack alignment
2428+
| ldp x29, x30, [sp], # SPAD // stack alignment
24312429
| JMP_IP, TMP1
24322430
} else {
2433-
| ldp FP, RX, T2 // retore FP and IP
2434-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
2431+
| ldp FP, RX, T2 // retore FP and IP
2432+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
24352433
| mov RETVALx, #1 // ZEND_VM_ENTER
24362434
| ret
24372435
}
@@ -2777,12 +2775,10 @@ static int zend_jit_prologue(dasm_State **Dst)
27772775
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
27782776
| SUB_HYBRID_SPAD
27792777
} else if (GCC_GLOBAL_REGS) {
2780-
| sub sp, sp, SPAD // TODO: stp x29, x30, [sp, #-SPAD]! can't be compiled
2781-
| stp x29, x30, [sp] // stack alignment
2778+
| stp x29, x30, [sp, # -SPAD]! // stack alignment
27822779
} else {
2783-
| sub sp, sp, NR_SPAD // TODO: stp x29, x30, [sp, #-NR_SPAD]! can't be compiled
2784-
| stp x29, x30, [sp] // stack alignment
2785-
| stp FP, RX, T2 // save FP and IP
2780+
| stp x29, x30, [sp, # -NR_SPAD]! // stack alignment
2781+
| stp FP, RX, T2 // save FP and IP
27862782
| mov FP, FCARG1x
27872783
}
27882784
return 1;
@@ -3034,15 +3030,13 @@ static int zend_jit_trace_link_to_root(dasm_State **Dst, zend_jit_trace_info *t,
30343030
prologue_size = 4;
30353031
#endif
30363032
} else if (GCC_GLOBAL_REGS) {
3037-
// sub sp, sp, #0x20
3038-
// stp x29, x30, [sp]
3039-
prologue_size = 8;
3033+
// stp x29, x30, [sp, # -SPAD]!
3034+
prologue_size = 4;
30403035
} else {
3041-
// sub sp, sp, NR_SPAD
3042-
// stp x29, x30, [sp]
3036+
// stp x29, x30, [sp, # -NR_SPAD]! // stack alignment
30433037
// stp FP, RX, T2
30443038
// mov FP, FCARG1x
3045-
prologue_size = 16;
3039+
prologue_size = 12;
30463040
}
30473041
link_addr = (const void*)((const char*)t->code_start + prologue_size);
30483042

@@ -3072,7 +3066,7 @@ static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
30723066
| br REG0
30733067
}
30743068
} else if (GCC_GLOBAL_REGS) {
3075-
| ldp x29, x30, [sp], #SPAD // stack alignment
3069+
| ldp x29, x30, [sp], # SPAD // stack alignment
30763070
if (!original_handler) {
30773071
| JMP_IP TMP1
30783072
} else {
@@ -3093,9 +3087,9 @@ static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
30933087
| ldr REG0, [REG0]
30943088
| blr REG0
30953089
}
3096-
| ldp FP, RX, T2 // retore FP and IP
3097-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
3098-
| mov RETVALx, #2 // ZEND_VM_LEAVE
3090+
| ldp FP, RX, T2 // retore FP and IP
3091+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
3092+
| mov RETVALx, #2 // ZEND_VM_LEAVE
30993093
| ret
31003094
}
31013095
return 1;
@@ -3351,11 +3345,11 @@ static int zend_jit_tail_handler(dasm_State **Dst, const zend_op *opline)
33513345
const void *handler = opline->handler;
33523346

33533347
if (GCC_GLOBAL_REGS) {
3354-
| ldp x29, x30, [sp], #SPAD // stack alignment
3348+
| ldp x29, x30, [sp], # SPAD // stack alignment
33553349
} else {
33563350
| mov FCARG1x, FP
3357-
| ldp FP, RX, T2 // retore FP and IP
3358-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
3351+
| ldp FP, RX, T2 // retore FP and IP
3352+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
33593353
}
33603354
| EXT_JMP handler, REG0
33613355
}
@@ -9518,11 +9512,11 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
95189512
| ADD_HYBRID_SPAD
95199513
| JMP_IP TMP1
95209514
} else if (GCC_GLOBAL_REGS) {
9521-
| ldp x29, x30, [sp], #SPAD // stack alignment
9515+
| ldp x29, x30, [sp], # SPAD // stack alignment
95229516
| JMP_IP TMP1
95239517
} else {
9524-
| ldp FP, RX, T2 // retore FP and IP
9525-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
9518+
| ldp FP, RX, T2 // retore FP and IP
9519+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
95269520
| mov RETVALx, #1 // ZEND_VM_ENTER
95279521
| ret
95289522
}
@@ -10864,7 +10858,7 @@ static int zend_jit_leave_func(dasm_State **Dst,
1086410858
| JMP_IP TMP1
1086510859
#endif
1086610860
} else if (GCC_GLOBAL_REGS) {
10867-
| ldp x29, x30, [sp], #SPAD // stack alignment
10861+
| ldp x29, x30, [sp], # SPAD // stack alignment
1086810862
#ifdef CONTEXT_THREADED_JIT
1086910863
| NIY // TODO
1087010864
#else
@@ -10877,9 +10871,9 @@ static int zend_jit_leave_func(dasm_State **Dst,
1087710871
// the value of execute_data in execute_ex()
1087810872
| NIY // TODO
1087910873
#else
10880-
| ldp FP, RX, T2 // retore FP and IP
10881-
| ldp x29, x30, [sp], #NR_SPAD // stack alignment
10882-
| mov RETVALx, #2 // ZEND_VM_LEAVE ????
10874+
| ldp FP, RX, T2 // retore FP and IP
10875+
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
10876+
| mov RETVALx, #2 // ZEND_VM_LEAVE ????
1088310877
| ret
1088410878
#endif
1088510879
}

0 commit comments

Comments
 (0)