From 8ed892a986331ed9e2512c37e2284c50c3872d35 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Fri, 2 Apr 2021 20:23:55 +0200 Subject: [PATCH] early-access version 1550 --- README.md | 2 +- .../dynarmic/include/dynarmic/A32/config.h | 7 +++++ .../dynarmic/include/dynarmic/A64/config.h | 7 +++++ .../src/backend/x64/a32_interface.cpp | 2 +- .../src/backend/x64/a64_interface.cpp | 2 +- .../src/backend/x64/block_of_code.cpp | 28 ++++++------------- .../dynarmic/src/backend/x64/block_of_code.h | 7 +++-- src/core/arm/dynarmic/arm_dynarmic_32.cpp | 4 +++ src/core/arm/dynarmic/arm_dynarmic_64.cpp | 4 +++ 9 files changed, 38 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index fcaf883f3..a0d1e474b 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1548. +This is the source code for early-access 1550. ## Legal Notice diff --git a/externals/dynarmic/include/dynarmic/A32/config.h b/externals/dynarmic/include/dynarmic/A32/config.h index da17ce822..a64cf737d 100755 --- a/externals/dynarmic/include/dynarmic/A32/config.h +++ b/externals/dynarmic/include/dynarmic/A32/config.h @@ -197,6 +197,13 @@ struct UserConfig { /// NOTE: Calling Jit::SetCpsr with CPSR.E=1 while this option is enabled may result /// in unusual behavior. bool always_little_endian = false; + + // Minimum size is about 8MiB. Maximum size is about 2GiB. Maximum size is limited by + // the maximum length of a x64 jump. + size_t code_cache_size = 256 * 1024 * 1024; // bytes + // Determines the relative size of the near and far code caches. Must be smaller than + // code_cache_size. + size_t far_code_offset = 200 * 1024 * 1024; // bytes }; } // namespace A32 diff --git a/externals/dynarmic/include/dynarmic/A64/config.h b/externals/dynarmic/include/dynarmic/A64/config.h index 9846f70ad..7249c6fa1 100755 --- a/externals/dynarmic/include/dynarmic/A64/config.h +++ b/externals/dynarmic/include/dynarmic/A64/config.h @@ -245,6 +245,13 @@ struct UserConfig { // Determines whether AddTicks and GetTicksRemaining are called. // If false, execution will continue until soon after Jit::HaltExecution is called. // bool enable_ticks = true; // TODO + + // Minimum size is about 8MiB. Maximum size is about 2GiB. Maximum size is limited by + // the maximum length of a x64 jump. + size_t code_cache_size = 256 * 1024 * 1024; // bytes + // Determines the relative size of the near and far code caches. Must be smaller than + // code_cache_size. + size_t far_code_offset = 200 * 1024 * 1024; // bytes }; } // namespace A64 diff --git a/externals/dynarmic/src/backend/x64/a32_interface.cpp b/externals/dynarmic/src/backend/x64/a32_interface.cpp index 85f934c8c..09d9d6c76 100755 --- a/externals/dynarmic/src/backend/x64/a32_interface.cpp +++ b/externals/dynarmic/src/backend/x64/a32_interface.cpp @@ -53,7 +53,7 @@ static std::function GenRCP(const A32::UserConfig& conf) { struct Jit::Impl { Impl(Jit* jit, A32::UserConfig conf) - : block_of_code(GenRunCodeCallbacks(conf.callbacks, &GetCurrentBlockThunk, this), JitStateInfo{jit_state}, GenRCP(conf)) + : block_of_code(GenRunCodeCallbacks(conf.callbacks, &GetCurrentBlockThunk, this), JitStateInfo{jit_state}, conf.code_cache_size, conf.far_code_offset, GenRCP(conf)) , emitter(block_of_code, conf, jit) , conf(std::move(conf)) , jit_interface(jit) diff --git a/externals/dynarmic/src/backend/x64/a64_interface.cpp b/externals/dynarmic/src/backend/x64/a64_interface.cpp index 646b426a3..acde3f34a 100755 --- a/externals/dynarmic/src/backend/x64/a64_interface.cpp +++ b/externals/dynarmic/src/backend/x64/a64_interface.cpp @@ -45,7 +45,7 @@ struct Jit::Impl final { public: Impl(Jit* jit, UserConfig conf) : conf(conf) - , block_of_code(GenRunCodeCallbacks(conf.callbacks, &GetCurrentBlockThunk, this), JitStateInfo{jit_state}, GenRCP(conf)) + , block_of_code(GenRunCodeCallbacks(conf.callbacks, &GetCurrentBlockThunk, this), JitStateInfo{jit_state}, conf.code_cache_size, conf.far_code_offset, GenRCP(conf)) , emitter(block_of_code, conf, jit) { ASSERT(conf.page_table_address_space_bits >= 12 && conf.page_table_address_space_bits <= 64); diff --git a/externals/dynarmic/src/backend/x64/block_of_code.cpp b/externals/dynarmic/src/backend/x64/block_of_code.cpp index 752ff7ccf..8b96b8afc 100755 --- a/externals/dynarmic/src/backend/x64/block_of_code.cpp +++ b/externals/dynarmic/src/backend/x64/block_of_code.cpp @@ -44,8 +44,6 @@ const std::array BlockOfCode::ABI_PARAMS = {BlockOfCode::ABI_PA namespace { -constexpr size_t TOTAL_CODE_SIZE = 256 * 1024 * 1024; -constexpr size_t FAR_CODE_OFFSET = 200 * 1024 * 1024; constexpr size_t CONSTANT_POOL_SIZE = 2 * 1024 * 1024; class CustomXbyakAllocator : public Xbyak::Allocator { @@ -75,10 +73,11 @@ void ProtectMemory(const void* base, size_t size, bool is_executable) { } // anonymous namespace -BlockOfCode::BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, std::function rcp) - : Xbyak::CodeGenerator(TOTAL_CODE_SIZE, nullptr, &s_allocator) +BlockOfCode::BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, size_t total_code_size, size_t far_code_offset, std::function rcp) + : Xbyak::CodeGenerator(total_code_size, nullptr, &s_allocator) , cb(std::move(cb)) , jsi(jsi) + , far_code_offset(far_code_offset) , constant_pool(*this, CONSTANT_POOL_SIZE) { EnableWriting(); @@ -88,7 +87,7 @@ BlockOfCode::BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, std::function(near_code_ptr) - getCode(); - far_code_offset = getCurr() - getCode(); - } else { - near_code_offset = getCurr() - getCode(); - far_code_offset = static_cast(far_code_ptr) - getCode(); - } - if (far_code_offset > TOTAL_CODE_SIZE) + const u8* current_near_ptr = in_far_code ? reinterpret_cast(near_code_ptr) : getCode(); + const u8* current_far_ptr = in_far_code ? getCode() : reinterpret_cast(far_code_ptr); + if (current_near_ptr >= far_code_begin) return 0; - if (near_code_offset > FAR_CODE_OFFSET) + if (current_far_ptr >= &top_[maxSize_]) return 0; - return std::min(TOTAL_CODE_SIZE - far_code_offset, FAR_CODE_OFFSET - near_code_offset); + return std::min(current_near_ptr - reinterpret_cast(far_code_begin), current_far_ptr - &top_[maxSize_]); } void BlockOfCode::RunCode(void* jit_state, CodePtr code_ptr) const { diff --git a/externals/dynarmic/src/backend/x64/block_of_code.h b/externals/dynarmic/src/backend/x64/block_of_code.h index 23ed16837..596c31bd4 100755 --- a/externals/dynarmic/src/backend/x64/block_of_code.h +++ b/externals/dynarmic/src/backend/x64/block_of_code.h @@ -31,7 +31,7 @@ struct RunCodeCallbacks { class BlockOfCode final : public Xbyak::CodeGenerator { public: - BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, std::function rcp); + BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, size_t total_code_size, size_t far_code_offset, std::function rcp); BlockOfCode(const BlockOfCode&) = delete; /// Call when external emitters have finished emitting their preludes. @@ -164,10 +164,11 @@ public: private: RunCodeCallbacks cb; JitStateInfo jsi; + size_t far_code_offset; bool prelude_complete = false; - CodePtr near_code_begin; - CodePtr far_code_begin; + CodePtr near_code_begin = nullptr; + CodePtr far_code_begin = nullptr; ConstantPool constant_pool; diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 4b2a62b4f..08d889135 100755 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -137,6 +137,10 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable* // Timing config.wall_clock_cntpct = uses_wall_clock; + // Code cache size + config.code_cache_size = 512 * 1024 * 1024; + config.far_code_offset = 256 * 1024 * 1024; + // Safe optimizations if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::DebugMode) { if (!Settings::values.cpuopt_page_tables) { diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index 083c2bdee..e12e50658 100755 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp @@ -177,6 +177,10 @@ std::shared_ptr ARM_Dynarmic_64::MakeJit(Common::PageTable* // Timing config.wall_clock_cntpct = uses_wall_clock; + // Code cache size + config.code_cache_size = 512 * 1024 * 1024; + config.far_code_offset = 256 * 1024 * 1024; + // Safe optimizations if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::DebugMode) { if (!Settings::values.cpuopt_page_tables) {