Skip to content

[RyuJIT] Sse2.Extract with sign-extension not working properly #10312

@gdkchan

Description

@gdkchan

I was trying the new X86 intrinsics and noticed that when casting a signed type extracted from a vector to a larger signed type, the value is not sign-extended, it is zero-extended.

The following program demonstrates the issue:

using System;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

namespace SseTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Vector128<short> test = Sse2.SetVector128(0, 0, 0, 0, 0, 0, 0, -1);

            Console.WriteLine(ExtractShortLow(test));
            Console.WriteLine(ExtractShortLow2(test));
        }

        private static int ExtractShortLow(Vector128<short> Vector)
        {
            return Sse2.Extract(Vector, 0);
        }

        private static int ExtractShortLow2(Vector128<short> Vector)
        {
            short tmp = Sse2.Extract(Vector, 0);
            return tmp;
        }
    }
}

On debug mode, the output is:

65535
-1

On release, it is:

65535
65535

The expected output is:

-1
-1

dotnet version: 2.1.300-rc1-008673.
Sorry if it was already reported elsewhere.

Edit: The issue also happens with sbyte, but not with int -> long.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions