From patchwork Thu Jan 25 04:36:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 25519 Received: (qmail 21877 invoked by alias); 25 Jan 2018 04:37:04 -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 Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21781 invoked by uid 89); 25 Jan 2018 04:37:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=frm, cls, Round, HX-Received:9343 X-HELO: mail-pf0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=pkhb0Cm5mzc7Bloqre+M2iHB4dz6LEbtN5DcfgBhmnI=; b=rONc7WgydcJlAKL19M3wf41wTiT5cXTAHlpcjglKI8VL2xcf97uAQdaK6UMA7w0J0Z Sn0ZUL5hqlTPZOnnLSq3iu2UNvHX+UC/b/51SvvEUCCKk4t1wXMIZsAuzXRVsrJQwsnp 9uKMmV31/dnW/Z2cOsOiL/M7RasDc/y0HSqPykFJ6FS43aF1b0VQFaUv98+Gyn+Qc7/q 4cMFF+dk2/PeEKZXAT/KXIGnU6vq9Ts4JdJqcEOpsdg9uGK6JrMq65y2ooJjJOJtB7oa Ka6FU48pzUdmnAcq+DAvvksC0uEm7hF7B+MGBJFdbLRi3WQPF884vul1tCm4imEqT5gx XlVw== X-Gm-Message-State: AKwxytciCUqUrotD/QaF7jLorVJy0YZzsoCVxZAQtNWX3dcS3BACTbYY E8Wc4DGUzN3wenB+Yw6yWi/rkw== X-Google-Smtp-Source: AH8x227KlGhQyGpTFlpLF5dkKQos8Y4Q1XK9SU6ODK4wQdqa5OydbKunWgWmN5FDLQxMUA0naiiHiQ== X-Received: by 2002:a17:902:9343:: with SMTP id g3-v6mr10329785plp.319.1516855009865; Wed, 24 Jan 2018 20:36:49 -0800 (PST) Subject: [PATCH 09/17] RISC-V: RV32F Support Date: Wed, 24 Jan 2018 20:36:13 -0800 Message-Id: <20180125043621.19972-10-palmer@dabbelt.com> In-Reply-To: <20180125043621.19972-1-palmer@dabbelt.com> References: <20180125043621.19972-1-palmer@dabbelt.com> Cc: Andrew Waterman , Darius Rad , dj@redhat.com, patches@groups.riscv.org, Palmer Dabbelt From: Palmer Dabbelt To: libc-alpha@sourceware.org, joseph@codesourcery.com This contains the base floating-point support for RISC-V, which is defined by the F extension. The code in this patch sufficies to implement RV32F systems only, additional routines are necessary to add support for RV32D, RV64F, and RV64D. These additional routines have been split out to avoid having too large of a patch. --- sysdeps/riscv/rv32/rvf/s_lroundf.c | 31 +++++++ sysdeps/riscv/rvf/e_sqrtf.c | 27 ++++++ sysdeps/riscv/rvf/fclrexcpt.c | 28 ++++++ sysdeps/riscv/rvf/fegetenv.c | 32 +++++++ sysdeps/riscv/rvf/fegetmode.c | 27 ++++++ sysdeps/riscv/rvf/fegetround.c | 29 ++++++ sysdeps/riscv/rvf/feholdexcpt.c | 30 +++++++ sysdeps/riscv/rvf/fesetenv.c | 30 +++++++ sysdeps/riscv/rvf/fesetexcept.c | 26 ++++++ sysdeps/riscv/rvf/fesetmode.c | 31 +++++++ sysdeps/riscv/rvf/fesetround.c | 39 ++++++++ sysdeps/riscv/rvf/feupdateenv.c | 30 +++++++ sysdeps/riscv/rvf/fgetexcptflg.c | 30 +++++++ sysdeps/riscv/rvf/fraiseexcpt.c | 30 +++++++ sysdeps/riscv/rvf/fsetexcptflg.c | 30 +++++++ sysdeps/riscv/rvf/ftestexcept.c | 27 ++++++ sysdeps/riscv/rvf/get-rounding-mode.h | 32 +++++++ sysdeps/riscv/rvf/math_private.h | 161 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_ceilf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_copysignf.c | 28 ++++++ sysdeps/riscv/rvf/s_finitef.c | 28 ++++++ sysdeps/riscv/rvf/s_floorf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_fmaf.c | 30 +++++++ sysdeps/riscv/rvf/s_fmaxf.c | 28 ++++++ sysdeps/riscv/rvf/s_fminf.c | 28 ++++++ sysdeps/riscv/rvf/s_fpclassifyf.c | 36 ++++++++ sysdeps/riscv/rvf/s_isinff.c | 29 ++++++ sysdeps/riscv/rvf/s_isnanf.c | 28 ++++++ sysdeps/riscv/rvf/s_issignalingf.c | 27 ++++++ sysdeps/riscv/rvf/s_nearbyintf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_rintf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_roundevenf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_roundf.c | 52 +++++++++++ sysdeps/riscv/rvf/s_truncf.c | 52 +++++++++++ 34 files changed, 1296 insertions(+) create mode 100644 sysdeps/riscv/rv32/rvf/s_lroundf.c create mode 100644 sysdeps/riscv/rvf/e_sqrtf.c create mode 100644 sysdeps/riscv/rvf/fclrexcpt.c create mode 100644 sysdeps/riscv/rvf/fegetenv.c create mode 100644 sysdeps/riscv/rvf/fegetmode.c create mode 100644 sysdeps/riscv/rvf/fegetround.c create mode 100644 sysdeps/riscv/rvf/feholdexcpt.c create mode 100644 sysdeps/riscv/rvf/fesetenv.c create mode 100644 sysdeps/riscv/rvf/fesetexcept.c create mode 100644 sysdeps/riscv/rvf/fesetmode.c create mode 100644 sysdeps/riscv/rvf/fesetround.c create mode 100644 sysdeps/riscv/rvf/feupdateenv.c create mode 100644 sysdeps/riscv/rvf/fgetexcptflg.c create mode 100644 sysdeps/riscv/rvf/fraiseexcpt.c create mode 100644 sysdeps/riscv/rvf/fsetexcptflg.c create mode 100644 sysdeps/riscv/rvf/ftestexcept.c create mode 100644 sysdeps/riscv/rvf/get-rounding-mode.h create mode 100644 sysdeps/riscv/rvf/math_private.h create mode 100644 sysdeps/riscv/rvf/s_ceilf.c create mode 100644 sysdeps/riscv/rvf/s_copysignf.c create mode 100644 sysdeps/riscv/rvf/s_finitef.c create mode 100644 sysdeps/riscv/rvf/s_floorf.c create mode 100644 sysdeps/riscv/rvf/s_fmaf.c create mode 100644 sysdeps/riscv/rvf/s_fmaxf.c create mode 100644 sysdeps/riscv/rvf/s_fminf.c create mode 100644 sysdeps/riscv/rvf/s_fpclassifyf.c create mode 100644 sysdeps/riscv/rvf/s_isinff.c create mode 100644 sysdeps/riscv/rvf/s_isnanf.c create mode 100644 sysdeps/riscv/rvf/s_issignalingf.c create mode 100644 sysdeps/riscv/rvf/s_nearbyintf.c create mode 100644 sysdeps/riscv/rvf/s_rintf.c create mode 100644 sysdeps/riscv/rvf/s_roundevenf.c create mode 100644 sysdeps/riscv/rvf/s_roundf.c create mode 100644 sysdeps/riscv/rvf/s_truncf.c diff --git a/sysdeps/riscv/rv32/rvf/s_lroundf.c b/sysdeps/riscv/rv32/rvf/s_lroundf.c new file mode 100644 index 000000000000..f31b43293627 --- /dev/null +++ b/sysdeps/riscv/rv32/rvf/s_lroundf.c @@ -0,0 +1,31 @@ +/* lroundf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + +long int +__lroundf (float x) +{ + int32_t res; + asm ("fcvt.w.s %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__lround, lround) diff --git a/sysdeps/riscv/rvf/e_sqrtf.c b/sysdeps/riscv/rvf/e_sqrtf.c new file mode 100644 index 000000000000..711d93e43060 --- /dev/null +++ b/sysdeps/riscv/rvf/e_sqrtf.c @@ -0,0 +1,27 @@ +/* Single precision floating point square root. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +float +__ieee754_sqrtf (float x) +{ + asm ("fsqrt.s %0, %1" : "=f" (x) : "f" (x)); + return x; +} +strong_alias (__ieee754_sqrtf, __sqrtf_finite) diff --git a/sysdeps/riscv/rvf/fclrexcpt.c b/sysdeps/riscv/rvf/fclrexcpt.c new file mode 100644 index 000000000000..bdad377e88da --- /dev/null +++ b/sysdeps/riscv/rvf/fclrexcpt.c @@ -0,0 +1,28 @@ +/* Clear given exceptions in current floating-point environment. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +feclearexcept (int excepts) +{ + asm volatile ("csrc fflags, %0" : : "r" (excepts)); + return 0; +} +libm_hidden_def (feclearexcept) diff --git a/sysdeps/riscv/rvf/fegetenv.c b/sysdeps/riscv/rvf/fegetenv.c new file mode 100644 index 000000000000..1c29413be5d2 --- /dev/null +++ b/sysdeps/riscv/rvf/fegetenv.c @@ -0,0 +1,32 @@ +/* Store current floating-point environment. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fegetenv (fenv_t *envp) +{ + _FPU_GETCW (*envp); + + /* Success. */ + return 0; +} +libm_hidden_def (__fegetenv) +weak_alias (__fegetenv, fegetenv) +libm_hidden_weak (fegetenv) diff --git a/sysdeps/riscv/rvf/fegetmode.c b/sysdeps/riscv/rvf/fegetmode.c new file mode 100644 index 000000000000..67ae14c4ffdd --- /dev/null +++ b/sysdeps/riscv/rvf/fegetmode.c @@ -0,0 +1,27 @@ +/* Store current floating-point control modes. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +int +fegetmode (femode_t *modep) +{ + _FPU_GETCW (*modep); + return 0; +} diff --git a/sysdeps/riscv/rvf/fegetround.c b/sysdeps/riscv/rvf/fegetround.c new file mode 100644 index 000000000000..f7692a827b85 --- /dev/null +++ b/sysdeps/riscv/rvf/fegetround.c @@ -0,0 +1,29 @@ +/* Return current rounding direction. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fegetround (void) +{ + return riscv_getround (); +} +libm_hidden_def (__fegetround) +weak_alias (__fegetround, fegetround) +libm_hidden_weak (fegetround) diff --git a/sysdeps/riscv/rvf/feholdexcpt.c b/sysdeps/riscv/rvf/feholdexcpt.c new file mode 100644 index 000000000000..ea9060f3dcd7 --- /dev/null +++ b/sysdeps/riscv/rvf/feholdexcpt.c @@ -0,0 +1,30 @@ +/* Store current floating-point environment and clear exceptions. + Copyright (C) 2000-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__feholdexcept (fenv_t *envp) +{ + libc_feholdexcept_riscv (envp); + return 0; +} +libm_hidden_def (__feholdexcept) +weak_alias (__feholdexcept, feholdexcept) +libm_hidden_weak (feholdexcept) diff --git a/sysdeps/riscv/rvf/fesetenv.c b/sysdeps/riscv/rvf/fesetenv.c new file mode 100644 index 000000000000..5d02d8010153 --- /dev/null +++ b/sysdeps/riscv/rvf/fesetenv.c @@ -0,0 +1,30 @@ +/* Install given floating-point environment. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fesetenv (const fenv_t *envp) +{ + libc_fesetenv_riscv (envp); + return 0; +} +libm_hidden_def (__fesetenv) +weak_alias (__fesetenv, fesetenv) +libm_hidden_weak (fesetenv) diff --git a/sysdeps/riscv/rvf/fesetexcept.c b/sysdeps/riscv/rvf/fesetexcept.c new file mode 100644 index 000000000000..70059aa61a20 --- /dev/null +++ b/sysdeps/riscv/rvf/fesetexcept.c @@ -0,0 +1,26 @@ +/* Set given exception flags. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +int +fesetexcept (int excepts) +{ + asm volatile ("csrs fflags, %0" : : "r" (excepts)); + return 0; +} diff --git a/sysdeps/riscv/rvf/fesetmode.c b/sysdeps/riscv/rvf/fesetmode.c new file mode 100644 index 000000000000..d39c5626fe09 --- /dev/null +++ b/sysdeps/riscv/rvf/fesetmode.c @@ -0,0 +1,31 @@ +/* Install given floating-point control modes. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +int +fesetmode (const femode_t *modep) +{ + asm volatile ("csrc fcsr, %0" : : "r" (~FE_ALL_EXCEPT)); + + if (modep != FE_DFL_MODE) + asm volatile ("csrs fcsr, %0" : : "r" (*modep & ~FE_ALL_EXCEPT)); + + return 0; +} diff --git a/sysdeps/riscv/rvf/fesetround.c b/sysdeps/riscv/rvf/fesetround.c new file mode 100644 index 000000000000..bf705ef0c980 --- /dev/null +++ b/sysdeps/riscv/rvf/fesetround.c @@ -0,0 +1,39 @@ +/* Set current rounding direction. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fesetround (int round) +{ + switch (round) + { + case FE_TONEAREST: + case FE_TOWARDZERO: + case FE_DOWNWARD: + case FE_UPWARD: + riscv_setround (round); + return 0; + default: + return round; /* A nonzero value. */ + } +} +libm_hidden_def (__fesetround) +weak_alias (__fesetround, fesetround) +libm_hidden_weak (fesetround) diff --git a/sysdeps/riscv/rvf/feupdateenv.c b/sysdeps/riscv/rvf/feupdateenv.c new file mode 100644 index 000000000000..133d7eca1126 --- /dev/null +++ b/sysdeps/riscv/rvf/feupdateenv.c @@ -0,0 +1,30 @@ +/* Install given floating-point environment and raise exceptions. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__feupdateenv (const fenv_t *envp) +{ + libc_feupdateenv_riscv (envp); + return 0; +} +libm_hidden_def (__feupdateenv) +weak_alias (__feupdateenv, feupdateenv) +libm_hidden_weak (feupdateenv) diff --git a/sysdeps/riscv/rvf/fgetexcptflg.c b/sysdeps/riscv/rvf/fgetexcptflg.c new file mode 100644 index 000000000000..367f0135d41b --- /dev/null +++ b/sysdeps/riscv/rvf/fgetexcptflg.c @@ -0,0 +1,30 @@ +/* Store current representation for exceptions. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +fegetexceptflag (fexcept_t *flagp, int excepts) +{ + /* Get the current exceptions. */ + *flagp = riscv_getflags () & excepts; + + /* Success. */ + return 0; +} diff --git a/sysdeps/riscv/rvf/fraiseexcpt.c b/sysdeps/riscv/rvf/fraiseexcpt.c new file mode 100644 index 000000000000..dee90c3476c2 --- /dev/null +++ b/sysdeps/riscv/rvf/fraiseexcpt.c @@ -0,0 +1,30 @@ +/* Raise given exceptions. + Copyright (C) 2000-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__feraiseexcept (int excepts) +{ + asm volatile ("csrs fflags, %0" : : "r" (excepts)); + return 0; +} +libm_hidden_def (__feraiseexcept) +weak_alias (__feraiseexcept, feraiseexcept) +libm_hidden_weak (feraiseexcept) diff --git a/sysdeps/riscv/rvf/fsetexcptflg.c b/sysdeps/riscv/rvf/fsetexcptflg.c new file mode 100644 index 000000000000..9e5bebf28994 --- /dev/null +++ b/sysdeps/riscv/rvf/fsetexcptflg.c @@ -0,0 +1,30 @@ +/* Set floating-point environment exception handling. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +fesetexceptflag (const fexcept_t *flagp, int excepts) +{ + fexcept_t flags = *flagp; + asm volatile ("csrc fflags, %0" : : "r" (excepts)); + asm volatile ("csrs fflags, %0" : : "r" (flags & excepts)); + + return 0; +} diff --git a/sysdeps/riscv/rvf/ftestexcept.c b/sysdeps/riscv/rvf/ftestexcept.c new file mode 100644 index 000000000000..a248bd63190c --- /dev/null +++ b/sysdeps/riscv/rvf/ftestexcept.c @@ -0,0 +1,27 @@ +/* Test exception in current environment. + Copyright (C) 1998-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +fetestexcept (int excepts) +{ + return libc_fetestexcept_riscv (excepts); +} +libm_hidden_def (fetestexcept) diff --git a/sysdeps/riscv/rvf/get-rounding-mode.h b/sysdeps/riscv/rvf/get-rounding-mode.h new file mode 100644 index 000000000000..42891324ddc3 --- /dev/null +++ b/sysdeps/riscv/rvf/get-rounding-mode.h @@ -0,0 +1,32 @@ +/* Determine floating-point rounding mode within libc. RISC-V version. + Copyright (C) 2015-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _RISCV_GET_ROUNDING_MODE_H +#define _RISCV_GET_ROUNDING_MODE_H + +/* Return the floating-point rounding mode. */ + +static inline int +get_rounding_mode (void) +{ + int rm; + asm volatile ("frrm %0" : "=r" (rm)); + return rm; +} + +#endif /* get-rounding-mode.h */ diff --git a/sysdeps/riscv/rvf/math_private.h b/sysdeps/riscv/rvf/math_private.h new file mode 100644 index 000000000000..cdb7858fc8ce --- /dev/null +++ b/sysdeps/riscv/rvf/math_private.h @@ -0,0 +1,161 @@ +/* Private floating point rounding and exceptions handling. RISC-V version. + Copyright (C) 2014-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef RISCV_MATH_PRIVATE_H +#define RISCV_MATH_PRIVATE_H 1 + +#include +#include +#include + +static __always_inline int +riscv_getround (void) +{ + return get_rounding_mode (); +} + +static __always_inline void +riscv_setround (int rm) +{ + asm volatile ("fsrm %z0" : : "rJ" (rm)); +} + +static __always_inline int +riscv_getflags (void) +{ + int flags; + asm volatile ("frflags %0" : "=r" (flags)); + return flags; +} + +static __always_inline void +riscv_setflags (int flags) +{ + asm volatile ("fsflags %z0" : : "rJ" (flags)); +} + +static __always_inline void +libc_feholdexcept_riscv (fenv_t *envp) +{ + asm volatile ("csrrc %0, fcsr, %1" : "=r" (*envp) : "i" (FE_ALL_EXCEPT)); +} + +#define libc_feholdexcept libc_feholdexcept_riscv +#define libc_feholdexceptf libc_feholdexcept_riscv +#define libc_feholdexceptl libc_feholdexcept_riscv + +static __always_inline void +libc_fesetround_riscv (int round) +{ + riscv_setround (round); +} + +#define libc_fesetround libc_fesetround_riscv +#define libc_fesetroundf libc_fesetround_riscv +#define libc_fesetroundl libc_fesetround_riscv + +static __always_inline void +libc_feholdexcept_setround_riscv (fenv_t *envp, int round) +{ + libc_fesetround_riscv (round); + libc_feholdexcept_riscv (envp); +} + +#define libc_feholdexcept_setround libc_feholdexcept_setround_riscv +#define libc_feholdexcept_setroundf libc_feholdexcept_setround_riscv +#define libc_feholdexcept_setroundl libc_feholdexcept_setround_riscv + +static __always_inline int +libc_fetestexcept_riscv (int ex) +{ + return riscv_getflags () & ex; +} + +#define libc_fetestexcept libc_fetestexcept_riscv +#define libc_fetestexceptf libc_fetestexcept_riscv +#define libc_fetestexceptl libc_fetestexcept_riscv + +static __always_inline void +libc_fesetenv_riscv (const fenv_t *envp) +{ + long int env = (long int) envp - (long int) FE_DFL_ENV; + if (env != 0) + env = *envp; + + _FPU_SETCW (env); +} + +#define libc_fesetenv libc_fesetenv_riscv +#define libc_fesetenvf libc_fesetenv_riscv +#define libc_fesetenvl libc_fesetenv_riscv +#define libc_feresetround_noex libc_fesetenv_riscv +#define libc_feresetround_noexf libc_fesetenv_riscv +#define libc_feresetround_noexl libc_fesetenv_riscv + +static __always_inline int +libc_feupdateenv_test_riscv (const fenv_t *envp, int ex) +{ + fenv_t env = *envp; + int flags = riscv_getflags (); + asm volatile ("csrw fcsr, %z0" : : "rJ" (env | flags)); + return flags & ex; +} + +#define libc_feupdateenv_test libc_feupdateenv_test_riscv +#define libc_feupdateenv_testf libc_feupdateenv_test_riscv +#define libc_feupdateenv_testl libc_feupdateenv_test_riscv + +static __always_inline void +libc_feupdateenv_riscv (const fenv_t *envp) +{ + _FPU_SETCW (*envp | riscv_getflags ()); +} + +#define libc_feupdateenv libc_feupdateenv_riscv +#define libc_feupdateenvf libc_feupdateenv_riscv +#define libc_feupdateenvl libc_feupdateenv_riscv + +static __always_inline void +libc_feholdsetround_riscv (fenv_t *envp, int round) +{ + /* Note this implementation makes an improperly-formatted fenv_t and + so should only be used in conjunction with libc_feresetround. */ + int old_round; + asm volatile ("csrrw %0, frm, %z1" : "=r" (old_round) : "rJ" (round)); + *envp = old_round; +} + +#define libc_feholdsetround libc_feholdsetround_riscv +#define libc_feholdsetroundf libc_feholdsetround_riscv +#define libc_feholdsetroundl libc_feholdsetround_riscv + +static __always_inline void +libc_feresetround_riscv (fenv_t *envp) +{ + /* Note this implementation takes an improperly-formatted fenv_t and + so should only be used in conjunction with libc_feholdsetround. */ + riscv_setround (*envp); +} + +#define libc_feresetround libc_feresetround_riscv +#define libc_feresetroundf libc_feresetround_riscv +#define libc_feresetroundl libc_feresetround_riscv + +#include_next + +#endif diff --git a/sysdeps/riscv/rvf/s_ceilf.c b/sysdeps/riscv/rvf/s_ceilf.c new file mode 100644 index 000000000000..d7e291acf8c0 --- /dev/null +++ b/sysdeps/riscv/rvf/s_ceilf.c @@ -0,0 +1,52 @@ +/* ceilf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__ceilf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1, rup" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1, rup" : "=f" (new_x) : "r" (i)); + + /* ceil(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__ceil, ceil) diff --git a/sysdeps/riscv/rvf/s_copysignf.c b/sysdeps/riscv/rvf/s_copysignf.c new file mode 100644 index 000000000000..4d1c122f7ea5 --- /dev/null +++ b/sysdeps/riscv/rvf/s_copysignf.c @@ -0,0 +1,28 @@ +/* copysignf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +float +__copysignf (float x, float y) +{ + asm ("fsgnj.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__copysign, copysign) diff --git a/sysdeps/riscv/rvf/s_finitef.c b/sysdeps/riscv/rvf/s_finitef.c new file mode 100644 index 000000000000..04ce08719b4b --- /dev/null +++ b/sysdeps/riscv/rvf/s_finitef.c @@ -0,0 +1,28 @@ +/* finitef(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__finitef (float x) +{ + return _FCLASS (x) & ~(_FCLASS_INF | _FCLASS_NAN); +} +hidden_def (__finitef) +weak_alias (__finitef, finitef) diff --git a/sysdeps/riscv/rvf/s_floorf.c b/sysdeps/riscv/rvf/s_floorf.c new file mode 100644 index 000000000000..3c9c625e2f2a --- /dev/null +++ b/sysdeps/riscv/rvf/s_floorf.c @@ -0,0 +1,52 @@ +/* floorf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__floorf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1, rdn" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1, rdn" : "=f" (new_x) : "r" (i)); + + /* floor(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__floor, floor) diff --git a/sysdeps/riscv/rvf/s_fmaf.c b/sysdeps/riscv/rvf/s_fmaf.c new file mode 100644 index 000000000000..946e7ed0c915 --- /dev/null +++ b/sysdeps/riscv/rvf/s_fmaf.c @@ -0,0 +1,30 @@ +/* fmaf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__fmaf (float x, float y, float z) +{ + asm ("fmadd.s %0, %1, %2, %3" : "=f" (x) : "f" (x), "f" (y), "f" (z)); + return x; +} +libm_alias_float (__fma, fma) diff --git a/sysdeps/riscv/rvf/s_fmaxf.c b/sysdeps/riscv/rvf/s_fmaxf.c new file mode 100644 index 000000000000..3293f2f41ca1 --- /dev/null +++ b/sysdeps/riscv/rvf/s_fmaxf.c @@ -0,0 +1,28 @@ +/* fmaxf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +float +__fmaxf (float x, float y) +{ + asm ("fmax.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fmax, fmax) diff --git a/sysdeps/riscv/rvf/s_fminf.c b/sysdeps/riscv/rvf/s_fminf.c new file mode 100644 index 000000000000..e4411f04b25c --- /dev/null +++ b/sysdeps/riscv/rvf/s_fminf.c @@ -0,0 +1,28 @@ +/* fminf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +float +__fminf (float x, float y) +{ + asm ("fmin.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fmin, fmin) diff --git a/sysdeps/riscv/rvf/s_fpclassifyf.c b/sysdeps/riscv/rvf/s_fpclassifyf.c new file mode 100644 index 000000000000..4abcf3edac59 --- /dev/null +++ b/sysdeps/riscv/rvf/s_fpclassifyf.c @@ -0,0 +1,36 @@ +/* fpclassifyf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__fpclassifyf (float x) +{ + int cls = _FCLASS (x); + if (__builtin_expect (cls & _FCLASS_NORM, _FCLASS_NORM)) + return FP_NORMAL; + if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO)) + return FP_ZERO; + if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM)) + return FP_SUBNORMAL; + if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF)) + return FP_INFINITE; + return FP_NAN; +} +libm_hidden_def (__fpclassifyf) diff --git a/sysdeps/riscv/rvf/s_isinff.c b/sysdeps/riscv/rvf/s_isinff.c new file mode 100644 index 000000000000..1c7413190cdf --- /dev/null +++ b/sysdeps/riscv/rvf/s_isinff.c @@ -0,0 +1,29 @@ +/* isinff(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__isinff (float x) +{ + int cls = _FCLASS (x); + return -((cls & _FCLASS_MINF) ? 1 : 0) | ((cls & _FCLASS_PINF) ? 1 : 0); +} +hidden_def (__isinff) +weak_alias (__isinff, isinff) diff --git a/sysdeps/riscv/rvf/s_isnanf.c b/sysdeps/riscv/rvf/s_isnanf.c new file mode 100644 index 000000000000..30a88bb23c26 --- /dev/null +++ b/sysdeps/riscv/rvf/s_isnanf.c @@ -0,0 +1,28 @@ +/* isnanf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__isnanf (float x) +{ + return (_FCLASS (x) & _FCLASS_NAN) != 0; +} +hidden_def (__isnanf) +weak_alias (__isnanf, isnanf) diff --git a/sysdeps/riscv/rvf/s_issignalingf.c b/sysdeps/riscv/rvf/s_issignalingf.c new file mode 100644 index 000000000000..e67efc794b71 --- /dev/null +++ b/sysdeps/riscv/rvf/s_issignalingf.c @@ -0,0 +1,27 @@ +/* issignalingf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include + +int +__issignalingf (float x) +{ + return (_FCLASS (x) & _FCLASS_SNAN) != 0; +} +libm_hidden_def (__issignalingf) diff --git a/sysdeps/riscv/rvf/s_nearbyintf.c b/sysdeps/riscv/rvf/s_nearbyintf.c new file mode 100644 index 000000000000..d653794d7174 --- /dev/null +++ b/sysdeps/riscv/rvf/s_nearbyintf.c @@ -0,0 +1,52 @@ +/* Round to int floating-point values. RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__nearbyintf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1" : "=f" (new_x) : "r" (i)); + + /* nearbyint(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__nearbyint, nearbyint) diff --git a/sysdeps/riscv/rvf/s_rintf.c b/sysdeps/riscv/rvf/s_rintf.c new file mode 100644 index 000000000000..2ec3877a4fb6 --- /dev/null +++ b/sysdeps/riscv/rvf/s_rintf.c @@ -0,0 +1,52 @@ +/* rintf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__rintf (float x) +{ + bool nan; + float mag; + + nan = isnan (x); + mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm ("fcvt.w.s %0, %1" : "=r" (i) : "f" (x)); + asm ("fcvt.s.w %0, %1" : "=f" (new_x) : "r" (i)); + + /* rint(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + } + + return x; +} + +libm_alias_float (__rint, rint) diff --git a/sysdeps/riscv/rvf/s_roundevenf.c b/sysdeps/riscv/rvf/s_roundevenf.c new file mode 100644 index 000000000000..48086c28ee53 --- /dev/null +++ b/sysdeps/riscv/rvf/s_roundevenf.c @@ -0,0 +1,52 @@ +/* Round to nearest integer value, rounding halfway cases to even. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +float +__roundevenf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1, rne" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1, rne" : "=f" (new_x) : "r" (i)); + + /* roundeven(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__roundeven, roundeven) diff --git a/sysdeps/riscv/rvf/s_roundf.c b/sysdeps/riscv/rvf/s_roundf.c new file mode 100644 index 000000000000..dedf57cbb340 --- /dev/null +++ b/sysdeps/riscv/rvf/s_roundf.c @@ -0,0 +1,52 @@ +/* roundf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__roundf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1, rmm" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1, rmm" : "=f" (new_x) : "r" (i)); + + /* round(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__round, round) diff --git a/sysdeps/riscv/rvf/s_truncf.c b/sysdeps/riscv/rvf/s_truncf.c new file mode 100644 index 000000000000..e23926a2aeeb --- /dev/null +++ b/sysdeps/riscv/rvf/s_truncf.c @@ -0,0 +1,52 @@ +/* truncf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include +#include + +float +__truncf (float x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + float mag = fabsf (x); + + if (nan) + return x + x; + + if (mag < (1 << __FLT_MANT_DIG__)) + { + int32_t i; + float new_x; + + asm volatile ("fcvt.w.s %0, %1, rtz" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.s.w %0, %1, rtz" : "=f" (new_x) : "r" (i)); + + /* trunc(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysignf (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_float (__trunc, trunc)