summaryrefslogtreecommitdiff
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)
downloadluajit2-be73a96751261bb3a424aa1c5d28547f23037733.tar.gz
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)
/* -- MCode area allocation ----------------------------------------------- */
-#if LJ_64
+#if LJ_TARGET_X64
+#define mcode_validptr(p) ((p) && (uintptr_t)(p) < (uintptr_t)1<<47)
+#else
+#define mcode_validptr(p) ((p) && (uintptr_t)(p) < 0xffff0000)
+#endif
+
+#if LJ_TARGET_X64
+#define MCODE_JUMPRANGE 31
+#elif LJ_TARGET_ARM
+#define MCODE_JUMPRANGE 26
+#else
+#define MCODE_JUMPRANGE 32
+#endif
+
+#if MCODE_JUMPRANGE == 32
+
+/* All 32 bit memory addresses are reachable by relative jumps. */
+#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN)
+
+#else
/* Get memory within relative jump distance of our code in 64 bit mode. */
static void *mcode_alloc(jit_State *J, size_t sz)
{
/* Target an address in the static assembler code (64K aligned).
- ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB.
+ ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB.
*/
uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;
- const uintptr_t range = (1u<<31) - (1u << 21);
+ const uintptr_t range = (1u << MCODE_JUMPRANGE) - (1u << 21);
/* First try a contiguous area below the last one. */
- uintptr_t hint = (uintptr_t)J->mcarea - sz;
+ uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;
int i;
for (i = 0; i < 32; i++) { /* 32 attempts ought to be enough ... */
- if (hint && hint < (uintptr_t)1<<47) {
+ if (mcode_validptr(hint)) {
void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);
- if (p && (uintptr_t)p < (uintptr_t)1<<47) {
+
+ if (mcode_validptr(p)) {
if ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)
return p;
mcode_free(J, p, sz); /* Free badly placed area. */
@@ -188,11 +208,6 @@ static void *mcode_alloc(jit_State *J, size_t sz)
return NULL;
}
-#else
-
-/* All 32 bit memory addresses are reachable by relative jumps on x86. */
-#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN)
-
#endif
/* -- MCode area management ----------------------------------------------- */