runtime: Avx.HorizontalAdd produces incorrect result sometimes

I have the following C++ code:

    float array[] = {8392608, 8394057, 8395506, 8396955, 8398404, 8399853, 8401302, 8402751};
    __m256 vec = _mm256_loadu_ps(array);
    __m256 add = _mm256_hadd_ps(vec, vec);

the result of _mm256_hadd_ps is:

16786664.0, 16792460.0, 16786664.0, 16792460.0, 16798256.0, 16804052.0, ...

but when I do it in C# using System.Runtime.Intrinsics.X86 I get different values:

16786660.0, 16792460.0, 16786660.0, 16792460.0, 16798260.0, 16804050.0, 16798260.0, 16804050.0

C# version:

    var array = new float[] {8392608, 8394057, 8395506, 8396955, 8398404, 8399853, 8401302, 8402751};
    fixed (float* ptr = &array[0])
    {
        var vec = Avx.LoadVector256(ptr);
        Vector256<float> add = Avx.HorizontalAdd(vec, vec);
    }

I am not an expert in SIMD so probably I am missing something?

System.Runtime.Intrinsics.Experimental: 4.5.0-rc1 dotnet --version: 2.1.300-preview2-008530

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Seems to work fine in VS debugger: image