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
Don't use Unsafe.BitCast on Mono
  • Loading branch information
@tannergooding
tannergooding committedJun 3, 2024
commit4dae1fc6dd06b6ae5e8282a94c0f7d1255f37346
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,11 @@ public static Vector<TTo> As<TFrom, TTo>(this Vector<TFrom> vector)
ThrowHelper.ThrowForUnsupportedNumericsVectorBaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedNumericsVectorBaseType<TTo>();

#if MONO
return Unsafe.As<Vector<TFrom>, Vector<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector<TFrom>, Vector<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see cref="Vector{Byte}" />.</summary>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,14 +12,26 @@ public static unsafe partial class Vector
/// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Plane" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Plane" />.</returns>
[Intrinsic]
internal static Plane AsPlane(this Vector4 value) => Unsafe.BitCast<Vector4, Plane>(value);
internal static Plane AsPlane(this Vector4 value)
{
#if MONO
Copy link
Member

Choose a reason for hiding this comment

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

Is this perf problem or functionality problem?

Either way, it is likely going to be fixed as side-effect of#102988 .

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Possibly a functionality problem that I've not dug into yet. The previous tested commit had seen some failures related to Quaternion/Vector4/Plane and their equality tests, but only on Mono.

My current guess is that there's something subtly incorrect in the Mono handling that breaks for SIMD here and it will need a fix before BitCast can be used, but I'd like to try and ensure CoreCLR is clean without regressions before I do any more in depth Mono changes.

return Unsafe.As<Vector4, Plane>(ref value);
#else
return Unsafe.BitCast<Vector4, Plane>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Quaternion" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Quaternion" />.</returns>
[Intrinsic]
internal static Quaternion AsQuaternion(this Vector4 value) => Unsafe.BitCast<Vector4, Quaternion>(value);
internal static Quaternion AsQuaternion(this Vector4 value)
{
#if MONO
return Unsafe.As<Vector4, Quaternion>(ref value);
#else
return Unsafe.BitCast<Vector4, Quaternion>(value);
#endif
}

/// <summary>Gets the element at the specified index.</summary>
/// <param name="vector">The vector to get the element from.</param>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -101,7 +101,11 @@ public static Vector128<TTo> As<TFrom, TTo>(this Vector128<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector128BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector128BaseType<TTo>();

#if MONO
return Unsafe.As<Vector128<TFrom>, Vector128<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector128<TFrom>, Vector128<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Byte}" />.</summary>
Expand DownExpand Up@@ -164,12 +168,26 @@ public static Vector128<TTo> As<TFrom, TTo>(this Vector128<TFrom> vector)
/// <summary>Reinterprets a <see cref="Vector128{Single}" /> as a new <see cref="Plane" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Plane" />.</returns>
internal static Plane AsPlane(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Plane>(value);
internal static Plane AsPlane(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Plane>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Plane>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector128{Single}" /> as a new <see cref="Quaternion" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Quaternion" />.</returns>
internal static Quaternion AsQuaternion(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Quaternion>(value);
internal static Quaternion AsQuaternion(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Quaternion>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Quaternion>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{SByte}" />.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
Expand DownExpand Up@@ -218,12 +236,28 @@ public static Vector128<TTo> As<TFrom, TTo>(this Vector128<TFrom> vector)
/// <summary>Reinterprets a <see cref="Plane" /> as a new <see cref="Vector128{Single}" />.</summary>
/// <param name="value">The plane to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
internal static Vector128<float> AsVector128(this Plane value) => Unsafe.BitCast<Plane, Vector128<float>>(value);
[Intrinsic]
internal static Vector128<float> AsVector128(this Plane value)
{
#if MONO
return Unsafe.As<Plane, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Plane, Vector128<float>>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Quaternion" /> as a new <see cref="Vector128{Single}" />.</summary>
/// <param name="value">The quaternion to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
internal static Vector128<float> AsVector128(this Quaternion value) => Unsafe.BitCast<Quaternion, Vector128<float>>(value);
[Intrinsic]
internal static Vector128<float> AsVector128(this Quaternion value)
{
#if MONO
return Unsafe.As<Quaternion, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Quaternion, Vector128<float>>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector2" /> as a new <see cref="Vector128{Single}" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
Expand All@@ -241,7 +275,14 @@ public static Vector128<TTo> As<TFrom, TTo>(this Vector128<TFrom> vector)
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
[Intrinsic]
public static Vector128<float> AsVector128(this Vector4 value) => Unsafe.BitCast<Vector4, Vector128<float>>(value);
public static Vector128<float> AsVector128(this Vector4 value)
{
#if MONO
return Unsafe.As<Vector4, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Vector4, Vector128<float>>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see cref="Vector128{T}" />.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
Expand DownExpand Up@@ -285,7 +326,14 @@ public static Vector3 AsVector3(this Vector128<float> value)
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector4" />.</returns>
[Intrinsic]
public static Vector4 AsVector4(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Vector4>(value);
public static Vector4 AsVector4(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Vector4>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Vector4>(value);
#endif
}

/// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector{T}" />.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,11 @@ public static Vector256<TTo> As<TFrom, TTo>(this Vector256<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector256BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector256BaseType<TTo>();

#if MONO
return Unsafe.As<Vector256<TFrom>, Vector256<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector256<TFrom>, Vector256<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Byte}" />.</summary>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,11 @@ public static Vector512<TTo> As<TFrom, TTo>(this Vector512<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector512BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector512BaseType<TTo>();

#if MONO
return Unsafe.As<Vector512<TFrom>, Vector512<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector512<TFrom>, Vector512<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector512{T}" /> as a new <see cref="Vector512{Byte}" />.</summary>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,7 +89,11 @@ public static Vector64<TTo> As<TFrom, TTo>(this Vector64<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector64BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector64BaseType<TTo>();

#if MONO
return Unsafe.As<Vector64<TFrom>, Vector64<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector64<TFrom>, Vector64<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Byte}" />.</summary>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp