This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gold patch committed: Provide own version of ffsll


Dave Korn <dave.korn.cygwin@googlemail.com> writes:

> Ian Lance Taylor wrote:
>> gold uses ffsll, particularly since gcc expands it inline when
>> possible.  However, some systems don't have ffsll.  I committed this
>> patch to add a version when the system does not have it.  I also tweaked
>> the other replacement functions, adding declarations so that they would
>> build without warnings.
>
>   Did you consider adding these to libiberty instead?  I don't know if they're
> all appropriate but some of them might well make handy additions, mightn't
> they?

I thought about it.  I added memmem to libiberty.  The version of mremap
in gold isn't general; it only does what gold needs.  ffsll is kind of
special purpose and I'm not convinced anything else will call it.


> +int
> +ffsll (long long arg)
> +{
> +  unsigned long long i;
> +  int ret;
> +
> +  ret = 0;
> +  for (i = (unsigned long long) arg; i != 0; i >>= 1)
> +    ++ret;
> +  return ret;
> +}
>
> ... does that really find the first set bit?  It looks to me like it counts
> all the one bits.  Possibly the terminating condition was meant to test "(i &
> 1) != 0"?

It doesn't matter too much, since gold will only call it with a power of
2.  But, yeah, I suppose it ought to work properly.  I committed the
appended patch.  Thanks.

Ian


2009-03-30  Ian Lance Taylor  <iant@google.com>

	* ffsll.c (ffsll): Correct implementation.


Index: ffsll.c
===================================================================
RCS file: /cvs/src/src/gold/ffsll.c,v
retrieving revision 1.1
diff -p -u -r1.1 ffsll.c
--- ffsll.c	28 Mar 2009 05:22:30 -0000	1.1
+++ ffsll.c	30 Mar 2009 23:16:39 -0000
@@ -36,8 +36,13 @@ ffsll (long long arg)
   unsigned long long i;
   int ret;
 
-  ret = 0;
-  for (i = (unsigned long long) arg; i != 0; i >>= 1)
-    ++ret;
+  if (arg == 0)
+    ret = 0;
+  else
+    {
+      ret = 1;
+      for (i = (unsigned long long) arg; (i & 1) == 0; i >>= 1)
+	++ret;
+    }
   return ret;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]