public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3230] Implement op1_range operators for unordered comparisons.
@ 2022-10-11 13:54 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-10-11 13:54 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fe7371e7f93c247b5d0e257ca2a68064123cd018

commit r13-3230-gfe7371e7f93c247b5d0e257ca2a68064123cd018
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Oct 10 16:58:29 2022 +0200

    Implement op1_range operators for unordered comparisons.
    
    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.

Diff:
---
 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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-11 13:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 13:54 [gcc r13-3230] Implement op1_range operators for unordered comparisons Aldy Hernandez

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).