RyuJIT not making full use of SIMD intrinsics

 ̄綄美尐妖づ 提交于 2019-12-05 11:46:07

问题


I'm running some C# code that uses System.Numerics.Vector<T> but as far as I can tell I'm not getting the full benefit of SIMD intrinsics. I'm using Visual Studio Community 2015 with Update 1, and my clrjit.dll is v4.6.1063.1.

I'm running on an Intel Core i5-3337U Processor, which implements the AVX instruction set extensions. Therefore, I figure, I should be able to execute most SIMD instructions on a 256 bit register. For example, the disassembly should contain instructions like vmovups, vmovupd, vaddups, etc..., and Vector<float>.Count should return 8, Vector<double>.Count should be 4, etc... But that's not what I'm seeing.

Instead my disassembly contains instructions like movups, movupd, addups, etc... and the following code:

WriteLine($"{Vector<byte>.Count} bytes per operation");
WriteLine($"{Vector<float>.Count} floats per operation");
WriteLine($"{Vector<int>.Count} ints per operation");
WriteLine($"{Vector<double>.Count} doubles per operation");

Produces:

16 bytes per operation
4 floats per operation
4 ints per operation
2 doubles per operation

Where am I going wrong? To see all project settings etc. the project is available here.


回答1:


Your processor is a bit dated, its micro-architecture is Ivy Bridge. The "tock" of Sandy Bridge, a feature shrink without architectural changes. Your nemesis is this bit of code in RyuJIT, located in ee_il_dll.cpp, CILJit::getMaxIntrinsicSIMDVectorLength() function:

if (((cpuCompileFlags & CORJIT_FLG_PREJIT) == 0) &&
    ((cpuCompileFlags & CORJIT_FLG_FEATURE_SIMD) != 0) &&
    ((cpuCompileFlags & CORJIT_FLG_USE_AVX2) != 0))
{
    static ConfigDWORD fEnableAVX;
    if (fEnableAVX.val(CLRConfig::EXTERNAL_EnableAVX) != 0)
    {
        return 32;
    }
}

Note the use of CORJIT_FLG_USE_AVX2. Your processor does not support AVX2 yet, that extension became available in Haswell. The next micro-architecture after Ivy Bridge, a "tick". Very nice processor btw, discoveries like this one have a major wow factor.

Nothing you can do about this but go shopping. For inspiration, you can look at the kind of code it generates in this post.



来源:https://stackoverflow.com/questions/34897178/ryujit-not-making-full-use-of-simd-intrinsics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!