From 0a1546c3e4db8e35abc635734ab868c0a4c2b526 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 23 Aug 2014 23:26:46 -0700 Subject: [PATCH] Adding vector min/max tests. --- tools/alloy-test/alloy-test.gypi | 2 + tools/alloy-test/test_vector_max.cc | 118 ++++++++++++++++++++++++++++ tools/alloy-test/test_vector_min.cc | 117 +++++++++++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 tools/alloy-test/test_vector_max.cc create mode 100644 tools/alloy-test/test_vector_min.cc diff --git a/tools/alloy-test/alloy-test.gypi b/tools/alloy-test/alloy-test.gypi index 560886289..ce7df1e44 100644 --- a/tools/alloy-test/alloy-test.gypi +++ b/tools/alloy-test/alloy-test.gypi @@ -23,6 +23,8 @@ 'alloy-test.cc', 'test_add.cc', 'test_vector_add.cc', + 'test_vector_max.cc', + 'test_vector_min.cc', 'util.h', ], }, diff --git a/tools/alloy-test/test_vector_max.cc b/tools/alloy-test/test_vector_max.cc new file mode 100644 index 000000000..0225c6823 --- /dev/null +++ b/tools/alloy-test/test_vector_max.cc @@ -0,0 +1,118 @@ +/** + ****************************************************************************** + * 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 + +#include + +using namespace alloy; +using namespace alloy::hir; +using namespace alloy::runtime; +using namespace alloy::test; +using alloy::frontend::ppc::PPCContext; + +TEST_CASE("VECTOR_MAX_I8_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT8_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = + vec128b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + ctx->v[5] = vec128b(-100, 1, 100, -3, 4, -5, 60, 7, -80, 9, 10, + INT8_MIN, INT8_MAX, 13, 2, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128b(0, 1, 100, 3, 4, 5, 60, 7, 8, 9, 10, 11, + INT8_MAX, 13, 14, 15)); + }); +} + +TEST_CASE("VECTOR_MAX_I8_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT8_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = + vec128b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + ctx->v[5] = vec128b(-100, 1, 100, -3, 4, -5, 60, 7, -80, 9, 10, + INT8_MIN, INT8_MAX, 13, 2, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128b(-100, 1, 100, -3, 4, -5, 60, 7, -80, 9, + 10, INT8_MIN, INT8_MAX, 13, 14, 15)); + }); +} + +TEST_CASE("VECTOR_MAX_I16_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT16_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128s(0, 1, 2, 3, 4, 5, -6000, 7); + ctx->v[5] = vec128s(-1000, 1, -2000, 3, 4, SHRT_MAX, 6, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128s(0, 1, 2, 3, 4, SHRT_MAX, 6, 7)); + }); +} + +TEST_CASE("VECTOR_MAX_I16_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT16_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128s(0, 1, 2, 3, 4, 5, -6000, 7); + ctx->v[5] = vec128s(-1000, 1, -2000, 3, 4, USHRT_MAX, 6, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == + vec128s(-1000, 1, -2000, 3, 4, USHRT_MAX, -6000, 7)); + }); +} + +TEST_CASE("VECTOR_MAX_I32_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT32_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128i(0, 1, 123, 3); + ctx->v[5] = vec128i(-1000000, 0, INT_MAX, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128i(0, 1, INT_MAX, 3)); + }); +} + +TEST_CASE("VECTOR_MAX_I32_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMax(LoadVR(b, 4), LoadVR(b, 5), INT32_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128i(0, 1, 123, 3); + ctx->v[5] = vec128i(-1000000, 0, UINT_MAX, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128i(-1000000, 1, UINT_MAX, 3)); + }); +} diff --git a/tools/alloy-test/test_vector_min.cc b/tools/alloy-test/test_vector_min.cc new file mode 100644 index 000000000..e82441189 --- /dev/null +++ b/tools/alloy-test/test_vector_min.cc @@ -0,0 +1,117 @@ +/** + ****************************************************************************** + * 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 + +#include + +using namespace alloy; +using namespace alloy::hir; +using namespace alloy::runtime; +using namespace alloy::test; +using alloy::frontend::ppc::PPCContext; + +TEST_CASE("VECTOR_MIN_I8_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT8_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = + vec128b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + ctx->v[5] = vec128b(-100, 1, 100, -3, 4, -5, 60, 7, -80, 9, 10, + INT8_MIN, INT8_MAX, 13, 2, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128b(-100, 1, 2, -3, 4, -5, 6, 7, -80, 9, 10, + INT8_MIN, 12, 13, 2, 0)); + }); +} + +TEST_CASE("VECTOR_MIN_I8_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT8_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = + vec128b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + ctx->v[5] = vec128b(255, 1, 200, -3, 4, -5, 60, 7, -80, 9, 10, 11, + 12, 13, 2, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 2, 0)); + }); +} + +TEST_CASE("VECTOR_MIN_I16_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT16_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128s(0, 1, 2, 3, 4, 5, -6000, 7); + ctx->v[5] = vec128s(-1000, 1, -2000, 3, 4, SHRT_MAX, 6, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128s(-1000, 1, -2000, 3, 4, 5, -6000, 0)); + }); +} + +TEST_CASE("VECTOR_MIN_I16_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT16_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128s(0, 1, 2, 3, 4, 5, -6000, 7); + ctx->v[5] = vec128s(-1000, 1, -2000, 3, 4, USHRT_MAX, 6, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128s(0, 1, 2, 3, 4, 5, 6, 0)); + }); +} + +TEST_CASE("VECTOR_MIN_I32_SIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT32_TYPE)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128i(0, 1, 123, 3); + ctx->v[5] = vec128i(-1000000, 0, INT_MAX, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128i(-1000000, 0, 123, 0)); + }); +} + +TEST_CASE("VECTOR_MIN_I32_UNSIGNED", "[instr]") { + TestFunction test([](hir::HIRBuilder& b) { + StoreVR(b, 3, b.VectorMin(LoadVR(b, 4), LoadVR(b, 5), INT32_TYPE, + ARITHMETIC_UNSIGNED)); + b.Return(); + }); + test.Run([](PPCContext* ctx) { + ctx->v[4] = vec128i(0, 1, 123, 3); + ctx->v[5] = vec128i(-1000000, 0, UINT_MAX, 0); + }, + [](PPCContext* ctx) { + auto result = ctx->v[3]; + REQUIRE(result == vec128i(0, 0, 123, 0)); + }); +}