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

Commit 3e619d7

Browse files
Merge pull request #15897 from tannergooding/hwintrin-debuggerdisplay
Adding a DebugView for Vector64<T>, Vector128<T>, and Vector256<T>
2 parents abe3c46 + 9133e9d commit 3e619d7

File tree

7 files changed

+454
-3
lines changed

7 files changed

+454
-3
lines changed

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@
253253
</ItemGroup>
254254
<ItemGroup>
255255
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector64.cs" />
256+
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector64DebugView.cs" />
256257
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector128.cs" />
258+
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector128DebugView.cs" />
257259
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector256.cs" />
260+
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\Vector256DebugView.cs" />
258261
</ItemGroup>
259262
<ItemGroup>
260263
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\X86\Enums.cs" />

src/mscorlib/src/System/Runtime/Intrinsics/Vector128.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@
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.Diagnostics;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
8+
using Internal.Runtime.CompilerServices;
79

810
namespace System.Runtime.Intrinsics
911
{
1012
[Intrinsic]
13+
[DebuggerDisplay("{DisplayString,nq}")]
14+
[DebuggerTypeProxy(typeof(Vector128DebugView<>))]
1115
[StructLayout(LayoutKind.Sequential, Size = 16)]
12-
public struct Vector128<T> where T : struct {}
16+
public struct Vector128<T> where T : struct
17+
{
18+
// These fields exist to ensure the alignment is 8, rather than 1.
19+
// This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
20+
private ulong _00;
21+
private ulong _01;
22+
23+
private unsafe string DisplayString
24+
{
25+
get
26+
{
27+
// The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr`
28+
// which are not actually supported by any current architecture. This shouldn't be
29+
// an issue however and greatly simplifies the check
30+
31+
if (typeof(T).IsPrimitive)
32+
{
33+
var items = new T[16 / Unsafe.SizeOf<T>()];
34+
Unsafe.WriteUnaligned(ref Unsafe.As<T, byte>(ref items[0]), this);
35+
return $"({string.Join(", ", items)})";
36+
}
37+
else
38+
{
39+
return SR.NotSupported_Type;
40+
}
41+
}
42+
}
43+
}
1344
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Internal.Runtime.CompilerServices;
6+
7+
namespace System.Runtime.Intrinsics
8+
{
9+
internal struct Vector128DebugView<T> where T : struct
10+
{
11+
private Vector128<T> _value;
12+
13+
public Vector128DebugView(Vector128<T> value)
14+
{
15+
_value = value;
16+
}
17+
18+
public byte[] ByteView
19+
{
20+
get
21+
{
22+
var items = new byte[16];
23+
Unsafe.WriteUnaligned(ref items[0], _value);
24+
return items;
25+
}
26+
}
27+
28+
public double[] DoubleView
29+
{
30+
get
31+
{
32+
var items = new double[2];
33+
Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
34+
return items;
35+
}
36+
}
37+
38+
public short[] Int16View
39+
{
40+
get
41+
{
42+
var items = new short[8];
43+
Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
44+
return items;
45+
}
46+
}
47+
48+
public int[] Int32View
49+
{
50+
get
51+
{
52+
var items = new int[4];
53+
Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
54+
return items;
55+
}
56+
}
57+
58+
public long[] Int64View
59+
{
60+
get
61+
{
62+
var items = new long[2];
63+
Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
64+
return items;
65+
}
66+
}
67+
68+
public sbyte[] SByteView
69+
{
70+
get
71+
{
72+
var items = new sbyte[16];
73+
Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
74+
return items;
75+
}
76+
}
77+
78+
public float[] SingleView
79+
{
80+
get
81+
{
82+
var items = new float[4];
83+
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
84+
return items;
85+
}
86+
}
87+
88+
public ushort[] UInt16View
89+
{
90+
get
91+
{
92+
var items = new ushort[8];
93+
Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
94+
return items;
95+
}
96+
}
97+
98+
public uint[] UInt32View
99+
{
100+
get
101+
{
102+
var items = new uint[4];
103+
Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
104+
return items;
105+
}
106+
}
107+
108+
public ulong[] UInt64View
109+
{
110+
get
111+
{
112+
var items = new ulong[2];
113+
Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
114+
return items;
115+
}
116+
}
117+
}
118+
}

src/mscorlib/src/System/Runtime/Intrinsics/Vector256.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,45 @@
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.Diagnostics;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
8+
using Internal.Runtime.CompilerServices;
79

810
namespace System.Runtime.Intrinsics
911
{
1012
[Intrinsic]
13+
[DebuggerDisplay("{DisplayString,nq}")]
14+
[DebuggerTypeProxy(typeof(Vector256DebugView<>))]
1115
[StructLayout(LayoutKind.Sequential, Size = 32)]
12-
public struct Vector256<T> where T : struct {}
16+
public struct Vector256<T> where T : struct
17+
{
18+
// These fields exist to ensure the alignment is 8, rather than 1.
19+
// This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
20+
private ulong _00;
21+
private ulong _01;
22+
private ulong _02;
23+
private ulong _03;
24+
25+
private unsafe string DisplayString
26+
{
27+
get
28+
{
29+
// The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr`
30+
// which are not actually supported by any current architecture. This shouldn't be
31+
// an issue however and greatly simplifies the check
32+
33+
if (typeof(T).IsPrimitive)
34+
{
35+
var items = new T[32 / Unsafe.SizeOf<T>()];
36+
Unsafe.WriteUnaligned(ref Unsafe.As<T, byte>(ref items[0]), this);
37+
return $"({string.Join(", ", items)})";
38+
}
39+
else
40+
{
41+
return SR.NotSupported_Type;
42+
}
43+
}
44+
}
45+
}
1346
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Internal.Runtime.CompilerServices;
6+
7+
namespace System.Runtime.Intrinsics
8+
{
9+
internal struct Vector256DebugView<T> where T : struct
10+
{
11+
private Vector256<T> _value;
12+
13+
public Vector256DebugView(Vector256<T> value)
14+
{
15+
_value = value;
16+
}
17+
18+
public byte[] ByteView
19+
{
20+
get
21+
{
22+
var items = new byte[32];
23+
Unsafe.WriteUnaligned(ref items[0], _value);
24+
return items;
25+
}
26+
}
27+
28+
public double[] DoubleView
29+
{
30+
get
31+
{
32+
var items = new double[4];
33+
Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
34+
return items;
35+
}
36+
}
37+
38+
public short[] Int16View
39+
{
40+
get
41+
{
42+
var items = new short[16];
43+
Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
44+
return items;
45+
}
46+
}
47+
48+
public int[] Int32View
49+
{
50+
get
51+
{
52+
var items = new int[8];
53+
Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
54+
return items;
55+
}
56+
}
57+
58+
public long[] Int64View
59+
{
60+
get
61+
{
62+
var items = new long[4];
63+
Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
64+
return items;
65+
}
66+
}
67+
68+
public sbyte[] SByteView
69+
{
70+
get
71+
{
72+
var items = new sbyte[32];
73+
Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
74+
return items;
75+
}
76+
}
77+
78+
public float[] SingleView
79+
{
80+
get
81+
{
82+
var items = new float[8];
83+
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
84+
return items;
85+
}
86+
}
87+
88+
public ushort[] UInt16View
89+
{
90+
get
91+
{
92+
var items = new ushort[16];
93+
Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
94+
return items;
95+
}
96+
}
97+
98+
public uint[] UInt32View
99+
{
100+
get
101+
{
102+
var items = new uint[8];
103+
Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
104+
return items;
105+
}
106+
}
107+
108+
public ulong[] UInt64View
109+
{
110+
get
111+
{
112+
var items = new ulong[4];
113+
Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
114+
return items;
115+
}
116+
}
117+
}
118+
}

src/mscorlib/src/System/Runtime/Intrinsics/Vector64.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
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.Diagnostics;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
8+
using Internal.Runtime.CompilerServices;
79

810
namespace System.Runtime.Intrinsics
911
{
1012
[Intrinsic]
13+
[DebuggerDisplay("{DisplayString,nq}")]
14+
[DebuggerTypeProxy(typeof(Vector64DebugView<>))]
1115
[StructLayout(LayoutKind.Sequential, Size = 8)]
12-
public struct Vector64<T> where T : struct {}
16+
public struct Vector64<T> where T : struct
17+
{
18+
// These fields exist to ensure the alignment is 8, rather than 1.
19+
// This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
20+
private ulong _00;
21+
22+
private unsafe string DisplayString
23+
{
24+
get
25+
{
26+
// The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr`
27+
// which are not actually supported by any current architecture. This shouldn't be
28+
// an issue however and greatly simplifies the check
29+
30+
if (typeof(T).IsPrimitive)
31+
{
32+
var items = new T[8 / Unsafe.SizeOf<T>()];
33+
Unsafe.WriteUnaligned(ref Unsafe.As<T, byte>(ref items[0]), this);
34+
return $"({string.Join(", ", items)})";
35+
}
36+
else
37+
{
38+
return SR.NotSupported_Type;
39+
}
40+
}
41+
}
42+
}
1343
}

0 commit comments

Comments
 (0)