PM4 buffer handling made a virtual member of commandprocessor, place the implementation/declaration into reusable macro files. this is probably the biggest boost here. Optimized SET_CONSTANT/ LOAD_CONSTANT pm4 ops based on the register range they start writing at, this was also a nice boost Expose X64 extension flags to code outside of x64 backend, so we can detect and use things like avx512, xop, avx2, etc in normal code Add freelists for HIR structures to try to reduce the number of last level cache misses during optimization (currently disabled... fixme later) Analyzed PGO feedback and reordered branches, uninlined functions, moved code out into different functions based on info from it in the PM4 functions, this gave like a 2% boost at best. Added support for the db16cyc opcode, which is used often in xb360 spinlocks. before it was just being translated to nop, now on x64 we translate it to _mm_pause but may change that in the future to reduce cpu time wasted texture util - all our divisors were powers of 2, instead we look up a shift. this made texture scaling slightly faster, more so on intel processors which seem to be worse at int divs. GetGuestTextureLayout is now a little faster, although it is still one of the heaviest functions in the emulator when scaling is on. xe_unlikely_mutex was not a good choice for the guest clock lock, (running theory) on intel processors another thread may take a significant time to update the clock? maybe because of the uint64 division? really not sure, but switched it to xe_mutex. This fixed audio stutter that i had introduced to 1 or 2 games, fixed performance on that n64 rare game with the monkeys. Took another crack at DMA implementation, another failure. Instead of passing as a parameter, keep the ringbuffer reader as the first member of commandprocessor so it can be accessed through this Added macro for noalias Applied noalias to Memory::LookupHeap. This reduced the size of the executable by 7 kb. Reworked kernel shim template, this shaved like 100kb off the exe and eliminated the indirect calls from the shim to the actual implementation. We still unconditionally generate string representations of kernel calls though :(, unless it is kHighFrequency Add nvapi extensions support, currently unused. Will use CPUVISIBLE memory at some point Inserted prefetches in a few places based on feedback from vtune. Add native implementation of SHA int8 if all elements are the same Vectorized comparisons for SetViewport, SetScissorRect Vectorized ranged comparisons for WriteRegister Add XE_MSVC_ASSUME Move FormatInfo::name out of the structure, instead look up the name in a different table. Debug related data and critical runtime data are best kept apart Templated UpdateSystemConstantValues based on ROV/RTV and primitive_polygonal Add ArchFloatMask functions, these are for storing the results of floating point comparisons without doing costly float->int pipeline transfers (vucomiss/setb) Use floatmasks in UpdateSystemConstantValues for checking if dirty, only transfer to int at end of function. Instead of dirty |= (x == y) in UpdateSystemConstantValues, now we do dirty_u32 |= (x^y). if any of them are not equal, dirty_u32 will be nz, else if theyre all equal it will be zero. This is more friendly to register renaming and the lack of dependencies on EFLAGS lets the compiler reorder better Add PrefetchSamplerParameters to D3D12TextureCache use PrefetchSamplerParameters in UpdateBindings to eliminate cache misses that vtune detected Add PrefetchTextureBinding to D3D12TextureCache Prefetch texture bindings to get rid of more misses vtune detected (more accesses out of order with random strides) Rewrote DMAC, still terrible though and have disabled it for now. Replace tiny memcmp of 6 U64 in render_target_cache with inline loop, msvc fails to make it a loop and instead does a thunk to their memcmp function, which is optimized for larger sizes PrefetchTextureBinding in AreActiveTextureSRVKeysUpToDate Replace memcmp calls for pipelinedescription with handwritten cmp Directly write some registers that dont have special handling in PM4 functions Changed EstimateMaxY to try to eliminate mispredictions that vtune was reporting, msvc ended up turning the changed code into a series of blends in ExecutePacketType3_EVENT_WRITE_EXT, instead of writing extents to an array on the stack and then doing xe_copy_and_swap_16 of the data to its dest, pre-swap each constant and then store those. msvc manages to unroll that into wider stores stop logging XE_SWAP every time we receive XE_SWAP, stop logging the start and end of each viz query Prefetch watch nodes in FireWatches based on feedback from vtune Removed dead code from texture_info.cc NOINLINE on GpuSwap, PGO builds did it so we should too.
160 lines
5.2 KiB
C++
160 lines
5.2 KiB
C++
/**
|
|
******************************************************************************
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
******************************************************************************
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
******************************************************************************
|
|
*/
|
|
|
|
#include "xenia/cpu/compiler/passes/context_promotion_pass.h"
|
|
|
|
#include "xenia/apu/apu_flags.h"
|
|
#include "xenia/base/cvar.h"
|
|
#include "xenia/base/profiling.h"
|
|
#include "xenia/cpu/compiler/compiler.h"
|
|
#include "xenia/cpu/ppc/ppc_context.h"
|
|
#include "xenia/cpu/processor.h"
|
|
|
|
DECLARE_bool(debug);
|
|
|
|
DEFINE_bool(store_all_context_values, false,
|
|
"Don't strip dead context stores to aid in debugging.", "CPU");
|
|
|
|
DEFINE_bool(full_optimization_even_with_debug, false,
|
|
"For developer use to analyze the quality of the generated code, "
|
|
"not intended for actual debugging of the code",
|
|
"CPU");
|
|
|
|
namespace xe {
|
|
namespace cpu {
|
|
namespace compiler {
|
|
namespace passes {
|
|
|
|
// TODO(benvanik): remove when enums redefined.
|
|
using namespace xe::cpu::hir;
|
|
|
|
using xe::cpu::hir::Block;
|
|
using xe::cpu::hir::HIRBuilder;
|
|
using xe::cpu::hir::Instr;
|
|
using xe::cpu::hir::Value;
|
|
|
|
ContextPromotionPass::ContextPromotionPass() : CompilerPass() {}
|
|
|
|
ContextPromotionPass::~ContextPromotionPass() {}
|
|
|
|
bool ContextPromotionPass::Initialize(Compiler* compiler) {
|
|
if (!CompilerPass::Initialize(compiler)) {
|
|
return false;
|
|
}
|
|
|
|
// This is a terrible implementation.
|
|
context_values_.resize(sizeof(ppc::PPCContext));
|
|
context_validity_.resize(static_cast<uint32_t>(sizeof(ppc::PPCContext)));
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ContextPromotionPass::Run(HIRBuilder* builder) {
|
|
// Like mem2reg, but because context memory is unaliasable it's easier to
|
|
// check and convert LoadContext/StoreContext into value operations.
|
|
// Example of load->value promotion:
|
|
// v0 = load_context +100
|
|
// store_context +200, v0
|
|
// v1 = load_context +100 <-- replace with v1 = v0
|
|
// store_context +200, v1
|
|
//
|
|
// It'd be possible in this stage to also remove redundant context stores:
|
|
// Example of dead store elimination:
|
|
// store_context +100, v0 <-- removed due to following store
|
|
// store_context +100, v1
|
|
// This is more generally done by DSE, however if it could be done here
|
|
// instead as it may be faster (at least on the block-level).
|
|
|
|
// Promote loads to values.
|
|
// Process each block independently, for now.
|
|
auto block = builder->first_block();
|
|
while (block) {
|
|
PromoteBlock(block);
|
|
block = block->next;
|
|
}
|
|
|
|
// Remove all dead stores.
|
|
// This will break debugging as we can't recover this information when
|
|
// trying to extract stack traces/register values, so we don't do that.
|
|
if (cvars::full_optimization_even_with_debug ||
|
|
(!cvars::debug && !cvars::store_all_context_values)) {
|
|
block = builder->first_block();
|
|
while (block) {
|
|
RemoveDeadStoresBlock(block);
|
|
block = block->next;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void ContextPromotionPass::PromoteBlock(Block* block) {
|
|
auto& validity = context_validity_;
|
|
validity.reset();
|
|
|
|
Instr* i = block->instr_head;
|
|
while (i) {
|
|
auto next = i->next;
|
|
if (i->opcode->flags & OPCODE_FLAG_VOLATILE) {
|
|
// Volatile instruction - requires all context values be flushed.
|
|
validity.reset();
|
|
} else if (i->opcode == &OPCODE_LOAD_CONTEXT_info) {
|
|
size_t offset = i->src1.offset;
|
|
if (validity.test(static_cast<uint32_t>(offset))) {
|
|
// Legit previous value, reuse.
|
|
Value* previous_value = context_values_[offset];
|
|
i->opcode = &hir::OPCODE_ASSIGN_info;
|
|
i->set_src1(previous_value);
|
|
} else {
|
|
// Store the loaded value into the table.
|
|
context_values_[offset] = i->dest;
|
|
validity.set(static_cast<uint32_t>(offset));
|
|
}
|
|
} else if (i->opcode == &OPCODE_STORE_CONTEXT_info) {
|
|
size_t offset = i->src1.offset;
|
|
Value* value = i->src2.value;
|
|
// Store value into the table for later.
|
|
context_values_[offset] = value;
|
|
validity.set(static_cast<uint32_t>(offset));
|
|
}
|
|
i = next;
|
|
}
|
|
}
|
|
|
|
void ContextPromotionPass::RemoveDeadStoresBlock(Block* block) {
|
|
auto& validity = context_validity_;
|
|
validity.reset();
|
|
|
|
// Walk backwards and mark offsets that are written to.
|
|
// If the offset was written to earlier, ignore the store.
|
|
Instr* i = block->instr_tail;
|
|
while (i) {
|
|
Instr* prev = i->prev;
|
|
if (i->opcode->flags & (OPCODE_FLAG_VOLATILE | OPCODE_FLAG_BRANCH)) {
|
|
// Volatile instruction - requires all context values be flushed.
|
|
validity.reset();
|
|
} else if (i->opcode == &OPCODE_STORE_CONTEXT_info) {
|
|
size_t offset = i->src1.offset;
|
|
if (!validity.test(static_cast<uint32_t>(offset))) {
|
|
// Offset not yet written, mark and continue.
|
|
validity.set(static_cast<uint32_t>(offset));
|
|
} else {
|
|
// Already written to. Remove this store.
|
|
i->UnlinkAndNOP();
|
|
}
|
|
}
|
|
i = prev;
|
|
}
|
|
}
|
|
|
|
} // namespace passes
|
|
} // namespace compiler
|
|
} // namespace cpu
|
|
} // namespace xe
|