From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 1FC873857011 for ; Wed, 18 Nov 2020 03:36:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1FC873857011 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-pj1-x102d.google.com with SMTP id t12so337656pjq.5 for ; Tue, 17 Nov 2020 19:36:00 -0800 (PST) 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:reply-to :mime-version:content-transfer-encoding; bh=mP+u7FEn9/fD9Sm4g+gBGWXiMnPbI7AiGy2csUECLhc=; b=SmMrhTLn4Pht1ZGnp5Hib2GebOE808P2c15/xO7ISjtoh+tTyKqMl9z/hN19NgivXG QuB1rXnBBF9jISFtKesyzfqGNY74uROW+cJ70TNDou3QXmLnB/OI2lZ/zsxyon/I7Mlz m7GuO0YfcIOKz73kt2vzjseYD/LIw6UJSe49O/XO9bt+KYY9ZS8eTS6cyyHx0amXuUfW zh62VdMzV68yuegNW2dHwDcagVbkzcrj1qRMmO4dCUw1qpNXxUtZebW9a3CbIZ0yXUN3 nSlDNNtBind7/f35jgfHCMs/M52hZ85BjiZjDf44DizONU61iZH2bHC51emlABSfG5Dq l2XQ== 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:reply-to:mime-version:content-transfer-encoding; bh=mP+u7FEn9/fD9Sm4g+gBGWXiMnPbI7AiGy2csUECLhc=; b=KNq5xYkMzjIrd4+EUWr9AyHBQPFbP5hhYCEsxqksnFcUM+MgxTsy4NRWlUs9Uwpzzn GA7jh1L8nKYHvNTuAEi37WKljblGaoNV2li6gi8vC4RncGABv/Y8MDXJ4874LmHAQrsv 6RLGPWklc4R8b+ldPSmSCmP/EVS3X3PCkD8mUQW6CBvxBFjVA6DOvSUF1U2YdFneVZsd Me4H5v04jrXQe7pSHGt10v6zX58ATuRFi0zn2EYQ303egk8900nb1CnJMQc9gn4xooAr Uzk0xmThYjI/JbywVbb/yUrqANUabbtfXo4yBvjPBUE/H5hc+OgLwxlNLzK6yqf9eEEN Wq1A== X-Gm-Message-State: AOAM531YpI637ktjheGPCYuET4Ofy2MWDWQiYkkq7EsytiVQTUCjgX4m DiPgKYmzSupmYnGKrduFyIDC262Tu0S21g4N X-Google-Smtp-Source: ABdhPJySlS8+Jbn4jsqlPyRA5iw24Z6HHT9+6VORjjf9/kPauSKpdaHipm4soT/PXYwFbsBjITr3MQ== X-Received: by 2002:a17:902:bc4a:b029:d6:d985:29cf with SMTP id t10-20020a170902bc4ab02900d6d98529cfmr2716436plz.62.1605670558483; Tue, 17 Nov 2020 19:35:58 -0800 (PST) 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 p19sm581836pjv.32.2020.11.17.19.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 19:35:57 -0800 (PST) From: Kito Cheng To: newlib@sourceware.org Cc: Kito Cheng Subject: [PATCH 3/3] RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f]. Date: Wed, 18 Nov 2020 11:35:43 +0800 Message-Id: <20201118033543.74968-4-kito.cheng@sifive.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118033543.74968-1-kito.cheng@sifive.com> References: <20201118033543.74968-1-kito.cheng@sifive.com> Reply-To: Kito Cheng MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.0 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: Wed, 18 Nov 2020 03:36:03 -0000 --- 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 + +#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 + +#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 + +#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 + +#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 + +#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 + +#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 + +#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 + +#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