Adding vector min/max tests.

This commit is contained in:
Ben Vanik 2014-08-23 23:26:46 -07:00
parent 6b0f49454d
commit 0a1546c3e4
3 changed files with 237 additions and 0 deletions

View File

@ -23,6 +23,8 @@
'alloy-test.cc', 'alloy-test.cc',
'test_add.cc', 'test_add.cc',
'test_vector_add.cc', 'test_vector_add.cc',
'test_vector_max.cc',
'test_vector_min.cc',
'util.h', 'util.h',
], ],
}, },

View File

@ -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 <tools/alloy-test/util.h>
#include <cfloat>
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));
});
}

View File

@ -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 <tools/alloy-test/util.h>
#include <cfloat>
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));
});
}