From fe6d2d4017f62068db505fa1fb9f16253f15f5ab Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Thu, 1 Dec 2016 15:54:53 +0100 Subject: [PATCH] Avoid unaligned accesses when hashing vertex data on ARM. Fixes #9114, may help #9128 and #9129. --- GPU/Common/SplineCommon.cpp | 1 - GPU/Common/TextureDecoderNEON.cpp | 8 ++++++++ ext/xxhash.c | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 7443bebafe..7a89cd4831 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -118,7 +118,6 @@ inline float bern1(float x) { return 3 * x * (1 - x) * (1 - x); } inline float bern2(float x) { return 3 * x * x * (1 - x); } inline float bern3(float x) { return x * x * x; } -// Not sure yet if these have any use inline float bern0deriv(float x) { return -3 * (x - 1) * (x - 1); } inline float bern1deriv(float x) { return 9 * x * x - 12 * x + 3; } inline float bern2deriv(float x) { return 3 * (2 - 3 * x) * x; } diff --git a/GPU/Common/TextureDecoderNEON.cpp b/GPU/Common/TextureDecoderNEON.cpp index ef09e97255..011b078f6c 100644 --- a/GPU/Common/TextureDecoderNEON.cpp +++ b/GPU/Common/TextureDecoderNEON.cpp @@ -16,8 +16,11 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "ppsspp_config.h" + #if PPSSPP_ARCH(ARM_NEON) +#include "ext/xxhash.h" + #include #include "GPU/GPUState.h" @@ -182,6 +185,11 @@ void DoUnswizzleTex16NEON(const u8 *texptr, u32 *ydestp, int bxc, int byc, u32 p #endif u32 ReliableHash32NEON(const void *input, size_t len, u32 seed) { + if (((uintptr_t)input & 3) != 0) { + // Cannot handle misaligned data. Fall back to XXH32. + return XXH32(input, len, seed); + } + const u8 *p = (const u8 *)input; const u8 *const bEnd = p + len; U32 h32; diff --git a/ext/xxhash.c b/ext/xxhash.c index 55356c9295..5149945e44 100644 --- a/ext/xxhash.c +++ b/ext/xxhash.c @@ -39,7 +39,11 @@ You can contact the author at : // For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected. // If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance. // You can also enable this parameter if you know your input data will always be aligned (boundaries of 4, for U32). -#if !defined(IOS) && (defined(ARM) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) + +#include "ppsspp_config.h" + +// ector NOTE: For whatever reason ARM is unhappy about this on Android. +#if !defined(IOS) && !defined(ANDROID) && (defined(ARM) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) # define XXH_USE_UNALIGNED_ACCESS 1 #endif