Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-10 08:27:42

0001 /*
0002  * SPDX-License-Identifier: BSD-3-Clause
0003  * Copyright © 2009 CNRS
0004  * Copyright © 2009-2025 Inria.  All rights reserved.
0005  * Copyright © 2009-2012 Université Bordeaux
0006  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
0007  * See COPYING in top-level directory.
0008  */
0009 
0010 /** \file
0011  * \brief The bitmap API, for use in hwloc itself.
0012  */
0013 
0014 #ifndef HWLOC_BITMAP_H
0015 #define HWLOC_BITMAP_H
0016 
0017 #include "hwloc/autogen/config.h"
0018 
0019 #include <assert.h>
0020 
0021 
0022 #ifdef __cplusplus
0023 extern "C" {
0024 #endif
0025 
0026 
0027 /** \defgroup hwlocality_bitmap The bitmap API
0028  *
0029  * The ::hwloc_bitmap_t type represents a set of integers (positive or null).
0030  * A bitmap may be of infinite size (all bits are set after some point).
0031  * A bitmap may even be full if all bits are set.
0032  *
0033  * Bitmaps are used by hwloc for sets of OS processors
0034  * (which may actually be hardware threads) as by ::hwloc_cpuset_t
0035  * (a typedef for ::hwloc_bitmap_t), or sets of NUMA memory nodes
0036  * as ::hwloc_nodeset_t (also a typedef for ::hwloc_bitmap_t).
0037  * Those are used for cpuset and nodeset fields in the ::hwloc_obj structure,
0038  * see \ref hwlocality_object_sets.
0039  *
0040  * <em>Both CPU and node sets are always indexed by OS physical number.</em>
0041  * However users should usually not build CPU and node sets manually
0042  * (e.g. with hwloc_bitmap_set()).
0043  * One should rather use existing object sets and combine them with
0044  * hwloc_bitmap_or(), etc.
0045  * For instance, binding the current thread on a pair of cores may be performed with:
0046  * \code
0047  * hwloc_obj_t core1 = ... , core2 = ... ;
0048  * hwloc_bitmap_t set = hwloc_bitmap_alloc();
0049  * hwloc_bitmap_or(set, core1->cpuset, core2->cpuset);
0050  * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
0051  * hwloc_bitmap_free(set);
0052  * \endcode
0053  *
0054  * \note Most functions below return 0 on success and -1 on error.
0055  * The usual error case would be an internal failure to realloc/extend
0056  * the storage of the bitmap (\p errno would be set to \c ENOMEM).
0057  * See also \ref hwlocality_api_error_reporting.
0058  *
0059  * \note Several examples of using the bitmap API are available under the
0060  * doc/examples/ directory in the source tree.
0061  * Regression tests such as tests/hwloc/hwloc_bitmap*.c also make intensive use
0062  * of this API.
0063  * @{
0064  */
0065 
0066 
0067 /** \brief
0068  * Set of bits represented as an opaque pointer to an internal bitmap.
0069  */
0070 typedef struct hwloc_bitmap_s * hwloc_bitmap_t;
0071 /** \brief a non-modifiable ::hwloc_bitmap_t */
0072 typedef const struct hwloc_bitmap_s * hwloc_const_bitmap_t;
0073 
0074 
0075 /*
0076  * Bitmap allocation, freeing and copying.
0077  */
0078 
0079 /** \brief Allocate a new empty bitmap.
0080  *
0081  * \returns A valid bitmap or \c NULL.
0082  *
0083  * The bitmap should be freed by a corresponding call to
0084  * hwloc_bitmap_free().
0085  */
0086 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc(void) __hwloc_attribute_malloc;
0087 
0088 /** \brief Allocate a new full bitmap.
0089  *
0090  * \returns A valid bitmap or \c NULL.
0091  *
0092  * The bitmap should be freed by a corresponding call to
0093  * hwloc_bitmap_free().
0094  */
0095 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc_full(void) __hwloc_attribute_malloc;
0096 
0097 /** \brief Free bitmap \p bitmap.
0098  *
0099  * If \p bitmap is \c NULL, no operation is performed.
0100  */
0101 HWLOC_DECLSPEC void hwloc_bitmap_free(hwloc_bitmap_t bitmap);
0102 
0103 /** \brief Duplicate bitmap \p bitmap by allocating a new bitmap and copying \p bitmap contents.
0104  *
0105  * If \p bitmap is \c NULL, \c NULL is returned.
0106  */
0107 HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap) __hwloc_attribute_malloc;
0108 
0109 /** \brief Copy the contents of bitmap \p src into the already allocated bitmap \p dst */
0110 HWLOC_DECLSPEC int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src);
0111 
0112 
0113 /*
0114  * Bitmap/String Conversion
0115  */
0116 
0117 /** \brief Stringify a bitmap in the default hwloc format.
0118  *
0119  * Print the bits set inside a bitmap as a comma-separated list of hexadecimal 32-bit blocks.
0120  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"0xffffffff,0x00000006,0x00000002"</tt>.
0121  *
0122  * Up to \p buflen characters may be written in buffer \p buf.
0123  *
0124  * If \p buflen is 0, \p buf may safely be \c NULL.
0125  *
0126  * \return the number of characters that were actually written if not truncating,
0127  * or that would have been written (not including the ending \c \0).
0128  * \return -1 on error.
0129  *
0130  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0131  * This should be clearly indicated when displaying such bitmaps to end users.
0132  * See also \ref faq_convert_indexes
0133  */
0134 HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
0135 
0136 /** \brief Stringify a bitmap into a newly allocated string in the default hwloc format.
0137  *
0138  * Print the bits set inside a bitmap as a comma-separated list of hexadecimal 32-bit blocks.
0139  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"0xffffffff,0x00000006,0x00000002"</tt>.
0140  *
0141  * \return the number of characters that were written (not including the ending \c \0).
0142  * \return -1 on error, for instance with \p errno set to \c ENOMEM on failure to allocate the output string.
0143  *
0144  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0145  * This should be clearly indicated when displaying such bitmaps to end users.
0146  * See also \ref faq_convert_indexes
0147  */
0148 HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
0149 
0150 /** \brief Parse a bitmap string as the default hwloc format and stores it in bitmap \p bitmap.
0151  *
0152  * The input string should be a comma-separared list of hexadecimal 32-bit blocks.
0153  * String <tt>"0xffffffff,0x6,0x2"</tt> is parsed as a bitmap containing all bits between 64 and 95,
0154  * and bits 33, 34 and 1.
0155  *
0156  * \return 0 on success, -1 on error.
0157  *
0158  * \note <b>If the bitmap is a CPU or nodeset, the input string must contain physical indexes.</b>
0159  */
0160 HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
0161 
0162 /** \brief Stringify a bitmap in the list format.
0163  *
0164  * Lists are comma-separated indexes or ranges.
0165  * Ranges are dash separated indexes.
0166  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"1,33-34,64-95"</tt>.
0167  * The last range may not have an ending index if the bitmap is infinitely set.
0168  *
0169  * Up to \p buflen characters may be written in buffer \p buf.
0170  *
0171  * If \p buflen is 0, \p buf may safely be \c NULL.
0172  *
0173  * \return the number of characters that were actually written if not truncating,
0174  * or that would have been written (not including the ending \c \0).
0175  * \return -1 on error.
0176  *
0177  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0178  * This should be clearly indicated when displaying such bitmaps to end users.
0179  * See also \ref faq_convert_indexes
0180  */
0181 HWLOC_DECLSPEC int hwloc_bitmap_list_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
0182 
0183 /** \brief Stringify a bitmap into a newly allocated list string.
0184  *
0185  * Lists are comma-separated indexes or ranges.
0186  * Ranges are dash separated indexes.
0187  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"1,33-34,64-95"</tt>.
0188  * The last range may not have an ending index if the bitmap is infinitely set.
0189  *
0190  * \return the number of characters that were written (not including the ending \c \0).
0191  * \return -1 on error, for instance with \p errno set to \c ENOMEM on failure to allocate the output string.
0192  *
0193  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0194  * This should be clearly indicated when displaying such bitmaps to end users.
0195  * See also \ref faq_convert_indexes
0196  */
0197 HWLOC_DECLSPEC int hwloc_bitmap_list_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
0198 
0199 /** \brief Parse a list string and stores it in bitmap \p bitmap.
0200  *
0201  * Lists are comma-separated indexes or ranges.
0202  * Ranges are dash separated indexes.
0203  * String <tt>"1,33-34,64-95"</tt> is parsed as a bitmap containing bits 1, 33, 34, and all from 64 to 95.
0204  * The last range may not have an ending index if the bitmap is infinitely set.
0205  *
0206  * \return 0 on success, -1 on error.
0207  *
0208  * \note <b>If the bitmap is a CPU or nodeset, the input string must contain physical indexes.</b>
0209  */
0210 HWLOC_DECLSPEC int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
0211 
0212 /** \brief Stringify a bitmap in the taskset-specific format.
0213  *
0214  * The taskset program manipulates bitmap strings that contain a single
0215  * (possible very long) hexadecimal number starting with 0x.
0216  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"0xffffffff0000000600000002"</tt>.
0217  *
0218  * Up to \p buflen characters may be written in buffer \p buf.
0219  *
0220  * If \p buflen is 0, \p buf may safely be \c NULL.
0221  *
0222  * \return the number of characters that were actually written if not truncating,
0223  * or that would have been written (not including the ending \c \0).
0224  * \return -1 on error.
0225  *
0226  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0227  * This should be clearly indicated when displaying such bitmaps to end users.
0228  * See also \ref faq_convert_indexes
0229  */
0230 HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
0231 
0232 /** \brief Stringify a bitmap into a newly allocated taskset-specific string.
0233  *
0234  * The taskset program manipulates bitmap strings that contain a single
0235  * (possible very long) hexadecimal number starting with 0x.
0236  * A bitmap containing bits 1, 33, 34, and all from 64 to 95 is printed as <tt>"0xffffffff0000000600000002"</tt>.
0237  *
0238  * \return the number of characters that were written (not including the ending \c \0).
0239  * \return -1 on error, for instance with \p errno set to \c ENOMEM on failure to allocate the output string.
0240  *
0241  * \note <b>If the bitmap is a CPU or nodeset, it contains physical indexes.</b>
0242  * This should be clearly indicated when displaying such bitmaps to end users.
0243  * See also \ref faq_convert_indexes
0244  */
0245 HWLOC_DECLSPEC int hwloc_bitmap_taskset_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
0246 
0247 /** \brief Parse a taskset-specific bitmap string and stores it in bitmap \p bitmap.
0248  *
0249  * The taskset program manipulates bitmap strings that contain a single
0250  * (possible very long) hexadecimal number starting with 0x.
0251  * String <tt>"0xffffffff0000000600000002"</tt> is parsed as a bitmap containing all bits between 64 and 95,
0252  * and bits 33, 34 and 1.
0253  *
0254  * \return 0 on success, -1 on error.
0255  *
0256  * \note <b>If the bitmap is a CPU or nodeset, the input string must contain physical indexes.</b>
0257  */
0258 HWLOC_DECLSPEC int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
0259 
0260 
0261 /*
0262  * Building bitmaps.
0263  */
0264 
0265 /** \brief Empty the bitmap \p bitmap */
0266 HWLOC_DECLSPEC void hwloc_bitmap_zero(hwloc_bitmap_t bitmap);
0267 
0268 /** \brief Fill bitmap \p bitmap with all possible indexes (even if those objects don't exist or are otherwise unavailable) */
0269 HWLOC_DECLSPEC void hwloc_bitmap_fill(hwloc_bitmap_t bitmap);
0270 
0271 /** \brief Empty the bitmap \p bitmap and add bit \p id */
0272 HWLOC_DECLSPEC int hwloc_bitmap_only(hwloc_bitmap_t bitmap, unsigned id);
0273 
0274 /** \brief Fill the bitmap \p and clear the index \p id */
0275 HWLOC_DECLSPEC int hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned id);
0276 
0277 /** \brief Setup bitmap \p bitmap from unsigned long \p mask */
0278 HWLOC_DECLSPEC int hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask);
0279 
0280 /** \brief Setup bitmap \p bitmap from unsigned long \p mask used as \p i -th subset */
0281 HWLOC_DECLSPEC int hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
0282 
0283 /** \brief Setup bitmap \p bitmap from unsigned longs \p masks used as first \p nr subsets */
0284 HWLOC_DECLSPEC int hwloc_bitmap_from_ulongs(hwloc_bitmap_t bitmap, unsigned nr, const unsigned long *masks);
0285 
0286 
0287 /*
0288  * Modifying bitmaps.
0289  */
0290 
0291 /** \brief Add index \p id in bitmap \p bitmap */
0292 HWLOC_DECLSPEC int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id);
0293 
0294 /** \brief Add indexes from \p begin to \p end in bitmap \p bitmap.
0295  *
0296  * If \p end is \c -1, the range is infinite.
0297  */
0298 HWLOC_DECLSPEC int hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
0299 
0300 /** \brief Replace \p i -th subset of bitmap \p bitmap with unsigned long \p mask */
0301 HWLOC_DECLSPEC int hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
0302 
0303 /** \brief Remove index \p id from bitmap \p bitmap */
0304 HWLOC_DECLSPEC int hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned id);
0305 
0306 /** \brief Remove indexes from \p begin to \p end in bitmap \p bitmap.
0307  *
0308  * If \p end is \c -1, the range is infinite.
0309  */
0310 HWLOC_DECLSPEC int hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
0311 
0312 /** \brief Keep a single index among those set in bitmap \p bitmap
0313  *
0314  * May be useful before binding so that the process does not
0315  * have a chance of migrating between multiple processors
0316  * in the original mask.
0317  * Instead of running the task on any PU inside the given CPU set,
0318  * the operating system scheduler will be forced to run it on a single
0319  * of these PUs.
0320  * It avoids a migration overhead and cache-line ping-pongs between PUs.
0321  *
0322  * \note This function is NOT meant to distribute multiple processes
0323  * within a single CPU set. It always return the same single bit when
0324  * called multiple times on the same input set. hwloc_distrib() may
0325  * be used for generating CPU sets to distribute multiple tasks below
0326  * a single multi-PU object.
0327  *
0328  * \note This function cannot be applied to an object set directly. It
0329  * should be applied to a copy (which may be obtained with hwloc_bitmap_dup()).
0330  */
0331 HWLOC_DECLSPEC int hwloc_bitmap_singlify(hwloc_bitmap_t bitmap);
0332 
0333 
0334 /*
0335  * Consulting bitmaps.
0336  */
0337 
0338 /** \brief Convert the beginning part of bitmap \p bitmap into unsigned long \p mask */
0339 HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0340 
0341 /** \brief Convert the \p i -th subset of bitmap \p bitmap into unsigned long mask */
0342 HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i) __hwloc_attribute_pure;
0343 
0344 /** \brief Convert the first \p nr subsets of bitmap \p bitmap into the array of \p nr unsigned long \p masks
0345  *
0346  * \p nr may be determined earlier with hwloc_bitmap_nr_ulongs().
0347  *
0348  * \return 0
0349  */
0350 HWLOC_DECLSPEC int hwloc_bitmap_to_ulongs(hwloc_const_bitmap_t bitmap, unsigned nr, unsigned long *masks);
0351 
0352 /** \brief Return the number of unsigned longs required for storing bitmap \p bitmap entirely
0353  *
0354  * This is the number of contiguous unsigned longs from the very first bit of the bitmap
0355  * (even if unset) up to the last set bit.
0356  * This is useful for knowing the \p nr parameter to pass to hwloc_bitmap_to_ulongs()
0357  * (or which calls to hwloc_bitmap_to_ith_ulong() are needed)
0358  * to entirely convert a bitmap into multiple unsigned longs.
0359  *
0360  * When called on the output of hwloc_topology_get_topology_cpuset(),
0361  * the returned number is large enough for all cpusets of the topology.
0362  *
0363  * \return the number of unsigned longs required.
0364  * \return -1 if \p bitmap is infinite.
0365  */
0366 HWLOC_DECLSPEC int hwloc_bitmap_nr_ulongs(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0367 
0368 /** \brief Test whether index \p id is part of bitmap \p bitmap.
0369  *
0370  * \return 1 if the bit at index \p id is set in bitmap \p bitmap, 0 otherwise.
0371  */
0372 HWLOC_DECLSPEC int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id) __hwloc_attribute_pure;
0373 
0374 /** \brief Test whether bitmap \p bitmap is empty
0375  *
0376  * \return 1 if bitmap is empty, 0 otherwise.
0377  */
0378 HWLOC_DECLSPEC int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0379 
0380 /** \brief Test whether bitmap \p bitmap is completely full
0381  *
0382  * \return 1 if bitmap is full, 0 otherwise.
0383  *
0384  * \note A full bitmap is always infinitely set.
0385  */
0386 HWLOC_DECLSPEC int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0387 
0388 /** \brief Compute the first index (least significant bit) in bitmap \p bitmap
0389  *
0390  * \return the first index set in \p bitmap.
0391  * \return -1 if \p bitmap is empty.
0392  */
0393 HWLOC_DECLSPEC int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0394 
0395 /** \brief Compute the next index in bitmap \p bitmap which is after index \p prev
0396  *
0397  * \return the first index set in \p bitmap if \p prev is \c -1.
0398  * \return the next index set in \p bitmap if \p prev is not \c -1.
0399  * \return -1 if no index with higher index is set in \p bitmap.
0400  */
0401 HWLOC_DECLSPEC int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
0402 
0403 /** \brief Compute the last index (most significant bit) in bitmap \p bitmap
0404  *
0405  * \return the last index set in \p bitmap.
0406  * \return -1 if \p bitmap is empty, or if \p bitmap is infinitely set.
0407  */
0408 HWLOC_DECLSPEC int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0409 
0410 /** \brief Compute the "weight" of bitmap \p bitmap (i.e., number of
0411  * indexes that are in the bitmap).
0412  *
0413  * \return the number of indexes that are in the bitmap.
0414  * \return -1 if \p bitmap is infinitely set.
0415  */
0416 HWLOC_DECLSPEC int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0417 
0418 /** \brief Compute the first unset index (least significant bit) in bitmap \p bitmap
0419  *
0420  * \return the first unset index in \p bitmap.
0421  * \return -1 if \p bitmap is full.
0422  */
0423 HWLOC_DECLSPEC int hwloc_bitmap_first_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0424 
0425 /** \brief Compute the next unset index in bitmap \p bitmap which is after index \p prev
0426  *
0427  * \return the first index unset in \p bitmap if \p prev is \c -1.
0428  * \return the next index unset in \p bitmap if \p prev is not \c -1.
0429  * \return -1 if no index with higher index is unset in \p bitmap.
0430  */
0431 HWLOC_DECLSPEC int hwloc_bitmap_next_unset(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
0432 
0433 /** \brief Compute the last unset index (most significant bit) in bitmap \p bitmap
0434  *
0435  * \return the last index unset in \p bitmap.
0436  * \return -1 if \p bitmap is full, or if \p bitmap is not infinitely set.
0437  */
0438 HWLOC_DECLSPEC int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
0439 
0440 /** \brief Loop macro iterating on bitmap \p bitmap
0441  *
0442  * The loop must start with hwloc_bitmap_foreach_begin() and end
0443  * with hwloc_bitmap_foreach_end() followed by a terminating ';'.
0444  *
0445  * \p id is the loop variable; it should be an unsigned int.  The
0446  * first iteration will set \p id to the lowest index in the bitmap.
0447  * Successive iterations will iterate through, in order, all remaining
0448  * indexes set in the bitmap.  To be specific: each iteration will return a
0449  * value for \p id such that hwloc_bitmap_isset(bitmap, id) is true.
0450  *
0451  * The assert prevents the loop from being infinite if the bitmap is infinitely set.
0452  *
0453  * \hideinitializer
0454  */
0455 #define hwloc_bitmap_foreach_begin(id, bitmap) \
0456 do { \
0457         assert(hwloc_bitmap_weight(bitmap) != -1); \
0458         for (id = hwloc_bitmap_first(bitmap); \
0459              (unsigned) id != (unsigned) -1; \
0460              id = hwloc_bitmap_next(bitmap, id)) {
0461 
0462 /** \brief End of loop macro iterating on a bitmap.
0463  *
0464  * Needs a terminating ';'.
0465  *
0466  * \sa hwloc_bitmap_foreach_begin()
0467  * \hideinitializer
0468  */
0469 #define hwloc_bitmap_foreach_end()      \
0470         } \
0471 } while (0)
0472 
0473 
0474 /*
0475  * Combining bitmaps.
0476  */
0477 
0478 /** \brief Or bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
0479  *
0480  * \p res can be the same as \p bitmap1 or \p bitmap2
0481  */
0482 HWLOC_DECLSPEC int hwloc_bitmap_or (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
0483 
0484 /** \brief And bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
0485  *
0486  * \p res can be the same as \p bitmap1 or \p bitmap2
0487  */
0488 HWLOC_DECLSPEC int hwloc_bitmap_and (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
0489 
0490 /** \brief And bitmap \p bitmap1 and the negation of \p bitmap2 and store the result in bitmap \p res
0491  *
0492  * \p res can be the same as \p bitmap1 or \p bitmap2
0493  */
0494 HWLOC_DECLSPEC int hwloc_bitmap_andnot (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
0495 
0496 /** \brief Xor bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
0497  *
0498  * \p res can be the same as \p bitmap1 or \p bitmap2
0499  */
0500 HWLOC_DECLSPEC int hwloc_bitmap_xor (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
0501 
0502 /** \brief Negate bitmap \p bitmap and store the result in bitmap \p res
0503  *
0504  * \p res can be the same as \p bitmap
0505  */
0506 HWLOC_DECLSPEC int hwloc_bitmap_not (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap);
0507 
0508 
0509 /*
0510  * Comparing bitmaps.
0511  */
0512 
0513 /** \brief Test whether bitmaps \p bitmap1 and \p bitmap2 intersects.
0514  *
0515  * \return 1 if bitmaps intersect, 0 otherwise.
0516  *
0517  * \note The empty bitmap does not intersect any other bitmap.
0518  */
0519 HWLOC_DECLSPEC int hwloc_bitmap_intersects (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
0520 
0521 /** \brief Test whether bitmap \p sub_bitmap is part of bitmap \p super_bitmap.
0522  *
0523  * \return 1 if \p sub_bitmap is included in \p super_bitmap, 0 otherwise.
0524  *
0525  * \note The empty bitmap is considered included in any other bitmap.
0526  */
0527 HWLOC_DECLSPEC int hwloc_bitmap_isincluded (hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap) __hwloc_attribute_pure;
0528 
0529 /** \brief Test whether bitmap \p bitmap1 is equal to bitmap \p bitmap2.
0530  *
0531  * \return 1 if bitmaps are equal, 0 otherwise.
0532  */
0533 HWLOC_DECLSPEC int hwloc_bitmap_isequal (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
0534 
0535 /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 using their lowest index.
0536  *
0537  * A bitmap is considered smaller if its least significant bit is smaller.
0538  * The empty bitmap is considered higher than anything (because its least significant bit does not exist).
0539  *
0540  * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
0541  * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
0542  *
0543  * For instance comparing binary bitmaps 0011 and 0110 returns -1
0544  * (hence 0011 is considered smaller than 0110)
0545  * because least significant bit of 0011 (0001) is smaller than least significant bit of 0110 (0010).
0546  * Comparing 01001 and 00110 would also return -1 for the same reason.
0547  *
0548  * \return 0 if bitmaps are considered equal, even if they are not strictly equal.
0549  * They just need to have the same least significant bit.
0550  * For instance, comparing binary bitmaps 0010 and 0110 returns 0 because they have the same least significant bit.
0551  */
0552 HWLOC_DECLSPEC int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
0553 
0554 /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 in lexicographic order.
0555  *
0556  * Lexicographic comparison of bitmaps, starting for their highest indexes.
0557  * Compare last indexes first, then second, etc.
0558  * The empty bitmap is considered lower than anything.
0559  *
0560  * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
0561  * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
0562  * \return 0 if bitmaps are equal (contrary to hwloc_bitmap_compare_first()).
0563  *
0564  * For instance comparing binary bitmaps 0011 and 0110 returns -1
0565  * (hence 0011 is considered smaller than 0110).
0566  * Comparing 00101 and 01010 returns -1 too.
0567  *
0568  * \note This is different from the non-existing hwloc_bitmap_compare_last()
0569  * which would only compare the highest index of each bitmap.
0570  */
0571 HWLOC_DECLSPEC int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
0572 
0573 /** @} */
0574 
0575 
0576 #ifdef __cplusplus
0577 } /* extern "C" */
0578 #endif
0579 
0580 
0581 #endif /* HWLOC_BITMAP_H */