1 /******************************************************************************
2  *
3  * Copyright (C) 2023 Analog Devices, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_UTILS_H_
20 #define LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_UTILS_H_
21 
22 /***** Includes *****/
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*
29  * Find least significant bit set in a 32-bit word
30  * Returns
31  *    least significant bit set, 0 if val is 0
32  */
wrap_utils_find_lsb_set(uint32_t val)33 static inline int wrap_utils_find_lsb_set(uint32_t val)
34 {
35     int lsb = 0;
36 
37     for (int i = 0; i < 32; i++) {
38         if (val & (1 << i)) {
39             lsb = (i + 1);
40             break;
41         }
42     }
43 
44     return lsb;
45 }
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif // LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_UTILS_H_
52