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