[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] minios: implement ffs, ffsl and ffsll.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1243500119 -3600
# Node ID 878e4c12899187b88f9a7a2e07129f8e1ed44fb2
# Parent  8baf03526ab1b0d3b553e08c39800148b023de87
minios: implement ffs, ffsl and ffsll.

The first function is compiled only in case minios is compiled without
newlib, since newlib already provides an implementation for ffs.
On the other hand ffsl and ffsll are always compiled because newlib
misses those functions.
This patch also provides an implementation for __ffsti2 and __ffsdi2
because they are needed by gcc in order to successfully link ffsll.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 extras/mini-os/include/posix/strings.h |    4 ++
 extras/mini-os/lib/string.c            |   50 +++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff -r 8baf03526ab1 -r 878e4c128991 extras/mini-os/include/posix/strings.h
--- a/extras/mini-os/include/posix/strings.h    Wed May 27 21:51:04 2009 +0100
+++ b/extras/mini-os/include/posix/strings.h    Thu May 28 09:41:59 2009 +0100
@@ -5,4 +5,8 @@
 
 #define bzero(ptr, size) (memset((ptr), '\0', (size)), (void) 0)
 
+int ffs (int i);
+int ffsl (long int li);
+int ffsll (long long int lli);
+
 #endif /* _POSIX_STRINGS_H */
diff -r 8baf03526ab1 -r 878e4c128991 extras/mini-os/lib/string.c
--- a/extras/mini-os/lib/string.c       Wed May 27 21:51:04 2009 +0100
+++ b/extras/mini-os/lib/string.c       Thu May 28 09:41:59 2009 +0100
@@ -18,6 +18,43 @@
  ****************************************************************************
  */
 
+#include <strings.h>
+
+/* newlib defines ffs but not ffsll or ffsl */
+int __ffsti2 (long long int lli)
+{
+    int i, num, t, tmpint, len;
+
+    num = sizeof(long long int) / sizeof(int);
+    if (num == 1) return (ffs((int) lli));
+    len = sizeof(int) * 8;
+
+    for (i = 0; i < num; i++) {
+        tmpint = (int) (((lli >> len) << len) ^ lli);
+
+        t = ffs(tmpint);
+        if (t)
+            return (t + i * len);
+        lli = lli >> len;
+    }
+    return 0;
+}
+
+int __ffsdi2 (long int li)
+{
+    return __ffsti2 ((long long int) li);
+}
+
+int ffsl (long int li)
+{
+    return __ffsti2 ((long long int) li);
+}
+
+int ffsll (long long int lli)
+{
+    return __ffsti2 (lli);
+}
+
 #if !defined HAVE_LIBC
 
 #include <os.h>
@@ -175,4 +212,17 @@ char *strdup(const char *x)
     return res;
 }
 
+int ffs(int i)
+{
+   int c = 1;
+
+   do {
+      if (i & 1)
+         return (c);
+      i = i >> 1;
+      c++;
+   } while (i);
+   return 0;
+}
+
 #endif

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.