aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2018-01-29 09:27:10 -0800
committerPalmer Dabbelt <palmer@dabbelt.com>2018-01-29 10:26:43 -0800
commitb2cb5e0298e08b486190610a9e82356ccb6f564b (patch)
treec63e4d8b3e10d2df1af2424483a50f3ce7bee7a2
parent67236aeb6e27bb6c975727f119e4b4f89e416706 (diff)
downloadglibc-b2cb5e0298e08b486190610a9e82356ccb6f564b.tar.xz
glibc-b2cb5e0298e08b486190610a9e82356ccb6f564b.zip
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 <palmer@sifive.com> * 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.
-rw-r--r--ChangeLog58
-rw-r--r--sysdeps/riscv/rv64/rvd/s_ceil.c52
-rw-r--r--sysdeps/riscv/rv64/rvd/s_floor.c52
-rw-r--r--sysdeps/riscv/rv64/rvd/s_llrint.c30
-rw-r--r--sysdeps/riscv/rv64/rvd/s_llround.c30
-rw-r--r--sysdeps/riscv/rv64/rvd/s_lrint.c30
-rw-r--r--sysdeps/riscv/rv64/rvd/s_lround.c30
-rw-r--r--sysdeps/riscv/rv64/rvd/s_nearbyint.c52
-rw-r--r--sysdeps/riscv/rv64/rvd/s_rint.c52
-rw-r--r--sysdeps/riscv/rv64/rvd/s_round.c52
-rw-r--r--sysdeps/riscv/rv64/rvd/s_roundeven.c53
-rw-r--r--sysdeps/riscv/rv64/rvd/s_trunc.c52
-rw-r--r--sysdeps/riscv/rv64/rvf/s_llrintf.c30
-rw-r--r--sysdeps/riscv/rv64/rvf/s_llroundf.c30
-rw-r--r--sysdeps/riscv/rv64/rvf/s_lrintf.c31
-rw-r--r--sysdeps/riscv/rv64/rvf/s_lroundf.c31
-rw-r--r--sysdeps/riscv/rvd/e_sqrt.c27
-rw-r--r--sysdeps/riscv/rvd/s_copysign.c28
-rw-r--r--sysdeps/riscv/rvd/s_finite.c28
-rw-r--r--sysdeps/riscv/rvd/s_fma.c30
-rw-r--r--sysdeps/riscv/rvd/s_fmax.c28
-rw-r--r--sysdeps/riscv/rvd/s_fmin.c28
-rw-r--r--sysdeps/riscv/rvd/s_fpclassify.c36
-rw-r--r--sysdeps/riscv/rvd/s_isinf.c29
-rw-r--r--sysdeps/riscv/rvd/s_isnan.c28
-rw-r--r--sysdeps/riscv/rvd/s_issignaling.c27
-rw-r--r--sysdeps/riscv/rvf/e_sqrtf.c27
-rw-r--r--sysdeps/riscv/rvf/fclrexcpt.c28
-rw-r--r--sysdeps/riscv/rvf/fegetenv.c32
-rw-r--r--sysdeps/riscv/rvf/fegetmode.c27
-rw-r--r--sysdeps/riscv/rvf/fegetround.c29
-rw-r--r--sysdeps/riscv/rvf/feholdexcpt.c30
-rw-r--r--sysdeps/riscv/rvf/fesetenv.c30
-rw-r--r--sysdeps/riscv/rvf/fesetexcept.c26
-rw-r--r--sysdeps/riscv/rvf/fesetmode.c31
-rw-r--r--sysdeps/riscv/rvf/fesetround.c39
-rw-r--r--sysdeps/riscv/rvf/feupdateenv.c30
-rw-r--r--sysdeps/riscv/rvf/fgetexcptflg.c30
-rw-r--r--sysdeps/riscv/rvf/fraiseexcpt.c30
-rw-r--r--sysdeps/riscv/rvf/fsetexcptflg.c30
-rw-r--r--sysdeps/riscv/rvf/ftestexcept.c27
-rw-r--r--sysdeps/riscv/rvf/get-rounding-mode.h32
-rw-r--r--sysdeps/riscv/rvf/math_private.h161
-rw-r--r--sysdeps/riscv/rvf/s_ceilf.c52
-rw-r--r--sysdeps/riscv/rvf/s_copysignf.c28
-rw-r--r--sysdeps/riscv/rvf/s_finitef.c28
-rw-r--r--sysdeps/riscv/rvf/s_floorf.c52
-rw-r--r--sysdeps/riscv/rvf/s_fmaf.c30
-rw-r--r--sysdeps/riscv/rvf/s_fmaxf.c28
-rw-r--r--sysdeps/riscv/rvf/s_fminf.c28
-rw-r--r--sysdeps/riscv/rvf/s_fpclassifyf.c36
-rw-r--r--sysdeps/riscv/rvf/s_isinff.c29
-rw-r--r--sysdeps/riscv/rvf/s_isnanf.c28
-rw-r--r--sysdeps/riscv/rvf/s_issignalingf.c27
-rw-r--r--sysdeps/riscv/rvf/s_nearbyintf.c52
-rw-r--r--sysdeps/riscv/rvf/s_rintf.c52
-rw-r--r--sysdeps/riscv/rvf/s_roundevenf.c52
-rw-r--r--sysdeps/riscv/rvf/s_roundf.c52
-rw-r--r--sysdeps/riscv/rvf/s_truncf.c52
59 files changed, 2219 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 841440c3d8..17edd31c9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,64 @@
* sysdeps/riscv/nofpu/Implies: Likewise.
* sysdeps/riscv/sfp-machine.h: Likewise.
* sysdeps/riscv/tininess.h: Likewise.
+ * 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.
2018-01-29 Florian Weimer <fweimer@redhat.com>
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
+ <http://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+#include <stdint.h>
+
+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
+ <http://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+#include <stdint.h>
+
+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