Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Move Vector4 to be implemented using HWIntrinsics on x86 #27483

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
34 changes: 23 additions & 11 deletions src/System.Private.CoreLib/shared/System/Numerics/Vector4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
using System.Text;

namespace System.Numerics
Expand All @@ -20,9 +23,13 @@ public partial struct Vector4 : IEquatable<Vector4>, IFormattable
/// </summary>
public static Vector4 Zero
{
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (Sse.IsSupported || AdvSimd.IsSupported)
{
return Vector128<float>.Zero.AsVector4();
}
return new Vector4();
}
}
Expand All @@ -31,9 +38,16 @@ public static Vector4 Zero
/// </summary>
public static Vector4 One
{
#if ARM64
[Intrinsic]
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (Sse.IsSupported)
{
return Vector128.Create(1.0f).AsVector4();
}
return new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
}
}
Expand All @@ -53,9 +67,9 @@ public static Vector4 One
/// Returns the vector (0,0,0,1).
/// </summary>
public static Vector4 UnitW { get { return new Vector4(0.0f, 0.0f, 0.0f, 1.0f); } }
#endregion Public Static Properties
#endregion Public Static Properties

#region Public instance methods
#region Public instance methods
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
Expand All @@ -73,9 +87,7 @@ public override readonly int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly bool Equals(object? obj)
{
if (!(obj is Vector4))
return false;
return Equals((Vector4)obj);
return (obj is Vector4 other) && Equals(other);
}

/// <summary>
Expand Down Expand Up @@ -159,9 +171,9 @@ public readonly float LengthSquared()
return X * X + Y * Y + Z * Z + W * W;
}
}
#endregion Public Instance Methods
#endregion Public Instance Methods

#region Public Static Methods
#region Public Static Methods
/// <summary>
/// Returns the Euclidean distance between the two given points.
/// </summary>
Expand Down Expand Up @@ -426,9 +438,9 @@ public static Vector4 Transform(Vector4 value, Quaternion rotation)
value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2),
value.W);
}
#endregion Public Static Methods
#endregion Public Static Methods

#region Public operator methods
#region Public operator methods
// All these methods should be inlines as they are implemented
// over JIT intrinsics

Expand Down Expand Up @@ -526,6 +538,6 @@ public static Vector4 Negate(Vector4 value)
{
return -value;
}
#endregion Public operator methods
#endregion Public operator methods
}
}
Loading