From 31ad4b28ed2821dce93949d15e2f9805853e6e87 Mon Sep 17 00:00:00 2001 From: dingusdev <52434309+dingusdev@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:25:07 -0700 Subject: [PATCH] Start fixes --- benchmark/bench1.cpp | 2 +- cpu/ppc/ppcexec.cpp | 34 ++++++++++++++++++++++++++++++---- cpu/ppc/ppcfpopcodes.include | 8 ++++---- cpu/ppc/ppcmacros_prototypes.h | 5 ----- cpu/ppc/ppcopcodes.include | 30 ++++++++++++++++++++++++++++-- cpu/ppc/ppcopmacros.h | 15 --------------- cpu/ppc/ppcoptablemacros.h | 17 ++++------------- 7 files changed, 67 insertions(+), 44 deletions(-) diff --git a/benchmark/bench1.cpp b/benchmark/bench1.cpp index 67ad0e1..6dcb8fa 100644 --- a/benchmark/bench1.cpp +++ b/benchmark/bench1.cpp @@ -42,7 +42,7 @@ uint32_t cs_code[] = { 0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914, 0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002, 0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114, - 0x7C650194, /* 0x4E800020 */ 0x00005AF0 + 0x7C650194, 0x4E800020 }; constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max diff --git a/cpu/ppc/ppcexec.cpp b/cpu/ppc/ppcexec.cpp index 4fa511a..2353612 100644 --- a/cpu/ppc/ppcexec.cpp +++ b/cpu/ppc/ppcexec.cpp @@ -222,7 +222,7 @@ void ppc_release_int() { /** Opcode decoding functions. */ -static void ppc_opcode16(uint32_t instr) { +static void ppc_opcode16(uint32_t subop, uint32_t instr) { Opcode16Grabber[instr & 3](instr); } @@ -289,8 +289,6 @@ template void ppc_opcode19(uint32_t); template void ppc_opcode19(uint32_t); void ppc_opcode31(uint32_t instr) { - uint16_t subop_grab = instr & 0x7FFUL; - Opcode31Grabber[subop_grab](instr); } void ppc_opcode59(uint32_t instr) { @@ -311,7 +309,35 @@ void ppc_main_opcode(uint32_t instr) { num_opcodes[instr]++; #endif #endif - OpcodeGrabber[(instr >> 26) & 0x3F](instr); + uint32_t opcode = (instr >> 26) & 63; + switch (opcode) { + case 16: + Opcode16Grabber[instr & 3](instr); + break; + case 18: + Opcode16Grabber[instr & 3](instr); + break; + case 19: + if (is_601) + ppc_opcode19(instr); + else + ppc_opcode19(instr); + break; + case 31: + uint16_t subop_grab = instr & 0x7FFUL; + Opcode31Grabber[subop_grab](instr); + break; + case 59: + uint16_t subop_grab = instr & 0x7FFUL; + Opcode31Grabber[subop_grab](instr); + break; + case 63: + uint16_t subop_grab = instr & 0x7FFUL; + Opcode31Grabber[subop_grab](instr); + break; + default: + OpcodeGrabber[opcode](instr); + } #ifdef CPU_PROFILING uint32_t load_chk = (instr >> 26); diff --git a/cpu/ppc/ppcfpopcodes.include b/cpu/ppc/ppcfpopcodes.include index 8733d27..9349669 100644 --- a/cpu/ppc/ppcfpopcodes.include +++ b/cpu/ppc/ppcfpopcodes.include @@ -583,7 +583,7 @@ OPCODEREC (mtfsfi, 63, 134, } ) -OPCODEREC (mtfsb0, 63, 70, +OPCODE31 (mtfsb0, 63, 70, int crf_d = (instr >> 21) & 0x1F; if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared ppc_state.fpscr &= ~(0x80000000UL >> crf_d); @@ -593,7 +593,7 @@ OPCODEREC (mtfsb0, 63, 70, ppc_update_cr1(); ) -OPCODEREC (mtfsb1, 63, 38, +OPCODE31 (mtfsb1, 63, 38, ppc_grab_crfd(instr); if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set ppc_state.fpscr |= (0x80000000UL >> crf_d); @@ -604,7 +604,7 @@ OPCODEREC (mtfsb1, 63, 38, } ) -OPCODE (mcrfs, 63, 64, +OPCODE31 (mcrfs, 63, 64, ppc_grab_crfds(instr); ppc_state.cr = ( (ppc_state.cr & ~(0xF0000000UL >> crf_d)) | @@ -622,7 +622,7 @@ OPCODE (mcrfs, 63, 64, // Floating Point Comparisons -OPCODE (fcmpo, 63, 32, +OPCODE31 (fcmpo, 63, 32, ppc_grab_regsfpsab(instr); uint32_t cmp_c = 0; diff --git a/cpu/ppc/ppcmacros_prototypes.h b/cpu/ppc/ppcmacros_prototypes.h index 7c8ae07..10cab52 100644 --- a/cpu/ppc/ppcmacros_prototypes.h +++ b/cpu/ppc/ppcmacros_prototypes.h @@ -45,11 +45,6 @@ along with this program. If not, see . template \ void ppc_##op(uint32_t instr); -#undef OPCODECARRY -#define OPCODECARRY(op, grabber, number, ...) \ - template \ - void ppc_##op(uint32_t instr); - #undef OPCODEOVREC #define OPCODEOVREC(op, grabber, number, ...) \ template \ diff --git a/cpu/ppc/ppcopcodes.include b/cpu/ppc/ppcopcodes.include index f5a8d7a..2937419 100644 --- a/cpu/ppc/ppcopcodes.include +++ b/cpu/ppc/ppcopcodes.include @@ -15,7 +15,7 @@ OPCODEREC (addic, , 6, ppc_store_iresult_reg(reg_d, ppc_result_d); ) -OPCODECARRY (add, 31, 10, +OPCODEREC (add, 31, 266, ppc_grab_regsdab(instr); uint32_t ppc_result_d = ppc_result_a + ppc_result_b; @@ -28,6 +28,18 @@ OPCODECARRY (add, 31, 10, ppc_store_iresult_reg(reg_d, ppc_result_d); ) +OPCODEREC (addc, 31, 10, + ppc_grab_regsdab(instr); + uint32_t ppc_result_d = ppc_result_a + ppc_result_b; + + ppc_carry(ppc_result_a, ppc_result_d); + if (ov) + ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d); + if (rec) + ppc_changecrf0(ppc_result_d); + ppc_store_iresult_reg(reg_d, ppc_result_d); +) + OPCODEOVREC (adde, 31, 138, ppc_grab_regsdab(instr); uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA); @@ -97,7 +109,21 @@ OPCODE (subfic, , 8, ppc_store_iresult_reg(reg_d, ppc_result_d); ) -OPCODECARRY (subf, 31, 8, +OPCODEOVREC (subf, 31, 40, + ppc_grab_regsdab(instr); + uint32_t ppc_result_d = ppc_result_b - ppc_result_a; + + if (carry) + ppc_carry_sub(ppc_result_a, ppc_result_b); + if (ov) + ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d); + if (rec) + ppc_changecrf0(ppc_result_d); + + ppc_store_iresult_reg(reg_d, ppc_result_d); +) + +OPCODEOVREC (subfc, 31, 8, ppc_grab_regsdab(instr); uint32_t ppc_result_d = ppc_result_b - ppc_result_a; diff --git a/cpu/ppc/ppcopmacros.h b/cpu/ppc/ppcopmacros.h index 957b73f..cdd79e5 100644 --- a/cpu/ppc/ppcopmacros.h +++ b/cpu/ppc/ppcopmacros.h @@ -63,21 +63,6 @@ along with this program. If not, see . template void dppc_interpreter::ppc_##op(uint32_t instr); \ template void dppc_interpreter::ppc_##op(uint32_t instr); -#undef OPCODECARRY -#define OPCODECARRY(op, grabber, number, ...) \ - template \ - void dppc_interpreter::ppc_##op(uint32_t instr) { \ - __VA_ARGS__ \ - } \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); \ - template void dppc_interpreter::ppc_##op(uint32_t instr); - #undef OPCODEOVREC #define OPCODEOVREC(op, grabber, number, ...) \ template \ diff --git a/cpu/ppc/ppcoptablemacros.h b/cpu/ppc/ppcoptablemacros.h index 1339900..1b02a2c 100644 --- a/cpu/ppc/ppcoptablemacros.h +++ b/cpu/ppc/ppcoptablemacros.h @@ -49,17 +49,6 @@ along with this program. If not, see . Opcode##grabber##Grabber[number + (1 << 9) ] = ppc_##op; \ Opcode##grabber##Grabber[number + (1 << 9) + 1] = ppc_##op; \ -#undef OPCODECARRY -#define OPCODECARRY(op, grabber, number, ...) \ - Opcode##grabber##Grabber[number ] = ppc_##op; \ - Opcode##grabber##Grabber[number + 1] = ppc_##op; \ - Opcode##grabber##Grabber[number + 2] = ppc_##op; \ - Opcode##grabber##Grabber[number + 3] = ppc_##op; \ - Opcode##grabber##Grabber[number + (1 << 10) ] = ppc_##op; \ - Opcode##grabber##Grabber[number + (1 << 10) + 1] = ppc_##op; \ - Opcode##grabber##Grabber[number + (1 << 10) + 2] = ppc_##op; \ - Opcode##grabber##Grabber[number + (1 << 10) + 3] = ppc_##op; - #undef OPCODEOVREC #define OPCODEOVREC(op, grabber, number, ...) \ Opcode##grabber##Grabber[number ] = ppc_##op; \ @@ -90,8 +79,10 @@ along with this program. If not, see . #undef OPCODERECF #define OPCODERECF(op, grabber, number, ...) \ - Opcode##grabber##Grabber[ number << 1 ] = ppc_##op; \ - Opcode##grabber##Grabber[(number << 1) + 1] = ppc_##op; \ + for (int i = 0; i < 2048; i += 32) { \ + Opcode##grabber##Grabber[(number + i) << 1 ] = ppc_##op; \ + Opcode##grabber##Grabber[((number + i) << 1) + 1] = ppc_##op; \ + } #undef POWEROPCODEREC #define POWEROPCODEREC(op, grabber, number, ...) \