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

Accelerate Vector128<long>::op_Multiply on x64 #103555

Merged
merged 21 commits into from
Jun 28, 2024
Merged
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
Expand All @@ -7,6 +7,8 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
using System.Text;

namespace System.Runtime.Intrinsics
Expand Down Expand Up @@ -261,6 +263,29 @@ public static Vector128<T> Zero
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector128<T> operator *(Vector128<T> left, Vector128<T> right)
{
// TODO: move this to JIT
if (AdvSimd.Arm64.IsSupported && typeof(T) == typeof(ulong))
{
Vector128<ulong> a = left.AsUInt64();
Vector128<ulong> b = left.AsUInt64();
return AdvSimd.Arm64.UnzipEven(
AdvSimd.MultiplyWideningLower(
a.GetLower().AsUInt32(), b.GetLower().AsUInt32()).AsUInt16(),
AdvSimd.MultiplyWideningUpper(
a.AsUInt32(), b.AsUInt32()).AsUInt16()).AsUInt64().As<ulong, T>();
}
if (Sse41.IsSupported)
{
Vector128<ulong> a = left.AsUInt64();
Vector128<ulong> b = left.AsUInt64();
return Sse2.Add(
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
Sse2.Multiply(a.AsUInt32(), b.AsUInt32()).AsUInt64(),
Sse2.Shuffle(
Ssse3.HorizontalAdd(
Sse41.MultiplyLow(a.AsUInt32(),
Sse2.Shuffle(b.AsUInt32(), 0xB1)).AsInt32(), Vector128<int>.Zero), 0x73).AsUInt64()).As<ulong, T>();
}

return Vector128.Create(
left._lower * right._lower,
left._upper * right._upper
Expand Down
Loading