From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 60BD1289DC for ; Wed, 12 Jun 2024 17:44:00 +0200 (CEST) Received: (qmail 11941 invoked by uid 550); 12 Jun 2024 15:43:56 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11906 invoked from network); 12 Jun 2024 15:43:55 -0000 Date: Wed, 12 Jun 2024 11:44:10 -0400 From: Rich Felker To: Meng Zhuo Cc: musl@lists.openwall.com Message-ID: <20240612154410.GU10433@brightrain.aerifal.cx> References: <20240612153105.335451-1-mzh@mzh.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240612153105.335451-1-mzh@mzh.io> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH v3] math: add riscv64 round/roundf On Wed, Jun 12, 2024 at 11:31:05PM +0800, Meng Zhuo wrote: > --- > v2 -> v3: > * use x + x to check +-inf and NaN > --- > v1 -> v2: > * drop ±inf check and use fabs as Rich suggested > --- > src/math/riscv64/round.c | 21 +++++++++++++++++++++ > src/math/riscv64/roundf.c | 21 +++++++++++++++++++++ > 2 files changed, 42 insertions(+) > create mode 100644 src/math/riscv64/round.c > create mode 100644 src/math/riscv64/roundf.c > > diff --git a/src/math/riscv64/round.c b/src/math/riscv64/round.c > new file mode 100644 > index 00000000..28d05aed > --- /dev/null > +++ b/src/math/riscv64/round.c > @@ -0,0 +1,21 @@ > +#include > + > +#if __riscv_flen >= 64 > + > +double round(double x) > +{ > + if (isnan(x + x)) return x; // if x is +-inf or nan > + if (fabs(x) >= 0x1p54) return x; Why? I already gave you a single expression that covers all these cases if you don't care about raising INVALID (I don't recall if that's allowed here): if (!(fabs(x) < 0x1p54)) return x; Your new x+x *does* raise INVALID, so it has no advantages. If the function needs to avoid raising INVALID, you need to check isnan(x) (or !isfinite(x) is probably better) separately like you were doing. We need to check this. Rich