bitmap.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * Copyright © 2009 CNRS
  3. * Copyright © 2009-2023 Inria. All rights reserved.
  4. * Copyright © 2009-2012 Université Bordeaux
  5. * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
  6. * See COPYING in top-level directory.
  7. */
  8. /** \file
  9. * \brief The bitmap API, for use in hwloc itself.
  10. */
  11. #ifndef HWLOC_BITMAP_H
  12. #define HWLOC_BITMAP_H
  13. #include "hwloc/autogen/config.h"
  14. #include <assert.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /** \defgroup hwlocality_bitmap The bitmap API
  19. *
  20. * The ::hwloc_bitmap_t type represents a set of integers (positive or null).
  21. * A bitmap may be of infinite size (all bits are set after some point).
  22. * A bitmap may even be full if all bits are set.
  23. *
  24. * Bitmaps are used by hwloc for sets of OS processors
  25. * (which may actually be hardware threads) as by ::hwloc_cpuset_t
  26. * (a typedef for ::hwloc_bitmap_t), or sets of NUMA memory nodes
  27. * as ::hwloc_nodeset_t (also a typedef for ::hwloc_bitmap_t).
  28. * Those are used for cpuset and nodeset fields in the ::hwloc_obj structure,
  29. * see \ref hwlocality_object_sets.
  30. *
  31. * <em>Both CPU and node sets are always indexed by OS physical number.</em>
  32. * However users should usually not build CPU and node sets manually
  33. * (e.g. with hwloc_bitmap_set()).
  34. * One should rather use existing object sets and combine them with
  35. * hwloc_bitmap_or(), etc.
  36. * For instance, binding the current thread on a pair of cores may be performed with:
  37. * \code
  38. * hwloc_obj_t core1 = ... , core2 = ... ;
  39. * hwloc_bitmap_t set = hwloc_bitmap_alloc();
  40. * hwloc_bitmap_or(set, core1->cpuset, core2->cpuset);
  41. * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
  42. * hwloc_bitmap_free(set);
  43. * \endcode
  44. *
  45. * \note Most functions below return 0 on success and -1 on error.
  46. * The usual error case would be an internal failure to realloc/extend
  47. * the storage of the bitmap (\p errno would be set to \c ENOMEM).
  48. * See also \ref hwlocality_api_error_reporting.
  49. *
  50. * \note Several examples of using the bitmap API are available under the
  51. * doc/examples/ directory in the source tree.
  52. * Regression tests such as tests/hwloc/hwloc_bitmap*.c also make intensive use
  53. * of this API.
  54. * @{
  55. */
  56. /** \brief
  57. * Set of bits represented as an opaque pointer to an internal bitmap.
  58. */
  59. typedef struct hwloc_bitmap_s * hwloc_bitmap_t;
  60. /** \brief a non-modifiable ::hwloc_bitmap_t */
  61. typedef const struct hwloc_bitmap_s * hwloc_const_bitmap_t;
  62. /*
  63. * Bitmap allocation, freeing and copying.
  64. */
  65. /** \brief Allocate a new empty bitmap.
  66. *
  67. * \returns A valid bitmap or \c NULL.
  68. *
  69. * The bitmap should be freed by a corresponding call to
  70. * hwloc_bitmap_free().
  71. */
  72. HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc(void) __hwloc_attribute_malloc;
  73. /** \brief Allocate a new full bitmap.
  74. *
  75. * \returns A valid bitmap or \c NULL.
  76. *
  77. * The bitmap should be freed by a corresponding call to
  78. * hwloc_bitmap_free().
  79. */
  80. HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc_full(void) __hwloc_attribute_malloc;
  81. /** \brief Free bitmap \p bitmap.
  82. *
  83. * If \p bitmap is \c NULL, no operation is performed.
  84. */
  85. HWLOC_DECLSPEC void hwloc_bitmap_free(hwloc_bitmap_t bitmap);
  86. /** \brief Duplicate bitmap \p bitmap by allocating a new bitmap and copying \p bitmap contents.
  87. *
  88. * If \p bitmap is \c NULL, \c NULL is returned.
  89. */
  90. HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap) __hwloc_attribute_malloc;
  91. /** \brief Copy the contents of bitmap \p src into the already allocated bitmap \p dst */
  92. HWLOC_DECLSPEC int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src);
  93. /*
  94. * Bitmap/String Conversion
  95. */
  96. /** \brief Stringify a bitmap.
  97. *
  98. * Up to \p buflen characters may be written in buffer \p buf.
  99. *
  100. * If \p buflen is 0, \p buf may safely be \c NULL.
  101. *
  102. * \return the number of characters that were actually written if not truncating,
  103. * or that would have been written (not including the ending \\0).
  104. */
  105. HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
  106. /** \brief Stringify a bitmap into a newly allocated string.
  107. *
  108. * \return 0 on success, -1 on error.
  109. */
  110. HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
  111. /** \brief Parse a bitmap string and stores it in bitmap \p bitmap.
  112. *
  113. * \return 0 on success, -1 on error.
  114. */
  115. HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
  116. /** \brief Stringify a bitmap in the list format.
  117. *
  118. * Lists are comma-separated indexes or ranges.
  119. * Ranges are dash separated indexes.
  120. * The last range may not have an ending indexes if the bitmap is infinitely set.
  121. *
  122. * Up to \p buflen characters may be written in buffer \p buf.
  123. *
  124. * If \p buflen is 0, \p buf may safely be \c NULL.
  125. *
  126. * \return the number of characters that were actually written if not truncating,
  127. * or that would have been written (not including the ending \\0).
  128. */
  129. HWLOC_DECLSPEC int hwloc_bitmap_list_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
  130. /** \brief Stringify a bitmap into a newly allocated list string.
  131. *
  132. * \return 0 on success, -1 on error.
  133. */
  134. HWLOC_DECLSPEC int hwloc_bitmap_list_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
  135. /** \brief Parse a list string and stores it in bitmap \p bitmap.
  136. *
  137. * \return 0 on success, -1 on error.
  138. */
  139. HWLOC_DECLSPEC int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
  140. /** \brief Stringify a bitmap in the taskset-specific format.
  141. *
  142. * The taskset command manipulates bitmap strings that contain a single
  143. * (possible very long) hexadecimal number starting with 0x.
  144. *
  145. * Up to \p buflen characters may be written in buffer \p buf.
  146. *
  147. * If \p buflen is 0, \p buf may safely be \c NULL.
  148. *
  149. * \return the number of characters that were actually written if not truncating,
  150. * or that would have been written (not including the ending \\0).
  151. */
  152. HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
  153. /** \brief Stringify a bitmap into a newly allocated taskset-specific string.
  154. *
  155. * \return 0 on success, -1 on error.
  156. */
  157. HWLOC_DECLSPEC int hwloc_bitmap_taskset_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
  158. /** \brief Parse a taskset-specific bitmap string and stores it in bitmap \p bitmap.
  159. *
  160. * \return 0 on success, -1 on error.
  161. */
  162. HWLOC_DECLSPEC int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
  163. /*
  164. * Building bitmaps.
  165. */
  166. /** \brief Empty the bitmap \p bitmap */
  167. HWLOC_DECLSPEC void hwloc_bitmap_zero(hwloc_bitmap_t bitmap);
  168. /** \brief Fill bitmap \p bitmap with all possible indexes (even if those objects don't exist or are otherwise unavailable) */
  169. HWLOC_DECLSPEC void hwloc_bitmap_fill(hwloc_bitmap_t bitmap);
  170. /** \brief Empty the bitmap \p bitmap and add bit \p id */
  171. HWLOC_DECLSPEC int hwloc_bitmap_only(hwloc_bitmap_t bitmap, unsigned id);
  172. /** \brief Fill the bitmap \p and clear the index \p id */
  173. HWLOC_DECLSPEC int hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned id);
  174. /** \brief Setup bitmap \p bitmap from unsigned long \p mask */
  175. HWLOC_DECLSPEC int hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask);
  176. /** \brief Setup bitmap \p bitmap from unsigned long \p mask used as \p i -th subset */
  177. HWLOC_DECLSPEC int hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
  178. /** \brief Setup bitmap \p bitmap from unsigned longs \p masks used as first \p nr subsets */
  179. HWLOC_DECLSPEC int hwloc_bitmap_from_ulongs(hwloc_bitmap_t bitmap, unsigned nr, const unsigned long *masks);
  180. /*
  181. * Modifying bitmaps.
  182. */
  183. /** \brief Add index \p id in bitmap \p bitmap */
  184. HWLOC_DECLSPEC int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id);
  185. /** \brief Add indexes from \p begin to \p end in bitmap \p bitmap.
  186. *
  187. * If \p end is \c -1, the range is infinite.
  188. */
  189. HWLOC_DECLSPEC int hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
  190. /** \brief Replace \p i -th subset of bitmap \p bitmap with unsigned long \p mask */
  191. HWLOC_DECLSPEC int hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
  192. /** \brief Remove index \p id from bitmap \p bitmap */
  193. HWLOC_DECLSPEC int hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned id);
  194. /** \brief Remove indexes from \p begin to \p end in bitmap \p bitmap.
  195. *
  196. * If \p end is \c -1, the range is infinite.
  197. */
  198. HWLOC_DECLSPEC int hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
  199. /** \brief Keep a single index among those set in bitmap \p bitmap
  200. *
  201. * May be useful before binding so that the process does not
  202. * have a chance of migrating between multiple processors
  203. * in the original mask.
  204. * Instead of running the task on any PU inside the given CPU set,
  205. * the operating system scheduler will be forced to run it on a single
  206. * of these PUs.
  207. * It avoids a migration overhead and cache-line ping-pongs between PUs.
  208. *
  209. * \note This function is NOT meant to distribute multiple processes
  210. * within a single CPU set. It always return the same single bit when
  211. * called multiple times on the same input set. hwloc_distrib() may
  212. * be used for generating CPU sets to distribute multiple tasks below
  213. * a single multi-PU object.
  214. *
  215. * \note This function cannot be applied to an object set directly. It
  216. * should be applied to a copy (which may be obtained with hwloc_bitmap_dup()).
  217. */
  218. HWLOC_DECLSPEC int hwloc_bitmap_singlify(hwloc_bitmap_t bitmap);
  219. /*
  220. * Consulting bitmaps.
  221. */
  222. /** \brief Convert the beginning part of bitmap \p bitmap into unsigned long \p mask */
  223. HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  224. /** \brief Convert the \p i -th subset of bitmap \p bitmap into unsigned long mask */
  225. HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i) __hwloc_attribute_pure;
  226. /** \brief Convert the first \p nr subsets of bitmap \p bitmap into the array of \p nr unsigned long \p masks
  227. *
  228. * \p nr may be determined earlier with hwloc_bitmap_nr_ulongs().
  229. *
  230. * \return 0
  231. */
  232. HWLOC_DECLSPEC int hwloc_bitmap_to_ulongs(hwloc_const_bitmap_t bitmap, unsigned nr, unsigned long *masks);
  233. /** \brief Return the number of unsigned longs required for storing bitmap \p bitmap entirely
  234. *
  235. * This is the number of contiguous unsigned longs from the very first bit of the bitmap
  236. * (even if unset) up to the last set bit.
  237. * This is useful for knowing the \p nr parameter to pass to hwloc_bitmap_to_ulongs()
  238. * (or which calls to hwloc_bitmap_to_ith_ulong() are needed)
  239. * to entirely convert a bitmap into multiple unsigned longs.
  240. *
  241. * When called on the output of hwloc_topology_get_topology_cpuset(),
  242. * the returned number is large enough for all cpusets of the topology.
  243. *
  244. * \return the number of unsigned longs required.
  245. * \return -1 if \p bitmap is infinite.
  246. */
  247. HWLOC_DECLSPEC int hwloc_bitmap_nr_ulongs(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  248. /** \brief Test whether index \p id is part of bitmap \p bitmap.
  249. *
  250. * \return 1 if the bit at index \p id is set in bitmap \p bitmap, 0 otherwise.
  251. */
  252. HWLOC_DECLSPEC int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id) __hwloc_attribute_pure;
  253. /** \brief Test whether bitmap \p bitmap is empty
  254. *
  255. * \return 1 if bitmap is empty, 0 otherwise.
  256. */
  257. HWLOC_DECLSPEC int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  258. /** \brief Test whether bitmap \p bitmap is completely full
  259. *
  260. * \return 1 if bitmap is full, 0 otherwise.
  261. *
  262. * \note A full bitmap is always infinitely set.
  263. */
  264. HWLOC_DECLSPEC int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  265. /** \brief Compute the first index (least significant bit) in bitmap \p bitmap
  266. *
  267. * \return the first index set in \p bitmap.
  268. * \return -1 if \p bitmap is empty.
  269. */
  270. HWLOC_DECLSPEC int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  271. /** \brief Compute the next index in bitmap \p bitmap which is after index \p prev
  272. *
  273. * \return the first index set in \p bitmap if \p prev is \c -1.
  274. * \return the next index set in \p bitmap if \p prev is not \c -1.
  275. * \return -1 if no index with higher index is set in \p bitmap.
  276. */
  277. HWLOC_DECLSPEC int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
  278. /** \brief Compute the last index (most significant bit) in bitmap \p bitmap
  279. *
  280. * \return the last index set in \p bitmap.
  281. * \return -1 if \p bitmap is empty, or if \p bitmap is infinitely set.
  282. */
  283. HWLOC_DECLSPEC int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  284. /** \brief Compute the "weight" of bitmap \p bitmap (i.e., number of
  285. * indexes that are in the bitmap).
  286. *
  287. * \return the number of indexes that are in the bitmap.
  288. * \return -1 if \p bitmap is infinitely set.
  289. */
  290. HWLOC_DECLSPEC int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  291. /** \brief Compute the first unset index (least significant bit) in bitmap \p bitmap
  292. *
  293. * \return the first unset index in \p bitmap.
  294. * \return -1 if \p bitmap is full.
  295. */
  296. HWLOC_DECLSPEC int hwloc_bitmap_first_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  297. /** \brief Compute the next unset index in bitmap \p bitmap which is after index \p prev
  298. *
  299. * \return the first index unset in \p bitmap if \p prev is \c -1.
  300. * \return the next index unset in \p bitmap if \p prev is not \c -1.
  301. * \return -1 if no index with higher index is unset in \p bitmap.
  302. */
  303. HWLOC_DECLSPEC int hwloc_bitmap_next_unset(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
  304. /** \brief Compute the last unset index (most significant bit) in bitmap \p bitmap
  305. *
  306. * \return the last index unset in \p bitmap.
  307. * \return -1 if \p bitmap is full, or if \p bitmap is not infinitely set.
  308. */
  309. HWLOC_DECLSPEC int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
  310. /** \brief Loop macro iterating on bitmap \p bitmap
  311. *
  312. * The loop must start with hwloc_bitmap_foreach_begin() and end
  313. * with hwloc_bitmap_foreach_end() followed by a terminating ';'.
  314. *
  315. * \p id is the loop variable; it should be an unsigned int. The
  316. * first iteration will set \p id to the lowest index in the bitmap.
  317. * Successive iterations will iterate through, in order, all remaining
  318. * indexes set in the bitmap. To be specific: each iteration will return a
  319. * value for \p id such that hwloc_bitmap_isset(bitmap, id) is true.
  320. *
  321. * The assert prevents the loop from being infinite if the bitmap is infinitely set.
  322. *
  323. * \hideinitializer
  324. */
  325. #define hwloc_bitmap_foreach_begin(id, bitmap) \
  326. do { \
  327. assert(hwloc_bitmap_weight(bitmap) != -1); \
  328. for (id = hwloc_bitmap_first(bitmap); \
  329. (unsigned) id != (unsigned) -1; \
  330. id = hwloc_bitmap_next(bitmap, id)) {
  331. /** \brief End of loop macro iterating on a bitmap.
  332. *
  333. * Needs a terminating ';'.
  334. *
  335. * \sa hwloc_bitmap_foreach_begin()
  336. * \hideinitializer
  337. */
  338. #define hwloc_bitmap_foreach_end() \
  339. } \
  340. } while (0)
  341. /*
  342. * Combining bitmaps.
  343. */
  344. /** \brief Or bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
  345. *
  346. * \p res can be the same as \p bitmap1 or \p bitmap2
  347. */
  348. HWLOC_DECLSPEC int hwloc_bitmap_or (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
  349. /** \brief And bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
  350. *
  351. * \p res can be the same as \p bitmap1 or \p bitmap2
  352. */
  353. HWLOC_DECLSPEC int hwloc_bitmap_and (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
  354. /** \brief And bitmap \p bitmap1 and the negation of \p bitmap2 and store the result in bitmap \p res
  355. *
  356. * \p res can be the same as \p bitmap1 or \p bitmap2
  357. */
  358. HWLOC_DECLSPEC int hwloc_bitmap_andnot (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
  359. /** \brief Xor bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
  360. *
  361. * \p res can be the same as \p bitmap1 or \p bitmap2
  362. */
  363. HWLOC_DECLSPEC int hwloc_bitmap_xor (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
  364. /** \brief Negate bitmap \p bitmap and store the result in bitmap \p res
  365. *
  366. * \p res can be the same as \p bitmap
  367. */
  368. HWLOC_DECLSPEC int hwloc_bitmap_not (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap);
  369. /*
  370. * Comparing bitmaps.
  371. */
  372. /** \brief Test whether bitmaps \p bitmap1 and \p bitmap2 intersects.
  373. *
  374. * \return 1 if bitmaps intersect, 0 otherwise.
  375. *
  376. * \note The empty bitmap does not intersect any other bitmap.
  377. */
  378. HWLOC_DECLSPEC int hwloc_bitmap_intersects (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
  379. /** \brief Test whether bitmap \p sub_bitmap is part of bitmap \p super_bitmap.
  380. *
  381. * \return 1 if \p sub_bitmap is included in \p super_bitmap, 0 otherwise.
  382. *
  383. * \note The empty bitmap is considered included in any other bitmap.
  384. */
  385. HWLOC_DECLSPEC int hwloc_bitmap_isincluded (hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap) __hwloc_attribute_pure;
  386. /** \brief Test whether bitmap \p bitmap1 is equal to bitmap \p bitmap2.
  387. *
  388. * \return 1 if bitmaps are equal, 0 otherwise.
  389. */
  390. HWLOC_DECLSPEC int hwloc_bitmap_isequal (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
  391. /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 using their lowest index.
  392. *
  393. * A bitmap is considered smaller if its least significant bit is smaller.
  394. * The empty bitmap is considered higher than anything (because its least significant bit does not exist).
  395. *
  396. * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
  397. * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
  398. *
  399. * For instance comparing binary bitmaps 0011 and 0110 returns -1
  400. * (hence 0011 is considered smaller than 0110)
  401. * because least significant bit of 0011 (0001) is smaller than least significant bit of 0110 (0010).
  402. * Comparing 01001 and 00110 would also return -1 for the same reason.
  403. *
  404. * \return 0 if bitmaps are considered equal, even if they are not strictly equal.
  405. * They just need to have the same least significant bit.
  406. * For instance, comparing binary bitmaps 0010 and 0110 returns 0 because they have the same least significant bit.
  407. */
  408. HWLOC_DECLSPEC int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
  409. /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 in lexicographic order.
  410. *
  411. * Lexicographic comparison of bitmaps, starting for their highest indexes.
  412. * Compare last indexes first, then second, etc.
  413. * The empty bitmap is considered lower than anything.
  414. *
  415. * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
  416. * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
  417. * \return 0 if bitmaps are equal (contrary to hwloc_bitmap_compare_first()).
  418. *
  419. * For instance comparing binary bitmaps 0011 and 0110 returns -1
  420. * (hence 0011 is considered smaller than 0110).
  421. * Comparing 00101 and 01010 returns -1 too.
  422. *
  423. * \note This is different from the non-existing hwloc_bitmap_compare_last()
  424. * which would only compare the highest index of each bitmap.
  425. */
  426. HWLOC_DECLSPEC int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
  427. /** @} */
  428. #ifdef __cplusplus
  429. } /* extern "C" */
  430. #endif
  431. #endif /* HWLOC_BITMAP_H */