--- nono/m680x0/testacc.cpp 2026/04/29 17:05:08 1.1.1.4 +++ nono/m680x0/testacc.cpp 2026/04/29 17:05:30 1.1.1.7 @@ -4,8 +4,8 @@ // Licensed under nono-license.txt // -#include "m68030core.h" -#include "m68030acc.h" +#include "mpu680x0.h" +#include "m680x0acc.h" #include #include @@ -14,8 +14,6 @@ [[noreturn]] void usage(); -static m68kcpu *cpu; - static int argc; // getopt(3) 処理後の argc static char **argv; // getopt(3) 処理後の argv static const char *testname; // 現在のテスト名 @@ -63,7 +61,7 @@ xp_equal(uint32 expected, uint32 actual, // 値(32bitまで)と CCR を検査する static void -xp_equal(uint32 actValue, m68030ccr& actCCR, uint32 expValue, +xp_equal(uint32 actValue, m680x0CCR& actCCR, uint32 expValue, bool expX, bool expN, bool expZ, bool expV, bool expC) { if (expValue != actValue || @@ -97,7 +95,7 @@ xp_equal(uint32 actValue, m68030ccr& act // 値(64bit)と CCR を検査する static void __unused -xp_equal64(uint64 actValue, m68030ccr& actCCR, uint64 expValue, +xp_equal64(uint64 actValue, m680x0CCR& actCCR, uint64 expValue, bool expX, bool expN, bool expZ, bool expV, bool expC) { if (expValue != actValue || @@ -286,7 +284,7 @@ static uint32 add_table[] = { }; static void -test_add(int sz) +test_add(m680x0ACC& acc, int sz) { for (int i = 0; i < countof(add_table); i++) { for (int j = 0; j < countof(add_table); j++) { @@ -302,45 +300,45 @@ test_add(int sz) uint32 actual; if (sz == 8) { - actual = acc_add_8(cpu, src, dst); + actual = acc.add_8(src, dst); } else if (sz == 16) { - actual = acc_add_16(cpu, src, dst); + actual = acc.add_16(src, dst); } else { - actual = acc_add_32(cpu, src, dst); + actual = acc.add_32(src, dst); } - xp_equal(actual, CCR, res, + xp_equal(actual, acc, res, C, ISNEG(res, sz), (res == 0), V, C); } } } static void -test_add_8() +test_add_8(m680x0ACC& acc) { start_test(); - test_add(8); + test_add(acc, 8); end_test(); } static void -test_add_16() +test_add_16(m680x0ACC& acc) { start_test(); - test_add(16); + test_add(acc, 16); end_test(); } static void -test_add_32() +test_add_32(m680x0ACC& acc) { start_test(); - test_add(32); + test_add(acc, 32); end_test(); } static void -test_sub(int sz) +test_sub(m680x0ACC& acc, int sz) { for (int i = 0; i < countof(add_table); i++) { for (int j = 0; j < countof(add_table); j++) { @@ -363,40 +361,40 @@ test_sub(int sz) uint32 actual; if (sz == 8) { - actual = acc_sub_8(cpu, src, dst); + actual = acc.sub_8(src, dst); } else if (sz == 16) { - actual = acc_sub_16(cpu, src, dst); + actual = acc.sub_16(src, dst); } else { - actual = acc_sub_32(cpu, src, dst); + actual = acc.sub_32(src, dst); } - xp_equal(actual, CCR, res, + xp_equal(actual, acc, res, C, ISNEG(res, sz), (res == 0), V, C); } } } static void -test_sub_8() +test_sub_8(m680x0ACC& acc) { start_test(); - test_sub(8); + test_sub(acc, 8); end_test(); } static void -test_sub_16() +test_sub_16(m680x0ACC& acc) { start_test(); - test_sub(16); + test_sub(acc, 16); end_test(); } static void -test_sub_32() +test_sub_32(m680x0ACC& acc) { start_test(); - test_sub(32); + test_sub(acc, 32); end_test(); } @@ -419,7 +417,7 @@ static struct { }; static void -test_addx_32() +test_addx_32(m680x0ACC& acc) { start_test(); for (int i = 0; i < countof(addx32_table); i++) { @@ -431,12 +429,12 @@ test_addx_32() bool expZ = addx32_table[i].expZ; bool expV = addx32_table[i].expV; bool expC = addx32_table[i].expC; - sprintf(where, "%08x + %08x + %d", src, dst, inX); + snprintf(where, sizeof(where), "%08x + %08x + %d", src, dst, inX); - CCR.PutX(inX); - CCR.PutZ(true); - uint32 actual = acc_addx_32(cpu, src, dst); - xp_equal(actual, CCR, res, expC, expN, expZ, expV, expC); + acc.SetX(inX); + acc.SetZ(true); + uint32 actual = acc.addx_32(src, dst); + xp_equal(actual, acc, res, expC, expN, expZ, expV, expC); } end_test(); } @@ -448,14 +446,14 @@ test_addx_32() // ローテート/シフト系のパフォーマンス測定 #define DEFINE_PERF_ROTATE(name) \ static void \ -__CONCAT(perf_,name)() \ +__CONCAT(perf_,name)(m680x0ACC& acc) \ { \ START_PERF; \ volatile uint32 dst = 0; \ for (; perf_signaled == 0;) { \ for (int count = 0; count < 32; count++) { \ uint32 src = xor32(); \ - dst ^= __CONCAT(acc_,name)(cpu, src, count); \ + dst ^= acc.name(src, count); \ perf_count++; \ } \ } \ @@ -472,13 +470,13 @@ DEFINE_PERF_ROTATE(roxr_32) DEFINE_PERF_ROTATE(ror_32) static void -perf_add_32() +perf_add_32(m680x0ACC& acc) { START_PERF; volatile uint32 dst = 0; for (; perf_signaled == 0; ) { uint32 src = xor32(); - dst = acc_add_32(cpu, src, dst); + dst = acc.add_32(src, dst); perf_count++; } END_PERF; @@ -511,31 +509,29 @@ main(int ac, char *av[]) argc = ac; argv = av; - // 本当はコンストラクタを呼ぶべきだが、そうすると必要なオブジェクトが - // 芋づる式に増えて正しく解決するのは面倒。ここのテストではとりあえず - // 存在しててアクセスできればいい程度なのでこれで誤魔化してある。 - cpu = (m68kcpu *)calloc(sizeof(*cpu), 1); + std::unique_ptr accptr(new m680x0ACC()); + m680x0ACC& acc = *(accptr.get()); if (do_test) { - test_add_8(); - test_add_16(); - test_add_32(); - test_sub_8(); - test_sub_16(); - test_sub_32(); - test_addx_32(); + test_add_8(acc); + test_add_16(acc); + test_add_32(acc); + test_sub_8(acc); + test_sub_16(acc); + test_sub_32(acc); + test_addx_32(acc); } if (do_perf) { - perf_asl_32(); - perf_lsl_32(); - perf_roxl_32(); - perf_rol_32(); - perf_asr_32(); - perf_lsr_32(); - perf_roxr_32(); - perf_ror_32(); - perf_add_32(); + perf_asl_32(acc); + perf_lsl_32(acc); + perf_roxl_32(acc); + perf_rol_32(acc); + perf_asr_32(acc); + perf_lsr_32(acc); + perf_roxr_32(acc); + perf_ror_32(acc); + perf_add_32(acc); } return 0;