Skip to content

Commit 4bcb670

Browse files
committed
util: Add missing no_os_find_last_set_bit_u64 function
Add the missing 64-bit version of no_os_find_last_set_bit to provide complete coverage for bit manipulation operations. Signed-off-by: Antoniu Miclaus <[email protected]>
1 parent 99ba6e4 commit 4bcb670

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/no_os_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ uint32_t no_os_find_first_set_bit(uint32_t word);
137137
uint64_t no_os_find_first_set_bit_u64(uint64_t word);
138138
/* Find last set bit in word. */
139139
uint32_t no_os_find_last_set_bit(uint32_t word);
140+
uint64_t no_os_find_last_set_bit_u64(uint64_t word);
140141
/* Locate the closest element in an array. */
141142
uint32_t no_os_find_closest(int32_t val,
142143
const int32_t *array,

util/no_os_util.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ uint32_t no_os_find_last_set_bit(uint32_t word)
8989
return last_set_bit;
9090
}
9191

92+
/**
93+
* Find last set bit in word.
94+
*/
95+
uint64_t no_os_find_last_set_bit_u64(uint64_t word)
96+
{
97+
uint64_t bit = 0;
98+
uint64_t last_set_bit = 64;
99+
100+
while (word) {
101+
if (word & 0x1)
102+
last_set_bit = bit;
103+
word >>= 1;
104+
bit ++;
105+
}
106+
107+
return last_set_bit;
108+
}
109+
92110
/**
93111
* Locate the closest element in an array.
94112
*/

0 commit comments

Comments
 (0)