1 // pinvoke_ppcf.cs - Test cases for passing structures to and and returning
2 // structures from functions. This particular test is for
3 // structures consisting wholy of 4 byte fields.
5 // The Power ABI version 2 allows for special parameter
6 // passing and returning optimizations for certain
7 // structures of homogenous composition (like all ints).
8 // This set of tests checks all the possible combinations
9 // that use the special parm/return rules and one beyond.
11 // Bill Seurer (seurer@linux.vnet.ibm.com)
13 // (C) {Copyright holder}
17 using System.Runtime.InteropServices;
20 public class Test_float {
22 [DllImport ("libtest", EntryPoint="mono_return_float1")]
23 public static extern float mono_return_float1 (float1 s, int addend);
24 [StructLayout(LayoutKind.Sequential)]
25 public struct float1 {
28 [DllImport ("libtest", EntryPoint="mono_return_float2")]
29 public static extern float mono_return_float2 (float2 s, int addend);
30 [StructLayout(LayoutKind.Sequential)]
31 public struct float2 {
34 [DllImport ("libtest", EntryPoint="mono_return_float3")]
35 public static extern float mono_return_float3 (float3 s, int addend);
36 [StructLayout(LayoutKind.Sequential)]
37 public struct float3 {
38 public float f1,f2,f3;
40 [DllImport ("libtest", EntryPoint="mono_return_float4")]
41 public static extern float mono_return_float4 (float4 s, int addend);
42 [StructLayout(LayoutKind.Sequential)]
43 public struct float4 {
44 public float f1,f2,f3,f4;
46 // This structure is 1 element too large to use the special return
48 [DllImport ("libtest", EntryPoint="mono_return_float5")]
49 public static extern float mono_return_float5 (float5 s, int addend);
50 [StructLayout(LayoutKind.Sequential)]
51 public struct float5 {
52 public float f1,f2,f3,f4,f5;
54 [DllImport ("libtest", EntryPoint="mono_return_float6")]
55 public static extern float mono_return_float6 (float6 s, int addend);
56 [StructLayout(LayoutKind.Sequential)]
57 public struct float6 {
58 public float f1,f2,f3,f4,f5,f6;
60 [DllImport ("libtest", EntryPoint="mono_return_float7")]
61 public static extern float mono_return_float7 (float7 s, int addend);
62 [StructLayout(LayoutKind.Sequential)]
63 public struct float7 {
64 public float f1,f2,f3,f4,f5,f6,f7;
66 [DllImport ("libtest", EntryPoint="mono_return_float8")]
67 public static extern float mono_return_float8 (float8 s, int addend);
68 [StructLayout(LayoutKind.Sequential)]
69 public struct float8 {
70 public float f1,f2,f3,f4,f5,f6,f7,f8;
72 // This structure is 1 element too large to use the special parameter
74 [DllImport ("libtest", EntryPoint="mono_return_float9")]
75 public static extern float mono_return_float9 (float9 s, int addend);
76 [StructLayout(LayoutKind.Sequential)]
77 public struct float9 {
78 public float f1,f2,f3,f4,f5,f6,f7,f8,f9;
81 // This structure has nested structures within it but they are
82 // homogenous and thus should still use the special rules.
83 public struct float4_nested1 {
86 public struct float4_nested2 {
89 [DllImport ("libtest", EntryPoint="mono_return_float4_nested")]
90 public static extern float4_nested mono_return_float4_nested (float4_nested s, int addend);
91 [StructLayout(LayoutKind.Sequential)]
92 public struct float4_nested {
93 public float4_nested1 nested1;
95 public float4_nested2 nested2;
98 public static int Main (string[] args) {
102 float retval1 = mono_return_float1(s1, 906);
103 if (retval1 != 2*906) {
104 Console.WriteLine(" float1 retval1: got {0} but expected {1}", retval1, 2*906);
111 float retval2 = mono_return_float2(s2, 906);
112 if (retval2 != 2*906) {
113 Console.WriteLine(" float2 retval2: got {0} but expected {1}", retval2, 2*906);
121 float retval3 = mono_return_float3(s3, 906);
122 if (retval3 != 2*906) {
123 Console.WriteLine(" float3 retval3: got {0} but expected {1}", retval3, 2*906);
132 float retval4 = mono_return_float4(s4, 906);
133 if (retval4 != 2*906) {
134 Console.WriteLine(" float4 retval4: got {0} but expected {1}", retval4, 2*906);
144 float retval5 = mono_return_float5(s5, 906);
145 if (retval5 != 2*906) {
146 Console.WriteLine(" float5 retval5: got {0} but expected {1}", retval5, 2*906);
157 float retval6 = mono_return_float6(s6, 906);
158 if (retval6 != 2*906) {
159 Console.WriteLine(" float6 retval6: got {0} but expected {1}", retval6, 2*906);
171 float retval7 = mono_return_float7(s7, 906);
172 if (retval7 != 2*906) {
173 Console.WriteLine(" float7 retval7: got {0} but expected {1}", retval7, 2*906);
186 float retval8 = mono_return_float8(s8, 906);
187 if (retval8 != 2*906) {
188 Console.WriteLine(" float8 retval8: got {0} but expected {1}", retval8, 2*906);
202 float retval9 = mono_return_float9(s9, 906);
203 if (retval9 != 2*906) {
204 Console.WriteLine(" float9 retval9: got {0} but expected {1}", retval9, 2*906);
211 } // end class Test_float