From bbf9f6d1cbb94d3486072228781f6e3b6e2252e4 Mon Sep 17 00:00:00 2001 From: reed Date: Thu, 10 Jul 2014 14:29:43 -0700 Subject: [PATCH] Revert of Slim Skia down to just one murmur3 implementation. (https://codereview.chromium.org/376183004/) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reason for revert: broke 10.6 compile [17:13:56.863876] [4/336] CXX obj/src/core/core.SkBBoxHierarchyRecord.o [17:13:56.863997] FAILED: c++ -MMD -MF obj/src/core/core.SkBBoxRecord.o.d -DSK_INTERNAL -DSK_GAMMA_SRGB -DSK_GAMMA_APPLY_TO_A8 -DSK_SCALAR_TO_FLOAT_EXCLUDED -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1 -DSK_SUPPORT_GPU=1 -DSK_SUPPORT_OPENCL=0 -DSK_FORCE_DISTANCEFIELD_FONTS=0 -DSK_SCALAR_IS_FLOAT -DSK_BUILD_FOR_MAC -DSK_USE_POSIX_THREADS -DSK_RELEASE -DNDEBUG -I../../include/config -I../../include/core -I../../include/pathops -I../../include/pipe -I../../include/ports -I../../include/utils -I../../include/xml -I../../src/core -I../../src/sfnt -I../../src/image -I../../src/opts -I../../src/utils -I../../include/utils/mac -I../../include/gpu -I../../src/gpu -fasm-blocks -mpascal-strings -O3 -gdwarf-2 -Wnewline-eof -mmacosx-version-min=10.6 -arch x86_64 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -c ../../src/core/SkBBoxRecord.cpp -o obj/src/core/core.SkBBoxRecord.o [17:13:56.864085] In file included from ../../src/core/SkPictureFlat.h:14, [17:13:56.864130] from ../../src/core/SkPictureData.h:14, [17:13:56.864173] from ../../src/core/SkPictureRecord.h:18, [17:13:56.864217] from ../../src/core/SkBBoxRecord.h:12, [17:13:56.864261] from ../../src/core/SkBBoxRecord.cpp:9: [17:13:56.864336] ../../src/core/SkChecksum.h: In static member function ‘static uint32_t SkChecksum::Compute(const uint32_t*, size_t)’: [17:13:56.864397] ../../src/core/SkChecksum.h:127: error: invalid conversion from ‘const uint32_t*’ to ‘const uint32_t*’ [17:13:56.864462] ../../src/core/SkChecksum.h:128: error: invalid conversion from ‘const uint32_t*’ to ‘const uint32_t*’ [17:13:56.864510] ../../src/core/SkChecksum.h:129: error: comparison between distinct pointer types ‘const uint32_t*’ and ‘const uint32_t*’ lacks a cast Original issue's description: > Slim Skia down to just one murmur3 implementation. > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/6ac0037b70410ff7d5ce5788bc89314223e1a587 > > Committed: https://skia.googlesource.com/skia/+/67a3271f0de9ccc32d559b042b862528272047cc > > Committed: https://skia.googlesource.com/skia/+/53d435990bdb4d14df78013da45a9364d0287ebe R=mtklein@google.com, mtklein@chromium.org TBR=mtklein@chromium.org, mtklein@google.com NOTREECHECKS=true NOTRY=true BUG=skia: Author: reed@google.com Review URL: https://codereview.chromium.org/381253003 --- src/core/SkChecksum.h | 8 ++------ src/core/SkImageFilter.cpp | 28 ++++++++++++++++++++++++++-- tests/ChecksumTest.cpp | 6 ++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/core/SkChecksum.h b/src/core/SkChecksum.h index daf87cf..fe1e958 100644 --- a/src/core/SkChecksum.h +++ b/src/core/SkChecksum.h @@ -51,10 +51,6 @@ public: return hash; } - // Remind compiler that our users will be intentionally violating strict aliasing by casting - // their data to const uint32_t*, so don't apply any strict-aliasing-based optimizations. - typedef uint32_t SK_ATTRIBUTE(may_alias) FourByteAligned; - /** * Calculate 32-bit Murmur hash (murmur3). * This should take 2-3x longer than SkChecksum::Compute, but is a considerably better hash. @@ -65,7 +61,7 @@ public: * @param seed Initial hash seed. (optional) * @return hash result */ - static uint32_t Murmur3(const FourByteAligned* data, size_t bytes, uint32_t seed=0) { + static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) { SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes); const size_t words = bytes/4; @@ -98,7 +94,7 @@ public: * @param size Size of the data block in bytes. Must be a multiple of 4. * @return checksum result */ - static uint32_t Compute(const FourByteAligned* data, size_t size) { + static uint32_t Compute(const uint32_t* data, size_t size) { SkASSERT(SkIsAlign4(size)); /* diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 8a0e734..64603b4 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -8,7 +8,6 @@ #include "SkImageFilter.h" #include "SkBitmap.h" -#include "SkChecksum.h" #include "SkDevice.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" @@ -335,6 +334,31 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, } #endif +static uint32_t compute_hash(const uint32_t* data, int count) { + uint32_t hash = 0; + + for (int i = 0; i < count; ++i) { + uint32_t k = data[i]; + k *= 0xcc9e2d51; + k = (k << 15) | (k >> 17); + k *= 0x1b873593; + + hash ^= k; + hash = (hash << 13) | (hash >> 19); + hash *= 5; + hash += 0xe6546b64; + } + + // hash ^= size; + hash ^= hash >> 16; + hash *= 0x85ebca6b; + hash ^= hash >> 13; + hash *= 0xc2b2ae35; + hash ^= hash >> 16; + + return hash; +} + class CacheImpl : public SkImageFilter::Cache { public: explicit CacheImpl(int minChildren) : fMinChildren(minChildren) { @@ -357,7 +381,7 @@ private: return v.fKey; } static uint32_t Hash(Key key) { - return SkChecksum::Murmur3(reinterpret_cast(&key), sizeof(Key)); + return compute_hash(reinterpret_cast(&key), sizeof(Key) / sizeof(uint32_t)); } }; SkTDynamicHash fData; diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp index 923f303..6248678 100644 --- a/tests/ChecksumTest.cpp +++ b/tests/ChecksumTest.cpp @@ -11,15 +11,13 @@ // Murmur3 has an optional third seed argument, so we wrap it to fit a uniform type. -static uint32_t murmur_noseed(const SkChecksum::FourByteAligned* d, size_t l) { - return SkChecksum::Murmur3(d, l); -} +static uint32_t murmur_noseed(const uint32_t* d, size_t l) { return SkChecksum::Murmur3(d, l); } #define ASSERT(x) REPORTER_ASSERT(r, x) DEF_TEST(Checksum, r) { // Algorithms to test. They're currently all uint32_t(const uint32_t*, size_t). - typedef uint32_t(*algorithmProc)(const SkChecksum::FourByteAligned*, size_t); + typedef uint32_t(*algorithmProc)(const uint32_t*, size_t); const algorithmProc kAlgorithms[] = { &SkChecksum::Compute, &murmur_noseed }; // Put 128 random bytes into two identical buffers. Any multiple of 4 will do. -- 2.7.4