Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Unified Diff: tests/ChecksumTest.cpp

Issue 2208903002: Use sse4.2 CRC32 instructions to hash when available. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | tools/UrlDataManager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ChecksumTest.cpp
diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp
index cf9d65c59edbb6f344c0f7b945443d7b21fbdf3c..2aaf2688b72e910fd64a33c44f39781bffc9c3db 100644
--- a/tests/ChecksumTest.cpp
+++ b/tests/ChecksumTest.cpp
@@ -5,21 +5,11 @@
* found in the LICENSE file.
*/
-#include "SkChecksum.h"
+#include "SkOpts.h"
#include "SkRandom.h"
#include "Test.h"
-
-// Murmur3 has an optional third seed argument, so we wrap it to fit a uniform type.
-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 uint32_t*, size_t);
- const algorithmProc kAlgorithms[] = { &murmur_noseed };
-
// Put 128 random bytes into two identical buffers. Any multiple of 4 will do.
const size_t kBytes = SkAlign4(128);
SkRandom rand;
@@ -28,38 +18,26 @@ DEF_TEST(Checksum, r) {
data[i] = tweaked[i] = rand.nextU();
}
- // Test each algorithm.
- for (size_t i = 0; i < SK_ARRAY_COUNT(kAlgorithms); ++i) {
- const algorithmProc algorithm = kAlgorithms[i];
-
- // Hash of nullptr is always 0.
- ASSERT(algorithm(nullptr, 0) == 0);
-
- const uint32_t hash = algorithm(data, kBytes);
- // Should be deterministic.
- ASSERT(hash == algorithm(data, kBytes));
-
- // Changing any single element should change the hash.
- for (size_t j = 0; j < SK_ARRAY_COUNT(tweaked); ++j) {
- const uint32_t saved = tweaked[j];
- tweaked[j] = rand.nextU();
- const uint32_t tweakedHash = algorithm(tweaked, kBytes);
- ASSERT(tweakedHash != hash);
- ASSERT(tweakedHash == algorithm(tweaked, kBytes));
- tweaked[j] = saved;
- }
+ // Hash of nullptr is always 0.
+ REPORTER_ASSERT(r, SkOpts::hash(nullptr, 0) == 0);
+
+ const uint32_t hash = SkOpts::hash(data, kBytes);
+ // Should be deterministic.
+ REPORTER_ASSERT(r, hash == SkOpts::hash(data, kBytes));
+
+ // Changing any single element should change the hash.
+ for (size_t j = 0; j < SK_ARRAY_COUNT(tweaked); ++j) {
+ const uint32_t saved = tweaked[j];
+ tweaked[j] = rand.nextU();
+ const uint32_t tweakedHash = SkOpts::hash(tweaked, kBytes);
+ REPORTER_ASSERT(r, tweakedHash != hash);
+ REPORTER_ASSERT(r, tweakedHash == SkOpts::hash(tweaked, kBytes));
+ tweaked[j] = saved;
}
}
DEF_TEST(GoodHash, r) {
- ASSERT(SkGoodHash()(( int32_t)4) == 614249093); // 4 bytes. Hits SkChecksum::Mix fast path.
- ASSERT(SkGoodHash()((uint32_t)4) == 614249093); // (Ditto)
-
- // None of these are 4 byte sized, so they use SkChecksum::Murmur3, not SkChecksum::Mix.
- ASSERT(SkGoodHash()((uint64_t)4) == 3491892518);
- ASSERT(SkGoodHash()((uint16_t)4) == 899251846);
- ASSERT(SkGoodHash()( (uint8_t)4) == 962700458);
-
- // Tests SkString is correctly specialized.
- ASSERT(SkGoodHash()(SkString("Hi")) == 55667557);
+ // 4 bytes --> hits SkChecksum::Mix fast path.
+ REPORTER_ASSERT(r, SkGoodHash()(( int32_t)4) == 614249093);
+ REPORTER_ASSERT(r, SkGoodHash()((uint32_t)4) == 614249093);
}
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | tools/UrlDataManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698