17fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray/*
27fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
37fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray *
47fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
57fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * you may not use this file except in compliance with the License.
67fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * You may obtain a copy of the License at
77fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray *
87fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
97fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray *
107fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
117fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
127fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * See the License for the specific language governing permissions and
147fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray * limitations under the License.
157fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray */
167fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
177fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraypublic class Main {
187fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static void main(String[] args) {
197fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.2f, returnFloat());
20102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    float[] a = new float[2];
217fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    a[0] = 42.2f;
22102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[1] = 3.2f;
23102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(45.4f, returnFloat(a));
247fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
257fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.4, returnDouble());
267fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    double[] b = new double[1];
277fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    b[0] = 42.4;
287fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(42.4, returnDouble(b));
297fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
307fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.2f, invokeReturnFloat());
317fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.4, invokeReturnDouble());
327fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.2f, takeAFloat(4.2f));
337fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(3.1, takeADouble(3.1));
347fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(12.7, takeThreeDouble(3.1, 4.4, 5.2));
357fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(12.7f, takeThreeFloat(3.1f, 4.4f, 5.2f));
367fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(4.2f, invokeTakeAFloat(4.2f));
377fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(3.1, invokeTakeADouble(3.1));
387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(12.7, invokeTakeThreeDouble(3.1, 4.4, 5.2));
397fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    assertEquals(12.7f, invokeTakeThreeFloat(3.1f, 4.4f, 5.2f));
40102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray
41102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    testArrayOperations(new float[2], 0, 1.2f, 3.4f);
42102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    testArrayOperations(new double[2], 0, 4.1, 7.6);
437fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
447fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
457fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float invokeReturnFloat() {
467fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return returnFloat();
477fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
487fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
497fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double invokeReturnDouble() {
507fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return returnDouble();
517fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
527fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
537fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float returnFloat() {
547fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return 4.2f;
557fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
567fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
577fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float returnFloat(float[] a) {
58102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    return a[0] + a[1];
597fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
607fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
617fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double returnDouble() {
627fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return 4.4;
637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
647fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double returnDouble(double[] a) {
667fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return a[0];
677fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
687fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
697fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float takeAFloat(float a) {
707fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return a;
717fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
727fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
737fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double takeADouble(double a) {
747fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return a;
757fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
767fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
777fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double takeThreeDouble(double a, double b, double c) {
787fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return a + b + c;
797fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
807fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
817fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float takeThreeFloat(float a, float b, float c) {
827fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return a + b + c;
837fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
847fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
857fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float invokeTakeAFloat(float a) {
867fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return takeAFloat(a);
877fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
887fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
897fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double invokeTakeADouble(double a) {
907fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return takeADouble(a);
917fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
927fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
937fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static double invokeTakeThreeDouble(double a, double b, double c) {
947fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return takeThreeDouble(a, b, c);
957fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
967fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
977fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static float invokeTakeThreeFloat(float a, float b, float c) {
987fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    return takeThreeFloat(a, b, c);
997fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
1007fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
101102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  // Test simple operations on a float array to ensure the register allocator works
102102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  // properly.
103102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  public static void testArrayOperations(float[] a, int index, float value1, float value2) {
104102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[0] = value1;
105102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[1] = value2;
106102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(value1 + value2, a[0] + a[1]);
107102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[0] = 0.0f;
108102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[1] = 0.0f;
109102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(0.0f, a[0] + a[1]);
110102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[index] = value1;
111102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[index + 1] = value2;
112102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(value1 + value2, a[0] + a[1]);
113102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  }
114102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray
115102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  // Test simple operations on a double array to ensure the register allocator works
116102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  // properly.
117102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  public static void testArrayOperations(double[] a, int index, double value1, double value2) {
118102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[0] = value1;
119102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[1] = value2;
120102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(value1 + value2, a[0] + a[1]);
121102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[0] = 0.0;
122102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[1] = 0.0;
123102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(0.0, a[0] + a[1]);
124102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[index] = value1;
125102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    a[index + 1] = value2;
126102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray    assertEquals(value1 + value2, a[0] + a[1]);
127102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  }
128102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray
1297fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static void assertEquals(float expected, float actual) {
1307fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    if (expected != actual) {
1317fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      throw new AssertionError("Expected " + expected + " got " + actual);
1327fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    }
1337fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
1347fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
1357fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  public static void assertEquals(double expected, double actual) {
1367fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    if (expected != actual) {
1377fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      throw new AssertionError("Expected " + expected + " got " + actual);
1387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    }
1397fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  }
1407fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray}
141