Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ext/standard/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@
# if defined(__linux__)
# include <sys/auxv.h>
# include <asm/hwcap.h>
# elif defined(__FreeBSD__)
# include <sys/auxv.h>
# include <elf.h>
# endif

static inline int has_crc32_insn() {
/* Only go through the runtime detection once. */
static int res = -1;
if (res != -1)
return res;
# if defined(__linux__)
# if defined(HWCAP_CRC32)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should be indented.

res = getauxval(AT_HWCAP) & HWCAP_CRC32;
return res;
# elif defined(HWCAP2_CRC32)
res = getauxval(AT_HWCAP2) & HWCAP2_CRC32;
return res;
# endif
# elif defined(__FreeBSD__)
# if defined(HWCAP_CRC32)
zend_long crc32 = 0;
if (elf_aux_info(AT_HWCAP, &crc32, sizeof(crc32)) == 0)
res = crc32 & HWCAP_CRC32;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

res isn't returned here. This will only work on the second run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I forgot about this one but a lot had changed since and it s an useless change now, FreeBSD uses a wrapper to be closer to Linux.

# endif
# else
res = 0;
return res;
Expand Down