Skip to content

Conversation

@radekdoulik
Copy link
Member

No description provided.

@ghost
Copy link

ghost commented Apr 19, 2023

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned radekdoulik Apr 19, 2023
@ghost
Copy link

ghost commented Apr 19, 2023

Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: radekdoulik
Assignees: radekdoulik
Labels:

area-System.Runtime.Intrinsics, new-api-needs-documentation

Milestone: -

@radekdoulik
Copy link
Member Author

A test method:

    static void TestSatA()
    {
        Vector128<int> v1int = Vector128.Create(Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next());
        Vector128<int> v2int = Vector128.Create(Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next());

        Vector128<byte> v1byte = Vector128.Create((byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next());
        Vector128<byte> v2byte = Vector128.Create((byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next(), (byte)Random.Shared.Next());

        Vector128<short> v1short = Vector128.Create((short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next());
        Vector128<short> v2short = Vector128.Create((short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next(), (short)Random.Shared.Next());

        Console.WriteLine($"v1: {v1int}");
        Console.WriteLine($"v2: {v2int}");
        Console.WriteLine($"add sat: {PackedSimd.AddSaturate(v1byte, v2byte)}");
        Console.WriteLine($"sub sat: {PackedSimd.SubtractSaturate(v1byte, v2byte)}");
        Console.WriteLine($"mul round sat: {PackedSimd.MultiplyRoundedSaturateQ15(v1short, v2short)}");
        Console.WriteLine($"min: {PackedSimd.Min(v1int, v2int)}");
        Console.WriteLine($"max: {PackedSimd.Max(v1int, v2int)}");
        Console.WriteLine($"avg round sat: {PackedSimd.AverageRounded(v1byte, v2byte)}");
        Console.WriteLine($"abs: {PackedSimd.Abs(v1int)}");
    }

output:

  v1: <1050742669, 1570759397, 963964663, 1067018614>
  v2: <1111389472, 376157844, 484061419, 917414378>
  add sat: <255, 188, 255, 255, 84, 255, 146, 193, 255, 255, 220, 255, 255, 217, 196, 184>
  sub sat: <0, 0, 31, 0, 16, 26, 54, 0, 0, 0, 136, 100, 12, 0, 0, 14>
  mul round sat: <18625, -17392, -14101, 6577, 25508, -971, 10840, -8814>
  min: <1111389472, 1570759397, 963964663, 1067018614>
  max: <1050742669, 376157844, 484061419, 917414378>
  avg round sat: <138, 94, 239, 134, 42, 181, 73, 97, 131, 135, 110, 163, 145, 109, 98, 92>
  abs: <1050742669, 1570759397, 963964663, 1067018614>

and instructions in the emitted code:

> wa-info -d -f TestSat /mnt/d/git/wa-local/src/mono/sample/wasm/console-node/bin/Release/AppBundle/dotnet.wasm|grep SIMD|egrep 'sat|abs|avg|min|max'
     i8x16.add.sat.u    [SIMD]
     i8x16.sub.sat.u    [SIMD]
     i16x8.q15mulr.sat.s    [SIMD]
     i32x4.max.s    [SIMD]
     i32x4.min.s    [SIMD]
     i8x16.avgr.u    [SIMD]
 i32x4.abs    [SIMD]

@vargaz
Copy link
Contributor

vargaz commented Apr 19, 2023

The mono changes look ok.

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are implementing the already approved packed simd

@radekdoulik radekdoulik merged commit 1ad1f65 into dotnet:main Apr 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants