17ebf4122SConrad Meyer.\" Copyright (c) 2015 Conrad Meyer <cem@FreeBSD.org> 27ebf4122SConrad Meyer.\" All rights reserved. 37ebf4122SConrad Meyer.\" 47ebf4122SConrad Meyer.\" Redistribution and use in source and binary forms, with or without 57ebf4122SConrad Meyer.\" modification, are permitted provided that the following conditions 67ebf4122SConrad Meyer.\" are met: 77ebf4122SConrad Meyer.\" 1. Redistributions of source code must retain the above copyright 87ebf4122SConrad Meyer.\" notice, this list of conditions and the following disclaimer. 97ebf4122SConrad Meyer.\" 2. Redistributions in binary form must reproduce the above copyright 107ebf4122SConrad Meyer.\" notice, this list of conditions and the following disclaimer in the 117ebf4122SConrad Meyer.\" documentation and/or other materials provided with the distribution. 127ebf4122SConrad Meyer.\" 137ebf4122SConrad Meyer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 147ebf4122SConrad Meyer.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 157ebf4122SConrad Meyer.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 167ebf4122SConrad Meyer.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE 177ebf4122SConrad Meyer.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 187ebf4122SConrad Meyer.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 197ebf4122SConrad Meyer.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 207ebf4122SConrad Meyer.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 217ebf4122SConrad Meyer.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 227ebf4122SConrad Meyer.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 237ebf4122SConrad Meyer.\" POSSIBILITY OF SUCH DAMAGE. 247ebf4122SConrad Meyer.\" 257ebf4122SConrad Meyer.\" $FreeBSD$ 267ebf4122SConrad Meyer.\" 27*e058e1c4SKonstantin Belousov.Dd May 24, 2017 287ebf4122SConrad Meyer.Dt BITSET 9 297ebf4122SConrad Meyer.Os 307ebf4122SConrad Meyer.Sh NAME 317ebf4122SConrad Meyer.Nm bitset(9) 327ebf4122SConrad Meyer\(em 337ebf4122SConrad Meyer.Nm BITSET_DEFINE , 347ebf4122SConrad Meyer.Nm BITSET_T_INITIALIZER , 357ebf4122SConrad Meyer.Nm BITSET_FSET , 367ebf4122SConrad Meyer.Nm BIT_CLR , 377ebf4122SConrad Meyer.Nm BIT_COPY , 387ebf4122SConrad Meyer.Nm BIT_ISSET , 397ebf4122SConrad Meyer.Nm BIT_SET , 407ebf4122SConrad Meyer.Nm BIT_ZERO , 417ebf4122SConrad Meyer.Nm BIT_FILL , 427ebf4122SConrad Meyer.Nm BIT_SETOF , 437ebf4122SConrad Meyer.Nm BIT_EMPTY , 447ebf4122SConrad Meyer.Nm BIT_ISFULLSET , 457ebf4122SConrad Meyer.Nm BIT_FFS , 467ebf4122SConrad Meyer.Nm BIT_COUNT , 477ebf4122SConrad Meyer.Nm BIT_SUBSET , 487ebf4122SConrad Meyer.Nm BIT_OVERLAP , 497ebf4122SConrad Meyer.Nm BIT_CMP , 507ebf4122SConrad Meyer.Nm BIT_OR , 51*e058e1c4SKonstantin Belousov.Nm BIT_OR2 , 527ebf4122SConrad Meyer.Nm BIT_AND , 53*e058e1c4SKonstantin Belousov.Nm BIT_AND2 , 547ebf4122SConrad Meyer.Nm BIT_NAND , 55*e058e1c4SKonstantin Belousov.Nm BIT_NAND2 , 56*e058e1c4SKonstantin Belousov.Nm BIT_XOR , 57*e058e1c4SKonstantin Belousov.Nm BIT_XOR2 , 587ebf4122SConrad Meyer.Nm BIT_CLR_ATOMIC , 597ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC , 607ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC_ACQ , 617ebf4122SConrad Meyer.Nm BIT_AND_ATOMIC , 627ebf4122SConrad Meyer.Nm BIT_OR_ATOMIC , 637ebf4122SConrad Meyer.Nm BIT_COPY_STORE_REL 647ebf4122SConrad Meyer.Nd bitset manipulation macros 657ebf4122SConrad Meyer.Sh SYNOPSIS 667ebf4122SConrad Meyer.In sys/_bitset.h 677ebf4122SConrad Meyer.In sys/bitset.h 687ebf4122SConrad Meyer.\" 697ebf4122SConrad Meyer.Fn BITSET_DEFINE "STRUCTNAME" "const SETSIZE" 707ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER "ARRAY_CONTENTS" 717ebf4122SConrad Meyer.Fn BITSET_FSET "N_WORDS" 727ebf4122SConrad Meyer.\" 737ebf4122SConrad Meyer.Fn BIT_CLR "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 747ebf4122SConrad Meyer.Fn BIT_COPY "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to" 757ebf4122SConrad Meyer.Ft bool 767ebf4122SConrad Meyer.Fn BIT_ISSET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 777ebf4122SConrad Meyer.Fn BIT_SET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 787ebf4122SConrad Meyer.Fn BIT_ZERO "const SETSIZE" "struct STRUCTNAME *bitset" 797ebf4122SConrad Meyer.Fn BIT_FILL "const SETSIZE" "struct STRUCTNAME *bitset" 807ebf4122SConrad Meyer.Fn BIT_SETOF "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 817ebf4122SConrad Meyer.Ft bool 827ebf4122SConrad Meyer.Fn BIT_EMPTY "const SETSIZE" "struct STRUCTNAME *bitset" 837ebf4122SConrad Meyer.Ft bool 847ebf4122SConrad Meyer.Fn BIT_ISFULLSET "const SETSIZE" "struct STRUCTNAME *bitset" 8571aa6fbfSEric van Gyzen.Ft int 867ebf4122SConrad Meyer.Fn BIT_FFS "const SETSIZE" "struct STRUCTNAME *bitset" 8771aa6fbfSEric van Gyzen.Ft int 887ebf4122SConrad Meyer.Fn BIT_COUNT "const SETSIZE" "struct STRUCTNAME *bitset" 897ebf4122SConrad Meyer.\" 907ebf4122SConrad Meyer.Ft bool 917ebf4122SConrad Meyer.Fo BIT_SUBSET 927ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *haystack" "struct STRUCTNAME *needle" 937ebf4122SConrad Meyer.Fc 947ebf4122SConrad Meyer.Ft bool 957ebf4122SConrad Meyer.Fo BIT_OVERLAP 967ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2" 977ebf4122SConrad Meyer.Fc 987ebf4122SConrad Meyer.Ft bool 997ebf4122SConrad Meyer.Fo BIT_CMP 1007ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2" 1017ebf4122SConrad Meyer.Fc 1027ebf4122SConrad Meyer.Fn BIT_OR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 103*e058e1c4SKonstantin Belousov.Fo BIT_OR2 104*e058e1c4SKonstantin Belousov.Fa "const SETSIZE" 105*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst" 106*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1" 107*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2" 108*e058e1c4SKonstantin Belousov.Fc 1097ebf4122SConrad Meyer.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 110*e058e1c4SKonstantin Belousov.Fo BIT_AND2 111*e058e1c4SKonstantin Belousov.Fa "const SETSIZE" 112*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst" 113*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1" 114*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2" 115*e058e1c4SKonstantin Belousov.Fc 1167ebf4122SConrad Meyer.Fn BIT_NAND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 117*e058e1c4SKonstantin Belousov.Fo BIT_NAND2 118*e058e1c4SKonstantin Belousov.Fa "const SETSIZE" 119*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst" 120*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1" 121*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2" 122*e058e1c4SKonstantin Belousov.Fc 123*e058e1c4SKonstantin Belousov.Fn BIT_XOR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 124*e058e1c4SKonstantin Belousov.Fo BIT_XOR2 125*e058e1c4SKonstantin Belousov.Fa "const SETSIZE" 126*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst" 127*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1" 128*e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2" 129*e058e1c4SKonstantin Belousov.Fc 1307ebf4122SConrad Meyer.\" 1317ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 1327ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 1337ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" 1347ebf4122SConrad Meyer.\" 1357ebf4122SConrad Meyer.Fo BIT_AND_ATOMIC 1367ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 1377ebf4122SConrad Meyer.Fc 1387ebf4122SConrad Meyer.Fo BIT_OR_ATOMIC 1397ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" 1407ebf4122SConrad Meyer.Fc 1417ebf4122SConrad Meyer.Fo BIT_COPY_STORE_REL 1427ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to" 1437ebf4122SConrad Meyer.Fc 1447ebf4122SConrad Meyer.Sh DESCRIPTION 1457ebf4122SConrad MeyerThe 1467ebf4122SConrad Meyer.Nm 1477ebf4122SConrad Meyerfamily of macros provide a flexible and efficient bitset implementation if the 1487ebf4122SConrad Meyermaximum size of the set is known at compilation. 1497ebf4122SConrad MeyerThroughout this manual page, the name 1507ebf4122SConrad Meyer.Fa SETSIZE 1517ebf4122SConrad Meyerrefers to the size of the bitset in bits. 1527ebf4122SConrad MeyerIndividual bits in bitsets are referenced with indices zero through 1537ebf4122SConrad Meyer.Fa SETSIZE - 1 . 1547ebf4122SConrad MeyerOne example use of 1557ebf4122SConrad Meyer.In sys/bitset.h 1567ebf4122SConrad Meyeris 1577ebf4122SConrad Meyer.In sys/cpuset.h . 1587ebf4122SConrad Meyer.Pp 1597ebf4122SConrad MeyerThe 1607ebf4122SConrad Meyer.Fn BITSET_DEFINE 1617ebf4122SConrad Meyermacro defines a bitset struct 1627ebf4122SConrad Meyer.Fa STRUCTNAME 1637ebf4122SConrad Meyerwith room to represent 1647ebf4122SConrad Meyer.Fa SETSIZE 1657ebf4122SConrad Meyerbits. 1667ebf4122SConrad Meyer.Pp 1677ebf4122SConrad MeyerThe 1687ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER 1697ebf4122SConrad Meyermacro allows one to initialize a bitset struct with a compile time literal 1707ebf4122SConrad Meyervalue. 1717ebf4122SConrad Meyer.Pp 1727ebf4122SConrad MeyerThe 1737ebf4122SConrad Meyer.Fn BITSET_FSET 1747ebf4122SConrad Meyermacro generates a compile time literal, usable by 1757ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER , 1767ebf4122SConrad Meyerrepresenting a full bitset (all bits set). 1777ebf4122SConrad MeyerFor examples of 1787ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER 1797ebf4122SConrad Meyerand 1807ebf4122SConrad Meyer.Fn BITSET_FSET 1817ebf4122SConrad Meyerusage, see the 1827ebf4122SConrad Meyer.Sx BITSET_T_INITIALIZER EXAMPLE 1837ebf4122SConrad Meyersection. 1847ebf4122SConrad MeyerThe 1857ebf4122SConrad Meyer.Fa N_WORDS 1867ebf4122SConrad Meyerparameter to 1877ebf4122SConrad Meyer.Fn BITSET_FSET 1887ebf4122SConrad Meyershould be: 1897ebf4122SConrad Meyer.Bd -literal -offset indent 1907ebf4122SConrad Meyer__bitset_words(SETSIZE) 1917ebf4122SConrad Meyer.Ed 1927ebf4122SConrad Meyer.Pp 1937ebf4122SConrad MeyerThe 1947ebf4122SConrad Meyer.Fn BIT_CLR 1957ebf4122SConrad Meyermacro clears bit 1967ebf4122SConrad Meyer.Fa bit 1977ebf4122SConrad Meyerin the bitset pointed to by 1987ebf4122SConrad Meyer.Fa bitset . 1997ebf4122SConrad MeyerThe 2007ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC 2017ebf4122SConrad Meyermacro is identical, but the bit is cleared atomically. 2027ebf4122SConrad Meyer.Pp 2037ebf4122SConrad MeyerThe 2047ebf4122SConrad Meyer.Fn BIT_COPY 2057ebf4122SConrad Meyermacro copies the contents of the bitset 2067ebf4122SConrad Meyer.Fa from 2077ebf4122SConrad Meyerto the bitset 2087ebf4122SConrad Meyer.Fa to . 2097ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL 2107ebf4122SConrad Meyeris similar, but copies component machine words from 2117ebf4122SConrad Meyer.Fa from 2127ebf4122SConrad Meyerand writes them to 2137ebf4122SConrad Meyer.Fa to 2147ebf4122SConrad Meyerwith atomic store with release semantics. 2157ebf4122SConrad Meyer(That is, if 2167ebf4122SConrad Meyer.Fa to 2177ebf4122SConrad Meyeris composed of multiple machine words, 2187ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL 2197ebf4122SConrad Meyerperforms multiple individually atomic operations.) 2207ebf4122SConrad Meyer.Pp 2217ebf4122SConrad MeyerThe 2227ebf4122SConrad Meyer.Fn BIT_SET 2237ebf4122SConrad Meyermacro sets bit 2247ebf4122SConrad Meyer.Fa bit 2257ebf4122SConrad Meyerin the bitset pointed to by 2267ebf4122SConrad Meyer.Fa bitset . 2277ebf4122SConrad MeyerThe 2287ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC 2297ebf4122SConrad Meyermacro is identical, but the bit is set atomically. 2307ebf4122SConrad MeyerThe 2317ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ 2327ebf4122SConrad Meyermacro sets the bit with acquire semantics. 2337ebf4122SConrad Meyer.Pp 2347ebf4122SConrad MeyerThe 2357ebf4122SConrad Meyer.Fn BIT_ZERO 2367ebf4122SConrad Meyermacro clears all bits in 2377ebf4122SConrad Meyer.Fa bitset . 2387ebf4122SConrad Meyer.Pp 2397ebf4122SConrad MeyerThe 2407ebf4122SConrad Meyer.Fn BIT_FILL 2417ebf4122SConrad Meyermacro sets all bits in 2427ebf4122SConrad Meyer.Fa bitset . 2437ebf4122SConrad Meyer.Pp 2447ebf4122SConrad MeyerThe 2457ebf4122SConrad Meyer.Fn BIT_SETOF 2467ebf4122SConrad Meyermacro clears all bits in 2477ebf4122SConrad Meyer.Fa bitset 2487ebf4122SConrad Meyerbefore setting only bit 2497ebf4122SConrad Meyer.Fa bit . 2507ebf4122SConrad Meyer.Pp 2517ebf4122SConrad MeyerThe 2527ebf4122SConrad Meyer.Fn BIT_EMPTY 2537ebf4122SConrad Meyermacro returns 2547ebf4122SConrad Meyer.Dv true 2557ebf4122SConrad Meyerif 2567ebf4122SConrad Meyer.Fa bitset 2577ebf4122SConrad Meyeris empty. 2587ebf4122SConrad Meyer.Pp 2597ebf4122SConrad MeyerThe 2607ebf4122SConrad Meyer.Fn BIT_ISFULLSET 2617ebf4122SConrad Meyermacro returns 2627ebf4122SConrad Meyer.Dv true 2637ebf4122SConrad Meyerif 2647ebf4122SConrad Meyer.Fa bitset 2657ebf4122SConrad Meyeris full (all bits set). 2667ebf4122SConrad Meyer.Pp 2677ebf4122SConrad MeyerThe 2687ebf4122SConrad Meyer.Fn BIT_FFS 2697ebf4122SConrad Meyermacro returns the 1-index of the first (lowest) set bit in 2707ebf4122SConrad Meyer.Fa bitset , 2717ebf4122SConrad Meyeror zero if 2727ebf4122SConrad Meyer.Fa bitset 2737ebf4122SConrad Meyeris empty. 2747ebf4122SConrad MeyerLike with 2757ebf4122SConrad Meyer.Xr ffs 3 , 2767ebf4122SConrad Meyerto use the non-zero result of 2777ebf4122SConrad Meyer.Fn BIT_FFS 2787ebf4122SConrad Meyeras a 2797ebf4122SConrad Meyer.Fa bit 2807ebf4122SConrad Meyerindex parameter to any other 2817ebf4122SConrad Meyer.Nm 2827ebf4122SConrad Meyermacro, you must subtract one from the result. 2837ebf4122SConrad Meyer.Pp 2847ebf4122SConrad MeyerThe 2857ebf4122SConrad Meyer.Fn BIT_COUNT 2867ebf4122SConrad Meyermacro returns the total number of set bits in 2877ebf4122SConrad Meyer.Fa bitset . 2887ebf4122SConrad Meyer.Pp 2897ebf4122SConrad MeyerThe 2907ebf4122SConrad Meyer.Fn BIT_SUBSET 2917ebf4122SConrad Meyermacro returns 2927ebf4122SConrad Meyer.Dv true 2937ebf4122SConrad Meyerif 2947ebf4122SConrad Meyer.Fa needle 2957ebf4122SConrad Meyeris a subset of 2967ebf4122SConrad Meyer.Fa haystack . 2977ebf4122SConrad Meyer.Pp 2987ebf4122SConrad MeyerThe 2997ebf4122SConrad Meyer.Fn BIT_OVERLAP 3007ebf4122SConrad Meyermacro returns 3017ebf4122SConrad Meyer.Dv true 3027ebf4122SConrad Meyerif 3037ebf4122SConrad Meyer.Fa bitset1 3047ebf4122SConrad Meyerand 3057ebf4122SConrad Meyer.Fa bitset2 3067ebf4122SConrad Meyerhave any common bits. 3077ebf4122SConrad Meyer(That is, if 3087ebf4122SConrad Meyer.Fa bitset1 3097ebf4122SConrad MeyerAND 3107ebf4122SConrad Meyer.Fa bitset2 3117ebf4122SConrad Meyeris not the empty set.) 3127ebf4122SConrad Meyer.Pp 3137ebf4122SConrad MeyerThe 3147ebf4122SConrad Meyer.Fn BIT_CMP 3157ebf4122SConrad Meyermacro returns 3167ebf4122SConrad Meyer.Dv true 3177ebf4122SConrad Meyerif 3187ebf4122SConrad Meyer.Fa bitset1 3197ebf4122SConrad Meyeris NOT equal to 3207ebf4122SConrad Meyer.Fa bitset2 . 3217ebf4122SConrad Meyer.Pp 3227ebf4122SConrad MeyerThe 3237ebf4122SConrad Meyer.Fn BIT_OR 3247ebf4122SConrad Meyermacro sets bits present in 3257ebf4122SConrad Meyer.Fa src 3267ebf4122SConrad Meyerin 3277ebf4122SConrad Meyer.Fa dst . 3287ebf4122SConrad Meyer(It is the 3297ebf4122SConrad Meyer.Nm 3307ebf4122SConrad Meyerequivalent of the scalar: 3317ebf4122SConrad Meyer.Fa dst 3327ebf4122SConrad Meyer|= 3337ebf4122SConrad Meyer.Fa src . ) 3347ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC 3357ebf4122SConrad Meyeris similar, but sets bits in the component machine words in 3367ebf4122SConrad Meyer.Fa dst 3377ebf4122SConrad Meyeratomically. 3387ebf4122SConrad Meyer(That is, if 3397ebf4122SConrad Meyer.Fa dst 3407ebf4122SConrad Meyeris composed of multiple machine words, 3417ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC 3427ebf4122SConrad Meyerperforms multiple individually atomic operations.) 3437ebf4122SConrad Meyer.Pp 3447ebf4122SConrad MeyerThe 345*e058e1c4SKonstantin Belousov.Fn BIT_OR2 346*e058e1c4SKonstantin Belousovmacro computes 347*e058e1c4SKonstantin Belousov.Fa src1 348*e058e1c4SKonstantin Belousovbitwise or 349*e058e1c4SKonstantin Belousov.Fa src2 350*e058e1c4SKonstantin Belousovand assigns the result to 351*e058e1c4SKonstantin Belousov.Fa dst . 352*e058e1c4SKonstantin Belousov(It is the 353*e058e1c4SKonstantin Belousov.Nm 354*e058e1c4SKonstantin Belousovequivalent of the scalar: 355*e058e1c4SKonstantin Belousov.Fa dst 356*e058e1c4SKonstantin Belousov= 357*e058e1c4SKonstantin Belousov.Fa src1 358*e058e1c4SKonstantin Belousov| 359*e058e1c4SKonstantin Belousov.Fa src2 . ) 360*e058e1c4SKonstantin Belousov.Pp 361*e058e1c4SKonstantin BelousovThe 3627ebf4122SConrad Meyer.Fn BIT_AND 3637ebf4122SConrad Meyermacro clears bits absent from 3647ebf4122SConrad Meyer.Fa src 3657ebf4122SConrad Meyerfrom 3667ebf4122SConrad Meyer.Fa dst . 3677ebf4122SConrad Meyer(It is the 3687ebf4122SConrad Meyer.Nm 3697ebf4122SConrad Meyerequivalent of the scalar: 3707ebf4122SConrad Meyer.Fa dst 3717ebf4122SConrad Meyer&= 3727ebf4122SConrad Meyer.Fa src . ) 3737ebf4122SConrad Meyer.Fn BIT_AND_ATOMIC 3747ebf4122SConrad Meyeris similar, with the same atomic semantics as 3757ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC . 3767ebf4122SConrad Meyer.Pp 3777ebf4122SConrad MeyerThe 378*e058e1c4SKonstantin Belousov.Fn BIT_AND2 379*e058e1c4SKonstantin Belousovmacro computes 380*e058e1c4SKonstantin Belousov.Fa src1 381*e058e1c4SKonstantin Belousovbitwise and 382*e058e1c4SKonstantin Belousov.Fa src2 383*e058e1c4SKonstantin Belousovand assigns the result to 384*e058e1c4SKonstantin Belousov.Fa dst . 385*e058e1c4SKonstantin Belousov(It is the 386*e058e1c4SKonstantin Belousov.Nm 387*e058e1c4SKonstantin Belousovequivalent of the scalar: 388*e058e1c4SKonstantin Belousov.Fa dst 389*e058e1c4SKonstantin Belousov= 390*e058e1c4SKonstantin Belousov.Fa src1 391*e058e1c4SKonstantin Belousov& 392*e058e1c4SKonstantin Belousov.Fa src2 . ) 393*e058e1c4SKonstantin Belousov.Pp 394*e058e1c4SKonstantin BelousovThe 3957ebf4122SConrad Meyer.Fn BIT_NAND 3967ebf4122SConrad Meyermacro clears bits set in 3977ebf4122SConrad Meyer.Fa src 3987ebf4122SConrad Meyerfrom 3997ebf4122SConrad Meyer.Fa dst . 4007ebf4122SConrad Meyer(It is the 4017ebf4122SConrad Meyer.Nm 4027ebf4122SConrad Meyerequivalent of the scalar: 4037ebf4122SConrad Meyer.Fa dst 4047ebf4122SConrad Meyer&= 4057ebf4122SConrad Meyer.Fa ~ src . ) 406*e058e1c4SKonstantin Belousov.Pp 407*e058e1c4SKonstantin BelousovThe 408*e058e1c4SKonstantin Belousov.Fn BIT_NAND2 409*e058e1c4SKonstantin Belousovmacro computes 410*e058e1c4SKonstantin Belousov.Fa src1 411*e058e1c4SKonstantin Belousovbitwise and not 412*e058e1c4SKonstantin Belousov.Fa src2 413*e058e1c4SKonstantin Belousovand assigns the result to 414*e058e1c4SKonstantin Belousov.Fa dst . 415*e058e1c4SKonstantin Belousov(It is the 416*e058e1c4SKonstantin Belousov.Nm 417*e058e1c4SKonstantin Belousovequivalent of the scalar: 418*e058e1c4SKonstantin Belousov.Fa dst 419*e058e1c4SKonstantin Belousov= 420*e058e1c4SKonstantin Belousov.Fa src1 421*e058e1c4SKonstantin Belousov& ~ 422*e058e1c4SKonstantin Belousov.Fa src2 . ) 423*e058e1c4SKonstantin Belousov.Pp 424*e058e1c4SKonstantin BelousovThe 425*e058e1c4SKonstantin Belousov.Fn BIT_XOR 426*e058e1c4SKonstantin Belousovmacro toggles bits set in 427*e058e1c4SKonstantin Belousov.Fa src 428*e058e1c4SKonstantin Belousovin 429*e058e1c4SKonstantin Belousov.Fa dst . 430*e058e1c4SKonstantin Belousov(It is the 431*e058e1c4SKonstantin Belousov.Nm 432*e058e1c4SKonstantin Belousovequivalent of the scalar: 433*e058e1c4SKonstantin Belousov.Fa dst 434*e058e1c4SKonstantin Belousov^= 435*e058e1c4SKonstantin Belousov.Fa src . ) 436*e058e1c4SKonstantin Belousov.Pp 437*e058e1c4SKonstantin BelousovThe 438*e058e1c4SKonstantin Belousov.Fn BIT_XOR2 439*e058e1c4SKonstantin Belousovmacro computes 440*e058e1c4SKonstantin Belousov.Fa src1 441*e058e1c4SKonstantin Belousovbitwise exclusive or 442*e058e1c4SKonstantin Belousov.Fa src2 443*e058e1c4SKonstantin Belousovand assigns the result to 444*e058e1c4SKonstantin Belousov.Fa dst . 445*e058e1c4SKonstantin Belousov(It is the 446*e058e1c4SKonstantin Belousov.Nm 447*e058e1c4SKonstantin Belousovequivalent of the scalar: 448*e058e1c4SKonstantin Belousov.Fa dst 449*e058e1c4SKonstantin Belousov= 450*e058e1c4SKonstantin Belousov.Fa src1 451*e058e1c4SKonstantin Belousov^ 452*e058e1c4SKonstantin Belousov.Fa src2 . ) 4537ebf4122SConrad Meyer.Sh BITSET_T_INITIALIZER EXAMPLE 4547ebf4122SConrad Meyer.Bd -literal 4557ebf4122SConrad MeyerBITSET_DEFINE(_myset, MYSETSIZE); 4567ebf4122SConrad Meyer 4577ebf4122SConrad Meyerstruct _myset myset; 4587ebf4122SConrad Meyer 4597ebf4122SConrad Meyer/* Initialize myset to filled (all bits set) */ 4607ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(BITSET_FSET(__bitset_words(MYSETSIZE))); 4617ebf4122SConrad Meyer 4627ebf4122SConrad Meyer/* Initialize myset to only the lowest bit set */ 4637ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(0x1); 4647ebf4122SConrad Meyer.Ed 4657ebf4122SConrad Meyer.Sh SEE ALSO 4665546be25SConrad Meyer.Xr bitstring 3 , 4675546be25SConrad Meyer.Xr cpuset 9 4687ebf4122SConrad Meyer.Sh HISTORY 4697ebf4122SConrad MeyerThe 4707ebf4122SConrad Meyer.Nm 4717ebf4122SConrad Meyermacros first appeared in 4727ebf4122SConrad Meyer.Fx 10.0 4737ebf4122SConrad Meyerin January 2014. 4747ebf4122SConrad MeyerThey were MFCed to 4757ebf4122SConrad Meyer.Fx 9.3 , 4767ebf4122SConrad Meyerreleased in July 2014. 4777ebf4122SConrad Meyer.Pp 4787ebf4122SConrad MeyerThis manual page first appeared in 4797ebf4122SConrad Meyer.Fx 11.0 . 4807ebf4122SConrad Meyer.Sh AUTHORS 4817ebf4122SConrad Meyer.An -nosplit 4827ebf4122SConrad MeyerThe 4837ebf4122SConrad Meyer.Nm 4845546be25SConrad Meyermacros were generalized and pulled out of 4857ebf4122SConrad Meyer.In sys/cpuset.h 4865546be25SConrad Meyeras 4877ebf4122SConrad Meyer.In sys/_bitset.h 4887ebf4122SConrad Meyerand 4897ebf4122SConrad Meyer.In sys/bitset.h 4907ebf4122SConrad Meyerby 4917ebf4122SConrad Meyer.An Attilio Rao Aq Mt attilio@FreeBSD.org . 4927ebf4122SConrad MeyerThis manual page was written by 4937ebf4122SConrad Meyer.An Conrad Meyer Aq Mt cem@FreeBSD.org . 4947ebf4122SConrad Meyer.Sh CAVEATS 4957ebf4122SConrad MeyerThe 4967ebf4122SConrad Meyer.Fa SETSIZE 4977ebf4122SConrad Meyerargument to all of these macros must match the value given to 4987ebf4122SConrad Meyer.Fn BITSET_DEFINE . 4997ebf4122SConrad Meyer.Pp 5007ebf4122SConrad MeyerUnlike every other reference to individual set members, which are zero-indexed, 5017ebf4122SConrad Meyer.Fn BIT_FFS 5027ebf4122SConrad Meyerreturns a one-indexed result (or zero if the set is empty). 503