1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using System ;
5+ using System . Runtime . InteropServices ;
6+ using System . Runtime . CompilerServices ;
7+ using Xunit ;
8+
9+ public static class Program
10+ {
11+ #region ExtendedUint_RiscVTests
12+ [ DllImport ( "PrimitiveABINative" ) ]
13+ public static extern long Echo_ExtendedUint_RiscV ( int a0 , uint a1 ) ;
14+
15+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
16+ public static long Echo_ExtendedUint_RiscV_Managed ( int a0 , uint a1 ) => unchecked ( ( int ) a1 ) ;
17+
18+ [ Fact ]
19+ public static void Test_ExtendedUint_RiscV ( )
20+ {
21+ const uint arg = 0xB1ED0C1Eu ;
22+ const long ret = unchecked ( ( int ) arg ) ;
23+ long managed = Echo_ExtendedUint_RiscV_Managed ( 0 , arg ) ;
24+ long native = Echo_ExtendedUint_RiscV ( 0 , arg ) ;
25+
26+ Assert . Equal ( ret , managed ) ;
27+ Assert . Equal ( ret , native ) ;
28+ }
29+
30+ [ Fact ]
31+ public static void Test_ExtendedUint_ByReflection_RiscV ( )
32+ {
33+ const uint arg = 0xB1ED0C1Eu ;
34+ const long ret = unchecked ( ( int ) arg ) ;
35+ long managed = ( long ) typeof ( Program ) . GetMethod ( "Echo_ExtendedUint_RiscV_Managed" ) . Invoke (
36+ null , new object [ ] { 0 , arg } ) ;
37+ long native = ( long ) typeof ( Program ) . GetMethod ( "Echo_ExtendedUint_RiscV" ) . Invoke (
38+ null , new object [ ] { 0 , arg } ) ;
39+
40+ Assert . Equal ( ret , managed ) ;
41+ Assert . Equal ( ret , native ) ;
42+ }
43+
44+ [ DllImport ( "PrimitiveABINative" ) ]
45+ public static extern long Echo_ExtendedUint_OnStack_RiscV (
46+ int a0 , int a1 , int a2 , int a3 , int a4 , int a5 , int a6 , int a7 , uint stack0 ) ;
47+
48+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
49+ public static long Echo_ExtendedUint_OnStack_RiscV_Managed (
50+ int a0 , int a1 , int a2 , int a3 , int a4 , int a5 , int a6 , int a7 , uint stack0 ) => unchecked ( ( int ) stack0 ) ;
51+
52+ [ Fact ]
53+ public static void Test_ExtendedUint_OnStack_RiscV ( )
54+ {
55+ const uint arg = 0xB1ED0C1Eu ;
56+ const long ret = unchecked ( ( int ) arg ) ;
57+ long managed = Echo_ExtendedUint_OnStack_RiscV_Managed ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg ) ;
58+ long native = Echo_ExtendedUint_OnStack_RiscV ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg ) ;
59+
60+ Assert . Equal ( ret , managed ) ;
61+ Assert . Equal ( ret , native ) ;
62+ }
63+
64+ [ Fact ]
65+ public static void Test_ExtendedUint_OnStack_ByReflection_RiscV ( )
66+ {
67+ const uint arg = 0xB1ED0C1Eu ;
68+ const long ret = unchecked ( ( int ) arg ) ;
69+ long managed = ( long ) typeof ( Program ) . GetMethod ( "Echo_ExtendedUint_OnStack_RiscV_Managed" ) . Invoke (
70+ null , new object [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg } ) ;
71+ long native = ( long ) typeof ( Program ) . GetMethod ( "Echo_ExtendedUint_OnStack_RiscV" ) . Invoke (
72+ null , new object [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg } ) ;
73+
74+ Assert . Equal ( ret , managed ) ;
75+ Assert . Equal ( ret , native ) ;
76+ }
77+ #endregion
78+
79+ #region Float_RiscVTests
80+ [ DllImport ( "PrimitiveABINative" ) ]
81+ public static extern double Echo_Float_RiscV ( float fa0 , float fa1 ) ;
82+
83+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
84+ public static double Echo_Float_RiscV_Managed ( float fa0 , float fa1 ) => fa1 ;
85+
86+ [ Fact ]
87+ public static void Test_Float_RiscV ( )
88+ {
89+ const float arg = 3.14159f ;
90+ const double ret = 3.14159f ;
91+ double managed = Echo_Float_RiscV_Managed ( 0f , arg ) ;
92+ double native = Echo_Float_RiscV ( 0f , arg ) ;
93+
94+ Assert . Equal ( ret , managed ) ;
95+ Assert . Equal ( ret , native ) ;
96+ }
97+
98+ [ Fact ]
99+ public static void Test_Float_ByReflection_RiscV ( )
100+ {
101+ const float arg = 3.14159f ;
102+ const double ret = 3.14159f ;
103+ double managed = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_RiscV_Managed" ) . Invoke (
104+ null , new object [ ] { 0f , arg } ) ;
105+ double native = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_RiscV" ) . Invoke (
106+ null , new object [ ] { 0f , arg } ) ;
107+
108+ Assert . Equal ( ret , managed ) ;
109+ Assert . Equal ( ret , native ) ;
110+ }
111+
112+ [ DllImport ( "PrimitiveABINative" ) ]
113+ public static extern double Echo_Float_InIntegerReg_RiscV (
114+ float fa0 , float fa1 , float fa2 , float fa3 , float fa4 , float fa5 , float fa6 , float fa7 , float a0 ) ;
115+
116+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
117+ public static double Echo_Float_InIntegerReg_RiscV_Managed (
118+ float fa0 , float fa1 , float fa2 , float fa3 , float fa4 , float fa5 , float fa6 , float fa7 , float a0 ) => a0 ;
119+
120+ [ Fact ]
121+ public static void Test_Float_InIntegerReg_RiscV ( )
122+ {
123+ const float arg = 3.14159f ;
124+ const double ret = 3.14159f ;
125+ double managed = Echo_Float_InIntegerReg_RiscV_Managed ( 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , arg ) ;
126+ double native = Echo_Float_InIntegerReg_RiscV ( 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , arg ) ;
127+
128+ Assert . Equal ( ret , managed ) ;
129+ Assert . Equal ( ret , native ) ;
130+ }
131+
132+ [ Fact ]
133+ public static void Test_Float_InIntegerReg_ByReflection_RiscV ( )
134+ {
135+ const float arg = 3.14159f ;
136+ const double ret = 3.14159f ;
137+ double managed = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_InIntegerReg_RiscV_Managed" ) . Invoke (
138+ null , new object [ ] { 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , arg } ) ;
139+ double native = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_InIntegerReg_RiscV" ) . Invoke (
140+ null , new object [ ] { 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , arg } ) ;
141+
142+ Assert . Equal ( ret , managed ) ;
143+ Assert . Equal ( ret , native ) ;
144+ }
145+
146+ [ DllImport ( "PrimitiveABINative" ) ]
147+ public static extern double Echo_Float_OnStack_RiscV (
148+ float fa0 , float fa1 , float fa2 , float fa3 , float fa4 , float fa5 , float fa6 , float fa7 ,
149+ int a0 , int a1 , int a2 , int a3 , int a4 , int a5 , int a6 , int a7 , float stack0 ) ;
150+
151+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
152+ public static double Echo_Float_OnStack_RiscV_Managed (
153+ float fa0 , float fa1 , float fa2 , float fa3 , float fa4 , float fa5 , float fa6 , float fa7 ,
154+ int a0 , int a1 , int a2 , int a3 , int a4 , int a5 , int a6 , int a7 , float stack0 ) => stack0 ;
155+
156+ [ Fact ]
157+ public static void Test_Float_OnStack_RiscV ( )
158+ {
159+ const float arg = 3.14159f ;
160+ const double ret = 3.14159f ;
161+ double managed = Echo_Float_OnStack_RiscV_Managed ( 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg ) ;
162+ double native = Echo_Float_OnStack_RiscV ( 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg ) ;
163+
164+ Assert . Equal ( ret , managed ) ;
165+ Assert . Equal ( ret , native ) ;
166+ }
167+
168+ [ Fact ]
169+ public static void Test_Float_OnStack_ByReflection_RiscV ( )
170+ {
171+ const float arg = 3.14159f ;
172+ const double ret = 3.14159f ;
173+ double managed = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_OnStack_RiscV_Managed" ) . Invoke (
174+ null , new object [ ] { 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg } ) ;
175+ double native = ( double ) typeof ( Program ) . GetMethod ( "Echo_Float_OnStack_RiscV" ) . Invoke (
176+ null , new object [ ] { 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , arg } ) ;
177+
178+ Assert . Equal ( ret , managed ) ;
179+ Assert . Equal ( ret , native ) ;
180+ }
181+ #endregion
182+ }
0 commit comments