From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xenproject.org
Cc: Olaf Hering <olaf@aepfle.de>, Ian Jackson <iwj@xenproject.org>,
Wei Liu <wl@xen.org>
Subject: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
Date: Wed, 9 Dec 2020 16:54:51 +0100 [thread overview]
Message-ID: <20201209155452.28376-3-olaf@aepfle.de> (raw)
In-Reply-To: <20201209155452.28376-1-olaf@aepfle.de>
Introduce new API to test if a fixed number of bits is clear or set,
and clear or set them all at once.
The caller has to make sure the input bitnumber is a multiply of BITS_PER_LONG.
This API avoids the loop over each bit in a known range just to see
if all of them are either clear or set.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index f0bac4a071..92f38872fb 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other,
dst[i] |= other[i];
}
+static inline int test_bit_long_set(unsigned long nr_base, const void *_addr)
+{
+ const unsigned long *addr = _addr;
+ unsigned long val = addr[nr_base / BITS_PER_LONG];
+ return val == ~0;
+}
+
+static inline int test_bit_long_clear(unsigned long nr_base, const void *_addr)
+{
+ const unsigned long *addr = _addr;
+ unsigned long val = addr[nr_base / BITS_PER_LONG];
+ return val == 0;
+}
+
+static inline void clear_bit_long(unsigned long nr_base, void *_addr)
+{
+ unsigned long *addr = _addr;
+ addr[nr_base / BITS_PER_LONG] = 0;
+}
+
+static inline void set_bit_long(unsigned long nr_base, void *_addr)
+{
+ unsigned long *addr = _addr;
+ addr[nr_base / BITS_PER_LONG] = ~0;
+}
#endif /* XC_BITOPS_H */
next prev parent reply other threads:[~2020-12-09 15:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
2020-12-15 16:20 ` Wei Liu
2020-12-09 15:54 ` Olaf Hering [this message]
2020-12-15 16:22 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Wei Liu
2020-12-15 16:29 ` Olaf Hering
2020-12-15 16:30 ` Wei Liu
2020-12-15 16:11 ` [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201209155452.28376-3-olaf@aepfle.de \
--to=olaf@aepfle.de \
--cc=iwj@xenproject.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.