aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2011-05-16 02:29:44 +0200
committerMike Pall <mike>2011-05-16 02:29:44 +0200
commitbe73a96751261bb3a424aa1c5d28547f23037733 (patch)
tree4baa8353f73592a5b5cf034666fd19a7a96f74a5
parent58f38c254bcdcf1f874f2e052751f568c2866133 (diff)
downloadluajit-be73a96751261bb3a424aa1c5d28547f23037733.tar.gz
luajit-be73a96751261bb3a424aa1c5d28547f23037733.tar.bz2
luajit-be73a96751261bb3a424aa1c5d28547f23037733.zip
ARM: Generalize machine code co-location. ARM has a +-32MB range.
-rw-r--r--src/lj_mcode.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/lj_mcode.c b/src/lj_mcode.c
index b3ce1f7f..8d0f7213 100644
--- a/src/lj_mcode.c
+++ b/src/lj_mcode.c
@@ -156,23 +156,43 @@ static void mcode_protect(jit_State *J, int prot)
156 156
157/* -- MCode area allocation ----------------------------------------------- */ 157/* -- MCode area allocation ----------------------------------------------- */
158 158
159#if LJ_64 159#if LJ_TARGET_X64
160#define mcode_validptr(p) ((p) && (uintptr_t)(p) < (uintptr_t)1<<47)
161#else
162#define mcode_validptr(p) ((p) && (uintptr_t)(p) < 0xffff0000)
163#endif
164
165#if LJ_TARGET_X64
166#define MCODE_JUMPRANGE 31
167#elif LJ_TARGET_ARM
168#define MCODE_JUMPRANGE 26
169#else
170#define MCODE_JUMPRANGE 32
171#endif
172
173#if MCODE_JUMPRANGE == 32
174
175/* All 32 bit memory addresses are reachable by relative jumps. */
176#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN)
177
178#else
160 179
161/* Get memory within relative jump distance of our code in 64 bit mode. */ 180/* Get memory within relative jump distance of our code in 64 bit mode. */
162static void *mcode_alloc(jit_State *J, size_t sz) 181static void *mcode_alloc(jit_State *J, size_t sz)
163{ 182{
164 /* Target an address in the static assembler code (64K aligned). 183 /* Target an address in the static assembler code (64K aligned).
165 ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB. 184 ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB.
166 */ 185 */
167 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; 186 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;
168 const uintptr_t range = (1u<<31) - (1u << 21); 187 const uintptr_t range = (1u << MCODE_JUMPRANGE) - (1u << 21);
169 /* First try a contiguous area below the last one. */ 188 /* First try a contiguous area below the last one. */
170 uintptr_t hint = (uintptr_t)J->mcarea - sz; 189 uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;
171 int i; 190 int i;
172 for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */ 191 for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */
173 if (hint && hint < (uintptr_t)1<<47) { 192 if (mcode_validptr(hint)) {
174 void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); 193 void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);
175 if (p && (uintptr_t)p < (uintptr_t)1<<47) { 194
195 if (mcode_validptr(p)) {
176 if ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range) 196 if ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)
177 return p; 197 return p;
178 mcode_free(J, p, sz); /* Free badly placed area. */ 198 mcode_free(J, p, sz); /* Free badly placed area. */
@@ -188,11 +208,6 @@ static void *mcode_alloc(jit_State *J, size_t sz)
188 return NULL; 208 return NULL;
189} 209}
190 210
191#else
192
193/* All 32 bit memory addresses are reachable by relative jumps on x86. */
194#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN)
195
196#endif 211#endif
197 212
198/* -- MCode area management ----------------------------------------------- */ 213/* -- MCode area management ----------------------------------------------- */