2020-03-31 04:49:36 -04:00
|
|
|
/*
|
2021-10-26 04:24:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015 Wind River Systems, Inc.
|
|
|
|
* SPDX-FileCopyrightText: 2017 Oticon A/S
|
2020-03-31 04:49:36 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BLE_MESH_FFS_H_
|
|
|
|
#define _BLE_MESH_FFS_H_
|
|
|
|
|
2023-08-25 02:28:44 -04:00
|
|
|
#include "mesh/types.h"
|
|
|
|
#include "mesh/compiler.h"
|
2020-03-31 04:49:36 -04: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
|
|
|
|
*/
|
|
|
|
|
2020-12-07 04:03:11 -05:00
|
|
|
static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
|
2020-03-31 04:49:36 -04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2020-12-07 04:03:11 -05:00
|
|
|
static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
|
2020-03-31 04:49:36 -04:00
|
|
|
{
|
|
|
|
return __builtin_ffs(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _BLE_MESH_FFS_H_ */
|