Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
cpudetect.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : wwlib *
24 * *
25 * $Archive:: /Commando/Code/wwlib/cpudetect.h $*
26 * *
27 * Original Author:: Jani Penttinen *
28 * *
29 * $Author:: Jani_p $*
30 * *
31 * $Modtime:: 3/29/02 4:09p $*
32 * *
33 * $Revision:: 11 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef WWLIB_CPU_DETECT_H__
44#define WWLIB_CPU_DETECT_H__
45
46#include "always.h"
47#include "wwstring.h"
48
49#ifdef WIN32
50typedef signed __int64 sint64;
51#elif defined (_UNIX)
52typedef signed long long sint64;
53#endif
54
55class CPUDetectInitClass;
56
58{
59public:
72
106
130
139
148
149 inline static ProcessorManufacturerType Get_Processor_Manufacturer() {return ProcessorManufacturer;}
150 static const char* Get_Processor_Manufacturer_Name();
151
152 inline static bool Has_CPUID_Instruction() { return HasCPUIDInstruction; }
153 inline static bool Has_RDTSC_Instruction() { return HasRDTSCInstruction; }
154 inline static bool Has_CMOV_Instruction() { return HasCMOVSupport; }
155 inline static bool Has_MMX_Instruction_Set() { return HasMMXSupport; }
156 inline static bool Has_SSE_Instruction_Set() { return HasSSESupport; }
157 inline static bool Has_SSE2_Instruction_Set() { return HasSSE2Support; }
158 inline static bool Has_3DNow_Instruction_Set() { return Has3DNowSupport; }
159 inline static bool Has_Extended_3DNow_Instruction_Set() { return HasExtended3DNowSupport; }
160
161 // Call these functions after determining the manufacturer to find out which of the manufacturers processors
162 // the system has.
163 inline static IntelProcessorType Get_Intel_Processor() { return IntelProcessor; }
164 inline static AMDProcessorType Get_AMD_Processor() { return AMDProcessor; }
165 inline static VIAProcessorType Get_VIA_Processor() { return VIAProcessor; }
166 inline static RiseProcessorType Get_Rise_Processor() { return RiseProcessor; }
167
168 // Note that processor speed is only calculated at start and could change during execution, so
169 // this number is not to be relied on!
170 inline static int Get_Processor_Speed() { return ProcessorSpeed; }
171 inline static sint64 Get_Processor_Ticks_Per_Second() { return ProcessorTicksPerSecond; } // Ticks per second
172 inline static double Get_Inv_Processor_Ticks_Per_Second() { return InvProcessorTicksPerSecond; } // 1.0 / Ticks per second
173
174 static unsigned Get_Feature_Bits() { return FeatureBits; }
175 static unsigned Get_Extended_Feature_Bits() { return ExtendedFeatureBits; }
176
177 // L2 cache
178 static unsigned Get_L2_Cache_Size() { return L2CacheSize; }
179 static unsigned Get_L2_Cache_Line_Size() { return L2CacheLineSize; }
180 static unsigned Get_L2_Cache_Set_Associative() { return L2CacheSetAssociative; }
181
182 // L1 data cache
183 static unsigned Get_L1_Data_Cache_Size() { return L1DataCacheSize; }
184 static unsigned Get_L1_Data_Cache_Line_Size() { return L1DataCacheLineSize; }
185 static unsigned Get_L1_Data_Cache_Set_Associative() { return L1DataCacheSetAssociative; }
186
187 // L1 instruction cache
188 static unsigned Get_L1_Instruction_Cache_Size() { return L1InstructionCacheSize; }
189 static unsigned Get_L1_Instruction_Cache_Line_Size() { return L1InstructionCacheLineSize; }
190 static unsigned Get_L1_Instruction_Cache_Set_Associative() { return L1InstructionCacheSetAssociative; }
191
192 // L1 instruction trace cache
193 static unsigned Get_L1_Instruction_Trace_Cache_Size() { return L1InstructionTraceCacheSize; }
194 static unsigned Get_L1_Instruction_Trace_Cache_Set_Associative() { return L1InstructionTraceCacheSetAssociative; }
195
196 // System memory
197 static unsigned Get_Total_Physical_Memory() { return TotalPhysicalMemory; }
198 static unsigned Get_Available_Physical_Memory() { return AvailablePhysicalMemory; }
199 static unsigned Get_Total_Page_File_Size() { return TotalPageMemory; }
200 static unsigned Get_Available_Page_File_Size() { return AvailablePageMemory; }
201 static unsigned Get_Total_Virtual_Memory() { return TotalVirtualMemory; }
202 static unsigned Get_Available_Virtual_Memory() { return AvailableVirtualMemory; }
203
204 static unsigned Get_Processor_Type() { return ProcessorType; }
205
206 inline static const char* Get_Processor_String() { return ProcessorString; }
207 inline static const StringClass& Get_Processor_Log() { return ProcessorLog; }
208 inline static const StringClass& Get_Compact_Log() { return CompactLog; }
209
210 static bool CPUID(
211 unsigned& u_eax_,
212 unsigned& u_ebx_,
213 unsigned& u_ecx_,
214 unsigned& u_edx_,
215 unsigned cpuid_type);
216
217private:
218// static void Detect_CPU_Type();
219 static void Init_CPUID_Instruction();
220 static void Init_Processor_Speed();
221 static void Init_Processor_String();
222 static void Init_Processor_Manufacturer();
223 static void Init_Processor_Family();
224 static void Init_Processor_Features();
225 static void Init_Memory();
226 static void Init_OS();
227
228 static void Init_Intel_Processor_Type();
229 static void Init_AMD_Processor_Type();
230 static void Init_VIA_Processor_Type();
231 static void Init_Rise_Processor_Type();
232
233 static void Init_Cache();
234
235 static void Init_Processor_Log();
236 static void Init_Compact_Log();
237
238 static void Process_Cache_Info(unsigned value);
239 static void Process_Extended_Cache_Info();
240
241 friend class CPUDetectInitClass;
242
243 static StringClass ProcessorLog;
244 static StringClass CompactLog;
245
246 static int ProcessorType;
247 static int ProcessorFamily;
248 static int ProcessorModel;
249 static int ProcessorRevision;
250 static int ProcessorSpeed;
251 static sint64 ProcessorTicksPerSecond; // Ticks per second
252 static double InvProcessorTicksPerSecond; // 1.0 / Ticks per second
253
254 static ProcessorManufacturerType ProcessorManufacturer;
255 static IntelProcessorType IntelProcessor;
256 static AMDProcessorType AMDProcessor;
257 static VIAProcessorType VIAProcessor;
258 static RiseProcessorType RiseProcessor;
259
260 static unsigned FeatureBits;
261 static unsigned ExtendedFeatureBits;
262
263 // L2 cache information
264 static unsigned L2CacheSize;
265 static unsigned L2CacheLineSize;
266 static unsigned L2CacheSetAssociative;
267
268 // L1 data cache information
269 static unsigned L1DataCacheSize;
270 static unsigned L1DataCacheLineSize;
271 static unsigned L1DataCacheSetAssociative;
272
273 // L1 instruction cache information
274 static unsigned L1InstructionCacheSize;
275 static unsigned L1InstructionCacheLineSize;
276 static unsigned L1InstructionCacheSetAssociative;
277
278 // L1 instruction trace cache information
279 static unsigned L1InstructionTraceCacheSize;
280 static unsigned L1InstructionTraceCacheSetAssociative;
281
282 static unsigned TotalPhysicalMemory;
283 static unsigned AvailablePhysicalMemory;
284 static unsigned TotalPageMemory;
285 static unsigned AvailablePageMemory;
286 static unsigned TotalVirtualMemory;
287 static unsigned AvailableVirtualMemory;
288
289 static unsigned OSVersionNumberMajor;
290 static unsigned OSVersionNumberMinor;
291 static unsigned OSVersionBuildNumber;
292 static unsigned OSVersionPlatformId;
293 static StringClass OSVersionExtraInfo;
294
295 static bool HasCPUIDInstruction;
296 static bool HasRDTSCInstruction;
297 static bool HasSSESupport;
298 static bool HasSSE2Support;
299 static bool HasCMOVSupport;
300 static bool HasMMXSupport;
301 static bool Has3DNowSupport;
302 static bool HasExtended3DNowSupport;
303 static char VendorID[20];
304 static char ProcessorString[48];
305
306};
307
309{
310 unsigned Eax;
311 unsigned Ebx;
312 unsigned Ecx;
313 unsigned Edx;
314 CPUIDStruct(unsigned cpuid_type)
315 {
317 Eax=Ebx=Ecx=Edx=0;
318 return;
319 }
320 CPUDetectClass::CPUID(Eax,Ebx,Ecx,Edx,cpuid_type);
321 }
322};
323
324
325#endif // WWLIB_CPU_DETECT_H__
void const char * value
@ INTEL_PROCESSOR_80486SX
Definition cpudetect.h:78
@ INTEL_PROCESSOR_80486DX2_WB
Definition cpudetect.h:82
@ INTEL_PROCESSOR_CELERON_MODEL_8
Definition cpudetect.h:99
@ INTEL_PROCESSOR_PENTIUM_MMX
Definition cpudetect.h:87
@ INTEL_PROCESSOR_UNKNOWN
Definition cpudetect.h:75
@ INTEL_PROCESSOR_80486DX4_WB
Definition cpudetect.h:84
@ INTEL_PROCESSOR_80486SX2
Definition cpudetect.h:81
@ INTEL_PROCESSOR_80386
Definition cpudetect.h:76
@ INTEL_PROCESSOR_PENTIUM_II_MODEL_5
Definition cpudetect.h:94
@ INTEL_PROCESSOR_PENTIUM_III_MODEL_8
Definition cpudetect.h:100
@ INTEL_PROCESSOR_80486DX
Definition cpudetect.h:77
@ INTEL_PROCESSOR_PENTIUM_III_MODEL_B
Definition cpudetect.h:103
@ INTEL_PROCESSOR_PENTIUM_II_MODEL_3
Definition cpudetect.h:91
@ INTEL_PROCESSOR_80486DX4
Definition cpudetect.h:83
@ INTEL_PROCESSOR_PENTIUM_III_XEON_MODEL_7
Definition cpudetect.h:98
@ INTEL_PROCESSOR_80486SL
Definition cpudetect.h:80
@ INTEL_PROCESSOR_CELERON_MODEL_5
Definition cpudetect.h:93
@ INTEL_PROCESSOR_PENTIUM_PRO_SAMPLE
Definition cpudetect.h:88
@ INTEL_PROCESSOR_PENTIUM_III_XEON_MODEL_A
Definition cpudetect.h:102
@ INTEL_PROCESSOR_PENTIUM
Definition cpudetect.h:85
@ INTEL_PROCESSOR_PENTIUM_II_MODEL_4
Definition cpudetect.h:92
@ INTEL_PROCESSOR_PENTIUM_II_OVERDRIVE
Definition cpudetect.h:90
@ INTEL_PROCESSOR_PENTIUM_II_XEON_MODEL_5
Definition cpudetect.h:95
@ INTEL_PROCESSOR_PENTIUM_PRO
Definition cpudetect.h:89
@ INTEL_PROCESSOR_PENTIUM_III_MODEL_7
Definition cpudetect.h:97
@ INTEL_PROCESSOR_PENTIUM_OVERDRIVE
Definition cpudetect.h:86
@ INTEL_PROCESSOR_PENTIUM4
Definition cpudetect.h:104
@ INTEL_PROCESSOR_PENTIUM_III_XEON_MODEL_8
Definition cpudetect.h:101
@ INTEL_PROCESSOR_CELERON_MODEL_6
Definition cpudetect.h:96
@ INTEL_PROCESSOR_80486DX2
Definition cpudetect.h:79
static unsigned Get_Total_Physical_Memory()
Definition cpudetect.h:197
static unsigned Get_Total_Virtual_Memory()
Definition cpudetect.h:201
static AMDProcessorType Get_AMD_Processor()
Definition cpudetect.h:164
@ MANUFACTURER_TRANSMETA
Definition cpudetect.h:70
static int Get_Processor_Speed()
Definition cpudetect.h:170
static const char * Get_Processor_Manufacturer_Name()
static bool Has_CPUID_Instruction()
Definition cpudetect.h:152
static IntelProcessorType Get_Intel_Processor()
Definition cpudetect.h:163
static bool Has_3DNow_Instruction_Set()
Definition cpudetect.h:158
static unsigned Get_L1_Instruction_Trace_Cache_Size()
Definition cpudetect.h:193
static const StringClass & Get_Processor_Log()
Definition cpudetect.h:207
static ProcessorManufacturerType Get_Processor_Manufacturer()
Definition cpudetect.h:149
friend class CPUDetectInitClass
Definition cpudetect.h:241
static sint64 Get_Processor_Ticks_Per_Second()
Definition cpudetect.h:171
static RiseProcessorType Get_Rise_Processor()
Definition cpudetect.h:166
static bool Has_CMOV_Instruction()
Definition cpudetect.h:154
static unsigned Get_L2_Cache_Size()
Definition cpudetect.h:178
static const char * Get_Processor_String()
Definition cpudetect.h:206
static unsigned Get_Available_Page_File_Size()
Definition cpudetect.h:200
static unsigned Get_Total_Page_File_Size()
Definition cpudetect.h:199
static unsigned Get_L1_Data_Cache_Set_Associative()
Definition cpudetect.h:185
@ VIA_PROCESSOR_CYRIX_III_SAMUEL
Definition cpudetect.h:137
@ VIA_PROCESSOR_IDT_C6_WINCHIP2
Definition cpudetect.h:135
@ VIA_PROCESSOR_IDT_C6_WINCHIP3
Definition cpudetect.h:136
@ VIA_PROCESSOR_IDT_C6_WINCHIP
Definition cpudetect.h:134
static unsigned Get_L1_Data_Cache_Size()
Definition cpudetect.h:183
static unsigned Get_L1_Instruction_Trace_Cache_Set_Associative()
Definition cpudetect.h:194
static unsigned Get_Processor_Type()
Definition cpudetect.h:204
static unsigned Get_Available_Physical_Memory()
Definition cpudetect.h:198
static bool Has_Extended_3DNow_Instruction_Set()
Definition cpudetect.h:159
static unsigned Get_Available_Virtual_Memory()
Definition cpudetect.h:202
static double Get_Inv_Processor_Ticks_Per_Second()
Definition cpudetect.h:172
static unsigned Get_L1_Instruction_Cache_Line_Size()
Definition cpudetect.h:189
static unsigned Get_L2_Cache_Line_Size()
Definition cpudetect.h:179
static unsigned Get_L1_Instruction_Cache_Set_Associative()
Definition cpudetect.h:190
static bool CPUID(unsigned &u_eax_, unsigned &u_ebx_, unsigned &u_ecx_, unsigned &u_edx_, unsigned cpuid_type)
static unsigned Get_Feature_Bits()
Definition cpudetect.h:174
@ AMD_PROCESSOR_ATHLON_025
Definition cpudetect.h:124
@ AMD_PROCESSOR_K6_MODEL7
Definition cpudetect.h:119
@ AMD_PROCESSOR_K6_3_3DNOW_MODEL9
Definition cpudetect.h:121
@ AMD_PROCESSOR_K5_MODEL0
Definition cpudetect.h:114
@ AMD_PROCESSOR_K5_MODEL1
Definition cpudetect.h:115
@ AMD_PROCESSOR_K6_2_3DNOW_MODEL8
Definition cpudetect.h:120
@ AMD_PROCESSOR_ATHLON_018
Definition cpudetect.h:125
@ AMD_PROCESSOR_K5_MODEL2
Definition cpudetect.h:116
@ AMD_PROCESSOR_ATHLON_018_IL2
Definition cpudetect.h:127
@ AMD_PROCESSOR_K6_3_PLUS
Definition cpudetect.h:122
@ AMD_PROCESSOR_K6_MODEL6
Definition cpudetect.h:118
@ AMD_PROCESSOR_K5_MODEL3
Definition cpudetect.h:117
static bool Has_SSE_Instruction_Set()
Definition cpudetect.h:156
static unsigned Get_L2_Cache_Set_Associative()
Definition cpudetect.h:180
static bool Has_SSE2_Instruction_Set()
Definition cpudetect.h:157
@ RISE_PROCESSOR_DRAGON2_025
Definition cpudetect.h:145
@ RISE_PROCESSOR_DRAGON_018
Definition cpudetect.h:144
@ RISE_PROCESSOR_DRAGON_025
Definition cpudetect.h:143
@ RISE_PROCESSOR_DRAGON2_018
Definition cpudetect.h:146
static unsigned Get_Extended_Feature_Bits()
Definition cpudetect.h:175
static VIAProcessorType Get_VIA_Processor()
Definition cpudetect.h:165
static const StringClass & Get_Compact_Log()
Definition cpudetect.h:208
static unsigned Get_L1_Instruction_Cache_Size()
Definition cpudetect.h:188
static bool Has_RDTSC_Instruction()
Definition cpudetect.h:153
static unsigned Get_L1_Data_Cache_Line_Size()
Definition cpudetect.h:184
static bool Has_MMX_Instruction_Set()
Definition cpudetect.h:155
unsigned Eax
Definition cpudetect.h:310
unsigned Ecx
Definition cpudetect.h:312
unsigned Edx
Definition cpudetect.h:313
CPUIDStruct(unsigned cpuid_type)
Definition cpudetect.h:314
unsigned Ebx
Definition cpudetect.h:311