From b2cb5e0298e08b486190610a9e82356ccb6f564b Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Mon, 29 Jan 2018 09:27:10 -0800 Subject: RISC-V: Hard Float Support This patch contains hardware floating-point support for the RISC-V ISA. While we currently only support hard-float systems with both the F and D extensions, I've left the F-specific code split out into seperate folders in order to ease adding support for F-only and RV32I-based systems in the future. I gave this a quick once-over and believe I've removed all the code that implements RV32IF, RV32IFD, and RV64IF targets. 2018-01-29 Palmer Dabbelt * sysdeps/riscv/rv64/rvd/s_ceil.c: New file. * sysdeps/riscv/rv64/rvd/s_floor.c: Likewise. * sysdeps/riscv/rv64/rvd/s_llrint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_llround.c: Likewise. * sysdeps/riscv/rv64/rvd/s_lrint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_lround.c: Likewise. * sysdeps/riscv/rv64/rvd/s_nearbyint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_rint.c: Likewise. * sysdeps/riscv/rv64/rvd/s_round.c: Likewise. * sysdeps/riscv/rv64/rvd/s_roundeven.c: Likewise. * sysdeps/riscv/rv64/rvd/s_trunc.c: Likewise. * sysdeps/riscv/rv64/rvf/s_llrintf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_llroundf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_lrintf.c: Likewise. * sysdeps/riscv/rv64/rvf/s_lroundf.c: Likewise. * sysdeps/riscv/rvd/e_sqrt.c: Likewise. * sysdeps/riscv/rvd/s_copysign.c: Likewise. * sysdeps/riscv/rvd/s_finite.c: Likewise. * sysdeps/riscv/rvd/s_fma.c: Likewise. * sysdeps/riscv/rvd/s_fmax.c: Likewise. * sysdeps/riscv/rvd/s_fmin.c: Likewise. * sysdeps/riscv/rvd/s_fpclassify.c: Likewise. * sysdeps/riscv/rvd/s_isinf.c: Likewise. * sysdeps/riscv/rvd/s_isnan.c: Likewise. * sysdeps/riscv/rvd/s_issignaling.c: Likewise. * sysdeps/riscv/rvf/e_sqrtf.c: Likewise. * sysdeps/riscv/rvf/fclrexcpt.c: Likewise. * sysdeps/riscv/rvf/fegetenv.c: Likewise. * sysdeps/riscv/rvf/fegetmode.c: Likewise. * sysdeps/riscv/rvf/fegetround.c: Likewise. * sysdeps/riscv/rvf/feholdexcpt.c: Likewise. * sysdeps/riscv/rvf/fesetenv.c: Likewise. * sysdeps/riscv/rvf/fesetexcept.c: Likewise. * sysdeps/riscv/rvf/fesetmode.c: Likewise. * sysdeps/riscv/rvf/fesetround.c: Likewise. * sysdeps/riscv/rvf/feupdateenv.c: Likewise. * sysdeps/riscv/rvf/fgetexcptflg.c: Likewise. * sysdeps/riscv/rvf/fraiseexcpt.c: Likewise. * sysdeps/riscv/rvf/fsetexcptflg.c: Likewise. * sysdeps/riscv/rvf/ftestexcept.c: Likewise. * sysdeps/riscv/rvf/get-rounding-mode.h: Likewise. * sysdeps/riscv/rvf/math_private.h: Likewise. * sysdeps/riscv/rvf/s_ceilf.c: Likewise. * sysdeps/riscv/rvf/s_copysignf.c: Likewise. * sysdeps/riscv/rvf/s_finitef.c: Likewise. * sysdeps/riscv/rvf/s_floorf.c: Likewise. * sysdeps/riscv/rvf/s_fmaf.c: Likewise. * sysdeps/riscv/rvf/s_fmaxf.c: Likewise. * sysdeps/riscv/rvf/s_fminf.c: Likewise. * sysdeps/riscv/rvf/s_fpclassifyf.c: Likewise. * sysdeps/riscv/rvf/s_isinff.c: Likewise. * sysdeps/riscv/rvf/s_isnanf.c: Likewise. * sysdeps/riscv/rvf/s_issignalingf.c: Likewise. * sysdeps/riscv/rvf/s_nearbyintf.c: Likewise. * sysdeps/riscv/rvf/s_rintf.c: Likewise. * sysdeps/riscv/rvf/s_roundevenf.c: Likewise. * sysdeps/riscv/rvf/s_roundf.c: Likewise. * sysdeps/riscv/rvf/s_truncf.c: Likewise. --- 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/rv64/rvf/s_lroundf.c | 31 +++++++++++++++++++++ 15 files changed, 607 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_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/rv64/rvf/s_lroundf.c (limited to 'sysdeps/riscv/rv64') diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c new file mode 100644 index 0000000000..af99ecca3d --- /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 0000000000..f34af98cce --- /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 0000000000..8f37090d74 --- /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 0000000000..b7e448876b --- /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 0000000000..48f61be966 --- /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 0000000000..392233cd04 --- /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 0000000000..e17f038429 --- /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 0000000000..ef2380ea7f --- /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 0000000000..22cff63e09 --- /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 0000000000..26a0b2ded3 --- /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 0000000000..a0f78e6cd1 --- /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 0000000000..ddfda6cfe2 --- /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 0000000000..7132f81d2f --- /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 0000000000..d8b2fe88bf --- /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/rv64/rvf/s_lroundf.c b/sysdeps/riscv/rv64/rvf/s_lroundf.c new file mode 100644 index 0000000000..010ce6904d --- /dev/null +++ b/sysdeps/riscv/rv64/rvf/s_lroundf.c @@ -0,0 +1,31 @@ +/* lroundf(). RISC-V version. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + +long int +__lroundf (float x) +{ + int64_t res; + asm ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x)); + return res; +} + +libm_alias_float (__lround, lround) -- cgit 1.4.1