-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Move down S.N.Vector APIs and expose new conversion support #27401
Conversation
…tem.Runtime.Intrinsics vectors
@@ -1761,7 +1759,6 @@ public static Matrix4x4 Transform(Matrix4x4 value, Quaternion rotation) | |||
/// <returns>The transposed matrix.</returns> | |||
public static unsafe Matrix4x4 Transpose(Matrix4x4 matrix) | |||
{ | |||
#if HAS_INTRINSICS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only build for platforms where the intrinsics are exposed, so the #ifdefs
aren't needed.
- Noting that they are not necessarily supported everywhere and some platforms, such as mono, will treat
IsSupported
asfalse
(as with other places in shared corelib code).
@@ -11,6 +11,7 @@ namespace System.Numerics | |||
/// <summary> | |||
/// A structure encapsulating two single precision floating point values and provides hardware accelerated methods. | |||
/// </summary> | |||
[Intrinsic] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SIMD Types in S.P.Corelib are recognized by the Intrinsic
attribute
public static Vector128<T> AsVector128<T>(this Vector<T> value) | ||
where T : struct | ||
{ | ||
Debug.Assert(Vector<T>.Count >= Vector128<T>.Count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently assumes that Vector<T>
won't ever be less than 128-bits. This is true
today, but the logic would need to change if we ever supported something less (like on ARM
/ARM64
where Vector64<T>
is the minimum).
public static Vector256<T> AsVector256<T>(this Vector<T> value) | ||
where T : struct | ||
{ | ||
Debug.Assert(Vector256<T>.Count >= Vector<T>.Count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently assumes Vector<T>
is no bigger than Vector256<T>
, the logic would need to change if we supported Vector512
or others...
CC. @CarolEidt, @jkotas |
Does this change affect CoreLib size? I know there's a linker but anyway. |
There is a long standing issue (https://github.com/dotnet/corefx/issues/31425) tracking investigating this. The new |
Do you mean for the R2R scenario? These are basically a drop in the bucket compared to things like the System.Runtime.Intrinsics APIs that are being exposed (where we have 1500+ new APIs). |
@jkotas, I had to revert 9610d38 for the time being and will need to include it when addressing https://github.com/dotnet/coreclr/issues/27402 instead. Since the type forwards don't exist in System.Numerics.Vectors.dll yet (and can't until after this change makes its rounds), the consumed types are still those from System.Numerics.Vectors.dll and they need to resolve to the intrinsic types to avoid various asserts such as:
|
Hmmm, actually it looks like there is something invalid for public static Vector3 AsVector3(this Vector128<float> value)
{
return Unsafe.As<Vector128<float>, Vector3>(ref value);
} I've repushed up 9610d38 and changed the above method to throw PNSE while I try to investigate further... CC. @CarolEidt |
Found a simple repro indpendent of these changes and logged: https://github.com/dotnet/coreclr/issues/27405 |
Had to pull out 9610d38 anyways as there are tests that validate how the System.Numerics types were compiled.
|
This should be ready for merge after sign-off and then I can checkin the other changes after the type forwards flow from CoreFX |
This moves the S.N.Vector2/3/4 and supporting types down to S.P.Corelib. It additionally exposes the new conversion APIs approved in https://github.com/dotnet/corefx/issues/36379 to help reduce the turnaround time between CoreCLR and CoreFX (as S.N.Vector still needs type forwards exposed and the new APIs still need to be listed in the reference assembly after this change flows back).