@@ -1353,6 +1353,32 @@ RTM_EXPORT(rt_free_align);
13531353#endif /* RT_USING_HEAP */
13541354
13551355#ifndef RT_USING_CPU_FFS
1356+ #ifdef RT_KSERVICE_USING_TINY_FFS
1357+ const rt_uint8_t __lowest_bit_bitmap [] =
1358+ {
1359+ /* 0 - 7 */ 0 , 1 , 2 , 27 , 3 , 24 , 28 , 32 ,
1360+ /* 8 - 15 */ 4 , 17 , 25 , 31 , 29 , 12 , 32 , 14 ,
1361+ /* 16 - 23 */ 5 , 8 , 18 , 32 , 26 , 23 , 32 , 16 ,
1362+ /* 24 - 31 */ 30 , 11 , 13 , 7 , 32 , 22 , 15 , 10 ,
1363+ /* 32 - 36 */ 6 , 21 , 9 , 20 , 19
1364+ };
1365+
1366+ /**
1367+ * This function finds the first bit set (beginning with the least significant bit)
1368+ * in value and return the index of that bit.
1369+ *
1370+ * Bits are numbered starting at 1 (the least significant bit). A return value of
1371+ * zero from any of these functions means that the argument was zero.
1372+ *
1373+ * @return return the index of the first bit set. If value is 0, then this function
1374+ * shall return 0.
1375+ */
1376+ int __rt_ffs (int value )
1377+ {
1378+ rt_uint32_t result = (rt_uint32_t )value ;
1379+ return __lowest_bit_bitmap [ (result & (result - 1 ) ^ result ) % 37 ];
1380+ }
1381+ #else
13561382const rt_uint8_t __lowest_bit_bitmap [] =
13571383{
13581384 /* 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)
13981424
13991425 return __lowest_bit_bitmap [(value & 0xff000000 ) >> 24 ] + 25 ;
14001426}
1427+ #endif /* RT_KSERVICE_USING_TINY_FFS */
14011428#endif /* RT_USING_CPU_FFS */
14021429
14031430#ifdef RT_DEBUG
0 commit comments