Skip to content

Commit 2b375bf

Browse files
committed
cpu info check
find avx2 and avx512
1 parent 8a72ce5 commit 2b375bf

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

Engine/source/platform/platform.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ enum ProcessorProperties
7575
CPU_PROP_SSE4_1 = (1<<7), ///< Supports SSE4_1 instruction set extension.
7676
CPU_PROP_SSE4_2 = (1<<8), ///< Supports SSE4_2 instruction set extension.
7777
CPU_PROP_AVX = (1<<9), ///< Supports AVX256 instruction set extension.
78-
CPU_PROP_MP = (1<<10), ///< This is a multi-processor system.
79-
CPU_PROP_LE = (1<<11), ///< This processor is LITTLE ENDIAN.
80-
CPU_PROP_64bit = (1<<12), ///< This processor is 64-bit capable
81-
CPU_PROP_NEON = (1<<13), ///< Supports the Arm Neon instruction set extension.
78+
CPU_PROP_AVX2 = (1<<10), ///< Supports AVX256 instruction set extension.
79+
CPU_PROP_AVX512 = (1<<11), ///< Supports AVX256 instruction set extension.
80+
CPU_PROP_MP = (1<<12), ///< This is a multi-processor system.
81+
CPU_PROP_LE = (1<<13), ///< This processor is LITTLE ENDIAN.
82+
CPU_PROP_64bit = (1<<14), ///< This processor is 64-bit capable
83+
CPU_PROP_NEON = (1<<15), ///< Supports the Arm Neon instruction set extension.
8284
};
8385

8486
/// Processor info manager.

Engine/source/platformWin32/winCPUInfo.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ enum CpuFlags
7272

7373
BIT_XSAVE_RESTORE = BIT(27),
7474
BIT_AVX = BIT(28),
75+
BIT_AVX2 = BIT(5),
76+
BIT_AVX512F = BIT(16)
7577
};
7678

7779
static void detectCpuFeatures(Platform::SystemInfo_struct::Processor &processor)
7880
{
7981
S32 cpuInfo[4];
8082
__cpuid(cpuInfo, 1);
81-
//U32 eax = cpuInfo[0]; // eax
83+
int nIds = cpuInfo[0];
8284
U32 edx = cpuInfo[3]; // edx
8385
U32 ecx = cpuInfo[2]; // ecx
8486

@@ -90,6 +92,18 @@ static void detectCpuFeatures(Platform::SystemInfo_struct::Processor &processor)
9092
processor.properties |= (ecx & BIT_SSE4_1) ? CPU_PROP_SSE4_1 : 0;
9193
processor.properties |= (ecx & BIT_SSE4_2) ? CPU_PROP_SSE4_2 : 0;
9294

95+
if (nIds >= 7)
96+
{
97+
int ext[4];
98+
__cpuidex(ext, 7, 0);
99+
100+
if (ext[1] & (BIT_AVX2)) // EBX bit 5
101+
processor.properties |= CPU_PROP_AVX2;
102+
103+
if (ext[1] & (BIT_AVX512F)) // AVX-512 Foundation
104+
processor.properties |= CPU_PROP_AVX512;
105+
}
106+
93107
// AVX detection requires that xsaverestore is supported
94108
if (ecx & BIT_XSAVE_RESTORE && ecx & BIT_AVX)
95109
{
@@ -176,6 +190,10 @@ void Processor::init()
176190
Con::printf(" SSE4.2 detected" );
177191
if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX)
178192
Con::printf(" AVX detected");
193+
if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX2)
194+
Con::printf(" AVX2 detected");
195+
if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX512)
196+
Con::printf(" AVX512 detected");
179197

180198
if (Platform::SystemInfo.processor.properties & CPU_PROP_MP)
181199
Con::printf(" MultiCore CPU detected [%i cores, %i logical]", Platform::SystemInfo.processor.numPhysicalProcessors, Platform::SystemInfo.processor.numLogicalProcessors);

0 commit comments

Comments
 (0)