Optimize bit counting using __builtin_popcount

Use the __builtin_popcount intrinsic to optimize the bit counting
function if the compiler supports it. This change replaces the manual
bit counting algorithm with the more efficient built-in function, which
leverages hardware support on compatible processors.

This modification ensures that the code remains backward-compatible by
falling back to the original implementation when __builtin_popcount is
not available.
This commit is contained in:
Kuan-Wei Chiu
2024-06-24 05:51:55 +08:00
parent 540d741df0
commit ac5815d994
2 changed files with 8 additions and 0 deletions

View File

@ -116,6 +116,10 @@
#include <TargetConditionals.h>
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#undef LIST_FOREACH /* clashes with FreeBSD */
#include "list.h"
#ifndef SIMPLE_FILES