winCPUInfo.cpp
Engine/source/platformWin32/winCPUInfo.cpp
Public Functions
SetProcessorInfo(Platform::SystemInfo_struct::Processor & pInfo, char * vendor, U32 processor, U32 properties, U32 properties2)
Detailed Description
Public Functions
PlatformBlitInit()
SetProcessorInfo(Platform::SystemInfo_struct::Processor & pInfo, char * vendor, U32 processor, U32 properties, U32 properties2)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "platformWin32/platformWin32.h" 26#include "console/console.h" 27#include "core/stringTable.h" 28#include <math.h> 29#include <intrin.h> 30 31Platform::SystemInfo_struct Platform::SystemInfo; 32extern void PlatformBlitInit(); 33extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo, 34 char* vendor, U32 processor, U32 properties, U32 properties2); // platform/platformCPU.cc 35 36void Processor::init() 37{ 38 // Reference: 39 // www.cyrix.com 40 // www.amd.com 41 // www.intel.com 42 // http://developer.intel.com/design/PentiumII/manuals/24512701.pdf 43 44 Con::printf("Processor Init:"); 45 46 Platform::SystemInfo.processor.type = CPU_X86Compatible; 47 Platform::SystemInfo.processor.name = StringTable->insert("Unknown x86 Compatible"); 48 Platform::SystemInfo.processor.mhz = 0; 49 Platform::SystemInfo.processor.properties = CPU_PROP_C | CPU_PROP_LE; 50 51 char vendor[0x20]; 52 dMemset(vendor, 0, sizeof(vendor)); 53 U32 properties = 0; 54 U32 processor = 0; 55 U32 properties2 = 0; 56 57 S32 vendorInfo[4]; 58 __cpuid(vendorInfo, 0); 59 *reinterpret_cast<int*>(vendor) = vendorInfo[1]; // ebx 60 *reinterpret_cast<int*>(vendor + 4) = vendorInfo[3]; // edx 61 *reinterpret_cast<int*>(vendor + 8) = vendorInfo[2]; // ecx 62 63 S32 cpuInfo[4]; 64 __cpuid(cpuInfo, 1); 65 processor = cpuInfo[0]; // eax 66 properties = cpuInfo[3]; // edx 67 properties2 = cpuInfo[2]; // ecx 68 69 SetProcessorInfo(Platform::SystemInfo.processor, vendor, processor, properties, properties2); 70 71// now calculate speed of processor... 72 U32 nearmhz = 0; // nearest rounded mhz 73 U32 mhz = 0; // calculated value. 74 75 LONG result; 76 DWORD data = 0; 77 DWORD dataSize = 4; 78 HKEY hKey; 79 80 result = ::RegOpenKeyExA (HKEY_LOCAL_MACHINE,"Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey); 81 82 if (result == ERROR_SUCCESS) 83 { 84 result = ::RegQueryValueExA (hKey, "~MHz",NULL, NULL,(LPBYTE)&data, &dataSize); 85 86 if (result == ERROR_SUCCESS) 87 nearmhz = mhz = data; 88 89 ::RegCloseKey(hKey); 90 } 91 92 Platform::SystemInfo.processor.mhz = mhz; 93 94 if (mhz==0) 95 { 96 Con::printf(" %s, (Unknown) Mhz", Platform::SystemInfo.processor.name); 97 // stick SOMETHING in so it isn't ZERO. 98 Platform::SystemInfo.processor.mhz = 200; // seems a decent value. 99 } 100 else 101 { 102 if (nearmhz >= 1000) 103 Con::printf(" %s, ~%.2f Ghz", Platform::SystemInfo.processor.name, ((float)nearmhz)/1000.0f); 104 else 105 Con::printf(" %s, ~%d Mhz", Platform::SystemInfo.processor.name, nearmhz); 106 if (nearmhz != mhz) 107 { 108 if (mhz >= 1000) 109 Con::printf(" (timed at roughly %.2f Ghz)", ((float)mhz)/1000.0f); 110 else 111 Con::printf(" (timed at roughly %d Mhz)", mhz); 112 } 113 } 114 115 if( Platform::SystemInfo.processor.numAvailableCores > 0 116 || Platform::SystemInfo.processor.numPhysicalProcessors > 0 117 || Platform::SystemInfo.processor.isHyperThreaded ) 118 Platform::SystemInfo.processor.properties |= CPU_PROP_MP; 119 120 if (Platform::SystemInfo.processor.properties & CPU_PROP_FPU) 121 Con::printf( " FPU detected" ); 122 if (Platform::SystemInfo.processor.properties & CPU_PROP_MMX) 123 Con::printf( " MMX detected" ); 124 if (Platform::SystemInfo.processor.properties & CPU_PROP_3DNOW) 125 Con::printf( " 3DNow detected" ); 126 if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE) 127 Con::printf( " SSE detected" ); 128 if( Platform::SystemInfo.processor.properties & CPU_PROP_SSE2 ) 129 Con::printf( " SSE2 detected" ); 130 if( Platform::SystemInfo.processor.isHyperThreaded ) 131 Con::printf( " HT detected" ); 132 if( Platform::SystemInfo.processor.properties & CPU_PROP_MP ) 133 Con::printf( " MP detected [%i cores, %i logical, %i physical]", 134 Platform::SystemInfo.processor.numAvailableCores, 135 Platform::SystemInfo.processor.numLogicalProcessors, 136 Platform::SystemInfo.processor.numPhysicalProcessors ); 137 Con::printf(" "); 138 139 PlatformBlitInit(); 140} 141