[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v20210616 02/36] tools: add API to work with sevaral bits at once


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Wed, 16 Jun 2021 14:50:55 +0200
  • Arc-authentication-results: i=1; strato.com; dkim=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1623847894; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DqV9Bza4xh4lmngXwj1J3LSRM3kpJQsPapKBO4Z/YvI=; b=kh+V1rAx7xgK2zFpG6lcaLCQakgeMdWrwOYnXxg8ivaAECy3YwjOPQ617eESscoi8d 31+z2zGp4Nd8vEaoj8h00aVnVZTdPSzsBL4XWvGOac3xjFx4oIkfBuswAH83QrHL2pSm 0EYkkAMZLD4ZpWms/eLy33qxc6oXwFCVdbuw6iACNwmOv/WKNLPCpVRVMgDYJV0TUCDe EeMggkNZ4Mby7iJw0gEYIVXQkPOSZYM167QgaD8F42jdndQSR82EYkEfg3oFlt7D2j8r UyluyDkkau2rCTNlgNnNmh/Z3pqihoJSEVChtoDm1BN2AmSLG2gUM6s3+DaM2vDUXf/f M0wQ==
  • Arc-seal: i=1; a=rsa-sha256; t=1623847894; cv=none; d=strato.com; s=strato-dkim-0002; b=FeGjylmrxkl+Ci1PpMJGW1Tax2bnjr7O4fv8cyrOoEZvjjd28zNOYElLMC/KY6smkZ MR/Ql/hggF3Op+FrIVRcBDIT0Xjd53gWafL8smW/Ze4Ais3Qn6WkRwNFyEV7rques3NI 3kWV42VBxgxLKEKiTebKmgHaC8/ugSPPwlSZnGT7tsOtT2EvMIck+oxUMs7tQzPyi/QY cLpdl19/1WkfVvwKvuDQkZVQOgq/DSk3s1D9uGJ6qNgw6+e5RkncKEXiCFOfmzENnztA Ihg+zfDU3UIcjvZkxOpQVg2fn2lVcgZMlZUVXRf/z8BMGgmUgAp8h4wKkGFMd7kDq654 kJ1A==
  • Authentication-results: strato.com; dkim=none
  • Cc: Olaf Hering <olaf@xxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Wed, 16 Jun 2021 12:51:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 multiple 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@xxxxxxxxx>

v02:
- change return type from int to bool (jgross)
---
 tools/libs/ctrl/xc_bitops.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index f0bac4a071..8e8c6efb45 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -3,6 +3,7 @@
 
 /* bitmap operations for single threaded access */
 
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -77,4 +78,31 @@ static inline void bitmap_or(void *_dst, const void *_other,
         dst[i] |= other[i];
 }
 
+static inline bool 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 bool 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 */



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.