Skip to content

Improve Vector<uint> and Vector<ushort> multiply #30923

@IJzerbaard

Description

@IJzerbaard

I read on https://docs.microsoft.com/en-us/dotnet/api/system.numerics.vector-1?view=netcore-3.0 that Vector and Vector multiplications do not map to intrinsics. Experimentation confirmed that.

However, they could simply map to (v)pmulld (when available) and (v)pmullw.

Current workaround:

    static Vector<uint> Multiply(Vector<uint> a, Vector<uint> b)
    {
        return Vector.AsVectorUInt32(Vector.AsVectorInt32(a) * Vector.AsVectorInt32(b));
    }

    static Vector<ushort> Multiply(Vector<ushort> a, Vector<ushort> b)
    {
        return Vector.AsVectorUInt16(Vector.AsVectorInt16(a) * Vector.AsVectorInt16(b));
    }

byte, sbyte, long and ulong could potentially be supported with multi-operation sequences, which is at least better than calling some scalar fallback, especially for the 8bit cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cost:SWork that requires one engineer up to 1 weekarea-System.Numericshelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions