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

Commit

Permalink
Moving CreateScalarUnsafe, ToScalar, Vector128.ToVector256Unsafe, and…
Browse files Browse the repository at this point in the history
… Vector256.GetLower to be intrinsics (#21351)

* Moving CreateScalarUnsafe, ToScalar, Vector128.ToVector256Unsafe, and Vector256.GetLower to be intrinsics

* Adding containment support to the helper intrinsics
  • Loading branch information
tannergooding authored Dec 7, 2018
1 parent 61da68e commit 1c18b32
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;

namespace System.Runtime.Intrinsics
Expand Down Expand Up @@ -707,6 +708,7 @@ public static unsafe Vector128<ulong> CreateScalar(ulong value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<byte> CreateScalarUnsafe(byte value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -720,6 +722,7 @@ public static unsafe Vector128<byte> CreateScalarUnsafe(byte value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<double> CreateScalarUnsafe(double value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -733,6 +736,7 @@ public static unsafe Vector128<double> CreateScalarUnsafe(double value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<short> CreateScalarUnsafe(short value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -746,6 +750,7 @@ public static unsafe Vector128<short> CreateScalarUnsafe(short value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<int> CreateScalarUnsafe(int value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -759,6 +764,7 @@ public static unsafe Vector128<int> CreateScalarUnsafe(int value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<long> CreateScalarUnsafe(long value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -772,6 +778,7 @@ public static unsafe Vector128<long> CreateScalarUnsafe(long value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector128<sbyte> CreateScalarUnsafe(sbyte value)
{
Expand All @@ -786,6 +793,7 @@ public static unsafe Vector128<sbyte> CreateScalarUnsafe(sbyte value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector128<float> CreateScalarUnsafe(float value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -799,6 +807,7 @@ public static unsafe Vector128<float> CreateScalarUnsafe(float value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector128<ushort> CreateScalarUnsafe(ushort value)
{
Expand All @@ -813,6 +822,7 @@ public static unsafe Vector128<ushort> CreateScalarUnsafe(ushort value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector128<uint> CreateScalarUnsafe(uint value)
{
Expand All @@ -827,6 +837,7 @@ public static unsafe Vector128<uint> CreateScalarUnsafe(uint value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector128{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector128<ulong> CreateScalarUnsafe(ulong value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public Vector128<T> WithUpper(Vector64<T> value)
/// <summary>Converts the current instance to a scalar containing the value of the first element.</summary>
/// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
[Intrinsic]
public T ToScalar()
{
ThrowIfUnsupportedType();
Expand Down Expand Up @@ -356,6 +357,7 @@ public string ToString(string format, IFormatProvider formatProvider)
/// <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>
/// <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>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
[Intrinsic]
public Vector256<T> ToVector256()
{
ThrowIfUnsupportedType();
Expand All @@ -369,6 +371,7 @@ public Vector256<T> ToVector256()
/// <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>
/// <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>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
[Intrinsic]
public unsafe Vector256<T> ToVector256Unsafe()
{
ThrowIfUnsupportedType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;

namespace System.Runtime.Intrinsics
Expand Down Expand Up @@ -905,6 +906,7 @@ public static unsafe Vector256<ulong> CreateScalar(ulong value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<byte> CreateScalarUnsafe(byte value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -918,6 +920,7 @@ public static unsafe Vector256<byte> CreateScalarUnsafe(byte value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<double> CreateScalarUnsafe(double value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -931,6 +934,7 @@ public static unsafe Vector256<double> CreateScalarUnsafe(double value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<short> CreateScalarUnsafe(short value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -944,6 +948,7 @@ public static unsafe Vector256<short> CreateScalarUnsafe(short value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<int> CreateScalarUnsafe(int value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -957,6 +962,7 @@ public static unsafe Vector256<int> CreateScalarUnsafe(int value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<long> CreateScalarUnsafe(long value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -970,6 +976,7 @@ public static unsafe Vector256<long> CreateScalarUnsafe(long value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector256<sbyte> CreateScalarUnsafe(sbyte value)
{
Expand All @@ -984,6 +991,7 @@ public static unsafe Vector256<sbyte> CreateScalarUnsafe(sbyte value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
public static unsafe Vector256<float> CreateScalarUnsafe(float value)
{
// This relies on us stripping the "init" flag from the ".locals"
Expand All @@ -997,6 +1005,7 @@ public static unsafe Vector256<float> CreateScalarUnsafe(float value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector256<ushort> CreateScalarUnsafe(ushort value)
{
Expand All @@ -1011,6 +1020,7 @@ public static unsafe Vector256<ushort> CreateScalarUnsafe(ushort value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector256<uint> CreateScalarUnsafe(uint value)
{
Expand All @@ -1025,6 +1035,7 @@ public static unsafe Vector256<uint> CreateScalarUnsafe(uint value)
/// <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>
/// <param name="value">The value that element 0 will be initialized to.</param>
/// <returns>A new <see cref="Vector256{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
[Intrinsic]
[CLSCompliant(false)]
public static unsafe Vector256<ulong> CreateScalarUnsafe(ulong value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public override int GetHashCode()
/// <summary>Gets the value of the lower 128-bits as a new <see cref="Vector128{T}" />.</summary>
/// <returns>The value of the lower 128-bits as a new <see cref="Vector128{T}" />.</returns>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
[Intrinsic]
public Vector128<T> GetLower()
{
ThrowIfUnsupportedType();
Expand Down Expand Up @@ -305,6 +306,7 @@ public Vector256<T> WithUpper(Vector128<T> value)
/// <summary>Converts the current instance to a scalar containing the value of the first element.</summary>
/// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
[Intrinsic]
public T ToScalar()
{
ThrowIfUnsupportedType();
Expand Down
5 changes: 4 additions & 1 deletion src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,10 @@ class Compiler
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);

#ifdef FEATURE_HW_INTRINSICS
GenTree* impBaseIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* sig);
GenTree* impBaseIntrinsic(NamedIntrinsic intrinsic,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig);
GenTree* impHWIntrinsic(NamedIntrinsic intrinsic,
CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
Expand Down
Loading

0 comments on commit 1c18b32

Please sign in to comment.