diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-05-02 21:48:34 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-05-02 21:48:34 (GMT) |
commit | 67e7ec069710c2b524e0466502b0e9f14769b439 (patch) | |
tree | 42c9366d016c3db0ca8640dc6d9bfd3de1dc0b47 /unix | |
parent | dcda4402f580987fc79b3a8b5bbacebde71dbf18 (diff) | |
parent | b01b765d7b57559048e606b7a01156a807b26b9c (diff) | |
download | tcl-67e7ec069710c2b524e0466502b0e9f14769b439.zip tcl-67e7ec069710c2b524e0466502b0e9f14769b439.tar.gz tcl-67e7ec069710c2b524e0466502b0e9f14769b439.tar.bz2 |
Better detection and implementation for cpuid instruction on Intel-derived processors, both 32-bit and 64-bit
Diffstat (limited to 'unix')
-rwxr-xr-x | unix/configure | 13 | ||||
-rw-r--r-- | unix/configure.in | 12 | ||||
-rw-r--r-- | unix/tclUnixCompat.c | 17 |
3 files changed, 25 insertions, 17 deletions
diff --git a/unix/configure b/unix/configure index df67e5d..522828d 100755 --- a/unix/configure +++ b/unix/configure @@ -18925,9 +18925,13 @@ int main () { - int index,ax,bx,cx,dx; - __asm__ __volatile__ ("cpuid":\ - "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (index)); + int index,regsPtr[4]; + __asm__ __volatile__("mov %%ebx, %%edi \n\t" + "cpuid \n\t" + "mov %%ebx, %%esi \n\t" + "mov %%edi, %%ebx \n\t" + : "=a"(regsPtr[0]), "=S"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3]) + : "a"(index)); ; return 0; @@ -18968,7 +18972,8 @@ fi echo "$as_me:$LINENO: result: $tcl_cv_cpuid" >&5 echo "${ECHO_T}$tcl_cv_cpuid" >&6 if test $tcl_cv_cpuid = yes; then - cat >>confdefs.h <<\_ACEOF + +cat >>confdefs.h <<\_ACEOF #define HAVE_CPUID 1 _ACEOF diff --git a/unix/configure.in b/unix/configure.in index b2cf87a..aea5ee5 100644 --- a/unix/configure.in +++ b/unix/configure.in @@ -731,12 +731,16 @@ fi AC_CACHE_CHECK([whether the cpuid instruction is usable], tcl_cv_cpuid, [ AC_TRY_LINK(, [ - int index,ax,bx,cx,dx; - __asm__ __volatile__ ("cpuid":\ - "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (index)); + int index,regsPtr[4]; + __asm__ __volatile__("mov %%ebx, %%edi \n\t" + "cpuid \n\t" + "mov %%ebx, %%esi \n\t" + "mov %%edi, %%ebx \n\t" + : "=a"(regsPtr[0]), "=S"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3]) + : "a"(index)); ], tcl_cv_cpuid=yes, tcl_cv_cpuid=no)]) if test $tcl_cv_cpuid = yes; then - AC_DEFINE(HAVE_CPUID) + AC_DEFINE(HAVE_CPUID, 1, [Is the cpuid instruction usable?]) fi #-------------------------------------------------------------------- diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c index 0626111..d9d5052 100644 --- a/unix/tclUnixCompat.c +++ b/unix/tclUnixCompat.c @@ -803,8 +803,7 @@ CopyString( * Get CPU ID information on an Intel box under UNIX (either Linux or Cygwin) * * Results: - * Returns TCL_OK if successful, TCL_ERROR if CPUID is not supported or - * fails. + * Returns TCL_OK if successful, TCL_ERROR if CPUID is not supported. * * Side effects: * If successful, stores EAX, EBX, ECX and EDX registers after the CPUID @@ -820,14 +819,14 @@ TclWinCPUID( { int status = TCL_ERROR; -#if defined(HAVE_CPUID) && defined(__CYGWIN__) - __asm__ __volatile__("pushl %%ebx \n\t" /* save %ebx */ + /* See: <http://en.wikipedia.org/wiki/CPUID> */ +#if defined(HAVE_CPUID) + __asm__ __volatile__("mov %%ebx, %%edi \n\t" /* save %ebx */ "cpuid \n\t" - "movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */ - "popl %%ebx \n\t" /* restore the old %ebx */ - : "=a"(regsPtr[0]), "=r"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3]) - : "a"(index) - : "cc"); + "mov %%ebx, %%esi \n\t" /* save what cpuid just put in %ebx */ + "mov %%edi, %%ebx \n\t" /* restore the old %ebx */ + : "=a"(regsPtr[0]), "=S"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3]) + : "a"(index)); status = TCL_OK; #endif return status; |