diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-05-28 09:41:59 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-05-28 09:41:59 +0100 |
commit | 7f1f6b865b0d72977ee517873cedcba71744b099 (patch) | |
tree | 64759c37e31368f30322e63ef802f64430d3f610 /extras/mini-os/lib | |
parent | 18062591742c7c4f711678d8c2db4f1518965b6a (diff) | |
download | xen-7f1f6b865b0d72977ee517873cedcba71744b099.tar.gz xen-7f1f6b865b0d72977ee517873cedcba71744b099.tar.bz2 xen-7f1f6b865b0d72977ee517873cedcba71744b099.zip |
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>
Diffstat (limited to 'extras/mini-os/lib')
-rw-r--r-- | extras/mini-os/lib/string.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/extras/mini-os/lib/string.c b/extras/mini-os/lib/string.c index f6dfa609d0..a6f2abe0b0 100644 --- a/extras/mini-os/lib/string.c +++ b/extras/mini-os/lib/string.c @@ -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 |