[Bf-blender-cvs] [b3e2c694162] master: Add utility function to query CPU brand string

Sergey Sharybin noreply at git.blender.org
Wed Nov 28 14:42:03 CET 2018


Commit: b3e2c6941620773ccfba833f9945e2fce5169bb7
Author: Sergey Sharybin
Date:   Tue Nov 27 17:28:36 2018 +0100
Branches: master
https://developer.blender.org/rBb3e2c6941620773ccfba833f9945e2fce5169bb7

Add utility function to query CPU brand string

===================================================================

M	source/blender/blenlib/BLI_system.h
M	source/blender/blenlib/intern/system.c

===================================================================

diff --git a/source/blender/blenlib/BLI_system.h b/source/blender/blenlib/BLI_system.h
index f51b9623803..7f88f8a18b1 100644
--- a/source/blender/blenlib/BLI_system.h
+++ b/source/blender/blenlib/BLI_system.h
@@ -30,6 +30,10 @@
 int BLI_cpu_support_sse2(void);
 void BLI_system_backtrace(FILE *fp);
 
+
+/* Get CPU brand, result is to be MEM_freeN()-ed. */
+char *BLI_cpu_brand_string(void);
+
 /* getpid */
 #ifdef WIN32
 #  define BLI_SYSTEM_PID_H <process.h>
diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c
index ecb977c6e61..38fe2c7a9eb 100644
--- a/source/blender/blenlib/intern/system.c
+++ b/source/blender/blenlib/intern/system.c
@@ -27,6 +27,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_system.h"
+#include "BLI_string.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -138,3 +139,40 @@ void BLI_system_backtrace(FILE *fp)
 
 }
 /* end BLI_system_backtrace */
+
+/* NOTE: The code for CPU brand string is adopted from Cycles. */
+
+#if !defined(_WIN32) || defined(FREE_WINDOWS)
+static void __cpuid(int data[4], int selector)
+{
+#if defined(__x86_64__)
+	asm("cpuid" : "=a" (data[0]), "=b" (data[1]), "=c" (data[2]), "=d" (data[3]) : "a"(selector));
+#elif defined(__i386__)
+	asm("pushl %%ebx    \n\t"
+		"cpuid          \n\t"
+		"movl %%ebx, %1 \n\t"
+		"popl %%ebx     \n\t"
+		: "=a" (data[0]), "=r" (data[1]), "=c" (data[2]), "=d" (data[3])
+		: "a"(selector)
+		: "ebx");
+#else
+	data[0] = data[1] = data[2] = data[3] = 0;
+#endif
+}
+#endif
+
+char *BLI_cpu_brand_string(void)
+{
+	char buf[48] = { 0 };
+	int result[4] = { 0 };
+	__cpuid(result, 0x80000000);
+	if (result[0] >= (int)0x80000004) {
+		__cpuid((int*)(buf + 0), 0x80000002);
+		__cpuid((int*)(buf + 16), 0x80000003);
+		__cpuid((int*)(buf + 32), 0x80000004);
+		char *brand = BLI_strdup(buf);
+		/* TODO(sergey): Make it a bit more presentable by removing trademark. */
+		return brand;
+	}
+	return NULL;
+}



More information about the Bf-blender-cvs mailing list