Skip to content

Commit

Permalink
Replace Create(ulong) with CreateScalar(uint) in PopCount (#37912)
Browse files Browse the repository at this point in the history
* Replace Create(ulong) with CreateScalar(uint)
* Add CreateScalar() in shim
  • Loading branch information
kunalspathak authored Jun 16, 2020
1 parent bbb5902 commit 132be64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ public static int PopCount(uint value)
{
// PopCount works on vector so convert input value to vector first.

// Vector64.CreateScalar(uint) generates suboptimal code by storing and
// loading the result to memory.
// See https://github.com/dotnet/runtime/issues/35976 for details.
// Hence use Vector64.Create(ulong) to create Vector64<ulong> and operate on that.
Vector64<ulong> input = Vector64.Create((ulong)value);
Vector64<uint> input = Vector64.CreateScalar(value);
Vector64<byte> aggregated = AdvSimd.Arm64.AddAcross(AdvSimd.PopCount(input.AsByte()));
return aggregated.ToScalar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Runtime.Intrinsics
internal static class Vector64
{
public static Vector64<ulong> Create(ulong value) => throw new PlatformNotSupportedException();
public static Vector64<uint> CreateScalar(uint value) => throw new PlatformNotSupportedException();
public static Vector64<byte> AsByte<T>(this Vector64<T> vector) where T : struct => throw new PlatformNotSupportedException();
}
internal readonly struct Vector64<T>
Expand Down

0 comments on commit 132be64

Please sign in to comment.