diff options
| author | Mike Pall <mike> | 2010-02-16 23:39:24 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2010-02-16 23:39:24 +0100 |
| commit | 8060f5b53145b977c04bddf414aa541cb73ec536 (patch) | |
| tree | 9bae21eff945ef8794106427e1e7155f0612b7d0 | |
| parent | c225ee8db4300e1dbf13fcdfc15d8f44da175877 (diff) | |
| download | luajit-8060f5b53145b977c04bddf414aa541cb73ec536.tar.gz luajit-8060f5b53145b977c04bddf414aa541cb73ec536.tar.bz2 luajit-8060f5b53145b977c04bddf414aa541cb73ec536.zip | |
Just disable JIT compiler for non-SSE2 CPUs instead of aborting.
| -rw-r--r-- | doc/status.html | 11 | ||||
| -rw-r--r-- | src/lib_jit.c | 20 | ||||
| -rw-r--r-- | src/lj_dispatch.c | 6 | ||||
| -rw-r--r-- | src/lj_errmsg.h | 8 |
4 files changed, 27 insertions, 18 deletions
diff --git a/doc/status.html b/doc/status.html index c5564d58..ba62625e 100644 --- a/doc/status.html +++ b/doc/status.html | |||
| @@ -65,10 +65,13 @@ This is a list of the things you should know about the LuaJIT 2.0 beta test: | |||
| 65 | </p> | 65 | </p> |
| 66 | <ul> | 66 | <ul> |
| 67 | <li> | 67 | <li> |
| 68 | The JIT compiler can only generate code for CPUs with <b>SSE2</b> at the | 68 | The JIT compiler only generates code for CPUs with support for |
| 69 | moment. I.e. you need at least a P4, Core 2/i5/i7 or K8/K10 to use it. I | 69 | <b>SSE2</b> instructions. I.e. you need at least a P4, Core 2/i5/i7 |
| 70 | plan to fix this during the beta phase and add support for emitting x87 | 70 | or K8/K10 to get the full benefit.<br> |
| 71 | instructions to the backend. | 71 | If you run LuaJIT on older CPUs without SSE2 support, the JIT compiler |
| 72 | is disabled and the VM falls back to the interpreter. | ||
| 73 | Run the command line executable without arguments to show the current status | ||
| 74 | (<tt>JIT: ON</tt> or <tt>JIT: OFF</tt>). | ||
| 72 | </li> | 75 | </li> |
| 73 | <li> | 76 | <li> |
| 74 | Obviously there will be many <b>bugs</b> in a VM which has been | 77 | Obviously there will be many <b>bugs</b> in a VM which has been |
diff --git a/src/lib_jit.c b/src/lib_jit.c index 0ee5ad0d..34e5bd34 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c | |||
| @@ -49,12 +49,10 @@ static int setjitmode(lua_State *L, int mode) | |||
| 49 | mode |= LUAJIT_MODE_FUNC; | 49 | mode |= LUAJIT_MODE_FUNC; |
| 50 | } | 50 | } |
| 51 | if (luaJIT_setmode(L, idx, mode) != 1) { | 51 | if (luaJIT_setmode(L, idx, mode) != 1) { |
| 52 | if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE) | ||
| 53 | lj_err_caller(L, LJ_ERR_NOJIT); | ||
| 52 | err: | 54 | err: |
| 53 | #if LJ_HASJIT | ||
| 54 | lj_err_arg(L, 1, LJ_ERR_NOLFUNC); | 55 | lj_err_arg(L, 1, LJ_ERR_NOLFUNC); |
| 55 | #else | ||
| 56 | lj_err_caller(L, LJ_ERR_NOJIT); | ||
| 57 | #endif | ||
| 58 | } | 56 | } |
| 59 | return 0; | 57 | return 0; |
| 60 | } | 58 | } |
| @@ -532,19 +530,15 @@ static uint32_t jit_cpudetect(lua_State *L) | |||
| 532 | } | 530 | } |
| 533 | #endif | 531 | #endif |
| 534 | } | 532 | } |
| 535 | /* Check for required instruction set support on x86. */ | 533 | /* Check for required instruction set support on x86 (unnecessary on x64). */ |
| 536 | #if LJ_TARGET_X86 | 534 | #if LJ_TARGET_X86 |
| 537 | #if !defined(LUAJIT_CPU_NOCMOV) | 535 | #if !defined(LUAJIT_CPU_NOCMOV) |
| 538 | if (!(flags & JIT_F_CMOV)) | 536 | if (!(flags & JIT_F_CMOV)) |
| 539 | luaL_error(L, "Ancient CPU lacks CMOV support (recompile with -DLUAJIT_CPU_NOCMOV)"); | 537 | luaL_error(L, "Ancient CPU lacks CMOV support (recompile with -DLUAJIT_CPU_NOCMOV)"); |
| 540 | #endif | 538 | #endif |
| 541 | if (!(flags & JIT_F_SSE2)) | ||
| 542 | #if defined(LUAJIT_CPU_SSE2) | 539 | #if defined(LUAJIT_CPU_SSE2) |
| 540 | if (!(flags & JIT_F_SSE2)) | ||
| 543 | luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); | 541 | luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); |
| 544 | #elif LJ_HASJIT | ||
| 545 | luaL_error(L, "Sorry, SSE2 CPU support required for this beta release"); | ||
| 546 | #else | ||
| 547 | (void)0; | ||
| 548 | #endif | 542 | #endif |
| 549 | #endif | 543 | #endif |
| 550 | UNUSED(L); | 544 | UNUSED(L); |
| @@ -560,7 +554,11 @@ static void jit_init(lua_State *L) | |||
| 560 | uint32_t flags = jit_cpudetect(L); | 554 | uint32_t flags = jit_cpudetect(L); |
| 561 | #if LJ_HASJIT | 555 | #if LJ_HASJIT |
| 562 | jit_State *J = L2J(L); | 556 | jit_State *J = L2J(L); |
| 563 | J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; | 557 | #if LJ_TARGET_X86 |
| 558 | /* Silently turn off the JIT compiler on CPUs without SSE2. */ | ||
| 559 | if ((flags & JIT_F_SSE2)) | ||
| 560 | #endif | ||
| 561 | J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; | ||
| 564 | memcpy(J->param, jit_param_default, sizeof(J->param)); | 562 | memcpy(J->param, jit_param_default, sizeof(J->param)); |
| 565 | lj_dispatch_update(G(L)); | 563 | lj_dispatch_update(G(L)); |
| 566 | #else | 564 | #else |
diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c index 4629fb7e..7b3ff80b 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c | |||
| @@ -209,10 +209,12 @@ int luaJIT_setmode(lua_State *L, int idx, int mode) | |||
| 209 | if ((mode & LUAJIT_MODE_FLUSH)) { | 209 | if ((mode & LUAJIT_MODE_FLUSH)) { |
| 210 | lj_trace_flushall(L); | 210 | lj_trace_flushall(L); |
| 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; | ||
| 214 | else if ((G2J(g)->flags & JIT_F_SSE2)) | ||
| 213 | G2J(g)->flags |= (uint32_t)JIT_F_ON; | 215 | G2J(g)->flags |= (uint32_t)JIT_F_ON; |
| 214 | else | 216 | else |
| 215 | G2J(g)->flags &= ~(uint32_t)JIT_F_ON; | 217 | return 0; /* Don't turn on JIT compiler without SSE2 support. */ |
| 216 | lj_dispatch_update(g); | 218 | lj_dispatch_update(g); |
| 217 | } | 219 | } |
| 218 | break; | 220 | break; |
diff --git a/src/lj_errmsg.h b/src/lj_errmsg.h index 0a2d9dd7..4891b74e 100644 --- a/src/lj_errmsg.h +++ b/src/lj_errmsg.h | |||
| @@ -100,7 +100,13 @@ ERRDEF(STRFMTR, "invalid format (repeated flags)") | |||
| 100 | ERRDEF(STRFMTW, "invalid format (width or precision too long)") | 100 | ERRDEF(STRFMTW, "invalid format (width or precision too long)") |
| 101 | ERRDEF(STRGSRV, "invalid replacement value (a %s)") | 101 | ERRDEF(STRGSRV, "invalid replacement value (a %s)") |
| 102 | ERRDEF(BADMODN, "name conflict for module " LUA_QS) | 102 | ERRDEF(BADMODN, "name conflict for module " LUA_QS) |
| 103 | ERRDEF(NOJIT, "JIT compiler permanently disabled") | 103 | #if LJ_HASJIT |
| 104 | ERRDEF(NOJIT, "JIT compiler disabled, CPU does not support SSE2") | ||
| 105 | #elif defined(LJ_ARCH_NOJIT) | ||
| 106 | ERRDEF(NOJIT, "no JIT compiler for this architecture (yet)") | ||
| 107 | #else | ||
| 108 | ERRDEF(NOJIT, "JIT compiler permanently disabled by build option") | ||
| 109 | #endif | ||
| 104 | ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS) | 110 | ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS) |
| 105 | 111 | ||
| 106 | /* Lexer/parser errors. */ | 112 | /* Lexer/parser errors. */ |
