Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change Vector2/3/4, Quaternion, Plane, Vector<T>, and Vector64/128/256/512<T> to be implemented in managed where trivially possible#102301

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tannergooding merged 11 commits intodotnet:mainfromtannergooding:proto-102275
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
603dc39
Change Vector4 to be implemented entirely in managed
tannergoodingMay 16, 2024
c4bef1f
Change Plane to be implemented entirely in managed
tannergoodingMay 16, 2024
10c5dfd
Change Quaternion to be implemented entirely in managed
tannergoodingMay 16, 2024
bcd8926
Avoid accidental recursion on Mono
tannergoodingMay 16, 2024
69b9d08
Change Vector2/3, Vector<T>, and Vector64/128/256/512<T> to be implem…
tannergoodingMay 16, 2024
d93b621
Merge remote-tracking branch 'dotnet/main' into proto-102275
tannergoodingMay 16, 2024
2514560
Don't regress the implementation of Dot
tannergoodingMay 17, 2024
c993845
Merge remote-tracking branch 'dotnet/main' into proto-102275
tannergoodingJun 3, 2024
3eae1a6
Fixing the handling of Vector512.CreateScalar
tannergoodingJun 3, 2024
6c6d71e
Continue tracking the System.Numerics and System.Runtime.Intrinsics A…
tannergoodingJun 3, 2024
4dae1fc
Don't use Unsafe.BitCast on Mono
tannergoodingJun 3, 2024
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
PrevPrevious commit
NextNext commit
Continue tracking the System.Numerics and System.Runtime.Intrinsics A…
…PIs as intrinsic for the profitability boost
  • Loading branch information
@tannergooding
tannergooding committedJun 3, 2024
commit6c6d71ee896e67e7f657c099914b1a5c96ef8e01
19 changes: 19 additions & 0 deletionssrc/coreclr/jit/importercalls.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3089,6 +3089,13 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
}
#endif // FEATURE_HW_INTRINSICS

if ((ni == NI_System_Numerics_Intrinsic) || (ni == NI_System_Runtime_Intrinsics_Intrinsic))
{
// These are special markers used just to ensure we still get the inlining profitability
// boost. We actually have the implementation in managed, however, to keep the JIT simpler.
return nullptr;
}

if (!isIntrinsic)
{
// Outside the cases above, there are many intrinsics which apply to only a
Expand DownExpand Up@@ -10080,6 +10087,12 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)

result = NI_Throw_PlatformNotSupportedException;
}
else
{
// Otherwise mark this as a general intrinsic in the namespace
// so we can still get the inlining profitability boost.
result = NI_System_Runtime_Intrinsics_Intrinsic;
}
}
}
}
Expand DownExpand Up@@ -10304,6 +10317,12 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)

result = NI_Throw_PlatformNotSupportedException;
}
else
{
// Otherwise mark this as a general intrinsic in the namespace
// so we can still get the inlining profitability boost.
result = NI_System_Numerics_Intrinsic;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletionssrc/coreclr/jit/namedintrinsiclist.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,6 +140,10 @@ enum NamedIntrinsic : unsigned short
NI_System_Threading_Interlocked_MemoryBarrier,
NI_System_Threading_Interlocked_ReadMemoryBarrier,

// These two are special marker IDs so that we still get the inlining profitability boost
NI_System_Numerics_Intrinsic,
NI_System_Runtime_Intrinsics_Intrinsic,

#ifdef FEATURE_HW_INTRINSICS
NI_HW_INTRINSIC_START,
#if defined(TARGET_XARCH)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ public struct Plane : IEquatable<Plane>
/// <param name="y">The Y component of the normal.</param>
/// <param name="z">The Z component of the normal.</param>
/// <param name="d">The distance of the plane along its normal from the origin.</param>
[Intrinsic]
public Plane(float x, float y, float z, float d)
{
this = Vector128.Create(x, y, z, d).AsPlane();
Expand All@@ -35,13 +36,15 @@ public Plane(float x, float y, float z, float d)
/// <summary>Creates a <see cref="Plane" /> object from a specified normal and the distance along the normal from the origin.</summary>
/// <param name="normal">The plane's normal vector.</param>
/// <param name="d">The plane's distance from the origin along its normal vector.</param>
[Intrinsic]
public Plane(Vector3 normal, float d)
{
this = new Vector4(normal, d).AsPlane();
}

/// <summary>Creates a <see cref="Plane" /> object from a specified four-dimensional vector.</summary>
/// <param name="value">A vector whose first three elements describe the normal vector, and whose <see cref="Vector4.W" /> defines the distance along that normal from the origin.</param>
[Intrinsic]
public Plane(Vector4 value)
{
this = value.AsPlane();
Expand DownExpand Up@@ -103,6 +106,7 @@ public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 p
/// <param name="plane">The plane.</param>
/// <param name="value">The four-dimensional vector.</param>
/// <returns>The dot product.</returns>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(Plane plane, Vector4 value) => Vector128.Dot(plane.AsVector128(), value.AsVector128());

Expand DownExpand Up@@ -204,6 +208,7 @@ public static Plane Transform(Plane plane, Quaternion rotation)
/// <returns><see langword="true" /> if <paramref name="value1" /> and <paramref name="value2" /> are equal; otherwise, <see langword="false" />.</returns>
/// <remarks>Two <see cref="Plane" /> objects are equal if their <see cref="Normal" /> and <see cref="D" /> fields are equal.
/// The <see cref="op_Equality" /> method defines the operation of the equality operator for <see cref="Plane" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Plane value1, Plane value2) => value1.AsVector128() == value2.AsVector128();

Expand All@@ -212,6 +217,7 @@ public static Plane Transform(Plane plane, Quaternion rotation)
/// <param name="value2">The second plane to compare.</param>
/// <returns><see langword="true" /> if <paramref name="value1" /> and <paramref name="value2" /> are not equal; otherwise, <see langword="false" />.</returns>
/// <remarks>The <see cref="op_Inequality" /> method defines the operation of the inequality operator for <see cref="Plane" /> objects.</remarks>
[Intrinsic]
public static bool operator !=(Plane value1, Plane value2) => !(value1 == value2);

/// <summary>Returns a value that indicates whether this instance and a specified object are equal.</summary>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ public static unsafe partial class Vector
/// <param name="index">The index of the element to get.</param>
/// <returns>The value of the element at <paramref name="index" />.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static float GetElement(this Quaternion quaternion, int index)
{
Expand All@@ -26,6 +27,7 @@ internal static float GetElement(this Quaternion quaternion, int index)
/// <param name="value">The value to set the element to.</param>
/// <returns>A <see cref="Quaternion" /> with the value of the element at <paramref name="index" /> set to <paramref name="value" /> and the remaining elements set to the same value as that in <paramref name="quaternion" />.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
[Intrinsic]
internal static Quaternion WithElement(this Quaternion quaternion, int index, float value)
{
return quaternion.AsVector128().WithElement(index, value).AsQuaternion();
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@ public struct Quaternion : IEquatable<Quaternion>
/// <param name="y">The value to assign to the Y component of the quaternion.</param>
/// <param name="z">The value to assign to the Z component of the quaternion.</param>
/// <param name="w">The value to assign to the W component of the quaternion.</param>
[Intrinsic]
public Quaternion(float x, float y, float z, float w)
{
this = Vector128.Create(x, y, z, w).AsQuaternion();
Expand All@@ -43,25 +44,35 @@ public Quaternion(float x, float y, float z, float w)
/// <summary>Creates a quaternion from the specified vector and rotation parts.</summary>
/// <param name="vectorPart">The vector part of the quaternion.</param>
/// <param name="scalarPart">The rotation part of the quaternion.</param>
[Intrinsic]
public Quaternion(Vector3 vectorPart, float scalarPart)
{
this = new Vector4(vectorPart, scalarPart).AsQuaternion();
}

/// <summary>Gets a quaternion that represents a zero.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 0)</c>.</value>
public static Quaternion Zero => default;
public static Quaternion Zero
{
[Intrinsic]
get => default;
}

/// <summary>Gets a quaternion that represents no rotation.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 1)</c>.</value>
public static Quaternion Identity => new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
public static Quaternion Identity
{
[Intrinsic]
get => new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}

/// <summary>Gets or sets the element at the specified index.</summary>
/// <param name="index">The index of the element to get or set.</param>
/// <returns>The element at <paramref name="index" />.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
public float this[int index]
{
[Intrinsic]
readonly get => this.GetElement(index);

set => this = this.WithElement(index, value);
Expand All@@ -77,6 +88,7 @@ public float this[int index]
/// <param name="value2">The second quaternion.</param>
/// <returns>The quaternion that contains the summed values of <paramref name="value1" /> and <paramref name="value2" />.</returns>
/// <remarks>The <see cref="op_Addition" /> method defines the operation of the addition operator for <see cref="Quaternion" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion operator +(Quaternion value1, Quaternion value2) => (value1.AsVector128() + value2.AsVector128()).AsQuaternion();

Expand DownExpand Up@@ -129,13 +141,15 @@ public float this[int index]
/// <returns><see langword="true" /> if the two quaternions are equal; otherwise, <see langword="false" />.</returns>
/// <remarks>Two quaternions are equal if each of their corresponding components is equal.
/// The <see cref="op_Equality" /> method defines the operation of the equality operator for <see cref="Quaternion" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Quaternion value1, Quaternion value2) => value1.AsVector128() == value2.AsVector128();

/// <summary>Returns a value that indicates whether two quaternions are not equal.</summary>
/// <param name="value1">The first quaternion to compare.</param>
/// <param name="value2">The second quaternion to compare.</param>
/// <returns><see langword="true" /> if <paramref name="value1" /> and <paramref name="value2" /> are not equal; otherwise, <see langword="false" />.</returns>
[Intrinsic]
public static bool operator !=(Quaternion value1, Quaternion value2) => !(value1 == value2);

/// <summary>Returns the quaternion that results from multiplying two quaternions together.</summary>
Expand DownExpand Up@@ -191,6 +205,7 @@ public float this[int index]
/// <param name="value2">The scalar value.</param>
/// <returns>The scaled quaternion.</returns>
/// <remarks>The <see cref="Quaternion.op_Multiply" /> method defines the operation of the multiplication operator for <see cref="Quaternion" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion operator *(Quaternion value1, float value2) => (value1.AsVector128() * value2).AsQuaternion();

Expand All@@ -199,20 +214,23 @@ public float this[int index]
/// <param name="value2">The second quaternion.</param>
/// <returns>The quaternion containing the values that result from subtracting each element in <paramref name="value2" /> from its corresponding element in <paramref name="value1" />.</returns>
/// <remarks>The <see cref="op_Subtraction" /> method defines the operation of the subtraction operator for <see cref="Quaternion" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion operator -(Quaternion value1, Quaternion value2) => (value1.AsVector128() - value2.AsVector128()).AsQuaternion();

/// <summary>Reverses the sign of each component of the quaternion.</summary>
/// <param name="value">The quaternion to negate.</param>
/// <returns>The negated quaternion.</returns>
/// <remarks>The <see cref="op_UnaryNegation" /> method defines the operation of the unary negation operator for <see cref="Quaternion" /> objects.</remarks>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion operator -(Quaternion value) => (-value.AsVector128()).AsQuaternion();

/// <summary>Adds each element in one quaternion with its corresponding element in a second quaternion.</summary>
/// <param name="value1">The first quaternion.</param>
/// <param name="value2">The second quaternion.</param>
/// <returns>The quaternion that contains the summed values of <paramref name="value1" /> and <paramref name="value2" />.</returns>
[Intrinsic]
public static Quaternion Add(Quaternion value1, Quaternion value2) => value1 + value2;

/// <summary>Concatenates two quaternions.</summary>
Expand DownExpand Up@@ -253,6 +271,7 @@ public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
/// <summary>Returns the conjugate of a specified quaternion.</summary>
/// <param name="value">The quaternion.</param>
/// <returns>A new quaternion that is the conjugate of <see langword="value" />.</returns>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion Conjugate(Quaternion value) => (value.AsVector128() * Vector128.Create(-1.0f, -1.0f, -1.0f, 1.0f)).AsQuaternion();

Expand DownExpand Up@@ -372,12 +391,14 @@ public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float ro
/// <param name="quaternion1">The first quaternion.</param>
/// <param name="quaternion2">The second quaternion.</param>
/// <returns>The dot product.</returns>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(Quaternion quaternion1, Quaternion quaternion2) => Vector128.Dot(quaternion1.AsVector128(), quaternion2.AsVector128());

/// <summary>Returns the inverse of a quaternion.</summary>
/// <param name="value">The quaternion.</param>
/// <returns>The inverted quaternion.</returns>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion Inverse(Quaternion value)
{
Expand DownExpand Up@@ -440,16 +461,19 @@ public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, fl
/// <param name="value1">The source quaternion.</param>
/// <param name="value2">The scalar value.</param>
/// <returns>The scaled quaternion.</returns>
[Intrinsic]
public static Quaternion Multiply(Quaternion value1, float value2) => value1 * value2;

/// <summary>Reverses the sign of each component of the quaternion.</summary>
/// <param name="value">The quaternion to negate.</param>
/// <returns>The negated quaternion.</returns>
[Intrinsic]
public static Quaternion Negate(Quaternion value) => -value;

/// <summary>Divides each component of a specified <see cref="Quaternion" /> by its length.</summary>
/// <param name="value">The quaternion to normalize.</param>
/// <returns>The normalized quaternion.</returns>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion Normalize(Quaternion value) => (value.AsVector128() / value.Length()).AsQuaternion();

Expand DownExpand Up@@ -506,6 +530,7 @@ public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, f
/// <param name="value1">The first quaternion.</param>
/// <param name="value2">The second quaternion.</param>
/// <returns>The quaternion containing the values that result from subtracting each element in <paramref name="value2" /> from its corresponding element in <paramref name="value1" />.</returns>
[Intrinsic]
public static Quaternion Subtract(Quaternion value1, Quaternion value2) => value1 - value2;

/// <summary>Returns a value that indicates whether this instance and a specified object are equal.</summary>
Expand All@@ -527,10 +552,12 @@ public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, f

/// <summary>Calculates the length of the quaternion.</summary>
/// <returns>The computed length of the quaternion.</returns>
[Intrinsic]
public readonly float Length() => MathF.Sqrt(LengthSquared());

/// <summary>Calculates the squared length of the quaternion.</summary>
/// <returns>The length squared of the quaternion.</returns>
[Intrinsic]
public readonly float LengthSquared() => Dot(this, this);

/// <summary>Returns a string that represents this quaternion.</summary>
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp