From patchwork Mon Nov 7 14:05:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60099 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E0E0385B83E for ; Mon, 7 Nov 2022 14:06:14 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 8CF893858402 for ; Mon, 7 Nov 2022 14:05:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CF893858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.5]) by gateway (Coremail) with SMTP id _____8BxbbauEGljuw0FAA--.4908S3; Mon, 07 Nov 2022 22:05:34 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxb+KkEGljEHoOAA--.40708S7; Mon, 07 Nov 2022 22:05:34 +0800 (CST) From: Xiaolin Tang To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, i.swmail@xen0n.name Cc: caiyinyu@loongson.cn, xry111@xry111.site, xuchenghua@loongson.cn, chenglulu@loongson.cn, Xiaolin Tang Subject: [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ }. Date: Mon, 7 Nov 2022 22:05:18 +0800 Message-Id: <20221107140523.896735-6-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221107140523.896735-1-tangxiaolin@loongson.cn> References: <20221107140523.896735-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8C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Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8l38UUUUUU== X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use hardware Floating-point instruction fscaleb.{s/d}, fclass.{s/d} to implement functions scalb{f/ }, scalbn{f/ }. * sysdeps/loongarch/fpu/e_scalb.c: New file. * sysdeps/loongarch/fpu/e_scalbf.c: Likewise. * sysdeps/loongarch/fpu/s_scalbn.c: Likewise. * sysdeps/loongarch/fpu/s_scalbnf.c: Likewise. --- sysdeps/loongarch/fpu/e_scalb.c | 61 +++++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/e_scalbf.c | 61 +++++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_scalbn.c | 29 +++++++++++++++ sysdeps/loongarch/fpu/s_scalbnf.c | 29 +++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 sysdeps/loongarch/fpu/e_scalb.c create mode 100644 sysdeps/loongarch/fpu/e_scalbf.c create mode 100644 sysdeps/loongarch/fpu/s_scalbn.c create mode 100644 sysdeps/loongarch/fpu/s_scalbnf.c diff --git a/sysdeps/loongarch/fpu/e_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c new file mode 100644 index 0000000000..de01441186 --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalb.c @@ -0,0 +1,61 @@ +/* scalb(). LoongArch version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define NO_MATH_REDIRECT +#include +#include +#include +#include + +double +__ieee754_scalb (double x, double fn) +{ + int x_cond; + int fn_cond; + asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.d \t%0, %1" : "=f" (fn_cond) : "f" (fn)); + + if (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN)) + return x * fn; + else if (__glibc_unlikely(fn_cond & _FCLASS_INF)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__glibc_likely(-DBL_MAX < fn && fn < DBL_MAX)) + { + long y1; + double y; + + asm volatile ("frint.d \t%0, %1" : "=f" (y) : "f" (fn)); + asm volatile ("ftintrz.l.d \t%0, %1" : "=f" (y) : "f" (y)); + asm volatile ("movfr2gr.d \t%0, %1" : "=r" (y1) : "f" (y)); + + if (y1 != fn ) + return (x - x) / (x - x); + + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + } + else + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn)); + + return x; +} +libm_alias_finite (__ieee754_scalb, __scalb) diff --git a/sysdeps/loongarch/fpu/e_scalbf.c b/sysdeps/loongarch/fpu/e_scalbf.c new file mode 100644 index 0000000000..6b617e8fc1 --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalbf.c @@ -0,0 +1,61 @@ +/* scalbf(). LoongArch version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define NO_MATH_REDIRECT +#include +#include +#include +#include + +float +__ieee754_scalbf (float x, float fn) +{ + int x_cond; + int fn_cond; + asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.s \t%0, %1" : "=f" (fn_cond) : "f" (fn)); + + if (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN)) + return x * fn; + else if (__glibc_unlikely(fn_cond & _FCLASS_INF)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__glibc_likely(-FLT_MAX < fn && fn < FLT_MAX)) + { + int y1; + float y; + + asm volatile ("frint.s \t%0, %1" : "=f" (y) : "f" (fn)); + asm volatile ("ftintrz.w.s \t%0, %1" : "=f" (y) : "f" (y)); + asm volatile ("movfr2gr.s \t%0, %1" : "=r" (y1) : "f" (y)); + + if (y1 != fn ) + return (x - x) / (x - x); + + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + } + else + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn)); + + return x; +} +libm_alias_finite (__ieee754_scalb, __scalb) diff --git a/sysdeps/loongarch/fpu/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c new file mode 100644 index 0000000000..c03e81a31e --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbn.c @@ -0,0 +1,29 @@ +/* scalbn(). LoongArch version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define NO_MATH_REDIRECT +#include + +double +__scalbn (double x, int fn) +{ + double tmp; + asm volatile ("movgr2fr.d \t%0, %1" : "=f" (tmp) : "r" (fn)); + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + return x; +} diff --git a/sysdeps/loongarch/fpu/s_scalbnf.c b/sysdeps/loongarch/fpu/s_scalbnf.c new file mode 100644 index 0000000000..15e6428044 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbnf.c @@ -0,0 +1,29 @@ +/* scalbnf(). LoongArch version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define NO_MATH_REDIRECT +#include + +float +__scalbnf (float x, int fn) +{ + float tmp; + asm volatile ("movgr2fr.w \t%0, %1" : "=f" (tmp) : "r" (fn)); + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + return x; +}