summaryrefslogtreecommitdiff
path: root/tests/src/JIT/CodeGenBringUpTests/InstanceCalls.cs
blob: cc57fd091c085791a0b704c5775e689ff0671e68 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//


using System;
using System.Runtime.CompilerServices;

public class MiscMethods
{
    private int x;
    private int y;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public MiscMethods(int a, int b) {x=a; y=b;}

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public int Sum(int[] a)
    {
        int s = 0;
        for (int i = 0; i < a.Length; ++i)
            s += a[i];
        return s;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public float Sum(float[] a)
    {
        float s = 0;
        for (int i = 0; i < a.Length; ++i)
            s += a[i];
        return s;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public double Sum(double[] a)
    {
        double s = 0;
        for (int i = 0; i < a.Length; ++i)
            s += a[i];
        return s;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public int Sum(int a, int b, int c, int d, int e)
    {
        return a + b + c + d + e;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public float Sum(float a, float b, float c, float d, float e)
    {
        return a + b + c + d + e;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public double Sum(double a, double b, double c, double d, double e)
    {
        return a + b + c + d + e;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public void Print(int s)
    {
        Console.WriteLine(s);
    }
 
    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public bool InstanceCalls(MiscMethods m)    
    {
       return x == m.x && y == m.y;
    }
}

public class BringUpTest
{
    const int Pass = 100;
    const int Fail = -1;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static bool floatEqual(float x, float y)     
    {
        return System.Math.Abs(x-y) <= Single.Epsilon;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static bool doubleEqual(double x, double y)     
    {
        return System.Math.Abs(x-y) <= Double.Epsilon;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static int InstanceCalls(MiscMethods m, int[] a)
    {
        int result = Pass;

        int s = m.Sum(a);
        if (s != 15) result = Fail;

        s = m.Sum(1, 2, 3, 4, 5);
        if (s != 15) result = Fail;

        return result;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static int InstanceCalls(MiscMethods m, float[] a)
    {
        int result = Pass;

        float s = m.Sum(a);
        if (!floatEqual(s, 15f)) result = Fail;

        s = m.Sum(1f, 2f, 3f, 4f, 5f);
        if (!floatEqual(s, 15f)) result = Fail;

        return result;
    }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static int InstanceCalls(MiscMethods m, double[] a, double v1, double v2, double v3, double v4, double v5)
    {
        int result = Pass;

        double s1 = m.Sum(a);
        double s2 = m.Sum(v1, v2, v3, v4, v5);
        if (!doubleEqual(s1, s2)) result = Fail;

        return result;
    }


    public static int Main()
    {
        MiscMethods m = new MiscMethods(10,20);
        if (!m.InstanceCalls(m)) return Fail;

        int[] a = new int[5] { 1, 2, 3, 4, 5 };
        int x = InstanceCalls(m,a);

        float[] b = new float[5] { 1f, 2f, 3f, 4f, 5f };
        int y = InstanceCalls(m,b);

        double[] c = new double[5] { 1d, 2d, 3d, 4d, 5d };
        int z = InstanceCalls(m,c, 1d, 2d, 3d, 4d, 5d);

        if (x == Pass && y == Pass && z == Pass)
           return Pass;
        return Fail;        
    }
}