From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 023F61F45F for ; Sat, 4 May 2019 01:10:43 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=GCyN KJXkVi9hONjEuf6YrTwHCD6CiO0bb/0tSVhCppi7BOFu4QxPjfMHRp/rxZewdk3v Wd9/OVRXraiNh52sP1LW459FcVfBIKKj4eRJRH07IrC6BtH6OO/KcTZ1PaQnplME RFx3g4heuRNMTOYCtQWFVI2/HhUEmDcIMgt1ZbQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=hYIwTk57DB e85XdwSoxlG+Fha4Y=; b=DeSYsmsPolj0jLvABh1B9eCrb0KZWWAs7l69mOrELA mMsbAIPIaNQlMg4pn2e+dHNDvZrRtB1USFZh2xqEYZlQtEYxbaWHMB2c4nZ5rCCg 9NpkF6VxdgxzfJ70mqJ3Mzi0HJv9ozo9qEPJ5h/vV/CkJpL3EDPmjH5oYmUqJDHk 0= Received: (qmail 32215 invoked by alias); 4 May 2019 01:10:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 32205 invoked by uid 89); 4 May 2019 01:10:41 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: smtpout1.mo803.mail-out.ovh.net Date: Fri, 3 May 2019 22:10:31 -0300 From: "Gabriel F. T. Gomes" To: Adhemerval Zanella CC: Subject: Re: [PATCH 06/28] powerpc: round/roundf refactor Message-ID: <20190504011031.5pinthodq7fztpov@tereshkova> References: <20190329133529.22523-1-adhemerval.zanella@linaro.org> <20190329133529.22523-7-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190329133529.22523-7-adhemerval.zanella@linaro.org> User-Agent: NeoMutt/20180716 X-Ovh-Tracer-Id: 16612934604446813897 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduuddrjedvgdeghecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd On Fri, Mar 29 2019, Adhemerval Zanella wrote: > > * sysdeps/powerpc/fpu/round_to_integer.h (set_rounding_mode): Add > ROUND handling. > (round_to_integer_float): Likewise. Similar to what I mentioned for the floor patch, just make sure you mention the addition of the ROUND definition. > diff --git a/sysdeps/powerpc/fpu/round_to_integer.h b/sysdeps/powerpc/fpu/round_to_integer.h > index 77d9fc1f86..3fa2b77b6d 100644 > --- a/sysdeps/powerpc/fpu/round_to_integer.h > +++ b/sysdeps/powerpc/fpu/round_to_integer.h > @@ -38,6 +38,7 @@ set_fenv_mode (enum round_mode mode) > { > case CEIL: rmode = FE_UPWARD; break; > case FLOOR: rmode = FE_DOWNWARD; break; > + case ROUND: rmode = FE_TOWARDZERO; break; > default: rmode = FE_TONEAREST; break; > } Likewise, check that the FLOOR definition is added to round_mode. This patch looks good to me with these changes. Reviewed-by: Gabriel F. T. Gomes > @@ -60,12 +61,24 @@ round_to_integer_float (enum round_mode mode, float x) > set_fenv_mode (mode); > if (x > 0.0) > { > + /* IEEE 1003.1 round function. IEEE specifies "round to the nearest > + integer value, rounding halfway cases away from zero, regardless of > + the current rounding mode." However PowerPC Architecture defines > + "Round to Nearest" as "Choose the best approximation. In case of a > + tie, choose the one that is even (least significant bit o).". > + So we can't use the PowerPC "Round to Nearest" mode. Instead we set > + "Round toward Zero" mode and round by adding +-0.5 before rounding > + to the integer value. */ > + if (mode == ROUND) > + r += 0.5f; > r += 0x1p+23; > r -= 0x1p+23; > r = fabs (r); > } > else if (x < 0.0) > { > + if (mode == ROUND) > + r -= 0.5f; > r -= 0x1p+23; > r += 0x1p+23; > r = -fabs (r); OK. Restored from the .S files. > @@ -92,12 +105,16 @@ round_to_integer_double (enum round_mode mode, double x) > set_fenv_mode (mode); > if (x > 0.0) > { > + if (mode == ROUND) > + r += 0.5; > r += 0x1p+52; > r -= 0x1p+52; > r = fabs (r); > } > else if (x < 0.0) > { > + if (mode == ROUND) > + r -= 0.5; > r -= 0x1p+52; > r += 0x1p+52; > r = -fabs (r); OK. Likewise. > +double > +__round (double x) > +{ > +#ifdef _ARCH_PWR5X > + return __builtin_round (x); > +#else > + return round_to_integer_double (ROUND, x); > +#endif > +} OK. Arch check looks correct. > -.LC1: /* 0.5 */ > - .long 0x3f000000 > - > -/* double [fp1] round (double x [fp1]) > - IEEE 1003.1 round function. IEEE specifies "round to the nearest > - integer value, rounding halfway cases away from zero, regardless of > - the current rounding mode." However PowerPC Architecture defines > - "Round to Nearest" as "Choose the best approximation. In case of a > - tie, choose the one that is even (least significant bit o).". > - So we can't use the PowerPC "Round to Nearest" mode. Instead we set > - "Round toward Zero" mode and round by adding +-0.5 before rounding > - to the integer value. */ > > [...] > > -#ifdef SHARED > - lfs fp10,.LC1-.LC0(r9) > -#else > - lis r9,.LC1@ha > - lfs fp10,.LC1@l(r9) > -#endif > - ble- cr6,.L4 > - fadd fp1,fp1,fp10 /* x+= 0.5; */ OK. Moved to round_to_integer_float and round_to_integer_double.