mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-11-12 14:57:20 +00:00
[common] cpuinfo: move feature queries to platform code
This commit is contained in:
@@ -50,15 +50,7 @@ const CPUInfoFeatures * cpuInfo_getFeatures(void)
|
||||
int cpuid[4] = {0};
|
||||
|
||||
// leaf1
|
||||
asm volatile
|
||||
(
|
||||
"cpuid;"
|
||||
: "=a" (cpuid[0]),
|
||||
"=b" (cpuid[1]),
|
||||
"=c" (cpuid[2]),
|
||||
"=d" (cpuid[3])
|
||||
: "a" (1)
|
||||
);
|
||||
platform_cpuInfoCPUID(cpuid, 1, 0);
|
||||
|
||||
features.sse = cpuid[3] & (1 << 25);
|
||||
features.sse2 = cpuid[3] & (1 << 26);
|
||||
@@ -74,15 +66,7 @@ const CPUInfoFeatures * cpuInfo_getFeatures(void)
|
||||
features.avx = cpuid[2] & (1 << 28);
|
||||
|
||||
// leaf7
|
||||
asm volatile
|
||||
(
|
||||
"cpuid;"
|
||||
: "=a" (cpuid[0]),
|
||||
"=b" (cpuid[1]),
|
||||
"=c" (cpuid[2]),
|
||||
"=d" (cpuid[3])
|
||||
: "a" (7), "c" (0)
|
||||
);
|
||||
platform_cpuInfoCPUID(cpuid, 7, 0);
|
||||
|
||||
features.avx2 = cpuid[1] & (1 << 5);
|
||||
features.bmi1 = cpuid[2] & (1 << 3);
|
||||
@@ -90,14 +74,7 @@ const CPUInfoFeatures * cpuInfo_getFeatures(void)
|
||||
|
||||
if (features.osxsave && features.avx)
|
||||
{
|
||||
int xgetbv = 0;
|
||||
asm volatile
|
||||
(
|
||||
"xgetbv;"
|
||||
: "=a" (xgetbv)
|
||||
: "c" (0)
|
||||
: "edx"
|
||||
);
|
||||
const uint64_t xgetbv = platform_cpuInfoXGETBV(0);
|
||||
|
||||
if (!(xgetbv & 0x6))
|
||||
{
|
||||
|
||||
@@ -27,6 +27,33 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void platform_cpuInfoCPUID(int registers[4], int leaf, int subleaf)
|
||||
{
|
||||
asm volatile
|
||||
(
|
||||
"cpuid;"
|
||||
: "=a" (registers[0]),
|
||||
"=b" (registers[1]),
|
||||
"=c" (registers[2]),
|
||||
"=d" (registers[3])
|
||||
: "a" (leaf), "c" (subleaf)
|
||||
);
|
||||
}
|
||||
|
||||
uint64_t platform_cpuInfoXGETBV(unsigned int index)
|
||||
{
|
||||
uint32_t low;
|
||||
uint32_t high;
|
||||
asm volatile
|
||||
(
|
||||
"xgetbv;"
|
||||
: "=a" (low), "=d" (high)
|
||||
: "c" (index)
|
||||
);
|
||||
|
||||
return ((uint64_t)high << 32) | low;
|
||||
}
|
||||
|
||||
bool cpuInfo_get(char * model, size_t modelSize, int * procs, int * cores,
|
||||
int * sockets)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,19 @@
|
||||
#include "common/debug.h"
|
||||
#include "common/windebug.h"
|
||||
|
||||
#include <intrin.h>
|
||||
#include <windows.h>
|
||||
|
||||
void platform_cpuInfoCPUID(int registers[4], int leaf, int subleaf)
|
||||
{
|
||||
__cpuidex(registers, leaf, subleaf);
|
||||
}
|
||||
|
||||
uint64_t platform_cpuInfoXGETBV(unsigned int index)
|
||||
{
|
||||
return _xgetbv(index);
|
||||
}
|
||||
|
||||
static bool getCPUModel(char * model, size_t modelSize)
|
||||
{
|
||||
if (!model)
|
||||
|
||||
Reference in New Issue
Block a user