[haiku-commits] haiku: hrev45389 - headers/private/shared

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 20 Mar 2013 21:05:23 +0100 (CET)

hrev45389 adds 1 changeset to branch 'master'
old head: 190423a65660a7b4a3ad92c0a97a5fcfe2278d83
new head: df4d35e837cc7ba09409fc0111031351385411df
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=df4d35e+%5E190423a

----------------------------------------------------------------------------

df4d35e: Added a parse_amd() for CPU identification.
  
  * This parses the reported CPU name, and tries to translate it to a normal
    and concise identifier.
  * For example, it will translate "AMD FX(tm)-8320 Eight-core Processor" into
    "FX™ 8320" or "Dual Core AMD Opteron(tm) Processor 275 HE" into
    "Opteron™ 275 HE".
  * This means we can remove AMD strings for those models for which this
    function produces useful results.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev45389
Commit:      df4d35e837cc7ba09409fc0111031351385411df
URL:         http://cgit.haiku-os.org/haiku/commit/?id=df4d35e
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Mar 20 19:59:26 2013 UTC

----------------------------------------------------------------------------

1 file changed, 70 insertions(+)
headers/private/shared/cpu_type.h | 70 +++++++++++++++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/headers/private/shared/cpu_type.h 
b/headers/private/shared/cpu_type.h
index 71481c2..f4a9c75 100644
--- a/headers/private/shared/cpu_type.h
+++ b/headers/private/shared/cpu_type.h
@@ -78,6 +78,71 @@ parse_intel(const char* name)
        buffer[outIndex] = '\0';
        return buffer;
 }
+
+
+static const char*
+parse_amd(const char* name)
+{
+       static char buffer[49];
+
+       // ignore initial spaces
+       int index = 0;
+       for (; name[index] != '\0'; index++) {
+               if (name[index] != ' ')
+                       break;
+       }
+
+       // parse model
+       int outIndex = 0;
+       bool spaceWritten = false;
+       for (; name[index] != '\0'; index++) {
+               if (!strncasecmp(&name[index], "(r)", 3)) {
+                       outIndex += strlcpy(&buffer[outIndex], "®",
+                               sizeof(buffer) - outIndex);
+                       index += 2;
+               } else if (!strncasecmp(&name[index], "(tm)", 4)) {
+                       outIndex += strlcpy(&buffer[outIndex], "™",
+                               sizeof(buffer) - outIndex);
+                       index += 3;
+               } else if (!strncasecmp(&name[index], "Dual core", 9)) {
+                        index += 9;
+               } else if (!strncasecmp(&name[index], "Eight-core", 10)
+                       || !strncasecmp(&name[index], "Quad-core", 9)
+                       || !strncasecmp(&name[index], "Processor", 9)
+                       || !strncasecmp(&name[index], "AMD", 3)) {
+                       // Remove words
+                       while (name[index] != ' ' && name[index] != '\0')
+                               index++;
+
+                       index--;
+               } else if (name[index] == '-') {
+                       if (!spaceWritten)
+                               buffer[outIndex++] = ' ';
+                       spaceWritten = true;
+               } else {
+                       if (name[index] == ' ') {
+                               if (spaceWritten)
+                                       continue;
+                               spaceWritten = true;
+                       } else
+                               spaceWritten = false;
+                       buffer[outIndex++] = name[index];
+               }
+       }
+
+       // cut off trailing spaces
+       while (outIndex > 1 && buffer[outIndex - 1] == ' ')
+               outIndex--;
+
+       buffer[outIndex] = '\0';
+
+       // skip new initial spaces
+       for (outIndex = 0; buffer[outIndex] != '\0'; outIndex++) {
+               if (buffer[outIndex] != ' ')
+                       break;
+       }
+       return buffer + outIndex;
+}
 #endif
 
 
@@ -406,6 +471,11 @@ get_cpu_model_string(system_info *info)
                                get_cpuid_model_string(cpuidName);
                                return parse_intel(cpuidName);
                        }
+                       if ((info->cpu_type & B_CPU_x86_VENDOR_MASK) == 
B_CPU_AMD_x86) {
+                               // Fallback to manual parsing of the model 
string
+                               get_cpuid_model_string(cpuidName);
+                               return parse_amd(cpuidName);
+                       }
                        return NULL;
 #endif /* __INTEL__ || __x86_64__ */
        }


Other related posts:

  • » [haiku-commits] haiku: hrev45389 - headers/private/shared - axeld