From owner-freebsd-hackers@freebsd.org Sun May 28 04:45:30 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 65FE3D85DA4 for ; Sun, 28 May 2017 04:45:30 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [IPv6:2001:470:1f05:b76::196]) by mx1.freebsd.org (Postfix) with ESMTP id 4FDFE1EAB for ; Sun, 28 May 2017 04:45:30 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from Alfreds-MacBook-Pro-2.local (unknown [IPv6:2601:645:8003:a4d6:3d60:52ca:455b:2dfc]) by elvis.mu.org (Postfix) with ESMTPSA id A70433494EF9; Sat, 27 May 2017 21:45:24 -0700 (PDT) Subject: Re: [PATCH] bitset(9): Add some operations To: Sebastian Huber , freebsd-hackers@freebsd.org References: <1495198830-10573-1-git-send-email-sebastian.huber@embedded-brains.de> From: Alfred Perlstein Organization: FreeBSD Message-ID: Date: Sat, 27 May 2017 21:45:24 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1495198830-10573-1-git-send-email-sebastian.huber@embedded-brains.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 May 2017 04:45:30 -0000 Would you consider using "3" instead of "2" as that would match what machine opcodes typically are named. ex: OR3 instead of OR2. Search for addl3 vs addl2 in this paper: http://minnie.tuhs.org/CompArch/Resources/webext3.pdf -Alfred On 5/19/17 6:00 AM, Sebastian Huber wrote: > Add BIT_OR2(), BIT_AND2(), BIT_NAND2(), BIT_XOR() and BIT_XOR2(). > --- > share/man/man9/bitset.9 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ > sys/sys/bitset.h | 30 ++++++++++++++++ > 2 files changed, 121 insertions(+) > > diff --git a/share/man/man9/bitset.9 b/share/man/man9/bitset.9 > index ef55115..4842225 100644 > --- a/share/man/man9/bitset.9 > +++ b/share/man/man9/bitset.9 > @@ -48,8 +48,13 @@ > .Nm BIT_OVERLAP , > .Nm BIT_CMP , > .Nm BIT_OR , > +.Nm BIT_OR2 , > .Nm BIT_AND , > +.Nm BIT_AND2 , > .Nm BIT_NAND , > +.Nm BIT_NAND2 , > +.Nm BIT_XOR , > +.Nm BIT_XOR2 , > .Nm BIT_CLR_ATOMIC , > .Nm BIT_SET_ATOMIC , > .Nm BIT_SET_ATOMIC_ACQ , > @@ -95,8 +100,13 @@ > .Fa "const SETSIZE" "struct STRUCTNAME *bitset1" "struct STRUCTNAME *bitset2" > .Fc > .Fn BIT_OR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" > +.Fn BIT_OR2 "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src1" "struct STRUCTNAME *src2" > .Fn BIT_AND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" > +.Fn BIT_AND2 "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src1" "struct STRUCTNAME *src2" > .Fn BIT_NAND "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" > +.Fn BIT_NAND2 "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src1" "struct STRUCTNAME *src2" > +.Fn BIT_XOR "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src" > +.Fn BIT_XOR2 "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src1" "struct STRUCTNAME *src2" > .\" > .Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" > .Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset" > @@ -312,6 +322,23 @@ is composed of multiple machine words, > performs multiple individually atomic operations.) > .Pp > The > +.Fn BIT_OR2 > +macro computes > +.Fa src1 > +bitwise or > +.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 > @@ -328,6 +355,23 @@ is similar, with the same atomic semantics as > .Fn BIT_OR_ATOMIC . > .Pp > The > +.Fn BIT_AND2 > +macro computes > +.Fa src1 > +bitwise and > +.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_NAND > macro clears bits set in > .Fa src > @@ -339,6 +383,53 @@ equivalent of the scalar: > .Fa dst > &= > .Fa ~ src . ) > +.Pp > +The > +.Fn BIT_NAND2 > +macro computes > +.Fa src1 > +bitwise and 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_XOR > +macro toggles bits set in > +.Fa src > +in > +.Fa dst . > +(It is the > +.Nm > +equivalent of the scalar: > +.Fa dst > +^= > +.Fa src . ) > +.Pp > +The > +.Fn BIT_XOR2 > +macro computes > +.Fa src1 > +bitwise exclusive or > +.Fa src2 > +and assigns the result to > +.Fa dst . > +(It is the > +.Nm > +equivalent of the scalar: > +.Fa dst > += > +.Fa src1 > +^ > +.Fa src2 . ) > .Sh BITSET_T_INITIALIZER EXAMPLE > .Bd -literal > BITSET_DEFINE(_myset, MYSETSIZE); > diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h > index 723c39b..8bc9e3d 100644 > --- a/sys/sys/bitset.h > +++ b/sys/sys/bitset.h > @@ -122,18 +122,48 @@ > (d)->__bits[__i] |= (s)->__bits[__i]; \ > } while (0) > > +#define BIT_OR2(_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++) \ > (d)->__bits[__i] &= (s)->__bits[__i]; \ > } while (0) > > +#define BIT_AND2(_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_NAND(_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_NAND2(_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_XOR(_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_XOR2(_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_CLR_ATOMIC(_s, n, p) \ > atomic_clear_long(&(p)->__bits[__bitset_word(_s, n)], \ > __bitset_mask((_s), n))