summaryrefslogtreecommitdiff
path: root/pkg/mtdev/patch/0001-Avoid-__builtin_ffs.patch
blob: 749bda5612bf3c9c9a4e85267fbe8b87ffc69448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From 09e21bb5d6714687705dc8f2d00a09b3ff3b2436 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
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