Allow the compiler to inline matrix4x4 multiplication. Also add a unit test.

This commit is contained in:
Henrik Rydgård committed 2025-09-02 15:27:18 +02:00
1 parent 0332e67ad4
commit 9b6727e97a
5 files changed
+160 -39

No files matched your search

+75
View File
@@ -81,12 +81,14 @@
#include "Common/Data/Convert/ColorConv.h"
#include "Common/File/VFS/VFS.h"
#include "Common/File/VFS/DirectoryReader.h"
#include "Common/Math/fast/fast_matrix.h"
#include "Core/FileSystems/ISOFileSystem.h"
#include "Core/MemMap.h"
#include "Core/KeyMap.h"
#include "Core/MIPS/MIPSVFPUUtils.h"
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/GPUStateUtils.h"
#include "GPU/Math3D.h"
#include "Common/File/AndroidContentURI.h"
@@ -1229,6 +1231,78 @@ bool TestVolumeFunc() {
EXPECT_TRUE(smaller);
// printf("%d -> %f -> %d -> %f\n", i, mul, vol100, mul2);
}
}
bool TestLinAlg() {
static const float m1[16] = {
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
};
static const float m2[16] = {
56, 0, 24, 2,
0.5f, 35, 2, 4,
1, 6, 1, 2,
4, 0, -1, -4
};
static const float correct[16] = {
298.f, 380.f, 462.f, 544.f,
245.5f, 287.f, 328.5f, 370.f,
66.f, 76.f, 86.f, 96.f,
-57.f, -58.f, -59.f, -60.f,
};
float d[16]{};
fast_matrix_mul_4x4(d, m1, m2);
for (int i = 0; i < 16; i += 4) {
// printf("%0.2f, %0.2f, %0.2f, %0.2f,\n", d[i], d[i + 1], d[i + 2], d[i + 3]);
}
for (int i = 0; i < 16; i++) {
EXPECT_EQ_FLOAT(d[i], correct[i]);
}
// OK, now test 4x3 multiplication.
float a4x4[16];
float b4x4[16];
ConvertMatrix4x3To4x4(a4x4, m1);
ConvertMatrix4x3To4x4(b4x4, m1);
Matrix4ByMatrix4(d, a4x4, b4x4);
for (int i = 0; i < 16; i += 4) {
printf("%0.2f, %0.2f, %0.2f, %0.2f,\n", d[i], d[i + 1], d[i + 2], d[i + 3]);
}
static const float correct4x4[16] = {
30.00, 36.00, 42.00, 0.00,
66.00, 81.00, 96.00, 0.00,
102.00, 126.00, 150.00, 0.00,
148.00, 182.00, 216.00, 1.00,
};
for (int i = 0; i < 16; i++) {
EXPECT_EQ_FLOAT(d[i], correct4x4[i]);
}
ConvertMatrix4x3To4x4Transposed(b4x4, m1);
Matrix4ByMatrix4(d, a4x4, b4x4);
static const float correct4x4transposed[16] = {
14.00, 32.00, 50.00, 68.00,
32.00, 77.00, 122.00, 167.00,
50.00, 122.00, 194.00, 266.00,
68.00, 167.00, 266.00, 366.00,
};
for (int i = 0; i < 16; i++) {
EXPECT_EQ_FLOAT(d[i], correct4x4transposed[i]);
}
// TODO: Add direct 4x3 x 4x3 multiplication
return true;
}
@@ -1301,6 +1375,7 @@ TestItem availableTests[] = {
TEST_ITEM(SIMD),
TEST_ITEM(CrossSIMD),
TEST_ITEM(VolumeFunc),
TEST_ITEM(LinAlg),
};
int main(int argc, const char *argv[]) {