bitset: Add ORNOT macros

Macros to ANDNOT a bitset currently exist, but there are no ORNOT
equivalents. Introduce ORNOT macros for bitset(9), cpuset(9), and
domainset(9).

Approved by:	markj (mentor)
Reviewed by:	markj
MFC after:	1 week
Sponsored by:	NIKSUN, Inc.
Differential Revision:	https://reviews.freebsd.org/D44976
This commit is contained in:
Jake Freeland 2024-04-27 19:20:34 -05:00
parent 03a39a1708
commit cd4bd9750c
6 changed files with 73 additions and 0 deletions

View file

@ -635,6 +635,8 @@ MLINKS+=bitset.9 BITSET_DEFINE.9 \
bitset.9 BIT_CMP.9 \
bitset.9 BIT_OR.9 \
bitset.9 BIT_OR2.9 \
bitset.9 BIT_ORNOT.9 \
bitset.9 BIT_ORNOT2.9 \
bitset.9 BIT_AND.9 \
bitset.9 BIT_AND2.9 \
bitset.9 BIT_ANDNOT.9 \
@ -924,6 +926,7 @@ MLINKS+=cpuset.9 CPUSET_T_INITIALIZER.9 \
cpuset.9 CPU_OVERLAP.9 \
cpuset.9 CPU_CMP.9 \
cpuset.9 CPU_OR.9 \
cpuset.9 CPU_ORNOT.9 \
cpuset.9 CPU_AND.9 \
cpuset.9 CPU_ANDNOT.9 \
cpuset.9 CPU_CLR_ATOMIC.9 \

View file

@ -51,6 +51,8 @@
.Nm BIT_CMP ,
.Nm BIT_OR ,
.Nm BIT_OR2 ,
.Nm BIT_ORNOT ,
.Nm BIT_ORNOT2 ,
.Nm BIT_AND ,
.Nm BIT_AND2 ,
.Nm BIT_ANDNOT ,
@ -123,6 +125,13 @@
.Fa "struct STRUCTNAME *src1"
.Fa "struct STRUCTNAME *src2"
.Fc
.Fn BIT_ORNOT "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
.Fo BIT_ORNOT2
.Fa "const SETSIZE"
.Fa "struct STRUCTNAME *dst"
.Fa "struct STRUCTNAME *src1"
.Fa "struct STRUCTNAME *src2"
.Fc
.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
.Fo BIT_AND2
.Fa "const SETSIZE"
@ -459,6 +468,36 @@ equivalent of the scalar:
.Fa src2 . )
.Pp
The
.Fn BIT_ORNOT
macro sets bits not in
.Fa src
in
.Fa dst .
(It is the
.Nm
equivalent of the scalar:
.Fa dst
|=
.Fa ~ src . )
.Pp
The
.Fn BIT_ORNOT2
macro computes
.Fa src1
bitwise or not
.Fa src2
and assigns the result to
.Fa dst .
(It is the
.Nm
equivalent of the scalar:
.Fa dst
=
.Fa src1
| ~
.Fa src2 . )
.Pp
The
.Fn BIT_AND
macro clears bits absent from
.Fa src

View file

@ -45,6 +45,7 @@
.Nm CPU_OVERLAP ,
.Nm CPU_CMP ,
.Nm CPU_OR ,
.Nm CPU_ORNOT ,
.Nm CPU_AND ,
.Nm CPU_ANDNOT ,
.Nm CPU_XOR ,
@ -86,6 +87,7 @@
.Ft bool
.Fn CPU_CMP "cpuset_t *cpuset1" "cpuset_t *cpuset2"
.Fn CPU_OR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
.Fn CPU_ORNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
.Fn CPU_AND "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
.Fn CPU_ANDNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
.Fn CPU_XOR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
@ -296,6 +298,19 @@ is composed of multiple machine words,
performs multiple individually atomic operations.)
.Pp
The
.Fn CPU_ORNOT
macro add CPUs not in
.Fa src
to
.Fa dst .
(It is the
.Nm
equivalent of the scalar:
.Fa dst
|=
.Fa ~ src . )
.Pp
The
.Fn CPU_AND
macro removes CPUs absent from
.Fa src

View file

@ -135,6 +135,18 @@
(d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\
} while (0)
#define __BIT_ORNOT(_s, d, s) do { \
__size_t __i; \
for (__i = 0; __i < __bitset_words((_s)); __i++) \
(d)->__bits[__i] |= ~(s)->__bits[__i]; \
} while (0)
#define __BIT_ORNOT2(_s, d, s1, s2) do { \
__size_t __i; \
for (__i = 0; __i < __bitset_words((_s)); __i++) \
(d)->__bits[__i] = (s1)->__bits[__i] | ~(s2)->__bits[__i];\
} while (0)
#define __BIT_AND(_s, d, s) do { \
__size_t __i; \
for (__i = 0; __i < __bitset_words((_s)); __i++) \
@ -330,6 +342,8 @@
#define BIT_ISSET(_s, n, p) __BIT_ISSET(_s, n, p)
#define BIT_OR(_s, d, s) __BIT_OR(_s, d, s)
#define BIT_OR2(_s, d, s1, s2) __BIT_OR2(_s, d, s1, s2)
#define BIT_ORNOT(_s, d, s) __BIT_ORNOT(_s, d, s)
#define BIT_ORNOT2(_s, d, s1, s2) __BIT_ORNOT2(_s, d, s1, s2)
#define BIT_OR_ATOMIC(_s, d, s) __BIT_OR_ATOMIC(_s, d, s)
#define BIT_OVERLAP(_s, p, c) __BIT_OVERLAP(_s, p, c)
#define BIT_SET(_s, n, p) __BIT_SET(_s, n, p)

View file

@ -56,6 +56,7 @@
#define CPU_OVERLAP(p, c) __BIT_OVERLAP(CPU_SETSIZE, p, c)
#define CPU_CMP(p, c) __BIT_CMP(CPU_SETSIZE, p, c)
#define CPU_OR(d, s1, s2) __BIT_OR2(CPU_SETSIZE, d, s1, s2)
#define CPU_ORNOT(d, s1, s2) __BIT_ORNOT2(CPU_SETSIZE, d, s1, s2)
#define CPU_AND(d, s1, s2) __BIT_AND2(CPU_SETSIZE, d, s1, s2)
#define CPU_ANDNOT(d, s1, s2) __BIT_ANDNOT2(CPU_SETSIZE, d, s1, s2)
#define CPU_XOR(d, s1, s2) __BIT_XOR2(CPU_SETSIZE, d, s1, s2)

View file

@ -54,6 +54,7 @@
#define DOMAINSET_OVERLAP(p, c) __BIT_OVERLAP(DOMAINSET_SETSIZE, p, c)
#define DOMAINSET_CMP(p, c) __BIT_CMP(DOMAINSET_SETSIZE, p, c)
#define DOMAINSET_OR(d, s) __BIT_OR(DOMAINSET_SETSIZE, d, s)
#define DOMAINSET_ORNOT(d, s) __BIT_ORNOT(DOMAINSET_SETSIZE, d, s)
#define DOMAINSET_AND(d, s) __BIT_AND(DOMAINSET_SETSIZE, d, s)
#define DOMAINSET_ANDNOT(d, s) __BIT_ANDNOT(DOMAINSET_SETSIZE, d, s)
#define DOMAINSET_CLR_ATOMIC(n, p) __BIT_CLR_ATOMIC(DOMAINSET_SETSIZE, n, p)