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

Commit 1c18b32

Browse files
Moving CreateScalarUnsafe, ToScalar, Vector128.ToVector256Unsafe, and Vector256.GetLower to be intrinsics (#21351)
* Moving CreateScalarUnsafe, ToScalar, Vector128.ToVector256Unsafe, and Vector256.GetLower to be intrinsics * Adding containment support to the helper intrinsics
1 parent 61da68e commit 1c18b32

File tree

9 files changed

+349
-25
lines changed

9 files changed

+349
-25
lines changed

src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Runtime.CompilerServices;
56
using Internal.Runtime.CompilerServices;
67

78
namespace System.Runtime.Intrinsics
@@ -707,6 +708,7 @@ public static unsafe Vector128<ulong> CreateScalar(ulong value)
707708
/// <summary>Creates a new <see cref="Vector128{Byte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
708709
/// <param name="value">The value that element 0 will be initialized to.</param>
709710
/// <returns>A new <see cref="Vector128{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
711+
[Intrinsic]
710712
public static unsafe Vector128<byte> CreateScalarUnsafe(byte value)
711713
{
712714
// This relies on us stripping the "init" flag from the ".locals"
@@ -720,6 +722,7 @@ public static unsafe Vector128<byte> CreateScalarUnsafe(byte value)
720722
/// <summary>Creates a new <see cref="Vector128{Double}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
721723
/// <param name="value">The value that element 0 will be initialized to.</param>
722724
/// <returns>A new <see cref="Vector128{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
725+
[Intrinsic]
723726
public static unsafe Vector128<double> CreateScalarUnsafe(double value)
724727
{
725728
// This relies on us stripping the "init" flag from the ".locals"
@@ -733,6 +736,7 @@ public static unsafe Vector128<double> CreateScalarUnsafe(double value)
733736
/// <summary>Creates a new <see cref="Vector128{Int16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
734737
/// <param name="value">The value that element 0 will be initialized to.</param>
735738
/// <returns>A new <see cref="Vector128{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
739+
[Intrinsic]
736740
public static unsafe Vector128<short> CreateScalarUnsafe(short value)
737741
{
738742
// This relies on us stripping the "init" flag from the ".locals"
@@ -746,6 +750,7 @@ public static unsafe Vector128<short> CreateScalarUnsafe(short value)
746750
/// <summary>Creates a new <see cref="Vector128{Int32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
747751
/// <param name="value">The value that element 0 will be initialized to.</param>
748752
/// <returns>A new <see cref="Vector128{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
753+
[Intrinsic]
749754
public static unsafe Vector128<int> CreateScalarUnsafe(int value)
750755
{
751756
// This relies on us stripping the "init" flag from the ".locals"
@@ -759,6 +764,7 @@ public static unsafe Vector128<int> CreateScalarUnsafe(int value)
759764
/// <summary>Creates a new <see cref="Vector128{Int64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
760765
/// <param name="value">The value that element 0 will be initialized to.</param>
761766
/// <returns>A new <see cref="Vector128{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
767+
[Intrinsic]
762768
public static unsafe Vector128<long> CreateScalarUnsafe(long value)
763769
{
764770
// This relies on us stripping the "init" flag from the ".locals"
@@ -772,6 +778,7 @@ public static unsafe Vector128<long> CreateScalarUnsafe(long value)
772778
/// <summary>Creates a new <see cref="Vector128{SByte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
773779
/// <param name="value">The value that element 0 will be initialized to.</param>
774780
/// <returns>A new <see cref="Vector128{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
781+
[Intrinsic]
775782
[CLSCompliant(false)]
776783
public static unsafe Vector128<sbyte> CreateScalarUnsafe(sbyte value)
777784
{
@@ -786,6 +793,7 @@ public static unsafe Vector128<sbyte> CreateScalarUnsafe(sbyte value)
786793
/// <summary>Creates a new <see cref="Vector128{Single}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
787794
/// <param name="value">The value that element 0 will be initialized to.</param>
788795
/// <returns>A new <see cref="Vector128{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
796+
[Intrinsic]
789797
public static unsafe Vector128<float> CreateScalarUnsafe(float value)
790798
{
791799
// This relies on us stripping the "init" flag from the ".locals"
@@ -799,6 +807,7 @@ public static unsafe Vector128<float> CreateScalarUnsafe(float value)
799807
/// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
800808
/// <param name="value">The value that element 0 will be initialized to.</param>
801809
/// <returns>A new <see cref="Vector128{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
810+
[Intrinsic]
802811
[CLSCompliant(false)]
803812
public static unsafe Vector128<ushort> CreateScalarUnsafe(ushort value)
804813
{
@@ -813,6 +822,7 @@ public static unsafe Vector128<ushort> CreateScalarUnsafe(ushort value)
813822
/// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
814823
/// <param name="value">The value that element 0 will be initialized to.</param>
815824
/// <returns>A new <see cref="Vector128{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
825+
[Intrinsic]
816826
[CLSCompliant(false)]
817827
public static unsafe Vector128<uint> CreateScalarUnsafe(uint value)
818828
{
@@ -827,6 +837,7 @@ public static unsafe Vector128<uint> CreateScalarUnsafe(uint value)
827837
/// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
828838
/// <param name="value">The value that element 0 will be initialized to.</param>
829839
/// <returns>A new <see cref="Vector128{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
840+
[Intrinsic]
830841
[CLSCompliant(false)]
831842
public static unsafe Vector128<ulong> CreateScalarUnsafe(ulong value)
832843
{

src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public Vector128<T> WithUpper(Vector64<T> value)
303303
/// <summary>Converts the current instance to a scalar containing the value of the first element.</summary>
304304
/// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
305305
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
306+
[Intrinsic]
306307
public T ToScalar()
307308
{
308309
ThrowIfUnsupportedType();
@@ -356,6 +357,7 @@ public string ToString(string format, IFormatProvider formatProvider)
356357
/// <summary>Converts the current instance to a new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the current instance and the upper 128-bits initialized to zero.</summary>
357358
/// <returns>A new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the current instance and the upper 128-bits initialized to zero.</returns>
358359
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
360+
[Intrinsic]
359361
public Vector256<T> ToVector256()
360362
{
361363
ThrowIfUnsupportedType();
@@ -369,6 +371,7 @@ public Vector256<T> ToVector256()
369371
/// <summary>Converts the current instance to a new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the current instance and the upper 128-bits left uninitialized.</summary>
370372
/// <returns>A new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the current instance and the upper 128-bits left uninitialized.</returns>
371373
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
374+
[Intrinsic]
372375
public unsafe Vector256<T> ToVector256Unsafe()
373376
{
374377
ThrowIfUnsupportedType();

src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Runtime.CompilerServices;
56
using Internal.Runtime.CompilerServices;
67

78
namespace System.Runtime.Intrinsics
@@ -905,6 +906,7 @@ public static unsafe Vector256<ulong> CreateScalar(ulong value)
905906
/// <summary>Creates a new <see cref="Vector256{Byte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
906907
/// <param name="value">The value that element 0 will be initialized to.</param>
907908
/// <returns>A new <see cref="Vector256{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
909+
[Intrinsic]
908910
public static unsafe Vector256<byte> CreateScalarUnsafe(byte value)
909911
{
910912
// This relies on us stripping the "init" flag from the ".locals"
@@ -918,6 +920,7 @@ public static unsafe Vector256<byte> CreateScalarUnsafe(byte value)
918920
/// <summary>Creates a new <see cref="Vector256{Double}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
919921
/// <param name="value">The value that element 0 will be initialized to.</param>
920922
/// <returns>A new <see cref="Vector256{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
923+
[Intrinsic]
921924
public static unsafe Vector256<double> CreateScalarUnsafe(double value)
922925
{
923926
// This relies on us stripping the "init" flag from the ".locals"
@@ -931,6 +934,7 @@ public static unsafe Vector256<double> CreateScalarUnsafe(double value)
931934
/// <summary>Creates a new <see cref="Vector256{Int16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
932935
/// <param name="value">The value that element 0 will be initialized to.</param>
933936
/// <returns>A new <see cref="Vector256{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
937+
[Intrinsic]
934938
public static unsafe Vector256<short> CreateScalarUnsafe(short value)
935939
{
936940
// This relies on us stripping the "init" flag from the ".locals"
@@ -944,6 +948,7 @@ public static unsafe Vector256<short> CreateScalarUnsafe(short value)
944948
/// <summary>Creates a new <see cref="Vector256{Int32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
945949
/// <param name="value">The value that element 0 will be initialized to.</param>
946950
/// <returns>A new <see cref="Vector256{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
951+
[Intrinsic]
947952
public static unsafe Vector256<int> CreateScalarUnsafe(int value)
948953
{
949954
// This relies on us stripping the "init" flag from the ".locals"
@@ -957,6 +962,7 @@ public static unsafe Vector256<int> CreateScalarUnsafe(int value)
957962
/// <summary>Creates a new <see cref="Vector256{Int64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
958963
/// <param name="value">The value that element 0 will be initialized to.</param>
959964
/// <returns>A new <see cref="Vector256{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
965+
[Intrinsic]
960966
public static unsafe Vector256<long> CreateScalarUnsafe(long value)
961967
{
962968
// This relies on us stripping the "init" flag from the ".locals"
@@ -970,6 +976,7 @@ public static unsafe Vector256<long> CreateScalarUnsafe(long value)
970976
/// <summary>Creates a new <see cref="Vector256{SByte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
971977
/// <param name="value">The value that element 0 will be initialized to.</param>
972978
/// <returns>A new <see cref="Vector256{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
979+
[Intrinsic]
973980
[CLSCompliant(false)]
974981
public static unsafe Vector256<sbyte> CreateScalarUnsafe(sbyte value)
975982
{
@@ -984,6 +991,7 @@ public static unsafe Vector256<sbyte> CreateScalarUnsafe(sbyte value)
984991
/// <summary>Creates a new <see cref="Vector256{Single}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
985992
/// <param name="value">The value that element 0 will be initialized to.</param>
986993
/// <returns>A new <see cref="Vector256{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
994+
[Intrinsic]
987995
public static unsafe Vector256<float> CreateScalarUnsafe(float value)
988996
{
989997
// This relies on us stripping the "init" flag from the ".locals"
@@ -997,6 +1005,7 @@ public static unsafe Vector256<float> CreateScalarUnsafe(float value)
9971005
/// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
9981006
/// <param name="value">The value that element 0 will be initialized to.</param>
9991007
/// <returns>A new <see cref="Vector256{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
1008+
[Intrinsic]
10001009
[CLSCompliant(false)]
10011010
public static unsafe Vector256<ushort> CreateScalarUnsafe(ushort value)
10021011
{
@@ -1011,6 +1020,7 @@ public static unsafe Vector256<ushort> CreateScalarUnsafe(ushort value)
10111020
/// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
10121021
/// <param name="value">The value that element 0 will be initialized to.</param>
10131022
/// <returns>A new <see cref="Vector256{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
1023+
[Intrinsic]
10141024
[CLSCompliant(false)]
10151025
public static unsafe Vector256<uint> CreateScalarUnsafe(uint value)
10161026
{
@@ -1025,6 +1035,7 @@ public static unsafe Vector256<uint> CreateScalarUnsafe(uint value)
10251035
/// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
10261036
/// <param name="value">The value that element 0 will be initialized to.</param>
10271037
/// <returns>A new <see cref="Vector256{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
1038+
[Intrinsic]
10281039
[CLSCompliant(false)]
10291040
public static unsafe Vector256<ulong> CreateScalarUnsafe(ulong value)
10301041
{

src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public override int GetHashCode()
254254
/// <summary>Gets the value of the lower 128-bits as a new <see cref="Vector128{T}" />.</summary>
255255
/// <returns>The value of the lower 128-bits as a new <see cref="Vector128{T}" />.</returns>
256256
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
257+
[Intrinsic]
257258
public Vector128<T> GetLower()
258259
{
259260
ThrowIfUnsupportedType();
@@ -305,6 +306,7 @@ public Vector256<T> WithUpper(Vector128<T> value)
305306
/// <summary>Converts the current instance to a scalar containing the value of the first element.</summary>
306307
/// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
307308
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
309+
[Intrinsic]
308310
public T ToScalar()
309311
{
310312
ThrowIfUnsupportedType();

src/jit/compiler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,10 @@ class Compiler
34113411
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);
34123412

34133413
#ifdef FEATURE_HW_INTRINSICS
3414-
GenTree* impBaseIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* sig);
3414+
GenTree* impBaseIntrinsic(NamedIntrinsic intrinsic,
3415+
CORINFO_CLASS_HANDLE clsHnd,
3416+
CORINFO_METHOD_HANDLE method,
3417+
CORINFO_SIG_INFO* sig);
34153418
GenTree* impHWIntrinsic(NamedIntrinsic intrinsic,
34163419
CORINFO_METHOD_HANDLE method,
34173420
CORINFO_SIG_INFO* sig,

0 commit comments

Comments
 (0)