From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85662 invoked by alias); 22 Aug 2019 16:56:17 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 85648 invoked by uid 89); 22 Aug 2019 16:56:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.1 spammy=sk:clear_s X-HELO: mail-ed1-f68.google.com Received: from mail-ed1-f68.google.com (HELO mail-ed1-f68.google.com) (209.85.208.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Aug 2019 16:56:15 +0000 Received: by mail-ed1-f68.google.com with SMTP id z51so8860539edz.13 for ; Thu, 22 Aug 2019 09:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lfk4As9L4NaYxB4VQbeaE/0DaY4hEvQ8lWj6FoWh0gI=; b=rNYI3w5amCHwSL9aQ9NpCD/B2w47U/eOun4dmWndNJ8F+eSK98UH+nivc6whTCo+6y qUGY4WZtMpYt4HIyRX+voi39/BYWnZB624ndeHo8mCT9MtioqiWqcZeVDLQR2neY/hs9 JOSyPxp5PkCvDrY9KYokvpH8cqsVut0kXQDlrpGL1J7fiiTUiqePtF4k3Qdm4ZgwEUIM 1kxRc0CrSMLF5vg2jazTQSnR9HQAy6aqWr8oej9ipPtO6lC+uyZu/OeLXLjcikZ200wr PeCrOpibgSAlWvVRo3feOVhbnzBjQ18cvWtMtxK1h0OA8HawVI4FmDM9r7HuSq2rrgpy LQ0w== MIME-Version: 1.0 References: In-Reply-To: From: Tejas Joshi Date: Thu, 22 Aug 2019 16:56:00 -0000 Message-ID: Subject: Re: [PATCH] Builtin function roundeven folding implementation To: gcc@gcc.gnu.org Cc: Martin Jambor , hubicka@ucw.cz, joseph@codesourcery.com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00187.txt.bz2 > I think you should have at least four tests of sign of zero result > (arguments -0.5, -0.0, 0.0 and 0.5). Probably also tests of values > between +/- 0.5 and 0, e.g. test -0.25 and 0.25 as well. Okay, I have made the following changes and again, the tests pass for roundeven. void real_roundeven (REAL_VALUE_TYPE *r, format_helper fmt, const REAL_VALUE_TYPE *x) { if (is_halfway_below (x)) { /* Special case as -0.5 rounds to -0.0 and similarly +0.5 rounds to +0.0. */ if (REAL_EXP (x) == 0) { *r = *x; clear_significand_below (r, SIGNIFICAND_BITS); } else { do_add (r, x, &dconsthalf, x->sign); if (!is_even (r)) do_add (r, r, &dconstm1, x->sign); } if (fmt) real_convert (r, fmt, r); } else real_round (r, fmt, x); } Tests : /* { dg-do link } */ extern int link_error (int); #define TEST(FN, VALUE, RESULT) \ if (__builtin_##FN (VALUE) != RESULT) link_error (__LINE__); int main (void) { TEST(roundeven, 0, 0); TEST(roundeven, 0.5, 0); TEST(roundeven, -0.5, 0); TEST(roundeven, 6, 6); TEST(roundeven, -8, -8); TEST(roundeven, 2.5, 2); TEST(roundeven, 3.5, 4); TEST(roundeven, -1.5, -2); TEST(roundeven, 3.499, 3); TEST(roundeven, 3.501, 4); if (__builtin_copysign (1, __builtin_roundeven (-0.5)) != -1) link_error (__LINE__); if (__builtin_copysign (1, __builtin_roundeven (-0.0)) != -1) link_error (__LINE__); if (__builtin_copysign (-1, __builtin_roundeven (0.5)) != 1) link_error (__LINE__); if (__builtin_copysign (-1, __builtin_roundeven (0.0)) != 1) link_error (__LINE__); if (__builtin_copysign (1, __builtin_roundeven (-0.25)) != -1) link_error (__LINE__); if (__builtin_copysign (-1, __builtin_roundeven (0.25)) != 1) link_error (__LINE__); return 0; } Thanks, Tejas On Thu, 22 Aug 2019 at 22:05, Joseph Myers wrote: > > On Thu, 22 Aug 2019, Tejas Joshi wrote: > > > > I'm concerned that this would produce +0.0 for an argument of -0.5 (via > > > -0.5 - 0.5 - -1.0 producing +0.0) when it needs to produce -0.0. > > > > Would the following overhaul be acceptable as the condition is > > specialized for -0.5 and +0.5 only. This seems to solve the problem. I > > did test the roundeven tests and it passes the tests. > > I think that would be reasonable with a comment added to explain that it's > ensuring the correct sign of a zero result. > > > if (__builtin_copysign (1, __builtin_roundeven (-0.5)) != -1) > > link_error (__LINE__); > > I think you should have at least four tests of sign of zero result > (arguments -0.5, -0.0, 0.0 and 0.5). Probably also tests of values > between +/- 0.5 and 0, e.g. test -0.25 and 0.25 as well. > > -- > Joseph S. Myers > joseph@codesourcery.com