|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XEN PATCH][for-4.19 v4 1/8] xen/include: add macro ISOLATE_LOW_BIT
The purpose of this macro is to encapsulate the well-known expression
'x & -x' that in 2's complement architectures on unsigned integers will
give a mask where only the least significant nonzero bit of 'x' is set,
or 0 if none are set.
A deviation for ECLAIR is also introduced.
Signed-off-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
---
Changes in v2:
- rename to LOWEST_BIT
Changes in v3:
- entry for deviations.rst
- comment on the macro defn
Changes in v4:
- Change the macro's name to ISOLATE_LOW_BIT
---
automation/eclair_analysis/ECLAIR/deviations.ecl | 7 +++++++
docs/misra/deviations.rst | 8 ++++++++
xen/include/xen/macros.h | 10 ++++++++--
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl
b/automation/eclair_analysis/ECLAIR/deviations.ecl
index fa56e5c00a27..139dabc8477f 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -246,6 +246,13 @@ constant expressions are required.\""
"any()"}
-doc_end
+-doc_begin="The macro ISOLATE_LOW_BIT encapsulates a well-known pattern to
obtain
+a mask where only the lowest bit set in the argument is set, if any, for
unsigned
+integers arguments on two's complement architectures
+(all the architectures supported by Xen satisfy this requirement)."
+-config=MC3R1.R10.1,reports+={safe,
"any_area(any_loc(any_exp(macro(^ISOLATE_LOW_BIT$))))"}
+-doc_end
+
#
# Series 13
#
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index 8511a189253b..d76b28279e59 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -192,6 +192,14 @@ Deviations related to MISRA C:2012 Rules:
See automation/eclair_analysis/deviations.ecl for the full explanation.
- Tagged as `safe` for ECLAIR.
+ * - R10.1
+ - The macro ISOLATE_LOW_BIT encapsulates the well-known pattern (x & -x)
+ applied to unsigned integer values on 2's complement architectures
+ (i.e., all architectures supported by Xen), used to obtain a mask where
+ just the least significant nonzero bit of x is set.
+ If no bits are set, 0 is returned.
+ - Tagged as `safe` for ECLAIR.
+
* - R13.5
- All developers and reviewers can be safely assumed to be well aware of
the short-circuit evaluation strategy for logical operators.
diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h
index d0caae7db298..4e1b1f4e4b56 100644
--- a/xen/include/xen/macros.h
+++ b/xen/include/xen/macros.h
@@ -8,8 +8,14 @@
#define DIV_ROUND(n, d) (((n) + (d) / 2) / (d))
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
-#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
-#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+/*
+ * Given an unsigned integer argument, expands to a mask where just the least
+ * significant nonzero bit of the argument is set, or 0 if no bits are set.
+ */
+#define ISOLATE_LOW_BIT(x) ((x) & -(x))
+
+#define MASK_EXTR(v, m) (((v) & (m)) / ISOLATE_LOW_BIT(m))
+#define MASK_INSR(v, m) (((v) * ISOLATE_LOW_BIT(m)) & (m))
#define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x
#define count_args(args...) \
--
2.34.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |