public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3261] Add range-op entry for floating point NEGATE_EXPR. Date: Wed, 12 Oct 2022 18:28:44 +0000 (GMT) [thread overview] Message-ID: <20221012182844.CBA673857372@sourceware.org> (raw) https://gcc.gnu.org/g:a0c1a059101a3067d96211cbc4fae5905796d1db commit r13-3261-ga0c1a059101a3067d96211cbc4fae5905796d1db Author: Aldy Hernandez <aldyh@redhat.com> Date: Tue Oct 11 17:23:42 2022 +0200 Add range-op entry for floating point NEGATE_EXPR. gcc/ChangeLog: * range-op-float.cc (class foperator_negate): New. (floating_op_table::floating_op_table): Add NEGATE_EXPR (range_op_float_tests): Add negate tests. Diff: --- gcc/range-op-float.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 22b7418c197..229b9d23351 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1132,6 +1132,52 @@ foperator_ordered::op1_range (frange &r, tree type, return true; } +class foperator_negate : public range_operator_float +{ + using range_operator_float::fold_range; + using range_operator_float::op1_range; +public: + bool fold_range (frange &r, tree type, + const frange &op1, const frange &op2, + relation_kind = VREL_VARYING) const final override + { + 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; + } + + 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_kind rel = VREL_VARYING) const final override + { + return fold_range (r, type, lhs, op2, rel); + } +} fop_negate; + class foperator_abs : public range_operator_float { using range_operator_float::fold_range; @@ -1593,6 +1639,7 @@ floating_op_table::floating_op_table () set (UNORDERED_EXPR, fop_unordered); set (ABS_EXPR, fop_abs); + set (NEGATE_EXPR, fop_negate); } // Return a pointer to the range_operator_float instance, if there is @@ -1633,6 +1680,21 @@ frange_float (const char *lb, const char *ub, tree type = float_type_node) void range_op_float_tests () { + frange r, r0, r1; + frange trange (float_type_node); + + // negate([-5, +10]) => [-10, 5] + r0 = frange_float ("-5", "10"); + fop_negate.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); + r1 = frange_float ("-1", "-0"); + r1.update_nan (false); + ASSERT_EQ (r, r1); } } // namespace selftest
reply other threads:[~2022-10-12 18:28 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221012182844.CBA673857372@sourceware.org \ --to=aldyh@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).