From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: DJ Delorie Newsgroups: gmane.comp.lib.glibc.alpha Subject: riscv: fmax/fmin sNaN fix Date: Mon, 19 Feb 2018 21:57:49 -0500 Message-ID: NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1519095377 19547 195.159.176.226 (20 Feb 2018 02:56:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 20 Feb 2018 02:56:17 +0000 (UTC) To: libc-alpha@sourceware.org Original-X-From: libc-alpha-return-90385-glibc-alpha=m.gmane.org@sourceware.org Tue Feb 20 03:56:13 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:message-id:from:to:subject; q=dns; s= default; b=n+Bw61ly8l26UVyfmFK+vL8TSvCSXmmIja1fFyWaG/MAyR2hF1T9L NDvYp243Pxjc5t0EcEN13MWtnTvaVFTQxjf/V5gsRV0319pAvkMtYeyFtX4PYRXj 1U3BgEBWzFE7JAESz/uM3h3B7vNkfyCIPkVQsYra1Eugwn4GOnZWp4= 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:message-id:from:to:subject; s=default; bh=QK5Pu9tEvLHgbVB2HT30p+P8UVQ=; b=NI5xlwfQBhSTtGfifoPzeVMbRi2Q e2ilxqXIh55izdOLQX5Ta4TuFlrbyv4VV6TbshrizfnL51SYV4Md+DYEnY8avgWn 0TBaS66QlQOGVyC9336sV3ngkWA4SsKCBfJuTj9V3dHTo3KSpN7dLZKYYTwaUrRe pmrrYM45gSSLIw4= 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.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2902 X-HELO: mx1.redhat.com Xref: news.gmane.org gmane.comp.lib.glibc.alpha:83235 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 1eny5v-0003Rl-5v for glibc-alpha@blaine.gmane.org; Tue, 20 Feb 2018 03:55:51 +0100 Received: (qmail 98795 invoked by alias); 20 Feb 2018 02:57:53 -0000 Received: (qmail 98781 invoked by uid 89); 20 Feb 2018 02:57:53 -0000 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)