-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Rationale
Currently Vector64<T>, Vector128<T> and Vector256<T> in the System.Runtime.Intrinsics namespace are opaque types.
This is great for the hardware intrinsics API, but it provides a very poor experience in the debugger.
As such, I propose that the types be extended with the DebuggerTypeProxy and DebuggerDisplay attributes to provide a better debugging experience.
Additional Thoughts
I propose the DebuggerDisplay attribute should display a string of T elements.
Ex: For Vector128<float>, it would display "{e0, e1, e2, e3}", for Vector128<ushort> it would display "{e0, e1, e2, e3, e4, e5, e6, e7}" (where e# is the value of that given element).
I propose DebuggerTypeProxy should have several properties in the form of public <type>[] <type>View and there should be a property for each supported value of T (i.e. float, double, byte, short, int, long, sbyte, ushort, uint, and ulong).
Ex: Vector128DebugView would have public byte[] ByteView {get;}, public float[] SingleView {get;}, etc...
Notes
In doing a prototype for this proposal, I found that the debugger would always see 0 as the value of the underlying struct. I initially attempted to add serialization support, but that did not resolve the issue.
However, adding private fields to the structs allowed it to work (I'm guessing the debugger is marshalling the type, or something similar).
Ex: I had to change Vector128<T> to the following in order for DebuggerTypeProxy and DebuggerDisplay to work:
[Intrinsic]
[StructLayout(LayoutKind.Sequential, Size = 16)]
[DebuggerTypeProxy(typeof(Vector128DebugView<>))]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct Vector128<T> where T : struct
{
// These fields exist purely so debug view works
private ulong _lower;
private ulong _upper;
}