Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-11-27 19:28:36 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-11-28 16:35:26 +0300
commitb3e2c6941620773ccfba833f9945e2fce5169bb7 (patch)
tree52d923af110622def9cf5162305438ae9bce9894 /source/blender/blenlib/intern
parent683662e630b855947b7e083ca6cde0cfe7694687 (diff)
Add utility function to query CPU brand string
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/system.c38
1 files changed, 38 insertions, 0 deletions
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;
+}