1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NSI_COMMON_SRC_NSI_INTERNAL_H
8 #define NSI_COMMON_SRC_NSI_INTERNAL_H
9 
10 #include <stdint.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  *
18  * @brief find least significant bit set in a 32-bit word
19  *
20  * This routine finds the first bit set starting from the least significant bit
21  * in the argument passed in and returns the index of that bit. Bits are
22  * numbered starting at 1 from the least significant bit.  A return value of
23  * zero indicates that the value passed is zero.
24  *
25  * @return least significant bit set, 0 if @a op is 0
26  */
27 
nsi_find_lsb_set(uint32_t op)28 static inline unsigned int nsi_find_lsb_set(uint32_t op)
29 {
30 	return __builtin_ffs(op);
31 }
32 
33 #ifdef __cplusplus
34 }
35 #endif
36 
37 #endif /* NSI_COMMON_SRC_NSI_INTERNAL_H */
38