bitmap_cut(9)
π bitmap_cut(9) β the Kernel API Manual, but make it make sense β¨
okay bestie, so we're in the bitmap_cut(9) page of the Kernel API Manual and honestly? this one is lowkey iconic once you see it. it's a little helper that goes βοΈ snip snip on a chunk of bits and then scooches everything leftward to close the gap. no cap, it's giving scissors-emoji energy. π
β¨ NAME β¨
bitmap_cut β remove bit region from bitmap and right shift remaining bits π¦
like, literally: you pick a region, you cut it out, and the rest of the bits shift over to the right to fill the hole. periodt. π
πΈ SYNOPSIS πΈ
void bitmap_cut (unsigned long *dst , const unsigned long *src ,
unsigned int first , unsigned int cut , unsigned int nbits );
(yes the spaces before those commas are exactly like that, don't come for me, it's literally the API π)
π«Ά ARGUMENTS π«Ά
dstβ the destination bitmap, and heads up bestie it might overlap withsrcπ (more on that down below, it's fine, it's fine)srcβ the source bitmap, your original bits, the main character πfirstβ start bit of region to be removed β this is where the cutting begins βοΈcutβ number of bits to remove, i.e. how many bits we're yeeting πnbitsβ bitmap size, in bits β
π DESCRIPTION π
so here's the whole vibe, stated precisely so you can trust me: set the n-th bit of dst iff the n-th bit of src is set and n is less than first, or the m-th bit of src is set for any m such that first <= n < nbits, and m = n + cut.
read it twice, it'll click, i promise π§ and now the part that actually makes it click β pictures!! πΌοΈ
in pictures, example for a big-endian 32-bit architecture:
the src bitmap is:
31 63
| |
10000000 11000001 11110010 00010101 10000000 11000001 01110010 00010101
| | | |
16 14 0 32
if cut is 3, and first is 14, bits 14-16 in src are cut and dst is:
31 63
| |
10110000 00011000 00110010 00010101 00010000 00011000 00101110 01000010
| | |
14 (bit 17 0 32
from src)
see how bit 17 from src slid into spot 14? that's the shift-and-carry doing its lil dance π slay.
π important vibes: note thatdstandsrcmight overlap partially or entirely. not a typo, not a drill β it's literally fine, that's the design.
and how's it built? this is implemented in the obvious way, with a shift and carry step for each moved bit π₯ optimisation is left as an exercise for the compiler π (the compiler is the one doing homework around here, not us)
π SEE ALSO π
go off, bestie, here's the whole friend group π :
- Kernel file
./lib/bitmap.cbitmap introduction(9) __bitmap_shift_right(9)__bitmap_shift_left(9)bitmap_find_next_zero_area_off(9)bitmap_pos_to_ord(9)bitmap_remap(9)bitmap_bitremap(9)bitmap_onto(9)bitmap_fold(9)bitmap_from_arr32(9)bitmap_to_arr32(9)bitmap_from_arr64(9)bitmap_to_arr64(9)
and that's the whole page, bestie!! π₯³ this legendary lil slice lives in ./lib and was stamped October 2026 β so go forth, cut those bits, shift those bits, and remember: overlap is allowed and you're doing amazing π«Άπ β¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms