1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * Checker test for arm and arm64 simd optimizations. 19 */ 20 public class Main { 21 expectEquals(int expected, int result)22 private static void expectEquals(int expected, int result) { 23 if (expected != result) { 24 throw new Error("Expected: " + expected + ", found: " + result); 25 } 26 } 27 28 /// CHECK-START-ARM64: void Main.encodableConstants(byte[], short[], char[], int[], long[], float[], double[]) disassembly (after) 29 /// CHECK-DAG: <<C1:i\d+>> IntConstant 1 30 /// CHECK-DAG: <<C2:i\d+>> IntConstant -128 31 /// CHECK-DAG: <<C3:i\d+>> IntConstant 127 32 /// CHECK-DAG: <<C4:i\d+>> IntConstant -219 33 /// CHECK-DAG: <<C5:i\d+>> IntConstant 219 34 /// CHECK-DAG: <<L6:j\d+>> LongConstant 219 35 /// CHECK-DAG: <<F7:f\d+>> FloatConstant 2 36 /// CHECK-DAG: <<F8:f\d+>> FloatConstant 14.34 37 /// CHECK-DAG: <<D9:d\d+>> DoubleConstant 20 38 /// CHECK-DAG: <<D10:d\d+>> DoubleConstant 0 39 // 40 /// CHECK-DAG: VecReplicateScalar [<<C1>>] 41 /// CHECK-DAG: VecReplicateScalar [<<C2>>] 42 /// CHECK-DAG: VecReplicateScalar [<<C3>>] 43 /// CHECK-DAG: VecReplicateScalar [<<C4>>] 44 /// CHECK-DAG: VecReplicateScalar [<<C5>>] 45 /// CHECK-DAG: VecReplicateScalar [<<L6>>] 46 /// CHECK-DAG: VecReplicateScalar [<<F7>>] 47 /// CHECK-DAG: VecReplicateScalar [<<F8>>] 48 /// CHECK-DAG: VecReplicateScalar [<<D9>>] 49 /// CHECK-DAG: VecReplicateScalar [<<D10>>] encodableConstants(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d)50 private static void encodableConstants(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) { 51 for (int i = 0; i < ARRAY_SIZE; i++) { 52 b[i] += 1; 53 } 54 for (int i = 0; i < ARRAY_SIZE; i++) { 55 s[i] += -128; 56 } 57 for (int i = 0; i < ARRAY_SIZE; i++) { 58 c[i] += 127; 59 } 60 for (int i = 0; i < ARRAY_SIZE; i++) { 61 a[i] += -219; 62 } 63 for (int i = 0; i < ARRAY_SIZE; i++) { 64 a[i] += 219; 65 } 66 for (int i = 0; i < ARRAY_SIZE; i++) { 67 l[i] += 219; 68 } 69 for (int i = 0; i < ARRAY_SIZE; i++) { 70 f[i] += 2.0f; 71 } 72 for (int i = 0; i < ARRAY_SIZE; i++) { 73 f[i] += 14.34f; 74 } 75 for (int i = 0; i < ARRAY_SIZE; i++) { 76 d[i] += 20.0; 77 } 78 for (int i = 0; i < ARRAY_SIZE; i++) { 79 d[i] += 0.0; 80 } 81 } 82 sumArray(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d)83 private static int sumArray(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) { 84 int sum = 0; 85 for (int i = 0; i < ARRAY_SIZE; i++) { 86 sum += b[i] + s[i] + c[i] + a[i] + l[i] + f[i] + d[i]; 87 } 88 return sum; 89 } 90 91 public static final int ARRAY_SIZE = 128; 92 main(String[] args)93 public static void main(String[] args) { 94 byte[] b = new byte[ARRAY_SIZE]; 95 short[] s = new short[ARRAY_SIZE]; 96 char[] c = new char[ARRAY_SIZE]; 97 int[] a = new int[ARRAY_SIZE]; 98 long[] l = new long[ARRAY_SIZE]; 99 float[] f = new float[ARRAY_SIZE]; 100 double[] d = new double[ARRAY_SIZE]; 101 102 encodableConstants(b, s, c, a, l, f, d); 103 expectEquals(32640, sumArray(b, s, c, a, l, f, d)); 104 105 System.out.println("passed"); 106 } 107 } 108