Index: src/ia32/assembler-ia32.cc |
diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc |
index ab4e0a43d18597bd157fe06bdd96b3caf6b9aaf4..7ff691318971b62b969c023226f834105ccfc222 100644 |
--- a/src/ia32/assembler-ia32.cc |
+++ b/src/ia32/assembler-ia32.cc |
@@ -101,80 +101,28 @@ void CpuFeatures::Probe() { |
return; // No features if we might serialize. |
} |
- const int kBufferSize = 4 * KB; |
- VirtualMemory* memory = new VirtualMemory(kBufferSize); |
- if (!memory->IsReserved()) { |
- delete memory; |
- return; |
+ uint64_t probed_features = 0; |
+ CPU cpu; |
+ if (cpu.has_sse41()) { |
+ probed_features |= static_cast<uint64_t>(1) << SSE4_1; |
} |
- ASSERT(memory->size() >= static_cast<size_t>(kBufferSize)); |
- if (!memory->Commit(memory->address(), kBufferSize, true/*executable*/)) { |
- delete memory; |
- return; |
+ if (cpu.has_sse3()) { |
+ probed_features |= static_cast<uint64_t>(1) << SSE3; |
} |
- |
- Assembler assm(NULL, memory->address(), kBufferSize); |
- Label cpuid, done; |
-#define __ assm. |
- // Save old esp, since we are going to modify the stack. |
- __ push(ebp); |
- __ pushfd(); |
- __ push(ecx); |
- __ push(ebx); |
- __ mov(ebp, esp); |
- |
- // If we can modify bit 21 of the EFLAGS register, then CPUID is supported. |
- __ pushfd(); |
- __ pop(eax); |
- __ mov(edx, eax); |
- __ xor_(eax, 0x200000); // Flip bit 21. |
- __ push(eax); |
- __ popfd(); |
- __ pushfd(); |
- __ pop(eax); |
- __ xor_(eax, edx); // Different if CPUID is supported. |
- __ j(not_zero, &cpuid); |
- |
- // CPUID not supported. Clear the supported features in edx:eax. |
- __ xor_(eax, eax); |
- __ xor_(edx, edx); |
- __ jmp(&done); |
- |
- // Invoke CPUID with 1 in eax to get feature information in |
- // ecx:edx. Temporarily enable CPUID support because we know it's |
- // safe here. |
- __ bind(&cpuid); |
- __ mov(eax, 1); |
- supported_ = (1 << CPUID); |
- { CpuFeatureScope fscope(&assm, CPUID); |
- __ cpuid(); |
+ if (cpu.has_sse2()) { |
+ probed_features |= static_cast<uint64_t>(1) << SSE2; |
+ } |
+ if (cpu.has_cmov()) { |
+ probed_features |= static_cast<uint64_t>(1) << CMOV; |
} |
- supported_ = 0; |
- |
- // Move the result from ecx:edx to edx:eax and make sure to mark the |
- // CPUID feature as supported. |
- __ mov(eax, edx); |
- __ or_(eax, 1 << CPUID); |
- __ mov(edx, ecx); |
- |
- // Done. |
- __ bind(&done); |
- __ mov(esp, ebp); |
- __ pop(ebx); |
- __ pop(ecx); |
- __ popfd(); |
- __ pop(ebp); |
- __ ret(0); |
-#undef __ |
- |
- typedef uint64_t (*F0)(); |
- F0 probe = FUNCTION_CAST<F0>(reinterpret_cast<Address>(memory->address())); |
- uint64_t probed_features = probe(); |
+ |
+ // SAHF must be available in compat/legacy mode. |
+ ASSERT(cpu.has_sahf()); |
+ probed_features |= static_cast<uint64_t>(1) << SAHF; |
+ |
uint64_t platform_features = OS::CpuFeaturesImpliedByPlatform(); |
supported_ = probed_features | platform_features; |
found_by_runtime_probing_only_ = probed_features & ~platform_features; |
- |
- delete memory; |
} |
@@ -474,7 +422,6 @@ void Assembler::CodeTargetAlign() { |
void Assembler::cpuid() { |
- ASSERT(IsEnabled(CPUID)); |
EnsureSpace ensure_space(this); |
EMIT(0x0F); |
EMIT(0xA2); |