From 9db119f8a2e5a4d877f00b9efb40e4a109c95ef7 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 6 Jun 2019 19:20:15 -0400 Subject: kernel_executable: Optimize BLZ decompression --- src/core/file_sys/kernel_executable.cpp | 11 +++++------ src/core/loader/kip.cpp | 12 ++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp index 45cbde4c9..371300684 100644 --- a/src/core/file_sys/kernel_executable.cpp +++ b/src/core/file_sys/kernel_executable.cpp @@ -34,7 +34,7 @@ bool DecompressBLZ(std::vector& data) { --index; auto control = data[index + start_offset]; for (size_t i = 0; i < 8; ++i) { - if ((control & 0x80) > 0) { + if (((control << i) & 0x80) > 0) { if (index < 2) { return false; } @@ -70,9 +70,8 @@ bool DecompressBLZ(std::vector& data) { data[out_index + start_offset] = data[index + start_offset]; } - control <<= 1; if (out_index == 0) - return true; + break; } } @@ -132,15 +131,15 @@ std::vector KIP::GetSectionDecompressed(u8 index) const { } bool KIP::Is64Bit() const { - return header.flags & 0x8; + return (header.flags & 0x8) != 0; } bool KIP::Is39BitAddressSpace() const { - return header.flags & 0x10; + return (header.flags & 0x10) != 0; } bool KIP::IsService() const { - return header.flags & 0x20; + return (header.flags & 0x20) != 0; } std::vector KIP::GetKernelCapabilities() const { diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 2efd14f04..70051c13a 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp @@ -53,10 +53,14 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process) { return {kip->GetStatus(), {}}; } - const auto address_space = - kip->Is64Bit() ? (kip->Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit - : FileSys::ProgramAddressSpaceType::Is36Bit) - : FileSys::ProgramAddressSpaceType::Is32Bit; + const auto get_kip_address_space_type = [](const auto& kip) { + return kip.Is64Bit() + ? (kip.Is39BitAddressSpace() ? FileSys::ProgramAddressSpaceType::Is39Bit + : FileSys::ProgramAddressSpaceType::Is36Bit) + : FileSys::ProgramAddressSpaceType::Is32Bit; + }; + + const auto address_space = get_kip_address_space_type(*kip); FileSys::ProgramMetadata metadata; metadata.LoadManual(kip->Is64Bit(), address_space, kip->GetMainThreadPriority(), -- cgit v1.2.3