如何在ARM64中获取CPU品牌信息? [英] How to get CPU brand information in ARM64?

查看:381
本文介绍了如何在ARM64中获取CPU品牌信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows X86中,可以使用cpuid内在函数查询CPU品牌. 这是代码示例:

In Windows X86, the CPU brand can be queried with cpuid intrinsic function. Here is a sample of the code:

#include <stdio.h>
#include <intrin.h>

int main(void)
{
    int cpubrand[4 * 3];

    __cpuid(&cpubrand[0], 0x80000002);
    __cpuid(&cpubrand[4], 0x80000003);
    __cpuid(&cpubrand[8], 0x80000004);

    char str[48];
    memset(str, 0, sizeof str);
    memcpy(str, cpubrand, sizeof cpubrand);
    printf("%s\n", str);
}

在Windows ARM64中,这有什么替代方案?

What is the alternative of this in Windows ARM64?

推荐答案

尽管可能不是您要查找的答案(即直接询问CPU),但您可以获取"ProcessorNameString";使用以下代码从Windows注册表中获取值:

Although probably not the answer you're looking for (i.e. directly interrogating the CPU), you can fetch the "ProcessorNameString" value from the Windows Registry using code like the following:

#define BUFSIZ 64 // For easy adjustment of limits, if required

char answer[BUFSIZ] = "Error Reading CPU Name from Registry!", inBuffer[BUFSIZ] = "";
const char *csName = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
HKEY hKey;  DWORD gotType, gotSize = BUFSIZ;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, csName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
    if (!RegQueryValueExA(hKey, "ProcessorNameString", nullptr, &gotType, (PBYTE)(inBuffer), &gotSize)) {
        if ((gotType == REG_SZ) && strlen(inBuffer)) strcpy(answer, inBuffer);
    }
    RegCloseKey(hKey);
}

这将(或应该)为您提供Windows系统看到的处理器的名称"!我没有访问ARM64系统的权限,因此无法正确测试它,但是在我的x64系统上,我得到了以下(正确的)字符串:Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz(完全是 使用__cpuid()调用返回以获取品牌字符串").

This will (or should) give you the processor's 'name' that the Windows system sees! I don't have access to an ARM64 system, so I can't properly test it but, on my x64 system, I get the following (correct) string: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (which is exactly that returned by using __cpuid() calls to get the "Brand String").

但是,像您一样,我很想知道一种直接执行 的方法-即Windows操作系统如何在ARM64系统上获取此信息?

However, like you, I would be very interested to know of a way to do this directly - i.e., how would the Windows O/S get this info on an ARM64 system?

这篇关于如何在ARM64中获取CPU品牌信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆