From 586ec565e17b8ccc9da0d3d19069dd27d1f78698 Mon Sep 17 00:00:00 2001 From: Reece Date: Sat, 16 Oct 2021 00:15:13 +0100 Subject: [PATCH] [*] Count discontiguous bits in the win32 processor map --- Source/HWInfo/CpuInfo.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/HWInfo/CpuInfo.cpp b/Source/HWInfo/CpuInfo.cpp index 6abf868e..a210c145 100644 --- a/Source/HWInfo/CpuInfo.cpp +++ b/Source/HWInfo/CpuInfo.cpp @@ -435,11 +435,22 @@ namespace Aurora::HWInfo if (sysinfo[i].Relationship == RelationProcessorCore) { gCpuInfo.cores++; + auto mask = sysinfo[i].ProcessorMask; - unsigned long offset, count; - BitScanForward(&offset, mask); - BitScanForward(&count, ~(mask >> offset)); - gCpuInfo.threads += count; + unsigned long offset {}, tmp; + while (offset != (sizeof(offset) * 8 - 1)) + { + // Count the index to a 1 + if (BitScanForward(&tmp, mask >> offset) == 0) break; // mask was zero, end of scan + offset += tmp; + + // Count the 1's by inverting the bitmap and counting to 1 + BitScanForward(&tmp, ~(mask >> offset)); + offset += tmp; + + // Increment threads by the bits set in + gCpuInfo.threads += tmp; + } } else if (sysinfo[i].Relationship == RelationProcessorPackage) {