-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathLogicalTest.cpp
404 lines (306 loc) · 12.7 KB
/
LogicalTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*******************************************************************************
* Copyright (c) 2017, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#include "OpCodeTest.hpp"
#include "default_compiler.hpp"
#include "omrformatconsts.h"
int16_t sbyteswap(int16_t l) {
return ((l << 8) & 0xff00)
| ((l >> 8) & 0x00ff);
}
int32_t ineg(int32_t l) {
return -l;
}
int32_t iabs(int32_t l) {
if (l >= 0)
return l;
else
return -1 * l;
}
int32_t ibyteswap(int32_t l) {
return ((l << 24) & 0xff000000)
| ((l << 8) & 0x00ff0000)
| ((l >> 8) & 0x0000ff00)
| ((l >> 24) & 0x000000ff);
}
int32_t ior(int32_t l, int32_t r) {
return l | r;
}
int32_t iand(int32_t l, int32_t r) {
return l & r;
}
int32_t ixor(int32_t l, int32_t r) {
return l ^ r;
}
int64_t lbyteswap(int64_t l) {
return ((l << 56) & 0xff00000000000000)
| ((l << 40) & 0x00ff000000000000)
| ((l << 24) & 0x0000ff0000000000)
| ((l << 8) & 0x000000ff00000000)
| ((l >> 8) & 0x00000000ff000000)
| ((l >> 24) & 0x0000000000ff0000)
| ((l >> 40) & 0x000000000000ff00)
| ((l >> 56) & 0x00000000000000ff);
}
int64_t lor(int64_t l, int64_t r) {
return l | r;
}
int64_t land(int64_t l, int64_t r) {
return l & r;
}
int64_t lxor(int64_t l, int64_t r) {
return l ^ r;
}
int64_t lneg(int64_t l) {
return l == INT64_MIN ? INT64_MIN : -l;
}
class Int16LogicalUnary : public TRTest::UnaryOpTest<int16_t> {};
TEST_P(Int16LogicalUnary, UsingConst) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "sbyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120,
"(method return=Int16"
" (block"
" (ireturn"
" (s2i"
" (%s"
" (sconst %" OMR_PRId16 ") )"
"))))",
param.opcode.c_str(),
param.value);
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int16_t (*)()>();
volatile auto exp = param.oracle(param.value);
volatile auto act = entry_point();
ASSERT_EQ(exp, act);
}
TEST_P(Int16LogicalUnary, UsingLoadParam) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "sbyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120,
"(method return=Int16 args=[Int16]"
" (block"
" (ireturn"
" (s2i"
" (%s"
" (sload parm=0) )"
"))))",
param.opcode.c_str());
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int16_t (*)(int16_t)>();
ASSERT_EQ(param.oracle(param.value), entry_point(param.value));
}
INSTANTIATE_TEST_CASE_P(LogicalTest, Int16LogicalUnary, ::testing::Combine(
::testing::ValuesIn(TRTest::const_values<int16_t>()),
::testing::Values(
std::tuple<const char*, int16_t(*)(int16_t)>("sbyteswap", sbyteswap)
)));
class Int32LogicalUnary : public TRTest::UnaryOpTest<int32_t> {};
TEST_P(Int32LogicalUnary, UsingConst) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "ibyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120, "(method return=Int32 (block (ireturn (%s (iconst %d) ) )))", param.opcode.c_str(), param.value);
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int32_t (*)()>();
volatile auto exp = param.oracle(param.value);
volatile auto act = entry_point();
ASSERT_EQ(exp, act);
}
TEST_P(Int32LogicalUnary, UsingLoadParam) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "ibyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120, "(method return=Int32 args=[Int32] (block (ireturn (%s (iload parm=0) ) )))", param.opcode.c_str());
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int32_t (*)(int32_t)>();
ASSERT_EQ(param.oracle(param.value), entry_point(param.value));
}
INSTANTIATE_TEST_CASE_P(LogicalTest, Int32LogicalUnary, ::testing::Combine(
::testing::ValuesIn(TRTest::const_values<int32_t>()),
::testing::Values(
std::tuple<const char*, int32_t(*)(int32_t)>("ibyteswap", ibyteswap),
std::tuple<const char*, int32_t(*)(int32_t)>("ineg", ineg),
std::tuple<const char*, int32_t(*)(int32_t)>("iabs", iabs)
)));
class Int32LogicalBinary : public TRTest::BinaryOpTest<int32_t> {};
TEST_P(Int32LogicalBinary, UsingConst) {
auto param = TRTest::to_struct(GetParam());
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120, "(method return=Int32 (block (ireturn (%s (iconst %d) (iconst %d)) )))", param.opcode.c_str(), param.lhs, param.rhs);
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int32_t (*)(void)>();
volatile auto exp = param.oracle(param.lhs, param.rhs);
volatile auto act = entry_point();
ASSERT_EQ(exp, act);
}
TEST_P(Int32LogicalBinary, UsingLoadParam) {
auto param = TRTest::to_struct(GetParam());
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120, "(method return=Int32 args=[Int32, Int32] (block (ireturn (%s (iload parm=0) (iload parm=1)) )))", param.opcode.c_str());
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int32_t (*)(int32_t, int32_t)>();
ASSERT_EQ(param.oracle(param.lhs, param.rhs), entry_point(param.lhs, param.rhs));
}
INSTANTIATE_TEST_CASE_P(LogicalTest, Int32LogicalBinary, ::testing::Combine(
::testing::ValuesIn(TRTest::const_value_pairs<int32_t,int32_t>()),
::testing::Values(
std::tuple<const char*, int32_t(*)(int32_t, int32_t)>("ior", ior),
std::tuple<const char*, int32_t(*)(int32_t, int32_t)>("iand", iand),
std::tuple<const char*, int32_t(*)(int32_t, int32_t)>("ixor", ixor)
)));
class Int64LogicalBinary : public TRTest::BinaryOpTest<int64_t> {};
TEST_P(Int64LogicalBinary, UsingConst) {
auto param = TRTest::to_struct(GetParam());
char inputTrees[160] = {0};
std::snprintf(inputTrees, 160,
"(method return=Int64"
" (block"
" (lreturn"
" (%s"
" (lconst %" OMR_PRId64 ")"
" (lconst %" OMR_PRId64 ") ) ) ) )",
param.opcode.c_str(), param.lhs, param.rhs);
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int64_t (*)(void)>();
volatile auto exp = param.oracle(param.lhs, param.rhs);
volatile auto act = entry_point();
ASSERT_EQ(exp, act);
}
TEST_P(Int64LogicalBinary, UsingLoadParam) {
auto param = TRTest::to_struct(GetParam());
char inputTrees[160] = {0};
std::snprintf(inputTrees, 160,
"(method return=Int64 args=[Int64, Int64]"
" (block"
" (lreturn"
" (%s"
" (lload parm=0)"
" (lload parm=1) ) ) ) )",
param.opcode.c_str());
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int64_t (*)(int64_t, int64_t)>();
ASSERT_EQ(param.oracle(param.lhs, param.rhs), entry_point(param.lhs, param.rhs));
}
INSTANTIATE_TEST_CASE_P(LogicalTest, Int64LogicalBinary, ::testing::Combine(
::testing::ValuesIn(TRTest::const_value_pairs<int64_t,int64_t>()),
::testing::Values(
std::tuple<const char*, int64_t(*)(int64_t, int64_t)>("lor", lor),
std::tuple<const char*, int64_t(*)(int64_t, int64_t)>("land", land),
std::tuple<const char*, int64_t(*)(int64_t, int64_t)>("lxor", lxor)
)));
class Int64LogicalUnary : public TRTest::UnaryOpTest<int64_t> {};
TEST_P(Int64LogicalUnary, UsingConst) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "lbyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120,
"(method return=Int64"
" (block"
" (lreturn"
" (%s"
" (lconst %" OMR_PRId64 ") )"
")))",
param.opcode.c_str(),
param.value);
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int64_t (*)()>();
volatile auto exp = param.oracle(param.value);
volatile auto act = entry_point();
ASSERT_EQ(exp, act);
}
TEST_P(Int64LogicalUnary, UsingLoadParam) {
auto param = TRTest::to_struct(GetParam());
if (param.opcode == "lbyteswap") {
SKIP_ON_AARCH64(MissingImplementation);
SKIP_ON_ARM(MissingImplementation);
SKIP_ON_RISCV(MissingImplementation);
}
char inputTrees[120] = {0};
std::snprintf(inputTrees, 120,
"(method return=Int64 args=[Int64]"
" (block"
" (lreturn"
" (%s"
" (lload parm=0) )"
")))",
param.opcode.c_str());
auto trees = parseString(inputTrees);
ASSERT_NOTNULL(trees);
Tril::DefaultCompiler compiler(trees);
ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees;
auto entry_point = compiler.getEntryPoint<int64_t (*)(int64_t)>();
ASSERT_EQ(param.oracle(param.value), entry_point(param.value));
}
INSTANTIATE_TEST_CASE_P(LogicalTest, Int64LogicalUnary, ::testing::Combine(
::testing::ValuesIn(TRTest::const_values<int64_t>()),
::testing::Values(
std::tuple<const char*, int64_t(*)(int64_t)>("lbyteswap", lbyteswap),
std::tuple<const char*, int64_t(*)(int64_t)>("lneg", lneg)
)));