xref: /freebsd/share/man/man9/bitset.9 (revision ae4a8e52072a87bfd49d553b9b14450c626269f8)
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*ae4a8e52SRyan Libby.Dd December 31, 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 ,
63*ae4a8e52SRyan Libby.Nm BIT_TEST_SET_ATOMIC ,
64*ae4a8e52SRyan Libby.Nm BIT_TEST_CLR_ATOMIC ,
657ebf4122SConrad Meyer.Nm BIT_AND_ATOMIC ,
667ebf4122SConrad Meyer.Nm BIT_OR_ATOMIC ,
677ebf4122SConrad Meyer.Nm BIT_COPY_STORE_REL
687ebf4122SConrad Meyer.Nd bitset manipulation macros
697ebf4122SConrad Meyer.Sh SYNOPSIS
707ebf4122SConrad Meyer.In sys/_bitset.h
717ebf4122SConrad Meyer.In sys/bitset.h
727ebf4122SConrad Meyer.\"
737ebf4122SConrad Meyer.Fn BITSET_DEFINE "STRUCTNAME" "const SETSIZE"
747ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER "ARRAY_CONTENTS"
757ebf4122SConrad Meyer.Fn BITSET_FSET "N_WORDS"
767ebf4122SConrad Meyer.\"
777ebf4122SConrad Meyer.Fn BIT_CLR "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
787ebf4122SConrad Meyer.Fn BIT_COPY "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
797ebf4122SConrad Meyer.Ft bool
807ebf4122SConrad Meyer.Fn BIT_ISSET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
817ebf4122SConrad Meyer.Fn BIT_SET "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
827ebf4122SConrad Meyer.Fn BIT_ZERO "const SETSIZE" "struct STRUCTNAME *bitset"
837ebf4122SConrad Meyer.Fn BIT_FILL "const SETSIZE" "struct STRUCTNAME *bitset"
847ebf4122SConrad Meyer.Fn BIT_SETOF "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
857ebf4122SConrad Meyer.Ft bool
867ebf4122SConrad Meyer.Fn BIT_EMPTY "const SETSIZE" "struct STRUCTNAME *bitset"
877ebf4122SConrad Meyer.Ft bool
887ebf4122SConrad Meyer.Fn BIT_ISFULLSET "const SETSIZE" "struct STRUCTNAME *bitset"
8926a3bf76SD Scott Phillips.Ft long
907ebf4122SConrad Meyer.Fn BIT_FFS "const SETSIZE" "struct STRUCTNAME *bitset"
9126a3bf76SD Scott Phillips.Ft long
9226a3bf76SD Scott Phillips.Fn BIT_FFS_AT "const SETSIZE" "struct STRUCTNAME *bitset" "long start"
9326a3bf76SD Scott Phillips.Ft long
941550c622SKonstantin Belousov.Fn BIT_FLS "const SETSIZE" "struct STRUCTNAME *bitset"
9526a3bf76SD Scott Phillips.Ft long
967ebf4122SConrad Meyer.Fn BIT_COUNT "const SETSIZE" "struct STRUCTNAME *bitset"
977ebf4122SConrad Meyer.\"
987ebf4122SConrad Meyer.Ft bool
997ebf4122SConrad Meyer.Fo BIT_SUBSET
1007ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *haystack" "struct STRUCTNAME *needle"
1017ebf4122SConrad Meyer.Fc
1027ebf4122SConrad Meyer.Ft bool
1037ebf4122SConrad Meyer.Fo BIT_OVERLAP
1047ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1057ebf4122SConrad Meyer.Fc
1067ebf4122SConrad Meyer.Ft bool
1077ebf4122SConrad Meyer.Fo BIT_CMP
1087ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2"
1097ebf4122SConrad Meyer.Fc
1107ebf4122SConrad Meyer.Fn BIT_OR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
111e058e1c4SKonstantin Belousov.Fo BIT_OR2
112e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
113e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
114e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
115e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
116e058e1c4SKonstantin Belousov.Fc
1177ebf4122SConrad Meyer.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
118e058e1c4SKonstantin Belousov.Fo BIT_AND2
119e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
120e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
121e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
122e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
123e058e1c4SKonstantin Belousov.Fc
1249825eadfSRyan Libby.Fn BIT_ANDNOT "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1259825eadfSRyan Libby.Fo BIT_ANDNOT2
126e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
127e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
128e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
129e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
130e058e1c4SKonstantin Belousov.Fc
131e058e1c4SKonstantin Belousov.Fn BIT_XOR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
132e058e1c4SKonstantin Belousov.Fo BIT_XOR2
133e058e1c4SKonstantin Belousov.Fa "const SETSIZE"
134e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *dst"
135e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src1"
136e058e1c4SKonstantin Belousov.Fa "struct STRUCTNAME *src2"
137e058e1c4SKonstantin Belousov.Fc
1387ebf4122SConrad Meyer.\"
1397ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1407ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1417ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
142*ae4a8e52SRyan Libby.Ft bool
143*ae4a8e52SRyan Libby.Fn BIT_TEST_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
144*ae4a8e52SRyan Libby.Ft bool
145*ae4a8e52SRyan Libby.Fn BIT_TEST_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
1467ebf4122SConrad Meyer.\"
1477ebf4122SConrad Meyer.Fo BIT_AND_ATOMIC
1487ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1497ebf4122SConrad Meyer.Fc
1507ebf4122SConrad Meyer.Fo BIT_OR_ATOMIC
1517ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
1527ebf4122SConrad Meyer.Fc
1537ebf4122SConrad Meyer.Fo BIT_COPY_STORE_REL
1547ebf4122SConrad Meyer.Fa "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to"
1557ebf4122SConrad Meyer.Fc
1567ebf4122SConrad Meyer.Sh DESCRIPTION
1577ebf4122SConrad MeyerThe
1587ebf4122SConrad Meyer.Nm
1597ebf4122SConrad Meyerfamily of macros provide a flexible and efficient bitset implementation if the
1607ebf4122SConrad Meyermaximum size of the set is known at compilation.
1617ebf4122SConrad MeyerThroughout this manual page, the name
1627ebf4122SConrad Meyer.Fa SETSIZE
1637ebf4122SConrad Meyerrefers to the size of the bitset in bits.
1647ebf4122SConrad MeyerIndividual bits in bitsets are referenced with indices zero through
1657ebf4122SConrad Meyer.Fa SETSIZE - 1 .
1667ebf4122SConrad MeyerOne example use of
1677ebf4122SConrad Meyer.In sys/bitset.h
1687ebf4122SConrad Meyeris
1697ebf4122SConrad Meyer.In sys/cpuset.h .
1707ebf4122SConrad Meyer.Pp
1717ebf4122SConrad MeyerThe
1727ebf4122SConrad Meyer.Fn BITSET_DEFINE
1737ebf4122SConrad Meyermacro defines a bitset struct
1747ebf4122SConrad Meyer.Fa STRUCTNAME
1757ebf4122SConrad Meyerwith room to represent
1767ebf4122SConrad Meyer.Fa SETSIZE
1777ebf4122SConrad Meyerbits.
1787ebf4122SConrad Meyer.Pp
1797ebf4122SConrad MeyerThe
1807ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1817ebf4122SConrad Meyermacro allows one to initialize a bitset struct with a compile time literal
1827ebf4122SConrad Meyervalue.
1837ebf4122SConrad Meyer.Pp
1847ebf4122SConrad MeyerThe
1857ebf4122SConrad Meyer.Fn BITSET_FSET
1867ebf4122SConrad Meyermacro generates a compile time literal, usable by
1877ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER ,
1887ebf4122SConrad Meyerrepresenting a full bitset (all bits set).
1897ebf4122SConrad MeyerFor examples of
1907ebf4122SConrad Meyer.Fn BITSET_T_INITIALIZER
1917ebf4122SConrad Meyerand
1927ebf4122SConrad Meyer.Fn BITSET_FSET
1937ebf4122SConrad Meyerusage, see the
1947ebf4122SConrad Meyer.Sx BITSET_T_INITIALIZER EXAMPLE
1957ebf4122SConrad Meyersection.
1967ebf4122SConrad MeyerThe
1977ebf4122SConrad Meyer.Fa N_WORDS
1987ebf4122SConrad Meyerparameter to
1997ebf4122SConrad Meyer.Fn BITSET_FSET
2007ebf4122SConrad Meyershould be:
2017ebf4122SConrad Meyer.Bd -literal -offset indent
2027ebf4122SConrad Meyer__bitset_words(SETSIZE)
2037ebf4122SConrad Meyer.Ed
2047ebf4122SConrad Meyer.Pp
2057ebf4122SConrad MeyerThe
2067ebf4122SConrad Meyer.Fn BIT_CLR
2077ebf4122SConrad Meyermacro clears bit
2087ebf4122SConrad Meyer.Fa bit
2097ebf4122SConrad Meyerin the bitset pointed to by
2107ebf4122SConrad Meyer.Fa bitset .
2117ebf4122SConrad MeyerThe
2127ebf4122SConrad Meyer.Fn BIT_CLR_ATOMIC
2137ebf4122SConrad Meyermacro is identical, but the bit is cleared atomically.
214*ae4a8e52SRyan LibbyThe
215*ae4a8e52SRyan Libby.Fn BIT_TEST_CLR_ATOMIC
216*ae4a8e52SRyan Libbymacro atomically clears the bit and returns whether it was set.
2177ebf4122SConrad Meyer.Pp
2187ebf4122SConrad MeyerThe
2197ebf4122SConrad Meyer.Fn BIT_COPY
2207ebf4122SConrad Meyermacro copies the contents of the bitset
2217ebf4122SConrad Meyer.Fa from
2227ebf4122SConrad Meyerto the bitset
2237ebf4122SConrad Meyer.Fa to .
2247ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2257ebf4122SConrad Meyeris similar, but copies component machine words from
2267ebf4122SConrad Meyer.Fa from
2277ebf4122SConrad Meyerand writes them to
2287ebf4122SConrad Meyer.Fa to
2297ebf4122SConrad Meyerwith atomic store with release semantics.
2307ebf4122SConrad Meyer(That is, if
2317ebf4122SConrad Meyer.Fa to
2327ebf4122SConrad Meyeris composed of multiple machine words,
2337ebf4122SConrad Meyer.Fn BIT_COPY_STORE_REL
2347ebf4122SConrad Meyerperforms multiple individually atomic operations.)
2357ebf4122SConrad Meyer.Pp
2367ebf4122SConrad MeyerThe
2377ebf4122SConrad Meyer.Fn BIT_SET
2387ebf4122SConrad Meyermacro sets bit
2397ebf4122SConrad Meyer.Fa bit
2407ebf4122SConrad Meyerin the bitset pointed to by
2417ebf4122SConrad Meyer.Fa bitset .
2427ebf4122SConrad MeyerThe
2437ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC
2447ebf4122SConrad Meyermacro is identical, but the bit is set atomically.
2457ebf4122SConrad MeyerThe
2467ebf4122SConrad Meyer.Fn BIT_SET_ATOMIC_ACQ
2477ebf4122SConrad Meyermacro sets the bit with acquire semantics.
248*ae4a8e52SRyan LibbyThe
249*ae4a8e52SRyan Libby.Fn BIT_TEST_SET_ATOMIC
250*ae4a8e52SRyan Libbymacro atomically sets the bit and returns whether it was set.
2517ebf4122SConrad Meyer.Pp
2527ebf4122SConrad MeyerThe
2537ebf4122SConrad Meyer.Fn BIT_ZERO
2547ebf4122SConrad Meyermacro clears all bits in
2557ebf4122SConrad Meyer.Fa bitset .
2567ebf4122SConrad Meyer.Pp
2577ebf4122SConrad MeyerThe
2587ebf4122SConrad Meyer.Fn BIT_FILL
2597ebf4122SConrad Meyermacro sets all bits in
2607ebf4122SConrad Meyer.Fa bitset .
2617ebf4122SConrad Meyer.Pp
2627ebf4122SConrad MeyerThe
2637ebf4122SConrad Meyer.Fn BIT_SETOF
2647ebf4122SConrad Meyermacro clears all bits in
2657ebf4122SConrad Meyer.Fa bitset
2667ebf4122SConrad Meyerbefore setting only bit
2677ebf4122SConrad Meyer.Fa bit .
2687ebf4122SConrad Meyer.Pp
2697ebf4122SConrad MeyerThe
2707ebf4122SConrad Meyer.Fn BIT_EMPTY
2717ebf4122SConrad Meyermacro returns
2727ebf4122SConrad Meyer.Dv true
2737ebf4122SConrad Meyerif
2747ebf4122SConrad Meyer.Fa bitset
2757ebf4122SConrad Meyeris empty.
2767ebf4122SConrad Meyer.Pp
2777ebf4122SConrad MeyerThe
2787ebf4122SConrad Meyer.Fn BIT_ISFULLSET
2797ebf4122SConrad Meyermacro returns
2807ebf4122SConrad Meyer.Dv true
2817ebf4122SConrad Meyerif
2827ebf4122SConrad Meyer.Fa bitset
2837ebf4122SConrad Meyeris full (all bits set).
2847ebf4122SConrad Meyer.Pp
2857ebf4122SConrad MeyerThe
2867ebf4122SConrad Meyer.Fn BIT_FFS
2877ebf4122SConrad Meyermacro returns the 1-index of the first (lowest) set bit in
2887ebf4122SConrad Meyer.Fa bitset ,
2897ebf4122SConrad Meyeror zero if
2907ebf4122SConrad Meyer.Fa bitset
2917ebf4122SConrad Meyeris empty.
2927ebf4122SConrad MeyerLike with
2937ebf4122SConrad Meyer.Xr ffs 3 ,
2947ebf4122SConrad Meyerto use the non-zero result of
2957ebf4122SConrad Meyer.Fn BIT_FFS
2967ebf4122SConrad Meyeras a
2977ebf4122SConrad Meyer.Fa bit
2987ebf4122SConrad Meyerindex parameter to any other
2997ebf4122SConrad Meyer.Nm
3007ebf4122SConrad Meyermacro, you must subtract one from the result.
3017ebf4122SConrad Meyer.Pp
3027ebf4122SConrad MeyerThe
303f8782001SD Scott Phillips.Fn BIT_FFS_AT
304f8782001SD Scott Phillipsmacro returns the 1-index of the first (lowest) set bit in
305f8782001SD Scott Phillips.Fa bitset ,
306f8782001SD Scott Phillipswhich is greater than the given 1-indexed
307f8782001SD Scott Phillips.Fa start ,
308f8782001SD Scott Phillipsor zero if no bits in
309f8782001SD Scott Phillips.Fa bitset
310f8782001SD Scott Phillipsgreater than
311f8782001SD Scott Phillips.Fa start
312f8782001SD Scott Phillipsare set.
313f8782001SD Scott Phillips.Pp
314f8782001SD Scott PhillipsThe
3151550c622SKonstantin Belousov.Fn BIT_FLS
3161550c622SKonstantin Belousovmacro returns the 1-index of the last (highest) set bit in
3171550c622SKonstantin Belousov.Fa bitset ,
3181550c622SKonstantin Belousovor zero if
3191550c622SKonstantin Belousov.Fa bitset
3201550c622SKonstantin Belousovis empty.
3211550c622SKonstantin BelousovLike with
3221550c622SKonstantin Belousov.Xr fls 3 ,
3231550c622SKonstantin Belousovto use the non-zero result of
3241550c622SKonstantin Belousov.Fn BIT_FLS
3251550c622SKonstantin Belousovas a
3261550c622SKonstantin Belousov.Fa bit
3271550c622SKonstantin Belousovindex parameter to any other
3281550c622SKonstantin Belousov.Nm
3291550c622SKonstantin Belousovmacro, you must subtract one from the result.
3301550c622SKonstantin Belousov.Pp
3311550c622SKonstantin BelousovThe
3327ebf4122SConrad Meyer.Fn BIT_COUNT
3337ebf4122SConrad Meyermacro returns the total number of set bits in
3347ebf4122SConrad Meyer.Fa bitset .
3357ebf4122SConrad Meyer.Pp
3367ebf4122SConrad MeyerThe
3377ebf4122SConrad Meyer.Fn BIT_SUBSET
3387ebf4122SConrad Meyermacro returns
3397ebf4122SConrad Meyer.Dv true
3407ebf4122SConrad Meyerif
3417ebf4122SConrad Meyer.Fa needle
3427ebf4122SConrad Meyeris a subset of
3437ebf4122SConrad Meyer.Fa haystack .
3447ebf4122SConrad Meyer.Pp
3457ebf4122SConrad MeyerThe
3467ebf4122SConrad Meyer.Fn BIT_OVERLAP
3477ebf4122SConrad Meyermacro returns
3487ebf4122SConrad Meyer.Dv true
3497ebf4122SConrad Meyerif
3507ebf4122SConrad Meyer.Fa bitset1
3517ebf4122SConrad Meyerand
3527ebf4122SConrad Meyer.Fa bitset2
3537ebf4122SConrad Meyerhave any common bits.
3547ebf4122SConrad Meyer(That is, if
3557ebf4122SConrad Meyer.Fa bitset1
3567ebf4122SConrad MeyerAND
3577ebf4122SConrad Meyer.Fa bitset2
3587ebf4122SConrad Meyeris not the empty set.)
3597ebf4122SConrad Meyer.Pp
3607ebf4122SConrad MeyerThe
3617ebf4122SConrad Meyer.Fn BIT_CMP
3627ebf4122SConrad Meyermacro returns
3637ebf4122SConrad Meyer.Dv true
3647ebf4122SConrad Meyerif
3657ebf4122SConrad Meyer.Fa bitset1
3667ebf4122SConrad Meyeris NOT equal to
3677ebf4122SConrad Meyer.Fa bitset2 .
3687ebf4122SConrad Meyer.Pp
3697ebf4122SConrad MeyerThe
3707ebf4122SConrad Meyer.Fn BIT_OR
3717ebf4122SConrad Meyermacro sets bits present in
3727ebf4122SConrad Meyer.Fa src
3737ebf4122SConrad Meyerin
3747ebf4122SConrad Meyer.Fa dst .
3757ebf4122SConrad Meyer(It is the
3767ebf4122SConrad Meyer.Nm
3777ebf4122SConrad Meyerequivalent of the scalar:
3787ebf4122SConrad Meyer.Fa dst
3797ebf4122SConrad Meyer|=
3807ebf4122SConrad Meyer.Fa src . )
3817ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3827ebf4122SConrad Meyeris similar, but sets bits in the component machine words in
3837ebf4122SConrad Meyer.Fa dst
3847ebf4122SConrad Meyeratomically.
3857ebf4122SConrad Meyer(That is, if
3867ebf4122SConrad Meyer.Fa dst
3877ebf4122SConrad Meyeris composed of multiple machine words,
3887ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC
3897ebf4122SConrad Meyerperforms multiple individually atomic operations.)
3907ebf4122SConrad Meyer.Pp
3917ebf4122SConrad MeyerThe
392e058e1c4SKonstantin Belousov.Fn BIT_OR2
393e058e1c4SKonstantin Belousovmacro computes
394e058e1c4SKonstantin Belousov.Fa src1
395e058e1c4SKonstantin Belousovbitwise or
396e058e1c4SKonstantin Belousov.Fa src2
397e058e1c4SKonstantin Belousovand assigns the result to
398e058e1c4SKonstantin Belousov.Fa dst .
399e058e1c4SKonstantin Belousov(It is the
400e058e1c4SKonstantin Belousov.Nm
401e058e1c4SKonstantin Belousovequivalent of the scalar:
402e058e1c4SKonstantin Belousov.Fa dst
403e058e1c4SKonstantin Belousov=
404e058e1c4SKonstantin Belousov.Fa src1
405e058e1c4SKonstantin Belousov|
406e058e1c4SKonstantin Belousov.Fa src2 . )
407e058e1c4SKonstantin Belousov.Pp
408e058e1c4SKonstantin BelousovThe
4097ebf4122SConrad Meyer.Fn BIT_AND
4107ebf4122SConrad Meyermacro clears bits absent from
4117ebf4122SConrad Meyer.Fa src
4127ebf4122SConrad Meyerfrom
4137ebf4122SConrad Meyer.Fa dst .
4147ebf4122SConrad Meyer(It is the
4157ebf4122SConrad Meyer.Nm
4167ebf4122SConrad Meyerequivalent of the scalar:
4177ebf4122SConrad Meyer.Fa dst
4187ebf4122SConrad Meyer&=
4197ebf4122SConrad Meyer.Fa src . )
4207ebf4122SConrad Meyer.Fn BIT_AND_ATOMIC
4217ebf4122SConrad Meyeris similar, with the same atomic semantics as
4227ebf4122SConrad Meyer.Fn BIT_OR_ATOMIC .
4237ebf4122SConrad Meyer.Pp
4247ebf4122SConrad MeyerThe
425e058e1c4SKonstantin Belousov.Fn BIT_AND2
426e058e1c4SKonstantin Belousovmacro computes
427e058e1c4SKonstantin Belousov.Fa src1
428e058e1c4SKonstantin Belousovbitwise and
429e058e1c4SKonstantin Belousov.Fa src2
430e058e1c4SKonstantin Belousovand assigns the result to
431e058e1c4SKonstantin Belousov.Fa dst .
432e058e1c4SKonstantin Belousov(It is the
433e058e1c4SKonstantin Belousov.Nm
434e058e1c4SKonstantin Belousovequivalent of the scalar:
435e058e1c4SKonstantin Belousov.Fa dst
436e058e1c4SKonstantin Belousov=
437e058e1c4SKonstantin Belousov.Fa src1
438e058e1c4SKonstantin Belousov&
439e058e1c4SKonstantin Belousov.Fa src2 . )
440e058e1c4SKonstantin Belousov.Pp
441e058e1c4SKonstantin BelousovThe
4429825eadfSRyan Libby.Fn BIT_ANDNOT
4437ebf4122SConrad Meyermacro clears bits set in
4447ebf4122SConrad Meyer.Fa src
4457ebf4122SConrad Meyerfrom
4467ebf4122SConrad Meyer.Fa dst .
4477ebf4122SConrad Meyer(It is the
4487ebf4122SConrad Meyer.Nm
4497ebf4122SConrad Meyerequivalent of the scalar:
4507ebf4122SConrad Meyer.Fa dst
4517ebf4122SConrad Meyer&=
4527ebf4122SConrad Meyer.Fa ~ src . )
453e058e1c4SKonstantin Belousov.Pp
454e058e1c4SKonstantin BelousovThe
4559825eadfSRyan Libby.Fn BIT_ANDNOT2
456e058e1c4SKonstantin Belousovmacro computes
457e058e1c4SKonstantin Belousov.Fa src1
458e058e1c4SKonstantin Belousovbitwise and not
459e058e1c4SKonstantin Belousov.Fa src2
460e058e1c4SKonstantin Belousovand assigns the result to
461e058e1c4SKonstantin Belousov.Fa dst .
462e058e1c4SKonstantin Belousov(It is the
463e058e1c4SKonstantin Belousov.Nm
464e058e1c4SKonstantin Belousovequivalent of the scalar:
465e058e1c4SKonstantin Belousov.Fa dst
466e058e1c4SKonstantin Belousov=
467e058e1c4SKonstantin Belousov.Fa src1
468e058e1c4SKonstantin Belousov& ~
469e058e1c4SKonstantin Belousov.Fa src2 . )
470e058e1c4SKonstantin Belousov.Pp
471e058e1c4SKonstantin BelousovThe
472e058e1c4SKonstantin Belousov.Fn BIT_XOR
473e058e1c4SKonstantin Belousovmacro toggles bits set in
474e058e1c4SKonstantin Belousov.Fa src
475e058e1c4SKonstantin Belousovin
476e058e1c4SKonstantin Belousov.Fa dst .
477e058e1c4SKonstantin Belousov(It is the
478e058e1c4SKonstantin Belousov.Nm
479e058e1c4SKonstantin Belousovequivalent of the scalar:
480e058e1c4SKonstantin Belousov.Fa dst
481e058e1c4SKonstantin Belousov^=
482e058e1c4SKonstantin Belousov.Fa src . )
483e058e1c4SKonstantin Belousov.Pp
484e058e1c4SKonstantin BelousovThe
485e058e1c4SKonstantin Belousov.Fn BIT_XOR2
486e058e1c4SKonstantin Belousovmacro computes
487e058e1c4SKonstantin Belousov.Fa src1
488e058e1c4SKonstantin Belousovbitwise exclusive or
489e058e1c4SKonstantin Belousov.Fa src2
490e058e1c4SKonstantin Belousovand assigns the result to
491e058e1c4SKonstantin Belousov.Fa dst .
492e058e1c4SKonstantin Belousov(It is the
493e058e1c4SKonstantin Belousov.Nm
494e058e1c4SKonstantin Belousovequivalent of the scalar:
495e058e1c4SKonstantin Belousov.Fa dst
496e058e1c4SKonstantin Belousov=
497e058e1c4SKonstantin Belousov.Fa src1
498e058e1c4SKonstantin Belousov^
499e058e1c4SKonstantin Belousov.Fa src2 . )
5007ebf4122SConrad Meyer.Sh BITSET_T_INITIALIZER EXAMPLE
5017ebf4122SConrad Meyer.Bd -literal
5027ebf4122SConrad MeyerBITSET_DEFINE(_myset, MYSETSIZE);
5037ebf4122SConrad Meyer
5047ebf4122SConrad Meyerstruct _myset myset;
5057ebf4122SConrad Meyer
5067ebf4122SConrad Meyer/* Initialize myset to filled (all bits set) */
5077ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(BITSET_FSET(__bitset_words(MYSETSIZE)));
5087ebf4122SConrad Meyer
5097ebf4122SConrad Meyer/* Initialize myset to only the lowest bit set */
5107ebf4122SConrad Meyermyset = BITSET_T_INITIALIZER(0x1);
5117ebf4122SConrad Meyer.Ed
5127ebf4122SConrad Meyer.Sh SEE ALSO
5135546be25SConrad Meyer.Xr bitstring 3 ,
5145546be25SConrad Meyer.Xr cpuset 9
5157ebf4122SConrad Meyer.Sh HISTORY
5167ebf4122SConrad MeyerThe
5177ebf4122SConrad Meyer.Nm
5187ebf4122SConrad Meyermacros first appeared in
5197ebf4122SConrad Meyer.Fx 10.0
5207ebf4122SConrad Meyerin January 2014.
5217ebf4122SConrad MeyerThey were MFCed to
5227ebf4122SConrad Meyer.Fx 9.3 ,
5237ebf4122SConrad Meyerreleased in July 2014.
5247ebf4122SConrad Meyer.Pp
5257ebf4122SConrad MeyerThis manual page first appeared in
5267ebf4122SConrad Meyer.Fx 11.0 .
5277ebf4122SConrad Meyer.Sh AUTHORS
5287ebf4122SConrad Meyer.An -nosplit
5297ebf4122SConrad MeyerThe
5307ebf4122SConrad Meyer.Nm
5315546be25SConrad Meyermacros were generalized and pulled out of
5327ebf4122SConrad Meyer.In sys/cpuset.h
5335546be25SConrad Meyeras
5347ebf4122SConrad Meyer.In sys/_bitset.h
5357ebf4122SConrad Meyerand
5367ebf4122SConrad Meyer.In sys/bitset.h
5377ebf4122SConrad Meyerby
5387ebf4122SConrad Meyer.An Attilio Rao Aq Mt attilio@FreeBSD.org .
5397ebf4122SConrad MeyerThis manual page was written by
5407ebf4122SConrad Meyer.An Conrad Meyer Aq Mt cem@FreeBSD.org .
5417ebf4122SConrad Meyer.Sh CAVEATS
5427ebf4122SConrad MeyerThe
5437ebf4122SConrad Meyer.Fa SETSIZE
5447ebf4122SConrad Meyerargument to all of these macros must match the value given to
5457ebf4122SConrad Meyer.Fn BITSET_DEFINE .
5467ebf4122SConrad Meyer.Pp
5477ebf4122SConrad MeyerUnlike every other reference to individual set members, which are zero-indexed,
548f8782001SD Scott Phillips.Fn BIT_FFS ,
549f8782001SD Scott Phillips.Fn BIT_FFS_AT
550e967aa26SKonstantin Belousovand
551e967aa26SKonstantin Belousov.Fn BIT_FLS
552e967aa26SKonstantin Belousovreturn a one-indexed result (or zero if the set is empty).
553