Commit Graph

17 Commits

Author SHA1 Message Date
Martin Janiczek
efa5fb5c3a AK: Fix one-off error in BitmapView::find_first and find_one_anywhere
The mentioned functions used m_size / 8 instead of size_in_bytes()
(division with ceiling rounding mode), which resulted in an off-by-one
error such that the functions didn't search in the last not-fully-8-bits
byte.

Using size_in_bytes() instead of m_size / 8 fixes this.
2023-10-11 15:58:16 +02:00
Sam Atkins
067d0689c5 AK: Replace C-style casts 2023-03-09 21:43:54 +01:00
Andreas Kling
ae3ffdd521 AK: Make it possible to not using AK classes into the global namespace
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by
default, but can be overridden by build flags.

This is a step towards integrating Jakt and AK types.
2022-11-26 15:51:34 +01:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Nick Johnson
08e4a1a4dc AK+Everywhere: Replace __builtin bit functions
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount},
this commit removes all calls to these functions and replaces them with
the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21 22:13:51 +01:00
Nick Johnson
e122502f70 AK: Speed up BitmapView::find_next_range_of_unset_bits
While watching Andreas' most recent video, I noticed that this function
only worked with 32 bit values, but was a serious performance
bottleneck for the kernel. As such, I reworked it to use `size_t`, so
it now can switch to 64-bit sweeps on 64-bit platforms. This caused
test-js to go from 12.5 seconds hot to 11.5 seconds hot on my machine
when running on KVM x86_64.
2021-12-18 23:36:08 +01:00
Andrew Kaster
22feb9d47b AK: Resolve clang-tidy readability-bool-conversion warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Ben Wiederhake
b7e6118098 AK: Properly declare inheritance of Bitmap from BitmapView
All the read-only methods of Bitmap simply defer to BitmapView. Let's
make this relationship official by using class inheritance. This might
even shave off a few instructions, although any sufficiently optimizing
compiler probably already optimized them away.
2021-11-10 14:39:42 +01:00
Ben Wiederhake
bf7a2ff941 AK+Kernel: Make BitmapView read-only 2021-11-10 14:39:42 +01:00
Lenny Maiorani
d25d4ec0ee Bitmap: De-duplicate bitmasks
Problem:
- Bitmasks are duplicated.
- Bitmasks are C-style arrays.

Solution:
- Move bitmasks to BitmapView.h.
- Change C-style arrays to be AK::Array for added safety.
2021-05-19 23:37:10 +01:00
Lenny Maiorani
ebb1d9740e BitmapView: Disable mutations of the underlying Bitmap
Problem:
- `BitmapView` permits changing the underlying `Bitmap`. This violates
  the idea of a "view" since views are simply overlays which can
  themselves change but do not change the underlying data.

Solution:
- Migrate all non-`const` member functions to Bitmap.
2021-05-18 08:10:45 +02:00
Andreas Kling
bebbeda726 Revert "BitmapView: Disable mutations of the underlying Bitmap"
This reverts commit f25209113f.
2021-05-17 18:29:47 +02:00
Lenny Maiorani
f25209113f BitmapView: Disable mutations of the underlying Bitmap
Problem:
- `BitmapView` permits changing the underlying `Bitmap`. This violates
  the idea of a "view" since views are simply overlays which can
  themselves change but do not change the underlying data.

Solution:
- Migrate all non-`const` member functions to Bitmap.
2021-05-17 18:16:35 +02:00
Andrew Kaster
73adbb319c AK: Don't read past the end in BitmapView::count_in_range()
The current code is factored such that reads to the entirety of the last
byte should be dropped. This was relying on the fact that last would be
one past the end in that case. Instead of actually reading that byte
when it's completely out of bounds of the bitmask, just skip reads that
would be invalid. Add more tests to make sure that the behavior is
correct for byte aligned reads of byte aligned bitmaps.
2021-05-16 21:58:14 +01:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
c268df79e6 AK: Add BitmapView::set_range_and_verify_that_all_bits_flip()
This function sets a range of bits to the same value while also
verifying that all bits in the range get flipped in the process.
2021-04-09 17:08:49 +02:00
Andreas Kling
40552bb5fb AK: Add BitmapView class (like StringView but for bitmaps)
AK::Bitmap is an awkwardly modal class which can either own or wrap
the underlying data. To get ourselves out of this unpleasant situation,
this patch adds BitmapView to replace the wrapped mode.

A BitmapView is simply a { data pointer, bit count } tuple internally
and provides all the convenient functionality of a bitmap class.
2021-03-04 11:25:45 +01:00