merge from gcc
[deliverable/binutils-gdb.git] / libiberty / ffs.c
diff --git a/libiberty/ffs.c b/libiberty/ffs.c
new file mode 100644 (file)
index 0000000..8ffb03e
--- /dev/null
@@ -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;
+}
+
This page took 0.023314 seconds and 4 git commands to generate.