@@ -110,6 +110,8 @@ static int sp_adj[SP_ADJ_LAST];
110
110
#define LDRB_STRB_PIMM MAX_IMM12 // ldrb/strb insn
111
111
112
112
#define B_IMM (1<<27) // signed imm26 * 4
113
+ #define ADR_IMM (1<<20) // signed imm21
114
+ #define ADRP_IMM (1LL<<32) // signed imm21 * 4096
113
115
114
116
static bool arm64_may_use_b(const void *addr)
115
117
{
@@ -123,6 +125,30 @@ static bool arm64_may_use_b(const void *addr)
123
125
return 0;
124
126
}
125
127
128
+ static bool arm64_may_use_adr(const void *addr)
129
+ {
130
+ if (addr >= dasm_buf && addr < dasm_end) {
131
+ return (((char*)dasm_end - (char*)dasm_buf) < ADR_IMM);
132
+ } else if (addr >= dasm_end) {
133
+ return (((char*)addr - (char*)dasm_buf) < ADR_IMM);
134
+ } else if (addr < dasm_buf) {
135
+ return (((char*)dasm_end - (char*)addr) < ADR_IMM);
136
+ }
137
+ return 0;
138
+ }
139
+
140
+ static bool arm64_may_use_adrp(const void *addr)
141
+ {
142
+ if (addr >= dasm_buf && addr < dasm_end) {
143
+ return (((char*)dasm_end - (char*)dasm_buf) < ADRP_IMM);
144
+ } else if (addr >= dasm_end) {
145
+ return (((char*)addr - (char*)dasm_buf) < ADRP_IMM);
146
+ } else if (addr < dasm_buf) {
147
+ return (((char*)dasm_end - (char*)addr) < ADRP_IMM);
148
+ }
149
+ return 0;
150
+ }
151
+
126
152
#include "Zend/zend_cpuinfo.h"
127
153
128
154
#ifdef HAVE_VALGRIND
@@ -223,6 +249,13 @@ static int logical_immediate_p (uint64_t value, uint32_t reg_size)
223
249
| mov reg, xzr
224
250
|| } else if (((uintptr_t)(addr)) <= MOVZ_IMM) {
225
251
| movz reg, #((uint64_t)(addr))
252
+ || } else if (arm64_may_use_adr((void*)(addr))) {
253
+ | adr reg, &addr
254
+ || } else if (arm64_may_use_adrp((void*)(addr))) {
255
+ | adrp reg, &(((uintptr_t)(addr)))
256
+ || if (((uintptr_t)(addr)) & 0xfff) {
257
+ | add reg, reg, #(((uintptr_t)(addr)) & 0xfff)
258
+ || }
226
259
|| } else if ((uintptr_t)(addr) & 0xffff) {
227
260
| movz reg, #((uintptr_t)(addr) & 0xffff)
228
261
|| if (((uintptr_t)(addr) >> 16) & 0xffff) {
0 commit comments