-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
GenericsTest.Vector128F.cs
83 lines (63 loc) · 3.41 KB
/
GenericsTest.Vector128F.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<float> GetVector128F(float e00, float e01, float e02, float e03);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128FOut(float e00, float e01, float e02, float e03, Vector128<float>* value);
[DllImport(nameof(GenericsNative))]
public static extern void GetVector128FOut(float e00, float e01, float e02, float e03, out Vector128<float> value);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<float>* GetVector128FPtr(float e00, float e01, float e02, float e03);
[DllImport(nameof(GenericsNative), EntryPoint = "GetVector128FPtr")]
public static extern ref readonly Vector128<float> GetVector128FRef(float e00, float e01, float e02, float e03);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<float> AddVector128F(Vector128<float> lhs, Vector128<float> rhs);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<float> AddVector128Fs(Vector128<float>* pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<float> AddVector128Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128<float>[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern Vector128<float> AddVector128Fs(in Vector128<float> pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestVector128F()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128F(1.0f, 2.0f, 3.0f, 4.0f));
Vector128<float> value2;
GenericsNative.GetVector128FOut(1.0f, 2.0f, 3.0f, 4.0f, &value2);
Assert.Equal(value2.GetElement(0), 1.0f);
Assert.Equal(value2.GetElement(1), 2.0f);
Assert.Equal(value2.GetElement(2), 3.0f);
Assert.Equal(value2.GetElement(3), 4.0f);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128FOut(1.0f, 2.0f, 3.0f, 4.0f, out Vector128<float> value3));
Vector128<float>* value4 = GenericsNative.GetVector128FPtr(1.0f, 2.0f, 3.0f, 4.0f);
Assert.Equal(value4->GetElement(0), 1.0f);
Assert.Equal(value4->GetElement(1), 2.0f);
Assert.Equal(value4->GetElement(2), 3.0f);
Assert.Equal(value4->GetElement(3), 4.0f);
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetVector128FRef(1.0f, 2.0f, 3.0f, 4.0f));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128F(default, default));
Vector128<float>[] values = new Vector128<float>[] {
default,
value2,
default,
*value4,
default,
};
Assert.Throws<MarshalDirectiveException>(() => {
fixed (Vector128<float>* pValues = &values[0])
{
GenericsNative.AddVector128Fs(pValues, values.Length);
}
});
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Fs(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddVector128Fs(in values[0], values.Length));
}
}