public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1680] Unify NEGATE_EXPR range operator
@ 2023-06-10 0:34 Andrew Macleod
0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2023-06-10 0:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:56518befc2663ddc082e34dddd66b6334a3d4da5
commit r14-1680-g56518befc2663ddc082e34dddd66b6334a3d4da5
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Fri Jun 9 13:43:12 2023 -0400
Unify NEGATE_EXPR range operator
Move the declaration of the class to the range-op-mixed header, add the
floating point prototypes as well, and use it in the new unified table.
* range-op-float.cc (foperator_negate): Remove. Move prototypes
to range-op-mixed.h
(operator_negate::fold_range): Rename from foperator_negate.
(operator_negate::op1_range): Ditto.
(float_table::float_table): Remove NEGATE_EXPR.
* range-op-mixed.h (class operator_negate): Combined from integer
and float files.
* range-op.cc (op_negate): New object.
(unified_table::unified_table): Add NEGATE_EXPR.
(class operator_negate): Move to range-op-mixed.h.
(integral_table::integral_table): Remove NEGATE_EXPR.
(pointer_table::pointer_table): Remove NEGATE_EXPR.
Diff:
---
gcc/range-op-float.cc | 86 ++++++++++++++++++++++++---------------------------
gcc/range-op-mixed.h | 20 ++++++++++++
gcc/range-op.cc | 18 ++---------
3 files changed, 63 insertions(+), 61 deletions(-)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index db76dd5f39e..20b4b9f0d61 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1295,51 +1295,48 @@ foperator_ordered::op1_range (frange &r, tree type,
return true;
}
-class foperator_negate : public range_operator
+bool
+operator_negate::fold_range (frange &r, tree type,
+ const frange &op1, const frange &op2,
+ relation_trio) const
{
- using range_operator::fold_range;
- using range_operator::op1_range;
-public:
- bool fold_range (frange &r, tree type,
- const frange &op1, const frange &op2,
- relation_trio = TRIO_VARYING) const final override
- {
- if (empty_range_varying (r, type, op1, op2))
+ if (empty_range_varying (r, type, op1, op2))
+ return true;
+ if (op1.known_isnan ())
+ {
+ bool sign;
+ if (op1.nan_signbit_p (sign))
+ r.set_nan (type, !sign);
+ else
+ r.set_nan (type);
return true;
- if (op1.known_isnan ())
- {
- bool sign;
- if (op1.nan_signbit_p (sign))
- r.set_nan (type, !sign);
- else
- r.set_nan (type);
- return true;
- }
+ }
- REAL_VALUE_TYPE lh_lb = op1.lower_bound ();
- REAL_VALUE_TYPE lh_ub = op1.upper_bound ();
- lh_lb = real_value_negate (&lh_lb);
- lh_ub = real_value_negate (&lh_ub);
- r.set (type, lh_ub, lh_lb);
- if (op1.maybe_isnan ())
- {
- bool sign;
- if (op1.nan_signbit_p (sign))
- r.update_nan (!sign);
- else
- r.update_nan ();
- }
- else
- r.clear_nan ();
- return true;
- }
- bool op1_range (frange &r, tree type,
- const frange &lhs, const frange &op2,
- relation_trio rel = TRIO_VARYING) const final override
- {
- return fold_range (r, type, lhs, op2, rel);
- }
-} fop_negate;
+ REAL_VALUE_TYPE lh_lb = op1.lower_bound ();
+ REAL_VALUE_TYPE lh_ub = op1.upper_bound ();
+ lh_lb = real_value_negate (&lh_lb);
+ lh_ub = real_value_negate (&lh_ub);
+ r.set (type, lh_ub, lh_lb);
+ if (op1.maybe_isnan ())
+ {
+ bool sign;
+ if (op1.nan_signbit_p (sign))
+ r.update_nan (!sign);
+ else
+ r.update_nan ();
+ }
+ else
+ r.clear_nan ();
+ return true;
+}
+
+bool
+operator_negate::op1_range (frange &r, tree type,
+ const frange &lhs, const frange &op2,
+ relation_trio rel) const
+{
+ return fold_range (r, type, lhs, op2, rel);
+}
bool
operator_abs::fold_range (frange &r, tree type,
@@ -2674,7 +2671,6 @@ private:
float_table::float_table ()
{
- set (NEGATE_EXPR, fop_negate);
set (MULT_EXPR, fop_mult);
}
@@ -2719,13 +2715,13 @@ range_op_float_tests ()
// negate([-5, +10]) => [-10, 5]
r0 = frange_float ("-5", "10");
- fop_negate.fold_range (r, float_type_node, r0, trange);
+ range_op_handler (NEGATE_EXPR).fold_range (r, float_type_node, r0, trange);
ASSERT_EQ (r, frange_float ("-10", "5"));
// negate([0, 1] -NAN) => [-1, -0] +NAN
r0 = frange_float ("0", "1");
r0.update_nan (true);
- fop_negate.fold_range (r, float_type_node, r0, trange);
+ range_op_handler (NEGATE_EXPR).fold_range (r, float_type_node, r0, trange);
r1 = frange_float ("-1", "-0");
r1.update_nan (false);
ASSERT_EQ (r, r1);
diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index 520ec1929b9..598825af919 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -430,4 +430,24 @@ private:
const REAL_VALUE_TYPE &rh_lb, const REAL_VALUE_TYPE &rh_ub,
relation_kind) const final override;
};
+
+class operator_negate : public range_operator
+{
+ public:
+ using range_operator::fold_range;
+ using range_operator::op1_range;
+ bool fold_range (irange &r, tree type,
+ const irange &op1, const irange &op2,
+ relation_trio rel = TRIO_VARYING) const final override;
+ bool fold_range (frange &r, tree type,
+ const frange &op1, const frange &op2,
+ relation_trio = TRIO_VARYING) const final override;
+
+ bool op1_range (irange &r, tree type,
+ const irange &lhs, const irange &op2,
+ relation_trio rel = TRIO_VARYING) const final override;
+ bool op1_range (frange &r, tree type,
+ const frange &lhs, const frange &op2,
+ relation_trio rel = TRIO_VARYING) const final override;
+};
#endif // GCC_RANGE_OP_MIXED_H
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 209447928d8..539036d4cfa 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -74,6 +74,7 @@ operator_cast op_cast;
operator_plus op_plus;
operator_abs op_abs;
operator_minus op_minus;
+operator_negate op_negate;
// Invoke the initialization routines for each class of range.
@@ -99,6 +100,7 @@ unified_table::unified_table ()
set (PLUS_EXPR, op_plus);
set (ABS_EXPR, op_abs);
set (MINUS_EXPR, op_minus);
+ set (NEGATE_EXPR, op_negate);
}
// The tables are hidden and accessed via a simple extern function.
@@ -4378,21 +4380,6 @@ operator_absu::wi_fold (irange &r, tree type,
}
-class operator_negate : public range_operator
-{
- using range_operator::fold_range;
- using range_operator::op1_range;
- public:
- virtual bool fold_range (irange &r, tree type,
- const irange &op1,
- const irange &op2,
- relation_trio rel = TRIO_VARYING) const;
- virtual bool op1_range (irange &r, tree type,
- const irange &lhs,
- const irange &op2,
- relation_trio rel = TRIO_VARYING) const;
-} op_negate;
-
bool
operator_negate::fold_range (irange &r, tree type,
const irange &lh,
@@ -4665,7 +4652,6 @@ integral_table::integral_table ()
set (BIT_IOR_EXPR, op_bitwise_or);
set (BIT_XOR_EXPR, op_bitwise_xor);
set (BIT_NOT_EXPR, op_bitwise_not);
- set (NEGATE_EXPR, op_negate);
set (ADDR_EXPR, op_addr);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-10 0:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-10 0:34 [gcc r14-1680] Unify NEGATE_EXPR range operator Andrew Macleod
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).