public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* RISC-V: Implement more machine-specific for libm
@ 2020-11-18  3:35 Kito Cheng
  2020-11-18  3:35 ` [PATCH 1/3] RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c Kito Cheng
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kito Cheng @ 2020-11-18  3:35 UTC (permalink / raw)
  To: newlib

This patch set has implement more machine-specific for libm with F/D extension, most can be done with one instruction, verified on rv32im, rv32imaf, rv32imafd+ilp32, rv32imafd+ilp32d, rv64im, rv64imaf, rv64gc+lp64 rv64gc+lp64d.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c
  2020-11-18  3:35 RISC-V: Implement more machine-specific for libm Kito Cheng
@ 2020-11-18  3:35 ` Kito Cheng
  2020-11-18  3:35 ` [PATCH 2/3] RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] Kito Cheng
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2020-11-18  3:35 UTC (permalink / raw)
  To: newlib; +Cc: Kito Cheng

---
 newlib/libm/machine/riscv/Makefile.am |  4 +++-
 newlib/libm/machine/riscv/Makefile.in | 32 +++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
index 9e7b9e868..1cfcb3dad 100644
--- a/newlib/libm/machine/riscv/Makefile.am
+++ b/newlib/libm/machine/riscv/Makefile.am
@@ -10,7 +10,9 @@ LIB_SOURCES = \
 	s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c \
 	s_fmax.c s_fmin.c sf_fmax.c sf_fmin.c \
 	s_fabs.c sf_fabs.c \
-	s_fpclassify.c sf_fpclassify.c
+	s_fpclassify.c sf_fpclassify.c \
+	s_finite.c sf_finite.c \
+	s_isinf.c sf_isinf.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
diff --git a/newlib/libm/machine/riscv/Makefile.in b/newlib/libm/machine/riscv/Makefile.in
index 5c915e90f..6d0dfe28c 100644
--- a/newlib/libm/machine/riscv/Makefile.in
+++ b/newlib/libm/machine/riscv/Makefile.in
@@ -82,7 +82,9 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \
 	lib_a-s_fmin.$(OBJEXT) lib_a-sf_fmax.$(OBJEXT) \
 	lib_a-sf_fmin.$(OBJEXT) lib_a-s_fabs.$(OBJEXT) \
 	lib_a-sf_fabs.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
-	lib_a-sf_fpclassify.$(OBJEXT)
+	lib_a-sf_fpclassify.$(OBJEXT) lib_a-s_finite.$(OBJEXT) \
+	lib_a-sf_finite.$(OBJEXT) lib_a-s_isinf.$(OBJEXT) \
+	lib_a-sf_isinf.$(OBJEXT)
 am_lib_a_OBJECTS = $(am__objects_1)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
@@ -214,7 +216,9 @@ LIB_SOURCES = \
 	s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c \
 	s_fmax.c s_fmin.c sf_fmax.c sf_fmin.c \
 	s_fabs.c sf_fabs.c \
-	s_fpclassify.c sf_fpclassify.c
+	s_fpclassify.c sf_fpclassify.c \
+	s_finite.c sf_finite.c \
+	s_isinf.c sf_isinf.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
@@ -436,6 +440,30 @@ lib_a-sf_fpclassify.o: sf_fpclassify.c
 lib_a-sf_fpclassify.obj: sf_fpclassify.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fpclassify.obj `if test -f 'sf_fpclassify.c'; then $(CYGPATH_W) 'sf_fpclassify.c'; else $(CYGPATH_W) '$(srcdir)/sf_fpclassify.c'; fi`
 
+lib_a-s_finite.o: s_finite.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_finite.o `test -f 's_finite.c' || echo '$(srcdir)/'`s_finite.c
+
+lib_a-s_finite.obj: s_finite.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_finite.obj `if test -f 's_finite.c'; then $(CYGPATH_W) 's_finite.c'; else $(CYGPATH_W) '$(srcdir)/s_finite.c'; fi`
+
+lib_a-sf_finite.o: sf_finite.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_finite.o `test -f 'sf_finite.c' || echo '$(srcdir)/'`sf_finite.c
+
+lib_a-sf_finite.obj: sf_finite.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_finite.obj `if test -f 'sf_finite.c'; then $(CYGPATH_W) 'sf_finite.c'; else $(CYGPATH_W) '$(srcdir)/sf_finite.c'; fi`
+
+lib_a-s_isinf.o: s_isinf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isinf.o `test -f 's_isinf.c' || echo '$(srcdir)/'`s_isinf.c
+
+lib_a-s_isinf.obj: s_isinf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isinf.obj `if test -f 's_isinf.c'; then $(CYGPATH_W) 's_isinf.c'; else $(CYGPATH_W) '$(srcdir)/s_isinf.c'; fi`
+
+lib_a-sf_isinf.o: sf_isinf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isinf.o `test -f 'sf_isinf.c' || echo '$(srcdir)/'`sf_isinf.c
+
+lib_a-sf_isinf.obj: sf_isinf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isinf.obj `if test -f 'sf_isinf.c'; then $(CYGPATH_W) 'sf_isinf.c'; else $(CYGPATH_W) '$(srcdir)/sf_isinf.c'; fi`
+
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
 	unique=`for i in $$list; do \
-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] RISC-V: Add machine-specific implementation for isnan[f] and copysign[f]
  2020-11-18  3:35 RISC-V: Implement more machine-specific for libm Kito Cheng
  2020-11-18  3:35 ` [PATCH 1/3] RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c Kito Cheng
@ 2020-11-18  3:35 ` Kito Cheng
  2020-11-18  3:35 ` [PATCH 3/3] RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f] Kito Cheng
  2020-11-18  8:39 ` RISC-V: Implement more machine-specific for libm Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2020-11-18  3:35 UTC (permalink / raw)
  To: newlib; +Cc: Kito Cheng

---
 newlib/libm/machine/riscv/Makefile.am   |  4 +-
 newlib/libm/machine/riscv/Makefile.in   | 32 ++++++++++++++-
 newlib/libm/machine/riscv/s_copysign.c  | 50 ++++++++++++++++++++++++
 newlib/libm/machine/riscv/s_isnan.c     | 52 +++++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_copysign.c | 50 ++++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_isnan.c    | 52 +++++++++++++++++++++++++
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 newlib/libm/machine/riscv/s_copysign.c
 create mode 100644 newlib/libm/machine/riscv/s_isnan.c
 create mode 100644 newlib/libm/machine/riscv/sf_copysign.c
 create mode 100644 newlib/libm/machine/riscv/sf_isnan.c

diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
index 1cfcb3dad..5dfa35f30 100644
--- a/newlib/libm/machine/riscv/Makefile.am
+++ b/newlib/libm/machine/riscv/Makefile.am
@@ -12,7 +12,9 @@ LIB_SOURCES = \
 	s_fabs.c sf_fabs.c \
 	s_fpclassify.c sf_fpclassify.c \
 	s_finite.c sf_finite.c \
-	s_isinf.c sf_isinf.c
+	s_isinf.c sf_isinf.c \
+	s_isnan.c sf_isnan.c \
+	s_copysign.c sf_copysign.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
diff --git a/newlib/libm/machine/riscv/Makefile.in b/newlib/libm/machine/riscv/Makefile.in
index 6d0dfe28c..dcf71d00b 100644
--- a/newlib/libm/machine/riscv/Makefile.in
+++ b/newlib/libm/machine/riscv/Makefile.in
@@ -84,7 +84,9 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \
 	lib_a-sf_fabs.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
 	lib_a-sf_fpclassify.$(OBJEXT) lib_a-s_finite.$(OBJEXT) \
 	lib_a-sf_finite.$(OBJEXT) lib_a-s_isinf.$(OBJEXT) \
-	lib_a-sf_isinf.$(OBJEXT)
+	lib_a-sf_isinf.$(OBJEXT) lib_a-s_isnan.$(OBJEXT) \
+	lib_a-sf_isnan.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
+	lib_a-sf_copysign.$(OBJEXT)
 am_lib_a_OBJECTS = $(am__objects_1)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
@@ -218,7 +220,9 @@ LIB_SOURCES = \
 	s_fabs.c sf_fabs.c \
 	s_fpclassify.c sf_fpclassify.c \
 	s_finite.c sf_finite.c \
-	s_isinf.c sf_isinf.c
+	s_isinf.c sf_isinf.c \
+	s_isnan.c sf_isnan.c \
+	s_copysign.c sf_copysign.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
@@ -464,6 +468,30 @@ lib_a-sf_isinf.o: sf_isinf.c
 lib_a-sf_isinf.obj: sf_isinf.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isinf.obj `if test -f 'sf_isinf.c'; then $(CYGPATH_W) 'sf_isinf.c'; else $(CYGPATH_W) '$(srcdir)/sf_isinf.c'; fi`
 
+lib_a-s_isnan.o: s_isnan.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isnan.o `test -f 's_isnan.c' || echo '$(srcdir)/'`s_isnan.c
+
+lib_a-s_isnan.obj: s_isnan.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isnan.obj `if test -f 's_isnan.c'; then $(CYGPATH_W) 's_isnan.c'; else $(CYGPATH_W) '$(srcdir)/s_isnan.c'; fi`
+
+lib_a-sf_isnan.o: sf_isnan.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isnan.o `test -f 'sf_isnan.c' || echo '$(srcdir)/'`sf_isnan.c
+
+lib_a-sf_isnan.obj: sf_isnan.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isnan.obj `if test -f 'sf_isnan.c'; then $(CYGPATH_W) 'sf_isnan.c'; else $(CYGPATH_W) '$(srcdir)/sf_isnan.c'; fi`
+
+lib_a-s_copysign.o: s_copysign.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_copysign.o `test -f 's_copysign.c' || echo '$(srcdir)/'`s_copysign.c
+
+lib_a-s_copysign.obj: s_copysign.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_copysign.obj `if test -f 's_copysign.c'; then $(CYGPATH_W) 's_copysign.c'; else $(CYGPATH_W) '$(srcdir)/s_copysign.c'; fi`
+
+lib_a-sf_copysign.o: sf_copysign.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_copysign.o `test -f 'sf_copysign.c' || echo '$(srcdir)/'`sf_copysign.c
+
+lib_a-sf_copysign.obj: sf_copysign.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_copysign.obj `if test -f 'sf_copysign.c'; then $(CYGPATH_W) 'sf_copysign.c'; else $(CYGPATH_W) '$(srcdir)/sf_copysign.c'; fi`
+
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
 	unique=`for i in $$list; do \
diff --git a/newlib/libm/machine/riscv/s_copysign.c b/newlib/libm/machine/riscv/s_copysign.c
new file mode 100644
index 000000000..047535578
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_copysign.c
@@ -0,0 +1,50 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64
+
+double
+copysign (double x, double y)
+{
+  double result;
+  asm ("fsgnj.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y));
+  return result;
+}
+
+#else
+#include "../../common/s_copysign.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_isnan.c b/newlib/libm/machine/riscv/s_isnan.c
new file mode 100644
index 000000000..a0209729a
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_isnan.c
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <ieeefp.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64
+
+#include "riscv_math.h"
+#undef isnan
+
+int
+isnan (double x)
+{
+	long fclass = _fclass_d (x);
+	return (fclass & FCLASS_NAN);
+}
+#else
+#include "../../common/s_isnan.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_copysign.c b/newlib/libm/machine/riscv/sf_copysign.c
new file mode 100644
index 000000000..31b1321ad
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_copysign.c
@@ -0,0 +1,50 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32
+
+float
+copysignf (float x, float y)
+{
+  float result;
+  asm ("fsgnj.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y));
+  return result;
+}
+
+#else
+#include "../../common/sf_copysign.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_isnan.c b/newlib/libm/machine/riscv/sf_isnan.c
new file mode 100644
index 000000000..e38abf4ab
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_isnan.c
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <ieeefp.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32
+
+#include "riscv_math.h"
+#undef isnanf
+
+int
+isnanf (float x)
+{
+	long fclass = _fclass_f (x);
+	return (fclass & FCLASS_NAN);
+}
+#else
+#include "../../common/sf_isnan.c"
+#endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f].
  2020-11-18  3:35 RISC-V: Implement more machine-specific for libm Kito Cheng
  2020-11-18  3:35 ` [PATCH 1/3] RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c Kito Cheng
  2020-11-18  3:35 ` [PATCH 2/3] RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] Kito Cheng
@ 2020-11-18  3:35 ` Kito Cheng
  2020-11-18  8:39 ` RISC-V: Implement more machine-specific for libm Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2020-11-18  3:35 UTC (permalink / raw)
  To: newlib; +Cc: Kito Cheng

---
 newlib/libm/machine/riscv/Makefile.am  |  6 ++-
 newlib/libm/machine/riscv/Makefile.in  | 60 +++++++++++++++++++++++++-
 newlib/libm/machine/riscv/s_llrint.c   | 54 +++++++++++++++++++++++
 newlib/libm/machine/riscv/s_llround.c  | 54 +++++++++++++++++++++++
 newlib/libm/machine/riscv/s_lrint.c    | 56 ++++++++++++++++++++++++
 newlib/libm/machine/riscv/s_lround.c   | 56 ++++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_llrint.c  | 54 +++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_llround.c | 54 +++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_lrint.c   | 56 ++++++++++++++++++++++++
 newlib/libm/machine/riscv/sf_lround.c  | 56 ++++++++++++++++++++++++
 10 files changed, 503 insertions(+), 3 deletions(-)
 create mode 100644 newlib/libm/machine/riscv/s_llrint.c
 create mode 100644 newlib/libm/machine/riscv/s_llround.c
 create mode 100644 newlib/libm/machine/riscv/s_lrint.c
 create mode 100644 newlib/libm/machine/riscv/s_lround.c
 create mode 100644 newlib/libm/machine/riscv/sf_llrint.c
 create mode 100644 newlib/libm/machine/riscv/sf_llround.c
 create mode 100644 newlib/libm/machine/riscv/sf_lrint.c
 create mode 100644 newlib/libm/machine/riscv/sf_lround.c

diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
index 5dfa35f30..fd26d9508 100644
--- a/newlib/libm/machine/riscv/Makefile.am
+++ b/newlib/libm/machine/riscv/Makefile.am
@@ -14,7 +14,11 @@ LIB_SOURCES = \
 	s_finite.c sf_finite.c \
 	s_isinf.c sf_isinf.c \
 	s_isnan.c sf_isnan.c \
-	s_copysign.c sf_copysign.c
+	s_copysign.c sf_copysign.c \
+	s_lrint.c sf_lrint.c \
+	s_lround.c sf_lround.c \
+	s_llrint.c sf_llrint.c \
+	s_llround.c sf_llround.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
diff --git a/newlib/libm/machine/riscv/Makefile.in b/newlib/libm/machine/riscv/Makefile.in
index dcf71d00b..ceeaa59d1 100644
--- a/newlib/libm/machine/riscv/Makefile.in
+++ b/newlib/libm/machine/riscv/Makefile.in
@@ -86,7 +86,11 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \
 	lib_a-sf_finite.$(OBJEXT) lib_a-s_isinf.$(OBJEXT) \
 	lib_a-sf_isinf.$(OBJEXT) lib_a-s_isnan.$(OBJEXT) \
 	lib_a-sf_isnan.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
-	lib_a-sf_copysign.$(OBJEXT)
+	lib_a-sf_copysign.$(OBJEXT) lib_a-s_lrint.$(OBJEXT) \
+	lib_a-sf_lrint.$(OBJEXT) lib_a-s_lround.$(OBJEXT) \
+	lib_a-sf_lround.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
+	lib_a-sf_llrint.$(OBJEXT) lib_a-s_llround.$(OBJEXT) \
+	lib_a-sf_llround.$(OBJEXT)
 am_lib_a_OBJECTS = $(am__objects_1)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
@@ -222,7 +226,11 @@ LIB_SOURCES = \
 	s_finite.c sf_finite.c \
 	s_isinf.c sf_isinf.c \
 	s_isnan.c sf_isnan.c \
-	s_copysign.c sf_copysign.c
+	s_copysign.c sf_copysign.c \
+	s_lrint.c sf_lrint.c \
+	s_lround.c sf_lround.c \
+	s_llrint.c sf_llrint.c \
+	s_llround.c sf_llround.c
 
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(LIB_SOURCES)
@@ -492,6 +500,54 @@ lib_a-sf_copysign.o: sf_copysign.c
 lib_a-sf_copysign.obj: sf_copysign.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_copysign.obj `if test -f 'sf_copysign.c'; then $(CYGPATH_W) 'sf_copysign.c'; else $(CYGPATH_W) '$(srcdir)/sf_copysign.c'; fi`
 
+lib_a-s_lrint.o: s_lrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lrint.o `test -f 's_lrint.c' || echo '$(srcdir)/'`s_lrint.c
+
+lib_a-s_lrint.obj: s_lrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lrint.obj `if test -f 's_lrint.c'; then $(CYGPATH_W) 's_lrint.c'; else $(CYGPATH_W) '$(srcdir)/s_lrint.c'; fi`
+
+lib_a-sf_lrint.o: sf_lrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lrint.o `test -f 'sf_lrint.c' || echo '$(srcdir)/'`sf_lrint.c
+
+lib_a-sf_lrint.obj: sf_lrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lrint.obj `if test -f 'sf_lrint.c'; then $(CYGPATH_W) 'sf_lrint.c'; else $(CYGPATH_W) '$(srcdir)/sf_lrint.c'; fi`
+
+lib_a-s_lround.o: s_lround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lround.o `test -f 's_lround.c' || echo '$(srcdir)/'`s_lround.c
+
+lib_a-s_lround.obj: s_lround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lround.obj `if test -f 's_lround.c'; then $(CYGPATH_W) 's_lround.c'; else $(CYGPATH_W) '$(srcdir)/s_lround.c'; fi`
+
+lib_a-sf_lround.o: sf_lround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lround.o `test -f 'sf_lround.c' || echo '$(srcdir)/'`sf_lround.c
+
+lib_a-sf_lround.obj: sf_lround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_lround.obj `if test -f 'sf_lround.c'; then $(CYGPATH_W) 'sf_lround.c'; else $(CYGPATH_W) '$(srcdir)/sf_lround.c'; fi`
+
+lib_a-s_llrint.o: s_llrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llrint.o `test -f 's_llrint.c' || echo '$(srcdir)/'`s_llrint.c
+
+lib_a-s_llrint.obj: s_llrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llrint.obj `if test -f 's_llrint.c'; then $(CYGPATH_W) 's_llrint.c'; else $(CYGPATH_W) '$(srcdir)/s_llrint.c'; fi`
+
+lib_a-sf_llrint.o: sf_llrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llrint.o `test -f 'sf_llrint.c' || echo '$(srcdir)/'`sf_llrint.c
+
+lib_a-sf_llrint.obj: sf_llrint.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llrint.obj `if test -f 'sf_llrint.c'; then $(CYGPATH_W) 'sf_llrint.c'; else $(CYGPATH_W) '$(srcdir)/sf_llrint.c'; fi`
+
+lib_a-s_llround.o: s_llround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llround.o `test -f 's_llround.c' || echo '$(srcdir)/'`s_llround.c
+
+lib_a-s_llround.obj: s_llround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_llround.obj `if test -f 's_llround.c'; then $(CYGPATH_W) 's_llround.c'; else $(CYGPATH_W) '$(srcdir)/s_llround.c'; fi`
+
+lib_a-sf_llround.o: sf_llround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llround.o `test -f 'sf_llround.c' || echo '$(srcdir)/'`sf_llround.c
+
+lib_a-sf_llround.obj: sf_llround.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_llround.obj `if test -f 'sf_llround.c'; then $(CYGPATH_W) 'sf_llround.c'; else $(CYGPATH_W) '$(srcdir)/sf_llround.c'; fi`
+
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
 	unique=`for i in $$list; do \
diff --git a/newlib/libm/machine/riscv/s_llrint.c b/newlib/libm/machine/riscv/s_llrint.c
new file mode 100644
index 000000000..3f93e60b8
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_llrint.c
@@ -0,0 +1,54 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64 && __riscv_xlen >= 64
+long long int
+llrint (double x)
+{
+  long long result;
+  asm (
+#if __riscv_xlen == 64
+       "fcvt.l.d"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/s_llrint.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_llround.c b/newlib/libm/machine/riscv/s_llround.c
new file mode 100644
index 000000000..ff41394cf
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_llround.c
@@ -0,0 +1,54 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64 && __riscv_xlen >= 64
+long long int
+llround(double x)
+{
+  long long result;
+  asm (
+#if __riscv_xlen == 64
+       "fcvt.l.d"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1, rmm" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/s_llround.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_lrint.c b/newlib/libm/machine/riscv/s_lrint.c
new file mode 100644
index 000000000..0e9a9bc8b
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_lrint.c
@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64
+long int
+lrint (double x)
+{
+  long result;
+  asm (
+#if __riscv_xlen == 32
+       "fcvt.w.d"
+#elif __riscv_xlen == 64
+       "fcvt.l.d"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/s_lrint.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_lround.c b/newlib/libm/machine/riscv/s_lround.c
new file mode 100644
index 000000000..5be778834
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_lround.c
@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64
+long int
+lround (double x)
+{
+  long result;
+  asm (
+#if __riscv_xlen == 32
+       "fcvt.w.d"
+#elif __riscv_xlen == 64
+       "fcvt.l.d"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1, rmm" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/s_lround.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_llrint.c b/newlib/libm/machine/riscv/sf_llrint.c
new file mode 100644
index 000000000..58f2e5371
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_llrint.c
@@ -0,0 +1,54 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32 && __riscv_xlen >= 64
+long long int
+llrintf (float x)
+{
+  long long result;
+  asm (
+#if __riscv_xlen == 64
+       "fcvt.l.s"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/sf_llrint.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_llround.c b/newlib/libm/machine/riscv/sf_llround.c
new file mode 100644
index 000000000..389da692e
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_llround.c
@@ -0,0 +1,54 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32 && __riscv_xlen >= 64
+long long int
+llroundf (float x)
+{
+  long long result;
+  asm (
+#if __riscv_xlen == 64
+       "fcvt.l.s"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1, rmm" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/sf_llround.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_lrint.c b/newlib/libm/machine/riscv/sf_lrint.c
new file mode 100644
index 000000000..4f80a9339
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_lrint.c
@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32
+long int
+lrintf (float x)
+{
+  long result;
+  asm (
+#if __riscv_xlen == 32
+       "fcvt.w.s"
+#elif __riscv_xlen == 64
+       "fcvt.l.s"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/sf_lrint.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_lround.c b/newlib/libm/machine/riscv/sf_lround.c
new file mode 100644
index 000000000..dda6d984e
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_lround.c
@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Kito Cheng
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 32
+long int
+lroundf(float x)
+{
+  long result;
+  asm (
+#if __riscv_xlen == 32
+       "fcvt.w.s"
+#elif __riscv_xlen == 64
+       "fcvt.l.s"
+#else
+#error Unsupported XLEN
+#endif
+       "\t%0, %1, rmm" : "=r"(result) : "f"(x));
+  return result;
+}
+#else
+#include "../../common/sf_lround.c"
+#endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RISC-V: Implement more machine-specific for libm
  2020-11-18  3:35 RISC-V: Implement more machine-specific for libm Kito Cheng
                   ` (2 preceding siblings ...)
  2020-11-18  3:35 ` [PATCH 3/3] RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f] Kito Cheng
@ 2020-11-18  8:39 ` Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2020-11-18  8:39 UTC (permalink / raw)
  To: Kito Cheng; +Cc: newlib

On Nov 18 11:35, Kito Cheng wrote:
> This patch set has implement more machine-specific for libm with F/D extension, most can be done with one instruction, verified on rv32im, rv32imaf, rv32imafd+ilp32, rv32imafd+ilp32d, rv64im, rv64imaf, rv64gc+lp64 rv64gc+lp64d.
> 

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-18  8:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18  3:35 RISC-V: Implement more machine-specific for libm Kito Cheng
2020-11-18  3:35 ` [PATCH 1/3] RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c Kito Cheng
2020-11-18  3:35 ` [PATCH 2/3] RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] Kito Cheng
2020-11-18  3:35 ` [PATCH 3/3] RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f] Kito Cheng
2020-11-18  8:39 ` RISC-V: Implement more machine-specific for libm Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).