ia64/xen-unstable
changeset 19664:878e4c128991
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@eu.citrix.com>
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@eu.citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Thu May 28 09:41:59 2009 +0100 (2009-05-28) |
parents | 8baf03526ab1 |
children | bf37a89269bf |
files | extras/mini-os/include/posix/strings.h extras/mini-os/lib/string.c |
line diff
1.1 --- a/extras/mini-os/include/posix/strings.h Wed May 27 21:51:04 2009 +0100 1.2 +++ b/extras/mini-os/include/posix/strings.h Thu May 28 09:41:59 2009 +0100 1.3 @@ -5,4 +5,8 @@ 1.4 1.5 #define bzero(ptr, size) (memset((ptr), '\0', (size)), (void) 0) 1.6 1.7 +int ffs (int i); 1.8 +int ffsl (long int li); 1.9 +int ffsll (long long int lli); 1.10 + 1.11 #endif /* _POSIX_STRINGS_H */
2.1 --- a/extras/mini-os/lib/string.c Wed May 27 21:51:04 2009 +0100 2.2 +++ b/extras/mini-os/lib/string.c Thu May 28 09:41:59 2009 +0100 2.3 @@ -18,6 +18,43 @@ 2.4 **************************************************************************** 2.5 */ 2.6 2.7 +#include <strings.h> 2.8 + 2.9 +/* newlib defines ffs but not ffsll or ffsl */ 2.10 +int __ffsti2 (long long int lli) 2.11 +{ 2.12 + int i, num, t, tmpint, len; 2.13 + 2.14 + num = sizeof(long long int) / sizeof(int); 2.15 + if (num == 1) return (ffs((int) lli)); 2.16 + len = sizeof(int) * 8; 2.17 + 2.18 + for (i = 0; i < num; i++) { 2.19 + tmpint = (int) (((lli >> len) << len) ^ lli); 2.20 + 2.21 + t = ffs(tmpint); 2.22 + if (t) 2.23 + return (t + i * len); 2.24 + lli = lli >> len; 2.25 + } 2.26 + return 0; 2.27 +} 2.28 + 2.29 +int __ffsdi2 (long int li) 2.30 +{ 2.31 + return __ffsti2 ((long long int) li); 2.32 +} 2.33 + 2.34 +int ffsl (long int li) 2.35 +{ 2.36 + return __ffsti2 ((long long int) li); 2.37 +} 2.38 + 2.39 +int ffsll (long long int lli) 2.40 +{ 2.41 + return __ffsti2 (lli); 2.42 +} 2.43 + 2.44 #if !defined HAVE_LIBC 2.45 2.46 #include <os.h> 2.47 @@ -175,4 +212,17 @@ char *strdup(const char *x) 2.48 return res; 2.49 } 2.50 2.51 +int ffs(int i) 2.52 +{ 2.53 + int c = 1; 2.54 + 2.55 + do { 2.56 + if (i & 1) 2.57 + return (c); 2.58 + i = i >> 1; 2.59 + c++; 2.60 + } while (i); 2.61 + return 0; 2.62 +} 2.63 + 2.64 #endif