From 011ee110bc2bd4783501a3a978e3206a1960aa79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 16 May 2018 15:22:13 -0400 Subject: [PATCH] Common/Hash: Namespace code under the Common namespace Brings more common code under the Common namespace. --- Source/Core/Common/Hash.cpp | 3 +++ Source/Core/Common/Hash.h | 3 +++ Source/Core/Core/DSP/DSPCore.cpp | 4 ++-- Source/Core/Core/DSP/DSPHWInterface.cpp | 2 +- Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp | 5 +++-- Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp | 5 +++-- Source/Core/Core/Movie.cpp | 6 ++++-- Source/Core/DiscIO/CompressedBlob.cpp | 4 ++-- Source/Core/VideoCommon/NativeVertexFormat.h | 2 +- Source/Core/VideoCommon/TextureCacheBase.cpp | 22 ++++++++++---------- 10 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index 2678ab89bc..193ff5257b 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -15,6 +15,8 @@ #include #endif +namespace Common +{ static u64 (*ptrHashFunction)(const u8* src, u32 len, u32 samples) = nullptr; // uint32_t @@ -524,3 +526,4 @@ void SetHash64Function() ptrHashFunction = &GetMurmurHash3; } } +} // namespace Common diff --git a/Source/Core/Common/Hash.h b/Source/Core/Common/Hash.h index 42f5741b40..488f68cc1a 100644 --- a/Source/Core/Common/Hash.h +++ b/Source/Core/Common/Hash.h @@ -8,8 +8,11 @@ #include "Common/CommonTypes.h" +namespace Common +{ u32 HashFletcher(const u8* data_u8, size_t length); // FAST. Length & 1 == 0. u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightly slower u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS u64 GetHash64(const u8* src, u32 len, u32 samples); void SetHash64Function(); +} // namespace Common diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index 7b0a4a2244..83196a5c32 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -64,8 +64,8 @@ static bool VerifyRoms() {0x128ea7a2, 0xa4a575f5}, }}; - u32 hash_irom = HashAdler32((u8*)g_dsp.irom, DSP_IROM_BYTE_SIZE); - u32 hash_drom = HashAdler32((u8*)g_dsp.coef, DSP_COEF_BYTE_SIZE); + const u32 hash_irom = Common::HashAdler32(reinterpret_cast(g_dsp.irom), DSP_IROM_BYTE_SIZE); + const u32 hash_drom = Common::HashAdler32(reinterpret_cast(g_dsp.coef), DSP_COEF_BYTE_SIZE); int rom_idx = -1; for (size_t i = 0; i < known_roms.size(); ++i) diff --git a/Source/Core/Core/DSP/DSPHWInterface.cpp b/Source/Core/Core/DSP/DSPHWInterface.cpp index 09a700117c..c7ce209815 100644 --- a/Source/Core/Core/DSP/DSPHWInterface.cpp +++ b/Source/Core/Core/DSP/DSPHWInterface.cpp @@ -286,7 +286,7 @@ static const u8* gdsp_idma_in(u16 dsp_addr, u32 addr, u32 size) u16* dst = g_dsp.iram + (dsp_addr / 2); const u8* code = &g_dsp.cpu_ram[addr & 0x0fffffff]; - g_dsp.iram_crc = HashEctor(code, size); + g_dsp.iram_crc = Common::HashEctor(code, size); Common::UnWriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); memcpy(dst, code, size); diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp index 5ac0473d45..b896dd5e5c 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp @@ -101,8 +101,9 @@ void ROMUCode::HandleMail(u32 mail) void ROMUCode::BootUCode() { - u32 ector_crc = HashEctor((u8*)HLEMemory_Get_Pointer(m_current_ucode.m_ram_address), - m_current_ucode.m_length); + const u32 ector_crc = + Common::HashEctor(static_cast(HLEMemory_Get_Pointer(m_current_ucode.m_ram_address)), + m_current_ucode.m_length); if (SConfig::GetInstance().m_DumpUCode) { diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp index 8eaf746154..6fd250e47d 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp @@ -182,8 +182,9 @@ void UCodeInterface::PrepareBootUCode(u32 mail) m_needs_resume_mail = true; m_upload_setup_in_progress = false; - u32 ector_crc = - HashEctor((u8*)HLEMemory_Get_Pointer(m_next_ucode.iram_mram_addr), m_next_ucode.iram_size); + const u32 ector_crc = + Common::HashEctor(static_cast(HLEMemory_Get_Pointer(m_next_ucode.iram_mram_addr)), + m_next_ucode.iram_size); if (SConfig::GetInstance().m_DumpUCode) { diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 670949ccaf..4393439ee1 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1426,8 +1426,10 @@ void GetSettings() file_coef.Close(); for (u16& entry : coef) entry = Common::swap16(entry); - s_DSPiromHash = HashAdler32(reinterpret_cast(irom.data()), DSP::DSP_IROM_BYTE_SIZE); - s_DSPcoefHash = HashAdler32(reinterpret_cast(coef.data()), DSP::DSP_COEF_BYTE_SIZE); + s_DSPiromHash = + Common::HashAdler32(reinterpret_cast(irom.data()), DSP::DSP_IROM_BYTE_SIZE); + s_DSPcoefHash = + Common::HashAdler32(reinterpret_cast(coef.data()), DSP::DSP_COEF_BYTE_SIZE); } else { diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 285059e9c1..916773b90a 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -112,7 +112,7 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr) } // First, check hash. - u32 block_hash = HashAdler32(m_zlib_buffer.data(), comp_block_size); + u32 block_hash = Common::HashAdler32(m_zlib_buffer.data(), comp_block_size); if (block_hash != m_hashes[block_num]) PanicAlertT("The disc image \"%s\" is corrupt.\n" "Hash of block %" PRIu64 " is %08x instead of %08x.", @@ -304,7 +304,7 @@ bool CompressFileToBlob(const std::string& infile_path, const std::string& outfi position += write_size; - hashes[i] = HashAdler32(write_buf, write_size); + hashes[i] = Common::HashAdler32(write_buf, write_size); } header.compressed_data_size = position; diff --git a/Source/Core/VideoCommon/NativeVertexFormat.h b/Source/Core/VideoCommon/NativeVertexFormat.h index e7b575a587..75cf841a32 100644 --- a/Source/Core/VideoCommon/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/NativeVertexFormat.h @@ -91,7 +91,7 @@ struct hash { size_t operator()(const PortableVertexDeclaration& decl) const { - return HashFletcher((u8*)&decl, sizeof(decl)); + return Common::HashFletcher(reinterpret_cast(&decl), sizeof(decl)); } }; } diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 345770bba2..bf9dc98b9d 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -81,7 +81,7 @@ TextureCacheBase::TextureCacheBase() HiresTexture::Init(); - SetHash64Function(); + Common::SetHash64Function(); InvalidateAllBindPoints(); } @@ -733,13 +733,13 @@ TextureCacheBase::GetTexture(u32 address, u32 width, u32 height, const TextureFo // TODO: This doesn't hash GB tiles for preloaded RGBA8 textures (instead, it's hashing more data // from the low tmem bank than it should) - base_hash = GetHash64(src_data, texture_size, textureCacheSafetyColorSampleSize); + base_hash = Common::GetHash64(src_data, texture_size, textureCacheSafetyColorSampleSize); u32 palette_size = 0; if (isPaletteTexture) { palette_size = TexDecoder_GetPaletteSize(texformat); - full_hash = - base_hash ^ GetHash64(&texMem[tlutaddr], palette_size, textureCacheSafetyColorSampleSize); + full_hash = base_hash ^ Common::GetHash64(&texMem[tlutaddr], palette_size, + textureCacheSafetyColorSampleSize); } else { @@ -1225,17 +1225,17 @@ std::optional TextureCacheBase::ComputeTextureInformat // TODO: This doesn't hash GB tiles for preloaded RGBA8 textures (instead, it's hashing more data // from the low tmem bank than it should) - tex_info.base_hash = GetHash64(tex_info.src_data, tex_info.total_bytes, - tex_info.texture_cache_safety_color_sample_size); + tex_info.base_hash = Common::GetHash64(tex_info.src_data, tex_info.total_bytes, + tex_info.texture_cache_safety_color_sample_size); tex_info.is_palette_texture = IsColorIndexed(tex_format); if (tex_info.is_palette_texture) { tex_info.palette_size = TexDecoder_GetPaletteSize(tex_format); - tex_info.full_hash = - tex_info.base_hash ^ GetHash64(&texMem[tex_info.tlut_address], tex_info.palette_size, - tex_info.texture_cache_safety_color_sample_size); + tex_info.full_hash = tex_info.base_hash ^ + Common::GetHash64(&texMem[tex_info.tlut_address], tex_info.palette_size, + tex_info.texture_cache_safety_color_sample_size); } else { @@ -2043,7 +2043,7 @@ u64 TextureCacheBase::TCacheEntry::CalculateHash() const u8* ptr = Memory::GetPointer(addr); if (memory_stride == BytesPerRow()) { - return GetHash64(ptr, size_in_bytes, HashSampleSize()); + return Common::GetHash64(ptr, size_in_bytes, HashSampleSize()); } else { @@ -2062,7 +2062,7 @@ u64 TextureCacheBase::TCacheEntry::CalculateHash() const { // Multiply by a prime number to mix the hash up a bit. This prevents identical blocks from // canceling each other out - temp_hash = (temp_hash * 397) ^ GetHash64(ptr, BytesPerRow(), samples_per_row); + temp_hash = (temp_hash * 397) ^ Common::GetHash64(ptr, BytesPerRow(), samples_per_row); ptr += memory_stride; } return temp_hash;