aboutsummaryrefslogtreecommitdiff
path: root/libiberty/ffs.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2001-07-05 17:29:17 +0000
committerDJ Delorie <dj@redhat.com>2001-07-05 17:29:17 +0000
commit7b78baae9b0beeee74aa508c150c35b4f9f35982 (patch)
treea3cac4407bb945ea2425479741572dd5b05545a9 /libiberty/ffs.c
parentaf703f96203b5320baec426e5864cff71735a071 (diff)
downloadgdb-7b78baae9b0beeee74aa508c150c35b4f9f35982.zip
gdb-7b78baae9b0beeee74aa508c150c35b4f9f35982.tar.gz
gdb-7b78baae9b0beeee74aa508c150c35b4f9f35982.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty/ffs.c')
-rw-r--r--libiberty/ffs.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libiberty/ffs.c b/libiberty/ffs.c
new file mode 100644
index 0000000..8ffb03e
--- /dev/null
+++ b/libiberty/ffs.c
@@ -0,0 +1,29 @@
+/* ffs -- Find the first bit set in the parameter
+
+NAME
+ ffs -- Find the first bit set in the parameter
+
+SYNOPSIS
+ int ffs (int valu)
+
+DESCRIPTION
+ Find the first bit set in the parameter. Bits are numbered from
+ right to left, starting with bit 1.
+
+*/
+
+int
+ffs (valu)
+ register int valu;
+{
+ register int bit;
+
+ if (valu == 0)
+ return 0;
+
+ for (bit = 1; !(valu & 1); bit++)
+ valu >>= 1;
+
+ return bit;
+}
+