xref: /PHP-8.1/ext/opcache/jit/zend_jit_arm64.h (revision 643f3c29)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend JIT                                                             |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | https://www.php.net/license/3_01.txt                                 |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Dmitry Stogov <dmitry@php.net>                              |
16    |          Hao Sun <hao.sun@arm.com>                                   |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef HAVE_JIT_ARM64_H
21 #define HAVE_JIT_ARM64_H
22 
23 typedef enum _zend_reg {
24 	ZREG_NONE = -1,
25 
26 	ZREG_X0,
27 	ZREG_X1,
28 	ZREG_X2,
29 	ZREG_X3,
30 	ZREG_X4,
31 	ZREG_X5,
32 	ZREG_X6,
33 	ZREG_X7,
34 	ZREG_X8,
35 	ZREG_X9,
36 	ZREG_X10,
37 	ZREG_X11,
38 	ZREG_X12,
39 	ZREG_X13,
40 	ZREG_X14,
41 	ZREG_X15,
42 	ZREG_X16,
43 	ZREG_X17,
44 	ZREG_X18,
45 	ZREG_X19,
46 	ZREG_X20,
47 	ZREG_X21,
48 	ZREG_X22,
49 	ZREG_X23,
50 	ZREG_X24,
51 	ZREG_X25,
52 	ZREG_X26,
53 	ZREG_X27,
54 	ZREG_X28,
55 	ZREG_X29,
56 	ZREG_X30,
57 	ZREG_X31,
58 
59 	ZREG_V0,
60 	ZREG_V1,
61 	ZREG_V2,
62 	ZREG_V3,
63 	ZREG_V4,
64 	ZREG_V5,
65 	ZREG_V6,
66 	ZREG_V7,
67 	ZREG_V8,
68 	ZREG_V9,
69 	ZREG_V10,
70 	ZREG_V11,
71 	ZREG_V12,
72 	ZREG_V13,
73 	ZREG_V14,
74 	ZREG_V15,
75 	ZREG_V16,
76 	ZREG_V17,
77 	ZREG_V18,
78 	ZREG_V19,
79 	ZREG_V20,
80 	ZREG_V21,
81 	ZREG_V22,
82 	ZREG_V23,
83 	ZREG_V24,
84 	ZREG_V25,
85 	ZREG_V26,
86 	ZREG_V27,
87 	ZREG_V28,
88 	ZREG_V29,
89 	ZREG_V30,
90 	ZREG_V31,
91 
92 	ZREG_NUM,
93 
94 	ZREG_THIS, /* used for delayed FETCH_THIS deoptimization */
95 
96 	/* pseudo constants used by deoptimizer */
97 	ZREG_LONG_MIN_MINUS_1,
98 	ZREG_LONG_MIN,
99 	ZREG_LONG_MAX,
100 	ZREG_LONG_MAX_PLUS_1,
101 	ZREG_NULL,
102 
103 	ZREG_ZVAL_TRY_ADDREF,
104 	ZREG_ZVAL_COPY_GPR0,
105 } zend_reg;
106 
107 typedef struct _zend_jit_registers_buf {
108 	uint64_t gpr[32];   /* general purpose integer register */
109 	double   fpr[32];   /* floating point registers */
110 } zend_jit_registers_buf;
111 
112 #define ZREG_RSP   ZREG_X31
113 #define ZREG_RLR   ZREG_X30
114 #define ZREG_RFP   ZREG_X29
115 #define ZREG_RPR   ZREG_X18
116 
117 #define ZREG_FP    ZREG_X27
118 #define ZREG_IP    ZREG_X28
119 #define ZREG_RX    ZREG_IP
120 
121 #define ZREG_REG0  ZREG_X8
122 #define ZREG_REG1  ZREG_X9
123 #define ZREG_REG2  ZREG_X10
124 
125 #define ZREG_FPR0  ZREG_V0
126 #define ZREG_FPR1  ZREG_V1
127 
128 #define ZREG_TMP1  ZREG_X15
129 #define ZREG_TMP2  ZREG_X16
130 #define ZREG_TMP3  ZREG_X17
131 #define ZREG_FPTMP ZREG_V16
132 
133 #define ZREG_COPY      ZREG_REG0
134 #define ZREG_FIRST_FPR ZREG_V0
135 
136 typedef uint64_t zend_regset;
137 
138 #define ZEND_REGSET_64BIT 1
139 
140 # define ZEND_REGSET_FIXED \
141 	(ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_RLR) | ZEND_REGSET(ZREG_RFP) | \
142 	ZEND_REGSET(ZREG_RPR) | ZEND_REGSET(ZREG_FP) | ZEND_REGSET(ZREG_IP) | \
143 	ZEND_REGSET_INTERVAL(ZREG_TMP1, ZREG_TMP3) | ZEND_REGSET(ZREG_FPTMP))
144 # define ZEND_REGSET_GP \
145 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_X0, ZREG_X30), ZEND_REGSET_FIXED)
146 # define ZEND_REGSET_FP \
147 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_V0, ZREG_V31), ZEND_REGSET_FIXED)
148 # define ZEND_REGSET_SCRATCH \
149 	(ZEND_REGSET_INTERVAL(ZREG_X0, ZREG_X17) | ZEND_REGSET_INTERVAL(ZREG_V0, ZREG_V7) | \
150 	ZEND_REGSET_INTERVAL(ZREG_V16, ZREG_V31))
151 # define ZEND_REGSET_PRESERVED \
152 	(ZEND_REGSET_INTERVAL(ZREG_X19, ZREG_X28) | ZEND_REGSET_INTERVAL(ZREG_V8, ZREG_V15))
153 
154 #define ZEND_REGSET_LOW_PRIORITY \
155 	(ZEND_REGSET(ZREG_REG0) | ZEND_REGSET(ZREG_REG1) | ZEND_REGSET(ZREG_FPR0) | ZEND_REGSET(ZREG_FPR1))
156 
157 #endif /* ZEND_JIT_ARM64_H */
158