Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-11 08:27:02

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