From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 6C55238708A8 for ; Wed, 18 Nov 2020 03:35:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6C55238708A8 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-x102c.google.com with SMTP id t12so337622pjq.5 for ; Tue, 17 Nov 2020 19:35:58 -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=iuOfzzUk9bzEsnZNROKnfImlzv5I110ybwCPeAXQmMM=; b=N/XSF+7McYc7E3XH1qX5QTaMcGHD+V39qzjS42MP2LNKGrUBEJV03V/ByohPUVEdxF 3QfFovkFLuqCAfGsnaQ6Pi5kyBjrZsi0yMwi/sRbQfLT7DrJKYjnliXuXd++XPwMo0CR reUIUatcMmrS5139jEk/phtRFpR8PWDYIuUgg2urpKsjdbBiFBJ2Dik1QQrcmUdK0/fd O4AAcW7cdVLQxtxe6IZbCS3ZCL/7sBIT0VbAhbnVWCdIRsOtWF4rsV5KuoT+K4s2cink M4JLoH/ObeXJqdV96GLUx0FRpBOoxIw3nVTZuDbU8UUransqgXwYxHZInhbcw1k3DxmB NEYA== 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=iuOfzzUk9bzEsnZNROKnfImlzv5I110ybwCPeAXQmMM=; b=DseJKfg38Sb0p9WUJgrq7LgdZtKvBrK6Dc+W+8AXBuuqIloXffYQ76pwHxkcHiSTlz rgMJ/aDKx0bwdbtYOsn+dAs9TYmc72MAW/dK/+dbP2rXh+WZBuzKuQCISQvHmZz4MBNd yPS9lOlk1ybKlLdjqkNd0HhtG4vztLLZawqSkg2iu8TXs+VOj5rzkeXdmMGada2hQoVS n7RWSAM+BTba7JIxu6aknYV1sY9V1+8daWEv7Xz/Yk514bJSagAyH4vSImBuvr/XibVy wIe9FBIrXNdWB+9qGll8NFQua7o0E2MA39B2gUAKAuwB8ddPIhI5KvWMYR37cglMyGuU KdHQ== X-Gm-Message-State: AOAM531M5ZBbeJQkKJsuTIxdmGvmohtkW+ezRBynQLoBo+/QWJ8hmbg+ HI29Xvlxq2GQ6YvjadJXVBuQy/r51LodWrjM X-Google-Smtp-Source: ABdhPJwShxTWOLErN4li9c53I16Q8p5BPCiRVPkYUzp9SgXa0LtdmzKhxRR48b1ZAwlztXj7G1bNLw== X-Received: by 2002:a17:90a:4a12:: with SMTP id e18mr2245985pjh.9.1605670556874; Tue, 17 Nov 2020 19:35:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 19:35:56 -0800 (PST) From: Kito Cheng To: newlib@sourceware.org Cc: Kito Cheng Subject: [PATCH 2/3] RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] Date: Wed, 18 Nov 2020 11:35:42 +0800 Message-Id: <20201118033543.74968-3-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:00 -0000 --- newlib/libm/machine/riscv/Makefile.am | 4 +- newlib/libm/machine/riscv/Makefile.in | 32 ++++++++++++++- newlib/libm/machine/riscv/s_copysign.c | 50 ++++++++++++++++++++++++ newlib/libm/machine/riscv/s_isnan.c | 52 +++++++++++++++++++++++++ newlib/libm/machine/riscv/sf_copysign.c | 50 ++++++++++++++++++++++++ newlib/libm/machine/riscv/sf_isnan.c | 52 +++++++++++++++++++++++++ 6 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 newlib/libm/machine/riscv/s_copysign.c create mode 100644 newlib/libm/machine/riscv/s_isnan.c create mode 100644 newlib/libm/machine/riscv/sf_copysign.c create mode 100644 newlib/libm/machine/riscv/sf_isnan.c diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am index 1cfcb3dad..5dfa35f30 100644 --- a/newlib/libm/machine/riscv/Makefile.am +++ b/newlib/libm/machine/riscv/Makefile.am @@ -12,7 +12,9 @@ LIB_SOURCES = \ s_fabs.c sf_fabs.c \ s_fpclassify.c sf_fpclassify.c \ s_finite.c sf_finite.c \ - s_isinf.c sf_isinf.c + s_isinf.c sf_isinf.c \ + s_isnan.c sf_isnan.c \ + s_copysign.c sf_copysign.c noinst_LIBRARIES = lib.a lib_a_SOURCES = $(LIB_SOURCES) diff --git a/newlib/libm/machine/riscv/Makefile.in b/newlib/libm/machine/riscv/Makefile.in index 6d0dfe28c..dcf71d00b 100644 --- a/newlib/libm/machine/riscv/Makefile.in +++ b/newlib/libm/machine/riscv/Makefile.in @@ -84,7 +84,9 @@ am__objects_1 = lib_a-feclearexcept.$(OBJEXT) \ lib_a-sf_fabs.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \ lib_a-sf_fpclassify.$(OBJEXT) lib_a-s_finite.$(OBJEXT) \ lib_a-sf_finite.$(OBJEXT) lib_a-s_isinf.$(OBJEXT) \ - lib_a-sf_isinf.$(OBJEXT) + lib_a-sf_isinf.$(OBJEXT) lib_a-s_isnan.$(OBJEXT) \ + lib_a-sf_isnan.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \ + lib_a-sf_copysign.$(OBJEXT) am_lib_a_OBJECTS = $(am__objects_1) lib_a_OBJECTS = $(am_lib_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ @@ -218,7 +220,9 @@ LIB_SOURCES = \ s_fabs.c sf_fabs.c \ s_fpclassify.c sf_fpclassify.c \ s_finite.c sf_finite.c \ - s_isinf.c sf_isinf.c + s_isinf.c sf_isinf.c \ + s_isnan.c sf_isnan.c \ + s_copysign.c sf_copysign.c noinst_LIBRARIES = lib.a lib_a_SOURCES = $(LIB_SOURCES) @@ -464,6 +468,30 @@ lib_a-sf_isinf.o: sf_isinf.c lib_a-sf_isinf.obj: sf_isinf.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isinf.obj `if test -f 'sf_isinf.c'; then $(CYGPATH_W) 'sf_isinf.c'; else $(CYGPATH_W) '$(srcdir)/sf_isinf.c'; fi` +lib_a-s_isnan.o: s_isnan.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isnan.o `test -f 's_isnan.c' || echo '$(srcdir)/'`s_isnan.c + +lib_a-s_isnan.obj: s_isnan.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_isnan.obj `if test -f 's_isnan.c'; then $(CYGPATH_W) 's_isnan.c'; else $(CYGPATH_W) '$(srcdir)/s_isnan.c'; fi` + +lib_a-sf_isnan.o: sf_isnan.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isnan.o `test -f 'sf_isnan.c' || echo '$(srcdir)/'`sf_isnan.c + +lib_a-sf_isnan.obj: sf_isnan.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_isnan.obj `if test -f 'sf_isnan.c'; then $(CYGPATH_W) 'sf_isnan.c'; else $(CYGPATH_W) '$(srcdir)/sf_isnan.c'; fi` + +lib_a-s_copysign.o: s_copysign.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_copysign.o `test -f 's_copysign.c' || echo '$(srcdir)/'`s_copysign.c + +lib_a-s_copysign.obj: s_copysign.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_copysign.obj `if test -f 's_copysign.c'; then $(CYGPATH_W) 's_copysign.c'; else $(CYGPATH_W) '$(srcdir)/s_copysign.c'; fi` + +lib_a-sf_copysign.o: sf_copysign.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_copysign.o `test -f 'sf_copysign.c' || echo '$(srcdir)/'`sf_copysign.c + +lib_a-sf_copysign.obj: sf_copysign.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_copysign.obj `if test -f 'sf_copysign.c'; then $(CYGPATH_W) 'sf_copysign.c'; else $(CYGPATH_W) '$(srcdir)/sf_copysign.c'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/newlib/libm/machine/riscv/s_copysign.c b/newlib/libm/machine/riscv/s_copysign.c new file mode 100644 index 000000000..047535578 --- /dev/null +++ b/newlib/libm/machine/riscv/s_copysign.c @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Kito Cheng + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if defined(__riscv_flen) && __riscv_flen >= 64 + +double +copysign (double x, double y) +{ + double result; + asm ("fsgnj.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); + return result; +} + +#else +#include "../../common/s_copysign.c" +#endif diff --git a/newlib/libm/machine/riscv/s_isnan.c b/newlib/libm/machine/riscv/s_isnan.c new file mode 100644 index 000000000..a0209729a --- /dev/null +++ b/newlib/libm/machine/riscv/s_isnan.c @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Kito Cheng + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#if defined(__riscv_flen) && __riscv_flen >= 64 + +#include "riscv_math.h" +#undef isnan + +int +isnan (double x) +{ + long fclass = _fclass_d (x); + return (fclass & FCLASS_NAN); +} +#else +#include "../../common/s_isnan.c" +#endif diff --git a/newlib/libm/machine/riscv/sf_copysign.c b/newlib/libm/machine/riscv/sf_copysign.c new file mode 100644 index 000000000..31b1321ad --- /dev/null +++ b/newlib/libm/machine/riscv/sf_copysign.c @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Kito Cheng + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if defined(__riscv_flen) && __riscv_flen >= 32 + +float +copysignf (float x, float y) +{ + float result; + asm ("fsgnj.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); + return result; +} + +#else +#include "../../common/sf_copysign.c" +#endif diff --git a/newlib/libm/machine/riscv/sf_isnan.c b/newlib/libm/machine/riscv/sf_isnan.c new file mode 100644 index 000000000..e38abf4ab --- /dev/null +++ b/newlib/libm/machine/riscv/sf_isnan.c @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Kito Cheng + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#if defined(__riscv_flen) && __riscv_flen >= 32 + +#include "riscv_math.h" +#undef isnanf + +int +isnanf (float x) +{ + long fclass = _fclass_f (x); + return (fclass & FCLASS_NAN); +} +#else +#include "../../common/sf_isnan.c" +#endif -- 2.29.2