aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-05-09 18:16:39 +0200
committerMike Pall <mike>2011-05-09 20:46:58 +0200
commit67d3ac9b19caba68069e83d1e3e9de14994d66cd (patch)
treead1b075e255dcaabebfea8b6e5e70aa4a3eb63d2 /src
parent28e87d33e931661e8118a25b293213938a9e0af4 (diff)
downloadluajit-67d3ac9b19caba68069e83d1e3e9de14994d66cd.tar.gz
luajit-67d3ac9b19caba68069e83d1e3e9de14994d66cd.tar.bz2
luajit-67d3ac9b19caba68069e83d1e3e9de14994d66cd.zip
Fix some portability issues with the JIT compiler.
Diffstat (limited to 'src')
-rw-r--r--src/lib_jit.c4
-rw-r--r--src/lj_dispatch.c5
-rw-r--r--src/lj_jit.h33
-rw-r--r--src/lj_mcode.c4
-rw-r--r--src/lj_snap.c5
-rw-r--r--src/lj_trace.c4
6 files changed, 38 insertions, 17 deletions
diff --git a/src/lib_jit.c b/src/lib_jit.c
index 8f809875..e2fc8067 100644
--- a/src/lib_jit.c
+++ b/src/lib_jit.c
@@ -368,12 +368,16 @@ LJLIB_CF(jit_util_tracemc)
368/* local addr = jit.util.traceexitstub(idx) */ 368/* local addr = jit.util.traceexitstub(idx) */
369LJLIB_CF(jit_util_traceexitstub) 369LJLIB_CF(jit_util_traceexitstub)
370{ 370{
371#ifdef EXITSTUBS_PER_GROUP
371 ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1); 372 ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1);
372 jit_State *J = L2J(L); 373 jit_State *J = L2J(L);
373 if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) { 374 if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) {
374 setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno)); 375 setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno));
375 return 1; 376 return 1;
376 } 377 }
378#else
379 UNUSED(L);
380#endif
377 return 0; 381 return 0;
378} 382}
379 383
diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c
index 42027e7d..425eeaa2 100644
--- a/src/lj_dispatch.c
+++ b/src/lj_dispatch.c
@@ -211,10 +211,15 @@ int luaJIT_setmode(lua_State *L, int idx, int mode)
211 } else { 211 } else {
212 if (!(mode & LUAJIT_MODE_ON)) 212 if (!(mode & LUAJIT_MODE_ON))
213 G2J(g)->flags &= ~(uint32_t)JIT_F_ON; 213 G2J(g)->flags &= ~(uint32_t)JIT_F_ON;
214#if LJ_TARGET_X86ORX64
214 else if ((G2J(g)->flags & JIT_F_SSE2)) 215 else if ((G2J(g)->flags & JIT_F_SSE2))
215 G2J(g)->flags |= (uint32_t)JIT_F_ON; 216 G2J(g)->flags |= (uint32_t)JIT_F_ON;
216 else 217 else
217 return 0; /* Don't turn on JIT compiler without SSE2 support. */ 218 return 0; /* Don't turn on JIT compiler without SSE2 support. */
219#else
220 else
221 G2J(g)->flags |= (uint32_t)JIT_F_ON;
222#endif
218 lj_dispatch_update(g); 223 lj_dispatch_update(g);
219 } 224 }
220 break; 225 break;
diff --git a/src/lj_jit.h b/src/lj_jit.h
index cced4813..22f1d581 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -27,7 +27,8 @@
27#define JIT_F_CPU_FIRST JIT_F_CMOV 27#define JIT_F_CPU_FIRST JIT_F_CMOV
28#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM" 28#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM"
29#else 29#else
30#error "Missing CPU-specific JIT engine flags" 30#define JIT_F_CPU_FIRST 0
31#define JIT_F_CPUSTRING ""
31#endif 32#endif
32 33
33/* Optimization flags. */ 34/* Optimization flags. */
@@ -118,7 +119,11 @@ typedef enum {
118} PostProc; 119} PostProc;
119 120
120/* Machine code type. */ 121/* Machine code type. */
122#if LJ_TARGET_X86ORX64
121typedef uint8_t MCode; 123typedef uint8_t MCode;
124#else
125typedef uint32_t MCode;
126#endif
122 127
123/* Stack snapshot header. */ 128/* Stack snapshot header. */
124typedef struct SnapShot { 129typedef struct SnapShot {
@@ -252,6 +257,13 @@ enum {
252#define lj_resetsplit(J) UNUSED(J) 257#define lj_resetsplit(J) UNUSED(J)
253#endif 258#endif
254 259
260/* Exit stubs. */
261#if LJ_TARGET_X86ORX64
262/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
263#define EXITSTUB_SPACING (2+2)
264#define EXITSTUBS_PER_GROUP 32
265#endif
266
255/* Fold state is used to fold instructions on-the-fly. */ 267/* Fold state is used to fold instructions on-the-fly. */
256typedef struct FoldState { 268typedef struct FoldState {
257 IRIns ins; /* Currently emitted instruction. */ 269 IRIns ins; /* Currently emitted instruction. */
@@ -318,7 +330,9 @@ typedef struct jit_State {
318 330
319 int32_t param[JIT_P__MAX]; /* JIT engine parameters. */ 331 int32_t param[JIT_P__MAX]; /* JIT engine parameters. */
320 332
333#if LJ_TARGET_X86ORX64
321 MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */ 334 MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */
335#endif
322 336
323 HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ 337 HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */
324 uint32_t penaltyslot; /* Round-robin index into penalty slots. */ 338 uint32_t penaltyslot; /* Round-robin index into penalty slots. */
@@ -344,7 +358,7 @@ typedef struct jit_State {
344 size_t szallmcarea; /* Total size of all allocated mcode areas. */ 358 size_t szallmcarea; /* Total size of all allocated mcode areas. */
345 359
346 TValue errinfo; /* Additional info element for trace errors. */ 360 TValue errinfo; /* Additional info element for trace errors. */
347} jit_State; 361} LJ_ALIGN(16) jit_State;
348 362
349/* Trivial PRNG e.g. used for penalty randomization. */ 363/* Trivial PRNG e.g. used for penalty randomization. */
350static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits) 364static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
@@ -354,21 +368,14 @@ static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
354 return J->prngstate >> (32-bits); 368 return J->prngstate >> (32-bits);
355} 369}
356 370
357/* Exit stubs. */ 371#ifdef EXITSTUBS_PER_GROUP
358#if LJ_TARGET_X86ORX64
359/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
360#define EXITSTUB_SPACING (2+2)
361#define EXITSTUBS_PER_GROUP 32
362#else
363#error "Missing CPU-specific exit stub definitions"
364#endif
365
366/* Return the address of an exit stub. */ 372/* Return the address of an exit stub. */
367static LJ_AINLINE MCode *exitstub_addr(jit_State *J, ExitNo exitno) 373static LJ_AINLINE MCode *exitstub_addr(jit_State *J, ExitNo exitno)
368{ 374{
369 lua_assert(J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] != NULL); 375 lua_assert(J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] != NULL);
370 return J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] + 376 return (MCode *)((char *)J->exitstubgroup[exitno / EXITSTUBS_PER_GROUP] +
371 EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP); 377 EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP));
372} 378}
379#endif
373 380
374#endif 381#endif
diff --git a/src/lj_mcode.c b/src/lj_mcode.c
index 104e4925..b3ce1f7f 100644
--- a/src/lj_mcode.c
+++ b/src/lj_mcode.c
@@ -274,7 +274,7 @@ MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)
274 } else { 274 } else {
275 MCode *mc = J->mcarea; 275 MCode *mc = J->mcarea;
276 /* Try current area first to use the protection cache. */ 276 /* Try current area first to use the protection cache. */
277 if (ptr >= mc && ptr < mc + J->szmcarea) { 277 if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {
278 mcode_protect(J, MCPROT_GEN); 278 mcode_protect(J, MCPROT_GEN);
279 return mc; 279 return mc;
280 } 280 }
@@ -282,7 +282,7 @@ MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)
282 for (;;) { 282 for (;;) {
283 mc = ((MCLink *)mc)->next; 283 mc = ((MCLink *)mc)->next;
284 lua_assert(mc != NULL); 284 lua_assert(mc != NULL);
285 if (ptr >= mc && ptr < mc + ((MCLink *)mc)->size) { 285 if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {
286 mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN); 286 mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN);
287 return mc; 287 return mc;
288 } 288 }
diff --git a/src/lj_snap.c b/src/lj_snap.c
index c044923a..a3c081e1 100644
--- a/src/lj_snap.c
+++ b/src/lj_snap.c
@@ -406,7 +406,10 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
406 if (irt_isinteger(t)) { 406 if (irt_isinteger(t)) {
407 setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]); 407 setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);
408 } else if (irt_isnum(t)) { 408 } else if (irt_isnum(t)) {
409 setnumV(o, ex->fpr[r-RID_MIN_FPR]); 409 if (RID_NUM_FPR)
410 setnumV(o, ex->fpr[r-RID_MIN_FPR]);
411 else
412 setnumV(o, *(double *)&ex->gpr[r-RID_MIN_GPR]);
410#if LJ_64 413#if LJ_64
411 } else if (irt_islightud(t)) { 414 } else if (irt_islightud(t)) {
412 /* 64 bit lightuserdata which may escape already has the tag bits. */ 415 /* 64 bit lightuserdata which may escape already has the tag bits. */
diff --git a/src/lj_trace.c b/src/lj_trace.c
index ab75c9d2..ecfbfed6 100644
--- a/src/lj_trace.c
+++ b/src/lj_trace.c
@@ -278,7 +278,9 @@ int lj_trace_flushall(lua_State *L)
278 memset(J->penalty, 0, sizeof(J->penalty)); 278 memset(J->penalty, 0, sizeof(J->penalty));
279 /* Free the whole machine code and invalidate all exit stub groups. */ 279 /* Free the whole machine code and invalidate all exit stub groups. */
280 lj_mcode_free(J); 280 lj_mcode_free(J);
281#ifdef EXITSTUBS_PER_GROUP
281 memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup)); 282 memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
283#endif
282 lj_vmevent_send(L, TRACE, 284 lj_vmevent_send(L, TRACE,
283 setstrV(L, L->top++, lj_str_newlit(L, "flush")); 285 setstrV(L, L->top++, lj_str_newlit(L, "flush"));
284 ); 286 );
@@ -700,7 +702,7 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
700 702
701 lj_vmevent_send(L, TEXIT, 703 lj_vmevent_send(L, TEXIT,
702 ExitState *ex = (ExitState *)exptr; 704 ExitState *ex = (ExitState *)exptr;
703 uint32_t i; 705 int32_t i;
704 lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK); 706 lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);
705 setintV(L->top++, J->parent); 707 setintV(L->top++, J->parent);
706 setintV(L->top++, J->exitno); 708 setintV(L->top++, J->exitno);