WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] minios: implement ffs, ffsl, ffsll

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] minios: implement ffs, ffsl, ffsll
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 27 May 2009 17:37:18 +0100
Delivery-date: Wed, 27 May 2009 09:35:17 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.14 (X11/20080505)
Hi all,
this patch implements 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>

---


diff -r f0e2df69a8eb extras/mini-os/include/posix/strings.h
--- a/extras/mini-os/include/posix/strings.h    Tue May 26 15:01:36 2009 +0100
+++ b/extras/mini-os/include/posix/strings.h    Wed May 27 17:31:43 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 f0e2df69a8eb extras/mini-os/lib/string.c
--- a/extras/mini-os/lib/string.c       Tue May 26 15:01:36 2009 +0100
+++ b/extras/mini-os/lib/string.c       Wed May 27 17:31:43 2009 +0100
@@ -17,6 +17,43 @@
  * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
  ****************************************************************************
  */
+
+#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
 
@@ -175,4 +212,17 @@
     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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] minios: implement ffs, ffsl, ffsll, Stefano Stabellini <=