Fixed an overflow problem with the log function in the CPUID constructor.
1.1 --- a/Hardware/CPU/CPUID.cs Wed Apr 28 06:55:45 2010 +0000
1.2 +++ b/Hardware/CPU/CPUID.cs Fri Apr 30 20:53:40 2010 +0000
1.3 @@ -85,6 +85,20 @@
1.4 b.Append((char)((value >> 24) & 0xff));
1.5 }
1.6
1.7 + private uint NextLog2(long x) {
1.8 + if (x <= 0)
1.9 + return 0;
1.10 +
1.11 + x--;
1.12 + uint count = 0;
1.13 + while (x > 0) {
1.14 + x >>= 1;
1.15 + count++;
1.16 + }
1.17 +
1.18 + return count;
1.19 + }
1.20 +
1.21 public CPUID(int thread) {
1.22 this.thread = thread;
1.23
1.24 @@ -173,9 +187,9 @@
1.25 maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1;
1.26 else
1.27 maxCoreIdPerPackage = 1;
1.28 - threadMaskWith = (uint)Math.Ceiling(Math.Log(
1.29 - maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage, 2));
1.30 - coreMaskWith = (uint)Math.Ceiling(Math.Log(maxCoreIdPerPackage, 2));
1.31 + threadMaskWith =
1.32 + NextLog2(maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage);
1.33 + coreMaskWith = NextLog2(maxCoreIdPerPackage);
1.34 break;
1.35 case Vendor.AMD:
1.36 uint corePerPackage;
1.37 @@ -184,7 +198,7 @@
1.38 else
1.39 corePerPackage = 1;
1.40 threadMaskWith = 0;
1.41 - coreMaskWith = (uint)Math.Ceiling(Math.Log(corePerPackage, 2));
1.42 + coreMaskWith = NextLog2(corePerPackage);
1.43 break;
1.44 default:
1.45 threadMaskWith = 0;