This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Update CPUID feature check


The CPUID feature bits in x86 processors from Intel and AMD indicate
the availability of the same CPU feature.  There is no need to check
the same CPU feature separately for Intel and AMD processors.



H.J.
----
2009-05-25  H.J. Lu  <hongjiu.lu@intel.com>

	* sysdeps/x86_64/multiarch/init-arch.h (CPUID_INDEX_1): New.
	(CPUID_INDEX_MAX): Likewise.
	(INTEL_CPUID_INDEX_1): Removed.
	(AMD_CPUID_INDEX_1): Likewise.
	(INTEL_HAS_POPCOUNT): Likewise.
	(AMD_HAS_POPCOUNT): Likewise.
	(cpu_features): Add feature.
	(HAS_POPCOUNT): Updated.

	* sysdeps/x86_64/cacheinfo.c (init_cacheinfo): Updated.
	* sysdeps/x86_64/multiarch/init-arch.c (__init_cpu_features):
	Likewise.

diff --git a/sysdeps/x86_64/cacheinfo.c b/sysdeps/x86_64/cacheinfo.c
index 1ec4ca1..43357d1 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[CPUID_INDEX_1].eax;
+      ebx = __cpu_features.cpuid[CPUID_INDEX_1].ebx;
+      ecx = __cpu_features.cpuid[CPUID_INDEX_1].ecx;
+      edx = __cpu_features.cpuid[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 eb4365f..b48600a 100644
--- a/sysdeps/x86_64/multiarch/init-arch.c
+++ b/sysdeps/x86_64/multiarch/init-arch.c
@@ -40,26 +40,25 @@ __init_cpu_features (void)
   if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
     {
       __cpu_features.kind = arch_kind_intel;
-
-      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)
-		    : "0" (1));
+      __cpu_features.feature = arch_feature_normal;
     }
   /* This spells out "AuthenticAMD".  */
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
     {
       __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));
+      __cpu_features.feature = arch_feature_normal;
     }
   else
-    __cpu_features.kind = arch_kind_other;
+    {
+      __cpu_features.kind = arch_kind_other;
+      __cpu_features.feature = arch_feature_unknown;
+    }
+
+  if (__cpu_features.feature == arch_feature_normal)
+    asm volatile ("cpuid"
+		  : "=a" (__cpu_features.cpuid[CPUID_INDEX_1].eax),
+		    "=b" (__cpu_features.cpuid[CPUID_INDEX_1].ebx),
+		    "=c" (__cpu_features.cpuid[CPUID_INDEX_1].ecx),
+		    "=d" (__cpu_features.cpuid[CPUID_INDEX_1].edx)
+		  : "0" (1));
 }
diff --git a/sysdeps/x86_64/multiarch/init-arch.h b/sysdeps/x86_64/multiarch/init-arch.h
index 86cd83d..86cfc5c 100644
--- a/sysdeps/x86_64/multiarch/init-arch.h
+++ b/sysdeps/x86_64/multiarch/init-arch.h
@@ -20,16 +20,9 @@
 
 enum
   {
-    INTEL_CPUID_INDEX_1 = 0,
+    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
+    CPUID_INDEX_MAX
   };
 
 extern struct cpu_features
@@ -41,6 +34,11 @@ extern struct cpu_features
       arch_kind_amd,
       arch_kind_other
     } kind;
+  enum
+    {
+      arch_feature_unknown = 0,
+      arch_feature_normal
+    } feature;
   int max_cpuid;
   struct
   {
@@ -48,7 +46,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 [CPUID_INDEX_MAX];
 } __cpu_features attribute_hidden;
 
 
@@ -61,10 +59,6 @@ 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.feature == arch_feature_normal			\
+   && (__cpu_features.cpuid[CPUID_INDEX_1].ecx & (1 << 23)) != 0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]