libc/string: replace __builtin_ffsl with inline function

In the gcc-riscv compiler, __builtin_ffs will call ffs, and calling __builtin_ffs in ffs will cause recursion

Change ffs to an inline function, and compile ffs implemented by nuttx by default.
Only call the implementation of nuttx when the compiler cannot provide an ffs implementation.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai
2024-04-29 11:59:17 +08:00
committed by Xiang Xiao
parent 3b5b755d1e
commit b87804c2ba
7 changed files with 66 additions and 91 deletions
-15
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -55,13 +48,6 @@ int ffs(int j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_FFS
ret = __builtin_ffs(j);
#elif defined (CONFIG_HAVE_BUILTIN_CTZ)
/* Count trailing zeros function can be used to implement ffs. */
ret = __builtin_ctz(j) + 1;
#else
unsigned int value = (unsigned int)j;
int bitno;
@@ -73,7 +59,6 @@ int ffs(int j)
break;
}
}
#endif
}
return ret;
-15
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -55,13 +48,6 @@ int ffsl(long j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_FFSL
ret = __builtin_ffsl(j);
#elif defined (CONFIG_HAVE_BUILTIN_CTZ)
/* Count trailing zeros function can be used to implement ffs. */
ret = __builtin_ctzl(j) + 1;
#else
unsigned long value = (unsigned long)j;
int bitno;
@@ -73,7 +59,6 @@ int ffsl(long j)
break;
}
}
#endif
}
return ret;
-16
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -57,13 +50,6 @@ int ffsll(long long j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_FFSLL
ret = __builtin_ffsll(j);
#elif defined (CONFIG_HAVE_BUILTIN_CTZ)
/* Count trailing zeros function can be used to implement ffs. */
ret = __builtin_ctzll(j) + 1;
#else
unsigned long long value = (unsigned long long)j;
int bitno;
@@ -75,10 +61,8 @@ int ffsll(long long j)
break;
}
}
#endif
}
return ret;
}
#endif
-13
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -55,11 +48,6 @@ int fls(int j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_CLZ
/* Count leading zeros function can be used to implement fls. */
ret = NBITS - __builtin_clz(j);
#else
unsigned int value = (unsigned int)j;
int bitno;
@@ -71,7 +59,6 @@ int fls(int j)
break;
}
}
#endif
}
return ret;
-13
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -55,11 +48,6 @@ int flsl(long j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_CLZ
/* Count leading zeros function can be used to implement fls. */
ret = NBITS - __builtin_clzl(j);
#else
unsigned long value = (unsigned long)j;
int bitno;
@@ -71,7 +59,6 @@ int flsl(long j)
break;
}
}
#endif
}
return ret;
-14
View File
@@ -18,13 +18,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <strings.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -57,11 +50,6 @@ int flsll(long long j)
if (j != 0)
{
#ifdef CONFIG_HAVE_BUILTIN_CLZ
/* Count leading zeros function can be used to implement fls. */
ret = NBITS - __builtin_clzll(j);
#else
unsigned long long value = (unsigned long long)j;
int bitno;
@@ -73,10 +61,8 @@ int flsll(long long j)
break;
}
}
#endif
}
return ret;
}
#endif