From a267451614205c469b084a7d3afb46986e7f3156 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 12 Dec 2019 20:17:52 +1000 Subject: [PATCH] CPU/Recompiler: Remove unused code --- src/core/cpu_recompiler_code_generator.h | 6 - .../cpu_recompiler_code_generator_x64.cpp | 218 +----------------- 2 files changed, 1 insertion(+), 223 deletions(-) diff --git a/src/core/cpu_recompiler_code_generator.h b/src/core/cpu_recompiler_code_generator.h index 41f5bbc0d..b4ccf42e6 100644 --- a/src/core/cpu_recompiler_code_generator.h +++ b/src/core/cpu_recompiler_code_generator.h @@ -131,12 +131,6 @@ public: void EmitPushHostReg(HostReg reg, u32 position); void EmitPopHostReg(HostReg reg, u32 position); - // Flags copying from host. -#if defined(Y_CPU_X64) - void ReadFlagsFromHost(Value* value); - Value ReadFlagsFromHost(); -#endif - // Value ops Value AddValues(const Value& lhs, const Value& rhs, bool set_flags); Value SubValues(const Value& lhs, const Value& rhs, bool set_flags); diff --git a/src/core/cpu_recompiler_code_generator_x64.cpp b/src/core/cpu_recompiler_code_generator_x64.cpp index 4957b0d56..3c9a7ba83 100644 --- a/src/core/cpu_recompiler_code_generator_x64.cpp +++ b/src/core/cpu_recompiler_code_generator_x64.cpp @@ -1369,21 +1369,6 @@ void CodeGenerator::EmitPopHostReg(HostReg reg, u32 position) m_emit->pop(GetHostReg64(reg)); } -void CodeGenerator::ReadFlagsFromHost(Value* value) -{ - // this is a 64-bit push/pop, we ignore the upper 32 bits - DebugAssert(value->IsInHostRegister()); - m_emit->pushf(); - m_emit->pop(GetHostReg64(value->host_reg)); -} - -Value CodeGenerator::ReadFlagsFromHost() -{ - Value temp = m_register_cache.AllocateScratch(RegSize_32); - ReadFlagsFromHost(&temp); - return temp; -} - void CodeGenerator::EmitLoadCPUStructField(HostReg host_reg, RegSize guest_size, u32 offset) { switch (guest_size) @@ -1867,207 +1852,6 @@ void CodeGenerator::EmitRaiseException(Exception excode, Condition condition /* m_register_cache.PopState(); } -#if 0 -class ThunkGenerator -{ -public: - template - static DataType (*CompileMemoryReadFunction(JitCodeBuffer* code_buffer))(u8, u32) - { - using FunctionType = DataType (*)(u8, u32); - const auto rret = GetHostReg64(RRETURN); - const auto rcpuptr = GetHostReg64(RCPUPTR); - const auto rarg1 = GetHostReg32(RARG1); - const auto rarg2 = GetHostReg32(RARG2); - const auto rarg3 = GetHostReg32(RARG3); - const auto scratch = GetHostReg64(RARG3); - - Xbyak::CodeGenerator emitter(code_buffer->GetFreeCodeSpace(), code_buffer->GetFreeCodePointer()); - - // ensure function starts at aligned 16 bytes - emitter.align(); - FunctionType ret = emitter.getCurr(); - - // TODO: We can skip these if the base address is zero and the size is 4GB. - Xbyak::Label raise_gpf_label; - - static_assert(sizeof(CPU::SegmentCache) == 16); - emitter.movzx(rarg1, rarg1.cvt8()); - emitter.shl(rarg1, 4); - emitter.lea(rret, emitter.byte[rcpuptr + rarg1.cvt64() + offsetof(CPU, m_segment_cache[0])]); - - // if segcache->access_mask & Read == 0 - emitter.test(emitter.byte[rret + offsetof(CPU::SegmentCache, access_mask)], static_cast(AccessTypeMask::Read)); - emitter.jz(raise_gpf_label); - - // if offset < limit_low - emitter.cmp(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, limit_low)]); - emitter.jb(raise_gpf_label); - - // if offset + (size - 1) > limit_high - // offset += segcache->base_address - if constexpr (sizeof(DataType) > 1) - { - emitter.lea(scratch, emitter.qword[rarg2.cvt64() + (sizeof(DataType) - 1)]); - emitter.add(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, base_address)]); - emitter.mov(rret.cvt32(), emitter.dword[rret + offsetof(CPU::SegmentCache, limit_high)]); - emitter.cmp(scratch, rret); - emitter.ja(raise_gpf_label); - } - else - { - emitter.cmp(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, limit_high)]); - emitter.ja(raise_gpf_label); - emitter.add(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, base_address)]); - } - - // swap segment with CPU - emitter.mov(rarg1, rcpuptr); - - // go ahead with the memory read - if constexpr (std::is_same_v) - { - emitter.mov(rret, reinterpret_cast(static_cast(&CPU::ReadMemoryByte))); - } - else if constexpr (std::is_same_v) - { - emitter.mov(rret, - reinterpret_cast(static_cast(&CPU::ReadMemoryWord))); - } - else - { - emitter.mov(rret, - reinterpret_cast(static_cast(&CPU::ReadMemoryDWord))); - } - - emitter.jmp(rret); - - // RAISE GPF BRANCH - emitter.L(raise_gpf_label); - - // register swap since the CPU has to come first - emitter.cmp(rarg1, (Segment_SS << 4)); - emitter.mov(rarg1, Interrupt_StackFault); - emitter.mov(rarg2, Interrupt_GeneralProtectionFault); - emitter.cmove(rarg2, rarg1); - emitter.xor_(rarg3, rarg3); - emitter.mov(rarg1, rcpuptr); - - // cpu->RaiseException(ss ? Interrupt_StackFault : Interrupt_GeneralProtectionFault, 0) - emitter.mov(rret, reinterpret_cast(static_cast(&CPU::RaiseException))); - emitter.jmp(rret); - - emitter.ready(); - code_buffer->CommitCode(emitter.getSize()); - return ret; - } - - template - static void (*CompileMemoryWriteFunction(JitCodeBuffer* code_buffer))(u8, u32, DataType) - { - using FunctionType = void (*)(u8, u32, DataType); - const auto rret = GetHostReg64(RRETURN); - const auto rcpuptr = GetHostReg64(RCPUPTR); - const auto rarg1 = GetHostReg32(RARG1); - const auto rarg2 = GetHostReg32(RARG2); - const auto rarg3 = GetHostReg32(RARG3); - const auto scratch = GetHostReg64(RARG4); - - Xbyak::CodeGenerator emitter(code_buffer->GetFreeCodeSpace(), code_buffer->GetFreeCodePointer()); - - // ensure function starts at aligned 16 bytes - emitter.align(); - FunctionType ret = emitter.getCurr(); - - // TODO: We can skip these if the base address is zero and the size is 4GB. - Xbyak::Label raise_gpf_label; - - static_assert(sizeof(CPU::SegmentCache) == 16); - emitter.movzx(rarg1, rarg1.cvt8()); - emitter.shl(rarg1, 4); - emitter.lea(rret, emitter.byte[rcpuptr + rarg1.cvt64() + offsetof(CPU, m_segment_cache[0])]); - - // if segcache->access_mask & Read == 0 - emitter.test(emitter.byte[rret + offsetof(CPU::SegmentCache, access_mask)], - static_cast(AccessTypeMask::Write)); - emitter.jz(raise_gpf_label); - - // if offset < limit_low - emitter.cmp(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, limit_low)]); - emitter.jb(raise_gpf_label); - - // if offset + (size - 1) > limit_high - // offset += segcache->base_address - if constexpr (sizeof(DataType) > 1) - { - emitter.lea(scratch, emitter.qword[rarg2.cvt64() + (sizeof(DataType) - 1)]); - emitter.add(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, base_address)]); - emitter.mov(rret.cvt32(), emitter.dword[rret + offsetof(CPU::SegmentCache, limit_high)]); - emitter.cmp(scratch, rret.cvt64()); - emitter.ja(raise_gpf_label); - } - else - { - emitter.cmp(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, limit_high)]); - emitter.ja(raise_gpf_label); - emitter.add(rarg2, emitter.dword[rret + offsetof(CPU::SegmentCache, base_address)]); - } - - // swap segment with CPU - emitter.mov(rarg1, rcpuptr); - - // go ahead with the memory read - if constexpr (std::is_same_v) - { - emitter.mov( - rret, reinterpret_cast(static_cast(&CPU::WriteMemoryByte))); - } - else if constexpr (std::is_same_v) - { - emitter.mov( - rret, reinterpret_cast(static_cast(&CPU::WriteMemoryWord))); - } - else - { - emitter.mov( - rret, reinterpret_cast(static_cast(&CPU::WriteMemoryDWord))); - } - - emitter.jmp(rret); - - // RAISE GPF BRANCH - emitter.L(raise_gpf_label); - - // register swap since the CPU has to come first - emitter.cmp(rarg1, (Segment_SS << 4)); - emitter.mov(rarg1, Interrupt_StackFault); - emitter.mov(rarg2, Interrupt_GeneralProtectionFault); - emitter.cmove(rarg2, rarg1); - emitter.xor_(rarg3, rarg3); - emitter.mov(rarg1, rcpuptr); - - // cpu->RaiseException(ss ? Interrupt_StackFault : Interrupt_GeneralProtectionFault, 0) - emitter.mov(rret, reinterpret_cast(static_cast(&CPU::RaiseException))); - emitter.jmp(rret); - - emitter.ready(); - code_buffer->CommitCode(emitter.getSize()); - return ret; - } -}; - -#endif - -void ASMFunctions::Generate(JitCodeBuffer* code_buffer) -{ -#if 0 - read_memory_byte = ThunkGenerator::CompileMemoryReadFunction(code_buffer); - read_memory_word = ThunkGenerator::CompileMemoryReadFunction(code_buffer); - read_memory_dword = ThunkGenerator::CompileMemoryReadFunction(code_buffer); - write_memory_byte = ThunkGenerator::CompileMemoryWriteFunction(code_buffer); - write_memory_word = ThunkGenerator::CompileMemoryWriteFunction(code_buffer); - write_memory_dword = ThunkGenerator::CompileMemoryWriteFunction(code_buffer); -#endif -} +void ASMFunctions::Generate(JitCodeBuffer* code_buffer) {} } // namespace CPU::Recompiler