Add vector projection test

This commit is contained in:
Madeline Busig 2024-09-19 18:10:05 -07:00
parent 982752404e
commit 8f30ed4311
2 changed files with 29 additions and 0 deletions

View File

@ -39,6 +39,8 @@ public:
add_test(&transpose_v2, "transpose_v2");
add_test(&transpose_v3, "transpose_v3");
add_test(&transpose_v4, "transpose_v4");
add_test(&projection_v4, "projection_v4");
}
virtual string_view name() {
@ -92,6 +94,8 @@ public:
GBA_IWRAM ARM_MODE static bool transpose_v2();
GBA_IWRAM ARM_MODE static bool transpose_v3();
GBA_IWRAM ARM_MODE static bool transpose_v4();
GBA_IWRAM ARM_MODE static bool projection_v4();
};
} // namespace test

View File

@ -342,6 +342,31 @@ bool vec_suite::transpose_v4() {
return true;
}
bool vec_suite::projection_v4() {
struct {
NOINLINE GBA_IWRAM ARM_MODE
vec4 operator()(vec4 a, vec4 b) {
start_timer();
vec4 r = b * (a * b) / b.magnitude_sqr();
end_timer();
return r;
}
} f;
vec4 a(8, 3, 7, 0);
vec4 b(-3, 4, 14, 0);
vec4 c = f(a, b);
vec4 exp(fixed::from_raw(-74), fixed::from_raw(99), fixed::from_raw(348), 0);
log::debug << "A = " << a << endl;
log::debug << "B = " << b << endl;
log::debug << "C = proj(A, B) = " << c << endl;
return c == exp;
}
} // namespace test
} // namespace mtl