diff --git a/CMakeLists.txt b/CMakeLists.txt index 8152854ac19a6962dc7ddab682c16512d49813fb..124b8aca05cac14ae5e90f3afeabbab2c0a79d22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -640,6 +640,20 @@ IF(KWSYS_USE_SystemInformation) SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) ENDIF() + IF(BORLAND) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM + "Checking whether Borland CXX compiler supports assembler instructions" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID + "Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1) + ENDIF() + ENDIF() + ENDIF() IF(KWSYS_USE___INT64) SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_USE___INT64=1) diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 7cf93210e4403b36e4e35c1ab53a57aac3dab8a8..b20d72458917c7d9f7134ebd4edc22a129dc8380 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -202,7 +202,7 @@ typedef struct rlimit ResourceLimitType; #define USE_CPUID_INTRINSICS 0 #endif -#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS +#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) # define USE_CPUID 1 #else # define USE_CPUID 0 @@ -224,6 +224,7 @@ static bool call_cpuid(int select, int result[4]) return true; #else int tmp[4]; +#if defined(_MSC_VER) // Use SEH to determine CPUID presence __try { _asm { @@ -262,7 +263,24 @@ static bool call_cpuid(int select, int result[4]) return false; } - memcpy(result, tmp, sizeof(tmp)); + memcpy(result, tmp, sizeof(tmp)); +#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + unsigned int a, b, c, d; + __asm { + mov EAX, select; + cpuid + mov a, EAX; + mov b, EBX; + mov c, ECX; + mov d, EDX; + } + + result[0] = a; + result[1] = b; + result[2] = c; + result[3] = d; +#endif + // The cpuid instruction succeeded. return true; #endif @@ -432,7 +450,7 @@ protected: int CPUCount(); unsigned char LogicalCPUPerPhysicalCPU(); unsigned char GetAPICId(); - unsigned int IsHyperThreadingSupported(); + bool IsHyperThreadingSupported(); static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For Linux and Cygwin, /proc/cpuinfo formats are slightly different @@ -3742,8 +3760,13 @@ unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void) /** Works only for windows */ -unsigned int SystemInformationImplementation::IsHyperThreadingSupported() +bool SystemInformationImplementation::IsHyperThreadingSupported() { + if (this->Features.ExtendedFeatures.SupportsHyperthreading) + { + return true; + } + #if USE_CPUID int Regs[4] = { 0, 0, 0, 0 }, VendorId[4] = { 0, 0, 0, 0 }; @@ -3761,13 +3784,15 @@ unsigned int SystemInformationImplementation::IsHyperThreadingSupported() if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID)) { - if (VendorId[1] == 'uneG') + if (VendorId[1] == 0x756e6547) // 'uneG' { - if (VendorId[3] == 'Ieni') + if (VendorId[3] == 0x49656e69) // 'Ieni' { - if (VendorId[2] == 'letn') + if (VendorId[2] == 0x6c65746e) // 'letn' { - return(Regs[3] & HT_BIT); // Genuine Intel with hyper-Threading technology + // Genuine Intel with hyper-Threading technology + this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0); + return this->Features.ExtendedFeatures.SupportsHyperthreading; } } } diff --git a/kwsysPlatformTestsCXX.cxx b/kwsysPlatformTestsCXX.cxx index ae58703423a7b3fd3c1c0276d02d84c00c5c6309..48976c442a26035600027f32996183570ddd137d 100644 --- a/kwsysPlatformTestsCXX.cxx +++ b/kwsysPlatformTestsCXX.cxx @@ -580,3 +580,30 @@ int main() } } #endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM +int main() +{ + int a = 1; + __asm { + xor EBX, EBX; + mov a, EBX; + } + + return a; +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID +int main() +{ + int a = 0; + __asm { + xor EAX, EAX; + cpuid; + mov a, EAX; + } + + return a; +} +#endif