• <small id='22m0n'></small><noframes id='22m0n'>

  • <tfoot id='22m0n'></tfoot>
    • <bdo id='22m0n'></bdo><ul id='22m0n'></ul>
    <legend id='22m0n'><style id='22m0n'><dir id='22m0n'><q id='22m0n'></q></dir></style></legend>

      1. <i id='22m0n'><tr id='22m0n'><dt id='22m0n'><q id='22m0n'><span id='22m0n'><b id='22m0n'><form id='22m0n'><ins id='22m0n'></ins><ul id='22m0n'></ul><sub id='22m0n'></sub></form><legend id='22m0n'></legend><bdo id='22m0n'><pre id='22m0n'><center id='22m0n'></center></pre></bdo></b><th id='22m0n'></th></span></q></dt></tr></i><div id='22m0n'><tfoot id='22m0n'></tfoot><dl id='22m0n'><fieldset id='22m0n'></fieldset></dl></div>

        我如何调用“cpuid"?在 Linux 中?

        时间:2023-08-01

        <small id='QGhPZ'></small><noframes id='QGhPZ'>

        <tfoot id='QGhPZ'></tfoot>
          • <bdo id='QGhPZ'></bdo><ul id='QGhPZ'></ul>

                <tbody id='QGhPZ'></tbody>

              <i id='QGhPZ'><tr id='QGhPZ'><dt id='QGhPZ'><q id='QGhPZ'><span id='QGhPZ'><b id='QGhPZ'><form id='QGhPZ'><ins id='QGhPZ'></ins><ul id='QGhPZ'></ul><sub id='QGhPZ'></sub></form><legend id='QGhPZ'></legend><bdo id='QGhPZ'><pre id='QGhPZ'><center id='QGhPZ'></center></pre></bdo></b><th id='QGhPZ'></th></span></q></dt></tr></i><div id='QGhPZ'><tfoot id='QGhPZ'></tfoot><dl id='QGhPZ'><fieldset id='QGhPZ'></fieldset></dl></div>
                  <legend id='QGhPZ'><style id='QGhPZ'><dir id='QGhPZ'><q id='QGhPZ'></q></dir></style></legend>
                  本文介绍了我如何调用“cpuid"?在 Linux 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在为 Windows 编写新代码时,我偶然发现了 Windows API 中的 _cpuinfo().由于我主要处理 Linux 环境 (GCC),因此我想访问 CPUInfo.

                  While writing new code for Windows, I stumbled upon _cpuinfo() from the Windows API. As I am mainly dealing with a Linux environment (GCC) I want to have access to the CPUInfo.

                  我尝试了以下方法:

                  #include <iostream>
                  
                  int main()
                  {
                    int a, b;
                  
                    for (a = 0; a < 5; a++)
                    {
                      __asm ( "mov %1, %%eax; "            // a into eax
                            "cpuid;"
                            "mov %%eax, %0;"             // eax into b
                            :"=r"(b)                     // output
                            :"r"(a)                      // input
                            :"%eax","%ebx","%ecx","%edx" // clobbered register
                           );
                      std::cout << "The code " << a << " gives " << b << std::endl;
                    }
                  
                    return 0;
                  }
                  

                  这个使用程序集,但我不想重新发明轮子.有没有其他方法可以在没有汇编的情况下实现 CPUInfo?

                  This use assembly but I don't want to re-invent the wheel. Is there any other way to implement CPUInfo without assembly?

                  编译器错误:

                  lewis@lewis-desktop:~/Desktop/prog$ g++ -Wall CPUInfo.cpp
                  CPUInfo.cpp: In function ‘int main()’:
                  CPUInfo.cpp:10:22: error: expected ‘)’ before ‘;’ token
                  CPUInfo.cpp:10:23: error: expected primary-expression before ‘)’ token
                  CPUInfo.cpp:10:23: error: expected ‘;’ before ‘)’ token
                  CPUInfo.cpp:8:8: warning: unused variable ‘b’ [-Wunused-variable]
                  CPUInfo.cpp:12:8: error: expected ‘}’ at end of input
                  

                  推荐答案

                  既然你是用 GCC 编译的,那么你可以包含声明这些函数的 cpuid.h:

                  Since you are compiling with GCC then you can include cpuid.h which declares these functions:

                  /* Return highest supported input value for cpuid instruction.  ext can
                     be either 0x0 or 0x8000000 to return highest supported value for
                     basic or extended cpuid information.  Function returns 0 if cpuid
                     is not supported or whatever cpuid returns in eax register.  If sig
                     pointer is non-null, then first four bytes of the signature
                     (as found in ebx register) are returned in location pointed by sig.  */
                  unsigned int __get_cpuid_max (unsigned int __ext, unsigned int *__sig)
                  
                  /* Return cpuid data for requested cpuid level, as found in returned
                     eax, ebx, ecx and edx registers.  The function checks if cpuid is
                     supported and returns 1 for valid cpuid information or 0 for
                     unsupported cpuid level.  All pointers are required to be non-null.  */
                  int __get_cpuid (unsigned int __level,
                      unsigned int *__eax, unsigned int *__ebx,
                      unsigned int *__ecx, unsigned int *__edx)
                  

                  您不需要也不应该重新实现此功能.

                  You don't need to, and should not, re-implement this functionality.

                  这篇关于我如何调用“cpuid"?在 Linux 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:GCC 内联汇编中的标签 下一篇:高度优化的矩阵乘法代码在 MSVC 和 GCC 之间的性能

                  相关文章

                  最新文章

                • <i id='AaCCw'><tr id='AaCCw'><dt id='AaCCw'><q id='AaCCw'><span id='AaCCw'><b id='AaCCw'><form id='AaCCw'><ins id='AaCCw'></ins><ul id='AaCCw'></ul><sub id='AaCCw'></sub></form><legend id='AaCCw'></legend><bdo id='AaCCw'><pre id='AaCCw'><center id='AaCCw'></center></pre></bdo></b><th id='AaCCw'></th></span></q></dt></tr></i><div id='AaCCw'><tfoot id='AaCCw'></tfoot><dl id='AaCCw'><fieldset id='AaCCw'></fieldset></dl></div>

                    <bdo id='AaCCw'></bdo><ul id='AaCCw'></ul>
                • <legend id='AaCCw'><style id='AaCCw'><dir id='AaCCw'><q id='AaCCw'></q></dir></style></legend>
                  1. <tfoot id='AaCCw'></tfoot>

                      <small id='AaCCw'></small><noframes id='AaCCw'>