xtensa: fix find_msb_set() and find_lsb_set()
find_msb_set logic was wrong. find_lsb_set() is now an inline function. Change-Id: I2c19540907723589298b2f6af2ce1d68704bf1d7 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
aa3ab35c88
commit
73691609b9
1 changed files with 35 additions and 2 deletions
|
@ -38,8 +38,41 @@ extern "C" {
|
|||
|
||||
#include <arch/xtensa/exc.h>
|
||||
|
||||
#define find_lsb_set __builtin_ffs
|
||||
#define find_msb_set __builtin_clz
|
||||
/**
|
||||
*
|
||||
* @brief find most significant bit set in a 32-bit word
|
||||
*
|
||||
* This routine finds the first bit set starting from the most significant bit
|
||||
* in the argument passed in and returns the index of that bit. Bits are
|
||||
* numbered starting at 1 from the least significant bit. A return value of
|
||||
* zero indicates that the value passed is zero.
|
||||
*
|
||||
* @return most significant bit set, 0 if @a op is 0
|
||||
*/
|
||||
|
||||
static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
|
||||
{
|
||||
if (!op)
|
||||
return 0;
|
||||
return 32 - __builtin_clz(op);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief find least significant bit set in a 32-bit word
|
||||
*
|
||||
* This routine finds the first bit set starting from the least significant bit
|
||||
* in the argument passed in and returns the index of that bit. Bits are
|
||||
* numbered starting at 1 from the least significant bit. A return value of
|
||||
* zero indicates that the value passed is zero.
|
||||
*
|
||||
* @return least significant bit set, 0 if @a op is 0
|
||||
*/
|
||||
|
||||
static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
|
||||
{
|
||||
return __builtin_ffs(op);
|
||||
}
|
||||
|
||||
/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
|
||||
extern void _irq_priority_set(uint32_t irq, uint32_t prio, uint32_t flags);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue