From 997d70e625ef35643b5632c3d22d15ea357e88e2 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 5 Jan 2025 20:38:40 +0000 Subject: Simplification for [d58e315172] --- generic/tclBasic.c | 4 +- win/configure | 32 ++++++------- win/configure.ac | 27 +++++------ win/tclWin32Dll.c | 131 ++--------------------------------------------------- 4 files changed, 30 insertions(+), 164 deletions(-) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 622651a..c0e6557 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -68,7 +68,7 @@ * compatible with AddressSanitizer (ASan) use-after-return detection. */ -#if defined(_MSC_VER) && defined(HAVE_INTRIN_H) +#if defined(_MSC_VER) #include /* for _AddressOfReturnAddress() */ #endif @@ -85,7 +85,7 @@ TclGetCStackPtr(void) { #if defined( __GNUC__ ) || __has_builtin(__builtin_frame_address) return __builtin_frame_address(0); -#elif defined(_MSC_VER) && defined(HAVE_INTRIN_H) +#elif defined(_MSC_VER) return _AddressOfReturnAddress(); #else ptrdiff_t unused = 0; diff --git a/win/configure b/win/configure index 801ff64..10b6364 100755 --- a/win/configure +++ b/win/configure @@ -5361,50 +5361,44 @@ fi # See if the compiler supports cpuid header. -if test "${GCC}" = "yes" ; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cpuid-header support in compiler" >&5 -printf %s "checking for cpuid-header support in compiler... " >&6; } -if test ${tcl_cv_cpuidhead+y} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cpuid.h" >&5 +printf %s "checking for cpuid.h... " >&6; } +if test ${tcl_cv_cpuid_h+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) - # include - #endif +#include int main (void) { - unsigned int regs; - __get_cpuid(0, ®s, ®s, ®s, ®s); + __get_cpuid(0, 0, 0, 0, 0); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" +if ac_fn_c_try_compile "$LINENO" then : - tcl_cv_cpuidhead=yes + tcl_cv_cpuid_h=yes else case e in #( - e) tcl_cv_cpuidhead=no ;; + e) tcl_cv_cpuid_h=no ;; esac fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ - conftest$ac_exeext conftest.$ac_ext - ;; +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cpuidhead" >&5 -printf "%s\n" "$tcl_cv_cpuidhead" >&6; } - if test "$tcl_cv_cpuidhead" = "yes"; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cpuid_h" >&5 +printf "%s\n" "$tcl_cv_cpuid_h" >&6; } +if test "$tcl_cv_cpuid_h" = "yes"; then printf "%s\n" "#define HAVE_CPUID_H 1" >>confdefs.h - fi fi # See if the header file is present diff --git a/win/configure.ac b/win/configure.ac index 630d204..b7ede20 100644 --- a/win/configure.ac +++ b/win/configure.ac @@ -257,24 +257,19 @@ fi # See if the compiler supports cpuid header. -if test "${GCC}" = "yes" ; then - AC_CACHE_CHECK(for cpuid-header support in compiler, - tcl_cv_cpuidhead, - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) - # include - #endif - ]], [[ - unsigned int regs; - __get_cpuid(0, ®s, ®s, ®s, ®s); +AC_CACHE_CHECK(for cpuid.h, + tcl_cv_cpuid_h, +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +]], [[ + __get_cpuid(0, 0, 0, 0, 0); ]])], - [tcl_cv_cpuidhead=yes], - [tcl_cv_cpuidhead=no]) - ) - if test "$tcl_cv_cpuidhead" = "yes"; then + [tcl_cv_cpuid_h=yes], + [tcl_cv_cpuid_h=no]) +) +if test "$tcl_cv_cpuid_h" = "yes"; then AC_DEFINE(HAVE_CPUID_H, 1, - [Defined when the compilers supports cpuid header]) - fi + [Defined when cpuid.h exists]) fi # See if the header file is present diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 12dfab9..81db0f2 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -13,8 +13,8 @@ #include "tclWinInt.h" #if defined(HAVE_CPUID_H) -# include -#elif defined(HAVE_INTRIN_H) +# xinclude +#elif defined(_MSC_VER) # include #endif @@ -445,134 +445,12 @@ TclWinCPUID( __get_cpuid(index, ®s[0], ®s[1], ®s[2], ®s[3]); status = TCL_OK; -#elif defined(HAVE_INTRIN_H) && defined(_WIN64) && defined(HAVE_CPUID) +#elif defined(_MSC_VER) && defined(_WIN64) && defined(HAVE_CPUID) __cpuid((int *)regsPtr, index); status = TCL_OK; -#elif defined(__GNUC__) && defined(HAVE_CPUID) -# if defined(_WIN64) - /* - * Execute the CPUID instruction with the given index, and store results - * off 'regPtr'. - */ - - __asm__ __volatile__( - /* - * Do the CPUID instruction, and save the results in the 'regsPtr' - * area. - */ - - "movl %[rptr], %%edi" "\n\t" - "movl %[index], %%eax" "\n\t" - "cpuid" "\n\t" - "movl %%eax, 0x0(%%edi)" "\n\t" - "movl %%ebx, 0x4(%%edi)" "\n\t" - "movl %%ecx, 0x8(%%edi)" "\n\t" - "movl %%edx, 0xC(%%edi)" "\n\t" - - : - /* No outputs */ - : - [index] "m" (index), - [rptr] "m" (regsPtr) - : - "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); - status = TCL_OK; - -# else - - TCLEXCEPTION_REGISTRATION registration; - - /* - * Execute the CPUID instruction with the given index, and store results - * off 'regPtr'. - */ - - __asm__ __volatile__( - /* - * Construct an TCLEXCEPTION_REGISTRATION to protect the CPUID - * instruction (early 486's don't have CPUID) - */ - - "leal %[registration], %%edx" "\n\t" - "movl %%fs:0, %%eax" "\n\t" - "movl %%eax, 0x0(%%edx)" "\n\t" /* link */ - "leal 1f, %%eax" "\n\t" - "movl %%eax, 0x4(%%edx)" "\n\t" /* handler */ - "movl %%ebp, 0x8(%%edx)" "\n\t" /* ebp */ - "movl %%esp, 0xC(%%edx)" "\n\t" /* esp */ - "movl %[error], 0x10(%%edx)" "\n\t" /* status */ - - /* - * Link the TCLEXCEPTION_REGISTRATION on the chain - */ - - "movl %%edx, %%fs:0" "\n\t" - - /* - * Do the CPUID instruction, and save the results in the 'regsPtr' - * area. - */ - - "movl %[rptr], %%edi" "\n\t" - "movl %[index], %%eax" "\n\t" - "cpuid" "\n\t" - "movl %%eax, 0x0(%%edi)" "\n\t" - "movl %%ebx, 0x4(%%edi)" "\n\t" - "movl %%ecx, 0x8(%%edi)" "\n\t" - "movl %%edx, 0xC(%%edi)" "\n\t" - - /* - * Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION and - * store a TCL_OK status. - */ - - "movl %%fs:0, %%edx" "\n\t" - "movl %[ok], %%eax" "\n\t" - "movl %%eax, 0x10(%%edx)" "\n\t" - "jmp 2f" "\n" - - /* - * Come here on an exception. Get the TCLEXCEPTION_REGISTRATION that we - * previously put on the chain. - */ - - "1:" "\t" - "movl %%fs:0, %%edx" "\n\t" - "movl 0x8(%%edx), %%edx" "\n\t" - - /* - * Come here however we exited. Restore context from the - * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced. - */ - - "2:" "\t" - "movl 0xC(%%edx), %%esp" "\n\t" - "movl 0x8(%%edx), %%ebp" "\n\t" - "movl 0x0(%%edx), %%eax" "\n\t" - "movl %%eax, %%fs:0" "\n\t" - - : - /* No outputs */ - : - [index] "m" (index), - [rptr] "m" (regsPtr), - [registration] "m" (registration), - [ok] "i" (TCL_OK), - [error] "i" (TCL_ERROR) - : - "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); - status = registration.status; - -# endif /* !_WIN64 */ -#elif defined(_MSC_VER) && defined(HAVE_CPUID) -# if defined(_WIN64) - - __cpuid(regsPtr, index); - status = TCL_OK; - -# elif defined (_M_IX86) +#elif defined (_M_IX86) /* * Define a structure in the stack frame to hold the registers. */ @@ -619,7 +497,6 @@ TclWinCPUID( /* do nothing */ } -# endif #else (void)index; (void)regsPtr; -- cgit v0.12 From a0a8e2f294ec770dbb8713ce29dda0865d7028f0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 5 Jan 2025 20:41:05 +0000 Subject: oops --- win/tclWin32Dll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 81db0f2..3b7bbea 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -13,7 +13,7 @@ #include "tclWinInt.h" #if defined(HAVE_CPUID_H) -# xinclude +# include #elif defined(_MSC_VER) # include #endif -- cgit v0.12