diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-01 13:31:20 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-01 13:31:20 +0200 |
| commit | 790ffa870dee2c14cd45f669c0eb3e95c15fd1b6 (patch) | |
| tree | 87aef491cb4d43dc75b8acc5979d025d8bd1a170 /kernel/src/memory/bitmap_allocator.cpp | |
| parent | 6c1921d77a6d23bd5850db5b8db20e0f1bc67f40 (diff) | |
| download | teachos-790ffa870dee2c14cd45f669c0eb3e95c15fd1b6.tar.xz teachos-790ffa870dee2c14cd45f669c0eb3e95c15fd1b6.zip | |
kernel: add bitmap_allocator tests
Diffstat (limited to 'kernel/src/memory/bitmap_allocator.cpp')
| -rw-r--r-- | kernel/src/memory/bitmap_allocator.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/kernel/src/memory/bitmap_allocator.cpp b/kernel/src/memory/bitmap_allocator.cpp index c010f77..caaf5a4 100644 --- a/kernel/src/memory/bitmap_allocator.cpp +++ b/kernel/src/memory/bitmap_allocator.cpp @@ -6,6 +6,7 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <ranges> #include <span> #include <utility> @@ -17,7 +18,9 @@ namespace kernel::memory , m_frame_count{frame_count} , m_last_index{} { - std::ranges::fill(m_bitmap, ~0uz); + constexpr auto bits_per_word = 64uz; + auto to_fill = (frame_count + bits_per_word - 1) / bits_per_word; + std::ranges::fill(std::views::take(m_bitmap, to_fill), ~0uz); } auto bitmap_frame_allocator::allocate_many(std::size_t count) noexcept @@ -78,22 +81,25 @@ namespace kernel::memory auto bitmap_frame_allocator::test(std::size_t index) const noexcept -> bool { - auto entry_entry = index / 64; - auto entry_offset = index % 64; + constexpr auto bits_per_word = 64uz; + auto entry_entry = index / bits_per_word; + auto entry_offset = index % bits_per_word; return (m_bitmap[entry_entry] & (1uz << entry_offset)); } auto bitmap_frame_allocator::set(std::size_t index) noexcept -> void { - auto entry_entry = index / 64; - auto entry_offset = index % 64; + constexpr auto bits_per_word = 64uz; + auto entry_entry = index / bits_per_word; + auto entry_offset = index % bits_per_word; m_bitmap[entry_entry] |= (1uz << entry_offset); } auto bitmap_frame_allocator::clear(std::size_t index) noexcept -> void { - auto entry_entry = index / 64; - auto entry_offset = index % 64; + constexpr auto bits_per_word = 64uz; + auto entry_entry = index / bits_per_word; + auto entry_offset = index % bits_per_word; m_bitmap[entry_entry] &= ~(1uz << entry_offset); } |
