-
-
Save nikic/4b455d76d6cbb992700c326ae5a90acb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ext/standard/crc32.c b/ext/standard/crc32.c | |
index 904ea25ff7..ec48fa9301 100644 | |
--- a/ext/standard/crc32.c | |
+++ b/ext/standard/crc32.c | |
@@ -21,7 +21,6 @@ | |
#include "crc32.h" | |
#if defined(__aarch64__) | |
-# pragma GCC target ("+nothing+crc") | |
# include <arm_acle.h> | |
# if defined(__linux__) | |
# include <sys/auxv.h> | |
@@ -44,6 +43,29 @@ static inline int has_crc32_insn() { | |
return res; | |
# endif | |
} | |
+ | |
+static __attribute__((target("crc"))) | |
+uint32_t crc32_aarch64(uint32_t crc, char *p, size_t nr) { | |
+ while (nr >= sizeof(uint64_t)) { | |
+ crc = __crc32d(crc, *(uint64_t *)p); | |
+ p += sizeof(uint64_t); | |
+ nr -= sizeof(uint64_t); | |
+ } | |
+ if (nr >= sizeof(int32_t)) { | |
+ crc = __crc32w(crc, *(uint32_t *)p); | |
+ p += sizeof(uint32_t); | |
+ nr -= sizeof(uint32_t); | |
+ } | |
+ if (nr >= sizeof(int16_t)) { | |
+ crc = __crc32h(crc, *(uint16_t *)p); | |
+ p += sizeof(uint16_t); | |
+ nr -= sizeof(uint16_t); | |
+ } | |
+ if (nr) { | |
+ crc = __crc32b(crc, *p); | |
+ } | |
+ return crc; | |
+} | |
#endif | |
/* {{{ proto string crc32(string str) | |
@@ -63,28 +85,11 @@ PHP_NAMED_FUNCTION(php_if_crc32) | |
#if defined(__aarch64__) | |
if (has_crc32_insn()) { | |
- while(nr >= sizeof(uint64_t)) { | |
- crc = __crc32d(crc, *(uint64_t *)p); | |
- p += sizeof(uint64_t); | |
- nr -= sizeof(uint64_t); | |
- } | |
- if (nr >= sizeof(int32_t)) { | |
- crc = __crc32w(crc, *(uint32_t *)p); | |
- p += sizeof(uint32_t); | |
- nr -= sizeof(uint32_t); | |
- } | |
- if (nr >= sizeof(int16_t)) { | |
- crc = __crc32h(crc, *(uint16_t *)p); | |
- p += sizeof(uint16_t); | |
- nr -= sizeof(uint16_t); | |
- } | |
- if (nr) { | |
- crc = __crc32b(crc, *p); | |
- p += sizeof(uint8_t); | |
- nr -= sizeof(uint8_t); | |
- } | |
+ crc = crc32_aarch64(crc, p, nr); | |
+ RETVAL_LONG(crc^0xFFFFFFFF); | |
} | |
#endif | |
+ | |
for (; nr--; ++p) { | |
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment