summaryrefslogtreecommitdiff
path: root/lib/libc/strings/ffsll.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/strings/ffsll.c')
-rw-r--r--lib/libc/strings/ffsll.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/libc/strings/ffsll.c b/lib/libc/strings/ffsll.c
new file mode 100644
index 00000000..acfacb87
--- /dev/null
+++ b/lib/libc/strings/ffsll.c
@@ -0,0 +1,14 @@
+int ffsll(long long i)
+{
+ if (i == 0)
+ return 0;
+
+ int pos = 1;
+ unsigned long long u = (unsigned long long)i;
+
+ while ((u & 1ULL) == 0ULL) {
+ u >>= 1;
+ pos++;
+ }
+ return pos;
+}