RyuJIT没有充分利用SIMD内在函数

时间:2016-01-20 10:14:31

标签: c# sse simd avx ryujit

我正在运行一些使用System.Numerics.Vector<T>的C#代码但据我所知,我没有充分利用SIMD内在函数。我使用Visual Studio Community 2015和Update 1,我的clrjit.dll是v4.6.1063.1。

我在Intel Core i5-3337U Processor上运行,它实现了AVX指令集扩展。因此,我想,我应该能够在256位寄存器上执行大多数SIMD指令。例如,反汇编应包含vmovupsvmovupdvaddups等指示,而Vector<float>.Count应返回8,Vector<double>.Count应为4等等......但那不是我所看到的。

相反,我的反汇编包含movupsmovupdaddups等说明以及以下代码:

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");

产地:

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

我哪里错了?要查看所有项目设置等,项目可用here

1 个答案:

答案 0 :(得分:12)

你的处理器有点陈旧,它的微架构是Ivy Bridge。 Sandy Bridge的“tock”,功能缩小,没有架构变化。你的克星是RyuJIT中的一些代码,located in ee_il_dll.cpp,CILJit :: getMaxIntrinsicSIMDVectorLength()函数:

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;
    }
}

注意使用CORJIT_FLG_USE_AVX2。您的处理器尚不支持AVX2,该扩展程序在Haswell中可用。继Ivy Bridge之后的下一个微架构,一个“滴答”。非常好的处理器btw,像this one这样的发现有一个重要的惊人因素。

你无能为力,但去购物。为了获得灵感,您可以查看它在this post中生成的代码类型。