From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 5B99A3858D37 for ; Tue, 27 Oct 2020 06:20:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B99A3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kito.cheng@sifive.com Received: by mail-pf1-x436.google.com with SMTP id a200so299305pfa.10 for ; Mon, 26 Oct 2020 23:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5EoROnI/YZBRp+aVLtydTvMfDdFlgA1/4JfaDVog/b4=; b=XrVBW7o7MIr+c3hvOspOBSKs2KQw91EP6CQTtUsIhdxg0WyJK594+65md2/HeWEVHJ aX6fmWK0v6pA0EQwWhKJgPMsXyA6uwxTXaBiKDHdw5Jp4pc/FIXBXdC4I1/4av/0xSN+ 7dkoXDOZ8lSlBusgOldDhyOT0fQEDgDOSo2zeE149Q8uUj+JxXRVOBEonPAc6pidiYOO bRzzElMe/GGKsXd3YwfUIIeUfijJui1t03VZ40b0TOJkJeDJ5spWI4e8ajow+C2eeOun 1npxhkwk8gkTCORgrTnJygD+vbcZQN41guPeQbnrgfDV96vIilKplABIoSBwUctwJZmf te/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5EoROnI/YZBRp+aVLtydTvMfDdFlgA1/4JfaDVog/b4=; b=VrufIAVLlACC3RuL7M61KqkuYRzqdwYcHE/s5o8s4g6+W5T3NRE6gzxtc/Z//zogv4 cICJpXSz4pRtQsDMrnyRMjjksTECj98yD2luWu7K5dRff0qmJBjnbAUw0CixT/nEzjyK ymnCbB7rYMNg5UQIS21dwywh1+orF1jQQj+V10L64hMIX8GA6OrAivP8B6thB6j5wgtW wY15lA01vRwa51TYxLGFhel/SYcjHCmefddTsc/5h1qLcsRPJZDEeEC/UPrBy+182dPH 1Mzn0Fj+OaAgrT/F7nCXlqvOzIl1BeYEP16bAM8a4UICOhWmyxH9DE/IxV//q9JP3Qxi B68g== X-Gm-Message-State: AOAM530xoggQiU/v9anZ8/XWWLeFfN2QX0L7gIyOfa+r/6SRdAtdcBbj C8ny3UrD4Xvpp21BNPLuv99KbRkVrlAWfQ== X-Google-Smtp-Source: ABdhPJzN19642w91yArtrb/IyKd0atxajj2eSZfb5decxnOVVZvJnQs1BTXflRe+YeNP7I4RBMBi2g== X-Received: by 2002:aa7:9ac3:0:b029:158:db9f:c541 with SMTP id x3-20020aa79ac30000b0290158db9fc541mr943358pfp.34.1603779606656; Mon, 26 Oct 2020 23:20:06 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id ge6sm701479pjb.29.2020.10.26.23.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 23:20:06 -0700 (PDT) From: Kito Cheng To: newlib@sourceware.org Cc: Kito Cheng Subject: [PATCH 2/2] RISC-V: Implment finite and fpclassify Date: Tue, 27 Oct 2020 14:19:58 +0800 Message-Id: <20201027061958.83712-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027061958.83712-1-kito.cheng@sifive.com> References: <20201027061958.83712-1-kito.cheng@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Oct 2020 06:20:11 -0000 --- 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 + +#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 + +#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 +#include + +#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 + +#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 + +#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 +#include + +#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