Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose cross-platform helpers for Vector64, Vector128, and Vector256 #53450

Merged
merged 22 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
df33419
Refactoring Vector<T> to be alphabetically ordered and reduce duplica…
tannergooding May 22, 2021
bcf2bbd
Adding a debug view to System.Numerics.Vector<T>
tannergooding May 22, 2021
7ed4a28
Do some basic code cleanup and refactoring of Vector64/128/256
tannergooding May 22, 2021
b577114
Updating Vector64/128/256 to expose cross platform helper methods
tannergooding May 23, 2021
4cdec92
Adding templated tests for Vector64
tannergooding May 23, 2021
2f9ce11
Regenerating templated tests for Vector64
tannergooding May 23, 2021
4940fcf
Adding templated tests for Vector128
tannergooding May 23, 2021
ac9c477
Regenerating templated tests for Vector128
tannergooding May 23, 2021
557128e
Adding templated tests for Vector256
tannergooding May 23, 2021
81a012e
Regenerating templated tests for Vector256
tannergooding May 23, 2021
3245883
Fix getSIMDStructFromField to account for accessing the private ulong…
tannergooding May 24, 2021
37c521e
Ensure helper intrinsics don't insert on importation
tannergooding May 24, 2021
6cddb02
Minor cleanup of impBaseIntrinsic for x86/x64
tannergooding May 25, 2021
8c28873
Intrinsify the Vector64/128/256 methods
tannergooding May 26, 2021
1b665fc
Make the internal helper named IsTypeSupported to not conflict with m…
tannergooding May 30, 2021
f917ea6
Ensure we lie about the type for TYP_SIMD32 bitwise ops when only AVX…
tannergooding May 31, 2021
10dfe0c
Use gtNewSimdZeroNode rather than gtNewSIMDVectorZero
tannergooding Jun 1, 2021
6d34d27
Applying formatting patch
tannergooding Jun 1, 2021
57ce0a9
Apply suggestions from code review
tannergooding Jun 29, 2021
f2529d7
Apply suggestions from code review
tannergooding Jun 30, 2021
54610f9
Split HardwareIntrinsic tests into 3 groups
tannergooding Jun 30, 2021
fc5c5bc
Update src/coreclr/vm/class.cpp
tannergooding Sep 30, 2021
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
Prev Previous commit
Next Next commit
Adding a debug view to System.Numerics.Vector<T>
  • Loading branch information
tannergooding committed Sep 29, 2021
commit bcf2bbd26f407fad039145b9b933d52ef1e10c22
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector2.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector3.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector4.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\VectorDebugView_1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\VectorMath.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Object.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ObjectDisposedException.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Runtime.CompilerServices;

namespace System.Numerics
{
internal readonly struct VectorDebugView<T>
where T : struct
{
private readonly Vector<T> _value;

public VectorDebugView(Vector<T> value)
{
_value = value;
}

public byte[] ByteView
{
get
{
var items = new byte[Vector<byte>.Count];
Unsafe.WriteUnaligned(ref items[0], _value);
return items;
}
}

public double[] DoubleView
{
get
{
var items = new double[Vector<double>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
return items;
}
}

public short[] Int16View
{
get
{
var items = new short[Vector<short>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
return items;
}
}

public int[] Int32View
{
get
{
var items = new int[Vector<int>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
return items;
}
}

public long[] Int64View
{
get
{
var items = new long[Vector<long>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
return items;
}
}

public nint[] NIntView
{
get
{
var items = new nint[Vector<nint>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<nint, byte>(ref items[0]), _value);
return items;
}
}

public nuint[] NUIntView
{
get
{
var items = new nuint[Vector<nuint>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<nuint, byte>(ref items[0]), _value);
return items;
}
}

public sbyte[] SByteView
{
get
{
var items = new sbyte[Vector<sbyte>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
return items;
}
}

public float[] SingleView
{
get
{
var items = new float[Vector<float>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
return items;
}
}

public ushort[] UInt16View
{
get
{
var items = new ushort[Vector<ushort>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
return items;
}
}

public uint[] UInt32View
{
get
{
var items = new uint[Vector<uint>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
return items;
}
}

public ulong[] UInt64View
{
get
{
var items = new ulong[Vector<ulong>.Count];
Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
return items;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -30,6 +31,8 @@ namespace System.Numerics
/// large algorithms. This type is immutable, individual elements cannot be modified.
/// </summary>
[Intrinsic]
[DebuggerDisplay("{DisplayString,nq}")]
[DebuggerTypeProxy(typeof(VectorDebugView<>))]
public readonly struct Vector<T> : IEquatable<Vector<T>>, IFormattable
where T : struct
{
Expand Down Expand Up @@ -149,6 +152,23 @@ public static int Count
}
}

internal static bool IsSupported
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (typeof(T) == typeof(byte)) ||
(typeof(T) == typeof(double)) ||
(typeof(T) == typeof(short)) ||
(typeof(T) == typeof(int)) ||
(typeof(T) == typeof(long)) ||
(typeof(T) == typeof(nint)) ||
(typeof(T) == typeof(nuint)) ||
(typeof(T) == typeof(sbyte)) ||
(typeof(T) == typeof(float)) ||
(typeof(T) == typeof(ushort)) ||
(typeof(T) == typeof(uint)) ||
(typeof(T) == typeof(ulong));
}

/// <summary>Gets a new <see cref="Vector{T}" /> with all elements initialized to one.</summary>
/// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
public static Vector<T> One
Expand All @@ -169,6 +189,21 @@ public static Vector<T> Zero
}
}

internal unsafe string DisplayString
{
get
{
if (IsSupported)
{
return ToString();
}
else
{
return SR.NotSupported_Type;
}
}
}

/// <summary>Gets the element at the specified index.</summary>
/// <param name="index">The index of the element to get.</param>
/// <returns>The value of the element at <paramref name="index" />.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -600,12 +601,7 @@ internal static void IfNullAndNullsAreIllegalThenThrow<T>(object? value, Excepti
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void ThrowForUnsupportedNumericsVectorBaseType<T>() where T : struct
{
if (typeof(T) != typeof(byte) && typeof(T) != typeof(sbyte) &&
typeof(T) != typeof(short) && typeof(T) != typeof(ushort) &&
typeof(T) != typeof(int) && typeof(T) != typeof(uint) &&
typeof(T) != typeof(long) && typeof(T) != typeof(ulong) &&
typeof(T) != typeof(float) && typeof(T) != typeof(double) &&
typeof(T) != typeof(nint) && typeof(T) != typeof(nuint))
if (!Vector<T>.IsSupported)
{
ThrowNotSupportedException(ExceptionResource.Arg_TypeNotSupported);
}
Expand Down