From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Palmer Dabbelt Newsgroups: gmane.comp.lib.glibc.alpha Subject: Re: riscv: fmax/fmin sNaN fix Date: Wed, 21 Feb 2018 13:25:42 -0800 (PST) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1519248237 8957 195.159.176.226 (21 Feb 2018 21:23:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Feb 2018 21:23:57 +0000 (UTC) Cc: libc-alpha@sourceware.org To: dj@redhat.com Original-X-From: libc-alpha-return-90452-glibc-alpha=m.gmane.org@sourceware.org Wed Feb 21 22:23:52 2018 Return-path: Envelope-to: glibc-alpha@blaine.gmane.org 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:subject:in-reply-to:cc:from:to:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=vaf1YO7u7uCsLVnBdA9RxMSra2hRNUbZ8WDA/j6dwnw/lafIzpuW3 pHzLj0IxyATxKqJZJBYf57XG8AIiRkp1/5NELUzUYtdsNocbPpem+mBBTezGQ0B0 t2KkoGx1M1gI0taXeB0K44TKmcmpWpi0mgkegN6lG514gAtNFsXHNA= 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:subject:in-reply-to:cc:from:to:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=i5aaXzTyR8vMzla2nt9sY/T6EDo=; b=mIMGyr0CyNf/t/v/NHXkYW+36PHL 5WtqlLnxiZmV89i9BJPe1GDXy5dVDlXcUDlIR5Gn/K0m3K7vwqJZg/NvA93rnzgA pm1wEe+YUOU2nzfejficMad0mInhs8EqzT9fpa5Aui7QWXZg/kZRhPuAq1ClkKXB wTx74o9brPmSKvQ= 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: , Original-Sender: libc-alpha-owner@sourceware.org Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pl0-f51.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=ScZErcQnPeTotC1fWTFBBZX62D6OCALT030Lx3NXWb8=; b=ShpPEpJG2FUnf5JIZbV/Eje7WjdCsGfZgRS3KIYKwl7vr/W+TJp67Tz+5JtWfsZuL2 seBf5VA+zmJBz0EjjZCnHJmZ5H2wkHbDr0Vn4BL1h2jU3z+3GHJP+Z4eJo2/I2q+zBUM MxbBuOMjjLCxIXANfUDcr8KJYG+gTnhonLvao0tCNFxQ/GsIjROqLs/wTRMYL33Ku7uW u84bYb7kgNTvSWb2frPMVtgqOwnzwxlvnkiBgHkTWOrHIV5TKwtrpIE/jytVjKiusqEN nkxrqRTsrKCVW1ibaNCy/UTB2BaghnyEKwiJj/LwCMHfQDKdiFabP9bHcV1i0Fpdv6wa z6wA== X-Gm-Message-State: APf1xPBruAermfjozXJUn3qOrc4w56VWDwLLN3EARVk9YJKJmxlLq2GF wDrufxx2JpGdOogzLHSYLK/rADc/704= X-Google-Smtp-Source: AH8x226g3njgeQRL1XRpJ2M3Ljcnfw1ODQ2FUS1tS/0zUDoav+0LanSUy3zPy1LIQlt6w1fRW29ZVA== X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr4363047plt.205.1519248343108; Wed, 21 Feb 2018 13:25:43 -0800 (PST) X-Google-Original-Date: Wed, 21 Feb 2018 13:25:32 PST (-0800) In-Reply-To: Xref: news.gmane.org gmane.comp.lib.glibc.alpha:82784 Archived-At: Received: from server1.sourceware.org ([209.132.180.131] helo=sourceware.org) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eobrk-0001wX-5x for glibc-alpha@blaine.gmane.org; Wed, 21 Feb 2018 22:23:52 +0100 Received: (qmail 85762 invoked by alias); 21 Feb 2018 21:25:46 -0000 Received: (qmail 85646 invoked by uid 89); 21 Feb 2018 21:25:46 -0000 On Mon, 19 Feb 2018 18:57:49 PST (-0800), dj@redhat.com wrote: > > RISC-V's FPU follows the IEEE spec, not the POSIX spec. This patch > adds handling for sNaN cases where the two specs differ. > > * sysdeps/riscv/rvd/s_fmax.c (__fmax): Handle sNaNs correctly. > * sysdeps/riscv/rvd/s_fmin.c (__fmin): Likewise. > * sysdeps/riscv/rvf/s_fmaxf.c (__fmaxf): Likewise. > * sysdeps/riscv/rvf/s_fminf.c (__fminf): Likewise. > > diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c > index ef8f1344ce..22e91bfc4b 100644 > --- a/sysdeps/riscv/rvd/s_fmax.c > +++ b/sysdeps/riscv/rvd/s_fmax.c > @@ -17,12 +17,19 @@ > . */ > > #include > +#include > #include > > double > __fmax (double x, double y) > { > - asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); > - return x; > + double res; > + > + if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN)) > + return x + y; > + else > + asm ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); > + > + return res; > } > libm_alias_double (__fmax, fmax) > diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c > index c6ff24cefb..7b35230cac 100644 > --- a/sysdeps/riscv/rvd/s_fmin.c > +++ b/sysdeps/riscv/rvd/s_fmin.c > @@ -17,12 +17,19 @@ > . */ > > #include > +#include > #include > > double > __fmin (double x, double y) > { > - asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); > - return x; > + double res; > + > + if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN)) > + return x + y; > + else > + asm ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); > + > + return res; > } > libm_alias_double (__fmin, fmin) > diff --git a/sysdeps/riscv/rvf/s_fmaxf.c b/sysdeps/riscv/rvf/s_fmaxf.c > index 3293f2f41c..63f7e3d664 100644 > --- a/sysdeps/riscv/rvf/s_fmaxf.c > +++ b/sysdeps/riscv/rvf/s_fmaxf.c > @@ -17,12 +17,19 @@ > . */ > > #include > +#include > #include > > float > __fmaxf (float x, float y) > { > - asm ("fmax.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); > - return x; > + float res; > + > + if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN)) > + return x + y; > + else > + asm ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); > + > + return res; > } > libm_alias_float (__fmax, fmax) > diff --git a/sysdeps/riscv/rvf/s_fminf.c b/sysdeps/riscv/rvf/s_fminf.c > index e4411f04b2..82cca4e37d 100644 > --- a/sysdeps/riscv/rvf/s_fminf.c > +++ b/sysdeps/riscv/rvf/s_fminf.c > @@ -17,12 +17,19 @@ > . */ > > #include > +#include > #include > > float > __fminf (float x, float y) > { > - asm ("fmin.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); > - return x; > + float res; > + > + if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN)) > + return x + y; > + else > + asm ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); > + > + return res; > } > libm_alias_float (__fmin, fmin) Also looks good, modulo the commit message and ChangeLog. Thanks!