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-IF: hasIsaFeature("sve") 41 // 42 /// CHECK-DAG: VecReplicateScalar [<<C1>>,{{j\d+}}] 43 /// CHECK-DAG: VecReplicateScalar [<<C2>>,{{j\d+}}] 44 /// CHECK-DAG: VecReplicateScalar [<<C3>>,{{j\d+}}] 45 /// CHECK-DAG: VecReplicateScalar [<<C4>>,{{j\d+}}] 46 /// CHECK-DAG: VecReplicateScalar [<<C5>>,{{j\d+}}] 47 /// CHECK-DAG: VecReplicateScalar [<<L6>>,{{j\d+}}] 48 /// CHECK-DAG: VecReplicateScalar [<<F7>>,{{j\d+}}] 49 /// CHECK-DAG: VecReplicateScalar [<<F8>>,{{j\d+}}] 50 /// CHECK-DAG: VecReplicateScalar [<<D9>>,{{j\d+}}] 51 /// CHECK-DAG: VecReplicateScalar [<<D10>>,{{j\d+}}] 52 // 53 /// CHECK-ELSE: 54 // 55 /// CHECK-DAG: VecReplicateScalar [<<C1>>] 56 /// CHECK-DAG: VecReplicateScalar [<<C2>>] 57 /// CHECK-DAG: VecReplicateScalar [<<C3>>] 58 /// CHECK-DAG: VecReplicateScalar [<<C4>>] 59 /// CHECK-DAG: VecReplicateScalar [<<C5>>] 60 /// CHECK-DAG: VecReplicateScalar [<<L6>>] 61 /// CHECK-DAG: VecReplicateScalar [<<F7>>] 62 /// CHECK-DAG: VecReplicateScalar [<<F8>>] 63 /// CHECK-DAG: VecReplicateScalar [<<D9>>] 64 /// CHECK-DAG: VecReplicateScalar [<<D10>>] 65 // 66 /// CHECK-FI: encodableConstants(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d)67 private static void encodableConstants(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) { 68 for (int i = 0; i < ARRAY_SIZE; i++) { 69 b[i] += 1; 70 } 71 for (int i = 0; i < ARRAY_SIZE; i++) { 72 s[i] += -128; 73 } 74 for (int i = 0; i < ARRAY_SIZE; i++) { 75 c[i] += 127; 76 } 77 for (int i = 0; i < ARRAY_SIZE; i++) { 78 a[i] += -219; 79 } 80 for (int i = 0; i < ARRAY_SIZE; i++) { 81 a[i] += 219; 82 } 83 for (int i = 0; i < ARRAY_SIZE; i++) { 84 l[i] += 219; 85 } 86 for (int i = 0; i < ARRAY_SIZE; i++) { 87 f[i] += 2.0f; 88 } 89 for (int i = 0; i < ARRAY_SIZE; i++) { 90 f[i] += 14.34f; 91 } 92 for (int i = 0; i < ARRAY_SIZE; i++) { 93 d[i] += 20.0; 94 } 95 for (int i = 0; i < ARRAY_SIZE; i++) { 96 d[i] += 0.0; 97 } 98 } 99 sumArray(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d)100 private static int sumArray(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) { 101 int sum = 0; 102 for (int i = 0; i < ARRAY_SIZE; i++) { 103 sum += b[i] + s[i] + c[i] + a[i] + l[i] + f[i] + d[i]; 104 } 105 return sum; 106 } 107 108 public static final int ARRAY_SIZE = 128; 109 main(String[] args)110 public static void main(String[] args) { 111 byte[] b = new byte[ARRAY_SIZE]; 112 short[] s = new short[ARRAY_SIZE]; 113 char[] c = new char[ARRAY_SIZE]; 114 int[] a = new int[ARRAY_SIZE]; 115 long[] l = new long[ARRAY_SIZE]; 116 float[] f = new float[ARRAY_SIZE]; 117 double[] d = new double[ARRAY_SIZE]; 118 119 encodableConstants(b, s, c, a, l, f, d); 120 expectEquals(32640, sumArray(b, s, c, a, l, f, d)); 121 122 System.out.println("passed"); 123 } 124 } 125