diff options
author | Mike Pall <mike> | 2009-12-22 20:27:20 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-22 20:27:20 +0100 |
commit | 6ce0c90ed642157f019b50ad1eb06246471a47b1 (patch) | |
tree | e3cc5e7207db2167f7f22a64ee4bfc8a93cd6ca5 | |
parent | a5faa29aa951d4fbd874b24350c315efc1cf3133 (diff) | |
download | luajit-6ce0c90ed642157f019b50ad1eb06246471a47b1.tar.gz luajit-6ce0c90ed642157f019b50ad1eb06246471a47b1.tar.bz2 luajit-6ce0c90ed642157f019b50ad1eb06246471a47b1.zip |
Add build infrastructure for the SSE2-enabled interpreter.
Works on x86 now. Will be enabled by default on x64 (not ready, yet).
-rw-r--r-- | src/Makefile | 8 | ||||
-rw-r--r-- | src/buildvm_x86.dasc | 2 | ||||
-rw-r--r-- | src/buildvm_x86.h | 2 | ||||
-rw-r--r-- | src/lib_jit.c | 14 |
4 files changed, 21 insertions, 5 deletions
diff --git a/src/Makefile b/src/Makefile index 209758fe..f0496248 100644 --- a/src/Makefile +++ b/src/Makefile | |||
@@ -62,6 +62,14 @@ XCFLAGS= | |||
62 | # interpreter. Don't bother if your OS wouldn't run on them, anyway. | 62 | # interpreter. Don't bother if your OS wouldn't run on them, anyway. |
63 | #XCFLAGS+= -DLUAJIT_CPU_NOCMOV | 63 | #XCFLAGS+= -DLUAJIT_CPU_NOCMOV |
64 | # | 64 | # |
65 | # Use SSE2 instructions instead of x87 instructions in the x86 interpreter | ||
66 | # (always enabled for x64). A pure interpreter built with this flag won't | ||
67 | # run on older CPUs (before P4 or K8). There isn't much of a speed | ||
68 | # difference, so this is not enabled by default. | ||
69 | # The JIT compiler is not affected by this flag. It always uses runtime | ||
70 | # CPU feature detection before emitting code for SSE2 up to SSE4.1. | ||
71 | #XCFLAGS+= -DLUAJIT_CPU_SSE2 | ||
72 | # | ||
65 | # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter: | 73 | # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter: |
66 | #XCFLAGS+= -DLUAJIT_DISABLE_JIT | 74 | #XCFLAGS+= -DLUAJIT_DISABLE_JIT |
67 | # | 75 | # |
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index b858a733..99842d08 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
@@ -4554,7 +4554,7 @@ static int build_backend(BuildCtx *ctx) | |||
4554 | #ifdef LUAJIT_CPU_NOCMOV | 4554 | #ifdef LUAJIT_CPU_NOCMOV |
4555 | cmov = 0; | 4555 | cmov = 0; |
4556 | #endif | 4556 | #endif |
4557 | #ifdef LUAJIT_CPU_SSE2 | 4557 | #if defined(LUAJIT_CPU_SSE2) || defined(LJ_TARGET_X64) |
4558 | sse = 1; | 4558 | sse = 1; |
4559 | #endif | 4559 | #endif |
4560 | 4560 | ||
diff --git a/src/buildvm_x86.h b/src/buildvm_x86.h index 0b61f43f..e2ba7c1e 100644 --- a/src/buildvm_x86.h +++ b/src/buildvm_x86.h | |||
@@ -2290,7 +2290,7 @@ static int build_backend(BuildCtx *ctx) | |||
2290 | #ifdef LUAJIT_CPU_NOCMOV | 2290 | #ifdef LUAJIT_CPU_NOCMOV |
2291 | cmov = 0; | 2291 | cmov = 0; |
2292 | #endif | 2292 | #endif |
2293 | #ifdef LUAJIT_CPU_SSE2 | 2293 | #if defined(LUAJIT_CPU_SSE2) || defined(LJ_TARGET_X64) |
2294 | sse = 1; | 2294 | sse = 1; |
2295 | #endif | 2295 | #endif |
2296 | 2296 | ||
diff --git a/src/lib_jit.c b/src/lib_jit.c index 6cd0d0b6..0352fbe5 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c | |||
@@ -524,10 +524,11 @@ static uint32_t jit_cpudetect(lua_State *L) | |||
524 | if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { | 524 | if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { |
525 | #if !LJ_HASJIT | 525 | #if !LJ_HASJIT |
526 | #define JIT_F_CMOV 1 | 526 | #define JIT_F_CMOV 1 |
527 | #define JIT_F_SSE2 2 | ||
527 | #endif | 528 | #endif |
528 | flags |= ((features[3] >> 15)&1) * JIT_F_CMOV; | 529 | flags |= ((features[3] >> 15)&1) * JIT_F_CMOV; |
529 | #if LJ_HASJIT | ||
530 | flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; | 530 | flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; |
531 | #if LJ_HASJIT | ||
531 | flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; | 532 | flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; |
532 | if (vendor[2] == 0x6c65746e) { /* Intel. */ | 533 | if (vendor[2] == 0x6c65746e) { /* Intel. */ |
533 | if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */ | 534 | if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */ |
@@ -543,13 +544,20 @@ static uint32_t jit_cpudetect(lua_State *L) | |||
543 | } | 544 | } |
544 | #endif | 545 | #endif |
545 | } | 546 | } |
546 | #ifndef LUAJIT_CPU_NOCMOV | 547 | /* Check for required instruction set support on x86. */ |
548 | #if LJ_TARGET_X86 | ||
549 | #if !defined(LUAJIT_CPU_NOCMOV) | ||
547 | if (!(flags & JIT_F_CMOV)) | 550 | if (!(flags & JIT_F_CMOV)) |
548 | luaL_error(L, "Ancient CPU lacks CMOV support (recompile with -DLUAJIT_CPU_NOCMOV)"); | 551 | luaL_error(L, "Ancient CPU lacks CMOV support (recompile with -DLUAJIT_CPU_NOCMOV)"); |
549 | #endif | 552 | #endif |
550 | #if LJ_HASJIT | ||
551 | if (!(flags & JIT_F_SSE2)) | 553 | if (!(flags & JIT_F_SSE2)) |
554 | #if defined(LUAJIT_CPU_SSE2) | ||
555 | luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); | ||
556 | #elif LJ_HASJIT | ||
552 | luaL_error(L, "Sorry, SSE2 CPU support required for this beta release"); | 557 | luaL_error(L, "Sorry, SSE2 CPU support required for this beta release"); |
558 | #else | ||
559 | (void)0; | ||
560 | #endif | ||
553 | #endif | 561 | #endif |
554 | UNUSED(L); | 562 | UNUSED(L); |
555 | #else | 563 | #else |