[Mesa-dev] [PATCH v2 3/3] util: use faster zlib's CRC32 implementaion
Grazvydas Ignotas
notasas at gmail.com
Tue Jan 9 22:58:34 UTC 2018
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 <notasas at gmail.com>
---
v2: drop the size threshold check because size is unlikely to be that
low of things mesa is typically hashing
src/util/crc32.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/util/crc32.c b/src/util/crc32.c
index f2e01c6..9edd3e1 100644
--- a/src/util/crc32.c
+++ b/src/util/crc32.c
@@ -31,10 +31,13 @@
*
* @author Jose Fonseca
*/
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+#endif
#include "crc32.h"
static const uint32_t
util_crc32_table[256] = {
@@ -112,10 +115,19 @@ uint32_t
util_hash_crc32(const void *data, size_t size)
{
const uint8_t *p = data;
uint32_t crc = 0xffffffff;
+#ifdef HAVE_ZLIB
+ /* 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);
return crc;
}
--
2.7.4
More information about the mesa-dev
mailing list