[PPL-devel] [GIT] ppl/ppl(master): Let bitwise operators be applied to unsigned integer types.
Enea Zaffanella
zaffanella at cs.unipr.it
Mon Feb 20 17:32:18 CET 2012
Module: ppl/ppl
Branch: master
Commit: 73a3335f0a0974c903e88c4cd4b7107fb779bbcb
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=73a3335f0a0974c903e88c4cd4b7107fb779bbcb
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Mon Feb 20 17:23:49 2012 +0100
Let bitwise operators be applied to unsigned integer types.
Detected by ECLAIR service utypflag.
---
src/Result.defs.hh | 62 ++++++++++++++++++++++++++-----------------------
src/Result.inlines.hh | 39 +++++++++++++++++++++---------
src/globals.types.hh | 6 ++--
3 files changed, 63 insertions(+), 44 deletions(-)
diff --git a/src/Result.defs.hh b/src/Result.defs.hh
index e59147d..35eac7a 100644
--- a/src/Result.defs.hh
+++ b/src/Result.defs.hh
@@ -28,16 +28,16 @@ namespace Parma_Polyhedra_Library {
enum Result_Class {
//! \hideinitializer Representable number result class.
- VC_NORMAL = 0 << 4,
+ VC_NORMAL = 0U << 4,
//! \hideinitializer Negative infinity result class.
- VC_MINUS_INFINITY = 1 << 4,
+ VC_MINUS_INFINITY = 1U << 4,
//! \hideinitializer Positive infinity result class.
- VC_PLUS_INFINITY = 2 << 4,
+ VC_PLUS_INFINITY = 2U << 4,
//! \hideinitializer Not a number result class.
- VC_NAN = 3 << 4,
+ VC_NAN = 3U << 4,
VC_MASK = VC_NAN
};
@@ -45,16 +45,16 @@ enum Result_Class {
// This must be kept in sync with Relation_Symbol
enum Result_Relation {
//! \hideinitializer No values satisfies the relation.
- VR_EMPTY = 0,
+ VR_EMPTY = 0U,
//! \hideinitializer Equal. This need to be accompanied by a value.
- VR_EQ = 1,
+ VR_EQ = 1U,
//! \hideinitializer Less than. This need to be accompanied by a value.
- VR_LT = 2,
+ VR_LT = 2U,
//! \hideinitializer Greater than. This need to be accompanied by a value.
- VR_GT = 4,
+ VR_GT = 4U,
//! \hideinitializer Not equal. This need to be accompanied by a value.
VR_NE = VR_LT | VR_GT,
@@ -78,13 +78,13 @@ enum Result {
V_EMPTY = VR_EMPTY,
//! \hideinitializer The computed result is exact.
- V_EQ = VR_EQ,
+ V_EQ = static_cast<unsigned>(VR_EQ),
//! \hideinitializer The computed result is inexact and rounded up.
- V_LT = VR_LT,
+ V_LT = static_cast<unsigned>(VR_LT),
//! \hideinitializer The computed result is inexact and rounded down.
- V_GT = VR_GT,
+ V_GT = static_cast<unsigned>(VR_GT),
//! \hideinitializer The computed result is inexact.
V_NE = VR_NE,
@@ -99,7 +99,7 @@ enum Result {
V_LGE = VR_LGE,
//! \hideinitializer The exact result is a number out of finite bounds.
- V_OVERFLOW = 1 << 6,
+ V_OVERFLOW = 1U << 6,
//! \hideinitializer A negative integer overflow occurred (rounding up).
V_LT_INF = V_LT | V_OVERFLOW,
@@ -108,58 +108,62 @@ enum Result {
V_GT_SUP = V_GT | V_OVERFLOW,
//! \hideinitializer A positive integer overflow occurred (rounding up).
- V_LT_PLUS_INFINITY = V_LT | VC_PLUS_INFINITY,
+ V_LT_PLUS_INFINITY = V_LT | static_cast<unsigned>(VC_PLUS_INFINITY),
//! \hideinitializer A negative integer overflow occurred (rounding down).
- V_GT_MINUS_INFINITY = V_GT | VC_MINUS_INFINITY,
+ V_GT_MINUS_INFINITY = V_GT | static_cast<unsigned>(VC_MINUS_INFINITY),
//! \hideinitializer Negative infinity result.
- V_EQ_MINUS_INFINITY = V_EQ | VC_MINUS_INFINITY,
+ V_EQ_MINUS_INFINITY = V_EQ | static_cast<unsigned>(VC_MINUS_INFINITY),
//! \hideinitializer Positive infinity result.
- V_EQ_PLUS_INFINITY = V_EQ | VC_PLUS_INFINITY,
+ V_EQ_PLUS_INFINITY = V_EQ | static_cast<unsigned>(VC_PLUS_INFINITY),
//! \hideinitializer Not a number result.
- V_NAN = VC_NAN,
+ V_NAN = static_cast<unsigned>(VC_NAN),
//! \hideinitializer Converting from unknown string.
- V_CVT_STR_UNK = V_NAN | (1 << 8),
+ V_CVT_STR_UNK = V_NAN | (1U << 8),
//! \hideinitializer Dividing by zero.
- V_DIV_ZERO = V_NAN | (2 << 8),
+ V_DIV_ZERO = V_NAN | (2U << 8),
//! \hideinitializer Adding two infinities having opposite signs.
- V_INF_ADD_INF = V_NAN | (3 << 8),
+ V_INF_ADD_INF = V_NAN | (3U << 8),
//! \hideinitializer Dividing two infinities.
- V_INF_DIV_INF = V_NAN | (4 << 8),
+ V_INF_DIV_INF = V_NAN | (4U << 8),
//! \hideinitializer Taking the modulus of an infinity.
- V_INF_MOD = V_NAN | (5 << 8),
+ V_INF_MOD = V_NAN | (5U << 8),
//! \hideinitializer Multiplying an infinity by zero.
- V_INF_MUL_ZERO = V_NAN | (6 << 8),
+ V_INF_MUL_ZERO = V_NAN | (6U << 8),
//! \hideinitializer Subtracting two infinities having the same sign.
- V_INF_SUB_INF = V_NAN | (7 << 8),
+ V_INF_SUB_INF = V_NAN | (7U << 8),
//! \hideinitializer Computing a remainder modulo zero.
- V_MOD_ZERO = V_NAN | (8 << 8),
+ V_MOD_ZERO = V_NAN | (8U << 8),
//! \hideinitializer Taking the square root of a negative number.
- V_SQRT_NEG = V_NAN | (9 << 8),
+ V_SQRT_NEG = V_NAN | (9U << 8),
//! \hideinitializer Unknown result due to intermediate negative overflow.
- V_UNKNOWN_NEG_OVERFLOW = V_NAN | (10 << 8),
+ V_UNKNOWN_NEG_OVERFLOW = V_NAN | (10U << 8),
//! \hideinitializer Unknown result due to intermediate positive overflow.
- V_UNKNOWN_POS_OVERFLOW = V_NAN | (11 << 8),
+ V_UNKNOWN_POS_OVERFLOW = V_NAN | (11U << 8),
//! \hideinitializer The computed result is not representable.
- V_UNREPRESENTABLE = 1 << 7
+ V_UNREPRESENTABLE = 1U << 7
};
+Result operator&(Result x, Result y);
+Result operator|(Result x, Result y);
+Result operator-(Result x, Result y);
+
//! Extracts the value class part of \p r (representable number, unrepresentable minus/plus infinity or nan).
Result_Class result_class(Result r);
diff --git a/src/Result.inlines.hh b/src/Result.inlines.hh
index 36e754d..5141347 100644
--- a/src/Result.inlines.hh
+++ b/src/Result.inlines.hh
@@ -29,21 +29,44 @@ site: http://bugseng.com/products/ppl/ . */
namespace Parma_Polyhedra_Library {
/*! \relates Parma_Polyhedra_Library::Result */
+inline Result
+operator&(Result x, Result y) {
+ unsigned res = static_cast<unsigned>(x) & static_cast<unsigned>(y);
+ return static_cast<Result>(res);
+}
+
+/*! \relates Parma_Polyhedra_Library::Result */
+inline Result
+operator|(Result x, Result y) {
+ unsigned res = static_cast<unsigned>(x) | static_cast<unsigned>(y);
+ return static_cast<Result>(res);
+}
+
+/*! \relates Parma_Polyhedra_Library::Result */
+inline Result
+operator-(Result x, Result y) {
+ Result y_neg = static_cast<Result>(~static_cast<unsigned>(y));
+ return x & y_neg;
+}
+
+/*! \relates Parma_Polyhedra_Library::Result */
inline Result_Class
result_class(Result r) {
- return static_cast<Result_Class>(r & VC_MASK);
+ Result rc = r & static_cast<Result>(VC_MASK);
+ return static_cast<Result_Class>(rc);
}
/*! \relates Parma_Polyhedra_Library::Result */
inline Result_Relation
result_relation(Result r) {
- return static_cast<Result_Relation>(r & VR_MASK);
+ Result rc = r & static_cast<Result>(VR_MASK);
+ return static_cast<Result_Relation>(rc);
}
/*! \relates Parma_Polyhedra_Library::Result */
inline Result
result_relation_class(Result r) {
- return static_cast<Result>(r & (VR_MASK | VC_MASK));
+ return r & (static_cast<Result>(VR_MASK) | static_cast<Result>(VC_MASK));
}
inline int
@@ -71,15 +94,7 @@ result_overflow(Result r) {
inline bool
result_representable(Result r) {
- return (r & V_UNREPRESENTABLE) == 0;
-}
-
-inline Result operator|(Result a, Result b) {
- return static_cast<Result>((unsigned)a | (unsigned)b);
-}
-
-inline Result operator-(Result a, Result b) {
- return static_cast<Result>((unsigned)a & ~(unsigned)b);
+ return (r & V_UNREPRESENTABLE) != V_UNREPRESENTABLE;
}
} // namespace Parma_Polyhedra_Library
diff --git a/src/globals.types.hh b/src/globals.types.hh
index a74a80b..91cb692 100644
--- a/src/globals.types.hh
+++ b/src/globals.types.hh
@@ -39,13 +39,13 @@ enum Degenerate_Element {
// This must be kept in sync with Result
enum Relation_Symbol {
//! \hideinitializer Equal to.
- EQUAL = 1,
+ EQUAL = 1U,
//! \hideinitializer Less than.
- LESS_THAN = 2,
+ LESS_THAN = 2U,
//! \hideinitializer Less than or equal to.
LESS_OR_EQUAL = LESS_THAN | EQUAL,
//! \hideinitializer Greater than.
- GREATER_THAN = 4,
+ GREATER_THAN = 4U,
//! \hideinitializer Greater than or equal to.
GREATER_OR_EQUAL = GREATER_THAN | EQUAL,
//! \hideinitializer Not equal to.
More information about the PPL-devel
mailing list