From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 1A7DC3858434; Wed, 9 Nov 2022 07:08:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A7DC3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667977713; bh=2ZCxqsS583kD+c1kbpjN5gp37ggrYMpH6wzB3wwNJwQ=; h=From:To:Subject:Date:From; b=wgyzVXukfpn2rrDHqwV/Ec9LtX8vMsGyYncWEhuFQPIx5kfGkbNtYeyqb8x7iycQI om2H/q9Xz+NlCLD9qSxwNzXEI87XDolcOrOpppl/9p55QW9u4o26T90Fd35eHfnvhf 0WsHoTXsubEMu6sfe+TuY5YTbYiJRDsFy0sKSVyA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3825] [range-op-float] Implement MINUS_EXPR. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 0ef5649e9b9f409cf1e133e8670043f066ba3acb X-Git-Newrev: 38ec5e4bc8fed58e278e6dcad999d38c5efc1340 Message-Id: <20221109070833.1A7DC3858434@sourceware.org> Date: Wed, 9 Nov 2022 07:08:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:38ec5e4bc8fed58e278e6dcad999d38c5efc1340 commit r13-3825-g38ec5e4bc8fed58e278e6dcad999d38c5efc1340 Author: Aldy Hernandez Date: Tue Nov 8 23:49:48 2022 +0100 [range-op-float] Implement MINUS_EXPR. Now that the generic parts of the binary operators have been abstracted, implementing MINUS_EXPR is a cinch. The op[12]_range entries will be submitted as a follow-up. gcc/ChangeLog: * range-op-float.cc (class foperator_minus): New. (floating_op_table::floating_op_table): Add MINUS_EXPR entry. Diff: --- gcc/range-op-float.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 7075c25442a..d52e971f84e 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1884,6 +1884,29 @@ class foperator_plus : public range_operator_float } fop_plus; +class foperator_minus : public range_operator_float +{ + void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan, + tree type, + const REAL_VALUE_TYPE &lh_lb, + const REAL_VALUE_TYPE &lh_ub, + const REAL_VALUE_TYPE &rh_lb, + const REAL_VALUE_TYPE &rh_ub) const final override + { + frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub, dconstninf); + frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb, dconstinf); + + // [+INF] - [+INF] = NAN + if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false)) + maybe_nan = true; + // [-INF] - [-INF] = NAN + else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true)) + maybe_nan = true; + else + maybe_nan = false; + } +} fop_minus; + // Instantiate a range_op_table for floating point operations. static floating_op_table global_floating_table; @@ -1917,6 +1940,7 @@ floating_op_table::floating_op_table () set (ABS_EXPR, fop_abs); set (NEGATE_EXPR, fop_negate); set (PLUS_EXPR, fop_plus); + set (MINUS_EXPR, fop_minus); } // Return a pointer to the range_operator_float instance, if there is