From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 289EC3857C57 for ; Tue, 27 Oct 2020 06:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 289EC3857C57 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-pg1-x531.google.com with SMTP id r10so173510pgb.10 for ; Mon, 26 Oct 2020 23:20:05 -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:mime-version :content-transfer-encoding; bh=UI9P9qUkuI4iWrOo77cQ2eGY9VwSsQVFzEetVTxu6Ss=; b=aRpnF6kcfwQQ2c0wAnE5ynC+IDdOh7ToK5I0RemFXJlGrudfL9SMDtPhfHRADR6cZB w8sBlAM3n4nOAaR59cI0cYUBIc5pBXc+XWUg3NNvibSXPZ3IGZl7RSlCjzP9VEtNkSfl q+ncM83kvXA9muRuIbCThWz2z0d7LYagKKtxuCAoIPM4lMi3JIzbGnYynBzRyIvM3imk VWWtgPZcHUPFu7NP8feP9vAYIH+TN+Hyhxibt8ncBIDdVDMXgSZ0KMVUKcRnvoFra5dO 61MSc01rKB9/ObYSq47d/YZEOK11IOd8QxSgNbCLhBp9vkFxUrkDZ6m46Ys5pMYRZE+D BXlg== 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:mime-version :content-transfer-encoding; bh=UI9P9qUkuI4iWrOo77cQ2eGY9VwSsQVFzEetVTxu6Ss=; b=gr1mv5QBEKyvSJLDza9daYOpZD56tpVuNzn5MyfisntfHDUps1zbi/Sl0PkG5TZ9JA NL1drNYWRmzlAQnOszVPg37KJ12fCiADKwddicQDWqGLoLXJ3oXIK3ascV6nKYHVbgF3 2sw9AHaYaBL+nqeYiD6MGL5NE8F7GJciBiWtSjpICUWmZUDSMt/hgmrYdMAKr3DXhi9p 4QJ+SP3tHsU56VDLX0pWKIknsxtY1jk08TbJlmuE6Ak7BJiOBKTmH0W8KcHZVIHT59fM op6i9JFMAqSiDOGjLY1843vxy9WmlY6+LReGjE0ck8uqFALxfUpKZP7VoONh0b4feAiA Ro6Q== X-Gm-Message-State: AOAM533voS+5g8aBfzvDG2Snqs3AuKPbUeiq/icG2kEWCT4QH8Xw95Nu FcnRewZcAozdqcYYFPMpciCh9HxFdmyw4A== X-Google-Smtp-Source: ABdhPJyFxYXKtYQA/Va1VNubU/a2excLKQNrKo+Lby8Yday71EhaBoNTDTIeuB1y/4adJSzsjUJNvA== X-Received: by 2002:aa7:83c2:0:b029:156:5ece:98b6 with SMTP id j2-20020aa783c20000b02901565ece98b6mr973322pfn.4.1603779603405; Mon, 26 Oct 2020 23:20:03 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 23:20:02 -0700 (PDT) From: Kito Cheng To: newlib@sourceware.org Cc: Kito Cheng Subject: [PATCH 1/2] RISC-V: Add fabs[f], fmax[f] and fmin[f]. Date: Tue, 27 Oct 2020 14:19:57 +0800 Message-Id: <20201027061958.83712-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.28.0 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:07 -0000 --- 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 + +#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 + +#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 + +#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 + +#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 + +#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 + +#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