Permalink
Browse files

Merge pull request #6870 from lioncash/hash

Common/Hash: Namespace code under the Common namespace
  • Loading branch information...
degasus committed May 16, 2018
2 parents 8ca1bf5 + 011ee11 commit 8fa8aa3e1b31078a9ccf403a41fff622f77bfcaf
@@ -15,6 +15,8 @@
#include <arm_acle.h>
#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
@@ -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
@@ -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<u8*>(g_dsp.irom), DSP_IROM_BYTE_SIZE);
const u32 hash_drom = Common::HashAdler32(reinterpret_cast<u8*>(g_dsp.coef), DSP_COEF_BYTE_SIZE);
int rom_idx = -1;
for (size_t i = 0; i < known_roms.size(); ++i)
@@ -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);
@@ -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<u8*>(HLEMemory_Get_Pointer(m_current_ucode.m_ram_address)),
m_current_ucode.m_length);
if (SConfig::GetInstance().m_DumpUCode)
{
@@ -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<u8*>(HLEMemory_Get_Pointer(m_next_ucode.iram_mram_addr)),
m_next_ucode.iram_size);
if (SConfig::GetInstance().m_DumpUCode)
{
@@ -1426,8 +1426,10 @@ void GetSettings()
file_coef.Close();
for (u16& entry : coef)
entry = Common::swap16(entry);
s_DSPiromHash = HashAdler32(reinterpret_cast<u8*>(irom.data()), DSP::DSP_IROM_BYTE_SIZE);
s_DSPcoefHash = HashAdler32(reinterpret_cast<u8*>(coef.data()), DSP::DSP_COEF_BYTE_SIZE);
s_DSPiromHash =
Common::HashAdler32(reinterpret_cast<u8*>(irom.data()), DSP::DSP_IROM_BYTE_SIZE);
s_DSPcoefHash =
Common::HashAdler32(reinterpret_cast<u8*>(coef.data()), DSP::DSP_COEF_BYTE_SIZE);
}
else
{
@@ -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;
@@ -91,7 +91,7 @@ struct hash<PortableVertexDeclaration>
{
size_t operator()(const PortableVertexDeclaration& decl) const
{
return HashFletcher((u8*)&decl, sizeof(decl));
return Common::HashFletcher(reinterpret_cast<const u8*>(&decl), sizeof(decl));
}
};
}
@@ -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<TextureLookupInformation> 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;

0 comments on commit 8fa8aa3

Please sign in to comment.