Fix compilation on compilers that do not support target attribute (#13609)

introduced by https://github.com/redis/redis/pull/13359
failure CI on ARM64:
https://github.com/redis/redis-extra-ci/actions/runs/11377893230/job/31652773710

---------

Co-authored-by: Ozan Tezcan <ozantezcan@gmail.com>
Co-authored-by: ShooterIT <wangyuancode@163.com>
This commit is contained in:
debing.sun
2024-10-18 09:11:23 +08:00
committed by GitHub
parent 3788a055fe
commit 4f8cdc2a1e
2 changed files with 13 additions and 2 deletions

View File

@@ -16,12 +16,12 @@
/* Count number of bits set in the binary array pointed by 's' and long
* 'count' bytes. The implementation of this function is required to
* work with an input string length up to 512 MB or more (server.proto_max_bulk_len) */
__attribute__((target("popcnt")))
ATTRIBUTE_TARGET_POPCNT
long long redisPopcount(void *s, long count) {
long long bits = 0;
unsigned char *p = s;
uint32_t *p4;
#if defined(__x86_64__) && ((defined(__GNUC__) && __GNUC__ > 5) || (defined(__clang__)))
#if defined(HAVE_POPCNT)
int use_popcnt = __builtin_cpu_supports("popcnt"); /* Check if CPU supports POPCNT instruction. */
#else
int use_popcnt = 0; /* Assume CPU does not support POPCNT if

View File

@@ -307,4 +307,15 @@ void setcpuaffinity(const char *cpulist);
#define HAVE_FADVISE
#endif
#if defined(__x86_64__) && ((defined(__GNUC__) && __GNUC__ > 5) || (defined(__clang__)))
#if defined(__has_attribute) && __has_attribute(target)
#define HAVE_POPCNT
#define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))
#else
#define ATTRIBUTE_TARGET_POPCNT
#endif
#else
#define ATTRIBUTE_TARGET_POPCNT
#endif
#endif