summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Hash.cpp
diff options
context:
space:
mode:
authorMatthew Parlane <parlane@gmail.com>2015-06-09 10:39:52 +1000
committerMatthew Parlane <parlane@gmail.com>2015-06-09 10:39:52 +1000
commit42d5b5b48c18a1b7cf56db7d9781cdc46222d5b4 (patch)
tree963a48f14a947d73051cc3f950840a6049a7b9b6 /Source/Core/Common/Hash.cpp
parent9ed7e3bd3e5d0b35c5815197d6ff5e6d8018ce9d (diff)
parentffe085f5eaf0546018bdda342c4ce2753e4016f6 (diff)
Merge pull request #2568 from Sonicadvance1/aarch64_crc32_hash
[AArch64] Implement CRC32 texture hashing.
Diffstat (limited to 'Source/Core/Common/Hash.cpp')
-rw-r--r--Source/Core/Common/Hash.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp
index 844dd31f35..868de4e68f 100644
--- a/Source/Core/Common/Hash.cpp
+++ b/Source/Core/Common/Hash.cpp
@@ -228,7 +228,7 @@ u64 GetMurmurHash3(const u8 *src, u32 len, u32 samples)
// CRC32 hash using the SSE4.2 instruction
u64 GetCRC32(const u8 *src, u32 len, u32 samples)
{
-#if _M_SSE >= 0x402
+#if _M_SSE >= 0x402 || defined(_M_ARM_64)
u64 h[4] = { len, 0, 0, 0 };
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
@@ -238,6 +238,9 @@ u64 GetCRC32(const u8 *src, u32 len, u32 samples)
Step = Step / samples;
if (Step < 1)
Step = 1;
+#endif
+
+#if _M_SSE >= 0x402
while (data < end - Step * 3)
{
h[0] = _mm_crc32_u64(h[0], data[Step * 0]);
@@ -259,12 +262,66 @@ u64 GetCRC32(const u8 *src, u32 len, u32 samples)
memcpy(&temp, end, len & 7);
h[0] = _mm_crc32_u64(h[0], temp);
}
+#elif defined(_M_ARM_64)
+ // We should be able to use intrinsics for this
+ // Too bad the intrinsics for this instruction was added in GCC 4.9.1
+ // The Android NDK (as of r10e) only has GCC 4.9
+ // Once the Android NDK has a newer GCC version, update these to use intrinsics
+ while (data < end - Step * 3)
+ {
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[0])
+ : [two] "r" (h[0]),
+ [three] "r" (data[Step * 0]));
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[1])
+ : [two] "r" (h[1]),
+ [three] "r" (data[Step * 1]));
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[2])
+ : [two] "r" (h[2]),
+ [three] "r" (data[Step * 2]));
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[3])
+ : [two] "r" (h[3]),
+ [three] "r" (data[Step * 3]));
+
+ data += Step * 4;
+ }
+ if (data < end - Step * 0)
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[0])
+ : [two] "r" (h[0]),
+ [three] "r" (data[Step * 0]));
+ if (data < end - Step * 1)
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[1])
+ : [two] "r" (h[1]),
+ [three] "r" (data[Step * 1]));
+ if (data < end - Step * 2)
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[2])
+ : [two] "r" (h[2]),
+ [three] "r" (data[Step * 2]));
+
+ if (len & 7)
+ {
+ u64 temp = 0;
+ memcpy(&temp, end, len & 7);
+ asm ("crc32x %w[res], %w[two], %x[three]"
+ : [res] "=r" (h[0])
+ : [two] "r" (h[0]),
+ [three] "r" (temp));
+ }
+#endif
+#if _M_SSE >= 0x402 || defined(_M_ARM_64)
// FIXME: is there a better way to combine these partial hashes?
return h[0] + (h[1] << 10) + (h[2] << 21) + (h[3] << 32);
#else
return 0;
#endif
+
}
@@ -532,6 +589,12 @@ void SetHash64Function()
ptrHashFunction = &GetCRC32;
}
else
+#elif defined(_M_ARM_64)
+ if (cpu_info.bCRC32)
+ {
+ ptrHashFunction = &GetCRC32;
+ }
+ else
#endif
{
ptrHashFunction = &GetMurmurHash3;