-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
GenericsTest.Vector128L.cs
79 lines (59 loc) · 2.99 KB
/
GenericsTest.Vector128L.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
// 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<long> GetVector128L(long e00, long e01);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128LOut(long e00, long e01, Vector128<long>* value);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128LOut(long e00, long e01, out Vector128<long> value);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<long>* GetVector128LPtr(long e00, long e01);
[DllImport(nameof(GenericsNative), EntryPoint = "GetVector128LPtr")]
public static extern ref readonly Vector128<long> GetVector128LRef(long e00, long e01);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<long> AddVector128L(Vector128<long> lhs, Vector128<long> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<long> AddVector128Ls(Vector128<long>* pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<long> AddVector128Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128<long>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<long> AddVector128Ls(in Vector128<long> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestVector128L()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128L(1L, 2L));
Vector128<long> value2;
GenericsNative.GetVector128LOut(1L, 2L, &value2);
Assert.Equal(value2.GetElement(0), 1L);
Assert.Equal(value2.GetElement(1), 2L);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128LOut(1L, 2L, out Vector128<long> value3));
Vector128<long>* value4 = GenericsNative.GetVector128LPtr(1L, 2L);
Assert.Equal(value4->GetElement(0), 1L);
Assert.Equal(value4->GetElement(1), 2L);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128LRef(1L, 2L));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128L(default, default));
Vector128<long>[] values = new Vector128<long>[] {
default,
value2,
default,
*value4,
default,
};
Assert.Throws<MarshalDirectiveException>(() => {
fixed (Vector128<long>* pValues = &values[0])
{
GenericsNative.AddVector128Ls(pValues, values.Length);
}
});
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Ls(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Ls(in values[0], values.Length));
}
}