类似信息的CPUID的内在? [英] Intrinsics for CPUID like informations?

查看:181
本文介绍了类似信息的CPUID的内在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到我用C ++编写代码,如果可能,我想使用类似Intrinsics的解决方案来读取有关硬件的有用信息,我的注意事项是:




  • 我不知道程序集,这将是一个相当大的投资,只是为了获得这种信息(看起来像CPU只是关于翻转值和读取寄存器。)

  • 至少有两种流行的语法用于asm(Intel和AT& T),所以它是分段的

  • 奇怪的是Intrinsics比asm更受欢迎和支持

  • 并不是所有的编译器在我的雷达现在支持inline asm,MSVC 64位是一个;恐怕我会发现其他类似的缺陷,同时挖掘更多的不同编译器的功能集,我必须使用。

  • 考虑到我认为这是更有效的我对于Intrinsics来说,它应该也比任何一个asm代码更容易。



最后一个问题,我必须回答是:如何做一个类似的事情与内在的?因为我根本没有发现除了CPUID操作码之外没有任何其他信息。

解决方案

href =https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/X86-Built-in-Functions.html =nofollow>我发现一个有用的内置程序,



唯一的问题是这类函数真的有限(基本上你只有2个函数,1个用于CPU名称 1用于寄存器集合)



一个例子是

  include< stdio.h> 

int main()
{
if(__builtin_cpu_supports(mmx)){
printf(\\\
I got MMX!\\\
);
} else
printf(\\\
What?MMX?这是什么?\\\
);
return(0);
}

显然这个内置函数也在mingw-w64下工作。 p>

Considering that I'm coding in C++, if possible, I would like to use an Intrinsics-like solution to read useful informations about the hardware, my concerns/considerations are:

  • I don't know assembly that well, it will be a considerable investment just to get this kind of informations ( altough it looks like CPU it's just about flipping values and reading registers. )
  • there at least 2 popular syntax for asm ( Intel and AT&T ), so it's fragmented
  • strangely enough Intrinsics are more popular and supported than asm code this days
  • not all the the compilers that are in my radar right now support inline asm, MSVC 64 bit is one; I'm afraid that I will find other similar flaws while digging more into the feature sets of the different compilers that I have to use.
  • considering the trand I think that is more productive for me to bet on Intrinsics, it should be also way more easy than any asm code.

And the last question that I have to answer to is: how to do a similar thing with intrinsics ? Because I haven't found nothing other than CPUID opcodes to get this kind of informations at all.

解决方案

After some digging I have found a useful built-in functions that is gcc specific.

The only problem is that this kind of functions are really limited ( basically you have only 2 functions, 1 for the CPU "name" and 1 for the set of registers )

an example is

#include <stdio.h>

int main()
{
    if (__builtin_cpu_supports("mmx")) {
        printf("\nI got MMX !\n");
    } else
        printf("\nWhat ? MMX ? What is that ?\n");
    return (0);
}

and apparently this built-in functions work under mingw-w64 too.

这篇关于类似信息的CPUID的内在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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