summaryrefslogtreecommitdiff
path: root/include/asm-m68k/bitops.h
diff options
context:
space:
mode:
authorJohn Rigby <jrigby@freescale.com>2007-08-16 17:40:03 -0600
committerJohn Rigby <jrigby@freescale.com>2007-08-16 17:40:03 -0600
commit81735b2568cf634d601c0d4a1bbc3a3882bc8eda (patch)
tree521d22623e48f6923b4cda08a36cc26a9cc9abde /include/asm-m68k/bitops.h
parentd35b508a55508535b6e8445b718585d27df733d3 (diff)
parentd61ea14885631e58a25feaa81ee82eb464c62d6a (diff)
downloadu-boot-imx-81735b2568cf634d601c0d4a1bbc3a3882bc8eda.zip
u-boot-imx-81735b2568cf634d601c0d4a1bbc3a3882bc8eda.tar.gz
u-boot-imx-81735b2568cf634d601c0d4a1bbc3a3882bc8eda.tar.bz2
Merge branch 'denx-coldfire' into coldfire-aug2007
Diffstat (limited to 'include/asm-m68k/bitops.h')
-rw-r--r--include/asm-m68k/bitops.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/asm-m68k/bitops.h b/include/asm-m68k/bitops.h
index 3283714..0f9e8ab 100644
--- a/include/asm-m68k/bitops.h
+++ b/include/asm-m68k/bitops.h
@@ -15,4 +15,43 @@ extern int test_and_set_bit(int nr, volatile void *addr);
extern int test_and_clear_bit(int nr, volatile void *addr);
extern int test_and_change_bit(int nr, volatile void *addr);
+#ifdef __KERNEL__
+
+/*
+ * ffs: find first bit set. This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+extern __inline__ int ffs(int x)
+{
+ int r = 1;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xffff)) {
+ x >>= 16;
+ r += 16;
+ }
+ if (!(x & 0xff)) {
+ x >>= 8;
+ r += 8;
+ }
+ if (!(x & 0xf)) {
+ x >>= 4;
+ r += 4;
+ }
+ if (!(x & 3)) {
+ x >>= 2;
+ r += 2;
+ }
+ if (!(x & 1)) {
+ x >>= 1;
+ r += 1;
+ }
+ return r;
+}
+#define __ffs(x) (ffs(x) - 1)
+
+#endif /* __KERNEL__ */
+
#endif /* _M68K_BITOPS_H */