From b3e2c6941620773ccfba833f9945e2fce5169bb7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 27 Nov 2018 17:28:36 +0100 Subject: Add utility function to query CPU brand string --- source/blender/blenlib/intern/system.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source/blender/blenlib/intern') 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; +} -- cgit v1.2.3