From patchwork Wed Jun 14 18:30:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 775926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wnwKz6V7Wz9s4s for ; Thu, 15 Jun 2017 04:35:19 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="yKXE1ri+"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:cc:cc:cc:subject:date:message-id :in-reply-to:references; q=dns; s=default; b=rJiE+OmpGk/ngkJvTJa 1SBN6ZZwpkgrcXB0RA8Vq6uC1+cK0BkdIs4KLY+ytBdaYhfTPosep0dOs7zbNs9Y bHUTlzAR0Q12o5/opzNixCY+BMw2h9YCkD9ao0kuMTlp1RWjaMvRDYXfSgdydQNC VrcGZRUR9vG2trWddFH2LDQU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:cc:cc:cc:subject:date:message-id :in-reply-to:references; s=default; bh=WpybRF2AcnBQ//3YeOQDLeO4u RI=; b=yKXE1ri+13cP9GdBiPD06hNxnH5YyQKXWQZD9vHvc2NARSGW+j7VPaQVw 6vUpAjjc+YVCBXE+0pJrNUFNF8yP3BEfMHJoBixhO/LP23b8zXazNvVtTj7DiBXb Jg25JlS33lhpBEKqkX/SXL4L4Ox4vjeTuwIleZnxLTnL9+w/4U= Received: (qmail 99386 invoked by alias); 14 Jun 2017 18:33:25 -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 99156 invoked by uid 89); 14 Jun 2017 18:33:23 -0000 Authentication-Results: sourceware.org; auth=none 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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=cls, mag, UD:l, UD:d.l X-HELO: mail-pg0-f52.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:cc:cc:cc:subject:date:message-id :in-reply-to:references; bh=PO/koZ3S5gZUv4FgEJEG9nOjEWthss5Dr+mhcb+ryjo=; b=ua/OtI9HwE7r8AMFDmSxcaQeiwjqNBfPkAmcOiv/Cwgi8pznkpsIdVM4zvWFpATOyG bRGSbhZhpwLVqab64vPnb5Y0Ly5cS3pIwNmhXAlQygbjSDmIkCc+4ON7KZwlG/zxX4L/ d5X3grPetHM2+806YyBwvkNY7VJECPEO1Ke5eJd0rIKuivem9gSPcfS+e+liB86FfWZa OKn/AKPDOJmMLM+OdT9i9RJMrho1SxrShf6LqcbSEJLMiVbBdyvHEm3C3eP7tfx+qfoH PIsQ5RL7r176tzKgG3fa0DWhaVr85uCX6X825k6KTcJ4EHspmhD7sj8v4ZaI9qs8HrtF UF6Q== X-Gm-Message-State: AKS2vOxTUEBMUpyQJzKxtxzaPrEitUBZgBH+KYSTE/uqIiQIvuGn3Oet Tu2y/RNwfwCTS+x2k+9M1w== X-Received: by 10.84.178.131 with SMTP id z3mr1527733plb.175.1497465194523; Wed, 14 Jun 2017 11:33:14 -0700 (PDT) From: Palmer Dabbelt To: libc-alpha@sourceware.org Cc: Andrew Waterman Cc: patches@groups.riscv.org Cc: Darius Rad Cc: Palmer Dabbelt Subject: [PATCH 08/12] RISC-V: RV32D, RV64F, and RV64D Support Date: Wed, 14 Jun 2017 11:30:44 -0700 Message-Id: <20170614183048.11040-9-palmer@dabbelt.com> In-Reply-To: <20170614183048.11040-1-palmer@dabbelt.com> References: <20170614183048.11040-1-palmer@dabbelt.com> 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/rv64/rvd/s_ceil.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_floor.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llrint.c | 31 ++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llround.c | 31 ++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_nearbyint.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_rint.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_round.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_trunc.c | 50 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llrintf.c | 31 ++++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llroundf.c | 31 ++++++++++++++++++++++ sysdeps/riscv/rvd/e_sqrt.c | 27 +++++++++++++++++++ sysdeps/riscv/rvd/s_copysign.c | 27 +++++++++++++++++++ sysdeps/riscv/rvd/s_fabs.c | 27 +++++++++++++++++++ sysdeps/riscv/rvd/s_finite.c | 28 ++++++++++++++++++++ sysdeps/riscv/rvd/s_fma.c | 29 +++++++++++++++++++++ sysdeps/riscv/rvd/s_fmax.c | 27 +++++++++++++++++++ sysdeps/riscv/rvd/s_fmin.c | 27 +++++++++++++++++++ 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 +++++++++++++++++++ sysdeps/riscv/rvd/s_lrint.c | 33 ++++++++++++++++++++++++ sysdeps/riscv/rvd/s_lround.c | 33 ++++++++++++++++++++++++ 23 files changed, 802 insertions(+) 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_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_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/rvd/e_sqrt.c create mode 100644 sysdeps/riscv/rvd/s_copysign.c create mode 100644 sysdeps/riscv/rvd/s_fabs.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 create mode 100644 sysdeps/riscv/rvd/s_lrint.c create mode 100644 sysdeps/riscv/rvd/s_lround.c diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c new file mode 100644 index 0000000000..93d613cab1 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_ceil.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__ceil (double x) +{ + int flags = riscv_getflags (); + int nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__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 0000000000..db4ad9b153 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_floor.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__floor (double x) +{ + int flags = riscv_getflags (); + int nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__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 0000000000..47a60b9f58 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llrint.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 + . */ + +long long +__llrint (double x) +{ + long long res; + asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__llrint, llrint) +#ifdef __LP64__ +strong_alias (__llrint, __lrint) +weak_alias (__llrint, lrint) +#endif diff --git a/sysdeps/riscv/rv64/rvd/s_llround.c b/sysdeps/riscv/rv64/rvd/s_llround.c new file mode 100644 index 0000000000..4563240509 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llround.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 + . */ + +long long +__llround (double x) +{ + long long res; + asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__llround, llround) +#ifdef __LP64__ +strong_alias (__llround, __lround) +weak_alias (__llround, lround) +#endif diff --git a/sysdeps/riscv/rv64/rvd/s_nearbyint.c b/sysdeps/riscv/rv64/rvd/s_nearbyint.c new file mode 100644 index 0000000000..ea1805d9a0 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__nearbyint (double x) +{ + int flags = riscv_getflags (); + int nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__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 0000000000..08d218178a --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_rint.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__rint (double x) +{ + int nan; + double mag; + + nan = isnan (x); + mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__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 0000000000..5cc3370ba4 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_round.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__round (double x) +{ + int flags = riscv_getflags (); + int nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__round, round) diff --git a/sysdeps/riscv/rv64/rvd/s_trunc.c b/sysdeps/riscv/rv64/rvd/s_trunc.c new file mode 100644 index 0000000000..0b5482025e --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_trunc.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__trunc (double x) +{ + int flags = riscv_getflags (); + int nan = isnan (x); + double mag = fabs (x); + + if (nan) + return x + x; + + if (mag < (1ULL << __DBL_MANT_DIG__)) + { + long 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; +} + +weak_alias (__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 0000000000..5f2bed76af --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_llrintf.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 + . */ + +long long +__llrintf (float x) +{ + long long res; + asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__llrintf, llrintf) +#ifdef __LP64__ +strong_alias (__llrintf, __lrintf) +weak_alias (__llrintf, lrintf) +#endif diff --git a/sysdeps/riscv/rv64/rvf/s_llroundf.c b/sysdeps/riscv/rv64/rvf/s_llroundf.c new file mode 100644 index 0000000000..9f992bfbaf --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_llroundf.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 + . */ + +long long +__llroundf (float x) +{ + long long res; + asm ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__llroundf, llroundf) +#ifdef __LP64__ +strong_alias (__llroundf, __lroundf) +weak_alias (__llroundf, lroundf) +#endif diff --git a/sysdeps/riscv/rvd/e_sqrt.c b/sysdeps/riscv/rvd/e_sqrt.c new file mode 100644 index 0000000000..3dc8a81721 --- /dev/null +++ b/sysdeps/riscv/rvd/e_sqrt.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 0000000000..58b9babd64 --- /dev/null +++ b/sysdeps/riscv/rvd/s_copysign.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__copysign (double x, double y) +{ + asm ("fsgnj.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +weak_alias (__copysign, copysign) diff --git a/sysdeps/riscv/rvd/s_fabs.c b/sysdeps/riscv/rvd/s_fabs.c new file mode 100644 index 0000000000..9c762307ad --- /dev/null +++ b/sysdeps/riscv/rvd/s_fabs.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__fabs (double x) +{ + asm ("fabs.d %0, %1" : "=f" (x) : "f" (x)); + return x; +} +weak_alias (__fabs, fabs) diff --git a/sysdeps/riscv/rvd/s_finite.c b/sysdeps/riscv/rvd/s_finite.c new file mode 100644 index 0000000000..95e51dddf3 --- /dev/null +++ b/sysdeps/riscv/rvd/s_finite.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 0000000000..f1f4adf28b --- /dev/null +++ b/sysdeps/riscv/rvd/s_fma.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 + +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; +} +weak_alias (__fma, fma) diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c new file mode 100644 index 0000000000..c0c6b8ea2b --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmax.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__fmax (double x, double y) +{ + asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +weak_alias (__fmax, fmax) diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c new file mode 100644 index 0000000000..b71c076a60 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmin.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 +__fmin (double x, double y) +{ + asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +weak_alias (__fmin, fmin) diff --git a/sysdeps/riscv/rvd/s_fpclassify.c b/sysdeps/riscv/rvd/s_fpclassify.c new file mode 100644 index 0000000000..b02a7be8cf --- /dev/null +++ b/sysdeps/riscv/rvd/s_fpclassify.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 0000000000..bc2382e5b7 --- /dev/null +++ b/sysdeps/riscv/rvd/s_isinf.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 0000000000..b7567336f6 --- /dev/null +++ b/sysdeps/riscv/rvd/s_isnan.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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; +} +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 0000000000..8853b00bae --- /dev/null +++ b/sysdeps/riscv/rvd/s_issignaling.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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; +} +libm_hidden_def (__issignaling) diff --git a/sysdeps/riscv/rvd/s_lrint.c b/sysdeps/riscv/rvd/s_lrint.c new file mode 100644 index 0000000000..90b4be0184 --- /dev/null +++ b/sysdeps/riscv/rvd/s_lrint.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 __LP64__ + +#include + +long +__lrint (double x) +{ + long res; + asm ("fcvt.w.d %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__lrint, lrint) + +#endif diff --git a/sysdeps/riscv/rvd/s_lround.c b/sysdeps/riscv/rvd/s_lround.c new file mode 100644 index 0000000000..617fc3dcb7 --- /dev/null +++ b/sysdeps/riscv/rvd/s_lround.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by Andrew Waterman (andrew@sifive.com). + 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 __LP64__ + +#include + +long +__lround (double x) +{ + long res; + asm ("fcvt.w.d %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +weak_alias (__lround, lround) + +#endif