Unverified Commit 4f8cdc2a authored by debing.sun's avatar debing.sun Committed by GitHub
Browse files

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: default avatarOzan Tezcan <ozantezcan@gmail.com>
Co-authored-by: default avatarShooterIT <wangyuancode@163.com>
parent 3788a055
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
/* Count number of bits set in the binary array pointed by 's' and long /* Count number of bits set in the binary array pointed by 's' and long
* 'count' bytes. The implementation of this function is required to * '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) */ * 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 redisPopcount(void *s, long count) {
long long bits = 0; long long bits = 0;
unsigned char *p = s; unsigned char *p = s;
uint32_t *p4; 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. */ int use_popcnt = __builtin_cpu_supports("popcnt"); /* Check if CPU supports POPCNT instruction. */
#else #else
int use_popcnt = 0; /* Assume CPU does not support POPCNT if int use_popcnt = 0; /* Assume CPU does not support POPCNT if
......
...@@ -307,4 +307,15 @@ void setcpuaffinity(const char *cpulist); ...@@ -307,4 +307,15 @@ void setcpuaffinity(const char *cpulist);
#define HAVE_FADVISE #define HAVE_FADVISE
#endif #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 #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment