Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] PackedSimd, add floating point methods #85705

Merged
merged 2 commits into from
May 5, 2023

Conversation

radekdoulik
Copy link
Member

No description provided.

@dotnet-issue-labeler dotnet-issue-labeler bot added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners new-api-needs-documentation labels May 3, 2023
@ghost ghost assigned radekdoulik May 3, 2023
@dotnet-issue-labeler
Copy link

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.

@radekdoulik radekdoulik requested a review from lewing May 3, 2023 12:23
@radekdoulik radekdoulik added area-Codegen-AOT-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 3, 2023
@radekdoulik radekdoulik added this to the 8.0.0 milestone May 3, 2023
@radekdoulik
Copy link
Member Author

Test code:

static void TestFP()
{
    Vector128<float> v1float = Vector128.Create(RandomFloat, RandomFloat, RandomFloat, RandomFloat);
    Vector128<float> v2float = Vector128.Create(RandomFloat, RandomFloat, RandomFloat, RandomFloat);
    Vector128<double> v1double = Vector128.Create(RandomDouble, RandomDouble);
    Vector128<double> v2double = Vector128.Create(RandomDouble, RandomDouble);

    Console.WriteLine($"v1float: {v1float}");
    Console.WriteLine($"v2float: {v2float}");
    Console.WriteLine($"v1double: {v1double}");
    Console.WriteLine($"v2double: {v2double}");
    Console.WriteLine($"negate: {PackedSimd.Negate(v1float)}");
    Console.WriteLine($"negate: {PackedSimd.Negate(v1double)}");
    Console.WriteLine($"abs: {PackedSimd.Abs(v1float)}");
    Console.WriteLine($"abs: {PackedSimd.Abs(v1double)}");
    Console.WriteLine($"min: {PackedSimd.Min(v1float, v2float)}");
    Console.WriteLine($"min: {PackedSimd.Min(v1double, v2double)}");
    Console.WriteLine($"max: {PackedSimd.Max(v1float, v2float)}");
    Console.WriteLine($"max: {PackedSimd.Max(v1double, v2double)}");
    Console.WriteLine($"add: {PackedSimd.Add(v1float, v2float)}");
    Console.WriteLine($"add: {PackedSimd.Add(v1double, v2double)}");
    Console.WriteLine($"sub: {PackedSimd.Subtract(v1float, v2float)}");
    Console.WriteLine($"sub: {PackedSimd.Subtract(v1double, v2double)}");
    Console.WriteLine($"mul: {PackedSimd.Multiply(v1float, v2float)}");
    Console.WriteLine($"mul: {PackedSimd.Multiply(v1double, v2double)}");
    Console.WriteLine($"div: {PackedSimd.Divide(v1float, v2float)}");
    Console.WriteLine($"div: {PackedSimd.Divide(v1double, v2double)}");
    Console.WriteLine($"sqrt: {PackedSimd.Sqrt(v1float)}");
    Console.WriteLine($"sqrt: {PackedSimd.Sqrt(v1double)}");
    Console.WriteLine($"ceil: {PackedSimd.Ceiling(v1float)}");
    Console.WriteLine($"ceil: {PackedSimd.Ceiling(v1double)}");
    Console.WriteLine($"floor: {PackedSimd.Floor(v1float)}");
    Console.WriteLine($"floor: {PackedSimd.Floor(v1double)}");
    Console.WriteLine($"trunc: {PackedSimd.Truncate(v1float)}");
    Console.WriteLine($"trunc: {PackedSimd.Truncate(v1double)}");
    Console.WriteLine($"round: {PackedSimd.RoundToNearest(v1float)}");
    Console.WriteLine($"round: {PackedSimd.RoundToNearest(v1double)}");
}

output:

v1float: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, -6.6816656E+18>
v2float: <-7.5672293E+18, 1.2927375E+19, 1.180264E+19, -2.5176463E+18>
v1double: <-2.4079328523591848E+153, -1.0804325987423793E+154>
v2double: <8.28885808901554E+153, -1.0020291421904291E+154>
negate: <-1.1949302E+19, -1.6613655E+19, -1.5782416E+17, 6.6816656E+18>
negate: <2.4079328523591848E+153, 1.0804325987423793E+154>
abs: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, 6.6816656E+18>
abs: <2.4079328523591848E+153, 1.0804325987423793E+154>
min: <1.1949302E+19, 1.6613655E+19, 1.180264E+19, -2.5176463E+18>
min: <8.28885808901554E+153, -1.0020291421904291E+154>
max: <-7.5672293E+18, 1.2927375E+19, 1.5782416E+17, -6.6816656E+18>
max: <-2.4079328523591848E+153, -1.0804325987423793E+154>
add: <4.3820728E+18, 2.954103E+19, 1.1960464E+19, -9.199312E+18>
add: <5.880925236656354E+153, -2.0824617409328084E+154>
sub: <1.9516532E+19, 3.6862799E+18, -1.1644817E+19, -4.1640193E+18>
sub: <-1.0696790941374725E+154, -7.8403456551950115E+152>
mul: <-9.042311E+37, 2.1477094E+38, 1.8627417E+36, 1.6822071E+37>
mul: <-1.995901370108369E+307, 1.0826249501124025E+308>
div: <-1.5790855, 1.285153, 0.013371936, 2.6539333>
div: <-0.29050236190557976, 1.07824468695647>
sqrt: <3.4567762E+09, 4.0759852E+09, 397270880, NaN>
sqrt: <NaN, NaN>
ceil: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, -6.6816656E+18>
ceil: <-2.4079328523591848E+153, -1.0804325987423793E+154>
floor: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, -6.6816656E+18>
floor: <-2.4079328523591848E+153, -1.0804325987423793E+154>
trunc: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, -6.6816656E+18>
trunc: <-2.4079328523591848E+153, -1.0804325987423793E+154>
round: <1.1949302E+19, 1.6613655E+19, 1.5782416E+17, -6.6816656E+18>
round: <-2.4079328523591848E+153, -1.0804325987423793E+154>

simd instruction in the emitted code:

> wa-info -d -f TestF src/mono/sample/wasm/console-node/bin/Release/AppBundle/dotnet.wasm|grep SIMD|egrep -v 'splat|replace|extract'|egrep 'f32x4|f64x2'
  f32x4.neg    [SIMD]
  f64x2.neg    [SIMD]
  f32x4.abs    [SIMD]
  f64x2.abs    [SIMD]
  f32x4.pmax    [SIMD]
  f64x2.pmax    [SIMD]
  f32x4.pmin    [SIMD]
  f64x2.pmin    [SIMD]
  f32x4.add    [SIMD]
  f64x2.add    [SIMD]
  f32x4.sub    [SIMD]
  f64x2.sub    [SIMD]
  f32x4.mul    [SIMD]
  f64x2.mul    [SIMD]
  f32x4.div    [SIMD]
  f64x2.div    [SIMD]
  f32x4.sqrt    [SIMD]
  f64x2.sqrt    [SIMD]
  f32x4.ceil    [SIMD]
  f64x2.ceil    [SIMD]
  f32x4.floor    [SIMD]
  f64x2.floor    [SIMD]
  f32x4.trunc    [SIMD]
  f64x2.trunc    [SIMD]
  f32x4.nearest    [SIMD]
f64x2.nearest    [SIMD]

@radekdoulik
Copy link
Member Author

This looks related (https://helixre107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-85705-merge-2fe9b89552554f0585/Workloads-Wasm.Build.Tests.NativeBuildTests/1/console.f67d7589.log?helixlogtype=result):

             [qlz532ha.vpm] /root/helix/work/workitem/e/dotnet-latest/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/8.0.0-ci/Sdk/WasmApp.Native.targets(650,5): error : Precompiling failed for /root/helix/work/workitem/e/wbt/qlz532ha.vpm/obj/Release/net8.0/browser-wasm/wasm/for-publish/aot-in/System.Private.CoreLib.dll with exit code 134. [/root/helix/work/workitem/e/wbt/qlz532ha.vpm/mono_aot_cross_Release_True.csproj]
             [qlz532ha.vpm] /root/helix/work/workitem/e/dotnet-latest/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/8.0.0-ci/Sdk/WasmApp.Native.targets(650,5): error : Mono Ahead of Time compiler - compiling assembly /root/helix/work/workitem/e/wbt/qlz532ha.vpm/obj/Release/net8.0/browser-wasm/wasm/for-publish/aot-in/System.Private.CoreLib.dll [/root/helix/work/workitem/e/wbt/qlz532ha.vpm/mono_aot_cross_Release_True.csproj]
             [qlz532ha.vpm] /root/helix/work/workitem/e/dotnet-latest/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/8.0.0-ci/Sdk/WasmApp.Native.targets(650,5): error : * Assertion at /__w/1/s/src/mono/mono/mini/mini-llvm.c:13130, condition `res' not met [/root/helix/work/workitem/e/wbt/qlz532ha.vpm/mono_aot_cross_Release_True.csproj]

@radekdoulik
Copy link
Member Author

the github sync got stuck, only failing are the WBT builds, which are known

@radekdoulik radekdoulik merged commit c75757d into dotnet:main May 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 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.

2 participants