Huge set of performance improvements, combined with an architecture specific build and clang-cl users have reported absurd gains over master for some gains, in the range 50%-90%
But for normal msvc builds i would put it at around 30-50% Added per-xexmodule caching of information per instruction, can be used to remember what code needs compiling at start up Record what guest addresses wrote mmio and backpropagate that to future runs, eliminating dependence on exception trapping. this makes many games like h3 actually tolerable to run under a debugger fixed a number of errors where temporaries were being passed by reference/pointer Can now be compiled with clang-cl 14.0.1, requires -Werror off though and some other solution/project changes. Added macros wrapping compiler extensions like noinline, forceinline, __expect, and cold. Removed the "global lock" in guest code completely. It does not properly emulate the behavior of mfmsrd/mtmsr and it seriously cripples amd cpus. Removing this yielded around a 3x speedup in Halo Reach for me. Disabled the microprofiler for now. The microprofiler has a huge performance cost associated with it. Developers can re-enable it in the base/profiling header if they really need it Disable the trace writer in release builds. despite just returning after checking if the file was open the trace functions were consuming about 0.60% cpu time total Add IsValidReg, GetRegisterInfo is a huge (about 45k) branching function and using that to check if a register was valid consumed a significant chunk of time Optimized RingBuffer::ReadAndSwap and RingBuffer::read_count. This gave us the largest overall boost in performance. The memcpies were unnecessary and one of them was always a no-op Added simplification rules for multiplicative patterns like (x+x), (x<<1)+x For the most frequently called win32 functions i added code to call their underlying NT implementations, which lets us skip a lot of MS code we don't care about/isnt relevant to our usecases ^this can be toggled off in the platform_win header handle indirect call true with constant function pointer, was occurring in h3 lookup host format swizzle in denser array by default, don't check if a gpu register is unknown, instead just check if its out of range. controlled by a cvar ^looking up whether its known or not took approx 0.3% cpu time Changed some things in /cpu to make the project UNITYBUILD friendly The timer thread was spinning way too much and consuming a ton of cpu, changed it to use a blocking wait instead tagged some conditions as XE_UNLIKELY/LIKELY based on profiler feedback (will only affect clang builds) Shifted around some code in CommandProcessor::WriteRegister based on how frequently it was executed added support for docdecaduple precision floating point so that we can represent our performance gains numerically tons of other stuff im probably forgetting
This commit is contained in:
@@ -14,13 +14,16 @@
|
||||
#include "third_party/fmt/include/fmt/format.h"
|
||||
|
||||
#include "xenia/base/byte_order.h"
|
||||
#include "xenia/base/cvar.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/memory.h"
|
||||
|
||||
#include "xenia/cpu/cpu_flags.h"
|
||||
#include "xenia/cpu/export_resolver.h"
|
||||
#include "xenia/cpu/lzx.h"
|
||||
#include "xenia/cpu/processor.h"
|
||||
#include "xenia/emulator.h"
|
||||
#include "xenia/kernel/kernel_state.h"
|
||||
#include "xenia/kernel/xmodule.h"
|
||||
|
||||
@@ -29,6 +32,14 @@
|
||||
#include "third_party/crypto/rijndael-alg-fst.h"
|
||||
#include "third_party/pe/pe_image.h"
|
||||
|
||||
DEFINE_bool(disable_instruction_infocache, false,
|
||||
"Disables caching records of called instructions/mmio accesses.",
|
||||
"CPU");
|
||||
DEFINE_bool(disable_function_precompilation, true,
|
||||
"Disables pre-compiling guest functions that we know we've called "
|
||||
"on previous runs",
|
||||
"CPU");
|
||||
|
||||
static const uint8_t xe_xex2_retail_key[16] = {
|
||||
0x20, 0xB1, 0x85, 0xA5, 0x9D, 0x28, 0xFD, 0xC3,
|
||||
0x40, 0x58, 0x3F, 0xBB, 0x08, 0x96, 0xBF, 0x91};
|
||||
@@ -977,6 +988,7 @@ bool XexModule::LoadContinue() {
|
||||
|
||||
// Scan and find the low/high addresses.
|
||||
// All code sections are continuous, so this should be easy.
|
||||
// could use a source for the above information
|
||||
auto heap = memory()->LookupHeap(base_address_);
|
||||
auto page_size = heap->page_size();
|
||||
|
||||
@@ -1045,7 +1057,24 @@ bool XexModule::LoadContinue() {
|
||||
library_offset += library->size;
|
||||
}
|
||||
}
|
||||
sha1::SHA1 final_image_sha_;
|
||||
|
||||
final_image_sha_.reset();
|
||||
|
||||
unsigned high_code = this->high_address_ - this->low_address_;
|
||||
|
||||
final_image_sha_.processBytes(memory()->TranslateVirtual(this->low_address_),
|
||||
high_code);
|
||||
final_image_sha_.finalize(image_sha_bytes_);
|
||||
|
||||
char fmtbuf[16];
|
||||
|
||||
for (unsigned i = 0; i < 16; ++i) {
|
||||
sprintf_s(fmtbuf, "%X", image_sha_bytes_[i]);
|
||||
image_sha_str_ += &fmtbuf[0];
|
||||
}
|
||||
|
||||
info_cache_.Init(this);
|
||||
// Find __savegprlr_* and __restgprlr_* and the others.
|
||||
// We can flag these for special handling (inlining/etc).
|
||||
if (!FindSaveRest()) {
|
||||
@@ -1288,7 +1317,68 @@ std::unique_ptr<Function> XexModule::CreateFunction(uint32_t address) {
|
||||
return std::unique_ptr<Function>(
|
||||
processor_->backend()->CreateGuestFunction(this, address));
|
||||
}
|
||||
void XexInfoCache::Init(XexModule* xexmod) {
|
||||
if (cvars::disable_instruction_infocache) {
|
||||
return;
|
||||
}
|
||||
auto emu = xexmod->kernel_state_->emulator();
|
||||
std::filesystem::path infocache_path = emu->cache_root();
|
||||
|
||||
infocache_path.append(L"modules");
|
||||
|
||||
infocache_path.append(xexmod->image_sha_str_);
|
||||
|
||||
std::filesystem::create_directories(infocache_path);
|
||||
infocache_path.append("executable_addr_flags.bin");
|
||||
|
||||
unsigned num_codebytes = xexmod->high_address_ - xexmod->low_address_;
|
||||
num_codebytes += 3; // round up to nearest multiple of 4
|
||||
num_codebytes &= ~3;
|
||||
bool did_exist = true;
|
||||
if (!std::filesystem::exists(infocache_path)) {
|
||||
xe::filesystem::CreateEmptyFile(infocache_path);
|
||||
did_exist = false;
|
||||
}
|
||||
|
||||
// todo: prepopulate with stuff from pdata, dll exports
|
||||
this->executable_addr_flags_ = std::move(xe::MappedMemory::Open(
|
||||
infocache_path, xe::MappedMemory::Mode::kReadWrite, 0,
|
||||
sizeof(InfoCacheFlagsHeader) +
|
||||
(sizeof(InfoCacheFlags) *
|
||||
(num_codebytes /
|
||||
4)))); // one infocacheflags entry for each PPC instr-sized addr
|
||||
|
||||
if (did_exist) {
|
||||
xexmod->PrecompileKnownFunctions();
|
||||
}
|
||||
}
|
||||
|
||||
InfoCacheFlags* XexModule::GetInstructionAddressFlags(uint32_t guest_addr) {
|
||||
if (guest_addr < low_address_ || guest_addr > high_address_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
guest_addr -= low_address_;
|
||||
|
||||
return info_cache_.LookupFlags(guest_addr);
|
||||
}
|
||||
|
||||
void XexModule::PrecompileKnownFunctions() {
|
||||
if (cvars::disable_function_precompilation) {
|
||||
return;
|
||||
}
|
||||
uint32_t start = 0;
|
||||
uint32_t end = (high_address_ - low_address_) / 4;
|
||||
auto flags = info_cache_.LookupFlags(0);
|
||||
if (!flags) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < end; i++) {
|
||||
if (flags[i].was_resolved) {
|
||||
processor_->ResolveFunction(low_address_ + (i * 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
bool XexModule::FindSaveRest() {
|
||||
// Special stack save/restore functions.
|
||||
// http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/md/ppc/xxx.s.htm
|
||||
|
||||
Reference in New Issue
Block a user