diff mbox series

[v3,13/19] RISC-V: RV32D, RV64F, and RV64D Support

Message ID 20171227060534.3998-14-palmer@dabbelt.com
State New
Headers show
Series [v3,01/19] Avoid race conditions when rebuilding librt.so | expand

Commit Message

Palmer Dabbelt Dec. 27, 2017, 6:05 a.m. UTC
This patch adds support for the various other hardware floating point
configurations that RISC-V supports.  This is split from the RV32F patch
to avoid mailing list size restrictions.
---
 sysdeps/riscv/rv32/rvd/s_lrint.c     | 30 ++++++++++++++++++++
 sysdeps/riscv/rv32/rvd/s_lround.c    | 30 ++++++++++++++++++++
 sysdeps/riscv/rv32/rvf/s_llrintf.c   | 30 ++++++++++++++++++++
 sysdeps/riscv/rv32/rvf/s_lrintf.c    | 30 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_ceil.c      | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_floor.c     | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_llrint.c    | 29 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_llround.c   | 29 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_lrint.c     | 29 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_lround.c    | 29 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_nearbyint.c | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_rint.c      | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_round.c     | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_roundeven.c | 53 ++++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvd/s_trunc.c     | 51 ++++++++++++++++++++++++++++++++++
 sysdeps/riscv/rv64/rvf/s_llrintf.c   | 29 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvf/s_llroundf.c  | 30 ++++++++++++++++++++
 sysdeps/riscv/rv64/rvf/s_lrintf.c    | 30 ++++++++++++++++++++
 sysdeps/riscv/rvd/e_sqrt.c           | 27 ++++++++++++++++++
 sysdeps/riscv/rvd/s_copysign.c       | 28 +++++++++++++++++++
 sysdeps/riscv/rvd/s_finite.c         | 28 +++++++++++++++++++
 sysdeps/riscv/rvd/s_fma.c            | 30 ++++++++++++++++++++
 sysdeps/riscv/rvd/s_fmax.c           | 28 +++++++++++++++++++
 sysdeps/riscv/rvd/s_fmin.c           | 28 +++++++++++++++++++
 sysdeps/riscv/rvd/s_fpclassify.c     | 36 ++++++++++++++++++++++++
 sysdeps/riscv/rvd/s_isinf.c          | 29 ++++++++++++++++++++
 sysdeps/riscv/rvd/s_isnan.c          | 28 +++++++++++++++++++
 sysdeps/riscv/rvd/s_issignaling.c    | 27 ++++++++++++++++++
 28 files changed, 973 insertions(+)
 create mode 100644 sysdeps/riscv/rv32/rvd/s_lrint.c
 create mode 100644 sysdeps/riscv/rv32/rvd/s_lround.c
 create mode 100644 sysdeps/riscv/rv32/rvf/s_llrintf.c
 create mode 100644 sysdeps/riscv/rv32/rvf/s_lrintf.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_ceil.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_floor.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_llrint.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_llround.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_lrint.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_lround.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_nearbyint.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_rint.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_round.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_roundeven.c
 create mode 100644 sysdeps/riscv/rv64/rvd/s_trunc.c
 create mode 100644 sysdeps/riscv/rv64/rvf/s_llrintf.c
 create mode 100644 sysdeps/riscv/rv64/rvf/s_llroundf.c
 create mode 100644 sysdeps/riscv/rv64/rvf/s_lrintf.c
 create mode 100644 sysdeps/riscv/rvd/e_sqrt.c
 create mode 100644 sysdeps/riscv/rvd/s_copysign.c
 create mode 100644 sysdeps/riscv/rvd/s_finite.c
 create mode 100644 sysdeps/riscv/rvd/s_fma.c
 create mode 100644 sysdeps/riscv/rvd/s_fmax.c
 create mode 100644 sysdeps/riscv/rvd/s_fmin.c
 create mode 100644 sysdeps/riscv/rvd/s_fpclassify.c
 create mode 100644 sysdeps/riscv/rvd/s_isinf.c
 create mode 100644 sysdeps/riscv/rvd/s_isnan.c
 create mode 100644 sysdeps/riscv/rvd/s_issignaling.c

Comments

Joseph Myers Jan. 1, 2018, 5:08 p.m. UTC | #1
On Tue, 26 Dec 2017, Palmer Dabbelt wrote:

> +long
> +__lrint (double x)
> +{
> +  long res;

long int, as in the previous patch.

> +long
> +__lround (double x)
> +{
> +  long res;

Likewise.

> +long long
> +__llrintf (float x)
> +{
> +  long res;
> +  asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x));
> +  return res;

Likewise (long long int), and I don't see how "long res;" here can be 
correct at all, since this is in an rv32 file, and float can represent 
integers outside the range of 32-bit long, which need to be correctly 
converted to 64-bit long long for this function.  Maybe llrintf should 
actually be rv64-only, since you need to convert to a 64-bit integer?

> +long
> +__lrintf (float x)
> +{
> +  long res;

Likewise.

> diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c

> +      long i;

I would like to suggest, throughout the rv64 functions, where you are 
using long (as here) for a 64-bit internal temporary (as opposed to long 
int actually being part of the defined function API), you use int64_t 
instead of changing long -> long int - after all, the instructions you are 
using are defined to convert to/from 64-bit integers.  That way, the code 
would work unchanged if you support RV64 ILP32 in future, whereas if you 
use long int you need to change it again to support RV64 ILP32.

(More generally, if what you want about an integer type is a particular 
number of bits, using intN_t / uintN_t is encouraged.  That's definitely 
the case when using asm instructions as here that are defined to use 
integers with a given number of bits rather than linked to the C ABI.)

> +      long i;

Same in floor.

> +long long
> +__llrint (double x)
> +{
> +  long long res;

Use long long int.

> +long long
> +__llround (double x)
> +{
> +  long long res;

Use long long int.

> +long
> +__lrint (double x)
> +{
> +  long res;
> +  asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));

Use long int (but note a further change would be needed in future for RV64 
ILP32 where you want a conversion to 32-bit not 64-bit integer in the 
asm).

> +long
> +__lround (double x)
> +{
> +  long res;
> +  asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));

Likewise.

> +      long i;

int64_t in nearbyint as elsewhere.

> +      long i;

Likewise in rint.

> +      long i;

Likewise in round.

> +      long i;

Likewise in roundeven.

> +      long i;

Likewise in trunc.

> +long long
> +__llrintf (float x)
> +{
> +  long long res;

long long int.

> +#include <libm-alias-float.h>
> +#include <libm-alias-float.h>

You don't want to include the same header twice in a row (this is in 
llroundf).

> +long long
> +__llroundf (float x)
> +{
> +  long long res;

long long int.

> +long
> +__lrintf (float x)
> +{
> +  long res;
> +  asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));

long int (again, would need to change for ILP32 support).
Darius Rad Jan. 4, 2018, 6:50 p.m. UTC | #2
On 01/01/2018 12:08 PM, Joseph Myers wrote:
> On Tue, 26 Dec 2017, Palmer Dabbelt wrote:
> 
>> +long
>> +__lrint (double x)
>> +{
>> +  long res;
> 
> long int, as in the previous patch.
> 

Indeed, and I will fix.

>> +long
>> +__lround (double x)
>> +{
>> +  long res;
> 
> Likewise.
> 
>> +long long
>> +__llrintf (float x)
>> +{
>> +  long res;
>> +  asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x));
>> +  return res;
> 
> Likewise (long long int), and I don't see how "long res;" here can be 
> correct at all, since this is in an rv32 file, and float can represent 
> integers outside the range of 32-bit long, which need to be correctly 
> converted to 64-bit long long for this function.  Maybe llrintf should 
> actually be rv64-only, since you need to convert to a 64-bit integer?
> 

You're correct, llrintf should be RV64 only.  I will remove it.

>> +long
>> +__lrintf (float x)
>> +{
>> +  long res;
> 
> Likewise.
> 
>> diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c
> 
>> +      long i;
> 
> I would like to suggest, throughout the rv64 functions, where you are 
> using long (as here) for a 64-bit internal temporary (as opposed to long 
> int actually being part of the defined function API), you use int64_t 
> instead of changing long -> long int - after all, the instructions you are 
> using are defined to convert to/from 64-bit integers.  That way, the code 
> would work unchanged if you support RV64 ILP32 in future, whereas if you 
> use long int you need to change it again to support RV64 ILP32.
> 

Thanks.  I'll update to use int64_t/int32_t as appropriate for the assembly.

> (More generally, if what you want about an integer type is a particular 
> number of bits, using intN_t / uintN_t is encouraged.  That's definitely 
> the case when using asm instructions as here that are defined to use 
> integers with a given number of bits rather than linked to the C ABI.)
> 
>> +      long i;
> 
> Same in floor.
> 
>> +long long
>> +__llrint (double x)
>> +{
>> +  long long res;
> 
> Use long long int.
> 
>> +long long
>> +__llround (double x)
>> +{
>> +  long long res;
> 
> Use long long int.
> 
>> +long
>> +__lrint (double x)
>> +{
>> +  long res;
>> +  asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));
> 
> Use long int (but note a further change would be needed in future for RV64 
> ILP32 where you want a conversion to 32-bit not 64-bit integer in the 
> asm).
> 

Thanks, good to know for the future.

>> +long
>> +__lround (double x)
>> +{
>> +  long res;
>> +  asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));
> 
> Likewise.
> 
>> +      long i;
> 
> int64_t in nearbyint as elsewhere.
> 
>> +      long i;
> 
> Likewise in rint.
> 
>> +      long i;
> 
> Likewise in round.
> 
>> +      long i;
> 
> Likewise in roundeven.
> 
>> +      long i;
> 
> Likewise in trunc.
> 
>> +long long
>> +__llrintf (float x)
>> +{
>> +  long long res;
> 
> long long int.
> 
>> +#include <libm-alias-float.h>
>> +#include <libm-alias-float.h>
> 
> You don't want to include the same header twice in a row (this is in 
> llroundf).
> 

Yes, thanks.  I'll fix.

>> +long long
>> +__llroundf (float x)
>> +{
>> +  long long res;
> 
> long long int.
> 
>> +long
>> +__lrintf (float x)
>> +{
>> +  long res;
>> +  asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));
> 
> long int (again, would need to change for ILP32 support).
>
diff mbox series

Patch

diff --git a/sysdeps/riscv/rv32/rvd/s_lrint.c b/sysdeps/riscv/rv32/rvd/s_lrint.c
new file mode 100644
index 000000000000..7a1fff6ffd27
--- /dev/null
+++ b/sysdeps/riscv/rv32/rvd/s_lrint.c
@@ -0,0 +1,30 @@ 
+/* lrint().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-double.h>
+
+long
+__lrint (double x)
+{
+  long res;
+  asm ("fcvt.w.d %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double (__lrint, lrint)
diff --git a/sysdeps/riscv/rv32/rvd/s_lround.c b/sysdeps/riscv/rv32/rvd/s_lround.c
new file mode 100644
index 000000000000..7c2e0b81fbe0
--- /dev/null
+++ b/sysdeps/riscv/rv32/rvd/s_lround.c
@@ -0,0 +1,30 @@ 
+/* lround().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-double.h>
+
+long
+__lround (double x)
+{
+  long res;
+  asm ("fcvt.w.d %0, %1, rmm" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double (__lround, lround)
diff --git a/sysdeps/riscv/rv32/rvf/s_llrintf.c b/sysdeps/riscv/rv32/rvf/s_llrintf.c
new file mode 100644
index 000000000000..3de8aa99a7f3
--- /dev/null
+++ b/sysdeps/riscv/rv32/rvf/s_llrintf.c
@@ -0,0 +1,30 @@ 
+/* lrintf().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-float.h>
+
+long long
+__llrintf (float x)
+{
+  long res;
+  asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_float (__llrint, llrint)
diff --git a/sysdeps/riscv/rv32/rvf/s_lrintf.c b/sysdeps/riscv/rv32/rvf/s_lrintf.c
new file mode 100644
index 000000000000..806a160ce0d7
--- /dev/null
+++ b/sysdeps/riscv/rv32/rvf/s_lrintf.c
@@ -0,0 +1,30 @@ 
+/* lrintf().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-float.h>
+
+long
+__lrintf (float x)
+{
+  long res;
+  asm ("fcvt.w.s %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_float (__lrint, lrint)
diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c
new file mode 100644
index 000000000000..b26af1bd7275
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_ceil.c
@@ -0,0 +1,51 @@ 
+/* ceil().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1, rup" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1, rup" : "=f" (new_x) : "r" (i));
+
+      /* ceil(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+libm_alias_double (__ceil, ceil)
diff --git a/sysdeps/riscv/rv64/rvd/s_floor.c b/sysdeps/riscv/rv64/rvd/s_floor.c
new file mode 100644
index 000000000000..6e1ce9df8f62
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_floor.c
@@ -0,0 +1,51 @@ 
+/* floor().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1, rdn" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1, rdn" : "=f" (new_x) : "r" (i));
+
+      /* floor(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+libm_alias_double (__floor, floor)
diff --git a/sysdeps/riscv/rv64/rvd/s_llrint.c b/sysdeps/riscv/rv64/rvd/s_llrint.c
new file mode 100644
index 000000000000..77a7b0712f9c
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_llrint.c
@@ -0,0 +1,29 @@ 
+/* llrint().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-double.h>
+
+long long
+__llrint (double x)
+{
+  long long res;
+  asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double(__llrint, llrint)
diff --git a/sysdeps/riscv/rv64/rvd/s_llround.c b/sysdeps/riscv/rv64/rvd/s_llround.c
new file mode 100644
index 000000000000..5df866de7245
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_llround.c
@@ -0,0 +1,29 @@ 
+/* llround().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-double.h>
+
+long long
+__llround (double x)
+{
+  long long res;
+  asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double (__llround, llround)
diff --git a/sysdeps/riscv/rv64/rvd/s_lrint.c b/sysdeps/riscv/rv64/rvd/s_lrint.c
new file mode 100644
index 000000000000..2d11cc3cd16d
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_lrint.c
@@ -0,0 +1,29 @@ 
+/* lrint().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-double.h>
+
+long
+__lrint (double x)
+{
+  long res;
+  asm ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double (__lrint, lrint)
diff --git a/sysdeps/riscv/rv64/rvd/s_lround.c b/sysdeps/riscv/rv64/rvd/s_lround.c
new file mode 100644
index 000000000000..b4f37e15bd2e
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_lround.c
@@ -0,0 +1,29 @@ 
+/* llround().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-double.h>
+
+long
+__lround (double x)
+{
+  long res;
+  asm ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_double (__lround, lround)
diff --git a/sysdeps/riscv/rv64/rvd/s_nearbyint.c b/sysdeps/riscv/rv64/rvd/s_nearbyint.c
new file mode 100644
index 000000000000..01e8468e281c
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c
@@ -0,0 +1,51 @@ 
+/* nearbyint().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+
+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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1" : "=f" (new_x) : "r" (i));
+
+      /* nearbyint(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+libm_alias_double (__nearbyint, nearbyint)
diff --git a/sysdeps/riscv/rv64/rvd/s_rint.c b/sysdeps/riscv/rv64/rvd/s_rint.c
new file mode 100644
index 000000000000..6004bd73922f
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_rint.c
@@ -0,0 +1,51 @@ 
+/* rint().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+
+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__))
+    {
+      long i;
+      double new_x;
+
+      asm ("fcvt.l.d %0, %1" : "=r" (i) : "f" (x));
+      asm ("fcvt.d.l %0, %1" : "=f" (new_x) : "r" (i));
+
+      /* rint(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+    }
+
+  return x;
+}
+
+libm_alias_double (__rint, rint)
diff --git a/sysdeps/riscv/rv64/rvd/s_round.c b/sysdeps/riscv/rv64/rvd/s_round.c
new file mode 100644
index 000000000000..54092846ff23
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_round.c
@@ -0,0 +1,51 @@ 
+/* round().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+
+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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1, rmm" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1, rmm" : "=f" (new_x) : "r" (i));
+
+      /* round(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+libm_alias_double (__round, round)
diff --git a/sysdeps/riscv/rv64/rvd/s_roundeven.c b/sysdeps/riscv/rv64/rvd/s_roundeven.c
new file mode 100644
index 000000000000..1aeab4b0ff40
--- /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 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>
+
+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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1, rne" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1, rne" : "=f" (new_x) : "r" (i));
+
+      /* roundeven(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+hidden_def (__roundeven)
+libm_alias_double (__roundeven, roundeven)
diff --git a/sysdeps/riscv/rv64/rvd/s_trunc.c b/sysdeps/riscv/rv64/rvd/s_trunc.c
new file mode 100644
index 000000000000..b19a59d987a1
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvd/s_trunc.c
@@ -0,0 +1,51 @@ 
+/* trunc().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+#include <libm-alias-double.h>
+
+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__))
+    {
+      long i;
+      double new_x;
+
+      asm volatile ("fcvt.l.d %0, %1, rtz" : "=r" (i) : "f" (x));
+      asm volatile ("fcvt.d.l %0, %1, rtz" : "=f" (new_x) : "r" (i));
+
+      /* trunc(-0) == -0, and in general we'll always have the same
+	 sign as our input.  */
+      x = copysign (new_x, x);
+
+      riscv_setflags (flags);
+    }
+
+  return x;
+}
+
+libm_alias_double (__trunc, trunc)
diff --git a/sysdeps/riscv/rv64/rvf/s_llrintf.c b/sysdeps/riscv/rv64/rvf/s_llrintf.c
new file mode 100644
index 000000000000..bdebf1fde3fa
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvf/s_llrintf.c
@@ -0,0 +1,29 @@ 
+/* Round argument to nearest integral value according to current direction.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-float.h>
+
+long long
+__llrintf (float x)
+{
+  long long res;
+  asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_float (__llrint, llrint)
diff --git a/sysdeps/riscv/rv64/rvf/s_llroundf.c b/sysdeps/riscv/rv64/rvf/s_llroundf.c
new file mode 100644
index 000000000000..5b69c01648ec
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvf/s_llroundf.c
@@ -0,0 +1,30 @@ 
+/* Round float value to long long int.  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-float.h>
+#include <libm-alias-float.h>
+
+long long
+__llroundf (float x)
+{
+  long long res;
+  asm ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_float (__llround, llround)
diff --git a/sysdeps/riscv/rv64/rvf/s_lrintf.c b/sysdeps/riscv/rv64/rvf/s_lrintf.c
new file mode 100644
index 000000000000..cb28ffe1b536
--- /dev/null
+++ b/sysdeps/riscv/rv64/rvf/s_lrintf.c
@@ -0,0 +1,30 @@ 
+/* lrintf().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-float.h>
+
+long
+__lrintf (float x)
+{
+  long res;
+  asm ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));
+  return res;
+}
+
+libm_alias_float (__lrint, lrint)
diff --git a/sysdeps/riscv/rvd/e_sqrt.c b/sysdeps/riscv/rvd/e_sqrt.c
new file mode 100644
index 000000000000..ceac9f4c34a4
--- /dev/null
+++ b/sysdeps/riscv/rvd/e_sqrt.c
@@ -0,0 +1,27 @@ 
+/* Double precision floating point square root.  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+
+double
+__ieee754_sqrt (double x)
+{
+  asm ("fsqrt.d %0, %1" : "=f" (x) : "f" (x));
+  return x;
+}
+strong_alias (__ieee754_sqrt, __sqrt_finite)
diff --git a/sysdeps/riscv/rvd/s_copysign.c b/sysdeps/riscv/rvd/s_copysign.c
new file mode 100644
index 000000000000..d3a5000a6e7b
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_copysign.c
@@ -0,0 +1,28 @@ 
+/* Copy sign bit between floating-point values.  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__copysign (double x, double y)
+{
+  asm ("fsgnj.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+libm_alias_double (__copysign, copysign)
diff --git a/sysdeps/riscv/rvd/s_finite.c b/sysdeps/riscv/rvd/s_finite.c
new file mode 100644
index 000000000000..06914e1c1e71
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_finite.c
@@ -0,0 +1,28 @@ 
+/* finite().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__finite (double x)
+{
+  return _FCLASS (x) & ~(_FCLASS_INF | _FCLASS_NAN);
+}
+hidden_def (__finite)
+weak_alias (__finite, finite)
diff --git a/sysdeps/riscv/rvd/s_fma.c b/sysdeps/riscv/rvd/s_fma.c
new file mode 100644
index 000000000000..ff74857cf578
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_fma.c
@@ -0,0 +1,30 @@ 
+/* Double precision floating point fused multiply-add.  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <fenv.h>
+#include <ieee754.h>
+#include <libm-alias-double.h>
+
+double
+__fma (double x, double y, double z)
+{
+  asm ("fmadd.d %0, %1, %2, %3" : "=f" (x) : "f" (x), "f" (y), "f" (z));
+  return x;
+}
+libm_alias_double (__fma, fma)
diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c
new file mode 100644
index 000000000000..b108434cd64b
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_fmax.c
@@ -0,0 +1,28 @@ 
+/* fmax().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__fmax (double x, double y)
+{
+  asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+libm_alias_double (__fmax, fmax)
diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c
new file mode 100644
index 000000000000..4894377602c3
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_fmin.c
@@ -0,0 +1,28 @@ 
+/* fmin().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__fmin (double x, double y)
+{
+  asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+  return x;
+}
+libm_alias_double (__fmin, fmin)
diff --git a/sysdeps/riscv/rvd/s_fpclassify.c b/sysdeps/riscv/rvd/s_fpclassify.c
new file mode 100644
index 000000000000..cdfdbdfbc1e2
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_fpclassify.c
@@ -0,0 +1,36 @@ 
+/* fpclassify().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__fpclassify (double x)
+{
+  int cls = _FCLASS (x);
+  if (__builtin_expect (cls & _FCLASS_NORM, _FCLASS_NORM))
+    return FP_NORMAL;
+  if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO))
+    return FP_ZERO;
+  if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM))
+    return FP_SUBNORMAL;
+  if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF))
+    return FP_INFINITE;
+  return FP_NAN;
+}
+libm_hidden_def (__fpclassify)
diff --git a/sysdeps/riscv/rvd/s_isinf.c b/sysdeps/riscv/rvd/s_isinf.c
new file mode 100644
index 000000000000..92d2f2c261bc
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_isinf.c
@@ -0,0 +1,29 @@ 
+/* isinf().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__isinf (double x)
+{
+  int cls = _FCLASS (x);
+  return -((cls & _FCLASS_MINF) ? 1 : 0) | ((cls & _FCLASS_PINF) ? 1 : 0);
+}
+hidden_def (__isinf)
+weak_alias (__isinf, isinf)
diff --git a/sysdeps/riscv/rvd/s_isnan.c b/sysdeps/riscv/rvd/s_isnan.c
new file mode 100644
index 000000000000..e88b47287952
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_isnan.c
@@ -0,0 +1,28 @@ 
+/* isnan().  RISC_V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__isnan (double x)
+{
+  return _FCLASS (x) & _FCLASS_NAN;
+}
+hidden_def (__isnan)
+weak_alias (__isnan, isnan)
diff --git a/sysdeps/riscv/rvd/s_issignaling.c b/sysdeps/riscv/rvd/s_issignaling.c
new file mode 100644
index 000000000000..6136d7e7f33f
--- /dev/null
+++ b/sysdeps/riscv/rvd/s_issignaling.c
@@ -0,0 +1,27 @@ 
+/* issignaling().  RISC-V version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_private.h>
+
+int
+__issignaling (double x)
+{
+  return _FCLASS (x) & _FCLASS_SNAN;
+}
+libm_hidden_def (__issignaling)