diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2017-12-15 09:38:53 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2017-12-15 09:39:34 -0500 |
commit | f95a4a932476be2ba99e2fd081e8d2bc6ea12813 (patch) | |
tree | 75f67192cb2d7b7b575c94edda318e475239b63c /newlib/libc/misc/ffs.c | |
parent | f60aca96985e68c7d8a52eb7bc955fb80e132f73 (diff) |
Import newlib and create makefile
Diffstat (limited to 'newlib/libc/misc/ffs.c')
-rw-r--r-- | newlib/libc/misc/ffs.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/newlib/libc/misc/ffs.c b/newlib/libc/misc/ffs.c new file mode 100644 index 0000000..e4afe7a --- /dev/null +++ b/newlib/libc/misc/ffs.c @@ -0,0 +1,42 @@ +/* +FUNCTION + <<ffs>>---find first bit set in a word + +INDEX + ffs + +ANSI_SYNOPSIS + int ffs(int <[word]>); + +TRAD_SYNOPSIS + int ffs(<[word]>); + +DESCRIPTION + +<<ffs>> returns the first bit set in a word. + +RETURNS +<<ffs>> returns 0 if <[c]> is 0, 1 if <[c]> is odd, 2 if <[c]> is a multiple of +2, etc. + +PORTABILITY +<<ffs>> is not ANSI C. + +No supporting OS subroutines are required. */ + +int +ffs (word) + int word; +{ + int i; + + if (!word) + return 0; + + i = 0; + for (;;) + { + if (((1 << i++) & word) != 0) + return i; + } +} |