21#ifdef HAVE_AARCH64_CRC32
25# if defined(__linux__)
27# include <asm/hwcap.h>
28# elif defined(__APPLE__)
29# include <sys/sysctl.h>
30# elif defined(HAVE_ELF_AUX_INFO)
33static unsigned long getauxval(
unsigned long key) {
34 unsigned long ret = 0;
35 if (elf_aux_info(
key, &
ret,
sizeof(
ret)) != 0)
41static inline int has_crc32_insn(
void) {
46# if defined(HWCAP_CRC32)
47 res = getauxval(AT_HWCAP) & HWCAP_CRC32;
49# elif defined(HWCAP2_CRC32)
50 res = getauxval(AT_HWCAP2) & HWCAP2_CRC32;
52# elif defined(__APPLE__)
53 size_t reslen =
sizeof(
res);
54 if (sysctlbyname(
"hw.optional.armv8_crc32", &
res, &reslen,
NULL, 0) < 0)
58 res = (int)IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
67# if!defined(__clang__)
68# pragma GCC push_options
69# pragma GCC target ("+nothing+crc")
70# elif defined(__APPLE__)
71# pragma clang attribute push(__attribute__((target("crc"))), apply_to=function)
73# pragma clang attribute push(__attribute__((target("+nothing+crc"))), apply_to=function)
76static uint32_t crc32_aarch64(uint32_t crc,
const char *
p,
size_t nr) {
77 while (nr >=
sizeof(uint64_t)) {
78 crc = __crc32d(crc, *(uint64_t *)
p);
79 p +=
sizeof(uint64_t);
80 nr -=
sizeof(uint64_t);
82 if (nr >=
sizeof(int32_t)) {
83 crc = __crc32w(crc, *(uint32_t *)
p);
84 p +=
sizeof(uint32_t);
85 nr -=
sizeof(uint32_t);
87 if (nr >=
sizeof(int16_t)) {
88 crc = __crc32h(crc, *(uint16_t *)
p);
89 p +=
sizeof(uint16_t);
90 nr -=
sizeof(uint16_t);
93 crc = __crc32b(crc, *
p);
98# if !defined(__clang__)
99# pragma GCC pop_options
100# elif defined(__APPLE__)
101# pragma clang attribute pop
103# pragma clang attribute pop
110#ifdef HAVE_AARCH64_CRC32
111 if (has_crc32_insn()) {
112 crc = crc32_aarch64(crc,
p, nr);
117#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE) || defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
118 size_t nr_simd = crc32_x86_simd_update(
X86_CRC32B, &crc, (
const unsigned char *)
p, nr);
125 crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*
p)) & 0xFF ];
133 size_t handled = 0,
n;
136 while (handled < nr) {
PHPAPI uint32_t php_crc32_bulk_update(uint32_t crc, const char *p, size_t nr)
PHPAPI zend_result php_crc32_stream_bulk_update(uint32_t *crc, php_stream *fp, size_t nr)
#define php_crc32_bulk_init()
#define php_crc32_bulk_end(c)
zend_ffi_ctype_name_buf buf
unsigned char key[REFLECTION_KEY_LEN]
struct _php_stream php_stream
#define php_stream_read(stream, buf, count)
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_STRING(dest, dest_len)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
ZEND_RESULT_CODE zend_result