From patchwork Sat Jan 13 10:38:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 25381 Received: (qmail 100592 invoked by alias); 13 Jan 2018 10:39:09 -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 100323 invoked by uid 89); 13 Jan 2018 10:39:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 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=958 X-HELO: mail-pl0-f68.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=xZPgYjfzeO5HCtOiXnoKD3docAmyeXCHkuxYxi8BU6Y=; b=Hm2qOekdyqqetX5IeAJuSh9hBehTow2eOLi1x/dzrWrBctJuj0QwGhHeU9EzaWUqt4 BMjEXyJmD2c2Ahq4fSCMTGyZSeGXYJ1mkyqzwuROGtfRKNRVC5YyX22uPORnBv2pea4h +i1zS2sBg4GUJKEJ8gQyECP9GhcRMK0LRVQMQ6+jBY55xg5d8wIP+rX5vgWBcdJY5iCe 9frYG5a7z3lgEGdbFh4ui2Dw09uUEmm46CwwsGuaZdLG8B8pE4HUPcYUQsGrUUsYnM95 amD1MnXNtq9CcLkgkWgr0FK/paziXXX9pJ4sP7U5PI4/iVphIuLhQmuUONvBoxeCdmxQ CJ/A== X-Gm-Message-State: AKwxyte13XzQpleKRFt0mNWEPdp0MT0a4M/zOd/1pSW+1jGDXpzkb60y NkVgOYKILDJ4PLcGUCbgImuJGvSAdec= X-Google-Smtp-Source: ACJfBos9eBarzQPYGY/C2ZMfN6BpgcJJYEdxdPyHeGCFTWEy7UUp8hqAxte5INgJm9nM5a8zYLuW+w== X-Received: by 10.159.229.129 with SMTP id az1mr9196790plb.232.1515839935797; Sat, 13 Jan 2018 02:38:55 -0800 (PST) Subject: [PATCH v4 10/17] RISC-V: RV32D, RV64F, and RV64D Support Date: Sat, 13 Jan 2018 02:38:09 -0800 Message-Id: <20180113103816.4861-11-palmer@dabbelt.com> In-Reply-To: <20180113103816.4861-1-palmer@dabbelt.com> References: <20180113103816.4861-1-palmer@dabbelt.com> Cc: patches@groups.riscv.org, Palmer Dabbelt From: Palmer Dabbelt To: libc-alpha@sourceware.org This patch adds support for the various other hardware floating point configurations that RISC-V supports. This is split from the RV32F patch to avoid mailing list size restrictions. --- sysdeps/riscv/rv32/rvd/s_lrint.c | 31 +++++++++++++++++++++ sysdeps/riscv/rv32/rvd/s_lround.c | 31 +++++++++++++++++++++ sysdeps/riscv/rv32/rvf/s_lrintf.c | 31 +++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_ceil.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_floor.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llrint.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llround.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_lrint.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_lround.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_nearbyint.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_rint.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_round.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_roundeven.c | 53 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_trunc.c | 52 +++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llrintf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llroundf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_lrintf.c | 31 +++++++++++++++++++++ sysdeps/riscv/rvd/e_sqrt.c | 27 ++++++++++++++++++ sysdeps/riscv/rvd/s_copysign.c | 28 +++++++++++++++++++ sysdeps/riscv/rvd/s_finite.c | 28 +++++++++++++++++++ sysdeps/riscv/rvd/s_fma.c | 30 ++++++++++++++++++++ sysdeps/riscv/rvd/s_fmax.c | 28 +++++++++++++++++++ sysdeps/riscv/rvd/s_fmin.c | 28 +++++++++++++++++++ sysdeps/riscv/rvd/s_fpclassify.c | 36 ++++++++++++++++++++++++ sysdeps/riscv/rvd/s_isinf.c | 29 ++++++++++++++++++++ sysdeps/riscv/rvd/s_isnan.c | 28 +++++++++++++++++++ sysdeps/riscv/rvd/s_issignaling.c | 27 ++++++++++++++++++ 27 files changed, 958 insertions(+) create mode 100644 sysdeps/riscv/rv32/rvd/s_lrint.c create mode 100644 sysdeps/riscv/rv32/rvd/s_lround.c create mode 100644 sysdeps/riscv/rv32/rvf/s_lrintf.c create mode 100644 sysdeps/riscv/rv64/rvd/s_ceil.c create mode 100644 sysdeps/riscv/rv64/rvd/s_floor.c create mode 100644 sysdeps/riscv/rv64/rvd/s_llrint.c create mode 100644 sysdeps/riscv/rv64/rvd/s_llround.c create mode 100644 sysdeps/riscv/rv64/rvd/s_lrint.c create mode 100644 sysdeps/riscv/rv64/rvd/s_lround.c create mode 100644 sysdeps/riscv/rv64/rvd/s_nearbyint.c create mode 100644 sysdeps/riscv/rv64/rvd/s_rint.c create mode 100644 sysdeps/riscv/rv64/rvd/s_round.c create mode 100644 sysdeps/riscv/rv64/rvd/s_roundeven.c create mode 100644 sysdeps/riscv/rv64/rvd/s_trunc.c create mode 100644 sysdeps/riscv/rv64/rvf/s_llrintf.c create mode 100644 sysdeps/riscv/rv64/rvf/s_llroundf.c create mode 100644 sysdeps/riscv/rv64/rvf/s_lrintf.c create mode 100644 sysdeps/riscv/rvd/e_sqrt.c create mode 100644 sysdeps/riscv/rvd/s_copysign.c create mode 100644 sysdeps/riscv/rvd/s_finite.c create mode 100644 sysdeps/riscv/rvd/s_fma.c create mode 100644 sysdeps/riscv/rvd/s_fmax.c create mode 100644 sysdeps/riscv/rvd/s_fmin.c create mode 100644 sysdeps/riscv/rvd/s_fpclassify.c create mode 100644 sysdeps/riscv/rvd/s_isinf.c create mode 100644 sysdeps/riscv/rvd/s_isnan.c create mode 100644 sysdeps/riscv/rvd/s_issignaling.c diff --git a/sysdeps/riscv/rv32/rvd/s_lrint.c b/sysdeps/riscv/rv32/rvd/s_lrint.c new file mode 100644 index 000000000000..4d5bdbc200e4 --- /dev/null +++ b/sysdeps/riscv/rv32/rvd/s_lrint.c @@ -0,0 +1,31 @@ +/* lrint(). 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 +__lrint (double x) +{ + int32_t res; + asm ("fcvt.w.d %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__lrint, lrint) diff --git a/sysdeps/riscv/rv32/rvd/s_lround.c b/sysdeps/riscv/rv32/rvd/s_lround.c new file mode 100644 index 000000000000..f5d9cf2e070a --- /dev/null +++ b/sysdeps/riscv/rv32/rvd/s_lround.c @@ -0,0 +1,31 @@ +/* lround(). 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 +__lround (double x) +{ + int32_t res; + asm ("fcvt.w.d %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__lround, lround) diff --git a/sysdeps/riscv/rv32/rvf/s_lrintf.c b/sysdeps/riscv/rv32/rvf/s_lrintf.c new file mode 100644 index 000000000000..08d44fa7385a --- /dev/null +++ b/sysdeps/riscv/rv32/rvf/s_lrintf.c @@ -0,0 +1,31 @@ +/* lrintf(). 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 +__lrintf (float x) +{ + int32_t res; + asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__lrint, lrint) diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c new file mode 100644 index 000000000000..af99ecca3d07 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_ceil.c @@ -0,0 +1,52 @@ +/* ceil(). 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 + +double +__ceil (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1, rup" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %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 = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_double (__ceil, ceil) diff --git a/sysdeps/riscv/rv64/rvd/s_floor.c b/sysdeps/riscv/rv64/rvd/s_floor.c new file mode 100644 index 000000000000..f34af98cce40 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_floor.c @@ -0,0 +1,52 @@ +/* floor(). 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 + +double +__floor (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1, rdn" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %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 = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_double (__floor, floor) diff --git a/sysdeps/riscv/rv64/rvd/s_llrint.c b/sysdeps/riscv/rv64/rvd/s_llrint.c new file mode 100644 index 000000000000..8f37090d743a --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llrint.c @@ -0,0 +1,30 @@ +/* llrint(). 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 + +long long int +__llrint (double x) +{ + int64_t res; + asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__llrint, llrint) diff --git a/sysdeps/riscv/rv64/rvd/s_llround.c b/sysdeps/riscv/rv64/rvd/s_llround.c new file mode 100644 index 000000000000..b7e448876be3 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llround.c @@ -0,0 +1,30 @@ +/* llround(). 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 + +long long int +__llround (double x) +{ + int64_t res; + asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__llround, llround) diff --git a/sysdeps/riscv/rv64/rvd/s_lrint.c b/sysdeps/riscv/rv64/rvd/s_lrint.c new file mode 100644 index 000000000000..48f61be96676 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_lrint.c @@ -0,0 +1,30 @@ +/* lrint(). 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 + +long int +__lrint (double x) +{ + int64_t res; + asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__lrint, lrint) diff --git a/sysdeps/riscv/rv64/rvd/s_lround.c b/sysdeps/riscv/rv64/rvd/s_lround.c new file mode 100644 index 000000000000..392233cd048c --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_lround.c @@ -0,0 +1,30 @@ +/* llround(). 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 + +long int +__lround (double x) +{ + int64_t res; + asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_double (__lround, lround) diff --git a/sysdeps/riscv/rv64/rvd/s_nearbyint.c b/sysdeps/riscv/rv64/rvd/s_nearbyint.c new file mode 100644 index 000000000000..e17f03842908 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c @@ -0,0 +1,52 @@ +/* nearbyint(). 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 + +double +__nearbyint (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %0, %1" : "=f" (new_x) : "r" (i)); + + /* nearbyint(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_double (__nearbyint, nearbyint) diff --git a/sysdeps/riscv/rv64/rvd/s_rint.c b/sysdeps/riscv/rv64/rvd/s_rint.c new file mode 100644 index 000000000000..ef2380ea7fda --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_rint.c @@ -0,0 +1,52 @@ +/* rint(). 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 + +double +__rint (double x) +{ + bool nan; + double mag; + + nan = isnan (x); + mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm ("fcvt.l.d %0, %1" : "=r" (i) : "f" (x)); + asm ("fcvt.d.l %0, %1" : "=f" (new_x) : "r" (i)); + + /* rint(-0) == -0, and in general we'll always have the same + sign as our input. */ + x = copysign (new_x, x); + } + + return x; +} + +libm_alias_double (__rint, rint) diff --git a/sysdeps/riscv/rv64/rvd/s_round.c b/sysdeps/riscv/rv64/rvd/s_round.c new file mode 100644 index 000000000000..22cff63e093b --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_round.c @@ -0,0 +1,52 @@ +/* round(). 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 + +double +__round (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1, rmm" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %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 = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_double (__round, round) diff --git a/sysdeps/riscv/rv64/rvd/s_roundeven.c b/sysdeps/riscv/rv64/rvd/s_roundeven.c new file mode 100644 index 000000000000..26a0b2ded3d1 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_roundeven.c @@ -0,0 +1,53 @@ +/* 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 + +double +__roundeven (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1, rne" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %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 = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +hidden_def (__roundeven) +libm_alias_double (__roundeven, roundeven) diff --git a/sysdeps/riscv/rv64/rvd/s_trunc.c b/sysdeps/riscv/rv64/rvd/s_trunc.c new file mode 100644 index 000000000000..a0f78e6cd186 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_trunc.c @@ -0,0 +1,52 @@ +/* trunc(). 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 + +double +__trunc (double x) +{ + int flags = riscv_getflags (); + bool nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + int64_t i; + double new_x; + + asm volatile ("fcvt.l.d %0, %1, rtz" : "=r" (i) : "f" (x)); + asm volatile ("fcvt.d.l %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 = copysign (new_x, x); + + riscv_setflags (flags); + } + + return x; +} + +libm_alias_double (__trunc, trunc) diff --git a/sysdeps/riscv/rv64/rvf/s_llrintf.c b/sysdeps/riscv/rv64/rvf/s_llrintf.c new file mode 100644 index 000000000000..ddfda6cfe2f6 --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_llrintf.c @@ -0,0 +1,30 @@ +/* Round argument to nearest integral value according to current direction. + 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 + +long long int +__llrintf (float x) +{ + int64_t res; + asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__llrint, llrint) diff --git a/sysdeps/riscv/rv64/rvf/s_llroundf.c b/sysdeps/riscv/rv64/rvf/s_llroundf.c new file mode 100644 index 000000000000..7132f81d2fda --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_llroundf.c @@ -0,0 +1,30 @@ +/* Round float value to long long int. 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 + +long long int +__llroundf (float x) +{ + int64_t res; + asm ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__llround, llround) diff --git a/sysdeps/riscv/rv64/rvf/s_lrintf.c b/sysdeps/riscv/rv64/rvf/s_lrintf.c new file mode 100644 index 000000000000..d8b2fe88bf5a --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_lrintf.c @@ -0,0 +1,31 @@ +/* lrintf(). 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 +__lrintf (float x) +{ + int64_t res; + asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__lrint, lrint) diff --git a/sysdeps/riscv/rvd/e_sqrt.c b/sysdeps/riscv/rvd/e_sqrt.c new file mode 100644 index 000000000000..66627eec21b8 --- /dev/null +++ b/sysdeps/riscv/rvd/e_sqrt.c @@ -0,0 +1,27 @@ +/* Double 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 + +double +__ieee754_sqrt (double x) +{ + asm ("fsqrt.d %0, %1" : "=f" (x) : "f" (x)); + return x; +} +strong_alias (__ieee754_sqrt, __sqrt_finite) diff --git a/sysdeps/riscv/rvd/s_copysign.c b/sysdeps/riscv/rvd/s_copysign.c new file mode 100644 index 000000000000..36fef55aa276 --- /dev/null +++ b/sysdeps/riscv/rvd/s_copysign.c @@ -0,0 +1,28 @@ +/* Copy sign bit between 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 + +double +__copysign (double x, double y) +{ + asm ("fsgnj.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__copysign, copysign) diff --git a/sysdeps/riscv/rvd/s_finite.c b/sysdeps/riscv/rvd/s_finite.c new file mode 100644 index 000000000000..402ae3fa3a0a --- /dev/null +++ b/sysdeps/riscv/rvd/s_finite.c @@ -0,0 +1,28 @@ +/* finite(). 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 +__finite (double x) +{ + return _FCLASS (x) & ~(_FCLASS_INF | _FCLASS_NAN); +} +hidden_def (__finite) +weak_alias (__finite, finite) diff --git a/sysdeps/riscv/rvd/s_fma.c b/sysdeps/riscv/rvd/s_fma.c new file mode 100644 index 000000000000..165557962f18 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fma.c @@ -0,0 +1,30 @@ +/* Double precision floating point fused multiply-add. 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 + +double +__fma (double x, double y, double z) +{ + asm ("fmadd.d %0, %1, %2, %3" : "=f" (x) : "f" (x), "f" (y), "f" (z)); + return x; +} +libm_alias_double (__fma, fma) diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c new file mode 100644 index 000000000000..ef8f1344ce5a --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmax.c @@ -0,0 +1,28 @@ +/* fmax(). 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 + +double +__fmax (double x, double y) +{ + asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmax, fmax) diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c new file mode 100644 index 000000000000..c6ff24cefb8a --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmin.c @@ -0,0 +1,28 @@ +/* fmin(). 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 + +double +__fmin (double x, double y) +{ + asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmin, fmin) diff --git a/sysdeps/riscv/rvd/s_fpclassify.c b/sysdeps/riscv/rvd/s_fpclassify.c new file mode 100644 index 000000000000..fe693c2f4a0f --- /dev/null +++ b/sysdeps/riscv/rvd/s_fpclassify.c @@ -0,0 +1,36 @@ +/* fpclassify(). 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 +__fpclassify (double 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 (__fpclassify) diff --git a/sysdeps/riscv/rvd/s_isinf.c b/sysdeps/riscv/rvd/s_isinf.c new file mode 100644 index 000000000000..1b9767a71839 --- /dev/null +++ b/sysdeps/riscv/rvd/s_isinf.c @@ -0,0 +1,29 @@ +/* isinf(). 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 +__isinf (double x) +{ + int cls = _FCLASS (x); + return -((cls & _FCLASS_MINF) ? 1 : 0) | ((cls & _FCLASS_PINF) ? 1 : 0); +} +hidden_def (__isinf) +weak_alias (__isinf, isinf) diff --git a/sysdeps/riscv/rvd/s_isnan.c b/sysdeps/riscv/rvd/s_isnan.c new file mode 100644 index 000000000000..3739de7ec78a --- /dev/null +++ b/sysdeps/riscv/rvd/s_isnan.c @@ -0,0 +1,28 @@ +/* isnan(). 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 +__isnan (double x) +{ + return (_FCLASS (x) & _FCLASS_NAN) != 0; +} +hidden_def (__isnan) +weak_alias (__isnan, isnan) diff --git a/sysdeps/riscv/rvd/s_issignaling.c b/sysdeps/riscv/rvd/s_issignaling.c new file mode 100644 index 000000000000..1b65206e9af8 --- /dev/null +++ b/sysdeps/riscv/rvd/s_issignaling.c @@ -0,0 +1,27 @@ +/* issignaling(). 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 +__issignaling (double x) +{ + return (_FCLASS (x) & _FCLASS_SNAN) != 0; +} +libm_hidden_def (__issignaling)