Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

intrinsic for CPUID like informations

bp
初学者
2,740 次查看

I just found that the Intel C++ Compiler XE 13.1 offers this intrinsic

Now I'm under Linux with g++ and I would like to know if there is a similar intrinsic.

Thanks.

0 项奖励
12 回复数
SergeyKostrov
重要分销商 II
2,740 次查看
The _may_i_use_cpu_feature intrinsic function is declared in immintrin.h header file and I'm no sure if you could use the instruction if CPU doesn't support AVX or AVX2 instruction sets.
0 项奖励
SergeyKostrov
重要分销商 II
2,740 次查看
>>...I'm no sure if you could use the instruction if CPU doesn't support AVX or AVX2 instruction sets... It is working and it means the function uses a generic IA32 set of Intel instructions. Here are runtime outputs for two different systems: [ TestApp Executed on Ivy Bridge ] _FEATURE_SSE = 1 _FEATURE_SSE2 = 1 _FEATURE_F16C = 1 _FEATURE_AVX = 1 _FEATURE_AVX2 = 0 [ TestApp Executed on Pentium 4 ] _FEATURE_SSE = 1 _FEATURE_SSE2 = 1 _FEATURE_F16C = 0 _FEATURE_AVX = 0 _FEATURE_AVX2 = 0 Note: A test program TestApp was built on Ivy Bridge with VS 2008.
0 项奖励
maratyszcza
初学者
2,740 次查看

gcc 4.8 provides similar feature via __builtin_cpu_supports intrinsic. See GCC 4.8 release notes for details: http://gcc.gnu.org/gcc-4.8/changes.html

0 项奖励
SergeyKostrov
重要分销商 II
2,740 次查看
I'd like to add that the name of the intrinsic function: _may_i_use_cpu_feature looks very strange and it violates already defined naming conventions, that is, using _mm_ prefix for 99% of all intrinsic functions. I think Intel needs to rename the function to: __cpufeature ( similar to __cpuid ) or _mm_cpufeature and please consider it as a Feature Request. Thanks.
0 项奖励
andysem
新分销商 III
2,740 次查看

While I agree that _may_i_use_cpu_feature is a very odd name, I don't think that _mm_ prefix is appropriate because cpuid is not a SIMD (or "multimedia", in the early Intel terms; remember MMX) instruction.

Just for the sake of reference, MSVC supports __cpuid intrinsic: http://msdn.microsoft.com/es-es/library/vstudio/hskdteyh%28v=vs.100%29.aspx. I think, Intel on Windows should support it as well.

0 项奖励
Bernard
重要分销商 I
2,740 次查看

Sergey Kostrov wrote:

I'd like to add that the name of the intrinsic function:

_may_i_use_cpu_feature

looks very strange and it violates already defined naming conventions, that is, using _mm_ prefix for 99% of all intrinsic functions. I think Intel needs to rename the function to:

__cpufeature ( similar to __cpuid )

or

_mm_cpufeature

and please consider it as a Feature Request. Thanks.

Completely agree with you

0 项奖励
SergeyKostrov
重要分销商 II
2,740 次查看
[ SergeyK suggested ] >>...I think Intel needs to rename the function to: >> >>__cpufeature ( similar to __cpuid ) [ Andysem wrote ] >>...I don't think that _mm_ prefix is appropriate because cpuid is not a SIMD... Here is a question: Why wouldn't we vote for __cpufeature name?
0 项奖励
SergeyKostrov
重要分销商 II
2,740 次查看
A test case is very simple and here it is: #include "immintrin.h" #define __cpufeature _may_i_use_cpu_feature int _tmain( void ) { int iSse = __cpufeature( _FEATURE_SSE ); int iSse2 = __cpufeature( _FEATURE_SSE2 ); int iF16c = __cpufeature( _FEATURE_F16C ); int iAvx = __cpufeature( _FEATURE_AVX ); int iAvx2 = __cpufeature( _FEATURE_AVX2 ); _tprintf( _T("_FEATURE_SSE = %d\n") _T("_FEATURE_SSE2 = %d\n") _T("_FEATURE_F16C = %d\n") _T("_FEATURE_AVX = %d\n") _T("_FEATURE_AVX2 = %d\n"), iSse, iSse2, iF16c, iAvx, iAvx2 ); return ( int )0; }
0 项奖励
andysem
新分销商 III
2,740 次查看

Sergey Kostrov wrote:

Here is a question: Why wouldn't we vote for __cpufeature name?

Yes, that naming is my preference. +1 for renaming.

0 项奖励
Bernard
重要分销商 I
2,740 次查看

>>>Here is a question: Why wouldn't we vote for __cpufeature name?>>>

Proper for name for cpuid intrinsic function.

0 项奖励
andysem
新分销商 III
2,740 次查看

> Proper for name for cpuid intrinsic function.

cpuid intrinsic is more useful when you want to test for multiple features. Which, by the way, is often the case when testing for different versions of SSE/AVX.

0 项奖励
SergeyKostrov
重要分销商 II
2,740 次查看
I like that new intrinsic function and I used it already a couple of times. However, I vote for a change to __cpufeature name and the list of supported features needs to be extended. Thanks in advance.
0 项奖励
回复