]> granicus.if.org Git - php/commitdiff
Mac M1 crc32 detection support
authorDavid CARLIER <devnexen@gmail.com>
Thu, 31 Dec 2020 14:52:57 +0000 (14:52 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 4 Jan 2021 10:41:52 +0000 (11:41 +0100)
Closes GH-6556.

ext/standard/crc32.c

index 40d9404053e285aab1ba6357f3af4979a029701d..83f4314b694fb34037fc87885d9d431d155757c6 100644 (file)
@@ -24,6 +24,8 @@
 # if defined(__linux__)
 #  include <sys/auxv.h>
 #  include <asm/hwcap.h>
+# elif defined(__APPLE__)
+#  include <sys/sysctl.h>
 # endif
 
 static inline int has_crc32_insn() {
@@ -37,6 +39,10 @@ static inline int has_crc32_insn() {
 # elif defined(HWCAP2_CRC32)
        res = getauxval(AT_HWCAP2) & HWCAP2_CRC32;
        return res;
+# elif defined(__APPLE__)
+       size_t reslen = sizeof(res);
+       if (sysctlbyname("hw.optional.armv8_crc32", &res, &reslen, NULL, 0) < 0)
+               res = 0;
 # else
        res = 0;
        return res;