From b6ea96f367d791af72fc0f68c2f47a59388e7db0 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Tue, 24 Feb 2026 15:03:22 +0000 Subject: [PATCH] cpu info check find avx2 and avx512 --- Engine/source/platform/platform.h | 10 ++++++---- Engine/source/platformWin32/winCPUInfo.cpp | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Engine/source/platform/platform.h b/Engine/source/platform/platform.h index acb929a9f..1326c4692 100644 --- a/Engine/source/platform/platform.h +++ b/Engine/source/platform/platform.h @@ -75,10 +75,12 @@ enum ProcessorProperties CPU_PROP_SSE4_1 = (1<<7), ///< Supports SSE4_1 instruction set extension. CPU_PROP_SSE4_2 = (1<<8), ///< Supports SSE4_2 instruction set extension. CPU_PROP_AVX = (1<<9), ///< Supports AVX256 instruction set extension. - CPU_PROP_MP = (1<<10), ///< This is a multi-processor system. - CPU_PROP_LE = (1<<11), ///< This processor is LITTLE ENDIAN. - CPU_PROP_64bit = (1<<12), ///< This processor is 64-bit capable - CPU_PROP_NEON = (1<<13), ///< Supports the Arm Neon instruction set extension. + CPU_PROP_AVX2 = (1<<10), ///< Supports AVX256 instruction set extension. + CPU_PROP_AVX512 = (1<<11), ///< Supports AVX256 instruction set extension. + CPU_PROP_MP = (1<<12), ///< This is a multi-processor system. + CPU_PROP_LE = (1<<13), ///< This processor is LITTLE ENDIAN. + CPU_PROP_64bit = (1<<14), ///< This processor is 64-bit capable + CPU_PROP_NEON = (1<<15), ///< Supports the Arm Neon instruction set extension. }; /// Processor info manager. diff --git a/Engine/source/platformWin32/winCPUInfo.cpp b/Engine/source/platformWin32/winCPUInfo.cpp index c8e05f44f..3bd183f44 100644 --- a/Engine/source/platformWin32/winCPUInfo.cpp +++ b/Engine/source/platformWin32/winCPUInfo.cpp @@ -72,13 +72,15 @@ enum CpuFlags BIT_XSAVE_RESTORE = BIT(27), BIT_AVX = BIT(28), + BIT_AVX2 = BIT(5), + BIT_AVX512F = BIT(16) }; static void detectCpuFeatures(Platform::SystemInfo_struct::Processor &processor) { S32 cpuInfo[4]; __cpuid(cpuInfo, 1); - //U32 eax = cpuInfo[0]; // eax + int nIds = cpuInfo[0]; U32 edx = cpuInfo[3]; // edx U32 ecx = cpuInfo[2]; // ecx @@ -90,6 +92,18 @@ static void detectCpuFeatures(Platform::SystemInfo_struct::Processor &processor) processor.properties |= (ecx & BIT_SSE4_1) ? CPU_PROP_SSE4_1 : 0; processor.properties |= (ecx & BIT_SSE4_2) ? CPU_PROP_SSE4_2 : 0; + if (nIds >= 7) + { + int ext[4]; + __cpuidex(ext, 7, 0); + + if (ext[1] & (BIT_AVX2)) // EBX bit 5 + processor.properties |= CPU_PROP_AVX2; + + if (ext[1] & (BIT_AVX512F)) // AVX-512 Foundation + processor.properties |= CPU_PROP_AVX512; + } + // AVX detection requires that xsaverestore is supported if (ecx & BIT_XSAVE_RESTORE && ecx & BIT_AVX) { @@ -176,6 +190,10 @@ void Processor::init() Con::printf(" SSE4.2 detected" ); if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX) Con::printf(" AVX detected"); + if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX2) + Con::printf(" AVX2 detected"); + if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX512) + Con::printf(" AVX512 detected"); if (Platform::SystemInfo.processor.properties & CPU_PROP_MP) Con::printf(" MultiCore CPU detected [%i cores, %i logical]", Platform::SystemInfo.processor.numPhysicalProcessors, Platform::SystemInfo.processor.numLogicalProcessors);