From 97a9c375f99071ce953edd25d48c734ce7390796 Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 22 Sep 2010 02:42:17 +0000 Subject: [PATCH] JitIL/Jit64: Removed std::vector for speed up. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6222 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp | 8 +++++--- Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp | 8 +++++--- Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp | 15 ++++++++++++--- Source/Core/Core/Src/PowerPC/PPCAnalyst.h | 5 ++++- Source/Core/DebuggerWX/Src/JitWindow.cpp | 6 ++++-- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp index ffc455f524..99974085e3 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp @@ -437,11 +437,13 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc //Analyze the block, collect all instructions it is made of (including inlining, //if that is enabled), reorder instructions for optimal performance, and join joinable instructions. u32 nextPC = em_address; - std::vector merged_addresses; + u32 merged_addresses[32]; + const int capacity_of_merged_addresses = sizeof(merged_addresses) / sizeof(merged_addresses[0]); + int size_of_merged_addresses; if (!memory_exception) { // If there is a memory exception inside a block (broken_block==true), compile up to that instruction. - nextPC = PPCAnalyst::Flatten(em_address, &size, &js.st, &js.gpa, &js.fpa, broken_block, code_buf, blockSize, merged_addresses); + nextPC = PPCAnalyst::Flatten(em_address, &size, &js.st, &js.gpa, &js.fpa, broken_block, code_buf, blockSize, merged_addresses, capacity_of_merged_addresses, size_of_merged_addresses); } PPCAnalyst::CodeOp *ops = code_buf->codebuffer; @@ -498,7 +500,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc js.downcountAmount = 0; if (!Core::g_CoreStartupParameter.bEnableDebugging) { - for (unsigned int i = 0; i < merged_addresses.size(); ++i) + for (unsigned int i = 0; i < size_of_merged_addresses; ++i) { const u32 address = merged_addresses[i]; js.downcountAmount += PatchEngine::GetSpeedhackCycles(address); diff --git a/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp index 2650d2a64f..d26b99c78e 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp @@ -429,11 +429,13 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc //Analyze the block, collect all instructions it is made of (including inlining, //if that is enabled), reorder instructions for optimal performance, and join joinable instructions. b->exitAddress[0] = em_address; - std::vector merged_addresses; + u32 merged_addresses[32]; + const int capacity_of_merged_addresses = sizeof(merged_addresses) / sizeof(merged_addresses[0]); + int size_of_merged_addresses; if (!memory_exception) { // If there is a memory exception inside a block (broken_block==true), compile up to that instruction. - b->exitAddress[0] = PPCAnalyst::Flatten(em_address, &size, &js.st, &js.gpa, &js.fpa, broken_block, code_buf, blockSize, merged_addresses); + b->exitAddress[0] = PPCAnalyst::Flatten(em_address, &size, &js.st, &js.gpa, &js.fpa, broken_block, code_buf, blockSize, merged_addresses, capacity_of_merged_addresses, size_of_merged_addresses); } PPCAnalyst::CodeOp *ops = code_buf->codebuffer; @@ -472,7 +474,7 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc js.downcountAmount = 0; if (!Core::g_CoreStartupParameter.bEnableDebugging) { - for (unsigned int i = 0; i < merged_addresses.size(); ++i) + for (unsigned int i = 0; i < size_of_merged_addresses; ++i) { const u32 address = merged_addresses[i]; js.downcountAmount += PatchEngine::GetSpeedhackCycles(address); diff --git a/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp index e87ba79e1d..5de88c305c 100644 --- a/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/Src/PowerPC/PPCAnalyst.cpp @@ -285,9 +285,18 @@ bool CanSwapAdjacentOps(const CodeOp &a, const CodeOp &b) // Does not yet perform inlining - although there are plans for that. // Returns the exit address of the next PC -u32 Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, BlockRegStats *fpa, bool &broken_block, CodeBuffer *buffer, int blockSize, std::vector& merged_addresses) +u32 Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, + BlockRegStats *fpa, bool &broken_block, CodeBuffer *buffer, + int blockSize, u32* merged_addresses, + int capacity_of_merged_addresses, int& size_of_merged_addresses) { - merged_addresses.push_back(address); + if (capacity_of_merged_addresses < FUNCTION_FOLLOWING_THRESHOLD) { + PanicAlert("capacity of merged_addresses is too small!"); + } + std::fill_n(merged_addresses, capacity_of_merged_addresses, 0); + merged_addresses[0] = address; + size_of_merged_addresses = 1; + memset(st, 0, sizeof(st)); // Disabled the following optimization in preference of FAST_ICACHE @@ -475,7 +484,7 @@ u32 Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, Bloc // because bx may store a certain value to the link register. // Instead, we skip a part of bx in Jit**::bx(). address = destination; - merged_addresses.push_back(address); + merged_addresses[size_of_merged_addresses++] = address; } } else diff --git a/Source/Core/Core/Src/PowerPC/PPCAnalyst.h b/Source/Core/Core/Src/PowerPC/PPCAnalyst.h index 3eecc263c9..be1b6b7d6a 100644 --- a/Source/Core/Core/Src/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/Src/PowerPC/PPCAnalyst.h @@ -108,7 +108,10 @@ public: }; -u32 Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, BlockRegStats *fpa, bool &broken_block, CodeBuffer *buffer, int blockSize, std::vector& merged_addresses); +u32 Flatten(u32 address, int *realsize, BlockStats *st, BlockRegStats *gpa, + BlockRegStats *fpa, bool &broken_block, CodeBuffer *buffer, + int blockSize, u32* merged_addresses, + int capacity_of_merged_addresses, int& size_of_merged_addresses); void LogFunctionCall(u32 addr); void FindFunctions(u32 startAddr, u32 endAddr, PPCSymbolDB *func_db); bool AnalyzeFunction(u32 startAddr, Symbol &func, int max_size = 0); diff --git a/Source/Core/DebuggerWX/Src/JitWindow.cpp b/Source/Core/DebuggerWX/Src/JitWindow.cpp index f78a2646ef..d5e668fd23 100644 --- a/Source/Core/DebuggerWX/Src/JitWindow.cpp +++ b/Source/Core/DebuggerWX/Src/JitWindow.cpp @@ -177,8 +177,10 @@ void CJitWindow::Compare(u32 em_address) PPCAnalyst::BlockRegStats gpa; PPCAnalyst::BlockRegStats fpa; bool broken_block = false; - std::vector merged_addresses; - if (PPCAnalyst::Flatten(ppc_addr, &size, &st, &gpa, &fpa, broken_block, &code_buffer, size, merged_addresses) != 0xffffffff) + u32 merged_addresses[32]; + const int capacity_of_merged_addresses = sizeof(merged_addresses) / sizeof(merged_addresses[0]); + int size_of_merged_addresses; + if (PPCAnalyst::Flatten(ppc_addr, &size, &st, &gpa, &fpa, broken_block, &code_buffer, size, merged_addresses, capacity_of_merged_addresses, size_of_merged_addresses) != 0xffffffff) { sptr = (char*)xDis; for (int i = 0; i < size; i++)