com php-src: Load 8 bytes at a time in hash_func. (Seba stian Pop): Zend/zend_string.h
| From: | Dmitry Stogov | Date: | Mon, 13 May 2019 09:34:53 +0000 |
| Subject: | com php-src: Load 8 bytes at a time in hash_func. (Seba stian Pop): Zend/zend_string.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106157@lists.php.net to get a copy of this message | ||
Commit: 071793a0bb278559c32efefbde180727aa312856
Author: Dmitry Stogov <dmitry@zend.com> Mon, 13 May 2019 12:34:53 +0300
Parents: bec6ff90217376baeaf7114359c5273933cbeeca
Branches: PHP-7.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=071793a0bb278559c32efefbde180727aa312856
Log:
Load 8 bytes at a time in hash_func. (Sebastian Pop)
Changed paths:
M Zend/zend_string.h
Diff:
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index 793a519..4fb3e3b 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -364,6 +364,25 @@ static zend_always_inline zend_ulong zend_inline_hash_func(const char *str,
size
#if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
/* Version with multiplication works better on modern CPU */
for (; len >= 8; len -= 8, str += 8) {
+# if defined(__aarch64__)
+ /* On some architectures it is beneficial to load 8 bytes at a
+ time and extract each byte with a bit field extract instr. */
+ uint64_t chunk;
+
+ memcpy(&chunk, str, sizeof(chunk));
+ hash =
+ hash * 33 * 33 * 33 * 33 +
+ ((chunk >> (8 * 0)) & 0xff) * 33 * 33 * 33 +
+ ((chunk >> (8 * 1)) & 0xff) * 33 * 33 +
+ ((chunk >> (8 * 2)) & 0xff) * 33 +
+ ((chunk >> (8 * 3)) & 0xff);
+ hash =
+ hash * 33 * 33 * 33 * 33 +
+ ((chunk >> (8 * 4)) & 0xff) * 33 * 33 * 33 +
+ ((chunk >> (8 * 5)) & 0xff) * 33 * 33 +
+ ((chunk >> (8 * 6)) & 0xff) * 33 +
+ ((chunk >> (8 * 7)) & 0xff);
+# else
hash =
hash * 33 * 33 * 33 * 33 +
str[0] * 33 * 33 * 33 +
@@ -376,6 +395,7 @@ static zend_always_inline zend_ulong zend_inline_hash_func(const char *str, size
str[5] * 33 * 33 +
str[6] * 33 +
str[7];
+# endif
}
if (len >= 4) {
hash =