Starting tests. This is going to take some time.

This commit is contained in:
Ben Vanik 2014-08-23 17:09:19 -07:00
parent 423790209b
commit 96007049d2
5 changed files with 627 additions and 50 deletions

View File

@ -58,6 +58,34 @@ static inline vec128_t vec128f(float x, float y, float z, float w) {
v.f4[3] = w;
return v;
}
static inline vec128_t vec128s(uint16_t src) {
vec128_t v;
for (auto i = 0; i < 8; ++i) {
v.s8[i] = src;
}
return v;
}
static inline vec128_t vec128s(uint16_t x0, uint16_t x1, uint16_t y0,
uint16_t y1, uint16_t z0, uint16_t z1,
uint16_t w0, uint16_t w1) {
vec128_t v;
v.s8[0] = x0;
v.s8[1] = x1;
v.s8[2] = y0;
v.s8[3] = y1;
v.s8[4] = z0;
v.s8[5] = z1;
v.s8[6] = w0;
v.s8[7] = w1;
return v;
}
static inline vec128_t vec128b(uint8_t src) {
vec128_t v;
for (auto i = 0; i < 16; ++i) {
v.b16[i] = src;
}
return v;
}
static inline vec128_t vec128b(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3,
uint8_t y0, uint8_t y1, uint8_t y2, uint8_t y3,
uint8_t z0, uint8_t z1, uint8_t z2, uint8_t z3,

View File

@ -10,44 +10,32 @@
#define CATCH_CONFIG_RUNNER
#include <third_party/catch/single_include/catch.hpp>
#include <tools/alloy-test/test_util.h>
#include <tools/alloy-test/util.h>
namespace alloy {
namespace test {
using namespace alloy;
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::frontend::ppc::PPCContext;
using alloy::runtime::Runtime;
Value* LoadGPR(hir::HIRBuilder& b, int reg) {
return b.LoadContext(offsetof(PPCContext, r) + reg * 8, INT64_TYPE);
int main(std::vector<std::wstring>& args) {
std::vector<std::string> narrow_args;
auto narrow_argv = new char* [args.size()];
for (size_t i = 0; i < args.size(); ++i) {
auto narrow_arg = poly::to_string(args[i]);
narrow_argv[i] = const_cast<char*>(narrow_arg.data());
narrow_args.push_back(std::move(narrow_arg));
}
int ret = Catch::Session().run(int(args.size()), narrow_argv);
if (ret) {
if (poly::debugging::IsDebuggerAttached()) {
poly::debugging::Break();
}
}
return ret;
}
void StoreGPR(hir::HIRBuilder& b, int reg, Value* value) {
b.StoreContext(offsetof(PPCContext, r) + reg * 8, value);
}
TEST_CASE("ADD", "[instr]") {
alloy::test::TestFunction test([](hir::HIRBuilder& b) {
auto v = b.Add(LoadGPR(b, 4), LoadGPR(b, 5));
StoreGPR(b, 3, v);
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0x23);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0x24);
});
}
} // namespace test
} // namespace alloy
DEFINE_ENTRY_POINT(L"alloy-test", L"?", alloy::test::main);

View File

@ -22,7 +22,9 @@
'sources': [
'alloy-test.cc',
'test_util.h',
'test_add.cc',
'test_vector_add.cc',
'util.h',
],
},
],

View File

@ -0,0 +1,550 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <tools/alloy-test/util.h>
using namespace alloy;
using namespace alloy::hir;
using namespace alloy::runtime;
using namespace alloy::test;
using alloy::frontend::ppc::PPCContext;
TEST_CASE("ADD_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreGPR(b, 3, b.ZeroExtend(b.Add(b.Truncate(LoadGPR(b, 4), INT8_TYPE),
b.Truncate(LoadGPR(b, 5), INT8_TYPE)),
INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == 0x23);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = -10;
ctx->r[5] = -5;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == -15);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT8_MIN;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == INT8_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT8_MAX;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<uint8_t>(ctx->r[3]);
REQUIRE(result == UINT8_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT8_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == INT8_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT8_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = static_cast<int8_t>(ctx->r[3]);
REQUIRE(result == 0);
});
}
TEST_CASE("ADD_I8_CARRY", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
auto v = b.Add(b.Truncate(LoadGPR(b, 4), INT8_TYPE),
b.Truncate(LoadGPR(b, 5), INT8_TYPE), ARITHMETIC_SET_CARRY);
StoreGPR(b, 3, b.ZeroExtend(b.DidCarry(v), INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT8_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT8_MAX;
ctx->r[5] = UINT8_MAX;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT8_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
}
TEST_CASE("ADD_I16", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreGPR(b, 3, b.ZeroExtend(b.Add(b.Truncate(LoadGPR(b, 4), INT16_TYPE),
b.Truncate(LoadGPR(b, 5), INT16_TYPE)),
INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == 0x23);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = -10;
ctx->r[5] = -5;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == -15);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT16_MIN;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == INT16_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT16_MAX;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<uint16_t>(ctx->r[3]);
REQUIRE(result == UINT16_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT16_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == INT16_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT16_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = static_cast<int16_t>(ctx->r[3]);
REQUIRE(result == 0);
});
}
TEST_CASE("ADD_I16_CARRY", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
auto v = b.Add(b.Truncate(LoadGPR(b, 4), INT16_TYPE),
b.Truncate(LoadGPR(b, 5), INT16_TYPE), ARITHMETIC_SET_CARRY);
StoreGPR(b, 3, b.ZeroExtend(b.DidCarry(v), INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT16_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT16_MAX;
ctx->r[5] = UINT16_MAX;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT16_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
}
TEST_CASE("ADD_I32", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreGPR(b, 3, b.ZeroExtend(b.Add(b.Truncate(LoadGPR(b, 4), INT32_TYPE),
b.Truncate(LoadGPR(b, 5), INT32_TYPE)),
INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == 0x23);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = -10;
ctx->r[5] = -5;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == -15);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT32_MIN;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == INT32_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT32_MAX;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = static_cast<uint32_t>(ctx->r[3]);
REQUIRE(result == UINT32_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT32_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == INT32_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT32_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = static_cast<int32_t>(ctx->r[3]);
REQUIRE(result == 0);
});
}
TEST_CASE("ADD_I32_CARRY", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
auto v = b.Add(b.Truncate(LoadGPR(b, 4), INT32_TYPE),
b.Truncate(LoadGPR(b, 5), INT32_TYPE), ARITHMETIC_SET_CARRY);
StoreGPR(b, 3, b.ZeroExtend(b.DidCarry(v), INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT32_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT32_MAX;
ctx->r[5] = UINT32_MAX;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT32_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
}
TEST_CASE("ADD_I64", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreGPR(b, 3, b.Add(LoadGPR(b, 4), LoadGPR(b, 5)));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 10;
ctx->r[5] = 25;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0x23);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = -10;
ctx->r[5] = -5;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == -15);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT64_MIN;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == INT64_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT64_MAX;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == UINT64_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT64_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == INT64_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT64_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
}
TEST_CASE("ADD_I64_CARRY", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
auto v = b.Add(b.Truncate(LoadGPR(b, 4), INT64_TYPE),
b.Truncate(LoadGPR(b, 5), INT64_TYPE), ARITHMETIC_SET_CARRY);
StoreGPR(b, 3, b.ZeroExtend(b.DidCarry(v), INT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = 0;
ctx->r[5] = 0;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 0);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT64_MAX;
ctx->r[5] = 1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = UINT64_MAX;
ctx->r[5] = UINT64_MAX;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
test.Run([](PPCContext* ctx) {
ctx->r[4] = INT64_MIN;
ctx->r[5] = -1;
},
[](PPCContext* ctx) {
auto result = ctx->r[3];
REQUIRE(result == 1);
});
}
TEST_CASE("ADD_F32", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreFPR(b, 3, b.Convert(b.Add(b.Convert(LoadFPR(b, 4), FLOAT32_TYPE),
b.Convert(LoadFPR(b, 5), FLOAT32_TYPE)),
FLOAT64_TYPE));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = 0.0;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == 0.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = 5.0;
ctx->f[5] = 7.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == 12.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = FLT_MAX / 2.0;
ctx->f[5] = FLT_MAX / 2.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == FLT_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = -100.0;
ctx->f[5] = -150.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == -250.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = FLT_MIN;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == FLT_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = FLT_MAX;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == FLT_MAX);
});
}
TEST_CASE("ADD_F64", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) {
StoreFPR(b, 3, b.Add(LoadFPR(b, 4), LoadFPR(b, 5)));
b.Return();
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = 0.0;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == 0.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = 5.0;
ctx->f[5] = 7.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == 12.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = DBL_MAX / 2.0;
ctx->f[5] = DBL_MAX / 2.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == DBL_MAX);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = -100.0;
ctx->f[5] = -150.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == -250.0);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = DBL_MIN;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == DBL_MIN);
});
test.Run([](PPCContext* ctx) {
ctx->f[4] = DBL_MAX;
ctx->f[5] = 0.0;
},
[](PPCContext* ctx) {
auto result = ctx->f[3];
REQUIRE(result == DBL_MAX);
});
}

View File

@ -7,8 +7,8 @@
******************************************************************************
*/
#ifndef ALLOY_TEST_TEST_UTIL_H_
#define ALLOY_TEST_TEST_UTIL_H_
#ifndef ALLOY_TEST_UTIL_H_
#define ALLOY_TEST_UTIL_H_
#include <alloy/alloy.h>
#include <alloy/backend/ivm/ivm_backend.h>
@ -28,18 +28,6 @@ namespace test {
using alloy::frontend::ppc::PPCContext;
using alloy::runtime::Runtime;
int main(std::vector<std::wstring>& args) {
std::vector<std::string> narrow_args;
auto narrow_argv = new char* [args.size()];
for (size_t i = 0; i < args.size(); ++i) {
auto narrow_arg = poly::to_string(args[i]);
narrow_argv[i] = const_cast<char*>(narrow_arg.data());
narrow_args.push_back(std::move(narrow_arg));
}
int ret = Catch::Session().run(int(args.size()), narrow_argv);
return ret;
}
class ThreadState : public alloy::runtime::ThreadState {
public:
ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address,
@ -159,7 +147,28 @@ class TestFunction {
std::vector<std::unique_ptr<Runtime>> runtimes;
};
inline hir::Value* LoadGPR(hir::HIRBuilder& b, int reg) {
return b.LoadContext(offsetof(PPCContext, r) + reg * 8, hir::INT64_TYPE);
}
inline void StoreGPR(hir::HIRBuilder& b, int reg, hir::Value* value) {
b.StoreContext(offsetof(PPCContext, r) + reg * 8, value);
}
inline hir::Value* LoadFPR(hir::HIRBuilder& b, int reg) {
return b.LoadContext(offsetof(PPCContext, f) + reg * 8, hir::FLOAT64_TYPE);
}
inline void StoreFPR(hir::HIRBuilder& b, int reg, hir::Value* value) {
b.StoreContext(offsetof(PPCContext, f) + reg * 8, value);
}
inline hir::Value* LoadVR(hir::HIRBuilder& b, int reg) {
return b.LoadContext(offsetof(PPCContext, v) + reg * 16, hir::VEC128_TYPE);
}
inline void StoreVR(hir::HIRBuilder& b, int reg, hir::Value* value) {
b.StoreContext(offsetof(PPCContext, v) + reg * 16, value);
}
} // namespace test
} // namespace alloy
#endif // ALLOY_TEST_TEST_UTIL_H_
#endif // ALLOY_TEST_UTIL_H_