summaryrefslogtreecommitdiff
path: root/src/kservice.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2013-03-23 11:27:29 +0800
committerBernard Xiong <[email protected]>2013-03-23 11:27:29 +0800
commit1abaa0492d40a15e158537906ce2bf80cb77cdfd (patch)
treefd7004d2ac3c5952a1f8d5cde3cee67fe6afae93 /src/kservice.c
parent5a4d0d533875cf06b27510e17fb8ca708b9dd98b (diff)
implement __rt_ffs in kernel service library
Diffstat (limited to 'src/kservice.c')
-rw-r--r--src/kservice.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/kservice.c b/src/kservice.c
index 4276fc28ec..67262ff084 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -1190,6 +1190,54 @@ void rt_free_align(void *ptr)
RTM_EXPORT(rt_free_align);
#endif
+#ifndef RT_USING_CPU_FFS
+const rt_uint8_t __lowest_bit_bitmap[] =
+{
+ /* 00 */ 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 10 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 20 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 30 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 40 */ 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 50 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 60 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 70 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 80 */ 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* 90 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* A0 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* B0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* C0 */ 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* D0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* E0 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
+ /* F0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
+};
+
+/**
+ * This function finds the first bit set (beginning with the least significant bit)
+ * in value and return the index of that bit.
+ *
+ * Bits are numbered starting at 1 (the least significant bit). A return value of
+ * zero from any of these functions means that the argument was zero.
+ *
+ * @return return the index of the first bit set. If value is 0, then this function
+ * shall return 0.
+ */
+int __rt_ffs(int value)
+{
+ if (value == 0) return 0;
+
+ if (value & 0xff)
+ return __lowest_bit_bitmap[value & 0xff] + 1;
+
+ if (value & 0xff00)
+ return __lowest_bit_bitmap[(value & 0xff00) >> 8] + 9;
+
+ if (value & 0xff0000)
+ return __lowest_bit_bitmap[(value & 0xff0000) >> 16] + 17;
+
+ return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25;
+}
+#endif
+
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) && defined (__GNUC__)
#include <sys/types.h>
void *memcpy(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memcpy")));