Debian Codegraph @

test/655-checker-simd-arm-opt/src/Main.java

raw symbols SCIP
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 static int[] arr;
22
23 private static void expectEquals(int expected, int result) {
24 if (expected != result) {
25 throw new Error("Expected: " + expected + ", found: " + result);
26 }
27 }
28
29 /// CHECK-START-ARM64: void Main.encodableConstants(byte[], short[], char[], int[], long[], float[], double[]) disassembly (after)
30 /// CHECK-DAG: <<C1:i\d+>> IntConstant 1
31 /// CHECK-DAG: <<C2:i\d+>> IntConstant -128
32 /// CHECK-DAG: <<C3:i\d+>> IntConstant 127
33 /// CHECK-DAG: <<C4:i\d+>> IntConstant -219
34 /// CHECK-DAG: <<C5:i\d+>> IntConstant 219
35 /// CHECK-DAG: <<L6:j\d+>> LongConstant 219
36 /// CHECK-DAG: <<F7:f\d+>> FloatConstant 2
37 /// CHECK-DAG: <<F8:f\d+>> FloatConstant 14.34
38 /// CHECK-DAG: <<D9:d\d+>> DoubleConstant 20
39 /// CHECK-DAG: <<D10:d\d+>> DoubleConstant 0
40 //
41 /// CHECK-IF: hasIsaFeature("sve")
42 //
43 /// CHECK-DAG: VecReplicateScalar [<<C1>>,{{j\d+}}]
44 /// CHECK-DAG: VecReplicateScalar [<<C2>>,{{j\d+}}]
45 /// CHECK-DAG: VecReplicateScalar [<<C3>>,{{j\d+}}]
46 /// CHECK-DAG: VecReplicateScalar [<<C4>>,{{j\d+}}]
47 /// CHECK-DAG: VecReplicateScalar [<<C5>>,{{j\d+}}]
48 /// CHECK-DAG: VecReplicateScalar [<<L6>>,{{j\d+}}]
49 /// CHECK-DAG: VecReplicateScalar [<<F7>>,{{j\d+}}]
50 /// CHECK-DAG: VecReplicateScalar [<<F8>>,{{j\d+}}]
51 /// CHECK-DAG: VecReplicateScalar [<<D9>>,{{j\d+}}]
52 /// CHECK-DAG: VecReplicateScalar [<<D10>>,{{j\d+}}]
53 //
54 /// CHECK-ELSE:
55 //
56 /// CHECK-DAG: VecReplicateScalar [<<C1>>]
57 /// CHECK-DAG: VecReplicateScalar [<<C2>>]
58 /// CHECK-DAG: VecReplicateScalar [<<C3>>]
59 /// CHECK-DAG: VecReplicateScalar [<<C4>>]
60 /// CHECK-DAG: VecReplicateScalar [<<C5>>]
61 /// CHECK-DAG: VecReplicateScalar [<<L6>>]
62 /// CHECK-DAG: VecReplicateScalar [<<F7>>]
63 /// CHECK-DAG: VecReplicateScalar [<<F8>>]
64 /// CHECK-DAG: VecReplicateScalar [<<D9>>]
65 /// CHECK-DAG: VecReplicateScalar [<<D10>>]
66 //
67 /// CHECK-FI:
68 private static void encodableConstants(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) {
69 for (int i = 0; i < ARRAY_SIZE; i++) {
70 b[i] += 1;
71 }
72 for (int i = 0; i < ARRAY_SIZE; i++) {
73 s[i] += -128;
74 }
75 for (int i = 0; i < ARRAY_SIZE; i++) {
76 c[i] += 127;
77 }
78 for (int i = 0; i < ARRAY_SIZE; i++) {
79 a[i] += -219;
80 }
81 for (int i = 0; i < ARRAY_SIZE; i++) {
82 a[i] += 219;
83 }
84 for (int i = 0; i < ARRAY_SIZE; i++) {
85 l[i] += 219;
86 }
87 for (int i = 0; i < ARRAY_SIZE; i++) {
88 f[i] += 2.0f;
89 }
90 for (int i = 0; i < ARRAY_SIZE; i++) {
91 f[i] += 14.34f;
92 }
93 for (int i = 0; i < ARRAY_SIZE; i++) {
94 d[i] += 20.0;
95 }
96 for (int i = 0; i < ARRAY_SIZE; i++) {
97 d[i] += 0.0;
98 }
99 }
100
101 /// CHECK-START-ARM64: void Main.SVEIntermediateAddress(int) loop_optimization (after)
102 /// CHECK-DAG: VecLoad loop:<<Loop:B\d+>> outer_loop:none
103 /// CHECK-DAG: VecAdd loop:<<Loop>> outer_loop:none
104 /// CHECK-DAG: VecStore loop:<<Loop>> outer_loop:none
105 //
106 /// CHECK-START-ARM64: void Main.SVEIntermediateAddress(int) instruction_simplifier_arm64 (after)
107 /// CHECK-IF: hasIsaFeature("sve")
108 /// CHECK-DAG: <<IntAddr1:i\d+>> IntermediateAddress [{{l\d+}},{{i\d+}}] loop:<<Loop:B\d+>> outer_loop:none
109 /// CHECK-DAG: VecLoad [<<IntAddr1>>,{{i\d+}},{{j\d+}}] loop:<<Loop>> outer_loop:none
110 /// CHECK-DAG: VecAdd loop:<<Loop>> outer_loop:none
111 /// CHECK-DAG: <<IntAddr2:i\d+>> IntermediateAddress [{{l\d+}},{{i\d+}}] loop:<<Loop>> outer_loop:none
112 /// CHECK-DAG: VecStore [<<IntAddr2>>,{{i\d+}},{{d\d+}},{{j\d+}}] loop:<<Loop>> outer_loop:none
113 /// CHECK-FI:
114 //
115 /// CHECK-START-ARM64: void Main.SVEIntermediateAddress(int) GVN$after_arch (after)
116 /// CHECK-IF: hasIsaFeature("sve")
117 /// CHECK-DAG: <<IntAddr:i\d+>> IntermediateAddress [{{l\d+}},{{i\d+}}] loop:<<Loop:B\d+>> outer_loop:none
118 /// CHECK-DAG: VecLoad [<<IntAddr>>,{{i\d+}},{{j\d+}}] loop:<<Loop>> outer_loop:none
119 /// CHECK-DAG: VecAdd loop:<<Loop>> outer_loop:none
120 /// CHECK-DAG: VecStore [<<IntAddr>>,{{i\d+}},{{d\d+}},{{j\d+}}] loop:<<Loop>> outer_loop:none
121 /// CHECK-FI:
122 static void SVEIntermediateAddress(int x) {
123 for (int i = 0; i < ARRAY_SIZE; i++) {
124 arr[i] += x;
125 }
126 }
127
128 private static int sumArray(byte[] b, short[] s, char[] c, int[] a, long[] l, float[] f, double[] d) {
129 int sum = 0;
130 for (int i = 0; i < ARRAY_SIZE; i++) {
131 sum += b[i] + s[i] + c[i] + a[i] + l[i] + f[i] + d[i];
132 }
133 return sum;
134 }
135
136 public static final int ARRAY_SIZE = 128;
137
138 public static void checkEncodableConstants() {
139 byte[] b = new byte[ARRAY_SIZE];
140 short[] s = new short[ARRAY_SIZE];
141 char[] c = new char[ARRAY_SIZE];
142 int[] a = new int[ARRAY_SIZE];
143 long[] l = new long[ARRAY_SIZE];
144 float[] f = new float[ARRAY_SIZE];
145 double[] d = new double[ARRAY_SIZE];
146
147 encodableConstants(b, s, c, a, l, f, d);
148 expectEquals(32640, sumArray(b, s, c, a, l, f, d));
149
150 System.out.println("encodableConstants passed");
151 }
152
153 public static void checkSVEIntermediateAddress() {
154 arr = new int[ARRAY_SIZE];
155
156 // Setup.
157 for (int i = 0; i < ARRAY_SIZE; i++) {
158 arr[i] = i;
159 }
160
161 // Arithmetic operations.
162 SVEIntermediateAddress(2);
163 for (int i = 0; i < ARRAY_SIZE; i++) {
164 expectEquals(i + 2, arr[i]);
165 }
166
167 System.out.println("SVEIntermediateAddress passed");
168 }
169
170 public static void main(String[] args) {
171 checkEncodableConstants();
172 checkSVEIntermediateAddress();
173 }
174 }