/* local addr = jit.util.traceexitstub(idx) */
LJLIB_CF(jit_util_traceexitstub)
{
+#ifdef EXITSTUBS_PER_GROUP
ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1);
jit_State *J = L2J(L);
if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) {
setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno));
return 1;
}
+#else
+ UNUSED(L);
+#endif
return 0;
}
} else {
if (!(mode & LUAJIT_MODE_ON))
G2J(g)->flags &= ~(uint32_t)JIT_F_ON;
+#if LJ_TARGET_X86ORX64
else if ((G2J(g)->flags & JIT_F_SSE2))
G2J(g)->flags |= (uint32_t)JIT_F_ON;
else
return 0; /* Don't turn on JIT compiler without SSE2 support. */
+#else
+ else
+ G2J(g)->flags |= (uint32_t)JIT_F_ON;
+#endif
lj_dispatch_update(g);
}
break;
#define JIT_F_CPU_FIRST JIT_F_CMOV
#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM"
#else
-#error "Missing CPU-specific JIT engine flags"
+#define JIT_F_CPU_FIRST 0
+#define JIT_F_CPUSTRING ""
#endif
/* Optimization flags. */
} PostProc;
/* Machine code type. */
+#if LJ_TARGET_X86ORX64
typedef uint8_t MCode;
+#else
+typedef uint32_t MCode;
+#endif
/* Stack snapshot header. */
typedef struct SnapShot {
#define lj_resetsplit(J) UNUSED(J)
#endif
+/* Exit stubs. */
+#if LJ_TARGET_X86ORX64
+/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
+#define EXITSTUB_SPACING (2+2)
+#define EXITSTUBS_PER_GROUP 32
+#endif
+
/* Fold state is used to fold instructions on-the-fly. */
typedef struct FoldState {
IRIns ins; /* Currently emitted instruction. */
int32_t param[JIT_P__MAX]; /* JIT engine parameters. */
+#if LJ_TARGET_X86ORX64
MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */
+#endif
HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */
uint32_t penaltyslot; /* Round-robin index into penalty slots. */
size_t szallmcarea; /* Total size of all allocated mcode areas. */
TValue errinfo; /* Additional info element for trace errors. */
-} jit_State;
+} LJ_ALIGN(16) jit_State;
/* Trivial PRNG e.g. used for penalty randomization. */
static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
return J->prngstate >> (32-bits);
}
-/* Exit stubs. */
-#if LJ_TARGET_X86ORX64
-/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
-#define EXITSTUB_SPACING (2+2)
-#define EXITSTUBS_PER_GROUP 32
-#else
-#error "Missing CPU-specific exit stub definitions"
-#endif
-
+#ifdef EXITSTUBS_PER_GROUP
/* Return the address of an exit stub. */
static LJ_AINLINE MCode *exitstub_addr(jit_State *J, ExitNo exitno)
{
lua_assert(J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] != NULL);
- return J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] +
- EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP);
+ return (MCode *)((char *)J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] +
+ EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP));
}
+#endif
#endif
} else {
MCode *mc = J->mcarea;
/* Try current area first to use the protection cache. */
- if (ptr >= mc && ptr < mc + J->szmcarea) {
+ if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {
mcode_protect(J, MCPROT_GEN);
return mc;
}
for (;;) {
mc = ((MCLink *)mc)->next;
lua_assert(mc != NULL);
- if (ptr >= mc && ptr < mc + ((MCLink *)mc)->size) {
+ if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {
mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN);
return mc;
}
if (irt_isinteger(t)) {
setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);
} else if (irt_isnum(t)) {
- setnumV(o, ex->fpr[r-RID_MIN_FPR]);
+ if (RID_NUM_FPR)
+ setnumV(o, ex->fpr[r-RID_MIN_FPR]);
+ else
+ setnumV(o, *(double *)&ex->gpr[r-RID_MIN_GPR]);
#if LJ_64
} else if (irt_islightud(t)) {
/* 64 bit lightuserdata which may escape already has the tag bits. */
memset(J->penalty, 0, sizeof(J->penalty));
/* Free the whole machine code and invalidate all exit stub groups. */
lj_mcode_free(J);
+#ifdef EXITSTUBS_PER_GROUP
memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
+#endif
lj_vmevent_send(L, TRACE,
setstrV(L, L->top++, lj_str_newlit(L, "flush"));
);
lj_vmevent_send(L, TEXIT,
ExitState *ex = (ExitState *)exptr;
- uint32_t i;
+ int32_t i;
lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);
setintV(L->top++, J->parent);
setintV(L->top++, J->exitno);