Hardware Locality (hwloc)  PR-737-20250925.0822.gite8f69c77f
bitmap.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright © 2009 CNRS
4  * Copyright © 2009-2025 Inria. All rights reserved.
5  * Copyright © 2009-2012 Université Bordeaux
6  * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
7  * See COPYING in top-level directory.
8  */
9 
14 #ifndef HWLOC_BITMAP_H
15 #define HWLOC_BITMAP_H
16 
17 #include "hwloc/autogen/config.h"
18 
19 #include <assert.h>
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
70 typedef struct hwloc_bitmap_s * hwloc_bitmap_t;
72 typedef const struct hwloc_bitmap_s * hwloc_const_bitmap_t;
73 
74 
75 /*
76  * Bitmap allocation, freeing and copying.
77  */
78 
86 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc(void) __hwloc_attribute_malloc;
87 
95 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc_full(void) __hwloc_attribute_malloc;
96 
101 HWLOC_DECLSPEC void hwloc_bitmap_free(hwloc_bitmap_t bitmap);
102 
107 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap) __hwloc_attribute_malloc;
108 
110 HWLOC_DECLSPEC int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src);
111 
112 
113 /*
114  * Bitmap/String Conversion
115  */
116 
132 HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
133 
144 HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
145 
156 HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
157 
175 HWLOC_DECLSPEC int hwloc_bitmap_list_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
176 
189 HWLOC_DECLSPEC int hwloc_bitmap_list_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
190 
202 HWLOC_DECLSPEC int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
203 
220 HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
221 
233 HWLOC_DECLSPEC int hwloc_bitmap_taskset_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
234 
246 HWLOC_DECLSPEC int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
247 
248 
249 /*
250  * Building bitmaps.
251  */
252 
254 HWLOC_DECLSPEC void hwloc_bitmap_zero(hwloc_bitmap_t bitmap);
255 
257 HWLOC_DECLSPEC void hwloc_bitmap_fill(hwloc_bitmap_t bitmap);
258 
260 HWLOC_DECLSPEC int hwloc_bitmap_only(hwloc_bitmap_t bitmap, unsigned id);
261 
263 HWLOC_DECLSPEC int hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned id);
264 
266 HWLOC_DECLSPEC int hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask);
267 
269 HWLOC_DECLSPEC int hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
270 
272 HWLOC_DECLSPEC int hwloc_bitmap_from_ulongs(hwloc_bitmap_t bitmap, unsigned nr, const unsigned long *masks);
273 
274 
275 /*
276  * Modifying bitmaps.
277  */
278 
280 HWLOC_DECLSPEC int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id);
281 
286 HWLOC_DECLSPEC int hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
287 
289 HWLOC_DECLSPEC int hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
290 
292 HWLOC_DECLSPEC int hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned id);
293 
298 HWLOC_DECLSPEC int hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
299 
319 HWLOC_DECLSPEC int hwloc_bitmap_singlify(hwloc_bitmap_t bitmap);
320 
321 
322 /*
323  * Consulting bitmaps.
324  */
325 
327 HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
328 
330 HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i) __hwloc_attribute_pure;
331 
338 HWLOC_DECLSPEC int hwloc_bitmap_to_ulongs(hwloc_const_bitmap_t bitmap, unsigned nr, unsigned long *masks);
339 
354 HWLOC_DECLSPEC int hwloc_bitmap_nr_ulongs(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
355 
360 HWLOC_DECLSPEC int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id) __hwloc_attribute_pure;
361 
366 HWLOC_DECLSPEC int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
367 
374 HWLOC_DECLSPEC int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
375 
381 HWLOC_DECLSPEC int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
382 
389 HWLOC_DECLSPEC int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
390 
396 HWLOC_DECLSPEC int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
397 
404 HWLOC_DECLSPEC int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
405 
411 HWLOC_DECLSPEC int hwloc_bitmap_first_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
412 
419 HWLOC_DECLSPEC int hwloc_bitmap_next_unset(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
420 
426 HWLOC_DECLSPEC int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
427 
443 #define hwloc_bitmap_foreach_begin(id, bitmap) \
444 do { \
445  assert(hwloc_bitmap_weight(bitmap) != -1); \
446  for (id = hwloc_bitmap_first(bitmap); \
447  (unsigned) id != (unsigned) -1; \
448  id = hwloc_bitmap_next(bitmap, id)) {
449 
457 #define hwloc_bitmap_foreach_end() \
458  } \
459 } while (0)
460 
461 
462 /*
463  * Combining bitmaps.
464  */
465 
470 HWLOC_DECLSPEC int hwloc_bitmap_or (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
471 
476 HWLOC_DECLSPEC int hwloc_bitmap_and (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
477 
482 HWLOC_DECLSPEC int hwloc_bitmap_andnot (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
483 
488 HWLOC_DECLSPEC int hwloc_bitmap_xor (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
489 
494 HWLOC_DECLSPEC int hwloc_bitmap_not (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap);
495 
496 
497 /*
498  * Comparing bitmaps.
499  */
500 
507 HWLOC_DECLSPEC int hwloc_bitmap_intersects (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
508 
515 HWLOC_DECLSPEC int hwloc_bitmap_isincluded (hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap) __hwloc_attribute_pure;
516 
521 HWLOC_DECLSPEC int hwloc_bitmap_isequal (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
522 
540 HWLOC_DECLSPEC int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
541 
559 HWLOC_DECLSPEC int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
560 
564 #ifdef __cplusplus
565 } /* extern "C" */
566 #endif
567 
568 
569 #endif /* HWLOC_BITMAP_H */
hwloc_bitmap_first
int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap)
Compute the first index (least significant bit) in bitmap bitmap.
hwloc_bitmap_allbut
int hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned id)
Fill the bitmap and clear the index id.
hwloc_bitmap_alloc
hwloc_bitmap_t hwloc_bitmap_alloc(void)
Allocate a new empty bitmap.
hwloc_bitmap_isequal
int hwloc_bitmap_isequal(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmap bitmap1 is equal to bitmap bitmap2.
hwloc_bitmap_taskset_sscanf
int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char *restrict string)
Parse a taskset-specific bitmap string and stores it in bitmap bitmap.
hwloc_bitmap_taskset_snprintf
int hwloc_bitmap_taskset_snprintf(char *restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap)
Stringify a bitmap in the taskset-specific format.
hwloc_bitmap_iszero
int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is empty.
hwloc_bitmap_clr_range
int hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, int end)
Remove indexes from begin to end in bitmap bitmap.
hwloc_bitmap_free
void hwloc_bitmap_free(hwloc_bitmap_t bitmap)
Free bitmap bitmap.
hwloc_bitmap_fill
void hwloc_bitmap_fill(hwloc_bitmap_t bitmap)
Fill bitmap bitmap with all possible indexes (even if those objects don't exist or are otherwise unav...
hwloc_const_bitmap_t
const struct hwloc_bitmap_s * hwloc_const_bitmap_t
a non-modifiable hwloc_bitmap_t
Definition: bitmap.h:72
hwloc_bitmap_alloc_full
hwloc_bitmap_t hwloc_bitmap_alloc_full(void)
Allocate a new full bitmap.
hwloc_bitmap_compare_first
int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Compare bitmaps bitmap1 and bitmap2 using their lowest index.
hwloc_bitmap_next
int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, int prev)
Compute the next index in bitmap bitmap which is after index prev.
hwloc_bitmap_xor
int hwloc_bitmap_xor(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Xor bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
hwloc_bitmap_list_sscanf
int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char *restrict string)
Parse a list string and stores it in bitmap bitmap.
hwloc_bitmap_list_snprintf
int hwloc_bitmap_list_snprintf(char *restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap)
Stringify a bitmap in the list format.
hwloc_bitmap_asprintf
int hwloc_bitmap_asprintf(char **strp, hwloc_const_bitmap_t bitmap)
Stringify a bitmap into a newly allocated string in the default hwloc format.
hwloc_bitmap_set_ith_ulong
int hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask)
Replace i -th subset of bitmap bitmap with unsigned long mask.
hwloc_bitmap_not
int hwloc_bitmap_not(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap)
Negate bitmap bitmap and store the result in bitmap res.
hwloc_bitmap_weight
int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap)
Compute the "weight" of bitmap bitmap (i.e., number of indexes that are in the bitmap).
hwloc_bitmap_list_asprintf
int hwloc_bitmap_list_asprintf(char **strp, hwloc_const_bitmap_t bitmap)
Stringify a bitmap into a newly allocated list string.
hwloc_bitmap_last
int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap)
Compute the last index (most significant bit) in bitmap bitmap.
hwloc_bitmap_and
int hwloc_bitmap_and(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
And bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
hwloc_bitmap_t
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition: bitmap.h:70
hwloc_bitmap_andnot
int hwloc_bitmap_andnot(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
And bitmap bitmap1 and the negation of bitmap2 and store the result in bitmap res.
hwloc_bitmap_only
int hwloc_bitmap_only(hwloc_bitmap_t bitmap, unsigned id)
Empty the bitmap bitmap and add bit id.
hwloc_bitmap_to_ulongs
int hwloc_bitmap_to_ulongs(hwloc_const_bitmap_t bitmap, unsigned nr, unsigned long *masks)
Convert the first nr subsets of bitmap bitmap into the array of nr unsigned long masks.
hwloc_bitmap_nr_ulongs
int hwloc_bitmap_nr_ulongs(hwloc_const_bitmap_t bitmap)
Return the number of unsigned longs required for storing bitmap bitmap entirely.
hwloc_bitmap_set_range
int hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, int end)
Add indexes from begin to end in bitmap bitmap.
hwloc_bitmap_taskset_asprintf
int hwloc_bitmap_taskset_asprintf(char **strp, hwloc_const_bitmap_t bitmap)
Stringify a bitmap into a newly allocated taskset-specific string.
hwloc_bitmap_from_ith_ulong
int hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask)
Setup bitmap bitmap from unsigned long mask used as i -th subset.
hwloc_bitmap_singlify
int hwloc_bitmap_singlify(hwloc_bitmap_t bitmap)
Keep a single index among those set in bitmap bitmap.
hwloc_bitmap_to_ulong
unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap)
Convert the beginning part of bitmap bitmap into unsigned long mask.
hwloc_bitmap_copy
int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src)
Copy the contents of bitmap src into the already allocated bitmap dst.
hwloc_bitmap_first_unset
int hwloc_bitmap_first_unset(hwloc_const_bitmap_t bitmap)
Compute the first unset index (least significant bit) in bitmap bitmap.
hwloc_bitmap_from_ulongs
int hwloc_bitmap_from_ulongs(hwloc_bitmap_t bitmap, unsigned nr, const unsigned long *masks)
Setup bitmap bitmap from unsigned longs masks used as first nr subsets.
hwloc_bitmap_sscanf
int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char *restrict string)
Parse a bitmap string as the default hwloc format and stores it in bitmap bitmap.
hwloc_bitmap_isset
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
hwloc_bitmap_isfull
int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is completely full.
hwloc_bitmap_to_ith_ulong
unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i)
Convert the i -th subset of bitmap bitmap into unsigned long mask.
hwloc_bitmap_or
int hwloc_bitmap_or(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Or bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
hwloc_bitmap_intersects
int hwloc_bitmap_intersects(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmaps bitmap1 and bitmap2 intersects.
hwloc_bitmap_zero
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
hwloc_bitmap_set
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
hwloc_bitmap_compare
int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Compare bitmaps bitmap1 and bitmap2 in lexicographic order.
hwloc_bitmap_isincluded
int hwloc_bitmap_isincluded(hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap)
Test whether bitmap sub_bitmap is part of bitmap super_bitmap.
hwloc_bitmap_from_ulong
int hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask)
Setup bitmap bitmap from unsigned long mask.
hwloc_bitmap_next_unset
int hwloc_bitmap_next_unset(hwloc_const_bitmap_t bitmap, int prev)
Compute the next unset index in bitmap bitmap which is after index prev.
hwloc_bitmap_clr
int hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned id)
Remove index id from bitmap bitmap.
hwloc_bitmap_dup
hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap)
Duplicate bitmap bitmap by allocating a new bitmap and copying bitmap contents.
hwloc_bitmap_snprintf
int hwloc_bitmap_snprintf(char *restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap)
Stringify a bitmap in the default hwloc format.
hwloc_bitmap_last_unset
int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap)
Compute the last unset index (most significant bit) in bitmap bitmap.