From 9133e9dc3336a2a4cbd56c0f5d9e223cffa5d342 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 9 Jan 2018 17:02:55 -0800 Subject: [PATCH] Adding a DebugView for Vector64, Vector128, and Vector256 --- src/mscorlib/System.Private.CoreLib.csproj | 3 + .../src/System/Runtime/Intrinsics/Vector128.cs | 33 +++++- .../Runtime/Intrinsics/Vector128DebugView.cs | 118 +++++++++++++++++++++ .../src/System/Runtime/Intrinsics/Vector256.cs | 35 +++++- .../Runtime/Intrinsics/Vector256DebugView.cs | 118 +++++++++++++++++++++ .../src/System/Runtime/Intrinsics/Vector64.cs | 32 +++++- .../System/Runtime/Intrinsics/Vector64DebugView.cs | 118 +++++++++++++++++++++ 7 files changed, 454 insertions(+), 3 deletions(-) create mode 100644 src/mscorlib/src/System/Runtime/Intrinsics/Vector128DebugView.cs create mode 100644 src/mscorlib/src/System/Runtime/Intrinsics/Vector256DebugView.cs create mode 100644 src/mscorlib/src/System/Runtime/Intrinsics/Vector64DebugView.cs diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 0ff3659..faeafe3 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -253,8 +253,11 @@ + + + diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector128.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector128.cs index bfc1a2c..f61310e 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/Vector128.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector128.cs @@ -2,12 +2,43 @@ // 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.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Internal.Runtime.CompilerServices; namespace System.Runtime.Intrinsics { [Intrinsic] + [DebuggerDisplay("{DisplayString,nq}")] + [DebuggerTypeProxy(typeof(Vector128DebugView<>))] [StructLayout(LayoutKind.Sequential, Size = 16)] - public struct Vector128 where T : struct {} + public struct Vector128 where T : struct + { + // These fields exist to ensure the alignment is 8, rather than 1. + // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694) + private ulong _00; + private ulong _01; + + private unsafe string DisplayString + { + get + { + // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` + // which are not actually supported by any current architecture. This shouldn't be + // an issue however and greatly simplifies the check + + if (typeof(T).IsPrimitive) + { + var items = new T[16 / Unsafe.SizeOf()]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); + return $"({string.Join(", ", items)})"; + } + else + { + return SR.NotSupported_Type; + } + } + } + } } diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector128DebugView.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector128DebugView.cs new file mode 100644 index 0000000..7119757 --- /dev/null +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector128DebugView.cs @@ -0,0 +1,118 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + internal struct Vector128DebugView where T : struct + { + private Vector128 _value; + + public Vector128DebugView(Vector128 value) + { + _value = value; + } + + public byte[] ByteView + { + get + { + var items = new byte[16]; + Unsafe.WriteUnaligned(ref items[0], _value); + return items; + } + } + + public double[] DoubleView + { + get + { + var items = new double[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public short[] Int16View + { + get + { + var items = new short[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public int[] Int32View + { + get + { + var items = new int[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public long[] Int64View + { + get + { + var items = new long[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public sbyte[] SByteView + { + get + { + var items = new sbyte[16]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public float[] SingleView + { + get + { + var items = new float[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ushort[] UInt16View + { + get + { + var items = new ushort[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public uint[] UInt32View + { + get + { + var items = new uint[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ulong[] UInt64View + { + get + { + var items = new ulong[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + } +} diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector256.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector256.cs index f7015bd..88fd997 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/Vector256.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector256.cs @@ -2,12 +2,45 @@ // 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.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Internal.Runtime.CompilerServices; namespace System.Runtime.Intrinsics { [Intrinsic] + [DebuggerDisplay("{DisplayString,nq}")] + [DebuggerTypeProxy(typeof(Vector256DebugView<>))] [StructLayout(LayoutKind.Sequential, Size = 32)] - public struct Vector256 where T : struct {} + public struct Vector256 where T : struct + { + // These fields exist to ensure the alignment is 8, rather than 1. + // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694) + private ulong _00; + private ulong _01; + private ulong _02; + private ulong _03; + + private unsafe string DisplayString + { + get + { + // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` + // which are not actually supported by any current architecture. This shouldn't be + // an issue however and greatly simplifies the check + + if (typeof(T).IsPrimitive) + { + var items = new T[32 / Unsafe.SizeOf()]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); + return $"({string.Join(", ", items)})"; + } + else + { + return SR.NotSupported_Type; + } + } + } + } } diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector256DebugView.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector256DebugView.cs new file mode 100644 index 0000000..f072776 --- /dev/null +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector256DebugView.cs @@ -0,0 +1,118 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + internal struct Vector256DebugView where T : struct + { + private Vector256 _value; + + public Vector256DebugView(Vector256 value) + { + _value = value; + } + + public byte[] ByteView + { + get + { + var items = new byte[32]; + Unsafe.WriteUnaligned(ref items[0], _value); + return items; + } + } + + public double[] DoubleView + { + get + { + var items = new double[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public short[] Int16View + { + get + { + var items = new short[16]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public int[] Int32View + { + get + { + var items = new int[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public long[] Int64View + { + get + { + var items = new long[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public sbyte[] SByteView + { + get + { + var items = new sbyte[32]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public float[] SingleView + { + get + { + var items = new float[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ushort[] UInt16View + { + get + { + var items = new ushort[16]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public uint[] UInt32View + { + get + { + var items = new uint[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ulong[] UInt64View + { + get + { + var items = new ulong[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + } +} diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector64.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector64.cs index 42664da..776fe20 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/Vector64.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector64.cs @@ -2,12 +2,42 @@ // 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.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Internal.Runtime.CompilerServices; namespace System.Runtime.Intrinsics { [Intrinsic] + [DebuggerDisplay("{DisplayString,nq}")] + [DebuggerTypeProxy(typeof(Vector64DebugView<>))] [StructLayout(LayoutKind.Sequential, Size = 8)] - public struct Vector64 where T : struct {} + public struct Vector64 where T : struct + { + // These fields exist to ensure the alignment is 8, rather than 1. + // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694) + private ulong _00; + + private unsafe string DisplayString + { + get + { + // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` + // which are not actually supported by any current architecture. This shouldn't be + // an issue however and greatly simplifies the check + + if (typeof(T).IsPrimitive) + { + var items = new T[8 / Unsafe.SizeOf()]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); + return $"({string.Join(", ", items)})"; + } + else + { + return SR.NotSupported_Type; + } + } + } + } } diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/Vector64DebugView.cs b/src/mscorlib/src/System/Runtime/Intrinsics/Vector64DebugView.cs new file mode 100644 index 0000000..129832a --- /dev/null +++ b/src/mscorlib/src/System/Runtime/Intrinsics/Vector64DebugView.cs @@ -0,0 +1,118 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + internal struct Vector64DebugView where T : struct + { + private Vector64 _value; + + public Vector64DebugView(Vector64 value) + { + _value = value; + } + + public byte[] ByteView + { + get + { + var items = new byte[8]; + Unsafe.WriteUnaligned(ref items[0], _value); + return items; + } + } + + public double[] DoubleView + { + get + { + var items = new double[1]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public short[] Int16View + { + get + { + var items = new short[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public int[] Int32View + { + get + { + var items = new int[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public long[] Int64View + { + get + { + var items = new long[1]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public sbyte[] SByteView + { + get + { + var items = new sbyte[8]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public float[] SingleView + { + get + { + var items = new float[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ushort[] UInt16View + { + get + { + var items = new ushort[4]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public uint[] UInt32View + { + get + { + var items = new uint[2]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + + public ulong[] UInt64View + { + get + { + var items = new ulong[1]; + Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + return items; + } + } + } +} -- 2.7.4