# HG changeset patch # User moel.mich # Date 1272660820 0 # Node ID f46d163ffba2dc6ee361a5b500fd76f6d9c14883 # Parent 4a9f8154d8f0ac93b8588f66d0b383826daa2177 Fixed an overflow problem with the log function in the CPUID constructor. diff -r 4a9f8154d8f0 -r f46d163ffba2 Hardware/CPU/CPUID.cs --- a/Hardware/CPU/CPUID.cs Wed Apr 28 06:55:45 2010 +0000 +++ b/Hardware/CPU/CPUID.cs Fri Apr 30 20:53:40 2010 +0000 @@ -85,6 +85,20 @@ b.Append((char)((value >> 24) & 0xff)); } + private uint NextLog2(long x) { + if (x <= 0) + return 0; + + x--; + uint count = 0; + while (x > 0) { + x >>= 1; + count++; + } + + return count; + } + public CPUID(int thread) { this.thread = thread; @@ -173,9 +187,9 @@ maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; else maxCoreIdPerPackage = 1; - threadMaskWith = (uint)Math.Ceiling(Math.Log( - maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage, 2)); - coreMaskWith = (uint)Math.Ceiling(Math.Log(maxCoreIdPerPackage, 2)); + threadMaskWith = + NextLog2(maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage); + coreMaskWith = NextLog2(maxCoreIdPerPackage); break; case Vendor.AMD: uint corePerPackage; @@ -184,7 +198,7 @@ else corePerPackage = 1; threadMaskWith = 0; - coreMaskWith = (uint)Math.Ceiling(Math.Log(corePerPackage, 2)); + coreMaskWith = NextLog2(corePerPackage); break; default: threadMaskWith = 0;