Skip to content

[wasm] PackedSimd, add extending integer arithmetic#84687

Merged
radekdoulik merged 5 commits intodotnet:mainfrom
radekdoulik:pr-wasm-ext-arith
Apr 17, 2023
Merged

[wasm] PackedSimd, add extending integer arithmetic#84687
radekdoulik merged 5 commits intodotnet:mainfrom
radekdoulik:pr-wasm-ext-arith

Conversation

@radekdoulik
Copy link
Member

Add widening multiply and pairwise add intrinsics

@ghost
Copy link

ghost commented Apr 12, 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
Copy link

ghost commented Apr 12, 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

Add widening multiply and pairwise add intrinsics

Author: radekdoulik
Assignees: radekdoulik
Labels:

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

Milestone: -

@radekdoulik
Copy link
Member Author

A test method

    static void TestExt()
    {
        Vector128<int> v1 = Vector128.Create(Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next());
        Vector128<int> v2 = Vector128.Create(Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next(), Random.Shared.Next());
        Console.WriteLine($"v1: {v1}");
        Console.WriteLine($"v2: {v2}");
        Console.WriteLine($"mul  low: {PackedSimd.MultiplyWideningLower(v1, v2)}");
        Console.WriteLine($"mul high: {PackedSimd.MultiplyWideningUpper(v1, v2)}");

        Vector128<ushort> v3 = Vector128.Create((ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next());
        Vector128<ushort> v4 = Vector128.Create((ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next(), (ushort)Random.Shared.Next());
        Console.WriteLine($"v3: {v3}");
        Console.WriteLine($"v4: {v4}");
        Console.WriteLine($"mul  low: {PackedSimd.MultiplyWideningLower(v3, v4)}");
        Console.WriteLine($"mul high: {PackedSimd.MultiplyWideningUpper(v3, v4)}");
        Console.WriteLine($"add pair: {PackedSimd.AddPairwiseWidening(v3)}");

        Vector128<byte> v5 = 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> v6 = 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());
        Console.WriteLine($"v5: {v5}");
        Console.WriteLine($"v6: {v6}");
        Console.WriteLine($"mul  low: {PackedSimd.MultiplyWideningLower(v5, v6)}");
        Console.WriteLine($"mul high: {PackedSimd.MultiplyWideningUpper(v5, v6)}");
        Console.WriteLine($"add pair: {PackedSimd.AddPairwiseWidening(v5)}");
    }

an example output:

v1: <429928023, 1691702038, 1904026602, 395646954>
  v2: <1221797993, 1861441059, 1443288818, 519715237>
  mul  low: <525285195635857839, 3149003633127178242>
  mul high: <2748060303841136436, 205623750466438098>
  v3: <13320, 22412, 34559, 65169, 302, 8581, 869, 3941>
  v4: <36472, 35231, 22312, 11818, 8447, 63047, 44375, 8952>
  mul  low: <485807040, 789597172, 771080408, 770167242>
  mul high: <2550994, 541006307, 38561875, 35279832>
  add pair: <35732, 99728, 8883, 4810>
  v5: <81, 140, 13, 232, 150, 141, 51, 211, 218, 67, 189, 202, 76, 63, 203, 211>
  v6: <118, 89, 195, 18, 184, 161, 37, 171, 56, 66, 67, 39, 63, 63, 49, 46>
  mul  low: <9558, 12460, 2535, 4176, 27600, 22701, 1887, 36081>
  mul high: <12208, 4422, 12663, 7878, 4788, 3969, 9947, 9706>
  add pair: <221, 245, 291, 262, 285, 391, 139, 414>

and instructions in the emitted code:

> wa-info -d -f TestExt dotnet.wasm | grep SIMD | grep ext
     i64x2.extmul.low.i32x4.s    [SIMD]
     i64x2.extmul.high.i32x4.s    [SIMD]
     i32x4.extmul.low.i16x8.u    [SIMD]
     i32x4.extmul.high.i16x8.u    [SIMD]
     i32x4.extadd.pairwise.i16x8.u    [SIMD]
     i16x8.extmul.low.i8x16.u    [SIMD]
     i16x8.extmul.high.i8x16.u    [SIMD]
 i16x8.extadd.pairwise.i8x16.u    [SIMD]

@vargaz
Copy link
Contributor

vargaz commented Apr 12, 2023

The mono changes look ok.

@radekdoulik radekdoulik merged commit 636682c into dotnet:main Apr 17, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 17, 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