Skip to content

Commit

Permalink
Add byteswap Tril tests
Browse files Browse the repository at this point in the history
New Tril tests have now been added to test the sbyteswap, ibyteswap, and
lbyteswap opcodes.

Signed-off-by: Ben Thomas <ben@benthomas.ca>
  • Loading branch information
aviansie-ben committed Sep 14, 2020
1 parent f5e75be commit c58cb61
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions fvtest/compilertriltest/LogicalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#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;
}
Expand All @@ -35,6 +40,13 @@ int32_t iabs(int32_t l) {
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;
}
Expand All @@ -47,6 +59,17 @@ 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;
}
Expand All @@ -63,11 +86,92 @@ 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);
Expand All @@ -87,6 +191,12 @@ TEST_P(Int32LogicalUnary, UsingConst) {
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());

Expand All @@ -105,6 +215,7 @@ TEST_P(Int32LogicalUnary, UsingLoadParam) {
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)
)));
Expand Down Expand Up @@ -223,6 +334,12 @@ 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"
Expand Down Expand Up @@ -251,6 +368,12 @@ TEST_P(Int64LogicalUnary, UsingConst) {
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]"
Expand All @@ -276,5 +399,6 @@ TEST_P(Int64LogicalUnary, UsingLoadParam) {
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)
)));

0 comments on commit c58cb61

Please sign in to comment.