From 09e21bb5d6714687705dc8f2d00a09b3ff3b2436 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 7 Jun 2019 11:55:26 -0700 Subject: [PATCH] Avoid __builtin_ffs --- src/common.h | 5 +---- src/core.c | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/common.h b/src/common.h index 80a3d6e..3c77f48 100644 --- a/src/common.h +++ b/src/common.h @@ -77,12 +77,9 @@ static inline int bitcount(unsigned v) return (((v + (v>>4)) & 0xF0F0F0F) * 0x1010101) >> 24; } -/* Return index of first bit [0-31], -1 on zero */ -#define firstbit(v) (__builtin_ffs(v) - 1) - /* boost-style foreach bit */ #define foreach_bit(i, m) \ - for (i = firstbit(m); i >= 0; i = firstbit((m) & (~0U << (i + 1)))) + for (i = -1; (m) & ~0U << (i + 1);) if ((m) & 1U << ++i) /* robust system ioctl calls */ #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) diff --git a/src/core.c b/src/core.c index 0d91c0b..20ce0c6 100644 --- a/src/core.c +++ b/src/core.c @@ -304,7 +304,7 @@ static void apply_typeA_changes(struct mtdev_state *state, break; } if (id != MT_ID_NULL) { - slot = firstbit(unused); + foreach_bit(slot, unused) break; push_slot_changes(state, &data[i], prop[i], slot, syn); SETBIT(used, slot); CLEARBIT(unused, slot); -- 2.25.0