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
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class Main {
public static void main(String[] args) {
assertEquals(4.2f, returnFloat());
float[] a = new float[2];
a[0] = 42.2f;
a[1] = 3.2f;
assertEquals(45.4f, returnFloat(a));
assertEquals(4.4, returnDouble());
double[] b = new double[1];
b[0] = 42.4;
assertEquals(42.4, returnDouble(b));
assertEquals(4.2f, invokeReturnFloat());
assertEquals(4.4, invokeReturnDouble());
assertEquals(4.2f, takeAFloat(4.2f));
assertEquals(3.1, takeADouble(3.1));
assertEquals(12.7, takeThreeDouble(3.1, 4.4, 5.2));
assertEquals(12.7f, takeThreeFloat(3.1f, 4.4f, 5.2f));
assertEquals(4.2f, invokeTakeAFloat(4.2f));
assertEquals(3.1, invokeTakeADouble(3.1));
assertEquals(12.7, invokeTakeThreeDouble(3.1, 4.4, 5.2));
assertEquals(12.7f, invokeTakeThreeFloat(3.1f, 4.4f, 5.2f));
testArrayOperations(new float[2], 0, 1.2f, 3.4f);
testArrayOperations(new double[2], 0, 4.1, 7.6);
}
public static float invokeReturnFloat() {
return returnFloat();
}
public static double invokeReturnDouble() {
return returnDouble();
}
public static float returnFloat() {
return 4.2f;
}
public static float returnFloat(float[] a) {
return a[0] + a[1];
}
public static double returnDouble() {
return 4.4;
}
public static double returnDouble(double[] a) {
return a[0];
}
public static float takeAFloat(float a) {
return a;
}
public static double takeADouble(double a) {
return a;
}
public static double takeThreeDouble(double a, double b, double c) {
return a + b + c;
}
public static float takeThreeFloat(float a, float b, float c) {
return a + b + c;
}
public static float invokeTakeAFloat(float a) {
return takeAFloat(a);
}
public static double invokeTakeADouble(double a) {
return takeADouble(a);
}
public static double invokeTakeThreeDouble(double a, double b, double c) {
return takeThreeDouble(a, b, c);
}
public static float invokeTakeThreeFloat(float a, float b, float c) {
return takeThreeFloat(a, b, c);
}
// Test simple operations on a float array to ensure the register allocator works
// properly.
public static void testArrayOperations(float[] a, int index, float value1, float value2) {
a[0] = value1;
a[1] = value2;
assertEquals(value1 + value2, a[0] + a[1]);
a[0] = 0.0f;
a[1] = 0.0f;
assertEquals(0.0f, a[0] + a[1]);
a[index] = value1;
a[index + 1] = value2;
assertEquals(value1 + value2, a[0] + a[1]);
}
// Test simple operations on a double array to ensure the register allocator works
// properly.
public static void testArrayOperations(double[] a, int index, double value1, double value2) {
a[0] = value1;
a[1] = value2;
assertEquals(value1 + value2, a[0] + a[1]);
a[0] = 0.0;
a[1] = 0.0;
assertEquals(0.0, a[0] + a[1]);
a[index] = value1;
a[index + 1] = value2;
assertEquals(value1 + value2, a[0] + a[1]);
}
public static void assertEquals(float expected, float actual) {
if (expected != actual) {
throw new AssertionError("Expected " + expected + " got " + actual);
}
}
public static void assertEquals(double expected, double actual) {
if (expected != actual) {
throw new AssertionError("Expected " + expected + " got " + actual);
}
}
}
|