xref: /freebsd/share/man/man9/bitset.9 (revision 1550c6223618dbcd0ff049354c7d847b90c0361f)
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*1550c622SKonstantin Belousov.Dd July 6, 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 ,
46*1550c622SKonstantin Belousov.Nm BIT_FLS ,
477ebf4122SConrad Meyer.Nm BIT_COUNT ,
487ebf4122SConrad Meyer.Nm BIT_SUBSET ,
497ebf4122SConrad Meyer.Nm BIT_OVERLAP ,
507ebf4122SConrad Meyer.Nm BIT_CMP ,
517ebf4122SConrad Meyer.Nm BIT_OR ,
52e058e1c4SKonstantin Belousov.Nm BIT_OR2 ,
537ebf4122SConrad Meyer.Nm BIT_AND ,
54e058e1c4SKonstantin Belousov.Nm BIT_AND2 ,
557ebf4122SConrad Meyer.Nm BIT_NAND ,
56e058e1c4SKonstantin Belousov.Nm BIT_NAND2 ,
57e058e1c4SKonstantin Belousov.Nm BIT_XOR ,
58e058e1c4SKonstantin Belousov.Nm BIT_XOR2 ,
597ebf4122SConrad Meyer.Nm BIT_CLR_ATOMIC ,
607ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC ,
617ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC_ACQ ,
627ebf4122SConrad Meyer.Nm BIT_AND_ATOMIC ,
637ebf4122SConrad Meyer.Nm BIT_OR_ATOMIC ,
647ebf4122SConrad Meyer.Nm BIT_COPY_STORE_REL
657ebf4122SConrad Meyer.Nd bitset manipulation macros
667ebf4122SConrad Meyer.Sh SYNOPSIS
677ebf4122SConrad Meyer.In sys/_bitset.h
687ebf4122SConrad Meyer.In sys/bitset.h
697ebf4122SConrad Meyer.\"
707ebf4122SConrad Meyer.Fn BITSET_DEFINE "STRUCTNAME" "const SETSIZE"
717ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER "ARRAY_CONTENTS"
727ebf4122SConrad Meyer.Fn BITSET_FSET "N_WORDS"
737ebf4122SConrad Meyer.\"
747ebf4122SConrad Meyer.Fn BIT_CLR "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
757ebf4122SConrad Meyer.Fn BIT_COPY "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
767ebf4122SConrad Meyer.Ft bool
777ebf4122SConrad Meyer.Fn BIT_ISSET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
787ebf4122SConrad Meyer.Fn BIT_SET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
797ebf4122SConrad Meyer.Fn BIT_ZERO "const SETSIZE" "struct STRUCTNAME *bitset"
807ebf4122SConrad Meyer.Fn BIT_FILL "const SETSIZE" "struct STRUCTNAME *bitset"
817ebf4122SConrad Meyer.Fn BIT_SETOF "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
827ebf4122SConrad Meyer.Ft bool
837ebf4122SConrad Meyer.Fn BIT_EMPTY "const SETSIZE" "struct STRUCTNAME *bitset"
847ebf4122SConrad Meyer.Ft bool
857ebf4122SConrad Meyer.Fn BIT_ISFULLSET "const SETSIZE" "struct STRUCTNAME *bitset"
8671aa6fbfSEric van Gyzen.Ft int
877ebf4122SConrad Meyer.Fn BIT_FFS "const SETSIZE" "struct STRUCTNAME *bitset"
8871aa6fbfSEric van Gyzen.Ft int
89*1550c622SKonstantin Belousov.Fn BIT_FLS "const SETSIZE" "struct STRUCTNAME *bitset"
90*1550c622SKonstantin Belousov.Ft int
917ebf4122SConrad Meyer.Fn BIT_COUNT "const SETSIZE" "struct STRUCTNAME *bitset"
927ebf4122SConrad Meyer.\"
937ebf4122SConrad Meyer.Ft bool
947ebf4122SConrad Meyer.Fo BIT_SUBSET
957ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *haystack" "struct STRUCTNAME *needle"
967ebf4122SConrad Meyer.Fc
977ebf4122SConrad Meyer.Ft bool
987ebf4122SConrad Meyer.Fo BIT_OVERLAP
997ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1007ebf4122SConrad Meyer.Fc
1017ebf4122SConrad Meyer.Ft bool
1027ebf4122SConrad Meyer.Fo BIT_CMP
1037ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1047ebf4122SConrad Meyer.Fc
1057ebf4122SConrad Meyer.Fn BIT_OR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
106e058e1c4SKonstantin Belousov.Fo BIT_OR2
107e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
108e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
109e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
110e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
111e058e1c4SKonstantin Belousov.Fc
1127ebf4122SConrad Meyer.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
113e058e1c4SKonstantin Belousov.Fo BIT_AND2
114e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
115e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
116e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
117e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
118e058e1c4SKonstantin Belousov.Fc
1197ebf4122SConrad Meyer.Fn BIT_NAND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
120e058e1c4SKonstantin Belousov.Fo BIT_NAND2
121e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
122e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
123e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
124e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
125e058e1c4SKonstantin Belousov.Fc
126e058e1c4SKonstantin Belousov.Fn BIT_XOR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
127e058e1c4SKonstantin Belousov.Fo BIT_XOR2
128e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
129e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
130e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
131e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
132e058e1c4SKonstantin Belousov.Fc
1337ebf4122SConrad Meyer.\"
1347ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1357ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1367ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1377ebf4122SConrad Meyer.\"
1387ebf4122SConrad Meyer.Fo BIT_AND_ATOMIC
1397ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1407ebf4122SConrad Meyer.Fc
1417ebf4122SConrad Meyer.Fo BIT_OR_ATOMIC
1427ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1437ebf4122SConrad Meyer.Fc
1447ebf4122SConrad Meyer.Fo BIT_COPY_STORE_REL
1457ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
1467ebf4122SConrad Meyer.Fc
1477ebf4122SConrad Meyer.Sh DESCRIPTION
1487ebf4122SConrad MeyerThe
1497ebf4122SConrad Meyer.Nm
1507ebf4122SConrad Meyerfamily of macros provide a flexible and efficient bitset implementation if the
1517ebf4122SConrad Meyermaximum size of the set is known at compilation.
1527ebf4122SConrad MeyerThroughout this manual page, the name
1537ebf4122SConrad Meyer.Fa SETSIZE
1547ebf4122SConrad Meyerrefers to the size of the bitset in bits.
1557ebf4122SConrad MeyerIndividual bits in bitsets are referenced with indices zero through
1567ebf4122SConrad Meyer.Fa SETSIZE - 1 .
1577ebf4122SConrad MeyerOne example use of
1587ebf4122SConrad Meyer.In sys/bitset.h
1597ebf4122SConrad Meyeris
1607ebf4122SConrad Meyer.In sys/cpuset.h .
1617ebf4122SConrad Meyer.Pp
1627ebf4122SConrad MeyerThe
1637ebf4122SConrad Meyer.Fn BITSET_DEFINE
1647ebf4122SConrad Meyermacro defines a bitset struct
1657ebf4122SConrad Meyer.Fa STRUCTNAME
1667ebf4122SConrad Meyerwith room to represent
1677ebf4122SConrad Meyer.Fa SETSIZE
1687ebf4122SConrad Meyerbits.
1697ebf4122SConrad Meyer.Pp
1707ebf4122SConrad MeyerThe
1717ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1727ebf4122SConrad Meyermacro allows one to initialize a bitset struct with a compile time literal
1737ebf4122SConrad Meyervalue.
1747ebf4122SConrad Meyer.Pp
1757ebf4122SConrad MeyerThe
1767ebf4122SConrad Meyer.Fn BITSET_FSET
1777ebf4122SConrad Meyermacro generates a compile time literal, usable by
1787ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER ,
1797ebf4122SConrad Meyerrepresenting a full bitset (all bits set).
1807ebf4122SConrad MeyerFor examples of
1817ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1827ebf4122SConrad Meyerand
1837ebf4122SConrad Meyer.Fn BITSET_FSET
1847ebf4122SConrad Meyerusage, see the
1857ebf4122SConrad Meyer.Sx BITSET_T_INITIALIZER EXAMPLE
1867ebf4122SConrad Meyersection.
1877ebf4122SConrad MeyerThe
1887ebf4122SConrad Meyer.Fa N_WORDS
1897ebf4122SConrad Meyerparameter to
1907ebf4122SConrad Meyer.Fn BITSET_FSET
1917ebf4122SConrad Meyershould be:
1927ebf4122SConrad Meyer.Bd -literal -offset indent
1937ebf4122SConrad Meyer__bitset_words(SETSIZE)
1947ebf4122SConrad Meyer.Ed
1957ebf4122SConrad Meyer.Pp
1967ebf4122SConrad MeyerThe
1977ebf4122SConrad Meyer.Fn BIT_CLR
1987ebf4122SConrad Meyermacro clears bit
1997ebf4122SConrad Meyer.Fa bit
2007ebf4122SConrad Meyerin the bitset pointed to by
2017ebf4122SConrad Meyer.Fa bitset .
2027ebf4122SConrad MeyerThe
2037ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC
2047ebf4122SConrad Meyermacro is identical, but the bit is cleared atomically.
2057ebf4122SConrad Meyer.Pp
2067ebf4122SConrad MeyerThe
2077ebf4122SConrad Meyer.Fn BIT_COPY
2087ebf4122SConrad Meyermacro copies the contents of the bitset
2097ebf4122SConrad Meyer.Fa from
2107ebf4122SConrad Meyerto the bitset
2117ebf4122SConrad Meyer.Fa to .
2127ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2137ebf4122SConrad Meyeris similar, but copies component machine words from
2147ebf4122SConrad Meyer.Fa from
2157ebf4122SConrad Meyerand writes them to
2167ebf4122SConrad Meyer.Fa to
2177ebf4122SConrad Meyerwith atomic store with release semantics.
2187ebf4122SConrad Meyer(That is, if
2197ebf4122SConrad Meyer.Fa to
2207ebf4122SConrad Meyeris composed of multiple machine words,
2217ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2227ebf4122SConrad Meyerperforms multiple individually atomic operations.)
2237ebf4122SConrad Meyer.Pp
2247ebf4122SConrad MeyerThe
2257ebf4122SConrad Meyer.Fn BIT_SET
2267ebf4122SConrad Meyermacro sets bit
2277ebf4122SConrad Meyer.Fa bit
2287ebf4122SConrad Meyerin the bitset pointed to by
2297ebf4122SConrad Meyer.Fa bitset .
2307ebf4122SConrad MeyerThe
2317ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC
2327ebf4122SConrad Meyermacro is identical, but the bit is set atomically.
2337ebf4122SConrad MeyerThe
2347ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ
2357ebf4122SConrad Meyermacro sets the bit with acquire semantics.
2367ebf4122SConrad Meyer.Pp
2377ebf4122SConrad MeyerThe
2387ebf4122SConrad Meyer.Fn BIT_ZERO
2397ebf4122SConrad Meyermacro clears all bits in
2407ebf4122SConrad Meyer.Fa bitset .
2417ebf4122SConrad Meyer.Pp
2427ebf4122SConrad MeyerThe
2437ebf4122SConrad Meyer.Fn BIT_FILL
2447ebf4122SConrad Meyermacro sets all bits in
2457ebf4122SConrad Meyer.Fa bitset .
2467ebf4122SConrad Meyer.Pp
2477ebf4122SConrad MeyerThe
2487ebf4122SConrad Meyer.Fn BIT_SETOF
2497ebf4122SConrad Meyermacro clears all bits in
2507ebf4122SConrad Meyer.Fa bitset
2517ebf4122SConrad Meyerbefore setting only bit
2527ebf4122SConrad Meyer.Fa bit .
2537ebf4122SConrad Meyer.Pp
2547ebf4122SConrad MeyerThe
2557ebf4122SConrad Meyer.Fn BIT_EMPTY
2567ebf4122SConrad Meyermacro returns
2577ebf4122SConrad Meyer.Dv true
2587ebf4122SConrad Meyerif
2597ebf4122SConrad Meyer.Fa bitset
2607ebf4122SConrad Meyeris empty.
2617ebf4122SConrad Meyer.Pp
2627ebf4122SConrad MeyerThe
2637ebf4122SConrad Meyer.Fn BIT_ISFULLSET
2647ebf4122SConrad Meyermacro returns
2657ebf4122SConrad Meyer.Dv true
2667ebf4122SConrad Meyerif
2677ebf4122SConrad Meyer.Fa bitset
2687ebf4122SConrad Meyeris full (all bits set).
2697ebf4122SConrad Meyer.Pp
2707ebf4122SConrad MeyerThe
2717ebf4122SConrad Meyer.Fn BIT_FFS
2727ebf4122SConrad Meyermacro returns the 1-index of the first (lowest) set bit in
2737ebf4122SConrad Meyer.Fa bitset ,
2747ebf4122SConrad Meyeror zero if
2757ebf4122SConrad Meyer.Fa bitset
2767ebf4122SConrad Meyeris empty.
2777ebf4122SConrad MeyerLike with
2787ebf4122SConrad Meyer.Xr ffs 3 ,
2797ebf4122SConrad Meyerto use the non-zero result of
2807ebf4122SConrad Meyer.Fn BIT_FFS
2817ebf4122SConrad Meyeras a
2827ebf4122SConrad Meyer.Fa bit
2837ebf4122SConrad Meyerindex parameter to any other
2847ebf4122SConrad Meyer.Nm
2857ebf4122SConrad Meyermacro, you must subtract one from the result.
2867ebf4122SConrad Meyer.Pp
2877ebf4122SConrad MeyerThe
288*1550c622SKonstantin Belousov.Fn BIT_FLS
289*1550c622SKonstantin Belousovmacro returns the 1-index of the last (highest) set bit in
290*1550c622SKonstantin Belousov.Fa bitset ,
291*1550c622SKonstantin Belousovor zero if
292*1550c622SKonstantin Belousov.Fa bitset
293*1550c622SKonstantin Belousovis empty.
294*1550c622SKonstantin BelousovLike with
295*1550c622SKonstantin Belousov.Xr fls 3 ,
296*1550c622SKonstantin Belousovto use the non-zero result of
297*1550c622SKonstantin Belousov.Fn BIT_FLS
298*1550c622SKonstantin Belousovas a
299*1550c622SKonstantin Belousov.Fa bit
300*1550c622SKonstantin Belousovindex parameter to any other
301*1550c622SKonstantin Belousov.Nm
302*1550c622SKonstantin Belousovmacro, you must subtract one from the result.
303*1550c622SKonstantin Belousov.Pp
304*1550c622SKonstantin BelousovThe
3057ebf4122SConrad Meyer.Fn BIT_COUNT
3067ebf4122SConrad Meyermacro returns the total number of set bits in
3077ebf4122SConrad Meyer.Fa bitset .
3087ebf4122SConrad Meyer.Pp
3097ebf4122SConrad MeyerThe
3107ebf4122SConrad Meyer.Fn BIT_SUBSET
3117ebf4122SConrad Meyermacro returns
3127ebf4122SConrad Meyer.Dv true
3137ebf4122SConrad Meyerif
3147ebf4122SConrad Meyer.Fa needle
3157ebf4122SConrad Meyeris a subset of
3167ebf4122SConrad Meyer.Fa haystack .
3177ebf4122SConrad Meyer.Pp
3187ebf4122SConrad MeyerThe
3197ebf4122SConrad Meyer.Fn BIT_OVERLAP
3207ebf4122SConrad Meyermacro returns
3217ebf4122SConrad Meyer.Dv true
3227ebf4122SConrad Meyerif
3237ebf4122SConrad Meyer.Fa bitset1
3247ebf4122SConrad Meyerand
3257ebf4122SConrad Meyer.Fa bitset2
3267ebf4122SConrad Meyerhave any common bits.
3277ebf4122SConrad Meyer(That is, if
3287ebf4122SConrad Meyer.Fa bitset1
3297ebf4122SConrad MeyerAND
3307ebf4122SConrad Meyer.Fa bitset2
3317ebf4122SConrad Meyeris not the empty set.)
3327ebf4122SConrad Meyer.Pp
3337ebf4122SConrad MeyerThe
3347ebf4122SConrad Meyer.Fn BIT_CMP
3357ebf4122SConrad Meyermacro returns
3367ebf4122SConrad Meyer.Dv true
3377ebf4122SConrad Meyerif
3387ebf4122SConrad Meyer.Fa bitset1
3397ebf4122SConrad Meyeris NOT equal to
3407ebf4122SConrad Meyer.Fa bitset2 .
3417ebf4122SConrad Meyer.Pp
3427ebf4122SConrad MeyerThe
3437ebf4122SConrad Meyer.Fn BIT_OR
3447ebf4122SConrad Meyermacro sets bits present in
3457ebf4122SConrad Meyer.Fa src
3467ebf4122SConrad Meyerin
3477ebf4122SConrad Meyer.Fa dst .
3487ebf4122SConrad Meyer(It is the
3497ebf4122SConrad Meyer.Nm
3507ebf4122SConrad Meyerequivalent of the scalar:
3517ebf4122SConrad Meyer.Fa dst
3527ebf4122SConrad Meyer|=
3537ebf4122SConrad Meyer.Fa src . )
3547ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3557ebf4122SConrad Meyeris similar, but sets bits in the component machine words in
3567ebf4122SConrad Meyer.Fa dst
3577ebf4122SConrad Meyeratomically.
3587ebf4122SConrad Meyer(That is, if
3597ebf4122SConrad Meyer.Fa dst
3607ebf4122SConrad Meyeris composed of multiple machine words,
3617ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3627ebf4122SConrad Meyerperforms multiple individually atomic operations.)
3637ebf4122SConrad Meyer.Pp
3647ebf4122SConrad MeyerThe
365e058e1c4SKonstantin Belousov.Fn BIT_OR2
366e058e1c4SKonstantin Belousovmacro computes
367e058e1c4SKonstantin Belousov.Fa src1
368e058e1c4SKonstantin Belousovbitwise or
369e058e1c4SKonstantin Belousov.Fa src2
370e058e1c4SKonstantin Belousovand assigns the result to
371e058e1c4SKonstantin Belousov.Fa dst .
372e058e1c4SKonstantin Belousov(It is the
373e058e1c4SKonstantin Belousov.Nm
374e058e1c4SKonstantin Belousovequivalent of the scalar:
375e058e1c4SKonstantin Belousov.Fa dst
376e058e1c4SKonstantin Belousov=
377e058e1c4SKonstantin Belousov.Fa src1
378e058e1c4SKonstantin Belousov|
379e058e1c4SKonstantin Belousov.Fa src2 . )
380e058e1c4SKonstantin Belousov.Pp
381e058e1c4SKonstantin BelousovThe
3827ebf4122SConrad Meyer.Fn BIT_AND
3837ebf4122SConrad Meyermacro clears bits absent from
3847ebf4122SConrad Meyer.Fa src
3857ebf4122SConrad Meyerfrom
3867ebf4122SConrad Meyer.Fa dst .
3877ebf4122SConrad Meyer(It is the
3887ebf4122SConrad Meyer.Nm
3897ebf4122SConrad Meyerequivalent of the scalar:
3907ebf4122SConrad Meyer.Fa dst
3917ebf4122SConrad Meyer&=
3927ebf4122SConrad Meyer.Fa src . )
3937ebf4122SConrad Meyer.Fn BIT_AND_ATOMIC
3947ebf4122SConrad Meyeris similar, with the same atomic semantics as
3957ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC .
3967ebf4122SConrad Meyer.Pp
3977ebf4122SConrad MeyerThe
398e058e1c4SKonstantin Belousov.Fn BIT_AND2
399e058e1c4SKonstantin Belousovmacro computes
400e058e1c4SKonstantin Belousov.Fa src1
401e058e1c4SKonstantin Belousovbitwise and
402e058e1c4SKonstantin Belousov.Fa src2
403e058e1c4SKonstantin Belousovand assigns the result to
404e058e1c4SKonstantin Belousov.Fa dst .
405e058e1c4SKonstantin Belousov(It is the
406e058e1c4SKonstantin Belousov.Nm
407e058e1c4SKonstantin Belousovequivalent of the scalar:
408e058e1c4SKonstantin Belousov.Fa dst
409e058e1c4SKonstantin Belousov=
410e058e1c4SKonstantin Belousov.Fa src1
411e058e1c4SKonstantin Belousov&
412e058e1c4SKonstantin Belousov.Fa src2 . )
413e058e1c4SKonstantin Belousov.Pp
414e058e1c4SKonstantin BelousovThe
4157ebf4122SConrad Meyer.Fn BIT_NAND
4167ebf4122SConrad Meyermacro clears bits set in
4177ebf4122SConrad Meyer.Fa src
4187ebf4122SConrad Meyerfrom
4197ebf4122SConrad Meyer.Fa dst .
4207ebf4122SConrad Meyer(It is the
4217ebf4122SConrad Meyer.Nm
4227ebf4122SConrad Meyerequivalent of the scalar:
4237ebf4122SConrad Meyer.Fa dst
4247ebf4122SConrad Meyer&=
4257ebf4122SConrad Meyer.Fa ~ src . )
426e058e1c4SKonstantin Belousov.Pp
427e058e1c4SKonstantin BelousovThe
428e058e1c4SKonstantin Belousov.Fn BIT_NAND2
429e058e1c4SKonstantin Belousovmacro computes
430e058e1c4SKonstantin Belousov.Fa src1
431e058e1c4SKonstantin Belousovbitwise and not
432e058e1c4SKonstantin Belousov.Fa src2
433e058e1c4SKonstantin Belousovand assigns the result to
434e058e1c4SKonstantin Belousov.Fa dst .
435e058e1c4SKonstantin Belousov(It is the
436e058e1c4SKonstantin Belousov.Nm
437e058e1c4SKonstantin Belousovequivalent of the scalar:
438e058e1c4SKonstantin Belousov.Fa dst
439e058e1c4SKonstantin Belousov=
440e058e1c4SKonstantin Belousov.Fa src1
441e058e1c4SKonstantin Belousov& ~
442e058e1c4SKonstantin Belousov.Fa src2 . )
443e058e1c4SKonstantin Belousov.Pp
444e058e1c4SKonstantin BelousovThe
445e058e1c4SKonstantin Belousov.Fn BIT_XOR
446e058e1c4SKonstantin Belousovmacro toggles bits set in
447e058e1c4SKonstantin Belousov.Fa src
448e058e1c4SKonstantin Belousovin
449e058e1c4SKonstantin Belousov.Fa dst .
450e058e1c4SKonstantin Belousov(It is the
451e058e1c4SKonstantin Belousov.Nm
452e058e1c4SKonstantin Belousovequivalent of the scalar:
453e058e1c4SKonstantin Belousov.Fa dst
454e058e1c4SKonstantin Belousov^=
455e058e1c4SKonstantin Belousov.Fa src . )
456e058e1c4SKonstantin Belousov.Pp
457e058e1c4SKonstantin BelousovThe
458e058e1c4SKonstantin Belousov.Fn BIT_XOR2
459e058e1c4SKonstantin Belousovmacro computes
460e058e1c4SKonstantin Belousov.Fa src1
461e058e1c4SKonstantin Belousovbitwise exclusive or
462e058e1c4SKonstantin Belousov.Fa src2
463e058e1c4SKonstantin Belousovand assigns the result to
464e058e1c4SKonstantin Belousov.Fa dst .
465e058e1c4SKonstantin Belousov(It is the
466e058e1c4SKonstantin Belousov.Nm
467e058e1c4SKonstantin Belousovequivalent of the scalar:
468e058e1c4SKonstantin Belousov.Fa dst
469e058e1c4SKonstantin Belousov=
470e058e1c4SKonstantin Belousov.Fa src1
471e058e1c4SKonstantin Belousov^
472e058e1c4SKonstantin Belousov.Fa src2 . )
4737ebf4122SConrad Meyer.Sh BITSET_T_INITIALIZER EXAMPLE
4747ebf4122SConrad Meyer.Bd -literal
4757ebf4122SConrad MeyerBITSET_DEFINE(_myset, MYSETSIZE);
4767ebf4122SConrad Meyer
4777ebf4122SConrad Meyerstruct _myset myset;
4787ebf4122SConrad Meyer
4797ebf4122SConrad Meyer/* Initialize myset to filled (all bits set) */
4807ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(BITSET_FSET(__bitset_words(MYSETSIZE)));
4817ebf4122SConrad Meyer
4827ebf4122SConrad Meyer/* Initialize myset to only the lowest bit set */
4837ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(0x1);
4847ebf4122SConrad Meyer.Ed
4857ebf4122SConrad Meyer.Sh SEE ALSO
4865546be25SConrad Meyer.Xr bitstring 3 ,
4875546be25SConrad Meyer.Xr cpuset 9
4887ebf4122SConrad Meyer.Sh HISTORY
4897ebf4122SConrad MeyerThe
4907ebf4122SConrad Meyer.Nm
4917ebf4122SConrad Meyermacros first appeared in
4927ebf4122SConrad Meyer.Fx 10.0
4937ebf4122SConrad Meyerin January 2014.
4947ebf4122SConrad MeyerThey were MFCed to
4957ebf4122SConrad Meyer.Fx 9.3 ,
4967ebf4122SConrad Meyerreleased in July 2014.
4977ebf4122SConrad Meyer.Pp
4987ebf4122SConrad MeyerThis manual page first appeared in
4997ebf4122SConrad Meyer.Fx 11.0 .
5007ebf4122SConrad Meyer.Sh AUTHORS
5017ebf4122SConrad Meyer.An -nosplit
5027ebf4122SConrad MeyerThe
5037ebf4122SConrad Meyer.Nm
5045546be25SConrad Meyermacros were generalized and pulled out of
5057ebf4122SConrad Meyer.In sys/cpuset.h
5065546be25SConrad Meyeras
5077ebf4122SConrad Meyer.In sys/_bitset.h
5087ebf4122SConrad Meyerand
5097ebf4122SConrad Meyer.In sys/bitset.h
5107ebf4122SConrad Meyerby
5117ebf4122SConrad Meyer.An Attilio Rao Aq Mt attilio@FreeBSD.org .
5127ebf4122SConrad MeyerThis manual page was written by
5137ebf4122SConrad Meyer.An Conrad Meyer Aq Mt cem@FreeBSD.org .
5147ebf4122SConrad Meyer.Sh CAVEATS
5157ebf4122SConrad MeyerThe
5167ebf4122SConrad Meyer.Fa SETSIZE
5177ebf4122SConrad Meyerargument to all of these macros must match the value given to
5187ebf4122SConrad Meyer.Fn BITSET_DEFINE .
5197ebf4122SConrad Meyer.Pp
5207ebf4122SConrad MeyerUnlike every other reference to individual set members, which are zero-indexed,
5217ebf4122SConrad Meyer.Fn BIT_FFS
5227ebf4122SConrad Meyerreturns a one-indexed result (or zero if the set is empty).
523