PatchworkOS
da8a090
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
bitmap_find_first_set.c
Go to the documentation of this file.
1
#include <
sys/bitmap.h
>
2
3
uint64_t
bitmap_find_first_set
(
bitmap_t
*
map
,
uint64_t
startIdx,
uint64_t
endIdx)
4
{
5
if
(startIdx >=
map
->
length
)
6
{
7
return
map
->
length
;
8
}
9
10
uint64_t
startQwordIdx = startIdx / 64;
11
uint64_t
startBitIdx = startIdx % 64;
12
uint64_t
endQwordIdx =
BITMAP_BITS_TO_QWORDS
(
MIN
(endIdx,
map
->
length
));
13
14
while
(startQwordIdx < endQwordIdx)
15
{
16
uint64_t
qword =
map
->buffer[startQwordIdx];
17
if
(startBitIdx != 0)
18
{
19
qword &= ~((1ULL << startBitIdx) - 1);
20
}
21
22
if
(qword != 0)
23
{
24
return
startQwordIdx * 64 + __builtin_ctzll(qword);
25
}
26
27
startQwordIdx++;
28
startBitIdx = 0;
29
}
30
31
return
map
->
length
;
32
}
bitmap.h
bitmap_find_first_set
uint64_t bitmap_find_first_set(bitmap_t *map, uint64_t startIdx, uint64_t endIdx)
Find the first set bit in the bitmap.
Definition
bitmap_find_first_set.c:3
BITMAP_BITS_TO_QWORDS
#define BITMAP_BITS_TO_QWORDS(bits)
Convert number of bits to number of qwords.
Definition
bitmap.h:34
MIN
#define MIN(x, y)
Definition
math.h:16
map
boot_memory_map_t * map
Definition
mem.c:19
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
bitmap_t
Bitmap structure.
Definition
bitmap.h:22
boot_memory_map_t::length
uint64_t length
Definition
boot_info.h:58
src
libstd
functions
bitmap
bitmap_find_first_set.c
Generated on Fri Dec 12 2025 00:22:10 for PatchworkOS by
1.9.8