mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:43:28 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user