2019-06-03 01:07:43 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Wind River Systems, Inc.
|
|
|
|
* Copyright (c) 2017, Oticon A/S
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_
|
|
|
|
|
2019-08-13 01:54:01 +08:00
|
|
|
#ifndef _ASMLANGUAGE
|
|
|
|
|
|
|
|
#include <zephyr/types.h>
|
|
|
|
|
2019-06-03 01:07:43 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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(u32_t op)
|
|
|
|
{
|
|
|
|
if (op == 0) {
|
|
|
|
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(u32_t op)
|
|
|
|
{
|
|
|
|
return __builtin_ffs(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-13 01:54:01 +08:00
|
|
|
#endif /* _ASMLANGUAGE */
|
2019-06-03 01:07:43 +08:00
|
|
|
|
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_ */
|