blob: ec60240e903e045cb6b020a415168b5e336ebb29 [file] [log] [blame]
David Brazdilfb502702016-02-02 10:09:14 +00001/*
2 * Copyright (C) 2015 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
17public class Main {
18
19 /// CHECK-START: int Main.BoolCond_IntVarVar(boolean, int, int) register (after)
20 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}]
21
Mark Mendell7c0b44f2016-02-01 10:08:35 -050022 /// CHECK-START-X86_64: int Main.BoolCond_IntVarVar(boolean, int, int) disassembly (after)
23 /// CHECK: <<Cond:z\d+>> ParameterValue
24 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>]
25 /// CHECK: cmovnz/ne
26
David Brazdilfb502702016-02-02 10:09:14 +000027 public static int BoolCond_IntVarVar(boolean cond, int x, int y) {
28 return cond ? x : y;
29 }
30
31 /// CHECK-START: int Main.BoolCond_IntVarCst(boolean, int) register (after)
32 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}]
33
Mark Mendell7c0b44f2016-02-01 10:08:35 -050034 /// CHECK-START-X86_64: int Main.BoolCond_IntVarCst(boolean, int) disassembly (after)
35 /// CHECK: <<Cond:z\d+>> ParameterValue
36 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>]
37 /// CHECK: cmovnz/ne
38
David Brazdilfb502702016-02-02 10:09:14 +000039 public static int BoolCond_IntVarCst(boolean cond, int x) {
40 return cond ? x : 1;
41 }
42
43 /// CHECK-START: int Main.BoolCond_IntCstVar(boolean, int) register (after)
44 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}]
45
Mark Mendell7c0b44f2016-02-01 10:08:35 -050046 /// CHECK-START-X86_64: int Main.BoolCond_IntCstVar(boolean, int) disassembly (after)
47 /// CHECK: <<Cond:z\d+>> ParameterValue
48 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>]
49 /// CHECK: cmovnz/ne
50
David Brazdilfb502702016-02-02 10:09:14 +000051 public static int BoolCond_IntCstVar(boolean cond, int y) {
52 return cond ? 1 : y;
53 }
54
Mark Mendell7c0b44f2016-02-01 10:08:35 -050055 /// CHECK-START: long Main.BoolCond_LongVarVar(boolean, long, long) register (after)
56 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}]
57
58 /// CHECK-START-X86_64: long Main.BoolCond_LongVarVar(boolean, long, long) disassembly (after)
59 /// CHECK: <<Cond:z\d+>> ParameterValue
60 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
61 /// CHECK: cmovnz/neq
62
63 public static long BoolCond_LongVarVar(boolean cond, long x, long y) {
64 return cond ? x : y;
65 }
66
67 /// CHECK-START: long Main.BoolCond_LongVarCst(boolean, long) register (after)
68 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}]
69
70 /// CHECK-START-X86_64: long Main.BoolCond_LongVarCst(boolean, long) disassembly (after)
71 /// CHECK: <<Cond:z\d+>> ParameterValue
72 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
73 /// CHECK: cmovnz/neq
74
75 public static long BoolCond_LongVarCst(boolean cond, long x) {
76 return cond ? x : 1L;
77 }
78
79 /// CHECK-START: long Main.BoolCond_LongCstVar(boolean, long) register (after)
80 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}]
81
82 /// CHECK-START-X86_64: long Main.BoolCond_LongCstVar(boolean, long) disassembly (after)
83 /// CHECK: <<Cond:z\d+>> ParameterValue
84 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
85 /// CHECK: cmovnz/neq
86
87 public static long BoolCond_LongCstVar(boolean cond, long y) {
88 return cond ? 1L : y;
89 }
90
David Brazdilfb502702016-02-02 10:09:14 +000091 /// CHECK-START: float Main.BoolCond_FloatVarVar(boolean, float, float) register (after)
92 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}]
93
94 public static float BoolCond_FloatVarVar(boolean cond, float x, float y) {
95 return cond ? x : y;
96 }
97
98 /// CHECK-START: float Main.BoolCond_FloatVarCst(boolean, float) register (after)
99 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}]
100
101 public static float BoolCond_FloatVarCst(boolean cond, float x) {
102 return cond ? x : 1.0f;
103 }
104
105 /// CHECK-START: float Main.BoolCond_FloatCstVar(boolean, float) register (after)
106 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}]
107
108 public static float BoolCond_FloatCstVar(boolean cond, float y) {
109 return cond ? 1.0f : y;
110 }
111
112 /// CHECK-START: int Main.IntNonmatCond_IntVarVar(int, int, int, int) register (after)
113 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
114 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>]
115
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500116 /// CHECK-START-X86_64: int Main.IntNonmatCond_IntVarVar(int, int, int, int) disassembly (after)
117 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
118 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>]
119 /// CHECK: cmovle/ng
120
David Brazdilfb502702016-02-02 10:09:14 +0000121 public static int IntNonmatCond_IntVarVar(int a, int b, int x, int y) {
122 return a > b ? x : y;
123 }
124
125 /// CHECK-START: int Main.IntMatCond_IntVarVar(int, int, int, int) register (after)
126 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
127 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},{{z\d+}}]
128 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>]
129
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500130 /// CHECK-START-X86_64: int Main.IntMatCond_IntVarVar(int, int, int, int) disassembly (after)
131 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
132 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>]
133 /// CHECK: cmovle/ng
134
David Brazdilfb502702016-02-02 10:09:14 +0000135 public static int IntMatCond_IntVarVar(int a, int b, int x, int y) {
136 int result = (a > b ? x : y);
137 return result + (a > b ? 0 : 1);
138 }
139
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500140 /// CHECK-START: long Main.IntNonmatCond_LongVarVar(int, int, long, long) register (after)
141 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
142 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>]
143
144 /// CHECK-START-X86_64: long Main.IntNonmatCond_LongVarVar(int, int, long, long) disassembly (after)
145 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
146 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>]
147 /// CHECK: cmovle/ngq
148
149 public static long IntNonmatCond_LongVarVar(int a, int b, long x, long y) {
150 return a > b ? x : y;
151 }
152
153 /// CHECK-START: long Main.IntMatCond_LongVarVar(int, int, long, long) register (after)
154 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
155 /// CHECK: <<Sel1:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>]
156 /// CHECK: <<Sel2:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>]
157 /// CHECK: Add [<<Sel2>>,<<Sel1>>]
158
159 /// CHECK-START-X86_64: long Main.IntMatCond_LongVarVar(int, int, long, long) disassembly (after)
160 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}]
161 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
162 /// CHECK: cmovle/ngq
163 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
164 /// CHECK: cmovnz/neq
165
166 public static long IntMatCond_LongVarVar(int a, int b, long x, long y) {
167 long result = (a > b ? x : y);
168 return result + (a > b ? 0L : 1L);
169 }
170
171 /// CHECK-START: long Main.LongNonmatCond_LongVarVar(long, long, long, long) register (after)
172 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}]
173 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
174
175 /// CHECK-START-X86_64: long Main.LongNonmatCond_LongVarVar(long, long, long, long) disassembly (after)
176 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}]
177 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
178 /// CHECK: cmovle/ngq
179
180 public static long LongNonmatCond_LongVarVar(long a, long b, long x, long y) {
181 return a > b ? x : y;
182 }
183
184 /// CHECK-START: long Main.LongMatCond_LongVarVar(long, long, long, long) register (after)
185 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}]
186 /// CHECK: <<Sel1:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>]
187 /// CHECK: <<Sel2:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>]
188 /// CHECK: Add [<<Sel2>>,<<Sel1>>]
189
190 /// CHECK-START-X86_64: long Main.LongMatCond_LongVarVar(long, long, long, long) disassembly (after)
191 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}]
192 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
193 /// CHECK: cmovle/ngq
194 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>]
195 /// CHECK: cmovnz/neq
196
197 public static long LongMatCond_LongVarVar(long a, long b, long x, long y) {
198 long result = (a > b ? x : y);
199 return result + (a > b ? 0L : 1L);
200 }
201
David Brazdilfb502702016-02-02 10:09:14 +0000202 /// CHECK-START: int Main.FloatLtNonmatCond_IntVarVar(float, float, int, int) register (after)
203 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}]
204 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>]
205
206 public static int FloatLtNonmatCond_IntVarVar(float a, float b, int x, int y) {
207 return a > b ? x : y;
208 }
209
210 /// CHECK-START: int Main.FloatGtNonmatCond_IntVarVar(float, float, int, int) register (after)
211 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}]
212 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>]
213
214 public static int FloatGtNonmatCond_IntVarVar(float a, float b, int x, int y) {
215 return a < b ? x : y;
216 }
217
218 /// CHECK-START: float Main.FloatGtNonmatCond_FloatVarVar(float, float, float, float) register (after)
219 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}]
220 /// CHECK-NEXT: Select [{{f\d+}},{{f\d+}},<<Cond>>]
221
222 public static float FloatGtNonmatCond_FloatVarVar(float a, float b, float x, float y) {
223 return a < b ? x : y;
224 }
225
226 /// CHECK-START: int Main.FloatLtMatCond_IntVarVar(float, float, int, int) register (after)
227 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}]
228 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>]
229 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>]
230
231 public static int FloatLtMatCond_IntVarVar(float a, float b, int x, int y) {
232 int result = (a > b ? x : y);
233 return result + (a > b ? 0 : 1);
234 }
235
236 /// CHECK-START: int Main.FloatGtMatCond_IntVarVar(float, float, int, int) register (after)
237 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}]
238 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>]
239 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>]
240
241 public static int FloatGtMatCond_IntVarVar(float a, float b, int x, int y) {
242 int result = (a < b ? x : y);
243 return result + (a < b ? 0 : 1);
244 }
245
246 /// CHECK-START: float Main.FloatGtMatCond_FloatVarVar(float, float, float, float) register (after)
247 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual
248 /// CHECK-NEXT: <<Sel:f\d+>> Select [{{f\d+}},{{f\d+}},<<Cond>>]
249 /// CHECK-NEXT: TypeConversion [<<Cond>>]
250
251 public static float FloatGtMatCond_FloatVarVar(float a, float b, float x, float y) {
252 float result = (a < b ? x : y);
253 return result + (a < b ? 0 : 1);
254 }
255
256 public static void assertEqual(int expected, int actual) {
257 if (expected != actual) {
258 throw new Error("Assertion failed: " + expected + " != " + actual);
259 }
260 }
261
262 public static void assertEqual(float expected, float actual) {
263 if (expected != actual) {
264 throw new Error("Assertion failed: " + expected + " != " + actual);
265 }
266 }
267
268 public static void main(String[] args) {
269 assertEqual(5, BoolCond_IntVarVar(true, 5, 7));
270 assertEqual(7, BoolCond_IntVarVar(false, 5, 7));
271 assertEqual(5, BoolCond_IntVarCst(true, 5));
272 assertEqual(1, BoolCond_IntVarCst(false, 5));
273 assertEqual(1, BoolCond_IntCstVar(true, 7));
274 assertEqual(7, BoolCond_IntCstVar(false, 7));
275
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500276 assertEqual(5L, BoolCond_LongVarVar(true, 5L, 7L));
277 assertEqual(7L, BoolCond_LongVarVar(false, 5L, 7L));
278 assertEqual(5L, BoolCond_LongVarCst(true, 5L));
279 assertEqual(1L, BoolCond_LongVarCst(false, 5L));
280 assertEqual(1L, BoolCond_LongCstVar(true, 7L));
281 assertEqual(7L, BoolCond_LongCstVar(false, 7L));
282
David Brazdilfb502702016-02-02 10:09:14 +0000283 assertEqual(5, BoolCond_FloatVarVar(true, 5, 7));
284 assertEqual(7, BoolCond_FloatVarVar(false, 5, 7));
285 assertEqual(5, BoolCond_FloatVarCst(true, 5));
286 assertEqual(1, BoolCond_FloatVarCst(false, 5));
287 assertEqual(1, BoolCond_FloatCstVar(true, 7));
288 assertEqual(7, BoolCond_FloatCstVar(false, 7));
289
290 assertEqual(5, IntNonmatCond_IntVarVar(3, 2, 5, 7));
291 assertEqual(7, IntNonmatCond_IntVarVar(2, 3, 5, 7));
292 assertEqual(5, IntMatCond_IntVarVar(3, 2, 5, 7));
293 assertEqual(8, IntMatCond_IntVarVar(2, 3, 5, 7));
294
295 assertEqual(5, FloatLtNonmatCond_IntVarVar(3, 2, 5, 7));
296 assertEqual(7, FloatLtNonmatCond_IntVarVar(2, 3, 5, 7));
297 assertEqual(7, FloatLtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7));
298 assertEqual(7, FloatLtNonmatCond_IntVarVar(2, Float.NaN, 5, 7));
299
300 assertEqual(5, FloatGtNonmatCond_IntVarVar(2, 3, 5, 7));
301 assertEqual(7, FloatGtNonmatCond_IntVarVar(3, 2, 5, 7));
302 assertEqual(7, FloatGtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7));
303 assertEqual(7, FloatGtNonmatCond_IntVarVar(2, Float.NaN, 5, 7));
304
305 assertEqual(5, FloatGtNonmatCond_FloatVarVar(2, 3, 5, 7));
306 assertEqual(7, FloatGtNonmatCond_FloatVarVar(3, 2, 5, 7));
307 assertEqual(7, FloatGtNonmatCond_FloatVarVar(Float.NaN, 2, 5, 7));
308 assertEqual(7, FloatGtNonmatCond_FloatVarVar(2, Float.NaN, 5, 7));
309
310 assertEqual(5, FloatLtMatCond_IntVarVar(3, 2, 5, 7));
311 assertEqual(8, FloatLtMatCond_IntVarVar(2, 3, 5, 7));
312 assertEqual(8, FloatLtMatCond_IntVarVar(Float.NaN, 2, 5, 7));
313 assertEqual(8, FloatLtMatCond_IntVarVar(2, Float.NaN, 5, 7));
314
315 assertEqual(5, FloatGtMatCond_IntVarVar(2, 3, 5, 7));
316 assertEqual(8, FloatGtMatCond_IntVarVar(3, 2, 5, 7));
317 assertEqual(8, FloatGtMatCond_IntVarVar(Float.NaN, 2, 5, 7));
318 assertEqual(8, FloatGtMatCond_IntVarVar(2, Float.NaN, 5, 7));
319
320 assertEqual(5, FloatGtMatCond_FloatVarVar(2, 3, 5, 7));
321 assertEqual(8, FloatGtMatCond_FloatVarVar(3, 2, 5, 7));
322 assertEqual(8, FloatGtMatCond_FloatVarVar(Float.NaN, 2, 5, 7));
323 assertEqual(8, FloatGtMatCond_FloatVarVar(2, Float.NaN, 5, 7));
324 }
325}