xref: /freebsd/share/man/man9/bitset.9 (revision 26a3bf76c95f6a19edb63dca9a7f600ca01bcf23)
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.\"
27f8782001SD Scott Phillips.Dd August 25, 2020
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 ,
46f8782001SD Scott Phillips.Nm BIT_FFS_AT ,
471550c622SKonstantin Belousov.Nm BIT_FLS ,
487ebf4122SConrad Meyer.Nm BIT_COUNT ,
497ebf4122SConrad Meyer.Nm BIT_SUBSET ,
507ebf4122SConrad Meyer.Nm BIT_OVERLAP ,
517ebf4122SConrad Meyer.Nm BIT_CMP ,
527ebf4122SConrad Meyer.Nm BIT_OR ,
53e058e1c4SKonstantin Belousov.Nm BIT_OR2 ,
547ebf4122SConrad Meyer.Nm BIT_AND ,
55e058e1c4SKonstantin Belousov.Nm BIT_AND2 ,
569825eadfSRyan Libby.Nm BIT_ANDNOT ,
579825eadfSRyan Libby.Nm BIT_ANDNOT2 ,
58e058e1c4SKonstantin Belousov.Nm BIT_XOR ,
59e058e1c4SKonstantin Belousov.Nm BIT_XOR2 ,
607ebf4122SConrad Meyer.Nm BIT_CLR_ATOMIC ,
617ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC ,
627ebf4122SConrad Meyer.Nm BIT_SET_ATOMIC_ACQ ,
637ebf4122SConrad Meyer.Nm BIT_AND_ATOMIC ,
647ebf4122SConrad Meyer.Nm BIT_OR_ATOMIC ,
657ebf4122SConrad Meyer.Nm BIT_COPY_STORE_REL
667ebf4122SConrad Meyer.Nd bitset manipulation macros
677ebf4122SConrad Meyer.Sh SYNOPSIS
687ebf4122SConrad Meyer.In sys/_bitset.h
697ebf4122SConrad Meyer.In sys/bitset.h
707ebf4122SConrad Meyer.\"
717ebf4122SConrad Meyer.Fn BITSET_DEFINE "STRUCTNAME" "const SETSIZE"
727ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER "ARRAY_CONTENTS"
737ebf4122SConrad Meyer.Fn BITSET_FSET "N_WORDS"
747ebf4122SConrad Meyer.\"
757ebf4122SConrad Meyer.Fn BIT_CLR "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
767ebf4122SConrad Meyer.Fn BIT_COPY "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
777ebf4122SConrad Meyer.Ft bool
787ebf4122SConrad Meyer.Fn BIT_ISSET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
797ebf4122SConrad Meyer.Fn BIT_SET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
807ebf4122SConrad Meyer.Fn BIT_ZERO "const SETSIZE" "struct STRUCTNAME *bitset"
817ebf4122SConrad Meyer.Fn BIT_FILL "const SETSIZE" "struct STRUCTNAME *bitset"
827ebf4122SConrad Meyer.Fn BIT_SETOF "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
837ebf4122SConrad Meyer.Ft bool
847ebf4122SConrad Meyer.Fn BIT_EMPTY "const SETSIZE" "struct STRUCTNAME *bitset"
857ebf4122SConrad Meyer.Ft bool
867ebf4122SConrad Meyer.Fn BIT_ISFULLSET "const SETSIZE" "struct STRUCTNAME *bitset"
87*26a3bf76SD Scott Phillips.Ft long
887ebf4122SConrad Meyer.Fn BIT_FFS "const SETSIZE" "struct STRUCTNAME *bitset"
89*26a3bf76SD Scott Phillips.Ft long
90*26a3bf76SD Scott Phillips.Fn BIT_FFS_AT "const SETSIZE" "struct STRUCTNAME *bitset" "long start"
91*26a3bf76SD Scott Phillips.Ft long
921550c622SKonstantin Belousov.Fn BIT_FLS "const SETSIZE" "struct STRUCTNAME *bitset"
93*26a3bf76SD Scott Phillips.Ft long
947ebf4122SConrad Meyer.Fn BIT_COUNT "const SETSIZE" "struct STRUCTNAME *bitset"
957ebf4122SConrad Meyer.\"
967ebf4122SConrad Meyer.Ft bool
977ebf4122SConrad Meyer.Fo BIT_SUBSET
987ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *haystack" "struct STRUCTNAME *needle"
997ebf4122SConrad Meyer.Fc
1007ebf4122SConrad Meyer.Ft bool
1017ebf4122SConrad Meyer.Fo BIT_OVERLAP
1027ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1037ebf4122SConrad Meyer.Fc
1047ebf4122SConrad Meyer.Ft bool
1057ebf4122SConrad Meyer.Fo BIT_CMP
1067ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1077ebf4122SConrad Meyer.Fc
1087ebf4122SConrad Meyer.Fn BIT_OR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
109e058e1c4SKonstantin Belousov.Fo BIT_OR2
110e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
111e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
112e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
113e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
114e058e1c4SKonstantin Belousov.Fc
1157ebf4122SConrad Meyer.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
116e058e1c4SKonstantin Belousov.Fo BIT_AND2
117e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
118e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
119e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
120e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
121e058e1c4SKonstantin Belousov.Fc
1229825eadfSRyan Libby.Fn BIT_ANDNOT "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1239825eadfSRyan Libby.Fo BIT_ANDNOT2
124e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
125e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
126e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
127e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
128e058e1c4SKonstantin Belousov.Fc
129e058e1c4SKonstantin Belousov.Fn BIT_XOR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
130e058e1c4SKonstantin Belousov.Fo BIT_XOR2
131e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
132e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
133e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
134e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
135e058e1c4SKonstantin Belousov.Fc
1367ebf4122SConrad Meyer.\"
1377ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1387ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1397ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1407ebf4122SConrad Meyer.\"
1417ebf4122SConrad Meyer.Fo BIT_AND_ATOMIC
1427ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1437ebf4122SConrad Meyer.Fc
1447ebf4122SConrad Meyer.Fo BIT_OR_ATOMIC
1457ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1467ebf4122SConrad Meyer.Fc
1477ebf4122SConrad Meyer.Fo BIT_COPY_STORE_REL
1487ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
1497ebf4122SConrad Meyer.Fc
1507ebf4122SConrad Meyer.Sh DESCRIPTION
1517ebf4122SConrad MeyerThe
1527ebf4122SConrad Meyer.Nm
1537ebf4122SConrad Meyerfamily of macros provide a flexible and efficient bitset implementation if the
1547ebf4122SConrad Meyermaximum size of the set is known at compilation.
1557ebf4122SConrad MeyerThroughout this manual page, the name
1567ebf4122SConrad Meyer.Fa SETSIZE
1577ebf4122SConrad Meyerrefers to the size of the bitset in bits.
1587ebf4122SConrad MeyerIndividual bits in bitsets are referenced with indices zero through
1597ebf4122SConrad Meyer.Fa SETSIZE - 1 .
1607ebf4122SConrad MeyerOne example use of
1617ebf4122SConrad Meyer.In sys/bitset.h
1627ebf4122SConrad Meyeris
1637ebf4122SConrad Meyer.In sys/cpuset.h .
1647ebf4122SConrad Meyer.Pp
1657ebf4122SConrad MeyerThe
1667ebf4122SConrad Meyer.Fn BITSET_DEFINE
1677ebf4122SConrad Meyermacro defines a bitset struct
1687ebf4122SConrad Meyer.Fa STRUCTNAME
1697ebf4122SConrad Meyerwith room to represent
1707ebf4122SConrad Meyer.Fa SETSIZE
1717ebf4122SConrad Meyerbits.
1727ebf4122SConrad Meyer.Pp
1737ebf4122SConrad MeyerThe
1747ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1757ebf4122SConrad Meyermacro allows one to initialize a bitset struct with a compile time literal
1767ebf4122SConrad Meyervalue.
1777ebf4122SConrad Meyer.Pp
1787ebf4122SConrad MeyerThe
1797ebf4122SConrad Meyer.Fn BITSET_FSET
1807ebf4122SConrad Meyermacro generates a compile time literal, usable by
1817ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER ,
1827ebf4122SConrad Meyerrepresenting a full bitset (all bits set).
1837ebf4122SConrad MeyerFor examples of
1847ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1857ebf4122SConrad Meyerand
1867ebf4122SConrad Meyer.Fn BITSET_FSET
1877ebf4122SConrad Meyerusage, see the
1887ebf4122SConrad Meyer.Sx BITSET_T_INITIALIZER EXAMPLE
1897ebf4122SConrad Meyersection.
1907ebf4122SConrad MeyerThe
1917ebf4122SConrad Meyer.Fa N_WORDS
1927ebf4122SConrad Meyerparameter to
1937ebf4122SConrad Meyer.Fn BITSET_FSET
1947ebf4122SConrad Meyershould be:
1957ebf4122SConrad Meyer.Bd -literal -offset indent
1967ebf4122SConrad Meyer__bitset_words(SETSIZE)
1977ebf4122SConrad Meyer.Ed
1987ebf4122SConrad Meyer.Pp
1997ebf4122SConrad MeyerThe
2007ebf4122SConrad Meyer.Fn BIT_CLR
2017ebf4122SConrad Meyermacro clears bit
2027ebf4122SConrad Meyer.Fa bit
2037ebf4122SConrad Meyerin the bitset pointed to by
2047ebf4122SConrad Meyer.Fa bitset .
2057ebf4122SConrad MeyerThe
2067ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC
2077ebf4122SConrad Meyermacro is identical, but the bit is cleared atomically.
2087ebf4122SConrad Meyer.Pp
2097ebf4122SConrad MeyerThe
2107ebf4122SConrad Meyer.Fn BIT_COPY
2117ebf4122SConrad Meyermacro copies the contents of the bitset
2127ebf4122SConrad Meyer.Fa from
2137ebf4122SConrad Meyerto the bitset
2147ebf4122SConrad Meyer.Fa to .
2157ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2167ebf4122SConrad Meyeris similar, but copies component machine words from
2177ebf4122SConrad Meyer.Fa from
2187ebf4122SConrad Meyerand writes them to
2197ebf4122SConrad Meyer.Fa to
2207ebf4122SConrad Meyerwith atomic store with release semantics.
2217ebf4122SConrad Meyer(That is, if
2227ebf4122SConrad Meyer.Fa to
2237ebf4122SConrad Meyeris composed of multiple machine words,
2247ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2257ebf4122SConrad Meyerperforms multiple individually atomic operations.)
2267ebf4122SConrad Meyer.Pp
2277ebf4122SConrad MeyerThe
2287ebf4122SConrad Meyer.Fn BIT_SET
2297ebf4122SConrad Meyermacro sets bit
2307ebf4122SConrad Meyer.Fa bit
2317ebf4122SConrad Meyerin the bitset pointed to by
2327ebf4122SConrad Meyer.Fa bitset .
2337ebf4122SConrad MeyerThe
2347ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC
2357ebf4122SConrad Meyermacro is identical, but the bit is set atomically.
2367ebf4122SConrad MeyerThe
2377ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ
2387ebf4122SConrad Meyermacro sets the bit with acquire semantics.
2397ebf4122SConrad Meyer.Pp
2407ebf4122SConrad MeyerThe
2417ebf4122SConrad Meyer.Fn BIT_ZERO
2427ebf4122SConrad Meyermacro clears all bits in
2437ebf4122SConrad Meyer.Fa bitset .
2447ebf4122SConrad Meyer.Pp
2457ebf4122SConrad MeyerThe
2467ebf4122SConrad Meyer.Fn BIT_FILL
2477ebf4122SConrad Meyermacro sets all bits in
2487ebf4122SConrad Meyer.Fa bitset .
2497ebf4122SConrad Meyer.Pp
2507ebf4122SConrad MeyerThe
2517ebf4122SConrad Meyer.Fn BIT_SETOF
2527ebf4122SConrad Meyermacro clears all bits in
2537ebf4122SConrad Meyer.Fa bitset
2547ebf4122SConrad Meyerbefore setting only bit
2557ebf4122SConrad Meyer.Fa bit .
2567ebf4122SConrad Meyer.Pp
2577ebf4122SConrad MeyerThe
2587ebf4122SConrad Meyer.Fn BIT_EMPTY
2597ebf4122SConrad Meyermacro returns
2607ebf4122SConrad Meyer.Dv true
2617ebf4122SConrad Meyerif
2627ebf4122SConrad Meyer.Fa bitset
2637ebf4122SConrad Meyeris empty.
2647ebf4122SConrad Meyer.Pp
2657ebf4122SConrad MeyerThe
2667ebf4122SConrad Meyer.Fn BIT_ISFULLSET
2677ebf4122SConrad Meyermacro returns
2687ebf4122SConrad Meyer.Dv true
2697ebf4122SConrad Meyerif
2707ebf4122SConrad Meyer.Fa bitset
2717ebf4122SConrad Meyeris full (all bits set).
2727ebf4122SConrad Meyer.Pp
2737ebf4122SConrad MeyerThe
2747ebf4122SConrad Meyer.Fn BIT_FFS
2757ebf4122SConrad Meyermacro returns the 1-index of the first (lowest) set bit in
2767ebf4122SConrad Meyer.Fa bitset ,
2777ebf4122SConrad Meyeror zero if
2787ebf4122SConrad Meyer.Fa bitset
2797ebf4122SConrad Meyeris empty.
2807ebf4122SConrad MeyerLike with
2817ebf4122SConrad Meyer.Xr ffs 3 ,
2827ebf4122SConrad Meyerto use the non-zero result of
2837ebf4122SConrad Meyer.Fn BIT_FFS
2847ebf4122SConrad Meyeras a
2857ebf4122SConrad Meyer.Fa bit
2867ebf4122SConrad Meyerindex parameter to any other
2877ebf4122SConrad Meyer.Nm
2887ebf4122SConrad Meyermacro, you must subtract one from the result.
2897ebf4122SConrad Meyer.Pp
2907ebf4122SConrad MeyerThe
291f8782001SD Scott Phillips.Fn BIT_FFS_AT
292f8782001SD Scott Phillipsmacro returns the 1-index of the first (lowest) set bit in
293f8782001SD Scott Phillips.Fa bitset ,
294f8782001SD Scott Phillipswhich is greater than the given 1-indexed
295f8782001SD Scott Phillips.Fa start ,
296f8782001SD Scott Phillipsor zero if no bits in
297f8782001SD Scott Phillips.Fa bitset
298f8782001SD Scott Phillipsgreater than
299f8782001SD Scott Phillips.Fa start
300f8782001SD Scott Phillipsare set.
301f8782001SD Scott Phillips.Pp
302f8782001SD Scott PhillipsThe
3031550c622SKonstantin Belousov.Fn BIT_FLS
3041550c622SKonstantin Belousovmacro returns the 1-index of the last (highest) set bit in
3051550c622SKonstantin Belousov.Fa bitset ,
3061550c622SKonstantin Belousovor zero if
3071550c622SKonstantin Belousov.Fa bitset
3081550c622SKonstantin Belousovis empty.
3091550c622SKonstantin BelousovLike with
3101550c622SKonstantin Belousov.Xr fls 3 ,
3111550c622SKonstantin Belousovto use the non-zero result of
3121550c622SKonstantin Belousov.Fn BIT_FLS
3131550c622SKonstantin Belousovas a
3141550c622SKonstantin Belousov.Fa bit
3151550c622SKonstantin Belousovindex parameter to any other
3161550c622SKonstantin Belousov.Nm
3171550c622SKonstantin Belousovmacro, you must subtract one from the result.
3181550c622SKonstantin Belousov.Pp
3191550c622SKonstantin BelousovThe
3207ebf4122SConrad Meyer.Fn BIT_COUNT
3217ebf4122SConrad Meyermacro returns the total number of set bits in
3227ebf4122SConrad Meyer.Fa bitset .
3237ebf4122SConrad Meyer.Pp
3247ebf4122SConrad MeyerThe
3257ebf4122SConrad Meyer.Fn BIT_SUBSET
3267ebf4122SConrad Meyermacro returns
3277ebf4122SConrad Meyer.Dv true
3287ebf4122SConrad Meyerif
3297ebf4122SConrad Meyer.Fa needle
3307ebf4122SConrad Meyeris a subset of
3317ebf4122SConrad Meyer.Fa haystack .
3327ebf4122SConrad Meyer.Pp
3337ebf4122SConrad MeyerThe
3347ebf4122SConrad Meyer.Fn BIT_OVERLAP
3357ebf4122SConrad Meyermacro returns
3367ebf4122SConrad Meyer.Dv true
3377ebf4122SConrad Meyerif
3387ebf4122SConrad Meyer.Fa bitset1
3397ebf4122SConrad Meyerand
3407ebf4122SConrad Meyer.Fa bitset2
3417ebf4122SConrad Meyerhave any common bits.
3427ebf4122SConrad Meyer(That is, if
3437ebf4122SConrad Meyer.Fa bitset1
3447ebf4122SConrad MeyerAND
3457ebf4122SConrad Meyer.Fa bitset2
3467ebf4122SConrad Meyeris not the empty set.)
3477ebf4122SConrad Meyer.Pp
3487ebf4122SConrad MeyerThe
3497ebf4122SConrad Meyer.Fn BIT_CMP
3507ebf4122SConrad Meyermacro returns
3517ebf4122SConrad Meyer.Dv true
3527ebf4122SConrad Meyerif
3537ebf4122SConrad Meyer.Fa bitset1
3547ebf4122SConrad Meyeris NOT equal to
3557ebf4122SConrad Meyer.Fa bitset2 .
3567ebf4122SConrad Meyer.Pp
3577ebf4122SConrad MeyerThe
3587ebf4122SConrad Meyer.Fn BIT_OR
3597ebf4122SConrad Meyermacro sets bits present in
3607ebf4122SConrad Meyer.Fa src
3617ebf4122SConrad Meyerin
3627ebf4122SConrad Meyer.Fa dst .
3637ebf4122SConrad Meyer(It is the
3647ebf4122SConrad Meyer.Nm
3657ebf4122SConrad Meyerequivalent of the scalar:
3667ebf4122SConrad Meyer.Fa dst
3677ebf4122SConrad Meyer|=
3687ebf4122SConrad Meyer.Fa src . )
3697ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3707ebf4122SConrad Meyeris similar, but sets bits in the component machine words in
3717ebf4122SConrad Meyer.Fa dst
3727ebf4122SConrad Meyeratomically.
3737ebf4122SConrad Meyer(That is, if
3747ebf4122SConrad Meyer.Fa dst
3757ebf4122SConrad Meyeris composed of multiple machine words,
3767ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3777ebf4122SConrad Meyerperforms multiple individually atomic operations.)
3787ebf4122SConrad Meyer.Pp
3797ebf4122SConrad MeyerThe
380e058e1c4SKonstantin Belousov.Fn BIT_OR2
381e058e1c4SKonstantin Belousovmacro computes
382e058e1c4SKonstantin Belousov.Fa src1
383e058e1c4SKonstantin Belousovbitwise or
384e058e1c4SKonstantin Belousov.Fa src2
385e058e1c4SKonstantin Belousovand assigns the result to
386e058e1c4SKonstantin Belousov.Fa dst .
387e058e1c4SKonstantin Belousov(It is the
388e058e1c4SKonstantin Belousov.Nm
389e058e1c4SKonstantin Belousovequivalent of the scalar:
390e058e1c4SKonstantin Belousov.Fa dst
391e058e1c4SKonstantin Belousov=
392e058e1c4SKonstantin Belousov.Fa src1
393e058e1c4SKonstantin Belousov|
394e058e1c4SKonstantin Belousov.Fa src2 . )
395e058e1c4SKonstantin Belousov.Pp
396e058e1c4SKonstantin BelousovThe
3977ebf4122SConrad Meyer.Fn BIT_AND
3987ebf4122SConrad Meyermacro clears bits absent from
3997ebf4122SConrad Meyer.Fa src
4007ebf4122SConrad Meyerfrom
4017ebf4122SConrad Meyer.Fa dst .
4027ebf4122SConrad Meyer(It is the
4037ebf4122SConrad Meyer.Nm
4047ebf4122SConrad Meyerequivalent of the scalar:
4057ebf4122SConrad Meyer.Fa dst
4067ebf4122SConrad Meyer&=
4077ebf4122SConrad Meyer.Fa src . )
4087ebf4122SConrad Meyer.Fn BIT_AND_ATOMIC
4097ebf4122SConrad Meyeris similar, with the same atomic semantics as
4107ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC .
4117ebf4122SConrad Meyer.Pp
4127ebf4122SConrad MeyerThe
413e058e1c4SKonstantin Belousov.Fn BIT_AND2
414e058e1c4SKonstantin Belousovmacro computes
415e058e1c4SKonstantin Belousov.Fa src1
416e058e1c4SKonstantin Belousovbitwise and
417e058e1c4SKonstantin Belousov.Fa src2
418e058e1c4SKonstantin Belousovand assigns the result to
419e058e1c4SKonstantin Belousov.Fa dst .
420e058e1c4SKonstantin Belousov(It is the
421e058e1c4SKonstantin Belousov.Nm
422e058e1c4SKonstantin Belousovequivalent of the scalar:
423e058e1c4SKonstantin Belousov.Fa dst
424e058e1c4SKonstantin Belousov=
425e058e1c4SKonstantin Belousov.Fa src1
426e058e1c4SKonstantin Belousov&
427e058e1c4SKonstantin Belousov.Fa src2 . )
428e058e1c4SKonstantin Belousov.Pp
429e058e1c4SKonstantin BelousovThe
4309825eadfSRyan Libby.Fn BIT_ANDNOT
4317ebf4122SConrad Meyermacro clears bits set in
4327ebf4122SConrad Meyer.Fa src
4337ebf4122SConrad Meyerfrom
4347ebf4122SConrad Meyer.Fa dst .
4357ebf4122SConrad Meyer(It is the
4367ebf4122SConrad Meyer.Nm
4377ebf4122SConrad Meyerequivalent of the scalar:
4387ebf4122SConrad Meyer.Fa dst
4397ebf4122SConrad Meyer&=
4407ebf4122SConrad Meyer.Fa ~ src . )
441e058e1c4SKonstantin Belousov.Pp
442e058e1c4SKonstantin BelousovThe
4439825eadfSRyan Libby.Fn BIT_ANDNOT2
444e058e1c4SKonstantin Belousovmacro computes
445e058e1c4SKonstantin Belousov.Fa src1
446e058e1c4SKonstantin Belousovbitwise and not
447e058e1c4SKonstantin Belousov.Fa src2
448e058e1c4SKonstantin Belousovand assigns the result to
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 src1
456e058e1c4SKonstantin Belousov& ~
457e058e1c4SKonstantin Belousov.Fa src2 . )
458e058e1c4SKonstantin Belousov.Pp
459e058e1c4SKonstantin BelousovThe
460e058e1c4SKonstantin Belousov.Fn BIT_XOR
461e058e1c4SKonstantin Belousovmacro toggles bits set in
462e058e1c4SKonstantin Belousov.Fa src
463e058e1c4SKonstantin Belousovin
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 src . )
471e058e1c4SKonstantin Belousov.Pp
472e058e1c4SKonstantin BelousovThe
473e058e1c4SKonstantin Belousov.Fn BIT_XOR2
474e058e1c4SKonstantin Belousovmacro computes
475e058e1c4SKonstantin Belousov.Fa src1
476e058e1c4SKonstantin Belousovbitwise exclusive or
477e058e1c4SKonstantin Belousov.Fa src2
478e058e1c4SKonstantin Belousovand assigns the result to
479e058e1c4SKonstantin Belousov.Fa dst .
480e058e1c4SKonstantin Belousov(It is the
481e058e1c4SKonstantin Belousov.Nm
482e058e1c4SKonstantin Belousovequivalent of the scalar:
483e058e1c4SKonstantin Belousov.Fa dst
484e058e1c4SKonstantin Belousov=
485e058e1c4SKonstantin Belousov.Fa src1
486e058e1c4SKonstantin Belousov^
487e058e1c4SKonstantin Belousov.Fa src2 . )
4887ebf4122SConrad Meyer.Sh BITSET_T_INITIALIZER EXAMPLE
4897ebf4122SConrad Meyer.Bd -literal
4907ebf4122SConrad MeyerBITSET_DEFINE(_myset, MYSETSIZE);
4917ebf4122SConrad Meyer
4927ebf4122SConrad Meyerstruct _myset myset;
4937ebf4122SConrad Meyer
4947ebf4122SConrad Meyer/* Initialize myset to filled (all bits set) */
4957ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(BITSET_FSET(__bitset_words(MYSETSIZE)));
4967ebf4122SConrad Meyer
4977ebf4122SConrad Meyer/* Initialize myset to only the lowest bit set */
4987ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(0x1);
4997ebf4122SConrad Meyer.Ed
5007ebf4122SConrad Meyer.Sh SEE ALSO
5015546be25SConrad Meyer.Xr bitstring 3 ,
5025546be25SConrad Meyer.Xr cpuset 9
5037ebf4122SConrad Meyer.Sh HISTORY
5047ebf4122SConrad MeyerThe
5057ebf4122SConrad Meyer.Nm
5067ebf4122SConrad Meyermacros first appeared in
5077ebf4122SConrad Meyer.Fx 10.0
5087ebf4122SConrad Meyerin January 2014.
5097ebf4122SConrad MeyerThey were MFCed to
5107ebf4122SConrad Meyer.Fx 9.3 ,
5117ebf4122SConrad Meyerreleased in July 2014.
5127ebf4122SConrad Meyer.Pp
5137ebf4122SConrad MeyerThis manual page first appeared in
5147ebf4122SConrad Meyer.Fx 11.0 .
5157ebf4122SConrad Meyer.Sh AUTHORS
5167ebf4122SConrad Meyer.An -nosplit
5177ebf4122SConrad MeyerThe
5187ebf4122SConrad Meyer.Nm
5195546be25SConrad Meyermacros were generalized and pulled out of
5207ebf4122SConrad Meyer.In sys/cpuset.h
5215546be25SConrad Meyeras
5227ebf4122SConrad Meyer.In sys/_bitset.h
5237ebf4122SConrad Meyerand
5247ebf4122SConrad Meyer.In sys/bitset.h
5257ebf4122SConrad Meyerby
5267ebf4122SConrad Meyer.An Attilio Rao Aq Mt attilio@FreeBSD.org .
5277ebf4122SConrad MeyerThis manual page was written by
5287ebf4122SConrad Meyer.An Conrad Meyer Aq Mt cem@FreeBSD.org .
5297ebf4122SConrad Meyer.Sh CAVEATS
5307ebf4122SConrad MeyerThe
5317ebf4122SConrad Meyer.Fa SETSIZE
5327ebf4122SConrad Meyerargument to all of these macros must match the value given to
5337ebf4122SConrad Meyer.Fn BITSET_DEFINE .
5347ebf4122SConrad Meyer.Pp
5357ebf4122SConrad MeyerUnlike every other reference to individual set members, which are zero-indexed,
536f8782001SD Scott Phillips.Fn BIT_FFS ,
537f8782001SD Scott Phillips.Fn BIT_FFS_AT
538e967aa26SKonstantin Belousovand
539e967aa26SKonstantin Belousov.Fn BIT_FLS
540e967aa26SKonstantin Belousovreturn a one-indexed result (or zero if the set is empty).
541