From 6801e7165c3a5031db3cfe0e52f50cebb918695f Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 28 Mar 2016 23:04:33 +0200 Subject: [PATCH] x86: Detect BMI2 instruction support. --- src/lib_jit.c | 5 +++++ src/lj_jit.h | 3 ++- src/vm_x64.dasc | 1 + src/vm_x86.dasc | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib_jit.c b/src/lib_jit.c index 402ca35c..c6330c49 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c @@ -668,6 +668,11 @@ static uint32_t jit_cpudetect(lua_State *L) if (fam >= 0x00000f00) /* K8, K10. */ flags |= JIT_F_PREFER_IMUL; } + if (vendor[0] >= 7) { + uint32_t xfeatures[4]; + lj_vm_cpuid(7, xfeatures); + flags |= ((xfeatures[1] >> 8)&1) * JIT_F_BMI2; + } #endif } /* Check for required instruction set support on x86 (unnecessary on x64). */ diff --git a/src/lj_jit.h b/src/lj_jit.h index 5a51357e..2d2e833a 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h @@ -19,10 +19,11 @@ #define JIT_F_SSE4_1 0x00000040 #define JIT_F_PREFER_IMUL 0x00000080 #define JIT_F_LEA_AGU 0x00000100 +#define JIT_F_BMI2 0x00000200 /* Names for the CPU-specific flags. Must match the order above. */ #define JIT_F_CPU_FIRST JIT_F_SSE2 -#define JIT_F_CPUSTRING "\4SSE2\4SSE3\6SSE4.1\3AMD\4ATOM" +#define JIT_F_CPUSTRING "\4SSE2\4SSE3\6SSE4.1\3AMD\4ATOM\4BMI2" #elif LJ_TARGET_ARM #define JIT_F_ARMV6_ 0x00000010 #define JIT_F_ARMV6T2_ 0x00000020 diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc index bc2419c1..99ebb9b9 100644 --- a/src/vm_x64.dasc +++ b/src/vm_x64.dasc @@ -2639,6 +2639,7 @@ static void build_subroutines(BuildCtx *ctx) | mov eax, CARG1d | .if X64WIN; push rsi; mov rsi, CARG2; .endif | push rbx + | xor ecx, ecx | cpuid | mov [rsi], eax | mov [rsi+4], ebx diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index fcef660c..f108c0b5 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -3026,6 +3026,7 @@ static void build_subroutines(BuildCtx *ctx) | mov eax, CARG1d | .if X64WIN; push rsi; mov rsi, CARG2; .endif | push rbx + | xor ecx, ecx | cpuid | mov [rsi], eax | mov [rsi+4], ebx @@ -3049,6 +3050,7 @@ static void build_subroutines(BuildCtx *ctx) | mov eax, [esp+4] // Argument 1 is function number. | push edi | push ebx + | xor ecx, ecx | cpuid | mov edi, [esp+16] // Argument 2 is result area. | mov [edi], eax