-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
GenericsTest.Vector64L.cs
77 lines (57 loc) · 2.78 KB
/
GenericsTest.Vector64L.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
// 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 Vector64<long> GetVector64L(long e00);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector64LOut(long e00, Vector64<long>* value);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector64LOut(long e00, out Vector64<long> value);
[DllImport(nameof(GenericsNative))]
public static extern Vector64<long>* GetVector64LPtr(long e00);
[DllImport(nameof(GenericsNative), EntryPoint = "GetVector64LPtr")]
public static extern ref readonly Vector64<long> GetVector64LRef(long e00);
[DllImport(nameof(GenericsNative))]
public static extern Vector64<long> AddVector64L(Vector64<long> lhs, Vector64<long> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Vector64<long> AddVector64Ls(Vector64<long>* pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector64<long> AddVector64Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64<long>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector64<long> AddVector64Ls(in Vector64<long> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestVector64L()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector64L(1L));
Vector64<long> value2;
GenericsNative.GetVector64LOut(1L, &value2);
Assert.Equal(value2.GetElement(0), 1L);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector64LOut(1L, out Vector64<long> value3));
Vector64<long>* value4 = GenericsNative.GetVector64LPtr(1L);
Assert.Equal(value4->GetElement(0), 1L);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector64LRef(1L));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector64L(default, default));
Vector64<long>[] values = new Vector64<long>[] {
default,
value2,
default,
*value4,
default,
};
Assert.Throws<MarshalDirectiveException>(() => {
fixed (Vector64<long>* pValues = &values[0])
{
GenericsNative.AddVector64Ls(pValues, values.Length);
}
});
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector64Ls(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector64Ls(in values[0], values.Length));
}
}