__cpuid

__cpuid 是一个内联汇编函数,用于在 C 和 C++ 代码中获取有关 CPU 信息的指令集扩展。

引用头文件:

#include <cpuid.h>

这条指令利用了 x86 和 x86_64 处理器的 CPUID 指令,通过查询处理器支持的功能、型号、

制造商等硬件信息,为开发者提供了对 CPU 的低层访问。

/* x86-64 uses %rbx as the base register, so preserve it. */
#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
    __asm("  xchgq  %%rbx,%q1\n" \
          "  cpuid\n" \
          "  xchgq  %%rbx,%q1" \
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
        : "0"(__leaf))

 

posted @ 2025-09-18 10:10  hugingface  阅读(34)  评论(0)    收藏  举报