public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Workaround for ffs() on LP64 targets
@ 2017-07-27  8:06 Sebastian Huber
  2017-07-27  8:29 ` Kito Cheng
  2017-07-27 11:13 ` Eric Blake
  0 siblings, 2 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-07-27  8:06 UTC (permalink / raw)
  To: newlib

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
 newlib/libc/misc/ffs.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/newlib/libc/misc/ffs.c b/newlib/libc/misc/ffs.c
index ba5700920..a09cbd3bb 100644
--- a/newlib/libc/misc/ffs.c
+++ b/newlib/libc/misc/ffs.c
@@ -31,6 +31,17 @@ No supporting OS subroutines are required.  */
 int
 ffs(int i)
 {
+#ifdef __LP64__
+	/* GCC would expand the __builtin_ffs() to ffs() in this case */
+	int bit;
+
+	if (i == 0)
+		return (0);
+	for (bit = 1; !(i & 1); bit++)
+		i = (unsigned int)i >> 1;
+	return (bit);
+#else
 
 	return (__builtin_ffs(i));
+#endif
 }
-- 
2.12.3

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-07-27 21:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27  8:06 [PATCH] Workaround for ffs() on LP64 targets Sebastian Huber
2017-07-27  8:29 ` Kito Cheng
2017-07-27  8:40   ` Sebastian Huber
2017-07-27  9:01     ` Kito Cheng
2017-07-27 11:13 ` Eric Blake
2017-07-27 11:25   ` Sebastian Huber
2017-07-27 12:27     ` Corinna Vinschen
2017-07-27 12:34       ` Sebastian Huber
2017-07-27 12:49         ` Corinna Vinschen
2017-07-27 12:53           ` Sebastian Huber
2017-07-27 21:03     ` Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).