Lines Matching +full:int +full:- +full:map +full:- +full:mask
1 /* SPDX-License-Identifier: GPL-2.0 */
15 #include <linux/bitmap-str.h>
26 * specific are in various include/asm-<arch>/bitops.h headers
39 * compile-time and at most BITS_PER_LONG.
61 * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
62 * bitmap_find_next_zero_area_off(buf, len, pos, n, mask, mask_off) as above
66 * bitmap_replace(dst, old, new, mask, nbits) *dst = (*old & ~(*mask)) | (*new & *mask)
67 * bitmap_scatter(dst, src, mask, nbits) *dst = map(dense, sparse)(src)
68 * bitmap_gather(dst, src, mask, nbits) *dst = map(sparse, dense)(src)
69 * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
70 * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
84 * bitmap_get_value8(map, start) Get 8bit value from map at start
85 * bitmap_set_value8(map, value, start) Set 8bit value to map at start
86 * bitmap_read(map, start, nbits) Read an nbits-sized value from
87 * map at start
88 * bitmap_write(map, value, start, nbits) Write an nbits-sized value to
89 * map at start
125 * contain all bit positions from 0 to 'bits' - 1.
132 unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags);
133 unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
134 unsigned long *bitmap_alloc_node(unsigned int nbits, gfp_t flags, int node);
135 unsigned long *bitmap_zalloc_node(unsigned int nbits, gfp_t flags, int node);
142 unsigned int nbits, gfp_t flags);
144 unsigned int nbits, gfp_t flags);
151 const unsigned long *bitmap2, unsigned int nbits);
155 unsigned int nbits);
157 unsigned int nbits);
159 unsigned int shift, unsigned int nbits);
161 unsigned int shift, unsigned int nbits);
163 unsigned int first, unsigned int cut, unsigned int nbits);
165 const unsigned long *bitmap2, unsigned int nbits);
167 const unsigned long *bitmap2, unsigned int nbits);
169 const unsigned long *bitmap2, unsigned int nbits);
171 const unsigned long *bitmap2, unsigned int nbits);
174 const unsigned long *mask, unsigned int nbits);
176 const unsigned long *bitmap2, unsigned int nbits);
178 const unsigned long *bitmap2, unsigned int nbits);
179 unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
180 unsigned int __bitmap_weight_and(const unsigned long *bitmap1,
181 const unsigned long *bitmap2, unsigned int nbits);
182 unsigned int __bitmap_weight_andnot(const unsigned long *bitmap1,
183 const unsigned long *bitmap2, unsigned int nbits);
184 void __bitmap_set(unsigned long *map, unsigned int start, int len);
185 void __bitmap_clear(unsigned long *map, unsigned int start, int len);
187 unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
190 unsigned int nr,
195 * bitmap_find_next_zero_area - find a contiguous aligned zero area
196 * @map: The address to base the search on
200 * @align_mask: Alignment mask for zero area
207 unsigned long bitmap_find_next_zero_area(unsigned long *map, in bitmap_find_next_zero_area() argument
210 unsigned int nr, in bitmap_find_next_zero_area()
213 return bitmap_find_next_zero_area_off(map, size, start, nr, in bitmap_find_next_zero_area()
218 const unsigned long *old, const unsigned long *new, unsigned int nbits);
219 int bitmap_bitremap(int oldbit,
220 const unsigned long *old, const unsigned long *new, int bits);
222 const unsigned long *relmap, unsigned int bits);
224 unsigned int sz, unsigned int nbits);
226 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
227 #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
231 static __always_inline void bitmap_zero(unsigned long *dst, unsigned int nbits) in bitmap_zero()
233 unsigned int len = bitmap_size(nbits); in bitmap_zero()
241 static __always_inline void bitmap_fill(unsigned long *dst, unsigned int nbits) in bitmap_fill()
243 unsigned int len = bitmap_size(nbits); in bitmap_fill()
252 void bitmap_copy(unsigned long *dst, const unsigned long *src, unsigned int nbits) in bitmap_copy()
254 unsigned int len = bitmap_size(nbits); in bitmap_copy()
266 void bitmap_copy_clear_tail(unsigned long *dst, const unsigned long *src, unsigned int nbits) in bitmap_copy_clear_tail()
275 unsigned int count, unsigned int size) in bitmap_copy_and_extend()
277 unsigned int copy = BITS_TO_LONGS(count); in bitmap_copy_and_extend()
281 to[copy - 1] &= BITMAP_LAST_WORD_MASK(count); in bitmap_copy_and_extend()
282 memset(to + copy, 0, bitmap_size(size) - copy * sizeof(long)); in bitmap_copy_and_extend()
286 * On 32-bit systems bitmaps are represented as u32 arrays internally. On LE64
290 * to out-of-bound access. To avoid that, both LE and BE variants of 64-bit
295 unsigned int nbits);
297 unsigned int nbits);
308 * On 64-bit systems bitmaps are represented as u64 arrays internally. So,
312 void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits);
313 void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits);
323 const unsigned long *src2, unsigned int nbits) in bitmap_and()
332 const unsigned long *src2, unsigned int nbits) in bitmap_or()
342 const unsigned long *src2, unsigned int nbits) in bitmap_xor()
352 const unsigned long *src2, unsigned int nbits) in bitmap_andnot()
360 void bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int nbits) in bitmap_complement()
373 #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1)
376 bool bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) in bitmap_equal()
387 * bitmap_or_equal - Check whether the or of two bitmaps is equal to a third
397 const unsigned long *src3, unsigned int nbits) in bitmap_or_equal()
406 bool bitmap_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) in bitmap_intersects()
415 bool bitmap_subset(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) in bitmap_subset()
433 bool bitmap_full(const unsigned long *src, unsigned int nbits) in bitmap_full()
442 unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits) in bitmap_weight()
451 const unsigned long *src2, unsigned int nbits) in bitmap_weight_and()
460 const unsigned long *src2, unsigned int nbits) in bitmap_weight_andnot()
468 void bitmap_set(unsigned long *map, unsigned int start, unsigned int nbits) in bitmap_set() argument
471 __set_bit(start, map); in bitmap_set()
473 *map |= GENMASK(start + nbits - 1, start); in bitmap_set()
478 memset((char *)map + start / 8, 0xff, nbits / 8); in bitmap_set()
480 __bitmap_set(map, start, nbits); in bitmap_set()
484 void bitmap_clear(unsigned long *map, unsigned int start, unsigned int nbits) in bitmap_clear() argument
487 __clear_bit(start, map); in bitmap_clear()
489 *map &= ~GENMASK(start + nbits - 1, start); in bitmap_clear()
494 memset((char *)map + start / 8, 0, nbits / 8); in bitmap_clear()
496 __bitmap_clear(map, start, nbits); in bitmap_clear()
501 unsigned int shift, unsigned int nbits) in bitmap_shift_right()
511 unsigned int shift, unsigned int nbits) in bitmap_shift_left()
523 const unsigned long *mask, in bitmap_replace() argument
524 unsigned int nbits) in bitmap_replace()
527 *dst = (*old & ~(*mask)) | (*new & *mask); in bitmap_replace()
529 __bitmap_replace(dst, old, new, mask, nbits); in bitmap_replace()
533 * bitmap_scatter - Scatter a bitmap according to the given mask
536 * @mask: mask representing bits to assign to in the scattered bitmap
539 * Scatters bitmap with sequential bits according to the given @mask.
542 * If @src bitmap = 0x005a, with @mask = 0x1313, @dst will be 0x0302.
545 * @src @mask @dst
554 * +------+|||||
555 * | +----+||||
556 * | |+----+|||
557 * | || +-+||
559 * mask: ...v..vv...v..vv
569 const unsigned long *mask, unsigned int nbits) in bitmap_scatter() argument
571 unsigned int n = 0; in bitmap_scatter()
572 unsigned int bit; in bitmap_scatter()
576 for_each_set_bit(bit, mask, nbits) in bitmap_scatter()
581 * bitmap_gather - Gather a bitmap according to given mask
584 * @mask: mask representing bits to extract from in the scattered bitmap
587 * Gathers bitmap with sparse bits according to the given @mask.
590 * If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a.
593 * @src @mask @dst
600 * mask: ...v..vv...v..vv
605 * | |+--> 1010
606 * | +--> 11010
607 * +----> 011010
612 * Suppose scattered computed using bitmap_scatter(scattered, src, mask, n).
613 * The operation bitmap_gather(result, scattered, mask, n) leads to a result
619 * bitmap_scatter(res, src, mask, n) and a call to
620 * bitmap_scatter(res, result, mask, n) will lead to the same res value.
624 const unsigned long *mask, unsigned int nbits) in bitmap_gather() argument
626 unsigned int n = 0; in bitmap_gather()
627 unsigned int bit; in bitmap_gather()
631 for_each_set_bit(bit, mask, nbits) in bitmap_gather()
636 void bitmap_next_set_region(unsigned long *bitmap, unsigned int *rs, in bitmap_next_set_region()
637 unsigned int *re, unsigned int end) in bitmap_next_set_region()
644 * bitmap_release_region - release allocated bitmap region
653 void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order) in bitmap_release_region()
659 * bitmap_allocate_region - allocate bitmap region
666 * Returns: 0 on success, or %-EBUSY if specified region wasn't
670 int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) in bitmap_allocate_region()
672 unsigned int len = BIT(order); in bitmap_allocate_region()
675 return -EBUSY; in bitmap_allocate_region()
681 * bitmap_find_free_region - find a contiguous aligned mem region
692 * or -errno on failure.
695 int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order) in bitmap_find_free_region()
697 unsigned int pos, end; /* scans bitmap by regions of size order */ in bitmap_find_free_region()
703 return -ENOMEM; in bitmap_find_free_region()
707 * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
710 * Linux bitmaps are internally arrays of unsigned longs, i.e. 32-bit
711 * integers in 32-bit environment, and 64-bit integers in 64-bit one.
716 * On 64-bit kernels 64-bit LE and BE numbers are naturally ordered in
719 * On 32-bit kernels 32-bit LE ABI orders lo word of 64-bit number in memory
720 * prior to hi, and 32-bit BE orders hi word prior to lo. The bitmap on the
721 * other hand is represented as an array of 32-bit words and the position of
724 * It matches 32-bit LE ABI, and we can simply let the compiler store 64-bit
740 * bitmap_from_u64 - Check and swap words within u64.
741 * @mask: source bitmap
744 * In 32-bit Big Endian kernel, when using ``(u32 *)(&val)[*]``
745 * to read u64 mask, we will get the wrong word.
747 * but we expect the lower 32-bits of u64.
749 static __always_inline void bitmap_from_u64(unsigned long *dst, u64 mask) in bitmap_from_u64() argument
751 bitmap_from_arr64(dst, &mask, 64); in bitmap_from_u64()
755 * bitmap_read - read a value of n-bits from the memory region
756 * @map: address to the bitmap memory region
757 * @start: bit offset of the n-bit value
761 * @map memory region. For @nbits = 0 and @nbits > BITS_PER_LONG the return
765 unsigned long bitmap_read(const unsigned long *map, unsigned long start, unsigned long nbits) in bitmap_read() argument
769 unsigned long space = BITS_PER_LONG - offset; in bitmap_read()
776 return (map[index] >> offset) & BITMAP_LAST_WORD_MASK(nbits); in bitmap_read()
778 value_low = map[index] & BITMAP_FIRST_WORD_MASK(start); in bitmap_read()
779 value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + nbits); in bitmap_read()
784 * bitmap_write - write n-bit value within a memory region
785 * @map: address to the bitmap memory region
787 * @start: bit offset of the n-bit value
790 * bitmap_write() behaves as-if implemented as @nbits calls of __assign_bit(),
799 void bitmap_write(unsigned long *map, unsigned long value, in bitmap_write() argument
805 unsigned long mask; in bitmap_write() local
811 mask = BITMAP_LAST_WORD_MASK(nbits); in bitmap_write()
812 value &= mask; in bitmap_write()
814 space = BITS_PER_LONG - offset; in bitmap_write()
818 map[index] &= (fit ? (~(mask << offset)) : ~BITMAP_FIRST_WORD_MASK(start)); in bitmap_write()
819 map[index] |= value << offset; in bitmap_write()
823 map[index + 1] &= BITMAP_FIRST_WORD_MASK(start + nbits); in bitmap_write()
824 map[index + 1] |= (value >> space); in bitmap_write()
827 #define bitmap_get_value8(map, start) \ argument
828 bitmap_read(map, start, BITS_PER_BYTE)
829 #define bitmap_set_value8(map, value, start) \ argument
830 bitmap_write(map, value, start, BITS_PER_BYTE)