diff options
Diffstat (limited to 'src/lib_jit.c')
-rw-r--r-- | src/lib_jit.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/lib_jit.c b/src/lib_jit.c index 82e68258..555e581c 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c | |||
@@ -16,7 +16,11 @@ | |||
16 | #include "lj_debug.h" | 16 | #include "lj_debug.h" |
17 | #include "lj_str.h" | 17 | #include "lj_str.h" |
18 | #include "lj_tab.h" | 18 | #include "lj_tab.h" |
19 | #include "lj_state.h" | ||
19 | #include "lj_bc.h" | 20 | #include "lj_bc.h" |
21 | #if LJ_HASFFI | ||
22 | #include "lj_ctype.h" | ||
23 | #endif | ||
20 | #if LJ_HASJIT | 24 | #if LJ_HASJIT |
21 | #include "lj_ir.h" | 25 | #include "lj_ir.h" |
22 | #include "lj_jit.h" | 26 | #include "lj_jit.h" |
@@ -332,6 +336,13 @@ LJLIB_CF(jit_util_tracek) | |||
332 | slot = ir->op2; | 336 | slot = ir->op2; |
333 | ir = &T->ir[ir->op1]; | 337 | ir = &T->ir[ir->op1]; |
334 | } | 338 | } |
339 | #if LJ_HASFFI | ||
340 | if (ir->o == IR_KINT64 && !ctype_ctsG(G(L))) { | ||
341 | ptrdiff_t oldtop = savestack(L, L->top); | ||
342 | luaopen_ffi(L); /* Load FFI library on-demand. */ | ||
343 | L->top = restorestack(L, oldtop); | ||
344 | } | ||
345 | #endif | ||
335 | lj_ir_kvalue(L, L->top-2, ir); | 346 | lj_ir_kvalue(L, L->top-2, ir); |
336 | setintV(L->top-1, (int32_t)irt_type(ir->t)); | 347 | setintV(L->top-1, (int32_t)irt_type(ir->t)); |
337 | if (slot == -1) | 348 | if (slot == -1) |
@@ -538,23 +549,17 @@ static uint32_t jit_cpudetect(lua_State *L) | |||
538 | uint32_t features[4]; | 549 | uint32_t features[4]; |
539 | if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { | 550 | if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) { |
540 | #if !LJ_HASJIT | 551 | #if !LJ_HASJIT |
541 | #define JIT_F_CMOV 1 | ||
542 | #define JIT_F_SSE2 2 | 552 | #define JIT_F_SSE2 2 |
543 | #endif | 553 | #endif |
544 | flags |= ((features[3] >> 15)&1) * JIT_F_CMOV; | ||
545 | flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; | 554 | flags |= ((features[3] >> 26)&1) * JIT_F_SSE2; |
546 | #if LJ_HASJIT | 555 | #if LJ_HASJIT |
547 | flags |= ((features[2] >> 0)&1) * JIT_F_SSE3; | 556 | flags |= ((features[2] >> 0)&1) * JIT_F_SSE3; |
548 | flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; | 557 | flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1; |
549 | if (vendor[2] == 0x6c65746e) { /* Intel. */ | 558 | if (vendor[2] == 0x6c65746e) { /* Intel. */ |
550 | if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */ | 559 | if ((features[0] & 0x0fff0ff0) == 0x000106c0) /* Atom. */ |
551 | flags |= JIT_F_P4; /* Currently unused. */ | ||
552 | else if ((features[0] & 0x0fff0ff0) == 0x000106c0) /* Atom. */ | ||
553 | flags |= JIT_F_LEA_AGU; | 560 | flags |= JIT_F_LEA_AGU; |
554 | } else if (vendor[2] == 0x444d4163) { /* AMD. */ | 561 | } else if (vendor[2] == 0x444d4163) { /* AMD. */ |
555 | uint32_t fam = (features[0] & 0x0ff00f00); | 562 | uint32_t fam = (features[0] & 0x0ff00f00); |
556 | if (fam == 0x00000f00) /* K8. */ | ||
557 | flags |= JIT_F_SPLIT_XMM; | ||
558 | if (fam >= 0x00000f00) /* K8, K10. */ | 563 | if (fam >= 0x00000f00) /* K8, K10. */ |
559 | flags |= JIT_F_PREFER_IMUL; | 564 | flags |= JIT_F_PREFER_IMUL; |
560 | } | 565 | } |
@@ -562,14 +567,8 @@ static uint32_t jit_cpudetect(lua_State *L) | |||
562 | } | 567 | } |
563 | /* Check for required instruction set support on x86 (unnecessary on x64). */ | 568 | /* Check for required instruction set support on x86 (unnecessary on x64). */ |
564 | #if LJ_TARGET_X86 | 569 | #if LJ_TARGET_X86 |
565 | #if !defined(LUAJIT_CPU_NOCMOV) | ||
566 | if (!(flags & JIT_F_CMOV)) | ||
567 | luaL_error(L, "CPU not supported"); | ||
568 | #endif | ||
569 | #if defined(LUAJIT_CPU_SSE2) | ||
570 | if (!(flags & JIT_F_SSE2)) | 570 | if (!(flags & JIT_F_SSE2)) |
571 | luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)"); | 571 | luaL_error(L, "CPU with SSE2 required"); |
572 | #endif | ||
573 | #endif | 572 | #endif |
574 | #elif LJ_TARGET_ARM | 573 | #elif LJ_TARGET_ARM |
575 | #if LJ_HASJIT | 574 | #if LJ_HASJIT |
@@ -631,11 +630,7 @@ static void jit_init(lua_State *L) | |||
631 | uint32_t flags = jit_cpudetect(L); | 630 | uint32_t flags = jit_cpudetect(L); |
632 | #if LJ_HASJIT | 631 | #if LJ_HASJIT |
633 | jit_State *J = L2J(L); | 632 | jit_State *J = L2J(L); |
634 | #if LJ_TARGET_X86 | 633 | J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; |
635 | /* Silently turn off the JIT compiler on CPUs without SSE2. */ | ||
636 | if ((flags & JIT_F_SSE2)) | ||
637 | #endif | ||
638 | J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT; | ||
639 | memcpy(J->param, jit_param_default, sizeof(J->param)); | 634 | memcpy(J->param, jit_param_default, sizeof(J->param)); |
640 | lj_dispatch_update(G(L)); | 635 | lj_dispatch_update(G(L)); |
641 | #else | 636 | #else |
@@ -645,6 +640,7 @@ static void jit_init(lua_State *L) | |||
645 | 640 | ||
646 | LUALIB_API int luaopen_jit(lua_State *L) | 641 | LUALIB_API int luaopen_jit(lua_State *L) |
647 | { | 642 | { |
643 | jit_init(L); | ||
648 | lua_pushliteral(L, LJ_OS_NAME); | 644 | lua_pushliteral(L, LJ_OS_NAME); |
649 | lua_pushliteral(L, LJ_ARCH_NAME); | 645 | lua_pushliteral(L, LJ_ARCH_NAME); |
650 | lua_pushinteger(L, LUAJIT_VERSION_NUM); | 646 | lua_pushinteger(L, LUAJIT_VERSION_NUM); |
@@ -657,7 +653,6 @@ LUALIB_API int luaopen_jit(lua_State *L) | |||
657 | LJ_LIB_REG(L, "jit.opt", jit_opt); | 653 | LJ_LIB_REG(L, "jit.opt", jit_opt); |
658 | #endif | 654 | #endif |
659 | L->top -= 2; | 655 | L->top -= 2; |
660 | jit_init(L); | ||
661 | return 1; | 656 | return 1; |
662 | } | 657 | } |
663 | 658 | ||