From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26663 invoked by alias); 20 Dec 2017 07:24:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 15521 invoked by uid 89); 20 Dec 2017 07:24:08 -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=halfway X-HELO: mail-pl0-f65.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=4R1STDYxWf7V6FJtZstQPxebi1KXmwQGAmcGKOloRBY=; b=TSSCW2Cv3jdeWWurbJ1+7c7DqZgmAfstU5cHHbr8UxNpu9nyBWyYIdsv+FnDd19eai wjJYigkMoSW+CjuQi1P7IxigvFnz+K2eKcjLITeozE0hRcwZKgY7xO24n2gu1skH4fG7 X8XVeAqatWNdiZF8b/KW0BJcc23/iid/AilDzyviTJp3ZGb7TTYfZLzjHialSFIs3+UE 2BTgKShBz1942oBRQFePurfnYW9FD5p47QjLvAE8VfLH5awAOZ7GiJvbakqdYfDHZPFE LPHugSfj99e/bAeMlLUYyYopu00CGcmq4nJN4s7rFsQ0V/upPx9LK1S1XTUAFs4aOUAJ rzcQ== X-Gm-Message-State: AKGB3mKZPEjZqw65dFqIIhilMGIdGV6Nne+F1maa9Liqs6qz//Sscb6Y iMwAY8Qiz4FSZhZDLUV8NIwxiA== X-Google-Smtp-Source: ACJfBosYbmn6Iuuzzxik/DpPLttNx3j/au3GxM5X1NnTW+XHyAIY2qtdNE00CHLD5xaYyR0cG8oLww== X-Received: by 10.159.207.131 with SMTP id z3mr6042401plo.259.1513754637484; Tue, 19 Dec 2017 23:23:57 -0800 (PST) Subject: [PATCH v2 08/15] RISC-V: RV32D, RV64F, and RV64D Support Date: Wed, 20 Dec 2017 07:24:00 -0000 Message-Id: <20171220072022.26909-9-palmer@dabbelt.com> In-Reply-To: <20171220072022.26909-1-palmer@dabbelt.com> References: <20171220072022.26909-1-palmer@dabbelt.com> Cc: Andrew Waterman , Darius Rad , dj@redhat.com, Palmer Dabbelt From: Palmer Dabbelt To: libc-alpha@sourceware.org X-SW-Source: 2017-12/txt/msg00716.txt.bz2 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 | 30 ++++++++++++++++++++ sysdeps/riscv/rv32/rvd/s_lround.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv32/rvf/s_llrintf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv32/rvf/s_lrintf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_ceil.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_floor.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llrint.c | 29 +++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_llround.c | 29 +++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_lrint.c | 29 +++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_lround.c | 29 +++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_nearbyint.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_rint.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_round.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_roundeven.c | 54 ++++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvd/s_trunc.c | 51 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llrintf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_llroundf.c | 30 ++++++++++++++++++++ sysdeps/riscv/rv64/rvf/s_lrintf.c | 30 ++++++++++++++++++++ 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 ++++++++++++++++++ 28 files changed, 975 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_llrintf.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..7a1fff6ffd27 --- /dev/null +++ b/sysdeps/riscv/rv32/rvd/s_lrint.c @@ -0,0 +1,30 @@ +/* lrint(). RISC-V version. + Copyright (C) 2017 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 +__lrint (double x) +{ + long 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..7c2e0b81fbe0 --- /dev/null +++ b/sysdeps/riscv/rv32/rvd/s_lround.c @@ -0,0 +1,30 @@ +/* lround(). RISC-V version. + Copyright (C) 2017 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 +__lround (double x) +{ + long 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_llrintf.c b/sysdeps/riscv/rv32/rvf/s_llrintf.c new file mode 100644 index 000000000000..3de8aa99a7f3 --- /dev/null +++ b/sysdeps/riscv/rv32/rvf/s_llrintf.c @@ -0,0 +1,30 @@ +/* lrintf(). RISC-V version. + Copyright (C) 2017 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 +__llrintf (float x) +{ + long res; + asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__llrint, llrint) diff --git a/sysdeps/riscv/rv32/rvf/s_lrintf.c b/sysdeps/riscv/rv32/rvf/s_lrintf.c new file mode 100644 index 000000000000..806a160ce0d7 --- /dev/null +++ b/sysdeps/riscv/rv32/rvf/s_lrintf.c @@ -0,0 +1,30 @@ +/* lrintf(). RISC-V version. + Copyright (C) 2017 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 +__lrintf (float x) +{ + long 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..7968148b75a9 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_ceil.c @@ -0,0 +1,51 @@ +/* ceil(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..01ec0e06e4ce --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_floor.c @@ -0,0 +1,51 @@ +/* floor(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..77a7b0712f9c --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llrint.c @@ -0,0 +1,29 @@ +/* llrint(). RISC-V version. + Copyright (C) 2017 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 + +long long +__llrint (double x) +{ + long long 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..5df866de7245 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_llround.c @@ -0,0 +1,29 @@ +/* llround(). RISC-V version. + Copyright (C) 2017 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 + +long long +__llround (double x) +{ + long long 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..2d11cc3cd16d --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_lrint.c @@ -0,0 +1,29 @@ +/* lrint(). RISC-V version. + Copyright (C) 2017 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 + +long +__lrint (double x) +{ + long 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..b4f37e15bd2e --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_lround.c @@ -0,0 +1,29 @@ +/* llround(). RISC-V version. + Copyright (C) 2017 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 + +long +__lround (double x) +{ + long 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..aa4399f9c7f3 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c @@ -0,0 +1,51 @@ +/* nearbyint(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..a44d43373dc6 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_rint.c @@ -0,0 +1,51 @@ +/* rint(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..84e4fbfa7997 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_round.c @@ -0,0 +1,51 @@ +/* round(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..145955c3d6fc --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_roundeven.c @@ -0,0 +1,54 @@ +/* Round to nearest integer value, rounding halfway cases to even. + RISC-V version. + Copyright (C) 2017 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 + +double +__roundeven (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, 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..577e9da50554 --- /dev/null +++ b/sysdeps/riscv/rv64/rvd/s_trunc.c @@ -0,0 +1,51 @@ +/* trunc(). RISC-V version. + Copyright (C) 2017 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 + +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; +} + +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..69f4e8ea9b56 --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_llrintf.c @@ -0,0 +1,30 @@ +/* Round argument to nearest integral value according to current rounding + direction. RISC-V version. + Copyright (C) 2017 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 + +long long +__llrintf (float x) +{ + long long 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..5b69c01648ec --- /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 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 +__llroundf (float x) +{ + long long 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..cb28ffe1b536 --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_lrintf.c @@ -0,0 +1,30 @@ +/* lrintf(). RISC-V version. + Copyright (C) 2017 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 +__lrintf (float x) +{ + long 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..ceac9f4c34a4 --- /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 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..d3a5000a6e7b --- /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 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..06914e1c1e71 --- /dev/null +++ b/sysdeps/riscv/rvd/s_finite.c @@ -0,0 +1,28 @@ +/* finite(). RISC-V version. + Copyright (C) 2017 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..ff74857cf578 --- /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 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..b108434cd64b --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmax.c @@ -0,0 +1,28 @@ +/* fmax(). RISC-V version. + Copyright (C) 2017 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..4894377602c3 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmin.c @@ -0,0 +1,28 @@ +/* fmin(). RISC-V version. + Copyright (C) 2017 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..cdfdbdfbc1e2 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fpclassify.c @@ -0,0 +1,36 @@ +/* fpclassify(). RISC-V version. + Copyright (C) 2017 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..92d2f2c261bc --- /dev/null +++ b/sysdeps/riscv/rvd/s_isinf.c @@ -0,0 +1,29 @@ +/* isinf(). RISC-V version. + Copyright (C) 2017 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..e88b47287952 --- /dev/null +++ b/sysdeps/riscv/rvd/s_isnan.c @@ -0,0 +1,28 @@ +/* isnan(). RISC_V version. + Copyright (C) 2017 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; +} +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..6136d7e7f33f --- /dev/null +++ b/sysdeps/riscv/rvd/s_issignaling.c @@ -0,0 +1,27 @@ +/* issignaling(). RISC-V version. + Copyright (C) 2017 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; +} +libm_hidden_def (__issignaling) -- 2.13.6