From 9d8afc8ede235f95faa5c710181cc4fedf444554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=BE=84?= <36236188+Eureka1024@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E7=A7=8D=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E6=89=BE=E5=AD=97=E8=8A=82=E6=9C=80=E4=BD=8E?= =?UTF-8?q?=E9=9D=9E0=E4=BD=8D=E7=9A=84=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/kservice.c b/src/kservice.c index 25d34dfc47..7c62901e36 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1353,6 +1353,32 @@ RTM_EXPORT(rt_free_align); #endif /* RT_USING_HEAP */ #ifndef RT_USING_CPU_FFS +#ifdef RT_KSERVICE_USING_TINY_FFS +const rt_uint8_t __lowest_bit_bitmap[] = +{ + /* 0 - 7 */ 0, 1, 2, 27, 3, 24, 28, 32, + /* 8 - 15 */ 4, 17, 25, 31, 29, 12, 32, 14, + /* 16 - 23 */ 5, 8, 18, 32, 26, 23, 32, 16, + /* 24 - 31 */ 30, 11, 13, 7, 32, 22, 15, 10, + /* 32 - 36 */ 6, 21, 9, 20, 19 +}; + +/** + * 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) +{ + rt_uint32_t result = (rt_uint32_t)value; + return __lowest_bit_bitmap[ (result & (result - 1) ^ result) % 37]; +} +#else const rt_uint8_t __lowest_bit_bitmap[] = { /* 00 */ 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, @@ -1398,6 +1424,7 @@ int __rt_ffs(int value) return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25; } +#endif /* RT_KSERVICE_USING_TINY_FFS */ #endif /* RT_USING_CPU_FFS */ #ifdef RT_DEBUG -- GitLab