summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorGrazvydas Ignotas <[email protected]>2017-12-29 02:05:05 +0200
committerGrazvydas Ignotas <[email protected]>2018-01-14 19:10:33 +0200
commit6acf22a17991e3e98c35596f0b1cedfaebed6ec3 (patch)
treef4b25b6f62b76d4649122e4b908239fef4399b63 /src/util
parent87f723408b3f4c088dcb819e88922918ae064d72 (diff)
util: use faster zlib's CRC32 implementaion
zlib provides a faster slice-by-4 CRC32 implementation than the traditional single byte lookup one used by mesa. As most supported platforms now link zlib unconditionally, we can easily use it. Improvement for a 1MB buffer (avg MB/s, n=100, zlib 1.2.8): i5-6600K C2D E4500 mesa zlib mesa zlib 443 1443 225% +/- 2.1% 403 1175 191% +/- 0.9% It has been verified the calculation results stay the same after this change. Signed-off-by: Grazvydas Ignotas <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crc32.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/crc32.c b/src/util/crc32.c
index f2e01c61e58..425046ab5fd 100644
--- a/src/util/crc32.c
+++ b/src/util/crc32.c
@@ -33,6 +33,9 @@
*/
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+#endif
#include "crc32.h"
@@ -114,6 +117,16 @@ util_hash_crc32(const void *data, size_t size)
const uint8_t *p = data;
uint32_t crc = 0xffffffff;
+#ifdef HAVE_ZLIB
+ /* Prefer zlib's implementation for better performance.
+ * zlib's uInt is always "unsigned int" while size_t can be 64bit.
+ * Since 1.2.9 there's crc32_z that takes size_t, but use the more
+ * available function to avoid build system complications.
+ */
+ if ((uInt)size == size)
+ return ~crc32(0, data, size);
+#endif
+
while (size--)
crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);