about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-05-31 17:52:05 -0700
committerUlrich Drepper <drepper@redhat.com>2009-05-31 17:52:05 -0700
commit963cb6fcb47ca212c0c57cc57bd7510f6549579c (patch)
treee0b12d2f0af3a97193aaa12a7162e6c38b828a4f /sysdeps
parentfd469aac31dc09f1328c8c4b976f887ebd592c56 (diff)
downloadglibc-963cb6fcb47ca212c0c57cc57bd7510f6549579c.tar.gz
glibc-963cb6fcb47ca212c0c57cc57bd7510f6549579c.tar.xz
glibc-963cb6fcb47ca212c0c57cc57bd7510f6549579c.zip
Simplify CPUID value handling.
SO far Intel and AMD use exactly the same bits meaning the same
things in CPUID index 1.  Simplify the code.  Should an architecture
come along which doesn't use the same semantics then it must use a
different index value than COMMON_CPUID_INDEX_1.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/x86_64/cacheinfo.c8
-rw-r--r--sysdeps/x86_64/multiarch/init-arch.c18
-rw-r--r--sysdeps/x86_64/multiarch/init-arch.h24
-rw-r--r--sysdeps/x86_64/multiarch/sched_cpucount.c5
4 files changed, 19 insertions, 36 deletions
diff --git a/sysdeps/x86_64/cacheinfo.c b/sysdeps/x86_64/cacheinfo.c
index cd192caad8..362687c181 100644
--- a/sysdeps/x86_64/cacheinfo.c
+++ b/sysdeps/x86_64/cacheinfo.c
@@ -489,10 +489,10 @@ init_cacheinfo (void)
 	}
 
 #ifdef USE_MULTIARCH
-      eax = __cpu_features.cpuid[INTEL_CPUID_INDEX_1].eax;
-      ebx = __cpu_features.cpuid[INTEL_CPUID_INDEX_1].ebx;
-      ecx = __cpu_features.cpuid[INTEL_CPUID_INDEX_1].ecx;
-      edx = __cpu_features.cpuid[INTEL_CPUID_INDEX_1].edx;
+      eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
+      ebx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx;
+      ecx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx;
+      edx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx;
 #else
       asm volatile ("cpuid"
 		    : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
diff --git a/sysdeps/x86_64/multiarch/init-arch.c b/sysdeps/x86_64/multiarch/init-arch.c
index eb4365fe32..ec0eb29faf 100644
--- a/sysdeps/x86_64/multiarch/init-arch.c
+++ b/sysdeps/x86_64/multiarch/init-arch.c
@@ -1,6 +1,6 @@
 /* Initialize CPU feature data.
    This file is part of the GNU C Library.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
    Contributed by Ulrich Drepper <drepper@redhat.com>.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -41,11 +41,12 @@ __init_cpu_features (void)
     {
       __cpu_features.kind = arch_kind_intel;
 
+    get_common_cpuid:
       asm volatile ("cpuid"
-		    : "=a" (__cpu_features.cpuid[INTEL_CPUID_INDEX_1].eax),
-		      "=b" (__cpu_features.cpuid[INTEL_CPUID_INDEX_1].ebx),
-		      "=c" (__cpu_features.cpuid[INTEL_CPUID_INDEX_1].ecx),
-		      "=d" (__cpu_features.cpuid[INTEL_CPUID_INDEX_1].edx)
+		    : "=a" (__cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax),
+		      "=b" (__cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx),
+		      "=c" (__cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx),
+		      "=d" (__cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx)
 		    : "0" (1));
     }
   /* This spells out "AuthenticAMD".  */
@@ -53,12 +54,7 @@ __init_cpu_features (void)
     {
       __cpu_features.kind = arch_kind_amd;
 
-      asm volatile ("cpuid"
-		    : "=a" (__cpu_features.cpuid[AMD_CPUID_INDEX_1].eax),
-		      "=b" (__cpu_features.cpuid[AMD_CPUID_INDEX_1].ebx),
-		      "=c" (__cpu_features.cpuid[AMD_CPUID_INDEX_1].ecx),
-		      "=d" (__cpu_features.cpuid[AMD_CPUID_INDEX_1].edx)
-		    : "0" (1));
+      goto get_common_cpuid;
     }
   else
     __cpu_features.kind = arch_kind_other;
diff --git a/sysdeps/x86_64/multiarch/init-arch.h b/sysdeps/x86_64/multiarch/init-arch.h
index 86cd83dc4c..40b804571d 100644
--- a/sysdeps/x86_64/multiarch/init-arch.h
+++ b/sysdeps/x86_64/multiarch/init-arch.h
@@ -1,5 +1,5 @@
 /* This file is part of the GNU C Library.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,16 +20,9 @@
 
 enum
   {
-    INTEL_CPUID_INDEX_1 = 0,
+    COMMON_CPUID_INDEX_1 = 0,
     /* Keep the following line at the end.  */
-    INTEL_CPUID_INDEX_MAX
-  };
-
-enum
-  {
-    AMD_CPUID_INDEX_1 = 0,
-    /* Keep the following line at the end.  */
-    AMD_CPUID_INDEX_MAX
+    COMMON_CPUID_INDEX_MAX
   };
 
 extern struct cpu_features
@@ -48,7 +41,7 @@ extern struct cpu_features
     unsigned int ebx;
     unsigned int ecx;
     unsigned int edx;
-  } cpuid[MAX (INTEL_CPUID_INDEX_MAX, AMD_CPUID_INDEX_MAX)];
+  } cpuid[COMMON_CPUID_INDEX_MAX];
 } __cpu_features attribute_hidden;
 
 
@@ -61,10 +54,5 @@ extern void __init_cpu_features (void) attribute_hidden;
 
 /* Following are the feature tests used throughout libc.  */
 
-#define INTEL_HAS_POPCOUNT \
-  (__cpu_features.kind == arch_kind_intel				\
-   && (__cpu_features.cpuid[INTEL_CPUID_INDEX_1].ecx & (1 << 23)) != 0)
-
-#define AMD_HAS_POPCOUNT \
-  (__cpu_features.kind == arch_kind_amd				\
-   && (__cpu_features.cpuid[AMD_CPUID_INDEX_1].ecx & (1 << 23)) != 0)
+#define HAS_POPCOUNT \
+  ((__cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx & (1 << 23)) != 0)
diff --git a/sysdeps/x86_64/multiarch/sched_cpucount.c b/sysdeps/x86_64/multiarch/sched_cpucount.c
index dc20182df4..e7f9daed05 100644
--- a/sysdeps/x86_64/multiarch/sched_cpucount.c
+++ b/sysdeps/x86_64/multiarch/sched_cpucount.c
@@ -1,6 +1,6 @@
 /* Count bits in CPU set.  x86-64 multi-arch version.
    This file is part of the GNU C Library.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
    Contributed by Ulrich Drepper <drepper@redhat.com>.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -35,8 +35,7 @@
 # undef __sched_cpucount
 
 libc_ifunc (__sched_cpucount,
-	    INTEL_HAS_POPCOUNT || AMD_HAS_POPCOUNT
-	    ? popcount_cpucount : generic_cpucount);
+	    HAS_POPCOUNT ? popcount_cpucount : generic_cpucount);
 #else
 # include_next <sched_cpucount.c>
 #endif