From df772f57e2e4fb73b2cdc5f7b2b22bd7e02a1f84 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Tue, 28 Dec 2021 13:36:31 +0100 Subject: [PATCH] WIP: interpreter refactoring, part 2. --- cpu/ppc/ppcopcodes.cpp | 36 +++++++++++++++++++++++++++++++++--- debugger/debugger.cpp | 5 +++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index bf56104..6cc6257 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -241,16 +241,25 @@ void dppc_interpreter::ppc_addis() { } void dppc_interpreter::ppc_add() { +/* ppc_grab_regsdab(); ppc_result_d = ppc_result_a + ppc_result_b; if (oe_flag) ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d); if (rc_flag) ppc_changecrf0(ppc_result_d); - ppc_store_result_regd(); + ppc_store_result_regd();*/ + GET_rD_iA_iB(ppc_cur_instruction); + uint32_t result = imm_a + imm_b; + if (oe_flag) + ppc_setsoov(imm_a, ~imm_b, result); + if (rc_flag) + ppc_changecrf0(result); + SET_GPR(reg_d, result); } void dppc_interpreter::ppc_addc() { +/* ppc_grab_regsdab(); ppc_result_d = ppc_result_a + ppc_result_b; ppc_carry(ppc_result_a, ppc_result_d); @@ -260,7 +269,15 @@ void dppc_interpreter::ppc_addc() { if (rc_flag) ppc_changecrf0(ppc_result_d); - ppc_store_result_regd(); + ppc_store_result_regd();*/ + GET_rD_iA_iB(ppc_cur_instruction); + uint32_t result = imm_a + imm_b; + ppc_carry(imm_a, result); + if (oe_flag) + ppc_setsoov(imm_a, ~imm_b, result); + if (rc_flag) + ppc_changecrf0(result); + SET_GPR(reg_d, result); } void dppc_interpreter::ppc_adde() { @@ -747,6 +764,7 @@ void dppc_interpreter::ppc_rlwimi() { } void dppc_interpreter::ppc_rlwinm() { +/* ppc_grab_regssa(); unsigned rot_sh = (ppc_cur_instruction >> 11) & 31; unsigned rot_mb = (ppc_cur_instruction >> 6) & 31; @@ -757,7 +775,19 @@ void dppc_interpreter::ppc_rlwinm() { if ((ppc_cur_instruction & 0x01) == 1) { ppc_changecrf0(ppc_result_a); } - ppc_store_result_rega(); + ppc_store_result_rega();*/ + uint32_t opcode = ppc_cur_instruction; + GET_rA_iS(opcode); + unsigned rot_sh = (opcode >> 11) & 31; + unsigned rot_mb = (opcode >> 6) & 31; + unsigned rot_me = (opcode >> 1) & 31; + uint32_t mask = rot_mask(rot_mb, rot_me); + uint32_t r = ((imm_d << rot_sh) | (imm_d >> (32 - rot_sh))); + r &= mask; + SET_GPR(reg_a, r); + if (ppc_cur_instruction & 1) { + ppc_changecrf0(r); + } } void dppc_interpreter::ppc_rlwnm() { diff --git a/debugger/debugger.cpp b/debugger/debugger.cpp index 86174fc..10f0b98 100644 --- a/debugger/debugger.cpp +++ b/debugger/debugger.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . */ #include +#include #include #include #include @@ -499,7 +500,11 @@ void enter_debugger() { exec_until_68k(addr); #endif } else { + auto start_time = std::chrono::steady_clock::now(); ppc_exec_until(addr); + auto end_time = std::chrono::steady_clock::now(); + auto time_elapsed = std::chrono::duration_cast(end_time - start_time); + LOG_F(INFO, "Time elapsed: %lld ns", time_elapsed.count()); } } catch (invalid_argument& exc) { cout << exc.what() << endl;