From 920b5c583934d35e6c9bb9bfa73af00bf0de72ba Mon Sep 17 00:00:00 2001 From: gibbed Date: Sun, 25 Aug 2019 16:17:13 -0500 Subject: [PATCH] [x64] Simplify padding of code / unwind reservation in code cache. --- src/xenia/cpu/backend/x64/x64_code_cache.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/xenia/cpu/backend/x64/x64_code_cache.cc b/src/xenia/cpu/backend/x64/x64_code_cache.cc index fe0fd55a1..3dbe05f89 100644 --- a/src/xenia/cpu/backend/x64/x64_code_cache.cc +++ b/src/xenia/cpu/backend/x64/x64_code_cache.cc @@ -138,7 +138,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code, // unwind table requires entries AND code to be sorted in order. size_t low_mark; size_t high_mark; - uint8_t* code_address = nullptr; + size_t code_offset; + uint8_t* code_address; UnwindReservation unwind_reservation; { auto global_lock = global_critical_region_.Acquire(); @@ -147,7 +148,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code, // Reserve code. // Always move the code to land on 16b alignment. - code_address = generated_code_base_ + generated_code_offset_; + code_offset = generated_code_offset_; + code_address = generated_code_base_ + code_offset; generated_code_offset_ += xe::round_up(func_info.code_size.total, 16); // Reserve unwind info. @@ -155,7 +157,7 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code, // need it, and a few extra bytes of padding isn't the worst thing. unwind_reservation = RequestUnwindReservation(generated_code_base_ + generated_code_offset_); - generated_code_offset_ += unwind_reservation.data_size; + generated_code_offset_ += xe::round_up(unwind_reservation.data_size, 16); high_mark = generated_code_offset_; @@ -189,11 +191,8 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code, std::memcpy(code_address, machine_code, func_info.code_size.total); // Fill unused slots with 0xCC - std::memset( - code_address + func_info.code_size.total, 0xCC, - xe::round_up(func_info.code_size.total + unwind_reservation.data_size, - 16) - - func_info.code_size.total); + std::memset(code_address + func_info.code_size.total, 0xCC, + generated_code_offset_ - code_offset); // Notify subclasses of placed code. PlaceCode(guest_address, machine_code, func_info, code_address,