Chromium Code Reviews| Index: src/base/cpu.cc |
| diff --git a/src/base/cpu.cc b/src/base/cpu.cc |
| index 872b20dcbaaa73a2617026d7ccaa241a0a3a5594..b51336756b83b19cb3025dab907c7cb24393eb9b 100644 |
| --- a/src/base/cpu.cc |
| +++ b/src/base/cpu.cc |
| @@ -49,25 +49,26 @@ namespace base { |
| #elif V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
| // Define __cpuid() for non-MSVC libraries. |
| +// Clear ecx to align with __cpuid() of MSVC: |
|
Benedikt Meurer
2015/04/08 04:36:21
Nit: Move this comment into the actual function be
|
| +// https://msdn.microsoft.com/en-us/library/hskdteyh.aspx |
| #if !V8_LIBC_MSVCRT |
| static V8_INLINE void __cpuid(int cpu_info[4], int info_type) { |
| #if defined(__i386__) && defined(__pic__) |
| // Make sure to preserve ebx, which contains the pointer |
| // to the GOT in case we're generating PIC. |
| - __asm__ volatile ( |
| - "mov %%ebx, %%edi\n\t" |
| - "cpuid\n\t" |
| - "xchg %%edi, %%ebx\n\t" |
| - : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
| - : "a"(info_type) |
| - ); |
| + __asm__ volatile( |
| + "mov %%ebx, %%edi\n\t" |
| + "cpuid\n\t" |
| + "xchg %%edi, %%ebx\n\t" |
| + : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), |
| + "=d"(cpu_info[3]) |
| + : "a"(info_type), "c"(0)); |
| #else |
| - __asm__ volatile ( |
| - "cpuid \n\t" |
| - : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
| - : "a"(info_type) |
| - ); |
| + __asm__ volatile("cpuid \n\t" |
| + : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), |
| + "=d"(cpu_info[3]) |
| + : "a"(info_type), "c"(0)); |
| #endif // defined(__i386__) && defined(__pic__) |
| } |
| @@ -325,6 +326,10 @@ CPU::CPU() |
| has_osxsave_(false), |
| has_avx_(false), |
| has_fma3_(false), |
| + has_bmi1_(false), |
| + has_bmi2_(false), |
| + has_lzcnt_(false), |
| + has_popcnt_(false), |
| has_idiva_(false), |
| has_neon_(false), |
| has_thumb2_(false), |
| @@ -371,6 +376,7 @@ CPU::CPU() |
| has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; |
| has_sse41_ = (cpu_info[2] & 0x00080000) != 0; |
| has_sse42_ = (cpu_info[2] & 0x00100000) != 0; |
| + has_popcnt_ = (cpu_info[2] & 0x00800000) != 0; |
| has_osxsave_ = (cpu_info[2] & 0x08000000) != 0; |
| has_avx_ = (cpu_info[2] & 0x10000000) != 0; |
| has_fma3_ = (cpu_info[2] & 0x00001000) != 0; |
| @@ -392,10 +398,13 @@ CPU::CPU() |
| } |
| } |
| -#if V8_HOST_ARCH_IA32 |
| - // SAHF is always available in compat/legacy mode, |
| - has_sahf_ = true; |
| -#else |
| + // There are separate feature flags for VEX-encoded GPR instructions. |
| + if (num_ids >= 7) { |
| + __cpuid(cpu_info, 7); |
| + has_bmi1_ = (cpu_info[1] & 0x00000008) != 0; |
| + has_bmi2_ = (cpu_info[1] & 0x00000100) != 0; |
| + } |
| + |
| // Query extended IDs. |
| __cpuid(cpu_info, 0x80000000); |
| unsigned num_ext_ids = cpu_info[0]; |
| @@ -403,10 +412,10 @@ CPU::CPU() |
| // Interpret extended CPU feature information. |
| if (num_ext_ids > 0x80000000) { |
| __cpuid(cpu_info, 0x80000001); |
| + has_lzcnt_ = (cpu_info[2] & 0x00000020) != 0; |
| // SAHF must be probed in long mode. |
| has_sahf_ = (cpu_info[2] & 0x00000001) != 0; |
| } |
| -#endif |
| #elif V8_HOST_ARCH_ARM |