Replace SkConsistentChecksum with SkCityHash (now including CityHash via DEPS)

Alternative to https://codereview.appspot.com/6847087/ ('Change SkConsistentChecksum to use SuperFastHash')
Review URL: https://codereview.appspot.com/6867060

git-svn-id: http://skia.googlecode.com/svn/trunk@6701 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkCityHash.cpp b/src/utils/SkCityHash.cpp
new file mode 100644
index 0000000..a21aa89
--- /dev/null
+++ b/src/utils/SkCityHash.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * Pass any calls through to the CityHash library.
+ * This is the only source file that accesses the CityHash code directly.
+ */
+
+#include "SkCityHash.h"
+#include "SkTypes.h"
+#include "city.h"
+
+uint32_t SkCityHash::Compute32(const char *data, size_t size) {
+    return CityHash32(data, size);
+}
+
+uint64_t SkCityHash::Compute64(const char *data, size_t size) {
+    return CityHash64(data, size);
+}
diff --git a/src/utils/SkCityHash.h b/src/utils/SkCityHash.h
new file mode 100644
index 0000000..c69e0fb
--- /dev/null
+++ b/src/utils/SkCityHash.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * Hash functions, using the CityHash algorithm.
+ *
+ * Results are guaranteed to be:
+ *  1. consistent across revisions of the library (for a given set
+ *     of bytes, the checksum generated at one revision of the Skia
+ *     library will match the one generated on any other revision of
+ *     the Skia library)
+ *  2. consistent across platforms (for a given
+ *     set of bytes, the checksum generated on one platform will
+ *     match the one generated on any other platform)
+ */
+
+#ifndef SkCityHash_DEFINED
+#define SkCityHash_DEFINED
+
+#include "SkTypes.h"
+
+class SkCityHash : SkNoncopyable {
+public:
+    /**
+     *  Compute a 32-bit checksum for a given data block.
+     *
+     *  @param data Memory address of the data block to be processed.
+     *  @param size Size of the data block in bytes.
+     *  @return checksum result
+     */
+    static uint32_t Compute32(const char *data, size_t size);
+
+    /**
+     *  Compute a 64-bit checksum for a given data block.
+     *
+     *  @param data Memory address of the data block to be processed.
+     *  @param size Size of the data block in bytes.
+     *  @return checksum result
+     */
+    static uint64_t Compute64(const char *data, size_t size);
+};
+
+#endif
diff --git a/src/utils/SkConsistentChecksum.h b/src/utils/SkConsistentChecksum.h
deleted file mode 100644
index 8b7c53d..0000000
--- a/src/utils/SkConsistentChecksum.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkConsistentChecksum_DEFINED
-#define SkConsistentChecksum_DEFINED
-
-#include "SkTypes.h"
-
-class SkConsistentChecksum : SkNoncopyable {
-private:
-    /*
-     *  Our Rotate and Mash helpers are meant to automatically do the right
-     *  thing depending if sizeof(uintptr_t) is 4 or 8.
-     */
-    enum {
-        ROTR = 17,
-        ROTL = sizeof(uintptr_t) * 8 - ROTR,
-        HALFBITS = sizeof(uintptr_t) * 4
-    };
-
-    static inline uintptr_t Mash(uintptr_t total, uintptr_t value) {
-        return ((total >> ROTR) | (total << ROTL)) ^ value;
-    }
-
-public:
-    /**
-     *  Compute a 32-bit checksum for a given data block
-     *
-     *  WARNING: As of 1 Nov 2012, this algorithm is still in
-     *  flux... but once we get it doing what we want, it will be:
-     *  1. consistent across revisions of the library (for a given set
-     *     of bytes, the checksum generated at one revision of the Skia
-     *     library will match the one generated on any other revision of
-     *     the Skia library)
-     *  2. consistent across platforms (for a given
-     *     set of bytes, the checksum generated on one platform will
-     *     match the one generated on any other platform)
-     *
-     *  @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
-     */
-    static uint32_t Compute(const uint32_t* data, size_t size) {
-        SkASSERT(SkIsAlign4(size));
-
-        /*
-         *  We want to let the compiler use 32bit or 64bit addressing and math
-         *  so we use uintptr_t as our magic type. This makes the code a little
-         *  more obscure (we can't hard-code 32 or 64 anywhere, but have to use
-         *  sizeof()).
-         */
-        uintptr_t result = 0;
-        const uintptr_t* ptr = reinterpret_cast<const uintptr_t*>(data);
-
-        /*
-         *  count the number of quad element chunks. This takes into account
-         *  if we're on a 32bit or 64bit arch, since we use sizeof(uintptr_t)
-         *  to compute how much to shift-down the size.
-         */
-        size_t n4 = size / (sizeof(uintptr_t) << 2);
-        for (size_t i = 0; i < n4; ++i) {
-            result = Mash(result, *ptr++);
-            result = Mash(result, *ptr++);
-            result = Mash(result, *ptr++);
-            result = Mash(result, *ptr++);
-        }
-        size &= ((sizeof(uintptr_t) << 2) - 1);
-
-        data = reinterpret_cast<const uint32_t*>(ptr);
-        const uint32_t* stop = data + (size >> 2);
-        while (data < stop) {
-            result = Mash(result, *data++);
-        }
-
-        /*
-         *  smash us down to 32bits if we were 64. Note that when uintptr_t is
-         *  32bits, this code-path should go away, but I still got a warning
-         *  when I wrote
-         *      result ^= result >> 32;
-         *  since >>32 is undefined for 32bit ints, hence the wacky HALFBITS
-         *  define.
-         */
-        if (8 == sizeof(result)) {
-            result ^= result >> HALFBITS;
-        }
-        return static_cast<uint32_t>(result);
-    }
-};
-
-#endif
diff --git a/src/utils/cityhash/README b/src/utils/cityhash/README
new file mode 100644
index 0000000..d939288
--- /dev/null
+++ b/src/utils/cityhash/README
@@ -0,0 +1,2 @@
+This directory contains files needed to build third_party/externals/cityhash
+(such as the config.h file that would normally be created by autoconf)
diff --git a/src/utils/cityhash/config.h b/src/utils/cityhash/config.h
new file mode 100644
index 0000000..bd36416
--- /dev/null
+++ b/src/utils/cityhash/config.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * Converts from Skia build flags to the macro definitions cityhash normally
+ * gets from autoconf.
+ */
+
+#include "SkTypes.h"
+
+#ifdef SK_CPU_BENDIAN
+  #define WORDS_BIGENDIAN 1
+#endif