This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 07/12] RISC-V: RV32F Support


This contains the base floating-point support for RISC-V, which is
defined by the F extension.  The code in this patch sufficies to
implement RV32F systems only, additional routines are necessary to add
support for RV32D, RV64F, and RV64D.  These additional routines have
been split out to avoid having too large of a patch.
---
 sysdeps/riscv/rvf/e_sqrtf.c           |  27 ++++++
 sysdeps/riscv/rvf/fclrexcpt.c         |  30 +++++++
 sysdeps/riscv/rvf/fedisblxcpt.c       |  29 ++++++
 sysdeps/riscv/rvf/feenablxcpt.c       |  29 ++++++
 sysdeps/riscv/rvf/fegetenv.c          |  34 +++++++
 sysdeps/riscv/rvf/fegetexcept.c       |  29 ++++++
 sysdeps/riscv/rvf/fegetround.c        |  31 +++++++
 sysdeps/riscv/rvf/feholdexcpt.c       |  32 +++++++
 sysdeps/riscv/rvf/fesetenv.c          |  32 +++++++
 sysdeps/riscv/rvf/fesetround.c        |  41 +++++++++
 sysdeps/riscv/rvf/feupdateenv.c       |  32 +++++++
 sysdeps/riscv/rvf/fgetexcptflg.c      |  32 +++++++
 sysdeps/riscv/rvf/fraiseexcpt.c       |  32 +++++++
 sysdeps/riscv/rvf/fsetexcptflg.c      |  32 +++++++
 sysdeps/riscv/rvf/ftestexcept.c       |  29 ++++++
 sysdeps/riscv/rvf/get-rounding-mode.h |  34 +++++++
 sysdeps/riscv/rvf/math_private.h      | 161 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rvf/s_ceilf.c           |  50 +++++++++++
 sysdeps/riscv/rvf/s_copysignf.c       |  27 ++++++
 sysdeps/riscv/rvf/s_fabsf.c           |  27 ++++++
 sysdeps/riscv/rvf/s_finitef.c         |  28 ++++++
 sysdeps/riscv/rvf/s_floorf.c          |  50 +++++++++++
 sysdeps/riscv/rvf/s_fmaf.c            |  29 ++++++
 sysdeps/riscv/rvf/s_fmaxf.c           |  27 ++++++
 sysdeps/riscv/rvf/s_fminf.c           |  27 ++++++
 sysdeps/riscv/rvf/s_fpclassifyf.c     |  36 ++++++++
 sysdeps/riscv/rvf/s_isinff.c          |  29 ++++++
 sysdeps/riscv/rvf/s_isnanf.c          |  28 ++++++
 sysdeps/riscv/rvf/s_issignalingf.c    |  27 ++++++
 sysdeps/riscv/rvf/s_lrintf.c          |  33 +++++++
 sysdeps/riscv/rvf/s_lroundf.c         |  33 +++++++
 sysdeps/riscv/rvf/s_nearbyintf.c      |  50 +++++++++++
 sysdeps/riscv/rvf/s_rintf.c           |  50 +++++++++++
 sysdeps/riscv/rvf/s_roundf.c          |  50 +++++++++++
 sysdeps/riscv/rvf/s_truncf.c          |  50 +++++++++++
 35 files changed, 1317 insertions(+)
 create mode 100644 sysdeps/riscv/rvf/e_sqrtf.c
 create mode 100644 sysdeps/riscv/rvf/fclrexcpt.c
 create mode 100644 sysdeps/riscv/rvf/fedisblxcpt.c
 create mode 100644 sysdeps/riscv/rvf/feenablxcpt.c
 create mode 100644 sysdeps/riscv/rvf/fegetenv.c
 create mode 100644 sysdeps/riscv/rvf/fegetexcept.c
 create mode 100644 sysdeps/riscv/rvf/fegetround.c
 create mode 100644 sysdeps/riscv/rvf/feholdexcpt.c
 create mode 100644 sysdeps/riscv/rvf/fesetenv.c
 create mode 100644 sysdeps/riscv/rvf/fesetround.c
 create mode 100644 sysdeps/riscv/rvf/feupdateenv.c
 create mode 100644 sysdeps/riscv/rvf/fgetexcptflg.c
 create mode 100644 sysdeps/riscv/rvf/fraiseexcpt.c
 create mode 100644 sysdeps/riscv/rvf/fsetexcptflg.c
 create mode 100644 sysdeps/riscv/rvf/ftestexcept.c
 create mode 100644 sysdeps/riscv/rvf/get-rounding-mode.h
 create mode 100644 sysdeps/riscv/rvf/math_private.h
 create mode 100644 sysdeps/riscv/rvf/s_ceilf.c
 create mode 100644 sysdeps/riscv/rvf/s_copysignf.c
 create mode 100644 sysdeps/riscv/rvf/s_fabsf.c
 create mode 100644 sysdeps/riscv/rvf/s_finitef.c
 create mode 100644 sysdeps/riscv/rvf/s_floorf.c
 create mode 100644 sysdeps/riscv/rvf/s_fmaf.c
 create mode 100644 sysdeps/riscv/rvf/s_fmaxf.c
 create mode 100644 sysdeps/riscv/rvf/s_fminf.c
 create mode 100644 sysdeps/riscv/rvf/s_fpclassifyf.c
 create mode 100644 sysdeps/riscv/rvf/s_isinff.c
 create mode 100644 sysdeps/riscv/rvf/s_isnanf.c
 create mode 100644 sysdeps/riscv/rvf/s_issignalingf.c
 create mode 100644 sysdeps/riscv/rvf/s_lrintf.c
 create mode 100644 sysdeps/riscv/rvf/s_lroundf.c
 create mode 100644 sysdeps/riscv/rvf/s_nearbyintf.c
 create mode 100644 sysdeps/riscv/rvf/s_rintf.c
 create mode 100644 sysdeps/riscv/rvf/s_roundf.c
 create mode 100644 sysdeps/riscv/rvf/s_truncf.c

diff --git a/sysdeps/riscv/rvf/e_sqrtf.c b/sysdeps/riscv/rvf/e_sqrtf.c
new file mode 100644
index 0000000000..ba1ad6db8b
--- /dev/null
+++ b/sysdeps/riscv/rvf/e_sqrtf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+float
+__ieee754_sqrtf (float x)
+{
+  asm ("fsqrt.s %0, %1" : "=f" (x) : "f" (x));
+  return x;
+}
+strong_alias (__ieee754_sqrtf, __sqrtf_finite)
diff --git a/sysdeps/riscv/rvf/fclrexcpt.c b/sysdeps/riscv/rvf/fclrexcpt.c
new file mode 100644
index 0000000000..38411f6724
--- /dev/null
+++ b/sysdeps/riscv/rvf/fclrexcpt.c
@@ -0,0 +1,30 @@
+/* Clear given exceptions in current floating-point environment.
+   Copyright (C) 1998-2000, 2002, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+feclearexcept (int excepts)
+{
+  asm volatile ("csrc fflags, %0" : : "r" (excepts));
+  return 0;
+}
+libm_hidden_def (feclearexcept)
diff --git a/sysdeps/riscv/rvf/fedisblxcpt.c b/sysdeps/riscv/rvf/fedisblxcpt.c
new file mode 100644
index 0000000000..89434de352
--- /dev/null
+++ b/sysdeps/riscv/rvf/fedisblxcpt.c
@@ -0,0 +1,29 @@
+/* Disable floating-point exceptions.
+   Copyright (C) 2000, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+fedisableexcept (int excepts)
+{
+  /* FP exceptions never generate traps. */
+  return 0;
+}
diff --git a/sysdeps/riscv/rvf/feenablxcpt.c b/sysdeps/riscv/rvf/feenablxcpt.c
new file mode 100644
index 0000000000..e664a2fb3c
--- /dev/null
+++ b/sysdeps/riscv/rvf/feenablxcpt.c
@@ -0,0 +1,29 @@
+/* Enable floating-point exceptions.
+   Copyright (C) 2000, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+feenableexcept (int excepts)
+{
+  /* FP exceptions never generate traps. */
+  return -1;
+}
diff --git a/sysdeps/riscv/rvf/fegetenv.c b/sysdeps/riscv/rvf/fegetenv.c
new file mode 100644
index 0000000000..e8e95dee3c
--- /dev/null
+++ b/sysdeps/riscv/rvf/fegetenv.c
@@ -0,0 +1,34 @@
+/* Store current floating-point environment.
+   Copyright (C) 1998-2000, 2002, 2010, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+__fegetenv (fenv_t *envp)
+{
+  _FPU_GETCW (*envp);
+
+  /* Success.  */
+  return 0;
+}
+libm_hidden_def (__fegetenv)
+weak_alias (__fegetenv, fegetenv)
+libm_hidden_weak (fegetenv)
diff --git a/sysdeps/riscv/rvf/fegetexcept.c b/sysdeps/riscv/rvf/fegetexcept.c
new file mode 100644
index 0000000000..00dafd96fb
--- /dev/null
+++ b/sysdeps/riscv/rvf/fegetexcept.c
@@ -0,0 +1,29 @@
+/* Get enabled floating-point exceptions.
+   Copyright (C) 2000, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+fegetexcept (void)
+{
+  /* FP exceptions never generate traps. */
+  return 0;
+}
diff --git a/sysdeps/riscv/rvf/fegetround.c b/sysdeps/riscv/rvf/fegetround.c
new file mode 100644
index 0000000000..171063c319
--- /dev/null
+++ b/sysdeps/riscv/rvf/fegetround.c
@@ -0,0 +1,31 @@
+/* Return current rounding direction.
+   Copyright (C) 1998, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+__fegetround (void)
+{
+  return riscv_getround ();
+}
+libm_hidden_def (__fegetround)
+weak_alias (__fegetround, fegetround)
+libm_hidden_weak (fegetround)
diff --git a/sysdeps/riscv/rvf/feholdexcpt.c b/sysdeps/riscv/rvf/feholdexcpt.c
new file mode 100644
index 0000000000..710314e339
--- /dev/null
+++ b/sysdeps/riscv/rvf/feholdexcpt.c
@@ -0,0 +1,32 @@
+/* Store current floating-point environment and clear exceptions.
+   Copyright (C) 2000, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+__feholdexcept (fenv_t *envp)
+{
+  libc_feholdexcept_riscv (envp);
+  return 0;
+}
+libm_hidden_def (__feholdexcept)
+weak_alias (__feholdexcept, feholdexcept)
+libm_hidden_weak (feholdexcept)
diff --git a/sysdeps/riscv/rvf/fesetenv.c b/sysdeps/riscv/rvf/fesetenv.c
new file mode 100644
index 0000000000..cadb0ee962
--- /dev/null
+++ b/sysdeps/riscv/rvf/fesetenv.c
@@ -0,0 +1,32 @@
+/* Install given floating-point environment.
+   Copyright (C) 1998-2000, 2002, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+__fesetenv (const fenv_t *envp)
+{
+  libc_fesetenv_riscv (envp);
+  return 0;
+}
+libm_hidden_def (__fesetenv)
+weak_alias (__fesetenv, fesetenv)
+libm_hidden_weak (fesetenv)
diff --git a/sysdeps/riscv/rvf/fesetround.c b/sysdeps/riscv/rvf/fesetround.c
new file mode 100644
index 0000000000..938bf4a170
--- /dev/null
+++ b/sysdeps/riscv/rvf/fesetround.c
@@ -0,0 +1,41 @@
+/* Set current rounding direction.
+   Copyright (C) 1998, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+__fesetround (int round)
+{
+  switch (round)
+    {
+    case FE_TONEAREST:
+    case FE_TOWARDZERO:
+    case FE_DOWNWARD:
+    case FE_UPWARD:
+      riscv_setround (round);
+      return 0;
+    default:
+      return round; /* a nonzero value */
+    }
+}
+libm_hidden_def (__fesetround)
+weak_alias (__fesetround, fesetround)
+libm_hidden_weak (fesetround)
diff --git a/sysdeps/riscv/rvf/feupdateenv.c b/sysdeps/riscv/rvf/feupdateenv.c
new file mode 100644
index 0000000000..9c7e091ed5
--- /dev/null
+++ b/sysdeps/riscv/rvf/feupdateenv.c
@@ -0,0 +1,32 @@
+/* Install given floating-point environment and raise exceptions.
+   Copyright (C) 1998-2000, 2002, 2010, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+__feupdateenv (const fenv_t *envp)
+{
+  libc_feupdateenv_riscv (envp);
+  return 0;
+}
+libm_hidden_def (__feupdateenv)
+weak_alias (__feupdateenv, feupdateenv)
+libm_hidden_weak (feupdateenv)
diff --git a/sysdeps/riscv/rvf/fgetexcptflg.c b/sysdeps/riscv/rvf/fgetexcptflg.c
new file mode 100644
index 0000000000..867f673cdb
--- /dev/null
+++ b/sysdeps/riscv/rvf/fgetexcptflg.c
@@ -0,0 +1,32 @@
+/* Store current representation for exceptions.
+   Copyright (C) 1998-2000, 2002, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+fegetexceptflag (fexcept_t *flagp, int excepts)
+{
+  /* Get the current exceptions.  */
+  *flagp = riscv_getflags () & excepts;
+
+  /* Success.  */
+  return 0;
+}
diff --git a/sysdeps/riscv/rvf/fraiseexcpt.c b/sysdeps/riscv/rvf/fraiseexcpt.c
new file mode 100644
index 0000000000..2796f37713
--- /dev/null
+++ b/sysdeps/riscv/rvf/fraiseexcpt.c
@@ -0,0 +1,32 @@
+/* Raise given exceptions.
+   Copyright (C) 2000, 2002, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+__feraiseexcept (int excepts)
+{
+  asm volatile ("csrs fflags, %0" : : "r" (excepts));
+  return 0;
+}
+libm_hidden_def (__feraiseexcept)
+weak_alias (__feraiseexcept, feraiseexcept)
+libm_hidden_weak (feraiseexcept)
diff --git a/sysdeps/riscv/rvf/fsetexcptflg.c b/sysdeps/riscv/rvf/fsetexcptflg.c
new file mode 100644
index 0000000000..570421dafc
--- /dev/null
+++ b/sysdeps/riscv/rvf/fsetexcptflg.c
@@ -0,0 +1,32 @@
+/* Set floating-point environment exception handling.
+   Copyright (C) 1998-2000, 2002, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Hartvig Ekner <hartvige@mips.com>, 2002.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+fesetexceptflag (const fexcept_t *flagp, int excepts)
+{
+  fexcept_t flags = *flagp;
+  asm volatile ("csrc fflags, %0" : : "r" (excepts));
+  asm volatile ("csrs fflags, %0" : : "r" (flags & excepts));
+
+  return 0;
+}
diff --git a/sysdeps/riscv/rvf/ftestexcept.c b/sysdeps/riscv/rvf/ftestexcept.c
new file mode 100644
index 0000000000..b84a980f29
--- /dev/null
+++ b/sysdeps/riscv/rvf/ftestexcept.c
@@ -0,0 +1,29 @@
+/* Test exception in current environment.
+   Copyright (C) 1998, 2010, 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <fenv.h>
+#include <math_private.h>
+
+int
+fetestexcept (int excepts)
+{
+  return libc_fetestexcept_riscv (excepts);
+}
+libm_hidden_def (fetestexcept)
diff --git a/sysdeps/riscv/rvf/get-rounding-mode.h b/sysdeps/riscv/rvf/get-rounding-mode.h
new file mode 100644
index 0000000000..0f325607e3
--- /dev/null
+++ b/sysdeps/riscv/rvf/get-rounding-mode.h
@@ -0,0 +1,34 @@
+/* Determine floating-point rounding mode within libc.  RISC-V version.
+
+   Copyright (C) 2015, 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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _RISCV_GET_ROUNDING_MODE_H
+#define _RISCV_GET_ROUNDING_MODE_H
+
+/* Return the floating-point rounding mode.  */
+
+static inline int
+get_rounding_mode (void)
+{
+  int rm;
+  asm volatile ("frrm %0" : "=r" (rm));
+  return rm;
+}
+
+#endif /* get-rounding-mode.h */
diff --git a/sysdeps/riscv/rvf/math_private.h b/sysdeps/riscv/rvf/math_private.h
new file mode 100644
index 0000000000..6e4be81919
--- /dev/null
+++ b/sysdeps/riscv/rvf/math_private.h
@@ -0,0 +1,161 @@
+/* Private floating point rounding and exceptions handling.  RISC-V version.
+   Copyright (C) 2014-2015, 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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef RISCV_MATH_PRIVATE_H
+#define RISCV_MATH_PRIVATE_H 1
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <get-rounding-mode.h>
+
+static __always_inline int
+riscv_getround (void)
+{
+  return get_rounding_mode ();
+}
+
+static __always_inline void
+riscv_setround (int rm)
+{
+  asm volatile ("fsrm %z0" : : "rJ" (rm));
+}
+
+static __always_inline int
+riscv_getflags (void)
+{
+  int flags;
+  asm volatile ("frflags %0" : "=r" (flags));
+  return flags;
+}
+
+static __always_inline void
+riscv_setflags (int flags)
+{
+  asm volatile ("fsflags %z0" : : "rJ" (flags));
+}
+
+static __always_inline void
+libc_feholdexcept_riscv (fenv_t *envp)
+{
+  asm volatile ("csrrc %0, fcsr, %1" : "=r" (*envp) : "i" (FE_ALL_EXCEPT));
+}
+
+#define libc_feholdexcept  libc_feholdexcept_riscv
+#define libc_feholdexceptf libc_feholdexcept_riscv
+#define libc_feholdexceptl libc_feholdexcept_riscv
+
+static __always_inline void
+libc_fesetround_riscv (int round)
+{
+  riscv_setround (round);
+}
+
+#define libc_fesetround  libc_fesetround_riscv
+#define libc_fesetroundf libc_fesetround_riscv
+#define libc_fesetroundl libc_fesetround_riscv
+
+static __always_inline void
+libc_feholdexcept_setround_riscv (fenv_t *envp, int round)
+{
+  libc_fesetround_riscv (round);
+  libc_feholdexcept_riscv (envp);
+}
+
+#define libc_feholdexcept_setround  libc_feholdexcept_setround_riscv
+#define libc_feholdexcept_setroundf libc_feholdexcept_setround_riscv
+#define libc_feholdexcept_setroundl libc_feholdexcept_setround_riscv
+
+static __always_inline int
+libc_fetestexcept_riscv (int ex)
+{
+  return riscv_getflags () & ex;
+}
+
+#define libc_fetestexcept  libc_fetestexcept_riscv
+#define libc_fetestexceptf libc_fetestexcept_riscv
+#define libc_fetestexceptl libc_fetestexcept_riscv
+
+static __always_inline void
+libc_fesetenv_riscv (const fenv_t *envp)
+{
+  long env = (long) envp - (long) FE_DFL_ENV;
+  if (env != 0)
+    env = *envp;
+
+  _FPU_SETCW (env);
+}
+
+#define libc_fesetenv  libc_fesetenv_riscv
+#define libc_fesetenvf libc_fesetenv_riscv
+#define libc_fesetenvl libc_fesetenv_riscv
+#define libc_feresetround_noex  libc_fesetenv_riscv
+#define libc_feresetround_noexf libc_fesetenv_riscv
+#define libc_feresetround_noexl libc_fesetenv_riscv
+
+static __always_inline int
+libc_feupdateenv_test_riscv (const fenv_t *envp, int ex)
+{
+  fenv_t env = *envp;
+  int flags = riscv_getflags ();
+  asm volatile ("csrw fcsr, %z0" : : "rJ" (env | flags));
+  return flags & ex;
+}
+
+#define libc_feupdateenv_test  libc_feupdateenv_test_riscv
+#define libc_feupdateenv_testf libc_feupdateenv_test_riscv
+#define libc_feupdateenv_testl libc_feupdateenv_test_riscv
+
+static __always_inline void
+libc_feupdateenv_riscv (const fenv_t *envp)
+{
+  _FPU_SETCW (*envp | riscv_getflags ());
+}
+
+#define libc_feupdateenv  libc_feupdateenv_riscv
+#define libc_feupdateenvf libc_feupdateenv_riscv
+#define libc_feupdateenvl libc_feupdateenv_riscv
+
+static __always_inline void
+libc_feholdsetround_riscv (fenv_t *envp, int round)
+{
+  /* Note this implementation makes an improperly-formatted fenv_t and
+     so should only be used in conjunction with libc_feresetround.  */
+  int old_round;
+  asm volatile ("csrrw %0, frm, %z1" : "=r" (old_round) : "rJ" (round));
+  *envp = old_round;
+}
+
+#define libc_feholdsetround  libc_feholdsetround_riscv
+#define libc_feholdsetroundf libc_feholdsetround_riscv
+#define libc_feholdsetroundl libc_feholdsetround_riscv
+
+static __always_inline void
+libc_feresetround_riscv (fenv_t *envp)
+{
+  /* Note this implementation takes an improperly-formatted fenv_t and
+     so should only be used in conjunction with libc_feholdsetround.  */
+  riscv_setround (*envp);
+}
+
+#define libc_feresetround  libc_feresetround_riscv
+#define libc_feresetroundf libc_feresetround_riscv
+#define libc_feresetroundl libc_feresetround_riscv
+
+#include_next <math_private.h>
+
+#endif
diff --git a/sysdeps/riscv/rvf/s_ceilf.c b/sysdeps/riscv/rvf/s_ceilf.c
new file mode 100644
index 0000000000..c168f5f93b
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_ceilf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__ceilf (float x)
+{
+  int flags = riscv_getflags ();
+  int nan = isnanf (x);
+  float mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm volatile ("fcvt.w.s %0, %1, rup" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.s.w %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 = copysignf (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+weak_alias (__ceilf, ceilf)
diff --git a/sysdeps/riscv/rvf/s_copysignf.c b/sysdeps/riscv/rvf/s_copysignf.c
new file mode 100644
index 0000000000..eda12d014a
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_copysignf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+float
+__copysignf (float x, float y)
+{
+  asm ("fsgnj.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+weak_alias (__copysignf, copysignf)
diff --git a/sysdeps/riscv/rvf/s_fabsf.c b/sysdeps/riscv/rvf/s_fabsf.c
new file mode 100644
index 0000000000..c85961ed0f
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_fabsf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+float
+__fabsf (float x)
+{
+  asm ("fabs.s %0, %1" : "=f" (x) : "f" (x));
+  return x;
+}
+weak_alias (__fabsf, fabsf)
diff --git a/sysdeps/riscv/rvf/s_finitef.c b/sysdeps/riscv/rvf/s_finitef.c
new file mode 100644
index 0000000000..83eaf26d21
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_finitef.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__finitef (float x)
+{
+  return _FCLASS (x) & ~(_FCLASS_INF | _FCLASS_NAN);
+}
+hidden_def (__finitef)
+weak_alias (__finitef, finitef)
diff --git a/sysdeps/riscv/rvf/s_floorf.c b/sysdeps/riscv/rvf/s_floorf.c
new file mode 100644
index 0000000000..e33c0a8aad
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_floorf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__floorf (float x)
+{
+  int flags = riscv_getflags ();
+  int nan = isnanf (x);
+  float mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm volatile ("fcvt.w.s %0, %1, rdn" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.s.w %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 = copysignf (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+weak_alias (__floorf, floorf)
diff --git a/sysdeps/riscv/rvf/s_fmaf.c b/sysdeps/riscv/rvf/s_fmaf.c
new file mode 100644
index 0000000000..487d67c2cc
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_fmaf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <fenv.h>
+#include <ieee754.h>
+
+float
+__fmaf (float x, float y, float z)
+{
+  asm ("fmadd.s %0, %1, %2, %3" : "=f" (x) : "f" (x), "f" (y), "f" (z));
+  return x;
+}
+weak_alias (__fmaf, fmaf)
diff --git a/sysdeps/riscv/rvf/s_fmaxf.c b/sysdeps/riscv/rvf/s_fmaxf.c
new file mode 100644
index 0000000000..26b732e794
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_fmaxf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+float
+__fmaxf (float x, float y)
+{
+  asm ("fmax.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+weak_alias (__fmaxf, fmaxf)
diff --git a/sysdeps/riscv/rvf/s_fminf.c b/sysdeps/riscv/rvf/s_fminf.c
new file mode 100644
index 0000000000..a0ae10a7d5
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_fminf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+float
+__fminf (float x, float y)
+{
+  asm ("fmin.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+weak_alias (__fminf, fminf)
diff --git a/sysdeps/riscv/rvf/s_fpclassifyf.c b/sysdeps/riscv/rvf/s_fpclassifyf.c
new file mode 100644
index 0000000000..7df9d55ea1
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_fpclassifyf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__fpclassifyf (float 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 (__fpclassifyf)
diff --git a/sysdeps/riscv/rvf/s_isinff.c b/sysdeps/riscv/rvf/s_isinff.c
new file mode 100644
index 0000000000..a34f5d769a
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_isinff.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__isinff (float x)
+{
+  int cls = _FCLASS (x);
+  return -((cls & _FCLASS_MINF) ? 1 : 0) | ((cls & _FCLASS_PINF) ? 1 : 0);
+}
+hidden_def (__isinff)
+weak_alias (__isinff, isinff)
diff --git a/sysdeps/riscv/rvf/s_isnanf.c b/sysdeps/riscv/rvf/s_isnanf.c
new file mode 100644
index 0000000000..a025cfd3b1
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_isnanf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__isnanf (float x)
+{
+  return _FCLASS (x) & _FCLASS_NAN;
+}
+hidden_def (__isnanf)
+weak_alias (__isnanf, isnanf)
diff --git a/sysdeps/riscv/rvf/s_issignalingf.c b/sysdeps/riscv/rvf/s_issignalingf.c
new file mode 100644
index 0000000000..a73267cede
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_issignalingf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__issignalingf (float x)
+{
+  return _FCLASS (x) & _FCLASS_SNAN;
+}
+libm_hidden_def (__issignalingf)
diff --git a/sysdeps/riscv/rvf/s_lrintf.c b/sysdeps/riscv/rvf/s_lrintf.c
new file mode 100644
index 0000000000..a2bf280094
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_lrintf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __LP64__
+
+#include <math.h>
+
+long
+__lrintf (float x)
+{
+  long res;
+  asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+weak_alias (__lrintf, lrintf)
+
+#endif
diff --git a/sysdeps/riscv/rvf/s_lroundf.c b/sysdeps/riscv/rvf/s_lroundf.c
new file mode 100644
index 0000000000..3f01945ea0
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_lroundf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __LP64__
+
+#include <math.h>
+
+long
+__lroundf (float x)
+{
+  long res;
+  asm ("fcvt.w.s %0, %1, rmm" : "=r" (res) : "f" (x));
+  return res;
+}
+
+weak_alias (__lroundf, lroundf)
+
+#endif
diff --git a/sysdeps/riscv/rvf/s_nearbyintf.c b/sysdeps/riscv/rvf/s_nearbyintf.c
new file mode 100644
index 0000000000..e890d0ce8b
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_nearbyintf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__nearbyintf (float x)
+{
+  int flags = riscv_getflags ();
+  int nan = isnanf (x);
+  float mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm volatile ("fcvt.w.s %0, %1" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.s.w %0, %1" : "=f" (new_x) : "r" (i));
+
+      /* nearbyint(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysignf (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+weak_alias (__nearbyintf, nearbyintf)
diff --git a/sysdeps/riscv/rvf/s_rintf.c b/sysdeps/riscv/rvf/s_rintf.c
new file mode 100644
index 0000000000..2150b7916b
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_rintf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__rintf (float x)
+{
+  int nan;
+  float mag;
+
+  nan = isnanf (x);
+  mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm ("fcvt.w.s %0, %1" : "=r" (i) : "f" (x));
+      asm ("fcvt.s.w %0, %1" : "=f" (new_x) : "r" (i));
+
+      /* rint(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysignf (new_x, x);
+    }
+
+  return x;
+}
+
+weak_alias (__rintf, rintf)
diff --git a/sysdeps/riscv/rvf/s_roundf.c b/sysdeps/riscv/rvf/s_roundf.c
new file mode 100644
index 0000000000..b8ceb33298
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_roundf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__roundf (float x)
+{
+  int flags = riscv_getflags ();
+  int nan = isnanf (x);
+  float mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm volatile ("fcvt.w.s %0, %1, rmm" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.s.w %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 = copysignf (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+weak_alias (__roundf, roundf)
diff --git a/sysdeps/riscv/rvf/s_truncf.c b/sysdeps/riscv/rvf/s_truncf.c
new file mode 100644
index 0000000000..55eb27c610
--- /dev/null
+++ b/sysdeps/riscv/rvf/s_truncf.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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+float
+__truncf (float x)
+{
+  int flags = riscv_getflags ();
+  int nan = isnanf (x);
+  float mag = fabsf (x);
+
+  if (nan)
+    return x + x;
+
+  if (mag < (1 << __FLT_MANT_DIG__))
+    {
+      int i;
+      float new_x;
+
+      asm volatile ("fcvt.w.s %0, %1, rtz" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.s.w %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 = copysignf (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+weak_alias (__truncf, truncf)
-- 
2.13.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]