@@ -1360,6 +1360,31 @@ RTM_EXPORT(rt_free_align);
13601360#endif /* RT_USING_HEAP */
13611361
13621362#ifndef RT_USING_CPU_FFS
1363+ #ifdef RT_USING_TINY_FFS
1364+ const rt_uint8_t __lowest_bit_bitmap [] =
1365+ {
1366+ /* 0 - 7 */ 0 , 1 , 2 , 27 , 3 , 24 , 28 , 32 ,
1367+ /* 8 - 15 */ 4 , 17 , 25 , 31 , 29 , 12 , 32 , 14 ,
1368+ /* 16 - 23 */ 5 , 8 , 18 , 32 , 26 , 23 , 32 , 16 ,
1369+ /* 24 - 31 */ 30 , 11 , 13 , 7 , 32 , 22 , 15 , 10 ,
1370+ /* 32 - 36 */ 6 , 21 , 9 , 20 , 19
1371+ };
1372+
1373+ /**
1374+ * This function finds the first bit set (beginning with the least significant bit)
1375+ * in value and return the index of that bit.
1376+ *
1377+ * Bits are numbered starting at 1 (the least significant bit). A return value of
1378+ * zero from any of these functions means that the argument was zero.
1379+ *
1380+ * @return return the index of the first bit set. If value is 0, then this function
1381+ * shall return 0.
1382+ */
1383+ int __rt_ffs (int value )
1384+ {
1385+ return __lowest_bit_bitmap [(rt_uint32_t )(value & (value - 1 ) ^ value ) % 37 ];
1386+ }
1387+ #else
13631388const rt_uint8_t __lowest_bit_bitmap [] =
13641389{
13651390 /* 00 */ 0 , 0 , 1 , 0 , 2 , 0 , 1 , 0 , 3 , 0 , 1 , 0 , 2 , 0 , 1 , 0 ,
@@ -1405,6 +1430,7 @@ int __rt_ffs(int value)
14051430
14061431 return __lowest_bit_bitmap [(value & 0xff000000 ) >> 24 ] + 25 ;
14071432}
1433+ #endif /* RT_USING_TINY_FFS */
14081434#endif /* RT_USING_CPU_FFS */
14091435
14101436#ifdef RT_DEBUG
0 commit comments