aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkChecksum.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-09 17:40:48 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-09 17:40:48 +0000
commitfc8581b2d8c63439162c701623bce096088ce6e6 (patch)
treecf63f8899846e2c94c71af0df46f2b01dc6ab316 /include/core/SkChecksum.h
parentf8affe5adff8e82ca6a3e5b98b0d772e204edc51 (diff)
revert 4478
git-svn-id: http://skia.googlecode.com/svn/trunk@4479 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkChecksum.h')
-rw-r--r--include/core/SkChecksum.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/include/core/SkChecksum.h b/include/core/SkChecksum.h
index e66df54aaf..e767670191 100644
--- a/include/core/SkChecksum.h
+++ b/include/core/SkChecksum.h
@@ -10,6 +10,64 @@
#include "SkTypes.h"
+#if !defined(SK_PREFER_32BIT_CHECKSUM)
+#define SK_PREFER_32BIT_CHECKSUM 0
+#endif
+
+enum {
+ ChecksumRotateBits = 17
+};
+
+#define SkCHECKSUM_MASH(CHECKSUM, NEW_CHUNK) \
+ CHECKSUM = (((CHECKSUM) >> (sizeof(CHECKSUM)*8 - ChecksumRotateBits)) + \
+ ((CHECKSUM) << ChecksumRotateBits)) ^ (NEW_CHUNK);
+
+
+/**
+ * Compute a 64-bit checksum for a given data block
+ *
+ * @param data Memory address of the data block to be processed. Must be
+ * 32-bit aligned
+ * @param size Size of the data block in bytes. Must be a multiple of 8.
+ * @return checksum result
+ */
+inline uint64_t SkComputeChecksum64(const uint64_t* ptr, size_t size) {
+ SkASSERT(SkIsAlign8(size));
+ // Strict 8-byte alignment is not required on ptr. On current
+ // CPUs there is no measurable performance difference between 32-bit
+ // and 64-bit aligned access to uint64_t data
+ SkASSERT(SkIsAlign4((intptr_t)ptr));
+
+ const uint64_t* stop = ptr + (size >> 3);
+ uint64_t result = 0;
+ while (ptr < stop) {
+ SkCHECKSUM_MASH(result, *ptr);
+ ptr++;
+ }
+ return result;
+}
+
+/**
+ * Compute a 32-bit checksum for a given data block
+ *
+ * @param data Memory address of the data block to be processed. Must be
+ * 32-bit aligned.
+ * @param size Size of the data block in bytes. Must be a multiple of 4.
+ * @return checksum result
+ */
+inline uint32_t SkComputeChecksum32(const uint32_t* ptr, size_t size) {
+ SkASSERT(SkIsAlign4(size));
+ SkASSERT(SkIsAlign4((intptr_t)ptr));
+
+ const uint32_t* stop = ptr + (size >> 2);
+ uint32_t result = 0;
+ while (ptr < stop) {
+ SkCHECKSUM_MASH(result, *ptr);
+ ptr++;
+ }
+ return result;
+}
+
class SkChecksum : SkNoncopyable {
private:
/*