diff --git a/src/backend/x64/a32_emit_x64.cpp b/src/backend/x64/a32_emit_x64.cpp index 55c75bbb..fd37a0a6 100644 --- a/src/backend/x64/a32_emit_x64.cpp +++ b/src/backend/x64/a32_emit_x64.cpp @@ -115,6 +115,9 @@ A32EmitX64::BlockDescriptor A32EmitX64::Emit(IR::Block& block) { // Start emitting. code.align(); const u8* const entrypoint = code.getCurr(); + code.SwitchToFarCode(); + const u8* const entrypoint_far = code.getCurr(); + code.SwitchToNearCode(); EmitCondPrelude(ctx); @@ -160,7 +163,7 @@ A32EmitX64::BlockDescriptor A32EmitX64::Emit(IR::Block& block) { const auto range = boost::icl::discrete_interval::closed(descriptor.PC(), end_location.PC() - 1); block_ranges.AddRange(range, descriptor); - return RegisterBlock(descriptor, entrypoint, size); + return RegisterBlock(descriptor, entrypoint, entrypoint_far, size); } void A32EmitX64::ClearCache() { diff --git a/src/backend/x64/a64_emit_x64.cpp b/src/backend/x64/a64_emit_x64.cpp index 20514599..60e7fe65 100644 --- a/src/backend/x64/a64_emit_x64.cpp +++ b/src/backend/x64/a64_emit_x64.cpp @@ -81,6 +81,9 @@ A64EmitX64::BlockDescriptor A64EmitX64::Emit(IR::Block& block) { // Start emitting. code.align(); const u8* const entrypoint = code.getCurr(); + code.SwitchToFarCode(); + const u8* const entrypoint_far = code.getCurr(); + code.SwitchToNearCode(); ASSERT(block.GetCondition() == IR::Cond::AL); @@ -126,7 +129,7 @@ A64EmitX64::BlockDescriptor A64EmitX64::Emit(IR::Block& block) { const auto range = boost::icl::discrete_interval::closed(descriptor.PC(), end_location.PC() - 1); block_ranges.AddRange(range, descriptor); - return RegisterBlock(descriptor, entrypoint, size); + return RegisterBlock(descriptor, entrypoint, entrypoint_far, size); } void A64EmitX64::ClearCache() { @@ -358,6 +361,7 @@ void A64EmitX64::GenTerminalHandlers() { code.and_(code.ABI_PARAM1.cvt32(), fast_dispatch_table_mask); code.lea(code.ABI_RETURN, code.ptr[code.ABI_PARAM1 + code.ABI_PARAM2]); code.ret(); + PerfMapRegister(fast_dispatch_table_lookup, code.getCurr(), "a64_fast_dispatch_table_lookup"); } } diff --git a/src/backend/x64/emit_x64.cpp b/src/backend/x64/emit_x64.cpp index 6261f9ab..a53d1231 100644 --- a/src/backend/x64/emit_x64.cpp +++ b/src/backend/x64/emit_x64.cpp @@ -264,8 +264,11 @@ Xbyak::Label EmitX64::EmitCond(IR::Cond cond) { return pass; } -EmitX64::BlockDescriptor EmitX64::RegisterBlock(const IR::LocationDescriptor& descriptor, CodePtr entrypoint, size_t size) { +EmitX64::BlockDescriptor EmitX64::RegisterBlock(const IR::LocationDescriptor& descriptor, CodePtr entrypoint, CodePtr entrypoint_far, size_t size) { PerfMapRegister(entrypoint, code.getCurr(), LocationDescriptorToFriendlyName(descriptor)); + code.SwitchToFarCode(); + PerfMapRegister(entrypoint_far, code.getCurr(), LocationDescriptorToFriendlyName(descriptor) + "_far"); + code.SwitchToNearCode(); Patch(descriptor, entrypoint); BlockDescriptor block_desc{entrypoint, size}; diff --git a/src/backend/x64/emit_x64.h b/src/backend/x64/emit_x64.h index 7f784b47..c895aa73 100644 --- a/src/backend/x64/emit_x64.h +++ b/src/backend/x64/emit_x64.h @@ -94,7 +94,7 @@ protected: virtual std::string LocationDescriptorToFriendlyName(const IR::LocationDescriptor&) const = 0; void EmitAddCycles(size_t cycles); Xbyak::Label EmitCond(IR::Cond cond); - BlockDescriptor RegisterBlock(const IR::LocationDescriptor& location_descriptor, CodePtr entrypoint, size_t size); + BlockDescriptor RegisterBlock(const IR::LocationDescriptor& location_descriptor, CodePtr entrypoint, CodePtr entrypoint_far, size_t size); void PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_reg, IR::LocationDescriptor target); // Terminal instruction emitters diff --git a/src/backend/x64/perf_map.cpp b/src/backend/x64/perf_map.cpp index 4051445f..8b077537 100644 --- a/src/backend/x64/perf_map.cpp +++ b/src/backend/x64/perf_map.cpp @@ -47,6 +47,11 @@ void OpenFile() { namespace detail { void PerfMapRegister(const void* start, const void* end, std::string_view friendly_name) { + if (start == end) { + // Nothing to register + return; + } + std::lock_guard guard{mutex}; if (!file) {