From 2c8179f0570883926afefe9f1a83fed22a3083ba Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 14 Dec 2015 18:54:58 +0000 Subject: [PATCH] Added hasBMI2() feature detection and use it to list some Celeron Haswell CPUs as non-Haswell CPUs. --- .../freenet/support/CPUInformation/CPUID.java | 1 + .../support/CPUInformation/CPUIDCPUInfo.java | 4 +++ .../support/CPUInformation/CPUInfo.java | 25 +++++++++++++------ .../support/CPUInformation/IntelInfoImpl.java | 8 +++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java index 3a9977d3e..1a15464c0 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUID.java +++ b/core/java/src/freenet/support/CPUInformation/CPUID.java @@ -324,6 +324,7 @@ public class CPUID { System.out.println("\n **More CPUInfo**"); System.out.println("CPU model string: " + c.getCPUModelString()); System.out.println("CPU has MMX: " + c.hasMMX()); + System.out.println("CPU has BMI2: " + c.hasBMI2()); System.out.println("CPU has SSE: " + c.hasSSE()); System.out.println("CPU has SSE2: " + c.hasSSE2()); System.out.println("CPU has SSE3: " + c.hasSSE3()); diff --git a/core/java/src/freenet/support/CPUInformation/CPUIDCPUInfo.java b/core/java/src/freenet/support/CPUInformation/CPUIDCPUInfo.java index efe1dfc00..fa268a03f 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUIDCPUInfo.java +++ b/core/java/src/freenet/support/CPUInformation/CPUIDCPUInfo.java @@ -17,6 +17,10 @@ abstract class CPUIDCPUInfo implements CPUInfo return (CPUID.getEDXCPUFlags() & (1 << 23)) != 0; //EDX Bit 23 } + public boolean hasBMI2(){ + return (CPUID.getExtendedEBXFeatureFlags() & (1 << 8)) != 0; // Extended EBX Bit 8 + } + public boolean hasSSE(){ return (CPUID.getEDXCPUFlags() & (1 << 25)) != 0; //EDX Bit 25 } diff --git a/core/java/src/freenet/support/CPUInformation/CPUInfo.java b/core/java/src/freenet/support/CPUInformation/CPUInfo.java index 161f04aba..7531e0572 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUInfo.java +++ b/core/java/src/freenet/support/CPUInformation/CPUInfo.java @@ -22,6 +22,7 @@ public interface CPUInfo * @return A string indicating the vendor of the CPU. */ public String getVendor(); + /** * @return A string detailing what type of CPU that is present in the machine. I.e. 'Pentium IV' etc. * @throws UnknownCPUException If for any reason the retrieval of the requested information @@ -29,32 +30,39 @@ public interface CPUInfo * cause of the failure. */ public String getCPUModelString() throws UnknownCPUException; - + /** - * @return true iff the CPU support the MMX instruction set. + * @return true iff the CPU supports the MMX instruction set. */ public boolean hasMMX(); + /** - * @return true iff the CPU support the SSE instruction set. + * @return true iff the CPU supports the BMI2 instruction set. + */ + public boolean hasBMI2(); + + /** + * @return true iff the CPU supports the SSE instruction set. */ public boolean hasSSE(); + /** - * @return true iff the CPU support the SSE2 instruction set. + * @return true iff the CPU supports the SSE2 instruction set. */ public boolean hasSSE2(); /** - * @return true iff the CPU support the SSE3 instruction set. + * @return true iff the CPU supports the SSE3 instruction set. */ public boolean hasSSE3(); /** - * @return true iff the CPU support the SSE4.1 instruction set. + * @return true iff the CPU supports the SSE4.1 instruction set. */ public boolean hasSSE41(); /** - * @return true iff the CPU support the SSE4.2 instruction set. + * @return true iff the CPU supports the SSE4.2 instruction set. */ public boolean hasSSE42(); @@ -62,7 +70,7 @@ public interface CPUInfo * AMD K10 only. Not supported on Intel. * ref: https://en.wikipedia.org/wiki/SSE4.2#SSE4a * - * @return true iff the CPU support the SSE4A instruction set. + * @return true iff the CPU supports the SSE4A instruction set. */ public boolean hasSSE4A(); @@ -105,6 +113,7 @@ public interface CPUInfo * @since 0.9.21 */ public boolean hasTBM(); + /** * @return true iff the CPU supports the AES-NI instruction set. * @since 0.9.14 diff --git a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java index 0174b16dd..dd50f4b7e 100644 --- a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java +++ b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java @@ -37,7 +37,13 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo public boolean IsCoreiCompatible(){ return isCoreiCompatible; } public boolean IsSandyCompatible(){ return isSandyCompatible; } public boolean IsIvyCompatible(){ return isIvyCompatible; } - public boolean IsHaswellCompatible(){ return isHaswellCompatible; } + public boolean IsHaswellCompatible(){ + // Some Celeron Haswell CPUs do not support BMI2, which + // GMP-6.0 assumes is present in all Haswell CPUs and causes + // crashes. Mark these CPUs as non-Haswell. + + return this.hasBMI2() && isHaswellCompatible; + } public boolean IsBroadwellCompatible(){ return isBroadwellCompatible; } public String getCPUModelString() throws UnknownCPUException