about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2015-11-30 08:53:37 -0800
committerH.J. Lu <hjl.tools@gmail.com>2016-04-02 11:07:47 -0700
commitca9c5edeea52dc18f42ebbe29b1af352f5555538 (patch)
tree64da098b02b20b32d47c448a98ca21ec434c78ff
parentc23cdbac4ea473effbef5c50b1217f95595b3460 (diff)
downloadglibc-ca9c5edeea52dc18f42ebbe29b1af352f5555538.tar.gz
glibc-ca9c5edeea52dc18f42ebbe29b1af352f5555538.tar.xz
glibc-ca9c5edeea52dc18f42ebbe29b1af352f5555538.zip
Update family and model detection for AMD CPUs
AMD CPUs uses the similar encoding scheme for extended family and model
as Intel CPUs as shown in:

http://support.amd.com/TechDocs/25481.pdf

This patch updates get_common_indeces to get family and model for both
Intel and AMD CPUs when family == 0x0f.

	[BZ #19214]
	* sysdeps/x86/cpu-features.c (get_common_indeces): Add an
	argument to return extended model.  Update family and model
	with extended family and model when family == 0x0f.
	(init_cpu_features): Updated.
-rw-r--r--sysdeps/x86/cpu-features.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index 49b94a916b..d8f19d4413 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -21,7 +21,8 @@
 
 static inline void
 get_common_indeces (struct cpu_features *cpu_features,
-		    unsigned int *family, unsigned int *model)
+		    unsigned int *family, unsigned int *model,
+		    unsigned int *extended_model)
 {
   unsigned int eax;
   __cpuid (1, eax, cpu_features->cpuid[COMMON_CPUID_INDEX_1].ebx,
@@ -30,6 +31,12 @@ get_common_indeces (struct cpu_features *cpu_features,
   GLRO(dl_x86_cpu_features).cpuid[COMMON_CPUID_INDEX_1].eax = eax;
   *family = (eax >> 8) & 0x0f;
   *model = (eax >> 4) & 0x0f;
+  *extended_model = (eax >> 12) & 0xf0;
+  if (*family == 0x0f)
+    {
+      *family += (eax >> 20) & 0xff;
+      *model += *extended_model;
+    }
 }
 
 static inline void
@@ -45,19 +52,13 @@ init_cpu_features (struct cpu_features *cpu_features)
   /* This spells out "GenuineIntel".  */
   if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
     {
+      unsigned int extended_model;
+
       kind = arch_kind_intel;
 
-      get_common_indeces (cpu_features, &family, &model);
+      get_common_indeces (cpu_features, &family, &model, &extended_model);
 
-      unsigned int eax = cpu_features->cpuid[COMMON_CPUID_INDEX_1].eax;
-      unsigned int extended_family = (eax >> 20) & 0xff;
-      unsigned int extended_model = (eax >> 12) & 0xf0;
-      if (family == 0x0f)
-	{
-	  family += extended_family;
-	  model += extended_model;
-	}
-      else if (family == 0x06)
+      if (family == 0x06)
 	{
 	  ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
 	  model += extended_model;
@@ -130,9 +131,11 @@ init_cpu_features (struct cpu_features *cpu_features)
   /* This spells out "AuthenticAMD".  */
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
     {
+      unsigned int extended_model;
+
       kind = arch_kind_amd;
 
-      get_common_indeces (cpu_features, &family, &model);
+      get_common_indeces (cpu_features, &family, &model, &extended_model);
 
       ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;