From ec78add6ab1db373be9a8a9f7e22ef4bfd9bc716 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 25 Aug 2018 03:09:09 -0400 Subject: [PATCH] define ffzl utility function --- malloc.c | 4 ++-- util.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/malloc.c b/malloc.c index 93008dd..a3225bf 100644 --- a/malloc.c +++ b/malloc.c @@ -264,11 +264,11 @@ static size_t get_free_slot(struct random_state *rng, size_t slots, struct slab_ // randomize start location for linear search (uniform random choice is too slow) uint64_t random_split = ~0UL >> get_random_size_uniform(rng, slots); - size_t slot = __builtin_ffsl(~(masked | random_split)); + size_t slot = ffzl(masked | random_split); if (slot) { return slot - 1; } else { - return __builtin_ffsl(~masked) - 1; + return ffzl(masked) - 1; } } diff --git a/util.h b/util.h index 8f51f52..1a90e13 100644 --- a/util.h +++ b/util.h @@ -10,6 +10,10 @@ #define UNUSED __attribute__((unused)) #define EXPORT __attribute__((visibility("default"))) +static inline int ffzl(long x) { + return __builtin_ffsl(~x); +} + COLD noreturn void fatal_error(const char *s); #endif