Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/mono/sample/wasm/browser-bench/Vector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.Intrinsics;

namespace Sample
Expand Down Expand Up @@ -28,6 +29,7 @@ public VectorTask()
new MaxFloat(),
new MinDouble(),
new MaxDouble(),
new Normalize(),
};
}

Expand Down Expand Up @@ -301,5 +303,25 @@ public override void RunStep() {
result = Vector128.Max(vector1, vector2);
}
}

class Normalize : VectorMeasurement
{
Vector128<float> result;
float x, y, z, w;
public override string Name => "Normalize float";

public Normalize()
{
x = Random.Shared.NextSingle();
y = Random.Shared.NextSingle();
z = Random.Shared.NextSingle();
w = Random.Shared.NextSingle();
}

public override void RunStep() {
Vector128<float> vector = Vector128.Create(x, y, z, w);
result = vector / (float)Math.Sqrt(Vector128.Dot(vector, vector));
}
}
}
}