diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df5a740dc0c1fbc568888c05c0a7d70de648215..04dc05caecf56e7b40c71984141b592abbe741d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -638,6 +638,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 37bf98da989d9929fa5ca24bdff0cf6e42642ca9..f59e3aa4dfe14892f08fe65b12ca4c013ad62d44 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 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