-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
GenericsTest.Vector128U.cs
83 lines (63 loc) · 3.31 KB
/
GenericsTest.Vector128U.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using Xunit;
unsafe partial class GenericsNative
{
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint> GetVector128U(uint e00, uint e01, uint e02, uint e03);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128UOut(uint e00, uint e01, uint e02, uint e03, Vector128<uint>* value);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128UOut(uint e00, uint e01, uint e02, uint e03, out Vector128<uint> value);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint>* GetVector128UPtr(uint e00, uint e01, uint e02, uint e03);
[DllImport(nameof(GenericsNative), EntryPoint = "GetVector128UPtr")]
public static extern ref readonly Vector128<uint> GetVector128URef(uint e00, uint e01, uint e02, uint e03);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint> AddVector128U(Vector128<uint> lhs, Vector128<uint> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint> AddVector128Us(Vector128<uint>* pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint> AddVector128Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128<uint>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<uint> AddVector128Us(in Vector128<uint> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestVector128U()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128U(1u, 2u, 3u, 4u));
Vector128<uint> value2;
GenericsNative.GetVector128UOut(1u, 2u, 3u, 4u, &value2);
Assert.Equal(value2.GetElement(0), 1u);
Assert.Equal(value2.GetElement(1), 2u);
Assert.Equal(value2.GetElement(2), 3u);
Assert.Equal(value2.GetElement(3), 4u);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128UOut(1u, 2u, 3u, 4u, out Vector128<uint> value3));
Vector128<uint>* value4 = GenericsNative.GetVector128UPtr(1u, 2u, 3u, 4u);
Assert.Equal(value4->GetElement(0), 1u);
Assert.Equal(value4->GetElement(1), 2u);
Assert.Equal(value4->GetElement(2), 3u);
Assert.Equal(value4->GetElement(3), 4u);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128URef(1u, 2u, 3u, 4u));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128U(default, default));
Vector128<uint>[] values = new Vector128<uint>[] {
default,
value2,
default,
*value4,
default,
};
Assert.Throws<MarshalDirectiveException>(() => {
fixed (Vector128<uint>* pValues = &values[0])
{
GenericsNative.AddVector128Us(pValues, values.Length);
}
});
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Us(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Us(in values[0], values.Length));
}
}