Skip to content

Commit eabd804

Browse files
committed
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 (cherry picked from commit cd4bd97)
1 parent ba501a5 commit eabd804

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

share/man/man9/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ MLINKS+=bitset.9 BITSET_DEFINE.9 \
633633
bitset.9 BIT_CMP.9 \
634634
bitset.9 BIT_OR.9 \
635635
bitset.9 BIT_OR2.9 \
636+
bitset.9 BIT_ORNOT.9 \
637+
bitset.9 BIT_ORNOT2.9 \
636638
bitset.9 BIT_AND.9 \
637639
bitset.9 BIT_AND2.9 \
638640
bitset.9 BIT_ANDNOT.9 \
@@ -922,6 +924,7 @@ MLINKS+=cpuset.9 CPUSET_T_INITIALIZER.9 \
922924
cpuset.9 CPU_OVERLAP.9 \
923925
cpuset.9 CPU_CMP.9 \
924926
cpuset.9 CPU_OR.9 \
927+
cpuset.9 CPU_ORNOT.9 \
925928
cpuset.9 CPU_AND.9 \
926929
cpuset.9 CPU_ANDNOT.9 \
927930
cpuset.9 CPU_CLR_ATOMIC.9 \

share/man/man9/bitset.9

+39
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
.Nm BIT_CMP ,
5252
.Nm BIT_OR ,
5353
.Nm BIT_OR2 ,
54+
.Nm BIT_ORNOT ,
55+
.Nm BIT_ORNOT2 ,
5456
.Nm BIT_AND ,
5557
.Nm BIT_AND2 ,
5658
.Nm BIT_ANDNOT ,
@@ -123,6 +125,13 @@
123125
.Fa "struct STRUCTNAME *src1"
124126
.Fa "struct STRUCTNAME *src2"
125127
.Fc
128+
.Fn BIT_ORNOT "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
129+
.Fo BIT_ORNOT2
130+
.Fa "const SETSIZE"
131+
.Fa "struct STRUCTNAME *dst"
132+
.Fa "struct STRUCTNAME *src1"
133+
.Fa "struct STRUCTNAME *src2"
134+
.Fc
126135
.Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
127136
.Fo BIT_AND2
128137
.Fa "const SETSIZE"
@@ -459,6 +468,36 @@ equivalent of the scalar:
459468
.Fa src2 . )
460469
.Pp
461470
The
471+
.Fn BIT_ORNOT
472+
macro sets bits not in
473+
.Fa src
474+
in
475+
.Fa dst .
476+
(It is the
477+
.Nm
478+
equivalent of the scalar:
479+
.Fa dst
480+
|=
481+
.Fa ~ src . )
482+
.Pp
483+
The
484+
.Fn BIT_ORNOT2
485+
macro computes
486+
.Fa src1
487+
bitwise or not
488+
.Fa src2
489+
and assigns the result to
490+
.Fa dst .
491+
(It is the
492+
.Nm
493+
equivalent of the scalar:
494+
.Fa dst
495+
=
496+
.Fa src1
497+
| ~
498+
.Fa src2 . )
499+
.Pp
500+
The
462501
.Fn BIT_AND
463502
macro clears bits absent from
464503
.Fa src

share/man/man9/cpuset.9

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
.Nm CPU_OVERLAP ,
4646
.Nm CPU_CMP ,
4747
.Nm CPU_OR ,
48+
.Nm CPU_ORNOT ,
4849
.Nm CPU_AND ,
4950
.Nm CPU_ANDNOT ,
5051
.Nm CPU_XOR ,
@@ -86,6 +87,7 @@
8687
.Ft bool
8788
.Fn CPU_CMP "cpuset_t *cpuset1" "cpuset_t *cpuset2"
8889
.Fn CPU_OR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
90+
.Fn CPU_ORNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
8991
.Fn CPU_AND "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
9092
.Fn CPU_ANDNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
9193
.Fn CPU_XOR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2"
@@ -296,6 +298,19 @@ is composed of multiple machine words,
296298
performs multiple individually atomic operations.)
297299
.Pp
298300
The
301+
.Fn CPU_ORNOT
302+
macro add CPUs not in
303+
.Fa src
304+
to
305+
.Fa dst .
306+
(It is the
307+
.Nm
308+
equivalent of the scalar:
309+
.Fa dst
310+
|=
311+
.Fa ~ src . )
312+
.Pp
313+
The
299314
.Fn CPU_AND
300315
macro removes CPUs absent from
301316
.Fa src

sys/sys/bitset.h

+14
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@
135135
(d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\
136136
} while (0)
137137

138+
#define __BIT_ORNOT(_s, d, s) do { \
139+
__size_t __i; \
140+
for (__i = 0; __i < __bitset_words((_s)); __i++) \
141+
(d)->__bits[__i] |= ~(s)->__bits[__i]; \
142+
} while (0)
143+
144+
#define __BIT_ORNOT2(_s, d, s1, s2) do { \
145+
__size_t __i; \
146+
for (__i = 0; __i < __bitset_words((_s)); __i++) \
147+
(d)->__bits[__i] = (s1)->__bits[__i] | ~(s2)->__bits[__i];\
148+
} while (0)
149+
138150
#define __BIT_AND(_s, d, s) do { \
139151
__size_t __i; \
140152
for (__i = 0; __i < __bitset_words((_s)); __i++) \
@@ -330,6 +342,8 @@
330342
#define BIT_ISSET(_s, n, p) __BIT_ISSET(_s, n, p)
331343
#define BIT_OR(_s, d, s) __BIT_OR(_s, d, s)
332344
#define BIT_OR2(_s, d, s1, s2) __BIT_OR2(_s, d, s1, s2)
345+
#define BIT_ORNOT(_s, d, s) __BIT_ORNOT(_s, d, s)
346+
#define BIT_ORNOT2(_s, d, s1, s2) __BIT_ORNOT2(_s, d, s1, s2)
333347
#define BIT_OR_ATOMIC(_s, d, s) __BIT_OR_ATOMIC(_s, d, s)
334348
#define BIT_OVERLAP(_s, p, c) __BIT_OVERLAP(_s, p, c)
335349
#define BIT_SET(_s, n, p) __BIT_SET(_s, n, p)

sys/sys/cpuset.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define CPU_OVERLAP(p, c) __BIT_OVERLAP(CPU_SETSIZE, p, c)
5757
#define CPU_CMP(p, c) __BIT_CMP(CPU_SETSIZE, p, c)
5858
#define CPU_OR(d, s1, s2) __BIT_OR2(CPU_SETSIZE, d, s1, s2)
59+
#define CPU_ORNOT(d, s1, s2) __BIT_ORNOT2(CPU_SETSIZE, d, s1, s2)
5960
#define CPU_AND(d, s1, s2) __BIT_AND2(CPU_SETSIZE, d, s1, s2)
6061
#define CPU_ANDNOT(d, s1, s2) __BIT_ANDNOT2(CPU_SETSIZE, d, s1, s2)
6162
#define CPU_XOR(d, s1, s2) __BIT_XOR2(CPU_SETSIZE, d, s1, s2)

sys/sys/domainset.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#define DOMAINSET_OVERLAP(p, c) __BIT_OVERLAP(DOMAINSET_SETSIZE, p, c)
5555
#define DOMAINSET_CMP(p, c) __BIT_CMP(DOMAINSET_SETSIZE, p, c)
5656
#define DOMAINSET_OR(d, s) __BIT_OR(DOMAINSET_SETSIZE, d, s)
57+
#define DOMAINSET_ORNOT(d, s) __BIT_ORNOT(DOMAINSET_SETSIZE, d, s)
5758
#define DOMAINSET_AND(d, s) __BIT_AND(DOMAINSET_SETSIZE, d, s)
5859
#define DOMAINSET_ANDNOT(d, s) __BIT_ANDNOT(DOMAINSET_SETSIZE, d, s)
5960
#define DOMAINSET_CLR_ATOMIC(n, p) __BIT_CLR_ATOMIC(DOMAINSET_SETSIZE, n, p)

0 commit comments

Comments
 (0)