PatchworkOS
321f6ec
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
bitmap_find_first_clear.c
Go to the documentation of this file.
1
#include <
sys/bitmap.h
>
2
3
uint64_t
bitmap_find_first_clear
(
bitmap_t
*
map
,
uint64_t
startIdx,
uint64_t
endIdx)
4
{
5
if
(
map
->firstZeroIdx >=
map
->
length
)
6
{
7
return
map
->
length
;
8
}
9
10
startIdx =
MAX
(startIdx,
map
->firstZeroIdx);
11
uint64_t
qwordIdx = startIdx / 64;
12
uint64_t
bitIdx = startIdx % 64;
13
uint64_t
endQwordIdx =
BITMAP_BITS_TO_QWORDS
(
MIN
(endIdx,
map
->
length
));
14
15
if
(bitIdx != 0)
16
{
17
uint64_t
qword =
map
->buffer[qwordIdx];
18
uint64_t
maskedQword = qword | ((1ULL << bitIdx) - 1);
19
if
(maskedQword != ~0ULL)
20
{
21
return
qwordIdx * 64 + __builtin_ctzll(~maskedQword);
22
}
23
qwordIdx++;
24
}
25
26
for
(
uint64_t
i = qwordIdx; i < endQwordIdx; ++i)
27
{
28
if
(
map
->buffer[i] != ~0ULL)
29
{
30
return
i * 64 + __builtin_ctzll(~
map
->buffer[i]);
31
}
32
}
33
34
return
map
->
length
;
35
}
bitmap.h
bitmap_find_first_clear
uint64_t bitmap_find_first_clear(bitmap_t *map, uint64_t startIdx, uint64_t endIdx)
Find the first clear bit in the bitmap.
Definition
bitmap_find_first_clear.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
MAX
#define MAX(x, y)
Definition
math.h:15
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_clear.c
Generated on Mon Dec 15 2025 15:56:54 for PatchworkOS by
1.9.8