Skip to content

Commit 814696c

Browse files
Use a portable Vector3 broadcast reduction
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b72d686 commit 814696c

1 file changed

Lines changed: 2 additions & 13 deletions

File tree

  • src/libraries/System.Private.CoreLib/src/System/Numerics

src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Runtime.CompilerServices;
77
using System.Runtime.InteropServices;
88
using System.Runtime.Intrinsics;
9-
using System.Runtime.Intrinsics.X86;
109

1110
namespace System.Numerics
1211
{
@@ -988,18 +987,8 @@ public static float Sum(Vector3 value)
988987
[MethodImpl(MethodImplOptions.AggressiveInlining)]
989988
internal static Vector3 Sum(Vector128<float> value)
990989
{
991-
// Preserve Z while forming <Y + X, Z, Z, Z>, then add <Z, Y + X, Y + X, Y + X>.
992-
// This broadcasts the sum without an extra addition of zero; NaN payloads can differ by lane.
993-
if (Sse.IsSupported)
994-
{
995-
Vector128<float> pair = Sse.Shuffle(value, value, 0xA9);
996-
pair = Sse.AddScalar(pair, value);
997-
return (pair + Sse.Shuffle(pair, pair, 0x01)).AsVector3();
998-
}
999-
1000-
Vector128<float> sum = Vector128.Shuffle(value, Vector128.Create(1, 2, 2, 2));
1001-
sum = sum.WithElement(0, sum.ToScalar() + value.ToScalar());
1002-
return (sum + Vector128.Shuffle(sum, Vector128.Create(1, 0, 0, 0))).AsVector3();
990+
Vector128<float> sum = Vector128.Shuffle(value, Vector128.Create(1, 0, 3, 2)) + value;
991+
return Vector128.Create((Vector128.Shuffle(value, Vector128.Create(2)) + sum).ToScalar()).AsVector3();
1003992
}
1004993

1005994
/// <summary>Transforms a vector by a specified 4x4 matrix.</summary>

0 commit comments

Comments
 (0)