From 37de84d55f891e33c8e7e02e50cd2caf96c0901a Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 28 Mar 2016 14:33:21 +0200 Subject: [PATCH] x86emitter: initialize scalar field CID:147038 --- common/include/x86emitter/tools.h | 92 +++++++++++++++-------------- common/src/x86emitter/cpudetect.cpp | 24 +++++++- 2 files changed, 69 insertions(+), 47 deletions(-) diff --git a/common/include/x86emitter/tools.h b/common/include/x86emitter/tools.h index 84f9c31a05..f90584fd3e 100644 --- a/common/include/x86emitter/tools.h +++ b/common/include/x86emitter/tools.h @@ -53,60 +53,62 @@ public: // x86 CPU Capabilities Section (all boolean flags!) // ---------------------------------------------------------------------------- - u32 hasFloatingPointUnit :1; - u32 hasVirtual8086ModeEnhancements :1; - u32 hasDebuggingExtensions :1; - u32 hasPageSizeExtensions :1; - u32 hasTimeStampCounter :1; - u32 hasModelSpecificRegisters :1; - u32 hasPhysicalAddressExtension :1; - u32 hasCOMPXCHG8BInstruction :1; - u32 hasAdvancedProgrammableInterruptController :1; - u32 hasSEPFastSystemCall :1; - u32 hasMemoryTypeRangeRegisters :1; - u32 hasPTEGlobalFlag :1; - u32 hasMachineCheckArchitecture :1; - u32 hasConditionalMoveAndCompareInstructions :1; - u32 hasFGPageAttributeTable :1; - u32 has36bitPageSizeExtension :1; - u32 hasProcessorSerialNumber :1; - u32 hasCFLUSHInstruction :1; - u32 hasDebugStore :1; - u32 hasACPIThermalMonitorAndClockControl :1; - u32 hasFastStreamingSIMDExtensionsSaveRestore :1; - u32 hasStreamingSIMDExtensions :1; - u32 hasStreamingSIMD2Extensions :1; - u32 hasSelfSnoop :1; + union { + struct { + u32 hasFloatingPointUnit :1; + u32 hasVirtual8086ModeEnhancements :1; + u32 hasDebuggingExtensions :1; + u32 hasPageSizeExtensions :1; + u32 hasTimeStampCounter :1; + u32 hasModelSpecificRegisters :1; + u32 hasPhysicalAddressExtension :1; + u32 hasCOMPXCHG8BInstruction :1; + u32 hasAdvancedProgrammableInterruptController :1; + u32 hasSEPFastSystemCall :1; + u32 hasMemoryTypeRangeRegisters :1; + u32 hasPTEGlobalFlag :1; + u32 hasMachineCheckArchitecture :1; + u32 hasConditionalMoveAndCompareInstructions :1; + u32 hasFGPageAttributeTable :1; + u32 has36bitPageSizeExtension :1; + u32 hasProcessorSerialNumber :1; + u32 hasCFLUSHInstruction :1; + u32 hasDebugStore :1; + u32 hasACPIThermalMonitorAndClockControl :1; + u32 hasFastStreamingSIMDExtensionsSaveRestore :1; + u32 hasStreamingSIMDExtensions :1; + u32 hasStreamingSIMD2Extensions :1; + u32 hasSelfSnoop :1; - // is TRUE for both multi-core and Hyperthreaded CPUs. - u32 hasMultiThreading :1; + // is TRUE for both multi-core and Hyperthreaded CPUs. + u32 hasMultiThreading :1; - u32 hasThermalMonitor :1; - u32 hasIntel64BitArchitecture :1; - u32 hasStreamingSIMD3Extensions :1; - u32 hasSupplementalStreamingSIMD3Extensions :1; - u32 hasStreamingSIMD4Extensions :1; - u32 hasStreamingSIMD4Extensions2 :1; - u32 hasAVX :1; - u32 hasAVX2 :1; - u32 hasBMI1 :1; - u32 hasBMI2 :1; - u32 hasFMA :1; + u32 hasThermalMonitor :1; + u32 hasIntel64BitArchitecture :1; + u32 hasStreamingSIMD3Extensions :1; + u32 hasSupplementalStreamingSIMD3Extensions :1; + u32 hasStreamingSIMD4Extensions :1; + u32 hasStreamingSIMD4Extensions2 :1; + u32 hasAVX :1; + u32 hasAVX2 :1; + u32 hasBMI1 :1; + u32 hasBMI2 :1; + u32 hasFMA :1; - // AMD-specific CPU Features - u32 hasAMD64BitArchitecture :1; - u32 hasStreamingSIMD4ExtensionsA :1; + // AMD-specific CPU Features + u32 hasAMD64BitArchitecture :1; + u32 hasStreamingSIMD4ExtensionsA :1; + }; + + u32 AllCapabilities; + }; // Core Counts! u32 PhysicalCores; u32 LogicalCores; public: - x86capabilities() - { - isIdentified = false; - VendorID = x86Vendor_Unknown; - } + x86capabilities(); void Identify(); void CountCores(); diff --git a/common/src/x86emitter/cpudetect.cpp b/common/src/x86emitter/cpudetect.cpp index b8d89a6f0f..b318909ddf 100644 --- a/common/src/x86emitter/cpudetect.cpp +++ b/common/src/x86emitter/cpudetect.cpp @@ -24,6 +24,26 @@ __aligned16 x86capabilities x86caps; // Recompiled code buffer for SSE and MXCSR feature testing. static __pagealigned u8 targetFXSAVE[512]; +x86capabilities::x86capabilities() : + isIdentified(false), + VendorID(x86Vendor_Unknown), + FamilyID(0), + Model(0), + TypeID(0), + StepID(0), + Flags(0), + Flags2(0), + EFlags(0), + EFlags2(0), + SEFlag(0), + AllCapabilities(0), + PhysicalCores(0), + LogicalCores(0) +{ + memzero(VendorName); + memzero(FamilyName); +} + // Warning! We've had problems with the MXCSR detection code causing stack corruption in // MSVC PGO builds. The problem was fixed when I moved the MXCSR code to this function, and // moved the recSSE[] array to a global static (it was local to cpudetectInit). Commented @@ -146,7 +166,7 @@ void x86capabilities::CountCores() CountLogicalCores(); } -static const char* tbl_x86vendors[] = +static const char* tbl_x86vendors[] = { "GenuineIntel", "AuthenticAMD", @@ -266,7 +286,7 @@ void x86capabilities::Identify() hasSupplementalStreamingSIMD3Extensions = ( Flags2 >> 9 ) & 1; //ssse3 hasStreamingSIMD4Extensions = ( Flags2 >> 19 ) & 1; //sse4.1 hasStreamingSIMD4Extensions2 = ( Flags2 >> 20 ) & 1; //sse4.2 - + if((Flags2 >> 27) & 1) // OSXSAVE { if((_xgetbv(0) & 6) == 6) // XFEATURE_ENABLED_MASK[2:1] = '11b' (XMM state and YMM state are enabled by OS).