arch: implement brute force find_lsb_set()
On RISC-V 64-bit, GCC complains about undefined reference to 'ffs' via __builtin_ffs(). So implement a brute force way to do it. Once the toolchain has __builtin_ffs(), this can be reverted. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
3b2fd1ca0d
commit
783b20712e
2 changed files with 31 additions and 0 deletions
|
@ -955,3 +955,9 @@ config BOARD
|
|||
The Board is the first location where we search for a linker.ld file,
|
||||
if not found we look for the linker file in
|
||||
soc/<arch>/<family>/<series>
|
||||
|
||||
config TOOLCHAIN_HAS_BUILTIN_FFS
|
||||
bool
|
||||
default y if !(64BIT && RISCV)
|
||||
help
|
||||
Hidden option to signal that toolchain has __builtin_ffs*().
|
||||
|
|
|
@ -52,7 +52,32 @@ static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
|
|||
|
||||
static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
|
||||
{
|
||||
#ifdef CONFIG_TOOLCHAIN_HAS_BUILTIN_FFS
|
||||
return __builtin_ffs(op);
|
||||
|
||||
#else
|
||||
/*
|
||||
* Toolchain does not have __builtin_ffs().
|
||||
* Need to do this manually.
|
||||
*/
|
||||
int bit;
|
||||
|
||||
if (op == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (bit = 0; bit < 32; bit++) {
|
||||
if ((op & (1 << bit)) != 0) {
|
||||
return (bit + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This should never happen but we need to keep
|
||||
* compiler happy.
|
||||
*/
|
||||
return 0;
|
||||
#endif /* CONFIG_TOOLCHAIN_HAS_BUILTIN_FFS */
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue