com php-src: [AArch64] use rev64 to reverse strings: ext/standard/string.c
| From: | Nikita Popov | Date: | Tue, 07 May 2019 08:40:45 +0000 |
| Subject: | com php-src: [AArch64] use rev64 to reverse strings: ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106050@lists.php.net to get a copy of this message | ||
Commit: 68a7578243635c9dd83580ebbb32cdf5390a1984
Author: Sebastian Pop <spop@amazon.com> Fri, 3 May 2019 15:17:41 +0000
Committer: Nikita Popov <nikita.ppv@gmail.com> Tue, 7 May 2019 10:40:45 +0200
Parents: d9a2d76a43dd9343b6f95f9f3b0280f58225d4f6
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=68a7578243635c9dd83580ebbb32cdf5390a1984
Log:
[AArch64] use rev64 to reverse strings
The execution time goes from 4.388s down to 0.563s on a Graviton A1
instance for the benchmark:
function reverse_strings() {
$a = "foo";
for ($i = 0; $i < 100000; $i++) {
strrev($a);
$a .= "o";
}
}
Changed paths:
M ext/standard/string.c
Diff:
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 0ec4bf7..706828c 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3536,6 +3536,8 @@ PHP_FUNCTION(strtr)
Reverse a string */
#if ZEND_INTRIN_SSSE3_NATIVE
#include <tmmintrin.h>
+#elif defined(__aarch64__)
+#include <arm_neon.h>
#endif
PHP_FUNCTION(strrev)
{
@@ -3568,6 +3570,19 @@ PHP_FUNCTION(strrev)
e -= 16;
} while (e - s > 15);
}
+#elif defined(__aarch64__)
+ if (e - s > 15) {
+ do {
+ const uint8x16_t str = vld1q_u8((uint8_t *)(e - 15));
+ /* Synthesize rev128 with a rev64 + ext. */
+ const uint8x16_t rev = vrev64q_u8(str);
+ const uint8x16_t ext = (uint8x16_t)
+ vextq_u64((uint64x2_t)rev, (uint64x2_t)rev, 1);
+ vst1q_u8((uint8_t *)p, ext);
+ p += 16;
+ e -= 16;
+ } while (e - s > 15);
+ }
#endif
while (e >= s) {
*p++ = *e--;