From owner-freebsd-hackers@freebsd.org Fri May 19 13:00:36 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 2A7C7D72E9F for ; Fri, 19 May 2017 13:00:36 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DF573155A for ; Fri, 19 May 2017 13:00:34 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dBhWC-00014v-Fu for freebsd-hackers@freebsd.org; Fri, 19 May 2017 15:00:32 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dBhWC-0005oI-7Q for freebsd-hackers@freebsd.org; Fri, 19 May 2017 15:00:32 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 99F732A003F for ; Fri, 19 May 2017 15:01:08 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ikBF_njeu4v8 for ; Fri, 19 May 2017 15:01:08 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 1480C2A160A for ; Fri, 19 May 2017 15:01:08 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id uxU_lqcAWWHy for ; Fri, 19 May 2017 15:01:08 +0200 (CEST) Received: from huber-linux.eb.localhost (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 03C392A003F for ; Fri, 19 May 2017 15:01:08 +0200 (CEST) From: Sebastian Huber To: freebsd-hackers@freebsd.org Subject: [PATCH] bitset(9): Add some operations Date: Fri, 19 May 2017 15:00:30 +0200 Message-Id: <1495198830-10573-1-git-send-email-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 1.8.4.5 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.99.2/23398/Fri May 19 10:59:52 2017) 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: Fri, 19 May 2017 13:00:36 -0000 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)) -- 1.8.4.5