* [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f].
@ 2020-10-27 6:19 Kito Cheng
2020-10-27 6:19 ` [PATCH 2/2] RISC-V: Implment finite and fpclassify Kito Cheng
2020-10-27 7:59 ` [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] Corinna Vinschen
0 siblings, 2 replies; 8+ messages in thread
From: Kito Cheng @ 2020-10-27 6:19 UTC (permalink / raw)
To: newlib; +Cc: Kito Cheng
---
newlib/libm/machine/riscv/Makefile.am | 4 ++-
newlib/libm/machine/riscv/Makefile.in | 45 ++++++++++++++++++++++--
newlib/libm/machine/riscv/s_fabs.c | 50 +++++++++++++++++++++++++++
newlib/libm/machine/riscv/s_fmax.c | 49 ++++++++++++++++++++++++++
newlib/libm/machine/riscv/s_fmin.c | 50 +++++++++++++++++++++++++++
newlib/libm/machine/riscv/sf_fabs.c | 50 +++++++++++++++++++++++++++
newlib/libm/machine/riscv/sf_fmax.c | 50 +++++++++++++++++++++++++++
newlib/libm/machine/riscv/sf_fmin.c | 50 +++++++++++++++++++++++++++
8 files changed, 345 insertions(+), 3 deletions(-)
create mode 100644 newlib/libm/machine/riscv/s_fabs.c
create mode 100644 newlib/libm/machine/riscv/s_fmax.c
create mode 100644 newlib/libm/machine/riscv/s_fmin.c
create mode 100644 newlib/libm/machine/riscv/sf_fabs.c
create mode 100644 newlib/libm/machine/riscv/sf_fmax.c
create mode 100644 newlib/libm/machine/riscv/sf_fmin.c
diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
index 870f2a7b6..9443fb8e6 100644
--- a/newlib/libm/machine/riscv/Makefile.am
+++ b/newlib/libm/machine/riscv/Makefile.am
@@ -7,7 +7,9 @@ LIB_SOURCES = \
feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
- s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c
+ 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
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 4ac1d30c4..063c643bb 100644
--- a/newlib/libm/machine/riscv/Makefile.in
+++ b/newlib/libm/machine/riscv/Makefile.in
@@ -78,7 +78,10 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \
lib_a-fesetround.$(OBJEXT) lib_a-fetestexcept.$(OBJEXT) \
lib_a-feupdateenv.$(OBJEXT) lib_a-s_fma.$(OBJEXT) \
lib_a-e_sqrt.$(OBJEXT) lib_a-sf_fma.$(OBJEXT) \
- lib_a-ef_sqrt.$(OBJEXT)
+ lib_a-ef_sqrt.$(OBJEXT) lib_a-s_fmax.$(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)
am_lib_a_OBJECTS = $(am__objects_1)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
@@ -207,7 +210,9 @@ LIB_SOURCES = \
feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
- s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c
+ 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
noinst_LIBRARIES = lib.a
lib_a_SOURCES = $(LIB_SOURCES)
@@ -381,6 +386,42 @@ lib_a-ef_sqrt.o: ef_sqrt.c
lib_a-ef_sqrt.obj: ef_sqrt.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ef_sqrt.obj `if test -f 'ef_sqrt.c'; then $(CYGPATH_W) 'ef_sqrt.c'; else $(CYGPATH_W) '$(srcdir)/ef_sqrt.c'; fi`
+lib_a-s_fmax.o: s_fmax.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fmax.o `test -f 's_fmax.c' || echo '$(srcdir)/'`s_fmax.c
+
+lib_a-s_fmax.obj: s_fmax.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fmax.obj `if test -f 's_fmax.c'; then $(CYGPATH_W) 's_fmax.c'; else $(CYGPATH_W) '$(srcdir)/s_fmax.c'; fi`
+
+lib_a-s_fmin.o: s_fmin.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fmin.o `test -f 's_fmin.c' || echo '$(srcdir)/'`s_fmin.c
+
+lib_a-s_fmin.obj: s_fmin.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fmin.obj `if test -f 's_fmin.c'; then $(CYGPATH_W) 's_fmin.c'; else $(CYGPATH_W) '$(srcdir)/s_fmin.c'; fi`
+
+lib_a-sf_fmax.o: sf_fmax.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fmax.o `test -f 'sf_fmax.c' || echo '$(srcdir)/'`sf_fmax.c
+
+lib_a-sf_fmax.obj: sf_fmax.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fmax.obj `if test -f 'sf_fmax.c'; then $(CYGPATH_W) 'sf_fmax.c'; else $(CYGPATH_W) '$(srcdir)/sf_fmax.c'; fi`
+
+lib_a-sf_fmin.o: sf_fmin.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fmin.o `test -f 'sf_fmin.c' || echo '$(srcdir)/'`sf_fmin.c
+
+lib_a-sf_fmin.obj: sf_fmin.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fmin.obj `if test -f 'sf_fmin.c'; then $(CYGPATH_W) 'sf_fmin.c'; else $(CYGPATH_W) '$(srcdir)/sf_fmin.c'; fi`
+
+lib_a-s_fabs.o: s_fabs.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fabs.o `test -f 's_fabs.c' || echo '$(srcdir)/'`s_fabs.c
+
+lib_a-s_fabs.obj: s_fabs.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fabs.obj `if test -f 's_fabs.c'; then $(CYGPATH_W) 's_fabs.c'; else $(CYGPATH_W) '$(srcdir)/s_fabs.c'; fi`
+
+lib_a-sf_fabs.o: sf_fabs.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fabs.o `test -f 'sf_fabs.c' || echo '$(srcdir)/'`sf_fabs.c
+
+lib_a-sf_fabs.obj: sf_fabs.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fabs.obj `if test -f 'sf_fabs.c'; then $(CYGPATH_W) 'sf_fabs.c'; else $(CYGPATH_W) '$(srcdir)/sf_fabs.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_fabs.c b/newlib/libm/machine/riscv/s_fabs.c
new file mode 100644
index 000000000..abf7d2c0f
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_fabs.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
+fabs (double x)
+{
+ double result;
+ asm ("fabs.d\t%0, %1" : "=f"(result) : "f"(x));
+ return result;
+}
+
+#else
+#include "../../math/s_fabs.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_fmax.c b/newlib/libm/machine/riscv/s_fmax.c
new file mode 100644
index 000000000..bc174d0a0
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_fmax.c
@@ -0,0 +1,49 @@
+/*
+ * 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
+fmax (double x, double y)
+{
+ double result;
+ asm ("fmax.d\t%0, %1, %2" : "=f" (result) : "f" (x), "f" (y));
+ return result;
+}
+#else
+#include "../../common/s_fmax.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_fmin.c b/newlib/libm/machine/riscv/s_fmin.c
new file mode 100644
index 000000000..13dbbf5dd
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_fmin.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
+fmin (double x, double y)
+{
+ double result;
+ asm ("fmin.d\t%0, %1, %2" : "=f" (result) : "f" (x), "f" (y));
+ return result;
+}
+
+#else
+#include "../../common/s_fmin.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_fabs.c b/newlib/libm/machine/riscv/sf_fabs.c
new file mode 100644
index 000000000..1ca92d30d
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_fabs.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
+fabsf (float x)
+{
+ float result;
+ asm ("fabs.s\t%0, %1" : "=f"(result) : "f"(x));
+ return result;
+}
+
+#else
+#include "../../math/sf_fabs.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_fmax.c b/newlib/libm/machine/riscv/sf_fmax.c
new file mode 100644
index 000000000..7b18f0062
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_fmax.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
+fmaxf (float x, float y)
+{
+ float result;
+ asm ("fmax.s\t%0, %1, %2" : "=f" (result) : "f" (x), "f" (y));
+ return result;
+}
+
+#else
+#include "../../common/sf_fmax.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_fmin.c b/newlib/libm/machine/riscv/sf_fmin.c
new file mode 100644
index 000000000..771613338
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_fmin.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
+fminf (float x, float y)
+{
+ float result;
+ asm ("fmin.s\t%0, %1, %2" : "=f" (result) : "f" (x), "f" (y));
+ return result;
+}
+
+#else
+#include "../../common/sf_fmin.c"
+#endif
--
2.28.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-27 6:19 [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] Kito Cheng
@ 2020-10-27 6:19 ` Kito Cheng
2020-10-27 18:11 ` Keith Packard
2020-10-27 18:22 ` Keith Packard
2020-10-27 7:59 ` [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] Corinna Vinschen
1 sibling, 2 replies; 8+ messages in thread
From: Kito Cheng @ 2020-10-27 6:19 UTC (permalink / raw)
To: newlib; +Cc: Kito Cheng
---
newlib/libm/machine/riscv/Makefile.am | 3 +-
newlib/libm/machine/riscv/Makefile.in | 18 ++++-
newlib/libm/machine/riscv/riscv_math.h | 80 +++++++++++++++++++++++
newlib/libm/machine/riscv/s_finite.c | 51 +++++++++++++++
newlib/libm/machine/riscv/s_fpclassify.c | 60 +++++++++++++++++
newlib/libm/machine/riscv/s_isinf.c | 52 +++++++++++++++
newlib/libm/machine/riscv/sf_finite.c | 48 ++++++++++++++
newlib/libm/machine/riscv/sf_fpclassify.c | 60 +++++++++++++++++
newlib/libm/machine/riscv/sf_isinf.c | 52 +++++++++++++++
9 files changed, 421 insertions(+), 3 deletions(-)
create mode 100644 newlib/libm/machine/riscv/riscv_math.h
create mode 100644 newlib/libm/machine/riscv/s_finite.c
create mode 100644 newlib/libm/machine/riscv/s_fpclassify.c
create mode 100644 newlib/libm/machine/riscv/s_isinf.c
create mode 100644 newlib/libm/machine/riscv/sf_finite.c
create mode 100644 newlib/libm/machine/riscv/sf_fpclassify.c
create mode 100644 newlib/libm/machine/riscv/sf_isinf.c
diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
index 9443fb8e6..9e7b9e868 100644
--- a/newlib/libm/machine/riscv/Makefile.am
+++ b/newlib/libm/machine/riscv/Makefile.am
@@ -9,7 +9,8 @@ LIB_SOURCES = \
fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
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_fabs.c sf_fabs.c \
+ s_fpclassify.c sf_fpclassify.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 063c643bb..5c915e90f 100644
--- a/newlib/libm/machine/riscv/Makefile.in
+++ b/newlib/libm/machine/riscv/Makefile.in
@@ -81,7 +81,8 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \
lib_a-ef_sqrt.$(OBJEXT) lib_a-s_fmax.$(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-sf_fabs.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
+ lib_a-sf_fpclassify.$(OBJEXT)
am_lib_a_OBJECTS = $(am__objects_1)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
@@ -212,7 +213,8 @@ LIB_SOURCES = \
fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
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_fabs.c sf_fabs.c \
+ s_fpclassify.c sf_fpclassify.c
noinst_LIBRARIES = lib.a
lib_a_SOURCES = $(LIB_SOURCES)
@@ -422,6 +424,18 @@ lib_a-sf_fabs.o: sf_fabs.c
lib_a-sf_fabs.obj: sf_fabs.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fabs.obj `if test -f 'sf_fabs.c'; then $(CYGPATH_W) 'sf_fabs.c'; else $(CYGPATH_W) '$(srcdir)/sf_fabs.c'; fi`
+lib_a-s_fpclassify.o: s_fpclassify.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fpclassify.o `test -f 's_fpclassify.c' || echo '$(srcdir)/'`s_fpclassify.c
+
+lib_a-s_fpclassify.obj: s_fpclassify.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fpclassify.obj `if test -f 's_fpclassify.c'; then $(CYGPATH_W) 's_fpclassify.c'; else $(CYGPATH_W) '$(srcdir)/s_fpclassify.c'; fi`
+
+lib_a-sf_fpclassify.o: sf_fpclassify.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fpclassify.o `test -f 'sf_fpclassify.c' || echo '$(srcdir)/'`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`
+
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/riscv_math.h b/newlib/libm/machine/riscv/riscv_math.h
new file mode 100644
index 000000000..38948ca12
--- /dev/null
+++ b/newlib/libm/machine/riscv/riscv_math.h
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#ifndef __RISCV_MATH_H
+#define __RISCV_MATH_H
+
+
+
+#ifdef __riscv_flen
+
+#define FCLASS_NEG_INF (1 << 0)
+#define FCLASS_NEG_NORMAL (1 << 1)
+#define FCLASS_NEG_SUBNORMAL (1 << 2)
+#define FCLASS_NEG_ZERO (1 << 3)
+#define FCLASS_POS_ZERO (1 << 4)
+#define FCLASS_POS_SUBNORMAL (1 << 5)
+#define FCLASS_POS_NORMAL (1 << 6)
+#define FCLASS_POS_INF (1 << 7)
+#define FCLASS_SNAN (1 << 8)
+#define FCLASS_QNAN (1 << 9)
+
+
+#define FCLASS_INF (FCLASS_NEG_INF | FCLASS_POS_INF)
+#define FCLASS_ZERO (FCLASS_NEG_ZERO | FCLASS_POS_ZERO)
+#define FCLASS_NORMAL (FCLASS_NEG_NORMAL | FCLASS_POS_NORMAL)
+#define FCLASS_SUBNORMAL (FCLASS_NEG_SUBNORMAL | FCLASS_POS_SUBNORMAL)
+#define FCLASS_NAN (FCLASS_SNAN | FCLASS_QNAN)
+
+#if __riscv_flen >= 64
+static inline long _fclass_d(double x){
+ long fclass;
+ __asm __volatile ("fclass.d\t%0, %1" : "=r" (fclass) : "f" (x));
+ return fclass;
+}
+#endif
+
+#if __riscv_flen >= 32
+static inline long _fclass_f(float x){
+ long fclass;
+ __asm __volatile ("fclass.s\t%0, %1" : "=r" (fclass) : "f" (x));
+ return fclass;
+}
+#endif
+
+#endif /* __riscv_flen */
+
+
+#endif /* __RISCV_MATH_H */
diff --git a/newlib/libm/machine/riscv/s_finite.c b/newlib/libm/machine/riscv/s_finite.c
new file mode 100644
index 000000000..f5336e5dc
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_finite.c
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+/*
+ * finite(x) returns 1 is x is finite, else 0;
+ */
+
+#include <math.h>
+
+#if defined(__riscv_flen) && __riscv_flen >= 64
+#include "riscv_math.h"
+int finite(double x)
+{
+ long fclass = _fclass_d (x);
+ return (fclass & FCLASS_INF) == 0;
+}
+#else
+#include "../../common/s_finite.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_fpclassify.c b/newlib/libm/machine/riscv/s_fpclassify.c
new file mode 100644
index 000000000..8112d4f78
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_fpclassify.c
@@ -0,0 +1,60 @@
+/*
+ * 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
+
+#include "riscv_math.h"
+
+int
+__fpclassifyd (double x)
+{
+ long fclass = _fclass_d (x);
+
+ if (fclass & FCLASS_ZERO)
+ return FP_ZERO;
+ else if (fclass & FCLASS_NORMAL)
+ return FP_NORMAL;
+ else if (fclass & FCLASS_SUBNORMAL)
+ return FP_SUBNORMAL;
+ else if (fclass & FCLASS_INF)
+ return FP_INFINITE;
+ else
+ return FP_NAN;
+}
+
+#else
+#include "../../common/s_fpclassify.c"
+#endif
diff --git a/newlib/libm/machine/riscv/s_isinf.c b/newlib/libm/machine/riscv/s_isinf.c
new file mode 100644
index 000000000..3c82ee268
--- /dev/null
+++ b/newlib/libm/machine/riscv/s_isinf.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 isinf
+
+int
+isinf (double x)
+{
+ long fclass = _fclass_d (x);
+ return (fclass & FCLASS_INF);
+}
+#else
+#include "../../common/sf_isinf.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_finite.c b/newlib/libm/machine/riscv/sf_finite.c
new file mode 100644
index 000000000..f1cf5c6ce
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_finite.c
@@ -0,0 +1,48 @@
+/*
+ * 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
+
+#include "riscv_math.h"
+int finitef(float x)
+{
+ long fclass = _fclass_f (x);
+ return (fclass & FCLASS_INF) == 0;
+}
+#else
+#include "../../common/sf_finite.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_fpclassify.c b/newlib/libm/machine/riscv/sf_fpclassify.c
new file mode 100644
index 000000000..dee9a7a25
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_fpclassify.c
@@ -0,0 +1,60 @@
+/*
+ * 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
+
+#include "riscv_math.h"
+
+int
+__fpclassifyf (float x)
+{
+ long fclass = _fclass_f (x);
+
+ if (fclass & FCLASS_ZERO)
+ return FP_ZERO;
+ else if (fclass & FCLASS_NORMAL)
+ return FP_NORMAL;
+ else if (fclass & FCLASS_SUBNORMAL)
+ return FP_SUBNORMAL;
+ else if (fclass & FCLASS_INF)
+ return FP_INFINITE;
+ else
+ return FP_NAN;
+}
+
+#else
+#include "../../common/sf_fpclassify.c"
+#endif
diff --git a/newlib/libm/machine/riscv/sf_isinf.c b/newlib/libm/machine/riscv/sf_isinf.c
new file mode 100644
index 000000000..0c60f33af
--- /dev/null
+++ b/newlib/libm/machine/riscv/sf_isinf.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 isinff
+
+int
+isinff (float x)
+{
+ long fclass = _fclass_f (x);
+ return (fclass & FCLASS_INF);
+}
+#else
+#include "../../common/sf_isinf.c"
+#endif
--
2.28.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f].
2020-10-27 6:19 [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] Kito Cheng
2020-10-27 6:19 ` [PATCH 2/2] RISC-V: Implment finite and fpclassify Kito Cheng
@ 2020-10-27 7:59 ` Corinna Vinschen
1 sibling, 0 replies; 8+ messages in thread
From: Corinna Vinschen @ 2020-10-27 7:59 UTC (permalink / raw)
To: newlib
On Oct 27 14:19, Kito Cheng wrote:
> ---
> newlib/libm/machine/riscv/Makefile.am | 4 ++-
> newlib/libm/machine/riscv/Makefile.in | 45 ++++++++++++++++++++++--
> newlib/libm/machine/riscv/s_fabs.c | 50 +++++++++++++++++++++++++++
> newlib/libm/machine/riscv/s_fmax.c | 49 ++++++++++++++++++++++++++
> newlib/libm/machine/riscv/s_fmin.c | 50 +++++++++++++++++++++++++++
> newlib/libm/machine/riscv/sf_fabs.c | 50 +++++++++++++++++++++++++++
> newlib/libm/machine/riscv/sf_fmax.c | 50 +++++++++++++++++++++++++++
> newlib/libm/machine/riscv/sf_fmin.c | 50 +++++++++++++++++++++++++++
> 8 files changed, 345 insertions(+), 3 deletions(-)
> create mode 100644 newlib/libm/machine/riscv/s_fabs.c
> create mode 100644 newlib/libm/machine/riscv/s_fmax.c
> create mode 100644 newlib/libm/machine/riscv/s_fmin.c
> create mode 100644 newlib/libm/machine/riscv/sf_fabs.c
> create mode 100644 newlib/libm/machine/riscv/sf_fmax.c
> create mode 100644 newlib/libm/machine/riscv/sf_fmin.c
Pushed the set.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-27 6:19 ` [PATCH 2/2] RISC-V: Implment finite and fpclassify Kito Cheng
@ 2020-10-27 18:11 ` Keith Packard
2020-10-27 18:22 ` Keith Packard
1 sibling, 0 replies; 8+ messages in thread
From: Keith Packard @ 2020-10-27 18:11 UTC (permalink / raw)
To: Kito Cheng, newlib; +Cc: Kito Cheng
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
Kito Cheng <kito.cheng@sifive.com> writes:
> +int
> +isinf (double x)
> +{
> + long fclass = _fclass_d (x);
> + return (fclass & FCLASS_INF);
> +}
> +#else
> +#include "../../common/sf_isinf.c"
> +#endif
You probably want to include s_isinf.c here instead of sf_isinf.c
--
-keith
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-27 6:19 ` [PATCH 2/2] RISC-V: Implment finite and fpclassify Kito Cheng
2020-10-27 18:11 ` Keith Packard
@ 2020-10-27 18:22 ` Keith Packard
2020-10-28 15:42 ` Kito Cheng
1 sibling, 1 reply; 8+ messages in thread
From: Keith Packard @ 2020-10-27 18:22 UTC (permalink / raw)
To: Kito Cheng, newlib; +Cc: Kito Cheng
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
Kito Cheng <kito.cheng@sifive.com> writes:
> +#if defined(__riscv_flen) && __riscv_flen >= 64
> +#include "riscv_math.h"
> +int finite(double x)
> +{
> + long fclass = _fclass_d (x);
> + return (fclass & FCLASS_INF) == 0;
> +}
This also needs to check for FCLASS_NAN:
return (class & (FCLASS_INF|FCLASS_NAN)) == 0;
Same for finitef
--
-keith
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-27 18:22 ` Keith Packard
@ 2020-10-28 15:42 ` Kito Cheng
2020-10-28 20:45 ` Jim Wilson
0 siblings, 1 reply; 8+ messages in thread
From: Kito Cheng @ 2020-10-28 15:42 UTC (permalink / raw)
To: Keith Packard; +Cc: newlib
Hi Keith:
Thanks for your review! I sent patches to fix those two issues :)
On Wed, Oct 28, 2020 at 2:22 AM Keith Packard <keithp@keithp.com> wrote:
> Kito Cheng <kito.cheng@sifive.com> writes:
>
> > +#if defined(__riscv_flen) && __riscv_flen >= 64
> > +#include "riscv_math.h"
> > +int finite(double x)
> > +{
> > + long fclass = _fclass_d (x);
> > + return (fclass & FCLASS_INF) == 0;
> > +}
>
> This also needs to check for FCLASS_NAN:
>
> return (class & (FCLASS_INF|FCLASS_NAN)) == 0;
>
> Same for finitef
>
> --
> -keith
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-28 15:42 ` Kito Cheng
@ 2020-10-28 20:45 ` Jim Wilson
2020-10-29 3:02 ` Kito Cheng
0 siblings, 1 reply; 8+ messages in thread
From: Jim Wilson @ 2020-10-28 20:45 UTC (permalink / raw)
To: Kito Cheng; +Cc: Keith Packard, Newlib
A copysign hook would also be useful. That is a single instruction, just
like abs.
Jim
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] RISC-V: Implment finite and fpclassify
2020-10-28 20:45 ` Jim Wilson
@ 2020-10-29 3:02 ` Kito Cheng
0 siblings, 0 replies; 8+ messages in thread
From: Kito Cheng @ 2020-10-29 3:02 UTC (permalink / raw)
To: Jim Wilson; +Cc: Keith Packard, Newlib
Hi Jim:
Thanks for your inputs, next round I'll send fcvt* and fsgnj* related
functions :)
On Thu, Oct 29, 2020 at 4:45 AM Jim Wilson <jimw@sifive.com> wrote:
> A copysign hook would also be useful. That is a single instruction, just
> like abs.
>
> Jim
>
>
>>
>>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-10-29 3:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 6:19 [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] Kito Cheng
2020-10-27 6:19 ` [PATCH 2/2] RISC-V: Implment finite and fpclassify Kito Cheng
2020-10-27 18:11 ` Keith Packard
2020-10-27 18:22 ` Keith Packard
2020-10-28 15:42 ` Kito Cheng
2020-10-28 20:45 ` Jim Wilson
2020-10-29 3:02 ` Kito Cheng
2020-10-27 7:59 ` [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f] 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).