Add utility function to query CPU brand string
This commit is contained in:
parent
683662e630
commit
b3e2c69416
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user