diff options
author | 2016-08-08 09:06:27 -0700 | |
---|---|---|
committer | 2016-08-08 09:06:28 -0700 | |
commit | 4e97607d9a1cef66fac16f347c5ca813ec4f9515 (patch) | |
tree | e523cac97fae89a2abb1ec0d4c1fc87f86e3169f /include/private/SkChecksum.h | |
parent | 9a5a201472c3fb9f02b954ba09ae1ec13ebd50f4 (diff) |
Use sse4.2 CRC32 instructions to hash when available.
About 9x faster than Murmur3 for long inputs.
Most of this is a mechanical change from SkChecksum::Murmur3(...) to SkOpts::hash(...).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2208903002
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot;master.client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot
Review-Url: https://codereview.chromium.org/2208903002
Diffstat (limited to 'include/private/SkChecksum.h')
-rw-r--r-- | include/private/SkChecksum.h | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/include/private/SkChecksum.h b/include/private/SkChecksum.h index 6289a444ae..8a04c89ae7 100644 --- a/include/private/SkChecksum.h +++ b/include/private/SkChecksum.h @@ -12,6 +12,12 @@ #include "SkTLogic.h" #include "SkTypes.h" +// #include "SkOpts.h" +// It's sort of pesky to be able to include SkOpts.h here, so we'll just re-declare what we need. +namespace SkOpts { + extern uint32_t (*hash_fn)(const void*, size_t, uint32_t); +} + class SkChecksum : SkNoncopyable { public: /** @@ -41,17 +47,6 @@ public: hash ^= hash >> 16; return hash; } - - /** - * Calculate 32-bit Murmur hash (murmur3). - * See en.wikipedia.org/wiki/MurmurHash. - * - * @param data Memory address of the data block to be processed. - * @param size Size of the data block in bytes. - * @param seed Initial hash seed. (optional) - * @return hash result - */ - static uint32_t Murmur3(const void* data, size_t bytes, uint32_t seed=0); }; // SkGoodHash should usually be your first choice in hashing data. @@ -64,11 +59,11 @@ struct SkGoodHash { template <typename K> SK_WHEN(sizeof(K) != 4, uint32_t) operator()(const K& k) const { - return SkChecksum::Murmur3(&k, sizeof(K)); + return SkOpts::hash_fn(&k, sizeof(K), 0); } uint32_t operator()(const SkString& k) const { - return SkChecksum::Murmur3(k.c_str(), k.size()); + return SkOpts::hash_fn(k.c_str(), k.size(), 0); } }; |