client/tests/matrix4.c (2525B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_3B0044A0(void); 5 void sub_3B004580(void); 6 recomp_func_t recomp_lookup(uint32_t address) { abort(); } 7 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 8 9 static void test_product(unsigned mode) 10 { 11 const float left[] = {1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16}; 12 const float right[] = {16,15,14,13, 12,11,10,9, 8,7,6,5, 4,3,2,1}; 13 memcpy((void *)ADDR(0x50000000), left, sizeof(left)); 14 memcpy((void *)ADDR(0x50000040), right, sizeof(right)); 15 g_esp = 0x5000ff00; 16 g_ecx = 0x50000000; 17 g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456; 18 g_fp_top = 6; 19 for (unsigned i = 0; i < 8; ++i) { g_st[i] = i + .25; g_st_i64[i] = i + 123; } 20 /* In-place, separate output, and output aliasing the right operand. */ 21 MEM32(g_esp + 4) = mode == 1 ? 0x50000080 : 0x50000040; 22 MEM32(g_esp + 8) = 0x50000040; 23 24 if (mode == 0) sub_3B0044A0(); 25 else sub_3B004580(); 26 27 const float expected[] = {80,70,60,50, 240,214,188,162, 28 400,358,316,274, 560,502,444,386}; 29 assert(g_eax == (mode == 0 ? 0x50000000 : mode == 1 ? 0x50000080 : 0x50000040)); 30 assert(!memcmp((void *)ADDR(g_eax), expected, sizeof(expected))); 31 assert(g_esp == (mode == 0 ? 0x5000ff08 : 0x5000ff0c)); 32 assert(g_ecx == 0 && g_edx == (mode == 0 ? 0x50000048 : 0x5000fef8)); 33 assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456); 34 assert(g_fp_top == 6 && g_st[0] == .25 && g_st[5] == 5.25); 35 assert(g_st_i64[0] == 123 && g_st_i64[5] == 128); 36 assert(g_st[6] == 0 && g_st[7] == 0 && g_st_i64[6] == 0 && g_st_i64[7] == 0); 37 assert(g_flag_k == FK_DEC && g_flag_a == 1 && g_flag_b == 1 && g_flag_cf == 0); 38 } 39 40 static void test_rounding(void) 41 { 42 const float left[] = {16777216,1,-16777216,1, 0,0,0,0, 0,0,0,0, 0,0,0,0}; 43 const float right[] = {1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1}; 44 memcpy((void *)ADDR(0x50000000), left, sizeof(left)); 45 memcpy((void *)ADDR(0x50000040), right, sizeof(right)); 46 g_esp = 0x5000ff00; 47 g_ecx = 0x50000000; 48 MEM32(g_esp + 4) = 0x50000040; 49 50 sub_3B0044A0(); 51 52 const float expected[] = {2,2,2,2, 0,0,0,0, 0,0,0,0, 0,0,0,0}; 53 assert(!memcmp((void *)ADDR(0x50000000), expected, sizeof(expected))); 54 } 55 56 int main(void) 57 { 58 assert(guest_map("matrix fixture", 0x50000000, 0x10000)); 59 for (unsigned mode = 0; mode < 3; ++mode) test_product(mode); 60 test_rounding(); 61 puts("matrix4: multiplication, aliases, rounding and guest ABI passed"); 62 }