From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] Implement op1_range operators for unordered comparisons.
Date: Tue, 11 Oct 2022 15:51:35 +0200 [thread overview]
Message-ID: <20221011135136.369644-3-aldyh@redhat.com> (raw)
In-Reply-To: <20221011135136.369644-1-aldyh@redhat.com>
gcc/ChangeLog:
* range-op-float.cc (foperator_unordered_le::op1_range): New.
(foperator_unordered_le::op2_range): New.
(foperator_unordered_gt::op1_range): New.
(foperator_unordered_gt::op2_range): New.
(foperator_unordered_ge::op1_range): New.
(foperator_unordered_ge::op2_range): New.
(foperator_unordered_equal::op1_range): New.
---
gcc/range-op-float.cc | 205 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 205 insertions(+)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 8dd4bcc70c0..ef51b7538e3 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1162,6 +1162,8 @@ public:
class foperator_unordered_le : public range_operator_float
{
using range_operator_float::fold_range;
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
@@ -1184,11 +1186,65 @@ public:
return true;
}
}
+ bool op1_range (frange &r, tree type,
+ const irange &lhs, const frange &op2,
+ relation_kind rel) const final override;
+ bool op2_range (frange &r, tree type,
+ const irange &lhs, const frange &op1,
+ relation_kind rel) const final override;
} fop_unordered_le;
+bool
+foperator_unordered_le::op1_range (frange &r, tree type,
+ const irange &lhs, const frange &op2,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_le (r, type, op2);
+ break;
+
+ case BRS_FALSE:
+ build_gt (r, type, op2);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
+bool
+foperator_unordered_le::op2_range (frange &r,
+ tree type,
+ const irange &lhs,
+ const frange &op1,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_ge (r, type, op1);
+ break;
+
+ case BRS_FALSE:
+ build_lt (r, type, op1);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
class foperator_unordered_gt : public range_operator_float
{
using range_operator_float::fold_range;
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
@@ -1211,11 +1267,67 @@ public:
return true;
}
}
+ bool op1_range (frange &r, tree type,
+ const irange &lhs, const frange &op2,
+ relation_kind rel) const final override;
+ bool op2_range (frange &r, tree type,
+ const irange &lhs, const frange &op1,
+ relation_kind rel) const final override;
} fop_unordered_gt;
+bool
+foperator_unordered_gt::op1_range (frange &r,
+ tree type,
+ const irange &lhs,
+ const frange &op2,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_gt (r, type, op2);
+ break;
+
+ case BRS_FALSE:
+ build_le (r, type, op2);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
+bool
+foperator_unordered_gt::op2_range (frange &r,
+ tree type,
+ const irange &lhs,
+ const frange &op1,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_lt (r, type, op1);
+ break;
+
+ case BRS_FALSE:
+ build_ge (r, type, op1);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
class foperator_unordered_ge : public range_operator_float
{
using range_operator_float::fold_range;
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
@@ -1238,11 +1350,66 @@ public:
return true;
}
}
+ bool op1_range (frange &r, tree type,
+ const irange &lhs, const frange &op2,
+ relation_kind rel) const final override;
+ bool op2_range (frange &r, tree type,
+ const irange &lhs, const frange &op1,
+ relation_kind rel) const final override;
} fop_unordered_ge;
+bool
+foperator_unordered_ge::op1_range (frange &r,
+ tree type,
+ const irange &lhs,
+ const frange &op2,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_ge (r, type, op2);
+ break;
+
+ case BRS_FALSE:
+ build_lt (r, type, op2);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
+bool
+foperator_unordered_ge::op2_range (frange &r, tree type,
+ const irange &lhs,
+ const frange &op1,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ build_le (r, type, op1);
+ break;
+
+ case BRS_FALSE:
+ build_gt (r, type, op1);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
+
class foperator_unordered_equal : public range_operator_float
{
using range_operator_float::fold_range;
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
@@ -1265,8 +1432,46 @@ public:
return true;
}
}
+ bool op1_range (frange &r, tree type,
+ const irange &lhs, const frange &op2,
+ relation_kind rel) const final override;
+ bool op2_range (frange &r, tree type,
+ const irange &lhs, const frange &op1,
+ relation_kind rel) const final override
+ {
+ return op1_range (r, type, lhs, op1, rel);
+ }
} fop_unordered_equal;
+bool
+foperator_unordered_equal::op1_range (frange &r, tree type,
+ const irange &lhs,
+ const frange &op2,
+ relation_kind) const
+{
+ switch (get_bool_state (r, lhs, type))
+ {
+ case BRS_TRUE:
+ // If it's true, the result is the same as OP2 plus a NAN.
+ r = op2;
+ // Add both zeros if there's the possibility of zero equality.
+ frange_add_zeros (r, type);
+ // Add the posibility of a NAN.
+ r.update_nan ();
+ break;
+
+ case BRS_FALSE:
+ // The false side indictates !NAN and not equal. We can at least
+ // represent !NAN.
+ r.set_varying (type);
+ r.clear_nan ();
+ break;
+
+ default:
+ break;
+ }
+ return true;
+}
// Instantiate a range_op_table for floating point operations.
static floating_op_table global_floating_table;
--
2.37.3
next prev parent reply other threads:[~2022-10-11 13:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-11 13:51 [COMMITTED] Move TRUE case first in range-op.cc Aldy Hernandez
2022-10-11 13:51 ` [COMMITTED] Share common ordered comparison code with UN*_EXPR Aldy Hernandez
2022-10-11 13:51 ` Aldy Hernandez [this message]
2022-10-11 13:57 ` [COMMITTED] Implement op1_range operators for unordered comparisons Aldy Hernandez
2022-10-11 13:51 ` [COMMITTED] Implement ABS_EXPR operator for frange Aldy Hernandez
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=20221011135136.369644-3-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.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 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).