xref: /PHP-8.1/ext/opcache/jit/zend_jit_x86.h (revision c1198174)
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    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef HAVE_JIT_X86_H
20 #define HAVE_JIT_X86_H
21 
22 typedef enum _zend_reg {
23 	ZREG_NONE = -1,
24 
25 	ZREG_R0,
26 	ZREG_R1,
27 	ZREG_R2,
28 	ZREG_R3,
29 	ZREG_R4,
30 	ZREG_R5,
31 	ZREG_R6,
32 	ZREG_R7,
33 
34 #if defined(__x86_64__) || defined(_WIN64)
35 	ZREG_R8,
36 	ZREG_R9,
37 	ZREG_R10,
38 	ZREG_R11,
39 	ZREG_R12,
40 	ZREG_R13,
41 	ZREG_R14,
42 	ZREG_R15,
43 #endif
44 
45 	ZREG_XMM0,
46 	ZREG_XMM1,
47 	ZREG_XMM2,
48 	ZREG_XMM3,
49 	ZREG_XMM4,
50 	ZREG_XMM5,
51 	ZREG_XMM6,
52 	ZREG_XMM7,
53 
54 #if defined(__x86_64__) || defined(_WIN64)
55 	ZREG_XMM8,
56 	ZREG_XMM9,
57 	ZREG_XMM10,
58 	ZREG_XMM11,
59 	ZREG_XMM12,
60 	ZREG_XMM13,
61 	ZREG_XMM14,
62 	ZREG_XMM15,
63 #endif
64 
65 	ZREG_NUM,
66 
67 	ZREG_THIS, /* used for delayed FETCH_THIS deoptimization */
68 
69 	/* pseudo constants used by deoptimizer */
70 	ZREG_LONG_MIN_MINUS_1,
71 	ZREG_LONG_MIN,
72 	ZREG_LONG_MAX,
73 	ZREG_LONG_MAX_PLUS_1,
74 	ZREG_NULL,
75 
76 	ZREG_ZVAL_TRY_ADDREF,
77 	ZREG_ZVAL_COPY_GPR0,
78 } zend_reg;
79 
80 typedef struct _zend_jit_registers_buf {
81 #if defined(__x86_64__) || defined(_WIN64)
82 	uint64_t gpr[16]; /* general purpose integer register */
83 	double   fpr[16]; /* floating point registers */
84 #else
85 	uint32_t gpr[8]; /* general purpose integer register */
86 	double   fpr[8]; /* floating point registers */
87 #endif
88 } zend_jit_registers_buf;
89 
90 #define ZREG_FIRST_FPR ZREG_XMM0
91 #define ZREG_COPY      ZREG_R0
92 
93 #define ZREG_RAX ZREG_R0
94 #define ZREG_RCX ZREG_R1
95 #define ZREG_RDX ZREG_R2
96 #define ZREG_RBX ZREG_R3
97 #define ZREG_RSP ZREG_R4
98 #define ZREG_RBP ZREG_R5
99 #define ZREG_RSI ZREG_R6
100 #define ZREG_RDI ZREG_R7
101 
102 #ifdef _WIN64
103 # define ZREG_FP ZREG_R14
104 # define ZREG_IP ZREG_R15
105 #elif defined(__x86_64__)
106 # define ZREG_FP ZREG_R14
107 # define ZREG_IP ZREG_R15
108 #else
109 # define ZREG_FP ZREG_RSI
110 # define ZREG_IP ZREG_RDI
111 #endif
112 
113 #define ZREG_RX  ZREG_IP
114 
115 typedef uint32_t zend_regset;
116 
117 #define ZEND_REGSET_64BIT 0
118 
119 #ifdef _WIN64
120 # define ZEND_REGSET_FIXED \
121 	(ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_R14) | ZEND_REGSET(ZREG_R15))
122 # define ZEND_REGSET_GP \
123 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R15), ZEND_REGSET_FIXED)
124 # define ZEND_REGSET_FP \
125 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM15), ZEND_REGSET_FIXED)
126 # define ZEND_REGSET_SCRATCH \
127 	(ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET_INTERVAL(ZREG_R8, ZREG_R11) | ZEND_REGSET_FP)
128 # define ZEND_REGSET_PRESERVED \
129 	(ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP) | ZEND_REGSET(ZREG_R12) | ZEND_REGSET(ZREG_R13) | ZEND_REGSET(ZREG_RDI) | ZEND_REGSET(ZREG_RSI))
130 #elif defined(__x86_64__)
131 # define ZEND_REGSET_FIXED \
132 	(ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_R14) | ZEND_REGSET(ZREG_R15))
133 # define ZEND_REGSET_GP \
134 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R15), ZEND_REGSET_FIXED)
135 # define ZEND_REGSET_FP \
136 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM15), ZEND_REGSET_FIXED)
137 # define ZEND_REGSET_SCRATCH \
138 	(ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RDI) | ZEND_REGSET(ZREG_RSI) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET_INTERVAL(ZREG_R8, ZREG_R11) | ZEND_REGSET_FP)
139 # define ZEND_REGSET_PRESERVED \
140 	(ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP) | ZEND_REGSET(ZREG_R12) | ZEND_REGSET(ZREG_R13))
141 #else
142 # define ZEND_REGSET_FIXED \
143 	(ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_RSI) | ZEND_REGSET(ZREG_RDI))
144 # define ZEND_REGSET_GP \
145 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R7), ZEND_REGSET_FIXED)
146 # define ZEND_REGSET_FP \
147 	ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM7), ZEND_REGSET_FIXED)
148 # define ZEND_REGSET_SCRATCH \
149 	(ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET_FP)
150 # define ZEND_REGSET_PRESERVED \
151 	(ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP))
152 #endif
153 
154 #define ZEND_REGSET_LOW_PRIORITY \
155 	(ZEND_REGSET(ZREG_R0) | ZEND_REGSET(ZREG_R1) | ZEND_REGSET(ZREG_XMM0) | ZEND_REGSET(ZREG_XMM1))
156 
157 #endif /* ZEND_JIT_X86_H */
158