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

Optimize XxHash3 on ARM platform #77881

Merged
merged 3 commits into from
Nov 5, 2022
Merged
Changes from 1 commit
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
Next Next commit
Optimize XxHash3 on ARM platform
  • Loading branch information
xoofx committed Nov 4, 2022
commit 0f60e44e161bea1b8a89b9c00b1622d9501b909d
20 changes: 16 additions & 4 deletions src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,12 +896,24 @@ private static Vector128<ulong> Accumulate128(Vector128<ulong> accVec, byte* sou
Vector128<uint> sourceKey = sourceVec ^ secret;

// TODO: Figure out how to unwind this shuffle and just use Vector128.Multiply
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still relevant, or does it now refer to code in MultiplyWideningLower?

Vector128<uint> sourceKeyLow = Vector128.Shuffle(sourceKey, Vector128.Create(1u, 0, 3, 0));
Vector128<uint> sourceSwap = Vector128.Shuffle(sourceVec, Vector128.Create(2u, 3, 0, 1));
Vector128<ulong> sum = accVec + sourceSwap.AsUInt64();
Vector128<ulong> product = Sse2.IsSupported ?
Sse2.Multiply(sourceKey, sourceKeyLow) :
(sourceKey & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64() * (sourceKeyLow & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64();

Vector128<ulong> product;
// TODO: Workaround for ARM as `*` is software emulated.
xoofx marked this conversation as resolved.
Show resolved Hide resolved
if (System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported)
xoofx marked this conversation as resolved.
Show resolved Hide resolved
{
Vector64<uint> sourceKeyLow = Vector128.Shuffle(sourceKey, Vector128.Create(0u, 2, 0, 0)).GetLower();
Vector64<uint> sourceKeyHigh = Vector128.Shuffle(sourceKey, Vector128.Create(1u, 3, 0, 0)).GetLower();
product = System.Runtime.Intrinsics.Arm.AdvSimd.MultiplyWideningLower(sourceKeyLow, sourceKeyHigh);
}
else
{
Vector128<uint> sourceKeyLow = Vector128.Shuffle(sourceKey, Vector128.Create(1u, 0, 3, 0));
product = Sse2.IsSupported
? Sse2.Multiply(sourceKey, sourceKeyLow)
xoofx marked this conversation as resolved.
Show resolved Hide resolved
: (sourceKey & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64() * (sourceKeyLow & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64();
}

accVec = product + sum;
return accVec;
Expand Down