Skip to content

Vector256.Shuffle() returns incorrect result when index is out of bounds #85132

Closed
@DeepakRajendrakumaran

Description

@DeepakRajendrakumaran

Description

Vector256.Shuffle() returns incorrect result when index is out of bounds. When index is out of bounds, expected to return 0 for that and rest of values correctly

Reproduction Steps

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Numerics;

namespace InterfaceMain
{
    interface Program
    {
          public static unsafe int Main()
        {

            Vector256<int> v256Shuffle1 = Vector256.Create(100, 101, 102, 103, 104, 105, 106, 107);
            Vector256<int> resultElements256Shuffle = Vector256Shuffle(v256Shuffle1);
            Console.Write("\n Vector256Shuffle [ ");
            for (int index = 0; index < Vector256<int>.Count; index++)
            {
                Console.Write(resultElements256Shuffle[index] + ", ");
            }
            Console.Write("]\n Vector256Shuffle Done \n");




            return 100;
        }

        

        [MethodImpl(MethodImplOptions.NoInlining)]
        public static unsafe Vector256<int> Vector256Shuffle(Vector256<int> v1)
        {
            return Vector256.Shuffle(v1, Vector256.Create(7, 555, 3, 1, 6, 4, 2, 0));
        }

    }
}

Expected behavior

Not crash and return 0 for out of bound index

Actual behavior

Crashed on latest main for Debug build

on 7.0, returns incorrect value on sharplab(release?) :

Vector256Suffle [ 107, 0, 103, 101, 0, 0, 0, 0, ]
 Vector256Shuffle Done 

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions