[netcore] Implement missing Bmi1/Bmi2 intrinsics (#16919)
[mono-project.git] / mono / mini / nacl.cs
blobd47645a1ef21de3720f7e0308c5a21f07d51ead8
1 using System;
2 using Mono.Simd;
3 using System.Threading;
5 class A {
6 public void Print() { Console.WriteLine("A"); }
9 class B : A {
10 public void Print() { Console.WriteLine("B"); }
13 class ThreadRunner {
14 public Int32 Inc2(Int32 a) { return Inc1(a); }
15 public Int32 Inc1(Int32 a) { return a + 2; }
16 public void PrintA(A a) { a.Print(); ((B)a).Print(); }
17 public void Run() {
18 Console.WriteLine("Running thread" );
19 B b = new B();
20 Int32 a=0;
21 for(int i = 0; i < 1000000; i++) {
22 a = Inc2(a);
23 if(i % 100000 == 0) PrintA(b);
25 Console.WriteLine("Ending thread");
30 class Extensions { public static string BogusProperty { get; set; } }
32 class RuntimeServices {
33 public System.Reflection.MemberInfo[] members = typeof(Extensions).GetMembers();
34 public void Run() {
35 foreach (var m in members) System.Console.WriteLine(m);
39 class Tests {
40 struct myvt {
41 public int X;
42 public int Y;
45 static int test_0_vector4i_cmp_gt () {
46 Vector4i a = new Vector4i (10, 5, 12, -1);
47 Vector4i b = new Vector4i (-1, 5, 10, 10);
49 Vector4i c = a.CompareGreaterThan (b);
51 if (c.X != -1)
52 return 1;
53 if (c.Y != 0)
54 return 2;
55 if (c.Z != -1)
56 return 3;
57 if (c.W != 0)
58 return 4;
59 return 0;
62 static myvt CompareGT(myvt a, myvt b) {
63 myvt r;
64 r.X = a.X > b.X ? -1 : 0;
65 r.Y = a.Y > b.Y ? -1 : 0;
66 return r;
69 static int test_0_struct2i_cmp_gt() {
70 myvt a;
71 myvt b;
72 a.X = 10;
73 a.Y = 5;
74 b.X = -1;
75 b.Y = 5;
76 myvt c = CompareGT(a, b);
77 if (c.X != -1)
78 return 1;
79 if (c.Y != 0)
80 return 2;
81 return 0;
84 static int vararg_sum(params int[] args) {
85 int sum = 0;
86 foreach(int arg in args) {
87 sum += arg;
89 return sum;
91 static int test_21_vararg_test() {
92 int sum = 0;
93 sum += vararg_sum();
94 sum += vararg_sum(1);
95 sum += vararg_sum(2, 3);
96 sum += vararg_sum(4, 5, 6);
97 return sum;
100 static int test_0_threads() {
101 // Run a bunch of threads, make them JIT some code and
102 // do some casts
103 ThreadRunner runner = new ThreadRunner();
104 Thread[] threads = new Thread[10];
105 for (int i = 0; i < 10; i++) {
106 threads[i] = new Thread(new ThreadStart(runner.Run));
107 threads[i].Start();
109 for (int i = 0; i < 10; i++) {
110 threads[i].Join();
112 return 0;
116 static int test_0_reflection() {
117 RuntimeServices r = new RuntimeServices();
118 r.Run();
119 return 0;
122 public class BaseClass {
125 public class LongClass : BaseClass {
126 public long Value;
127 public LongClass(long val) { Value = val; }
130 static public long add_two_LongClass(BaseClass l1, BaseClass l2) {
131 long l = checked (((LongClass)l1).Value + ((LongClass)l2).Value);
132 return l;
135 static int test_0_laddcc() {
136 long l = add_two_LongClass(new LongClass(System.Int64.MinValue), new LongClass(1234));
137 if (l == 1234)
138 return 1;
139 return 0;
142 public static int Main(String[] args) {
143 return TestDriver.RunTests(typeof(Tests));