如何在新的.NET Framework 4.6中启用SIMD?

我写了一个代码来测试,哪种方式更快。 我在Release x64中运行代码。 我有VS 2015 Pro与.NET Framework 4.6。

#if SYSTEMMATHLIB using System.Numerics; #else using Engine.Mathematic; #endif namespace Engine.Editor { public static class Program { public static void Main() { #if SYSTEMMATHLIB Console.WriteLine("Hardware Acceleration: " + Vector.IsHardwareAccelerated.ToString()); #endif Stopwatch sw = new Stopwatch(); sw.Start(); #if SYSTEMMATHLIB for (int i = 0; i < 1000000; i++) { Matrix4x4 m = Matrix4x4.CreateRotationZ(0.50f); m.Translation = new Vector3(5, 10, 15); Matrix4x4 m2 = Matrix4x4.CreateRotationX(0.50f); m2.Translation = new Vector3(-5, 10, -15); Matrix4x4 m3 = m * m2; Matrix4x4 inv; Matrix4x4.Invert(m3, out inv); } #else for (int i = 0; i < 1000000; i++) { Matrix m = Matrix.RotationZ(0.50f); m.TranslationVector = new Vector3(5, 10, 15); Matrix m2 = Matrix.RotationX(0.50f); m2.TranslationVector = new Vector3(-5, 10, -15); Matrix m3 = m * m2; Matrix inv; Matrix.Invert(ref m3, out inv); } #endif long mili = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine("Total mili: " + mili.ToString()); Console.ReadLine(); } } } 

好吧,如果我使用Framework 4.6(Nuget版本)中的System.Numerics运行它,则计算需要212ms。 如果我将它切换到我的库,这只是简单的c#代码来计算它,它也需要大约210毫秒。 那有点奇怪吧? 我虽然SIMD应该更快!

顺便说一句,IsHardwareAccelerated返回“True”。

那么我做错了什么?

仅供参考:没有SIMD的C ++使用SIMD运行390ms和77ms。

我反编译System.Numerics.Vector并且我意识到,SIMD仅针对Vectors实现,而不是针对Matrix4x4实现。 所以Hans Passant是对的。

我希望他们也能尽快增加对SIMD Matrix的支持。